虚拟服务器moco

1、下载mock runner jar文件:
https://repo1.maven.org/maven2/com/github/dreamhead/moco-runner/0.11.0/moco-runner-0.11.0-standalone.jar

2、cmd执行命令:
java -jar moco-runner-0.11.1-standalone.jar http -p 12306 -c filename.json

3、官网文档:
https://github.com/dreamhead/moco/blob/master/moco-doc/apis.md#composite-java-api-desig

4、请求字段:
(1)uri:
“request” :
{“uri” : “/foo”}
(2)变量:
“request” :
{“uri” : “/foo”,
“queries” :
{ “param” : “blah”}
}
(3)method:
“request” :
{
“method” : “get”,
“uri” : “/foo”
}
(4)带请求参数(post)
“request” :
{
“method” : “post”,
“text” : “foo”
}
(5)Header
“request” :
{
“method” : “post”,
“headers” :
{
“content-type” : “application/json”
}
}
(6)Cookie
“request” :
{
“uri” : “/cookie”,
“cookies” :
{
“login” : “true”
}
}
(7)Form
“request” :
{
“method” : “post”,
“forms” :
{
“name” : “foo”
}
}
(8)xml
“request”:
{
“uri”: “/xml”,
“text”:
{
“xml”: “1”
}
}
(8)Json
“request”: {
“uri”: “/json”,
“json”: {
“foo”: “bar”
}
}
(9)Redirect
{
“request” :
{
“uri” : “/redirect”
},
“redirectTo” : “http://www.github.com”
}

(10)可以将请求内容放在文件中
{
“request” :
{
“file” : “foo.request”
},
“response” :
{
“text” : “bar”
}
}

5、响应字段:
(1)可以将响应内容放在文件中
{
“request” :
{
“text” : “foo”
},
“response” :
{
“file” : “bar.response”
}
}
(2)status code
“response” :
{
“status” : 200
}
(3)Cookie
“response” :
{
“cookies” :
{
“login” : “true”
}
}
(4)Attachment
“response”: {
“attachment”: {
“filename”: “foo.txt”,
“file”: “foo.response”
}
}

问题一:两个项目使用同一个mocksever
(1)全局配置文件all_project.json:
[ { “context”: “/boy”, “include”: “boy.json” }, { “context”: “/girl”, “include”: “girl.json” } ]
(2)各项目配置文件:
Boy.json:
[ { “request” : { “uri” : “/hello” }, “response” : { “text” : “I am a boy.” } } ]
Girl.json:
[ { “request” : { “uri” : “/hello” }, “response” : { “text” : “I am a girl.” } } ]
(3)执行命令:java -jar moco-runner--standalone.jar start -p 12306 -g all_project.json
http://localhost:12306/girl/hello
http://localhost:12306/boy/hello

问题二:模拟异常情况
[{
“description”: “查询sku信息”,
“request”: {
“uri”: “/productSaleorgext”,
“method”: “get”

	},
	"response": {
		"status": "500",
		"json": {
			"message": "fail"
		}
	}
}

]

http://localhost:12306/productSaleorgext

问题三:不同的参数对应不同的响应
配置文件:
[

{
 "description":"查询物料信息",
 "request":{
  "uri":"/productSaleorgext",
  "method":"get",
  "queries":{
    "skuNos":"ABC",
    "vkbur":"999"
  }
  
},
    "response":
    {
        "file":"ABC.json"
    }
},	
{
 "description":"查询物料信息",
 "request":{
  "uri":"/productSaleorgext",
  "method":"get",
  "queries":{
    "skuNos":"EFG",
    "vkbur":"888"
  }
  
},
    "response":
    {
        "file":"EFG.json"
    }
}

]

http://localhost:12306/productSaleorgext?skuNos=ABC&vkbur=999
http://localhost:12306/productSaleorgext?skuNos=EFG&vkbur=888

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值