Skip to content

Commit 30171ef

Browse files
author
eugenp
committed
upgrades
1 parent 42946dd commit 30171ef

8 files changed

Lines changed: 121 additions & 36 deletions

File tree

‎spring-rest/pom.xml‎

Lines changed: 62 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
23
<modelVersion>4.0.0</modelVersion>
34
<groupId>com.baeldung</groupId>
45
<artifactId>spring-rest</artifactId>
@@ -9,7 +10,7 @@
910
<parent>
1011
<groupId>org.springframework.boot</groupId>
1112
<artifactId>spring-boot-starter-parent</artifactId>
12-
<version>1.3.5.RELEASE</version>
13+
<version>1.4.2.RELEASE</version>
1314
</parent>
1415

1516
<dependencies>
@@ -24,6 +25,10 @@
2425
<groupId>org.springframework.boot</groupId>
2526
<artifactId>spring-boot-starter-actuator</artifactId>
2627
</dependency>
28+
<dependency>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot-devtools</artifactId>
31+
</dependency>
2732

2833
<!-- Spring -->
2934

@@ -49,7 +54,7 @@
4954
<dependency>
5055
<groupId>commons-fileupload</groupId>
5156
<artifactId>commons-fileupload</artifactId>
52-
<version>1.3.1</version>
57+
<version>1.3.2</version>
5358
</dependency>
5459
<!-- web -->
5560

@@ -73,9 +78,9 @@
7378
</dependency>
7479

7580
<dependency>
76-
<groupId>com.fasterxml.jackson.dataformat</groupId>
77-
<artifactId>jackson-dataformat-xml</artifactId>
78-
</dependency>
81+
<groupId>com.fasterxml.jackson.dataformat</groupId>
82+
<artifactId>jackson-dataformat-xml</artifactId>
83+
</dependency>
7984

8085
<dependency>
8186
<groupId>com.thoughtworks.xstream</groupId>
@@ -94,7 +99,7 @@
9499
<dependency>
95100
<groupId>org.apache.commons</groupId>
96101
<artifactId>commons-lang3</artifactId>
97-
<version>3.2.1</version>
102+
<version>3.5</version>
98103
</dependency>
99104

100105
<!-- logging -->
@@ -157,16 +162,21 @@
157162
</dependency>
158163

159164
<dependency>
160-
<groupId>com.jayway.restassured</groupId>
161-
<artifactId>rest-assured</artifactId>
162-
<version>${rest-assured.version}</version>
163-
</dependency>
165+
<groupId>com.jayway.restassured</groupId>
166+
<artifactId>rest-assured</artifactId>
167+
<version>${rest-assured.version}</version>
168+
</dependency>
164169

165-
<!-- -->
170+
<!-- -->
166171
<dependency>
167172
<groupId>com.google.protobuf</groupId>
168173
<artifactId>protobuf-java</artifactId>
169-
<version>2.6.1</version>
174+
<version>3.1.0</version>
175+
</dependency>
176+
<dependency>
177+
<groupId>com.googlecode.protobuf-java-format</groupId>
178+
<artifactId>protobuf-java-format</artifactId>
179+
<version>1.4</version>
170180
</dependency>
171181

172182
<dependency>
@@ -206,7 +216,8 @@
206216
<artifactId>maven-surefire-plugin</artifactId>
207217
<configuration>
208218
<excludes>
209-
<exclude>**/*LiveTest.java</exclude>
219+
<exclude>**/*IntegrationTest.java</exclude>
220+
<exclude>**/*LiveTest.java</exclude>
210221
</excludes>
211222
<systemPropertyVariables>
212223
<!-- <provPersistenceTarget>h2</provPersistenceTarget> -->
@@ -240,6 +251,36 @@
240251
</build>
241252

242253
<profiles>
254+
255+
<profile>
256+
<id>integration</id>
257+
<build>
258+
<plugins>
259+
<plugin>
260+
<groupId>org.apache.maven.plugins</groupId>
261+
<artifactId>maven-surefire-plugin</artifactId>
262+
<executions>
263+
<execution>
264+
<phase>integration-test</phase>
265+
<goals>
266+
<goal>test</goal>
267+
</goals>
268+
<configuration>
269+
<excludes>
270+
<exclude>none</exclude>
271+
</excludes>
272+
<includes>
273+
<include>**/*IntegrationTest.java</include>
274+
</includes>
275+
</configuration>
276+
</execution>
277+
</executions>
278+
</plugin>
279+
280+
</plugins>
281+
</build>
282+
</profile>
283+
243284
<profile>
244285
<id>live</id>
245286
<build>
@@ -292,20 +333,21 @@
292333
</plugins>
293334
</build>
294335
</profile>
336+
295337
</profiles>
296338

297339
<properties>
298340
<!-- Spring -->
299341

300342
<!-- persistence -->
301343
<hibernate.version>4.3.11.Final</hibernate.version>
302-
<mysql-connector-java.version>5.1.39</mysql-connector-java.version>
344+
<mysql-connector-java.version>5.1.40</mysql-connector-java.version>
303345

304346
<!-- various -->
305347
<hibernate-validator.version>5.2.2.Final</hibernate-validator.version>
306348

307349
<!-- util -->
308-
<guava.version>19.0</guava.version>
350+
<guava.version>20.0</guava.version>
309351
<commons-lang3.version>3.4</commons-lang3.version>
310352

311353
<!-- testing -->
@@ -323,7 +365,7 @@
323365
<logback.version>1.1.3</logback.version>
324366

325367
<!-- Maven plugins -->
326-
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
368+
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
327369
<maven-war-plugin.version>2.6</maven-war-plugin.version>
328370
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
329371
<cargo-maven2-plugin.version>1.6.0</cargo-maven2-plugin.version>
@@ -332,7 +374,8 @@
332374
<com.squareup.okhttp3.version>3.4.1</com.squareup.okhttp3.version>
333375

334376
</properties>
335-
<reporting>
377+
378+
<reporting>
336379
<plugins>
337380
<plugin>
338381
<groupId>org.codehaus.mojo</groupId>
@@ -345,4 +388,5 @@
345388
</plugin>
346389
</plugins>
347390
</reporting>
391+
348392
</project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.baeldung.config;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
5+
import org.springframework.context.annotation.Bean;
6+
import org.springframework.context.annotation.ComponentScan;
7+
import org.springframework.web.filter.ShallowEtagHeaderFilter;
8+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
9+
10+
@EnableAutoConfiguration
11+
@ComponentScan("org.baeldung")
12+
public class Application extends WebMvcConfigurerAdapter {
13+
14+
public static void main(final String[] args) {
15+
SpringApplication.run(Application.class, args);
16+
}
17+
18+
@Bean
19+
public ShallowEtagHeaderFilter shallowEtagHeaderFilter() {
20+
return new ShallowEtagHeaderFilter();
21+
}
22+
}

‎spring-rest/src/main/java/org/baeldung/config/WebConfig.java‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717

1818
/*
1919
* Please note that main web configuration is in src/main/webapp/WEB-INF/api-servlet.xml
20-
*
2120
*/
22-
2321
@Configuration
2422
@EnableWebMvc
2523
@ComponentScan({ "org.baeldung.web" })
@@ -33,13 +31,14 @@ public WebConfig() {
3331

3432
@Override
3533
public void configureMessageConverters(final List<HttpMessageConverter<?>> messageConverters) {
36-
messageConverters.add(createXmlHttpMessageConverter());
37-
// messageConverters.add(new MappingJackson2HttpMessageConverter());
38-
3934
final Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
4035
builder.indentOutput(true).dateFormat(new SimpleDateFormat("dd-MM-yyyy hh:mm"));
4136
messageConverters.add(new MappingJackson2HttpMessageConverter(builder.build()));
4237
// messageConverters.add(new MappingJackson2XmlHttpMessageConverter(builder.createXmlMapper(true).build()));
38+
39+
messageConverters.add(createXmlHttpMessageConverter());
40+
// messageConverters.add(new MappingJackson2HttpMessageConverter());
41+
4342
messageConverters.add(new ProtobufHttpMessageConverter());
4443
messageConverters.add(new KryoHttpMessageConverter());
4544
super.configureMessageConverters(messageConverters);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
server.port= 8082
2+
server.context-path=/spring-rest
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.baeldung.client;
2+
3+
public interface Consts {
4+
int APPLICATION_PORT = 8082;
5+
}

spring-security-rest-full/src/test/java/org/baeldung/client/RestTemplateBasicLiveTest.java renamed to spring-rest/src/test/java/org/baeldung/client/RestTemplateBasicLiveTest.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.baeldung.client;
22

3-
import static org.baeldung.Consts.APPLICATION_PORT;
3+
import static org.baeldung.client.Consts.APPLICATION_PORT;
44
import static org.hamcrest.CoreMatchers.equalTo;
55
import static org.hamcrest.MatcherAssert.assertThat;
66

@@ -12,10 +12,13 @@
1212
import org.springframework.http.ResponseEntity;
1313
import org.springframework.web.client.RestTemplate;
1414

15+
import com.fasterxml.jackson.databind.JsonNode;
16+
import com.fasterxml.jackson.databind.ObjectMapper;
17+
1518
public class RestTemplateBasicLiveTest {
1619

1720
private RestTemplate restTemplate;
18-
private static final String fooResourceUrl = "http://localhost:" + APPLICATION_PORT + "/spring-security-rest-full/auth/foos";
21+
private static final String fooResourceUrl = "http://localhost:" + APPLICATION_PORT + "/spring-rest/foos";
1922

2023
@Before
2124
public void beforeTest() {
@@ -26,9 +29,19 @@ public void beforeTest() {
2629

2730
@Test
2831
public void givenResourceUrl_whenSendGetForRequestEntity_thenStatusOk() throws IOException {
29-
final ResponseEntity<String> response = restTemplate.getForEntity(fooResourceUrl, String.class);
30-
32+
ResponseEntity<String> response = restTemplate.getForEntity(fooResourceUrl + "/1", String.class);
33+
3134
assertThat(response.getStatusCode(), equalTo(HttpStatus.OK));
3235
}
36+
37+
@Test
38+
public void givenResourceUrl_whenSendGetForRequestEntity_thenBodyCorrect() throws IOException {
39+
ResponseEntity<String> response = restTemplate.getForEntity(fooResourceUrl + "/1", String.class);
40+
41+
ObjectMapper mapper = new ObjectMapper();
42+
JsonNode root = mapper.readTree(response.getBody());
43+
JsonNode name = root.path("name");
44+
assertThat(name.asText(), equalTo("bar"));
45+
}
3346

3447
}

spring-rest/src/test/java/org/baeldung/web/controller/redirect/RedirectControllerTest.java renamed to spring-rest/src/test/java/org/baeldung/web/controller/redirect/RedirectControllerIntegrationTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.baeldung.web.controller.redirect;
22

3-
import static org.hamcrest.CoreMatchers.is;
3+
import static org.hamcrest.CoreMatchers.equalTo;
44
import static org.hamcrest.CoreMatchers.nullValue;
55
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
66
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.flash;
@@ -24,7 +24,7 @@
2424
@RunWith(SpringJUnit4ClassRunner.class)
2525
@ContextConfiguration("file:src/main/webapp/WEB-INF/api-servlet.xml")
2626
@WebAppConfiguration
27-
public class RedirectControllerTest {
27+
public class RedirectControllerIntegrationTest {
2828

2929
private MockMvc mockMvc;
3030

@@ -38,30 +38,30 @@ public void setup() {
3838

3939
@Test
4040
public void whenRedirectOnUrlWithUsingXMLConfig_thenStatusRedirectionAndRedirectedOnUrl() throws Exception {
41-
mockMvc.perform(get("/redirectWithXMLConfig")).andExpect(status().is3xxRedirection()).andExpect(view().name("RedirectedUrl")).andExpect(model().attribute("attribute", is("redirectWithXMLConfig")))
41+
mockMvc.perform(get("/redirectWithXMLConfig")).andExpect(status().is3xxRedirection()).andExpect(view().name("RedirectedUrl")).andExpect(model().attribute("attribute", equalTo("redirectWithXMLConfig")))
4242
.andExpect(redirectedUrl("redirectedUrl?attribute=redirectWithXMLConfig"));
4343
}
4444

4545
@Test
4646
public void whenRedirectOnUrlWithUsingRedirectPrefix_thenStatusRedirectionAndRedirectedOnUrl() throws Exception {
47-
mockMvc.perform(get("/redirectWithRedirectPrefix")).andExpect(status().is3xxRedirection()).andExpect(view().name("redirect:/redirectedUrl")).andExpect(model().attribute("attribute", is("redirectWithRedirectPrefix")))
47+
mockMvc.perform(get("/redirectWithRedirectPrefix")).andExpect(status().is3xxRedirection()).andExpect(view().name("redirect:/redirectedUrl")).andExpect(model().attribute("attribute", equalTo("redirectWithRedirectPrefix")))
4848
.andExpect(redirectedUrl("/redirectedUrl?attribute=redirectWithRedirectPrefix"));
4949
}
5050

5151
@Test
5252
public void whenRedirectOnUrlWithUsingRedirectAttributes_thenStatusRedirectionAndRedirectedOnUrlAndAddedAttributeToFlashScope() throws Exception {
53-
mockMvc.perform(get("/redirectWithRedirectAttributes")).andExpect(status().is3xxRedirection()).andExpect(flash().attribute("flashAttribute", is("redirectWithRedirectAttributes")))
54-
.andExpect(model().attribute("attribute", is("redirectWithRedirectAttributes"))).andExpect(model().attribute("flashAttribute", is(nullValue()))).andExpect(redirectedUrl("redirectedUrl?attribute=redirectWithRedirectAttributes"));
53+
mockMvc.perform(get("/redirectWithRedirectAttributes")).andExpect(status().is3xxRedirection()).andExpect(flash().attribute("flashAttribute", equalTo("redirectWithRedirectAttributes")))
54+
.andExpect(model().attribute("attribute", equalTo("redirectWithRedirectAttributes"))).andExpect(model().attribute("flashAttribute", equalTo(nullValue()))).andExpect(redirectedUrl("redirectedUrl?attribute=redirectWithRedirectAttributes"));
5555
}
5656

5757
@Test
5858
public void whenRedirectOnUrlWithUsingRedirectView_thenStatusRedirectionAndRedirectedOnUrlAndAddedAttributeToFlashScope() throws Exception {
59-
mockMvc.perform(get("/redirectWithRedirectView")).andExpect(status().is3xxRedirection()).andExpect(model().attribute("attribute", is("redirectWithRedirectView"))).andExpect(redirectedUrl("redirectedUrl?attribute=redirectWithRedirectView"));
59+
mockMvc.perform(get("/redirectWithRedirectView")).andExpect(status().is3xxRedirection()).andExpect(model().attribute("attribute", equalTo("redirectWithRedirectView"))).andExpect(redirectedUrl("redirectedUrl?attribute=redirectWithRedirectView"));
6060
}
6161

6262
@Test
6363
public void whenRedirectOnUrlWithUsingForwardPrefix_thenStatusOkAndForwardedOnUrl() throws Exception {
64-
mockMvc.perform(get("/forwardWithForwardPrefix")).andExpect(status().isOk()).andExpect(view().name("forward:/redirectedUrl")).andExpect(model().attribute("attribute", is("redirectWithForwardPrefix"))).andExpect(forwardedUrl("/redirectedUrl"));
64+
mockMvc.perform(get("/forwardWithForwardPrefix")).andExpect(status().isOk()).andExpect(view().name("forward:/redirectedUrl")).andExpect(model().attribute("attribute", equalTo("redirectWithForwardPrefix"))).andExpect(forwardedUrl("/redirectedUrl"));
6565
}
6666

6767
}

spring-rest/src/test/java/org/baeldung/web/controller/status/ExampleControllerTest.java renamed to spring-rest/src/test/java/org/baeldung/web/controller/status/ExampleControllerIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
@RunWith(SpringJUnit4ClassRunner.class)
1919
@ContextConfiguration(classes = WebConfig.class)
2020
@WebAppConfiguration
21-
public class ExampleControllerTest {
21+
public class ExampleControllerIntegrationTest {
2222

2323
private MockMvc mockMvc;
2424

0 commit comments

Comments
 (0)