From 61411e0831a334c86939b46b909d816a02df354e Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Mon, 26 Jun 2017 14:34:29 +0200 Subject: [PATCH] Don't swallow exceptions when downloading stubs without this change when any exception occurs (e.g. the stub can't be downloaded) a null will be returned with this change we want to throw an exception instead fixes #314 --- .../stubrunner/AetherStubDownloader.java | 4 +--- .../stubrunner/AetherStubDownloaderSpec.groovy | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) 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 dc6a901492..8b8c544059 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 @@ -165,13 +165,11 @@ public class AetherStubDownloader implements StubDownloader { throw ise; } catch (Exception e) { - //TODO: Start throwing this exception instead of returning null - log.warn( + throw new IllegalStateException( "Exception occurred while trying to download a stub for group [" + stubsGroup + "] module [" + stubsModule + "] and classifier [" + classifier + "] in " + this.remoteRepos, e); - return null; } } diff --git a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/AetherStubDownloaderSpec.groovy b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/AetherStubDownloaderSpec.groovy index de1e3f8586..ed0a25795e 100644 --- a/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/AetherStubDownloaderSpec.groovy +++ b/spring-cloud-contract-stub-runner/src/test/groovy/org/springframework/cloud/contract/stubrunner/AetherStubDownloaderSpec.groovy @@ -11,7 +11,7 @@ import spock.util.environment.RestoreSystemProperties class AetherStubDownloaderSpec extends Specification { @Rule - HoverflyRule hoverflyRule = HoverflyRule.inCaptureMode("simulation.json") + HoverflyRule hoverflyRule = HoverflyRule.inSimulationMode("simulation.json") def 'Should be able to download from a repository using username and password authentication'() { given: @@ -31,6 +31,22 @@ class AetherStubDownloaderSpec extends Specification { jar != null } + def 'Should throw an exception when artifact not found'() { + given: + StubRunnerOptions stubRunnerOptions = new StubRunnerOptionsBuilder() + .withWorkOffline(true) + .build() + + AetherStubDownloader aetherStubDownloader = new AetherStubDownloader(stubRunnerOptions) + + when: + def jar = aetherStubDownloader.downloadAndUnpackStubJar(new StubConfiguration("non.existing.group", "missing-artifact-id", "1.0-SNAPSHOT")) + + then: + IllegalStateException e = thrown(IllegalStateException) + e.message.contains("Exception occurred while trying to download a stub for group") + } + def 'Should throw an exception when a jar is in local m2 and not in remote repo'() { given: StubRunnerOptions stubRunnerOptions = new StubRunnerOptionsBuilder()