quick fix

This commit is contained in:
Azhwani 2021-01-17 02:27:34 +01:00
parent 100e3b652d
commit 8396dabf77
2 changed files with 1 additions and 11 deletions

View File

@ -23,11 +23,8 @@ public class ProductApi {
@GetMapping("/get")
public Product get(@RequestParam String criterion) throws JsonMappingException, JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper();
Criterion crt;
crt = objectMapper.readValue(criterion, Criterion.class);
Criterion crt = objectMapper.readValue(criterion, Criterion.class);
if (crt.getProp().equals("name"))
return findByName(crt.getValue());
@ -46,5 +43,4 @@ public class ProductApi {
}
// Other methods
}

View File

@ -21,26 +21,21 @@ public class RestTemplateExceptionLiveTest {
@Test(expected = IllegalArgumentException.class)
public void givenGetUrl_whenJsonIsPassed_thenThrowException() {
String url = "http://localhost:8080/spring-rest/api/get?criterion={\"prop\":\"name\",\"value\":\"ASUS VivoBook\"}";
Product product = restTemplate.getForObject(url, Product.class);
}
@Test
public void givenGetUrl_whenJsonIsPassed_thenGetProduct() {
String criterion = "{\"prop\":\"name\",\"value\":\"ASUS VivoBook\"}";
String url = "http://localhost:8080/spring-rest/api/get?criterion={criterion}";
Product product = restTemplate.getForObject(url, Product.class, criterion);
assertEquals(product.getPrice(), 650, 0);
}
@Test
public void givenGetUrl_whenJsonIsPassed_thenReturnProduct() {
String criterion = "{\"prop\":\"name\",\"value\":\"Acer Aspire 5\"}";
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);
assertEquals(product.getId(), 1, 0);
}
}