【三:Mock服务的使用】

目录

1、工具包

1、:服务包的下载

moco-runner-0.11.0-standalone.jar 下载

2、:运行命令

java -jar ./moco-runner-0.11.0-standalone.jar http -p 8888 -c startup1.json

2、mock的demo

json 复制代码
[
  {
    "description":"这是我们的第一个mock例子",
    "request":{
      "uri":"/demo"
    },
    "response":{
      "text":"第一个moco框架demo"
    }
  }
]

1、get请求

json 复制代码
[
  {
    "description":"模拟一个没有参数get请求",
    "request":{
      "uri":"/getdemo",
      "method":"get"
    },
    "response":{
      "text":"这是一个没有参数的get请求"
    }

  },
  {
    "description":"这是一个带参数get请求",
    "request":{
      "uri":"/getwithparam",
      "method":"get",
      "queries":{
        "name":"huhansan",
        "sex":"20"
      }
    },
    "response":{
      "text":"我胡汉三又回来啦!!!!"
    }

  }
]

2、post请求

json 复制代码
[
  {
    "description":"模拟一个post请求",
    "request":{
      "uri":"/postdemo",
      "method":"post"
    },
    "response":{
      "text":"这是我的第一个mock的post请求"
    }
  },
  {
    "description":"这是一个带参数的post请求",
    "request":{
      "uri":"/postwithparam",
      "method":"post",
      "forms":{
        "name":"huhansan",
        "sex":"man"
      }
    },
    "response":{
      "text":"我胡汉三带着参数来啦!!!"

    }
  }
]

3、带cookies的请求

json 复制代码
[
  {
    "description":"这是一个会返回cookies信息的get请求",
    "request":{
      "uri":"/getCookies",
      "method":"get"
    },
    "response":{
      "cookies":{
        "login":"true"
      },
      "text":"恭喜你获得cookies信息成功"
    }
  },
  
  
  {
    "description":"这是一个带cookies信息的get请求",
    "request":{
      "uri":"/get/with/cookies",
      "method":"get",
      "cookies":{
        "login":"true"
      }
    },
    "response":{
      "text":"这是一个需要携带cookies信息才能访问的get请求"
    }
  },
  
  
  {
    "description":"这是一个带cookies信息的post请求",
    "request":{
      "uri":"/post/with/cookies",
      "method":"post",
      "cookies":{
        "login":"true"
      },
      "json":{
        "name":"huhansan",
        "age":"18"
      }
    },
    "response":{
      "status":200,
      "json":{
        "huhansan":"success",
        "status":"1"
      }
    }
  }

]

4、带请求头的请求

json 复制代码
[
  {
    "description":"这是一个带header信息的post请求",
    "request":{
      "uri":"/post/with/headers",
      "method":"post",
      "headers":{
        "content-type":"application/json"
      },
      "json":{
        "name":"wanglaosi",
        "sex":"woman"
      }
    },
    "response":{
      "json":{
        "wanglaosi":"success",
        "status":"1"
      }
    }

  }
]

5、请求重定向

json 复制代码
[
  {
    "description":"重定向到百度",
    "request":{
      "uri":"/redirect"
    },
    "redirectTo":"http://www.baidu.com"
  },
  {
    "description":"重定向到一个自己的网页上",
    "request":{
      "uri":"/redirect/topath"
    },
    "redirectTo":"/redirect/new"
  },
  {
    "description":"这是被重定向到的请求",
    "request":{
      "uri":"/redirect/new"
    },
    "response":{
      "text":"重定向成功啦"
    }
  }

]
相关推荐
木梓辛铭2 分钟前
Spring Cache的详细使用
java·后端·spring
招风的黑耳6 分钟前
Java视频流RTMP/RTSP协议解析与实战代码
java·视频流
邪恶的贝利亚20 分钟前
定时器设计
java·linux·前端
工业互联网专业22 分钟前
基于springboot+vue的机场乘客服务系统
java·vue.js·spring boot·毕业设计·源码·课程设计·机场乘客服务系统
饕餮争锋23 分钟前
WebMvcConfigurer介绍-笔记
java·笔记·servlet
招风的黑耳29 分钟前
Java集合框架详解与使用场景示例
java·开发语言
xrkhy31 分钟前
java中XML的使用
xml·java·开发语言
胡斌附体41 分钟前
idea挂掉,会导致进程不结束,切换profile环境,导致token认证不通过
java·ide·intellij-idea·调试·token失效
y102121041 小时前
Pyhton训练营打卡Day27
java·开发语言·数据结构
AA-代码批发V哥1 小时前
Java类一文分解:JavaBean,工具类,测试类的深度剖析
java·开发语言