我有一个Orchestrator Spring Boot服务,该服务对外部服务发出几个异步的REST请求,我想模拟那些服务的响应。
我的代码是:
mockServer.expect(requestTo("http://localhost/retrieveBook/book1"))
.andExpect(method(HttpMethod.GET))
.andRespond(MockRestResponseCreators.withStatus(HttpStatus.OK)
.body("{\"book\":{\"title\":\"xxx\",\"year\":\"2000\"}}")
.contentType(MediaType.APPLICATION_JSON));
mockServer.expect(requestTo("http://localhost/retrieveFilm/film1"))
.andExpect(method(HttpMethod.GET))
.andRespond(MockRestResponseCreators.withStatus(HttpStatus.OK)
.body("{\"film\":{\"title\":\"yyy\",\"year\":\"1900\"}}")
.contentType(MediaType.APPLICATION_JSON));
service.retrieveBookAndFilm(book1,film1);
mockServer.verify();
Run Code Online (Sandbox Code Playgroud)
resolveBookAndFilm服务调用两种异步方法,一种方法是检索书本,另一种方法是检索电影,问题在于有时会先执行电影服务,但会出现错误:
java.util.concurrent.ExecutionException:java.lang.AssertionError:请求URI预期:HTTP://本地主机/ retrieveBook / BOOK1却被:HTTP://本地主机/ retrieveFilm / FILM1
任何想法我怎么解决这个问题,有什么类似mockito的说法,当执行此URL然后返回this或那个?
感谢和问候
我试图通过角度将JSON结构发送到REST服务
let test5var = {
"test5var1": {
"test5var2": "0317",
"test5var3": "9556"
},
"test5var4": "123",
"test5var": "0000046"
}
let dataPrincipalBlnc = {"test": {"test1": {"test2": "0317","test3": {"IDIOMA_ISO": " en","DIALECTO_ISO": "US"},"channel": "INT"},"input": {"test5": test5var}}};
let headers = new HttpHeaders();
headers.append('Content-Type', 'application/json');
let params = new HttpParams().set("requestData", dataPrincipalBlnc.toString()).set("authenticationType", this.authType);
return this.http.get(this.url, {params: params});
Run Code Online (Sandbox Code Playgroud)
请求的结果应如下所示:
但当前发送为:
https://example.com/test?requestData=%5Bobject%20Object%5D&authenticationType=cookie
有什么想法可以将json对象发送为第一个请求吗?我需要手动将json转换为有效的uri格式吗?
在angularJS中,仅使用以下代码即可正常工作:
var data = {
"test1": {
"test2": {
"test3": "0317",
"test4": {
"IDIOMA_ISO": " en",
"DIALECTO_ISO": "US"
},
"channel": "INT" …Run Code Online (Sandbox Code Playgroud)