下面列出了org.mockito.verification.VerificationMode#org.springframework.test.web.servlet.result.MockMvcResultHandlers 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 编辑项目
*
* @throws Exception
*/
@Test
public void test_project_2_edit() throws Exception {
EditProjectRequestBody body = new EditProjectRequestBody();
body.setId("3714708188751200256");
body.setDesc("修改项目后的描述");
String result = this.mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/project/edit")
.content(JSON.toJSONString(body))
.contentType(MediaType.APPLICATION_JSON)
.session((MockHttpSession) Utils.getLoginSession(this.mockMvc))
.accept(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andDo(MockMvcResultHandlers.print())
.andReturn().getResponse().getContentAsString();
Utils.assertResult(result);
}
@Test
public void testUpdateUser() throws Exception {
UpdateUserInputParam updateUser = new UpdateUserInputParam();
updateUser.setUserId(700001);
updateUser.setDescription("testtttttttttttttttttttttttt");
ResultActions resultActions = mockMvc.perform(MockMvcRequestBuilders.put("/user/userInfo").
content(JsonTools.toJSONString(updateUser)).
contentType(MediaType.APPLICATION_JSON_UTF8)
);
resultActions.
andExpect(MockMvcResultMatchers.status().isOk()).
andDo(MockMvcResultHandlers.print());
System.out
.println("response:" + resultActions.andReturn().getResponse().getContentAsString());
}
/**
* 删除项目成员
*
* @throws Exception
*/
@Test
public void test_project_7_member_delete() throws Exception {
DeleteProjectMemberRequestBody body = new DeleteProjectMemberRequestBody();
body.setId("3714708188751200256");
body.setUserId("3688919024172793856");
String result = this.mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/project/member/delete")
.content(JSON.toJSONString(body))
.contentType(MediaType.APPLICATION_JSON)
.session((MockHttpSession) Utils.getLoginSession(this.mockMvc))
.accept(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andDo(MockMvcResultHandlers.print())
.andReturn().getResponse().getContentAsString();
Utils.assertResult(result);
}
/**
* 查询最近的配置列表
*
* @throws Exception
*/
@Test
public void test_service_config_1_lastestList() throws Exception {
String result = this.mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/service/config/lastestList")
.param("project", "project3")
.param("cluster", "cluster1")
.param("service", "service1")
.param("version", "1.0.0.1")
.contentType(MediaType.APPLICATION_JSON)
.session((MockHttpSession) Utils.getLoginSession(this.mockMvc))
.accept(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andDo(MockMvcResultHandlers.print())
.andReturn().getResponse().getContentAsString();
Utils.assertResult(result);
}
@Test
@WithMockUser(username = "1050106266",
password = "123456",
authorities = "ROLE_ADMIN")
public void testFindUsers() throws Exception {
FindUsersReqVo reqVo = new FindUsersReqVo();
SysUser user = new SysUser();
user.setEnabled(true);
reqVo.setSysUser(user);
Page page = new Page();
page.setPageNum(0);
page.setPageSize(10);
reqVo.setPage(page);
System.out.println(objectMapper.writeValueAsString(reqVo));
mockMvc.perform(MockMvcRequestBuilders.post("/admin/user/findUsers")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(reqVo))
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultHandlers.print())
.andExpect(MockMvcResultMatchers.status().isOk());
}
/**
* 查询配置历史列表
*
* @throws Exception
*/
@Test
public void test_service_config_8_historyList() throws Exception {
String result = this.mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/service/config/historyList")
.param("project", "GG")
.param("cluster", "GG")
.param("service", "GG")
.param("version", "1.0")
.param("isPage", "1")
.contentType(MediaType.APPLICATION_JSON)
.session((MockHttpSession) Utils.getLoginSession(this.mockMvc))
.accept(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andDo(MockMvcResultHandlers.print())
.andReturn().getResponse().getContentAsString();
Utils.assertResult(result);
}
/**
* 回滚配置
*
* @throws Exception
*/
@Test
public void test_service_config_9_rollback() throws Exception {
IdsRequestBody body = new IdsRequestBody();
List<String> ids = new ArrayList<>();
ids.add("3731673452474531840");
ids.add("3731673452474531841");
body.setIds(ids);
String result = this.mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/service/config/rollback")
.content(JSON.toJSONString(body))
.contentType(MediaType.APPLICATION_JSON)
.session((MockHttpSession) Utils.getLoginSession(this.mockMvc))
.accept(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andDo(MockMvcResultHandlers.print())
.andReturn().getResponse().getContentAsString();
Utils.assertResult(result);
}
@Test
public void testFindByPartOfBytecodeBin() throws Exception {
String bytecodeBin = "6060604052341561000c57fe5b5b6001600060000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506402540be4006000600101819055506002600260000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060006002600101819055505b5b610443806100c26000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806366c99139146100465780636d4ce63c14610066575bfe5b341561004e57fe5b610064600480803590602001909190505061008c565b005b341561006e57fe5b610076610264565b6040518082815260200191505060405180910390f35b806000600101540360006001018190555080600260010160008282540192505081905550600480548060010182816100c49190610272565b916000526020600020906004020160005b608060405190810160405280604060405190810160405280600881526020017f32303137303431330000000000000000000000000000000000000000000000008152508152602001600060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001600260000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200185815250909190915060008201518160000190805190602001906101c49291906102a4565b5060208201518160010160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060408201518160020160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550606082015181600301555050505b50565b600060026001015490505b90565b81548183558181151161029f5760040281600402836000526020600020918201910161029e9190610324565b5b505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106102e557805160ff1916838001178555610313565b82800160010185558215610313579182015b828111156103125782518255916020019190600101906102f7565b5b50905061032091906103aa565b5090565b6103a791905b808211156103a357600060008201600061034491906103cf565b6001820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556002820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff021916905560038201600090555060040161032a565b5090565b90565b6103cc91905b808211156103c85760008160009055506001016103b0565b5090565b90565b50805460018160011615610100020316600290046000825580601f106103f55750610414565b601f01602090049060005260206000209081019061041391906103aa565b5b505600a165627a7a72305820d453cb481a312519166e409e7248d76d8c2672458c08b9500945a4004a1b69020029";
String partOfBytecodeBin = "test" + bytecodeBin;
QueryByBinParam param = new QueryByBinParam();
param.setGroupId(2);
param.setPartOfBytecodeBin(partOfBytecodeBin);
ResultActions resultActions = mockMvc
.perform(MockMvcRequestBuilders.post("/contract/findByPartOfBytecodeBin").
content(JsonTools.toJSONString(param)).
contentType(MediaType.APPLICATION_JSON_UTF8)
);
resultActions.
andExpect(MockMvcResultMatchers.status().isOk()).
andDo(MockMvcResultHandlers.print());
System.out
.println("response:" + resultActions.andReturn().getResponse().getContentAsString());
}
@Test
@WithMockUser(username = "1050106266",
password = "123456",
authorities = "ROLE_ADMIN")
public void testGetExamList() throws Exception {
Map<String, Object> reqVo = new HashMap<>();
reqVo.put("examType", 1);
System.out.println(objectMapper.writeValueAsString(reqVo));
mockMvc.perform(MockMvcRequestBuilders.post("/json/exam/getExamList")
.session(session)
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(reqVo))
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultHandlers.print())
.andExpect(MockMvcResultMatchers.status().isOk());
}
/**
* 推送配置
*
* @throws Exception
*/
@Test
public void test_gray_config_4_push() throws Exception {
PushServiceConfigRequestBody body = new PushServiceConfigRequestBody();
body.setId("3780959622257442816");
List<String> regionIds = new ArrayList<>();
regionIds.add("3777763353183649792");
body.setRegionIds(regionIds);
String result = this.mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/grayConfig/push")
.content(JSON.toJSONString(body))
.contentType(MediaType.APPLICATION_JSON)
.session((MockHttpSession) Utils.getLoginSession(this.mockMvc))
.accept(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andDo(MockMvcResultHandlers.print())
.andReturn().getResponse().getContentAsString();
Utils.assertResult(result);
}
/**
* 批量推送配置
*
* @throws Exception
*/
@Test
public void test_gray_config_5_batchPush() throws Exception {
BatchPushServiceConfigRequestBody body = new BatchPushServiceConfigRequestBody();
List<String> ids = new ArrayList<>();
ids.add("3780718589976248320");
ids.add("3780718590009802752");
ids.add("3780718590009802753");
body.setIds(ids);
List<String> regionIds = new ArrayList<>();
regionIds.add("3777763353183649792");
body.setRegionIds(regionIds);
String result = this.mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/grayConfig/batchPush")
.content(JSON.toJSONString(body))
.contentType(MediaType.APPLICATION_JSON)
.session((MockHttpSession) Utils.getLoginSession(this.mockMvc))
.accept(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andDo(MockMvcResultHandlers.print())
.andReturn().getResponse().getContentAsString();
Utils.assertResult(result);
}
/**
* 新增用户
*
* @throws Exception
*/
@Test
public void test_user_3_add() throws Exception {
AddUserRequestBody body = new AddUserRequestBody();
body.setAccount("sctang");
body.setEmail("[email protected]");
body.setPhone("13739263609");
body.setUserName("sctang");
String result = this.mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/user/add")
.content(JSON.toJSONString(body))
.contentType(MediaType.APPLICATION_JSON)
.session((MockHttpSession) Utils.getLoginSession(this.mockMvc))
.accept(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andDo(MockMvcResultHandlers.print())
.andReturn().getResponse().getContentAsString();
Utils.assertResult(result);
}
/**
* need to create exchange and queue with routing key in mq
* @throws Exception
*/
@Test
public void testRegisterContractEvent() throws Exception {
ReqContractEventRegister param = new ReqContractEventRegister();
param.setGroupId(groupId);
param.setAppId("app1");
param.setExchangeName("group001");
param.setQueueName("user1");
String abiStr = "[{\"constant\":false,\"inputs\":[{\"name\":\"n\",\"type\":\"string\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"name\",\"type\":\"string\"}],\"name\":\"SetName\",\"type\":\"event\"}]";
List<Object> abi = JsonUtils.toJavaObjectList(abiStr, Object.class);
param.setContractAbi(abi);
param.setFromBlock("latest");
param.setToBlock("latest");
param.setContractAddress("0x657201d59ec41d1dc278a67916f751f86ca672f7");
List<String> topics = new ArrayList<>();
topics.add("SetName(string)");
param.setTopicList(topics);
ResultActions resultActions = mockMvc
.perform(MockMvcRequestBuilders.post("/event/contractEvent").
content(JsonUtils.toJSONString(param)).
contentType(MediaType.APPLICATION_JSON)
);
resultActions.
// andExpect(MockMvcResultMatchers.status().isOk()).
andDo(MockMvcResultHandlers.print());
}
@Test
public void update() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.put("/groupdb/update")
.contentType(MediaType.APPLICATION_JSON_UTF8)
.content(requestJson)
.accept(MediaType.APPLICATION_JSON_UTF8))
.andExpect(MockMvcResultMatchers.status().isOk())
.andDo(MockMvcResultHandlers.print());
}
@Test
public void add() throws Exception {
String requestJson = JSONObject.toJSONString(DatabaseSet.builder().id(1L).name("name").build());
mockMvc.perform(MockMvcRequestBuilders.get("/groupdbset/add")
.contentType(MediaType.APPLICATION_JSON_UTF8)
.content(requestJson)
.accept(MediaType.APPLICATION_JSON_UTF8))
.andExpect(MockMvcResultMatchers.status().isOk())
.andDo(MockMvcResultHandlers.print());
}
@Test
public void testGetNodeIdList() throws Exception {
ResultActions resultActions = mockMvc
.perform(MockMvcRequestBuilders.get("/node/nodeIdList/2"));
resultActions.
andExpect(MockMvcResultMatchers.status().isOk()).
andDo(MockMvcResultHandlers.print());
System.out.println("======================response:"
+resultActions.andReturn().getResponse().getContentAsString());
}
@Test
public void delete() throws Exception {
String requestJson = JSONObject.toJSONString(DatabaseSet.builder().id(1L).name("name").build());
mockMvc.perform(MockMvcRequestBuilders.delete("/groupdbset/delete")
.contentType(MediaType.APPLICATION_JSON_UTF8)
.content(requestJson)
.accept(MediaType.APPLICATION_JSON_UTF8))
.andExpect(MockMvcResultMatchers.status().isOk())
.andDo(MockMvcResultHandlers.print());
}
@Test
public void list() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get("/groupdbSetEntry//{dbsetId}/list", 1)
.contentType(MediaType.APPLICATION_JSON_UTF8)
.accept(MediaType.APPLICATION_JSON_UTF8))
.andExpect(MockMvcResultMatchers.status().isOk())
.andDo(MockMvcResultHandlers.print());
}
@Test
public void list() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get("/groupdbset/list")
.contentType(MediaType.APPLICATION_JSON_UTF8)
.param("projectId", "1")
.accept(MediaType.APPLICATION_JSON_UTF8))
.andExpect(MockMvcResultMatchers.status().isOk())
.andDo(MockMvcResultHandlers.print());
}
@Test
public void add() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.post("/group/add")
.contentType(MediaType.APPLICATION_JSON_UTF8)
.content(requestJson)
.accept(MediaType.APPLICATION_JSON_UTF8))
.andExpect(MockMvcResultMatchers.status().isOk())
.andDo(MockMvcResultHandlers.print());
}
@Test
public void update() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.put("/selectEntity/update")
.contentType(MediaType.APPLICATION_JSON_UTF8)
.content(requestJson)
.accept(MediaType.APPLICATION_JSON_UTF8))
.andExpect(MockMvcResultMatchers.status().isOk())
.andDo(MockMvcResultHandlers.print());
}
@Test
public void add() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.post("/tableEntity/add")
.contentType(MediaType.APPLICATION_JSON_UTF8)
.content(requestJson)
.accept(MediaType.APPLICATION_JSON_UTF8))
.andExpect(MockMvcResultMatchers.status().isOk())
.andDo(MockMvcResultHandlers.print());
}
@Test
public void update() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.put("/project/update")
.contentType(MediaType.APPLICATION_JSON_UTF8)
.content(requestJson)
.accept(MediaType.APPLICATION_JSON_UTF8))
.andExpect(MockMvcResultMatchers.status().isOk())
.andDo(MockMvcResultHandlers.print());
}
@Test
public void getProjectsByAppGroupId() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get("/project/projectsByAppGroupId")
.contentType(MediaType.APPLICATION_JSON_UTF8)
.param("appGroupId","1")
.accept(MediaType.APPLICATION_JSON_UTF8))
.andExpect(MockMvcResultMatchers.status().isOk())
.andDo(MockMvcResultHandlers.print());
}
@Test
public void testGetAbiById() throws Exception {
Integer abiId = 1;
// post action
String url = String.format("/abi/%1s", abiId);
ResultActions resultActions = mockMvc.perform(
MockMvcRequestBuilders.get(url)
.contentType(MediaType.APPLICATION_JSON_UTF8)
);
resultActions.
andExpect(MockMvcResultMatchers.status().isOk()).
andDo(MockMvcResultHandlers.print());
System.out
.println("response:" + resultActions.andReturn().getResponse().getContentAsString());
}
@Test
public void sync() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.post("/groupdbset/sync")
.contentType(MediaType.APPLICATION_JSON_UTF8)
.param("id", "1")
.accept(MediaType.APPLICATION_JSON_UTF8))
.andExpect(MockMvcResultMatchers.status().isOk())
.andDo(MockMvcResultHandlers.print());
}
@Test
public void delete() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.delete("/group/delete")
.contentType(MediaType.APPLICATION_JSON_UTF8)
.content(requestJson)
.accept(MediaType.APPLICATION_JSON_UTF8))
.andExpect(MockMvcResultMatchers.status().isOk())
.andDo(MockMvcResultHandlers.print());
}
@Test
public void connectionTest() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.post("/setupDb/connectionTest")
.contentType(MediaType.APPLICATION_JSON_UTF8)
.content(requestJson)
.accept(MediaType.APPLICATION_JSON_UTF8))
.andExpect(MockMvcResultMatchers.status().isOk())
.andDo(MockMvcResultHandlers.print());
}
@Test
public void testUserList() throws Exception {
ResultActions resultActions = mockMvc
.perform(MockMvcRequestBuilders.get("/monitor/userList/1"));
resultActions.
andExpect(MockMvcResultMatchers.status().isOk()).
andDo(MockMvcResultHandlers.print());
System.out.println(
"======================response:" + resultActions.andReturn().getResponse()
.getContentAsString());
}
/**
* 查询项目成员列表
*
* @throws Exception
*/
@Test
public void test_project_8_member_list() throws Exception {
String result = this.mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/project/member/list")
.param("id", "3688919024172793856")
.contentType(MediaType.APPLICATION_JSON)
.session((MockHttpSession) Utils.getLoginSession(this.mockMvc))
.accept(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andDo(MockMvcResultHandlers.print())
.andReturn().getResponse().getContentAsString();
Utils.assertResult(result);
}