quick fix
This commit is contained in:
parent
100e3b652d
commit
8396dabf77
|
@ -23,11 +23,8 @@ public class ProductApi {
|
||||||
|
|
||||||
@GetMapping("/get")
|
@GetMapping("/get")
|
||||||
public Product get(@RequestParam String criterion) throws JsonMappingException, JsonProcessingException {
|
public Product get(@RequestParam String criterion) throws JsonMappingException, JsonProcessingException {
|
||||||
|
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
Criterion crt;
|
Criterion crt = objectMapper.readValue(criterion, Criterion.class);
|
||||||
|
|
||||||
crt = objectMapper.readValue(criterion, Criterion.class);
|
|
||||||
if (crt.getProp().equals("name"))
|
if (crt.getProp().equals("name"))
|
||||||
return findByName(crt.getValue());
|
return findByName(crt.getValue());
|
||||||
|
|
||||||
|
@ -46,5 +43,4 @@ public class ProductApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Other methods
|
// Other methods
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,26 +21,21 @@ public class RestTemplateExceptionLiveTest {
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void givenGetUrl_whenJsonIsPassed_thenThrowException() {
|
public void givenGetUrl_whenJsonIsPassed_thenThrowException() {
|
||||||
|
|
||||||
String url = "http://localhost:8080/spring-rest/api/get?criterion={\"prop\":\"name\",\"value\":\"ASUS VivoBook\"}";
|
String url = "http://localhost:8080/spring-rest/api/get?criterion={\"prop\":\"name\",\"value\":\"ASUS VivoBook\"}";
|
||||||
Product product = restTemplate.getForObject(url, Product.class);
|
Product product = restTemplate.getForObject(url, Product.class);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenGetUrl_whenJsonIsPassed_thenGetProduct() {
|
public void givenGetUrl_whenJsonIsPassed_thenGetProduct() {
|
||||||
|
|
||||||
String criterion = "{\"prop\":\"name\",\"value\":\"ASUS VivoBook\"}";
|
String criterion = "{\"prop\":\"name\",\"value\":\"ASUS VivoBook\"}";
|
||||||
String url = "http://localhost:8080/spring-rest/api/get?criterion={criterion}";
|
String url = "http://localhost:8080/spring-rest/api/get?criterion={criterion}";
|
||||||
Product product = restTemplate.getForObject(url, Product.class, criterion);
|
Product product = restTemplate.getForObject(url, Product.class, criterion);
|
||||||
|
|
||||||
assertEquals(product.getPrice(), 650, 0);
|
assertEquals(product.getPrice(), 650, 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenGetUrl_whenJsonIsPassed_thenReturnProduct() {
|
public void givenGetUrl_whenJsonIsPassed_thenReturnProduct() {
|
||||||
|
|
||||||
String criterion = "{\"prop\":\"name\",\"value\":\"Acer Aspire 5\"}";
|
String criterion = "{\"prop\":\"name\",\"value\":\"Acer Aspire 5\"}";
|
||||||
String url = "http://localhost:8080/spring-rest/api/get";
|
String url = "http://localhost:8080/spring-rest/api/get";
|
||||||
|
|
||||||
|
@ -48,6 +43,5 @@ public class RestTemplateExceptionLiveTest {
|
||||||
Product product = restTemplate.getForObject(builder.build().toUri(), Product.class);
|
Product product = restTemplate.getForObject(builder.build().toUri(), Product.class);
|
||||||
|
|
||||||
assertEquals(product.getId(), 1, 0);
|
assertEquals(product.getId(), 1, 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue