From 413a3d23bbc5600b819f261d60a8beb290d82de4 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Wed, 26 Oct 2016 10:01:13 +0100 Subject: [PATCH] The spring context now fails to start if the stub cannot be found The spring context now fails to start if the stub cannot be found, enabling the test to fail as quickly as possible for feedback --- README.adoc | 2 +- .../stubrunner/AetherStubDownloader.java | 2 +- .../FailFastLoanApplicationServiceTests.java | 35 +++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 tests/spring-cloud-contract-stub-runner-context-path/src/test/java/com/example/loan/FailFastLoanApplicationServiceTests.java diff --git a/README.adoc b/README.adoc index 16d4f9b610..ad85e2e6f9 100644 --- a/README.adoc +++ b/README.adoc @@ -1298,7 +1298,7 @@ Example of a `pom.xml` inside the `server` folder. UTF-8 1.8 - 1.0.1.BUILD-SNAPSHOT + 1.0.2.BUILD-SNAPSHOT Camden.BUILD-SNAPSHOT diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/AetherStubDownloader.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/AetherStubDownloader.java index 006650c410..0a6372f2c4 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/AetherStubDownloader.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/AetherStubDownloader.java @@ -197,7 +197,7 @@ public class AetherStubDownloader implements StubDownloader { throw new IllegalStateException("Cannot resolve version range", e); } if (rangeResult.getHighestVersion() == null) { - log.error("For groupId [" + stubsGroup + "] artifactId [" + stubsModule + "] " + throw new IllegalArgumentException("For groupId [" + stubsGroup + "] artifactId [" + stubsModule + "] " + "and classifier [" + classifier + "] the version was not resolved!"); } return rangeResult.getHighestVersion() == null ? null : rangeResult.getHighestVersion().toString(); diff --git a/tests/spring-cloud-contract-stub-runner-context-path/src/test/java/com/example/loan/FailFastLoanApplicationServiceTests.java b/tests/spring-cloud-contract-stub-runner-context-path/src/test/java/com/example/loan/FailFastLoanApplicationServiceTests.java new file mode 100644 index 0000000000..18dcf704d4 --- /dev/null +++ b/tests/spring-cloud-contract-stub-runner-context-path/src/test/java/com/example/loan/FailFastLoanApplicationServiceTests.java @@ -0,0 +1,35 @@ +package com.example.loan; + +import com.google.common.collect.ImmutableMap; +import org.junit.Test; +import org.springframework.beans.BeanInstantiationException; +import org.springframework.beans.factory.BeanCreationException; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.cloud.contract.stubrunner.spring.StubRunnerConfiguration; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.catchThrowable; + +/** + * @author Andrew Morgan + */ +public class FailFastLoanApplicationServiceTests { + + @Test + public void shouldFailToStartContextWhenNoStubCanBeFound() { + // When + final Throwable throwable = catchThrowable(() -> new SpringApplicationBuilder(Application.class, StubRunnerConfiguration.class) + .properties(ImmutableMap.of( + "stubrunner.repositoryRoot", "classpath:m2repo/repository/", + "stubrunner.ids", new String[]{"org.springframework.cloud.contract.verifier.stubs:should-not-be-found"})) + .run()); + + // Then + assertThat(throwable).isInstanceOf(BeanCreationException.class); + assertThat(throwable.getCause()).isInstanceOf(BeanInstantiationException.class); + assertThat(throwable.getCause().getCause()) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("For groupId [org.springframework.cloud.contract.verifier.stubs] artifactId [should-not-be-found] and classifier [stubs] the version was not resolved!"); + } + +}