`
yeluowuhen
  • 浏览: 155759 次
  • 性别: Icon_minigender_2
  • 来自: 北京
社区版块
存档分类
最新评论

使用wiremock模拟返回数据

 
阅读更多

       步骤如下:

  1. 下载wiremock-body-transformer-1.1.3.jar及wiremock-standalone-2.3.1.jar

       2. 在__file文件中创建一个file,存放json格式的返回数据,内容如下

       cat __file/dsp.json 

{
  "cur": "CNY",
  "seatbid": [
    {
      "bid": [
        {
          "ext": {
            "style": 3,
            "adm": [
              {
                "url": "http://img1.126.net/autoftp/yipin/7c07edc4b6822f17.jpg",
                "type": 0
              }
            ],
            "advertiser":{
                "id" : 2345,
                "industry" : "3",
                "subIndustry" : "0201"
             },
            "title": "gif_ad",
            "linkUrl":"https://www.iteye.com/"
          },
          "clickm": [
            "https://126.com"
          ],
          "crid": "3737",
          "pvm": [
            "https://126.com"
          ],
          "price": 49999,
          "impid": "210",
          "nurl": "http://test.dsp.com:8040",
          "id": "1138050_182i500_52476_0"
        },
        {
          "ext": {
            "style": 3,
            "androidUrl":"http://www.mediafire.com/download/xfvpuy6lw4aoayv/com.nianticlabs.pokemongo_0.35.0-ARM.apk",
            "title": "bigpig_download",
            "linkUrl":"https://www.zhihu.com",
            "adm": [
              {
                "url": "http://img1.126.net/autoftp/yipin/7c07edc4b6822f17.jpg",
                "type": 0
              }
            ]
          },
          "clickm": [
            "https://kaola.com"
          ],
          "nurl": "https://10.165.124.30:8040/",
          "crid": "1738",
          "pvm": [
            "https://v.admaster.com.cn/i/a17943,b200491230,c1327,i0,m202,h"
          ],
          "price": 1550,
          "impid": "240",
          "id": "1138050_182i500_52476_0"
        },
        {
          "ext": {
            "style": 16,
            "title": "bigpig",
            "linkUrl":"http://www.oschina.net",
            "adm": [
              {
                "url": "https://10.165.120.7/270202/270202.jpg",
                "type": 0
              }
            ]
          },
          "clickm": [
            "https://kaola.com_8050"
          ],
          "nurl": "http://www.xiachufang.com/",
          "crid": "265",
          "pvm": [
            "https://v.admaster.com.cn/i/a17943,b200491229,c1327,i0,m202,h"
          ],
          "price": 40002,
          "impid": "250",
          "id": "11329_182i500_52476_1"
        },
        {
          "ext": {
            "style": 3,
            "title": "threepics",
            "linkUrl":"https://www.oschina.net",
            "adm": [
              {
                "url": "http://img1.126.net/autoftp/yipin/7c07edc4b6822f17.jpg",
                "type": 0
              }
            ]
          },
          "clickm": [
            "https://baidu.com"
          ],
          "nurl": "https://www.360doc.com/",
          "crid": "1738",
          "pvm": [
            "https://weibo.com"
          ],
          "price": 3512,
          "impid": "190",
          "id": "11329_182i500_52476_3"
        }
      ]
    }
  ],
  "id": "$(id)",
  "bidid": "1138050_182500_52476"
}

  

       3. 设置mapping的json格式如下:

       cat mappings/test.json

       

{
    "request": {
        "url": "/api/dsp",
        "method": "POST"
    },
    "response": {
        "status": 200,
        "bodyFileName": "dsp.json",
        "headers": {
            "Content-Type": "text/xml; charset=utf-8"
        },
        "transformers": ["body-transformer"]
    }
}  

  4.  运行脚本如下:

java -cp "wiremock-body-transformer-1.1.3.jar:wiremock-standalone-2.3.1.jar" com.github.tomakehurst.wiremock.standalone.WireMockServerRunner --extensions com.opentable.extension.BodyTransformer --port 9990

     5. 然后访问http://xxxx:9990/api/dsp即可得到2中的返回。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics