My task is to implement integration tags that should use a remote quiet service . The fact is that we do not want any test data to be placed in a real recreation service.
In the general case, we have:
The controller responsible for saving and loading data from RESTful:
@RequestMapping(value="/user/save", method = RequestMethod.POST)
saveUserData(@RequestParam String data, @RequestParam String user){
restfulClient.save(user, data);
}
@RequestMapping(value="/user/load", method = RequestMethod.POST)
loadUserData(@RequestParam String data , @RequestParam String user){
return restfulClient.load(user, data);
}
RestfulClient only does put and receives requests to the remote recovery service to save and load user data.
2 Cucumber scenario:
When user User is saving data some_data
Then user User sees saved data is some_data
3 Cucumber Test:
@When("^user (.+) is saving data (.+)$")
public void whenSave(String userName, String data) throws Exception {
MockHttpServletRequestBuilder req = post("/user/save").contentType(APPLICATION_JSON_UTF8).content(data);
callUrl = getMockMvc().perform(req.session(userName));
}
@Then("^user (.+) sees saved data is (.+)$")
public void thenResponseAndDataAreCorrect(String userName, String data) throws Exception {
MockHttpServletRequestBuilder req = get("/user/load").content(data);
callUrl = getMockMvc().perform(req.session(req.session(userName));
callUrl.andExpect(status().isOk());
callUrl.andExpect(jsonPath("$.Records[*].data", hasItems(userName)));
}
Tests can be run simultaneously in different threads, so user_id may be different for each test. In this case, we need the ability to write and read data for each identifier.
http:
- , , .