【三: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":"重定向成功啦"
    }
  }

]
相关推荐
努力也学不会java7 分钟前
【设计模式】抽象工厂模式
java·设计模式·oracle·抽象工厂模式
用户60830892904717 分钟前
集合处理利器,Java中的Stream流API
java·后端
玉衡子18 分钟前
八、MySQL全局优化总结&MySQL8新特性
java·mysql
9号达人20 分钟前
Java 14 新特性详解与实践
java·后端·面试
ytadpole23 分钟前
揭秘XXL-JOB:Bean、GLUE 与脚本模式的底层奥秘
java·后端
计算机毕业设计木哥38 分钟前
计算机毕设选题推荐:基于Java+SpringBoot物品租赁管理系统【源码+文档+调试】
java·vue.js·spring boot·mysql·spark·毕业设计·课程设计
青衫客3638 分钟前
Spring异步编程- 浅谈 Reactor 核心操作符
java·spring·响应式编程
Seven9738 分钟前
剑指offer-30、连续⼦数组的最⼤和
java
BenChuat42 分钟前
Java常见排序算法实现
java·算法·排序算法
熙客43 分钟前
SpringCloud概述
java·spring cloud·微服务