如何在signe测试用例中为不同的url多次模拟res模板

k97glaaz  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(182)
String urlFetchCustomers="http://localhost:8080/fetch/customers";

String urlFetchPlaces="http://localhost:8080/fetch/places";

JsonNode customerJSON = mapper.readTree("{"result":["User1","User2","User3"],"message":"Fetched customers successfully.","status":200}");

JsonNode placeJSON = mapper.readTree("{"result":["Place1","Place2","Place3"],"message":"Fetched customers successfully.","status":200}");

ResponseEntity<JsonNode> customerResponse = new ResponseEntity<JsonNode>(customerJSON, HttpStatus.OK);

ResponseEntity<JsonNode> placeResponse = new ResponseEntity<JsonNode>(placeJSON, HttpStatus.OK);

when(restTemplate.exchange(urlFetchCustomers, 
                       Matchers.any(HttpMethod.class),
                       Matchers.<HttpEntity<?>> any(), 
                       Matchers.<Class<String>> any()
                      )
                     ).thenReturn(customerResponse);

when(restTemplate.exchange(urlFetchPlaces, 
                       Matchers.any(HttpMethod.class),
                       Matchers.<HttpEntity<?>> any(), 
                       Matchers.<Class<String>> any()
                      )
                     ).thenReturn(placeResponse);

我想对不同的url使用不同的exchange调用并返回相应的响应。但这会引发以下错误。。有人能帮忙吗?在此处输入图像描述

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题