Skip to content

Update to Spring Boot 2.1.5. #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id 'java'
id 'idea'
id 'jacoco'
id "io.spring.dependency-management" version "1.0.2.RELEASE"
id "io.spring.dependency-management" version "1.0.7.RELEASE"
id 'maven-publish'
id 'signing'
id 'nebula.optional-base' version '3.0.3'
Expand Down Expand Up @@ -44,7 +44,7 @@ repositories {

dependencyManagement {
imports {
mavenBom 'io.spring.platform:platform-bom:Brussels-SR2'
mavenBom 'org.springframework.boot:spring-boot-dependencies:2.1.5.RELEASE'
Copy link
Owner

@polysantiago polysantiago Jul 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why using version 2.1.5? Is there any specific reason? The latest is 2.24.1.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, for egoistic reasons mainly, it's the version our application uses :) But I guess there's no reason to not use the latest and greatest. Where did you find the latest version to be 2.24.1? I tried checking the Maven central and there it seems to be 2.1.6 but maybe I'm missing something...

https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-dependencies

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, nevermind. I was looking at the wrong dependency. You're right. Latest is 2.1.6

}
}

Expand All @@ -55,10 +55,12 @@ dependencies {
compile("org.springframework:spring-webmvc")
compile('org.springframework:spring-aop')
compile('org.aspectj:aspectjweaver')

annotationProcessor('org.springframework.boot:spring-boot-configuration-processor')

compile 'org.springframework.retry:spring-retry', optional

provided 'org.projectlombok:lombok'
annotationProcessor("org.projectlombok:lombok")
compile 'org.apache.commons:commons-lang3:3.5'
compile 'net.javacrumbs.future-converter:future-converter-spring-java8:1.1.0'

Expand All @@ -67,6 +69,7 @@ dependencies {
testCompile("com.fasterxml.jackson.datatype:jackson-datatype-jdk8")
testCompile("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml")
testCompile('org.assertj:assertj-core:3.6.2')
testAnnotationProcessor("org.projectlombok:lombok")
}

tasks.withType(Jar) {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-bin.zip
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ public void testRestClientGetObjectWithNoContentShouldReturnNull() throws Except
getResponse(fooClient.fooObject());
fail("Should get NOT FOUND");
} catch (ExecutionException executionException) {
assertThat(executionException).hasCauseExactlyInstanceOf(HttpClientErrorException.class);
assertThat(executionException)
.hasCauseExactlyInstanceOf(HttpClientErrorException.NotFound.class);
}
}

Expand Down Expand Up @@ -198,7 +199,8 @@ public void testRestClientPostAsyncServerError() throws Exception {
getResponse(fooClient.bar("some-body"));
fail("Should have gotten Exception");
} catch (ExecutionException executionException) {
assertThat(executionException).hasCauseExactlyInstanceOf(HttpServerErrorException.class);
assertThat(executionException)
.hasCauseExactlyInstanceOf(HttpServerErrorException.InternalServerError.class);
}
}

Expand Down Expand Up @@ -251,7 +253,8 @@ public void testRestClientDoesNotRetryIfNotEnabled() throws Exception {
getResponse(fooClient.defaultFoo());
fail("Should have gotten exception");
} catch (ExecutionException executionException) {
assertThat(executionException).hasCauseExactlyInstanceOf(HttpServerErrorException.class);
assertThat(executionException)
.hasCauseExactlyInstanceOf(HttpServerErrorException.ServiceUnavailable.class);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ FormattingConversionService mvcConversionService() {

}

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

@GetMapping("str")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected static class TestConfiguration extends BaseTestConfiguration {

}

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

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package io.github.polysantiago.spring.rest;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.Module;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
Expand All @@ -19,10 +17,10 @@
import org.springframework.hateoas.PagedResources;
import org.springframework.hateoas.Resources;
import org.springframework.hateoas.config.EnableHypermediaSupport;
import org.springframework.hateoas.hal.Jackson2HalModule;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.client.MockRestServiceServer;
Expand Down Expand Up @@ -52,33 +50,19 @@ public class RestClientHateoasTest {

@Configuration
@EnableAutoConfiguration
@EnableRestClients(basePackageClasses = FooClient.class)
@EnableRestClients(basePackageClasses = BarClient.class)
@EnableHypermediaSupport(type = EnableHypermediaSupport.HypermediaType.HAL)
static class ContextConfiguration {

@Bean
BeanPostProcessor halObjectMapperPostProcessor(Jackson2ObjectMapperBuilder builder) {
return new BeanPostProcessor() {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
return bean;
}

@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (!"_halObjectMapper".equals(beanName)) {
return bean;
}
builder.configure((ObjectMapper) bean);
return bean;
}
};
Module halModule() {
return new Jackson2HalModule();
}

}

@RestClient(value = "localhost", url = "${localhost.uri}")
interface FooClient {
@RestClient(value = "bar-client", url = "${localhost.uri}")
interface BarClient {

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

@Autowired
private FooClient fooClient;
private BarClient barClient;

@Autowired
private RestTemplate restTemplate;
Expand Down Expand Up @@ -132,7 +116,7 @@ public void testSingleResource() throws Exception {

mockServerHalResponse(endpoint, fooResourceJson);

FooResource foo = fooClient.getFoo("1234");
FooResource foo = barClient.getFoo("1234");

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

mockServerHalResponse(endpoint, fooResourceJson);

org.springframework.hateoas.Resource<Foo> resource = fooClient.getFooWrapped("1234");
org.springframework.hateoas.Resource<Foo> resource = barClient.getFooWrapped("1234");

assertThat(resource).isNotNull();
assertThat(resource.getId()).isNotNull();
Expand All @@ -159,7 +143,7 @@ public void testSingleResourceWrapped() throws Exception {
public void testCollectionResource() throws Exception {
mockServerHalResponse(COLLECTION_RESOURCE, fooResourcesJson);

Resources<FooResource> foos = fooClient.getFoos();
Resources<FooResource> foos = barClient.getFoos();

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

Optional<Resources<FooResource>> optionalFoos = fooClient.getOptionalFoos();
Optional<Resources<FooResource>> optionalFoos = barClient.getOptionalFoos();

assertThat(optionalFoos).isNotPresent();
}
Expand All @@ -180,7 +164,7 @@ public void testOptionalCollectionResource_notFound() throws Exception {
public void testOptionalCollectionResource_found() throws Exception {
mockServerHalResponse(OPTIONAL_COLLECTION_RESOURCE, fooResourcesJson);

Optional<Resources<FooResource>> optionalFoos = fooClient.getOptionalFoos();
Optional<Resources<FooResource>> optionalFoos = barClient.getOptionalFoos();

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

PagedResources<FooResource> pagedFoos = fooClient.getPagedFoos();
PagedResources<FooResource> pagedFoos = barClient.getPagedFoos();

assertThat(pagedFoos).isNotEmpty();
assertThat(pagedFoos.getContent()).isNotEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected static class TestConfiguration extends BaseTestConfiguration {
@Mock
private ListenableFutureCallback<Optional<String>> callback;

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import org.junit.Test;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;

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

public class RestClientPropertiesTest {

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

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

registerAndRefresh();

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

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

registerAndRefresh();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,26 @@
public class RestClientRetryTest {

@Autowired
private FooClient fooClient;
private BazClient bazClient;

@Autowired
private RestTemplate restTemplate;

@Value("${spring.rest.client.services.localhost}")
@Value("${localhost.uri}")
private String requestUrl;

private MockRestServiceServer server;

@Configuration
@EnableAutoConfiguration
@EnableRestClients(basePackageClasses = FooClient.class)
@EnableRestClients(basePackageClasses = BazClient.class)
@EnableRetry
protected static class TestConfiguration {

}

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

@RequestMapping
Void foo();
Expand All @@ -80,7 +80,7 @@ public void testRetry() throws Exception {
.andExpect(method(HttpMethod.GET))
.andRespond(withSuccess());

fooClient.foo();
bazClient.foo();
}

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

fooClient.foo();
bazClient.foo();
}

@Test
Expand All @@ -109,7 +109,7 @@ public void testShouldRetryOnIoException() throws Exception {
.andExpect(method(HttpMethod.GET))
.andRespond(withSuccess());

fooClient.foo();
bazClient.foo();
}

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

fooClient.foo();
bazClient.foo();
}

private String defaultUrl() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected static class ContextConfiguration {

}

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

@GetMapping
Expand Down Expand Up @@ -161,7 +161,7 @@ interface FooParent<T> {

}

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

}
Expand Down
1 change: 1 addition & 0 deletions src/test/lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lombok.anyConstructor.addConstructorProperties=true
8 changes: 7 additions & 1 deletion src/test/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ spring:
rest:
client:
services:
localhost: http://localhost
test-client: http://localhost
completable-future: http://localhost
listenable-future: http://localhost
foo-client: http://localhost
foo-child-client: http://localhost
bar-client: http://localhost
baz-client: http://localhost
retry:
max-attempts: 2

Expand Down