From 30171ef89bcd5e0e919263fcb66ffa9c9960cbea Mon Sep 17 00:00:00 2001 From: eugenp Date: Fri, 18 Nov 2016 14:01:31 +0200 Subject: [PATCH] upgrades --- spring-rest/pom.xml | 80 ++++++++++++++----- .../java/org/baeldung/config/Application.java | 22 +++++ .../java/org/baeldung/config/WebConfig.java | 9 +-- .../src/main/resources/application.properties | 2 + .../test/java/org/baeldung/client/Consts.java | 5 ++ .../client/RestTemplateBasicLiveTest.java | 21 ++++- ...=> RedirectControllerIntegrationTest.java} | 16 ++-- ... => ExampleControllerIntegrationTest.java} | 2 +- 8 files changed, 121 insertions(+), 36 deletions(-) create mode 100644 spring-rest/src/main/java/org/baeldung/config/Application.java create mode 100644 spring-rest/src/main/resources/application.properties create mode 100644 spring-rest/src/test/java/org/baeldung/client/Consts.java rename {spring-security-rest-full => spring-rest}/src/test/java/org/baeldung/client/RestTemplateBasicLiveTest.java (51%) rename spring-rest/src/test/java/org/baeldung/web/controller/redirect/{RedirectControllerTest.java => RedirectControllerIntegrationTest.java} (78%) rename spring-rest/src/test/java/org/baeldung/web/controller/status/{ExampleControllerTest.java => ExampleControllerIntegrationTest.java} (96%) diff --git a/spring-rest/pom.xml b/spring-rest/pom.xml index 6580f5ecc7..3c23f1bca7 100644 --- a/spring-rest/pom.xml +++ b/spring-rest/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 com.baeldung spring-rest @@ -9,7 +10,7 @@ org.springframework.boot spring-boot-starter-parent - 1.3.5.RELEASE + 1.4.2.RELEASE @@ -24,6 +25,10 @@ org.springframework.boot spring-boot-starter-actuator + + org.springframework.boot + spring-boot-devtools + @@ -49,7 +54,7 @@ commons-fileupload commons-fileupload - 1.3.1 + 1.3.2 @@ -73,9 +78,9 @@ - com.fasterxml.jackson.dataformat - jackson-dataformat-xml - + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + com.thoughtworks.xstream @@ -94,7 +99,7 @@ org.apache.commons commons-lang3 - 3.2.1 + 3.5 @@ -157,16 +162,21 @@ - com.jayway.restassured - rest-assured - ${rest-assured.version} - + com.jayway.restassured + rest-assured + ${rest-assured.version} + - + com.google.protobuf protobuf-java - 2.6.1 + 3.1.0 + + + com.googlecode.protobuf-java-format + protobuf-java-format + 1.4 @@ -206,7 +216,8 @@ maven-surefire-plugin - **/*LiveTest.java + **/*IntegrationTest.java + **/*LiveTest.java @@ -240,6 +251,36 @@ + + + integration + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + none + + + **/*IntegrationTest.java + + + + + + + + + + live @@ -292,6 +333,7 @@ + @@ -299,13 +341,13 @@ 4.3.11.Final - 5.1.39 + 5.1.40 5.2.2.Final - 19.0 + 20.0 3.4 @@ -323,7 +365,7 @@ 1.1.3 - 3.5.1 + 3.6.0 2.6 2.19.1 1.6.0 @@ -332,7 +374,8 @@ 3.4.1 - + + org.codehaus.mojo @@ -345,4 +388,5 @@ + diff --git a/spring-rest/src/main/java/org/baeldung/config/Application.java b/spring-rest/src/main/java/org/baeldung/config/Application.java new file mode 100644 index 0000000000..f7b74659c8 --- /dev/null +++ b/spring-rest/src/main/java/org/baeldung/config/Application.java @@ -0,0 +1,22 @@ +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 +@ComponentScan("org.baeldung") +public class Application extends WebMvcConfigurerAdapter { + + public static void main(final String[] args) { + 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 d116148f09..1516e9915c 100644 --- a/spring-rest/src/main/java/org/baeldung/config/WebConfig.java +++ b/spring-rest/src/main/java/org/baeldung/config/WebConfig.java @@ -17,9 +17,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter /* * Please note that main web configuration is in src/main/webapp/WEB-INF/api-servlet.xml - * */ - @Configuration @EnableWebMvc @ComponentScan({ "org.baeldung.web" }) @@ -33,13 +31,14 @@ public class WebConfig extends WebMvcConfigurerAdapter { @Override public void configureMessageConverters(final List> messageConverters) { - messageConverters.add(createXmlHttpMessageConverter()); - // messageConverters.add(new MappingJackson2HttpMessageConverter()); - final Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder(); builder.indentOutput(true).dateFormat(new SimpleDateFormat("dd-MM-yyyy hh:mm")); messageConverters.add(new MappingJackson2HttpMessageConverter(builder.build())); // messageConverters.add(new MappingJackson2XmlHttpMessageConverter(builder.createXmlMapper(true).build())); + + messageConverters.add(createXmlHttpMessageConverter()); + // messageConverters.add(new MappingJackson2HttpMessageConverter()); + messageConverters.add(new ProtobufHttpMessageConverter()); messageConverters.add(new KryoHttpMessageConverter()); super.configureMessageConverters(messageConverters); diff --git a/spring-rest/src/main/resources/application.properties b/spring-rest/src/main/resources/application.properties new file mode 100644 index 0000000000..300589f561 --- /dev/null +++ b/spring-rest/src/main/resources/application.properties @@ -0,0 +1,2 @@ +server.port= 8082 +server.context-path=/spring-rest \ No newline at end of file diff --git a/spring-rest/src/test/java/org/baeldung/client/Consts.java b/spring-rest/src/test/java/org/baeldung/client/Consts.java new file mode 100644 index 0000000000..b40561d9c3 --- /dev/null +++ b/spring-rest/src/test/java/org/baeldung/client/Consts.java @@ -0,0 +1,5 @@ +package org.baeldung.client; + +public interface Consts { + int APPLICATION_PORT = 8082; +} diff --git a/spring-security-rest-full/src/test/java/org/baeldung/client/RestTemplateBasicLiveTest.java b/spring-rest/src/test/java/org/baeldung/client/RestTemplateBasicLiveTest.java similarity index 51% rename from spring-security-rest-full/src/test/java/org/baeldung/client/RestTemplateBasicLiveTest.java rename to spring-rest/src/test/java/org/baeldung/client/RestTemplateBasicLiveTest.java index 3516e5161d..9e968b94f3 100644 --- a/spring-security-rest-full/src/test/java/org/baeldung/client/RestTemplateBasicLiveTest.java +++ b/spring-rest/src/test/java/org/baeldung/client/RestTemplateBasicLiveTest.java @@ -1,6 +1,6 @@ package org.baeldung.client; -import static org.baeldung.Consts.APPLICATION_PORT; +import static org.baeldung.client.Consts.APPLICATION_PORT; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; @@ -12,10 +12,13 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestTemplate; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + public class RestTemplateBasicLiveTest { private RestTemplate restTemplate; - private static final String fooResourceUrl = "http://localhost:" + APPLICATION_PORT + "/spring-security-rest-full/auth/foos"; + private static final String fooResourceUrl = "http://localhost:" + APPLICATION_PORT + "/spring-rest/foos"; @Before public void beforeTest() { @@ -26,9 +29,19 @@ public class RestTemplateBasicLiveTest { @Test public void givenResourceUrl_whenSendGetForRequestEntity_thenStatusOk() throws IOException { - final ResponseEntity response = restTemplate.getForEntity(fooResourceUrl, String.class); - + ResponseEntity response = restTemplate.getForEntity(fooResourceUrl + "/1", String.class); + assertThat(response.getStatusCode(), equalTo(HttpStatus.OK)); } + + @Test + public void givenResourceUrl_whenSendGetForRequestEntity_thenBodyCorrect() throws IOException { + ResponseEntity response = restTemplate.getForEntity(fooResourceUrl + "/1", String.class); + + ObjectMapper mapper = new ObjectMapper(); + JsonNode root = mapper.readTree(response.getBody()); + JsonNode name = root.path("name"); + assertThat(name.asText(), equalTo("bar")); + } } diff --git a/spring-rest/src/test/java/org/baeldung/web/controller/redirect/RedirectControllerTest.java b/spring-rest/src/test/java/org/baeldung/web/controller/redirect/RedirectControllerIntegrationTest.java similarity index 78% rename from spring-rest/src/test/java/org/baeldung/web/controller/redirect/RedirectControllerTest.java rename to spring-rest/src/test/java/org/baeldung/web/controller/redirect/RedirectControllerIntegrationTest.java index cafaff7b07..b31bfcf5ec 100644 --- a/spring-rest/src/test/java/org/baeldung/web/controller/redirect/RedirectControllerTest.java +++ b/spring-rest/src/test/java/org/baeldung/web/controller/redirect/RedirectControllerIntegrationTest.java @@ -1,6 +1,6 @@ package org.baeldung.web.controller.redirect; -import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.nullValue; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.flash; @@ -24,7 +24,7 @@ import org.springframework.web.context.WebApplicationContext; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("file:src/main/webapp/WEB-INF/api-servlet.xml") @WebAppConfiguration -public class RedirectControllerTest { +public class RedirectControllerIntegrationTest { private MockMvc mockMvc; @@ -38,30 +38,30 @@ public class RedirectControllerTest { @Test public void whenRedirectOnUrlWithUsingXMLConfig_thenStatusRedirectionAndRedirectedOnUrl() throws Exception { - mockMvc.perform(get("/redirectWithXMLConfig")).andExpect(status().is3xxRedirection()).andExpect(view().name("RedirectedUrl")).andExpect(model().attribute("attribute", is("redirectWithXMLConfig"))) + mockMvc.perform(get("/redirectWithXMLConfig")).andExpect(status().is3xxRedirection()).andExpect(view().name("RedirectedUrl")).andExpect(model().attribute("attribute", equalTo("redirectWithXMLConfig"))) .andExpect(redirectedUrl("redirectedUrl?attribute=redirectWithXMLConfig")); } @Test public void whenRedirectOnUrlWithUsingRedirectPrefix_thenStatusRedirectionAndRedirectedOnUrl() throws Exception { - mockMvc.perform(get("/redirectWithRedirectPrefix")).andExpect(status().is3xxRedirection()).andExpect(view().name("redirect:/redirectedUrl")).andExpect(model().attribute("attribute", is("redirectWithRedirectPrefix"))) + mockMvc.perform(get("/redirectWithRedirectPrefix")).andExpect(status().is3xxRedirection()).andExpect(view().name("redirect:/redirectedUrl")).andExpect(model().attribute("attribute", equalTo("redirectWithRedirectPrefix"))) .andExpect(redirectedUrl("/redirectedUrl?attribute=redirectWithRedirectPrefix")); } @Test public void whenRedirectOnUrlWithUsingRedirectAttributes_thenStatusRedirectionAndRedirectedOnUrlAndAddedAttributeToFlashScope() throws Exception { - mockMvc.perform(get("/redirectWithRedirectAttributes")).andExpect(status().is3xxRedirection()).andExpect(flash().attribute("flashAttribute", is("redirectWithRedirectAttributes"))) - .andExpect(model().attribute("attribute", is("redirectWithRedirectAttributes"))).andExpect(model().attribute("flashAttribute", is(nullValue()))).andExpect(redirectedUrl("redirectedUrl?attribute=redirectWithRedirectAttributes")); + mockMvc.perform(get("/redirectWithRedirectAttributes")).andExpect(status().is3xxRedirection()).andExpect(flash().attribute("flashAttribute", equalTo("redirectWithRedirectAttributes"))) + .andExpect(model().attribute("attribute", equalTo("redirectWithRedirectAttributes"))).andExpect(model().attribute("flashAttribute", equalTo(nullValue()))).andExpect(redirectedUrl("redirectedUrl?attribute=redirectWithRedirectAttributes")); } @Test public void whenRedirectOnUrlWithUsingRedirectView_thenStatusRedirectionAndRedirectedOnUrlAndAddedAttributeToFlashScope() throws Exception { - mockMvc.perform(get("/redirectWithRedirectView")).andExpect(status().is3xxRedirection()).andExpect(model().attribute("attribute", is("redirectWithRedirectView"))).andExpect(redirectedUrl("redirectedUrl?attribute=redirectWithRedirectView")); + mockMvc.perform(get("/redirectWithRedirectView")).andExpect(status().is3xxRedirection()).andExpect(model().attribute("attribute", equalTo("redirectWithRedirectView"))).andExpect(redirectedUrl("redirectedUrl?attribute=redirectWithRedirectView")); } @Test public void whenRedirectOnUrlWithUsingForwardPrefix_thenStatusOkAndForwardedOnUrl() throws Exception { - mockMvc.perform(get("/forwardWithForwardPrefix")).andExpect(status().isOk()).andExpect(view().name("forward:/redirectedUrl")).andExpect(model().attribute("attribute", is("redirectWithForwardPrefix"))).andExpect(forwardedUrl("/redirectedUrl")); + mockMvc.perform(get("/forwardWithForwardPrefix")).andExpect(status().isOk()).andExpect(view().name("forward:/redirectedUrl")).andExpect(model().attribute("attribute", equalTo("redirectWithForwardPrefix"))).andExpect(forwardedUrl("/redirectedUrl")); } } diff --git a/spring-rest/src/test/java/org/baeldung/web/controller/status/ExampleControllerTest.java b/spring-rest/src/test/java/org/baeldung/web/controller/status/ExampleControllerIntegrationTest.java similarity index 96% rename from spring-rest/src/test/java/org/baeldung/web/controller/status/ExampleControllerTest.java rename to spring-rest/src/test/java/org/baeldung/web/controller/status/ExampleControllerIntegrationTest.java index c50e1b4f43..e29bef501e 100644 --- a/spring-rest/src/test/java/org/baeldung/web/controller/status/ExampleControllerTest.java +++ b/spring-rest/src/test/java/org/baeldung/web/controller/status/ExampleControllerIntegrationTest.java @@ -18,7 +18,7 @@ import org.springframework.web.context.WebApplicationContext; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = WebConfig.class) @WebAppConfiguration -public class ExampleControllerTest { +public class ExampleControllerIntegrationTest { private MockMvc mockMvc;