Skip to content

Commit d83e058

Browse files
mmorskypolysantiago
authored andcommitted
Update to Spring Boot 2.1.6 (#3)
1 parent cc7dd75 commit d83e058

12 files changed

+54
-58
lines changed

build.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ plugins {
22
id 'java'
33
id 'idea'
44
id 'jacoco'
5-
id "io.spring.dependency-management" version "1.0.2.RELEASE"
5+
id "io.spring.dependency-management" version "1.0.7.RELEASE"
66
id 'maven-publish'
77
id 'signing'
88
id 'nebula.optional-base' version '3.0.3'
@@ -44,7 +44,7 @@ repositories {
4444

4545
dependencyManagement {
4646
imports {
47-
mavenBom 'io.spring.platform:platform-bom:Brussels-SR2'
47+
mavenBom 'org.springframework.boot:spring-boot-dependencies:2.1.6.RELEASE'
4848
}
4949
}
5050

@@ -55,7 +55,8 @@ dependencies {
5555
compile("org.springframework:spring-webmvc")
5656
compile('org.springframework:spring-aop')
5757
compile('org.aspectj:aspectjweaver')
58-
58+
annotationProcessor('org.springframework.boot:spring-boot-configuration-processor')
59+
5960
compile 'org.springframework.retry:spring-retry', optional
6061

6162
provided 'org.projectlombok:lombok'

src/main/java/io/github/polysantiago/spring/rest/RestClientAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
66
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
77
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
8-
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
8+
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
99
import org.springframework.boot.context.properties.EnableConfigurationProperties;
1010
import org.springframework.boot.web.client.RestTemplateBuilder;
1111
import org.springframework.context.annotation.Bean;

src/test/java/io/github/polysantiago/spring/rest/AbstractRestClientAsyncTest.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ public void testRestClientGetObjectWithNoContentShouldReturnNull() throws Except
155155
getResponse(fooClient.fooObject());
156156
fail("Should get NOT FOUND");
157157
} catch (ExecutionException executionException) {
158-
assertThat(executionException).hasCauseExactlyInstanceOf(HttpClientErrorException.class);
158+
assertThat(executionException)
159+
.hasCauseExactlyInstanceOf(HttpClientErrorException.NotFound.class);
159160
}
160161
}
161162

@@ -198,7 +199,8 @@ public void testRestClientPostAsyncServerError() throws Exception {
198199
getResponse(fooClient.bar("some-body"));
199200
fail("Should have gotten Exception");
200201
} catch (ExecutionException executionException) {
201-
assertThat(executionException).hasCauseExactlyInstanceOf(HttpServerErrorException.class);
202+
assertThat(executionException)
203+
.hasCauseExactlyInstanceOf(HttpServerErrorException.InternalServerError.class);
202204
}
203205
}
204206

@@ -251,7 +253,8 @@ public void testRestClientDoesNotRetryIfNotEnabled() throws Exception {
251253
getResponse(fooClient.defaultFoo());
252254
fail("Should have gotten exception");
253255
} catch (ExecutionException executionException) {
254-
assertThat(executionException).hasCauseExactlyInstanceOf(HttpServerErrorException.class);
256+
assertThat(executionException)
257+
.hasCauseExactlyInstanceOf(HttpServerErrorException.ServiceUnavailable.class);
255258
}
256259
}
257260

src/test/java/io/github/polysantiago/spring/rest/RestClientAutoConfigurationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ FormattingConversionService mvcConversionService() {
8181

8282
}
8383

84-
@RestClient(value = "localhost", url = "http://someserver")
84+
@RestClient(value = "test-client", url = "http://someserver")
8585
interface TestClient {
8686

8787
@GetMapping("str")

src/test/java/io/github/polysantiago/spring/rest/RestClientCompletableFutureAsyncTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ protected static class TestConfiguration extends BaseTestConfiguration {
2020

2121
}
2222

23-
@RestClient(value = "localhost", url = "${localhost.uri}")
23+
@RestClient(value = "completable-future", url = "${localhost.uri}")
2424
interface CompletableFutureAsyncFooClient extends AbstractRestClientAsyncTest.AsyncFooClient {
2525

2626
@Override

src/test/java/io/github/polysantiago/spring/rest/RestClientHateoasTest.java

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package io.github.polysantiago.spring.rest;
22

3-
import com.fasterxml.jackson.databind.ObjectMapper;
3+
import com.fasterxml.jackson.databind.Module;
44
import org.junit.After;
55
import org.junit.Before;
66
import org.junit.Test;
77
import org.junit.runner.RunWith;
8-
import org.springframework.beans.BeansException;
98
import org.springframework.beans.factory.annotation.Autowired;
109
import org.springframework.beans.factory.annotation.Value;
11-
import org.springframework.beans.factory.config.BeanPostProcessor;
1210
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
1311
import org.springframework.boot.test.context.SpringBootTest;
1412
import org.springframework.context.annotation.Bean;
@@ -19,10 +17,10 @@
1917
import org.springframework.hateoas.PagedResources;
2018
import org.springframework.hateoas.Resources;
2119
import org.springframework.hateoas.config.EnableHypermediaSupport;
20+
import org.springframework.hateoas.hal.Jackson2HalModule;
2221
import org.springframework.http.HttpHeaders;
2322
import org.springframework.http.HttpMethod;
2423
import org.springframework.http.HttpStatus;
25-
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
2624
import org.springframework.test.context.ActiveProfiles;
2725
import org.springframework.test.context.junit4.SpringRunner;
2826
import org.springframework.test.web.client.MockRestServiceServer;
@@ -52,33 +50,19 @@ public class RestClientHateoasTest {
5250

5351
@Configuration
5452
@EnableAutoConfiguration
55-
@EnableRestClients(basePackageClasses = FooClient.class)
53+
@EnableRestClients(basePackageClasses = BarClient.class)
5654
@EnableHypermediaSupport(type = EnableHypermediaSupport.HypermediaType.HAL)
5755
static class ContextConfiguration {
5856

5957
@Bean
60-
BeanPostProcessor halObjectMapperPostProcessor(Jackson2ObjectMapperBuilder builder) {
61-
return new BeanPostProcessor() {
62-
@Override
63-
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
64-
return bean;
65-
}
66-
67-
@Override
68-
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
69-
if (!"_halObjectMapper".equals(beanName)) {
70-
return bean;
71-
}
72-
builder.configure((ObjectMapper) bean);
73-
return bean;
74-
}
75-
};
58+
Module halModule() {
59+
return new Jackson2HalModule();
7660
}
7761

7862
}
7963

80-
@RestClient(value = "localhost", url = "${localhost.uri}")
81-
interface FooClient {
64+
@RestClient(value = "bar-client", url = "${localhost.uri}")
65+
interface BarClient {
8266

8367
@GetMapping(value = SINGLE_RESOURCE, produces = MediaTypes.HAL_JSON_VALUE)
8468
FooResource getFoo(@PathVariable("id") String id);
@@ -100,7 +84,7 @@ interface FooClient {
10084
private PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper("{", "}");
10185

10286
@Autowired
103-
private FooClient fooClient;
87+
private BarClient barClient;
10488

10589
@Autowired
10690
private RestTemplate restTemplate;
@@ -132,7 +116,7 @@ public void testSingleResource() throws Exception {
132116

133117
mockServerHalResponse(endpoint, fooResourceJson);
134118

135-
FooResource foo = fooClient.getFoo("1234");
119+
FooResource foo = barClient.getFoo("1234");
136120

137121
assertThat(foo).isNotNull();
138122
assertThat(foo.getId()).isNotNull();
@@ -146,7 +130,7 @@ public void testSingleResourceWrapped() throws Exception {
146130

147131
mockServerHalResponse(endpoint, fooResourceJson);
148132

149-
org.springframework.hateoas.Resource<Foo> resource = fooClient.getFooWrapped("1234");
133+
org.springframework.hateoas.Resource<Foo> resource = barClient.getFooWrapped("1234");
150134

151135
assertThat(resource).isNotNull();
152136
assertThat(resource.getId()).isNotNull();
@@ -159,7 +143,7 @@ public void testSingleResourceWrapped() throws Exception {
159143
public void testCollectionResource() throws Exception {
160144
mockServerHalResponse(COLLECTION_RESOURCE, fooResourcesJson);
161145

162-
Resources<FooResource> foos = fooClient.getFoos();
146+
Resources<FooResource> foos = barClient.getFoos();
163147

164148
assertThat(foos.getId()).isNotNull();
165149
assertThat(foos.getContent()).isNotEmpty();
@@ -171,7 +155,7 @@ public void testOptionalCollectionResource_notFound() throws Exception {
171155
mockServerHalResponse(OPTIONAL_COLLECTION_RESOURCE)
172156
.andRespond(withStatus(HttpStatus.NOT_FOUND));
173157

174-
Optional<Resources<FooResource>> optionalFoos = fooClient.getOptionalFoos();
158+
Optional<Resources<FooResource>> optionalFoos = barClient.getOptionalFoos();
175159

176160
assertThat(optionalFoos).isNotPresent();
177161
}
@@ -180,7 +164,7 @@ public void testOptionalCollectionResource_notFound() throws Exception {
180164
public void testOptionalCollectionResource_found() throws Exception {
181165
mockServerHalResponse(OPTIONAL_COLLECTION_RESOURCE, fooResourcesJson);
182166

183-
Optional<Resources<FooResource>> optionalFoos = fooClient.getOptionalFoos();
167+
Optional<Resources<FooResource>> optionalFoos = barClient.getOptionalFoos();
184168

185169
assertThat(optionalFoos).isPresent();
186170
assertThat(optionalFoos).hasValueSatisfying(resources -> assertThat(resources).isNotEmpty());
@@ -194,7 +178,7 @@ public void testOptionalCollectionResource_found() throws Exception {
194178
public void testPagedCollectionResource() throws Exception {
195179
mockServerHalResponse(PAGED_RESOURCE, fooPagedResourcesJson);
196180

197-
PagedResources<FooResource> pagedFoos = fooClient.getPagedFoos();
181+
PagedResources<FooResource> pagedFoos = barClient.getPagedFoos();
198182

199183
assertThat(pagedFoos).isNotEmpty();
200184
assertThat(pagedFoos.getContent()).isNotEmpty();

src/test/java/io/github/polysantiago/spring/rest/RestClientListenableFutureAsyncTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ protected static class TestConfiguration extends BaseTestConfiguration {
2929
@Mock
3030
private ListenableFutureCallback<Optional<String>> callback;
3131

32-
@RestClient(value = "localhost", url = "${localhost.uri}")
32+
@RestClient(value = "listenable-future", url = "${localhost.uri}")
3333
interface ListenableFutureAsyncFooClient extends AbstractRestClientAsyncTest.AsyncFooClient {
3434

3535
@Override

src/test/java/io/github/polysantiago/spring/rest/RestClientPropertiesTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
import org.junit.Test;
77
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
88
import org.springframework.boot.context.properties.EnableConfigurationProperties;
9+
import org.springframework.boot.test.util.TestPropertyValues;
910
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
1011
import org.springframework.context.annotation.Configuration;
1112

1213
import static org.assertj.core.api.Assertions.assertThat;
13-
import static org.springframework.boot.test.util.EnvironmentTestUtils.addEnvironment;
1414

1515
public class RestClientPropertiesTest {
1616

@@ -32,7 +32,7 @@ public void testDefaultProperties() throws Exception {
3232

3333
@Test
3434
public void testMaxAttempts() throws Exception {
35-
addEnvironment(this.context, "spring.rest.client.retry.max-attempts:5");
35+
TestPropertyValues.of("spring.rest.client.retry.max-attempts:5").applyTo(this.context);
3636

3737
registerAndRefresh();
3838

@@ -41,10 +41,11 @@ public void testMaxAttempts() throws Exception {
4141

4242
@Test
4343
public void testBackOffSettings() throws Exception {
44-
addEnvironment(this.context, "spring.rest.client.retry.back-off.delay:2000");
45-
addEnvironment(this.context, "spring.rest.client.retry.back-off.max-delay:10000");
46-
addEnvironment(this.context, "spring.rest.client.retry.back-off.multiplier:2.5");
47-
addEnvironment(this.context, "spring.rest.client.retry.back-off.random:true");
44+
TestPropertyValues.of("spring.rest.client.retry.back-off.delay:2000")
45+
.and("spring.rest.client.retry.back-off.max-delay:10000")
46+
.and("spring.rest.client.retry.back-off.multiplier:2.5")
47+
.and("spring.rest.client.retry.back-off.random:true")
48+
.applyTo(this.context);
4849

4950
registerAndRefresh();
5051

src/test/java/io/github/polysantiago/spring/rest/RestClientRetryTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,26 @@
3434
public class RestClientRetryTest {
3535

3636
@Autowired
37-
private FooClient fooClient;
37+
private BazClient bazClient;
3838

3939
@Autowired
4040
private RestTemplate restTemplate;
4141

42-
@Value("${spring.rest.client.services.localhost}")
42+
@Value("${localhost.uri}")
4343
private String requestUrl;
4444

4545
private MockRestServiceServer server;
4646

4747
@Configuration
4848
@EnableAutoConfiguration
49-
@EnableRestClients(basePackageClasses = FooClient.class)
49+
@EnableRestClients(basePackageClasses = BazClient.class)
5050
@EnableRetry
5151
protected static class TestConfiguration {
5252

5353
}
5454

55-
@RestClient(name = "localhost", retryOn = {HttpStatus.SERVICE_UNAVAILABLE}, retryOnException = {ResourceAccessException.class})
56-
interface FooClient {
55+
@RestClient(name = "baz-client", retryOn = {HttpStatus.SERVICE_UNAVAILABLE}, retryOnException = {ResourceAccessException.class})
56+
interface BazClient {
5757

5858
@RequestMapping
5959
Void foo();
@@ -80,7 +80,7 @@ public void testRetry() throws Exception {
8080
.andExpect(method(HttpMethod.GET))
8181
.andRespond(withSuccess());
8282

83-
fooClient.foo();
83+
bazClient.foo();
8484
}
8585

8686
@Test(expected = HttpServerErrorException.class)
@@ -89,7 +89,7 @@ public void testShouldNotRetry() throws Exception {
8989
.andExpect(method(HttpMethod.GET))
9090
.andRespond(withServerError());
9191

92-
fooClient.foo();
92+
bazClient.foo();
9393
}
9494

9595
@Test
@@ -109,7 +109,7 @@ public void testShouldRetryOnIoException() throws Exception {
109109
.andExpect(method(HttpMethod.GET))
110110
.andRespond(withSuccess());
111111

112-
fooClient.foo();
112+
bazClient.foo();
113113
}
114114

115115
@Test(expected = RuntimeException.class)
@@ -120,7 +120,7 @@ public void testShouldNotRetryOnOtherExceptions() throws Exception {
120120
throw new RuntimeException();
121121
});
122122

123-
fooClient.foo();
123+
bazClient.foo();
124124
}
125125

126126
private String defaultUrl() {

src/test/java/io/github/polysantiago/spring/rest/RestClientTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ protected static class ContextConfiguration {
6565

6666
}
6767

68-
@RestClient(value = "localhost", url = "${localhost.uri}")
68+
@RestClient(value = "foo-client", url = "${localhost.uri}")
6969
interface FooClient {
7070

7171
@GetMapping
@@ -161,7 +161,7 @@ interface FooParent<T> {
161161

162162
}
163163

164-
@RestClient(value = "localhost", url = "${localhost.uri}")
164+
@RestClient(value = "foo-child-client", url = "${localhost.uri}")
165165
interface FooChildClient extends FooParent<Foo> {
166166

167167
}

src/test/lombok.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lombok.anyConstructor.addConstructorProperties=true

src/test/resources/application-test.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ spring:
44
rest:
55
client:
66
services:
7-
localhost: http://localhost
7+
test-client: http://localhost
8+
completable-future: http://localhost
9+
listenable-future: http://localhost
10+
foo-client: http://localhost
11+
foo-child-client: http://localhost
12+
bar-client: http://localhost
13+
baz-client: http://localhost
814
retry:
915
max-attempts: 2
1016

0 commit comments

Comments
 (0)