diff --git a/spring-rest/src/main/java/org/baeldung/config/Application.java b/spring-rest/src/main/java/org/baeldung/config/Application.java index f7b74659c8..077213b04d 100644 --- a/spring-rest/src/main/java/org/baeldung/config/Application.java +++ b/spring-rest/src/main/java/org/baeldung/config/Application.java @@ -2,9 +2,7 @@ package org.baeldung.config; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; -import org.springframework.web.filter.ShallowEtagHeaderFilter; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; @EnableAutoConfiguration @@ -15,8 +13,4 @@ public class Application extends WebMvcConfigurerAdapter { SpringApplication.run(Application.class, args); } - @Bean - public ShallowEtagHeaderFilter shallowEtagHeaderFilter() { - return new ShallowEtagHeaderFilter(); - } } \ No newline at end of file diff --git a/spring-rest/src/main/java/org/baeldung/config/WebConfig.java b/spring-rest/src/main/java/org/baeldung/config/WebConfig.java index 1516e9915c..39c1252c4f 100644 --- a/spring-rest/src/main/java/org/baeldung/config/WebConfig.java +++ b/spring-rest/src/main/java/org/baeldung/config/WebConfig.java @@ -36,7 +36,7 @@ public class WebConfig extends WebMvcConfigurerAdapter { messageConverters.add(new MappingJackson2HttpMessageConverter(builder.build())); // messageConverters.add(new MappingJackson2XmlHttpMessageConverter(builder.createXmlMapper(true).build())); - messageConverters.add(createXmlHttpMessageConverter()); + // messageConverters.add(createXmlHttpMessageConverter()); // messageConverters.add(new MappingJackson2HttpMessageConverter()); messageConverters.add(new ProtobufHttpMessageConverter()); diff --git a/spring-rest/src/main/java/org/baeldung/web/controller/FooController.java b/spring-rest/src/main/java/org/baeldung/web/controller/FooController.java index dd1e3ca222..21ba3c6d13 100644 --- a/spring-rest/src/main/java/org/baeldung/web/controller/FooController.java +++ b/spring-rest/src/main/java/org/baeldung/web/controller/FooController.java @@ -1,7 +1,6 @@ package org.baeldung.web.controller; import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; -import static org.apache.commons.lang3.RandomStringUtils.randomNumeric; import org.baeldung.web.dto.Foo; import org.baeldung.web.dto.FooProtos; @@ -26,7 +25,7 @@ public class FooController { @RequestMapping(method = RequestMethod.GET, value = "/foos/{id}") @ResponseBody public Foo findById(@PathVariable final long id) { - return new Foo(Long.parseLong(randomNumeric(2)), randomAlphabetic(4)); + return new Foo(id, randomAlphabetic(4)); } // API - write diff --git a/spring-rest/src/test/java/org/baeldung/client/RestTemplateBasicLiveTest.java b/spring-rest/src/test/java/org/baeldung/client/RestTemplateBasicLiveTest.java index 9e968b94f3..e4321e163f 100644 --- a/spring-rest/src/test/java/org/baeldung/client/RestTemplateBasicLiveTest.java +++ b/spring-rest/src/test/java/org/baeldung/client/RestTemplateBasicLiveTest.java @@ -2,10 +2,14 @@ package org.baeldung.client; import static org.baeldung.client.Consts.APPLICATION_PORT; import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.Matchers.notNull; import java.io.IOException; +import org.baeldung.web.dto.Foo; import org.junit.Before; import org.junit.Test; import org.springframework.http.HttpStatus; @@ -41,7 +45,15 @@ public class RestTemplateBasicLiveTest { ObjectMapper mapper = new ObjectMapper(); JsonNode root = mapper.readTree(response.getBody()); JsonNode name = root.path("name"); - assertThat(name.asText(), equalTo("bar")); + assertThat(name.asText(), is(notNull())); } - + + @Test + public void givenResourceUrl_whenRetrievingResource_thenCorrect() throws IOException { + final Foo foo = restTemplate.getForObject(fooResourceUrl + "/1", Foo.class); + + assertThat(foo.getName(), notNullValue()); + assertThat(foo.getId(), is(1L)); + } + }