Merge branch '1.0.x'
This commit is contained in:
@@ -16,6 +16,11 @@
|
||||
|
||||
package org.springframework.cloud.contract.stubrunner;
|
||||
|
||||
import static java.nio.file.Files.createTempDirectory;
|
||||
import static org.springframework.cloud.contract.stubrunner.AetherFactories.newRepositorySystem;
|
||||
import static org.springframework.cloud.contract.stubrunner.AetherFactories.newSession;
|
||||
import static org.springframework.cloud.contract.stubrunner.util.ZipCategory.unzipTo;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
@@ -35,20 +40,12 @@ import org.eclipse.aether.resolution.ArtifactResult;
|
||||
import org.eclipse.aether.resolution.VersionRangeRequest;
|
||||
import org.eclipse.aether.resolution.VersionRangeResolutionException;
|
||||
import org.eclipse.aether.resolution.VersionRangeResult;
|
||||
import org.eclipse.aether.resolution.VersionRequest;
|
||||
import org.eclipse.aether.resolution.VersionResolutionException;
|
||||
import org.eclipse.aether.resolution.VersionResult;
|
||||
import org.eclipse.aether.util.repository.AuthenticationBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cloud.contract.stubrunner.StubRunnerOptions.StubRunnerProxyOptions;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static java.nio.file.Files.createTempDirectory;
|
||||
import static org.springframework.cloud.contract.stubrunner.AetherFactories.newRepositorySystem;
|
||||
import static org.springframework.cloud.contract.stubrunner.AetherFactories.newSession;
|
||||
import static org.springframework.cloud.contract.stubrunner.util.ZipCategory.unzipTo;
|
||||
|
||||
/**
|
||||
* @author Mariusz Smykula
|
||||
*/
|
||||
@@ -215,26 +212,12 @@ public class AetherStubDownloader implements StubDownloader {
|
||||
}
|
||||
if (rangeResult.getHighestVersion() == null) {
|
||||
throw new IllegalArgumentException("For groupId [" + stubsGroup + "] artifactId [" + stubsModule + "] "
|
||||
+ "and classifier [" + classifier + "] the version was not resolved!");
|
||||
+ "and classifier [" + classifier + "] the version was not resolved! The following exceptions took place "
|
||||
+ rangeResult.getExceptions());
|
||||
}
|
||||
return rangeResult.getHighestVersion() == null ? null : rangeResult.getHighestVersion().toString();
|
||||
}
|
||||
|
||||
private String resolveArtifactVersion(String stubsGroup, String stubsModule,
|
||||
String version, String classifier) {
|
||||
Artifact artifact = new DefaultArtifact(stubsGroup, stubsModule, classifier,
|
||||
ARTIFACT_EXTENSION, version);
|
||||
VersionRequest versionRequest = new VersionRequest(artifact, this.remoteRepos, null);
|
||||
VersionResult versionResult;
|
||||
try {
|
||||
versionResult = this.repositorySystem.resolveVersion(this.session, versionRequest);
|
||||
}
|
||||
catch (VersionResolutionException e) {
|
||||
throw new IllegalStateException("Cannot resolve version", e);
|
||||
}
|
||||
return versionResult.getVersion() == null ? null : versionResult.getVersion();
|
||||
}
|
||||
|
||||
private static File unpackStubJarToATemporaryFolder(URI stubJarUri) {
|
||||
File tmpDirWhereStubsWillBeUnzipped;
|
||||
try {
|
||||
|
||||
@@ -1,52 +1,70 @@
|
||||
/*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.loan;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.catchThrowable;
|
||||
|
||||
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;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/**
|
||||
* @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());
|
||||
@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!");
|
||||
}
|
||||
// Then
|
||||
assertThat(throwable).isInstanceOf(BeanCreationException.class);
|
||||
assertThat(throwable.getCause()).isInstanceOf(BeanInstantiationException.class);
|
||||
assertThat(throwable.getCause().getCause())
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessageContaining("For groupId [org.springframework.cloud.contract.verifier.stubs] artifactId [should-not-be-found] "
|
||||
+ "and classifier [stubs] the version was not resolved! The following exceptions took place");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotTryAndWorkOfflineWhenWorkOfflineIsSetToFalse() {
|
||||
// When
|
||||
final Throwable throwable = catchThrowable(() -> new SpringApplicationBuilder(Application.class, StubRunnerConfiguration.class)
|
||||
.properties(ImmutableMap.of(
|
||||
"stubrunner.workOffline", "false",
|
||||
"stubrunner.ids", new String[]{"org.springframework.cloud.contract.verifier.stubs:should-not-be-found"}))
|
||||
.run());
|
||||
@Test
|
||||
public void shouldNotTryAndWorkOfflineWhenWorkOfflineIsSetToFalse() {
|
||||
// When
|
||||
final Throwable throwable = catchThrowable(() -> new SpringApplicationBuilder(Application.class, StubRunnerConfiguration.class)
|
||||
.properties(ImmutableMap.of(
|
||||
"stubrunner.workOffline", "false",
|
||||
"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(IllegalStateException.class)
|
||||
.hasMessage("Remote repositories for stubs are not specified and work offline flag wasn't passed");
|
||||
}
|
||||
// Then
|
||||
assertThat(throwable).isInstanceOf(BeanCreationException.class);
|
||||
assertThat(throwable.getCause()).isInstanceOf(BeanInstantiationException.class);
|
||||
assertThat(throwable.getCause().getCause())
|
||||
.isInstanceOf(IllegalStateException.class)
|
||||
.hasMessage("Remote repositories for stubs are not specified and work offline flag wasn't passed");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user