org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties Java Examples

The following examples show how to use org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MavenContractsDownloader.java    From spring-cloud-contract with Apache License 2.0 6 votes vote down vote up
MavenContractsDownloader(MavenProject project, Dependency contractDependency,
		String contractsPath, String contractsRepositoryUrl,
		StubRunnerProperties.StubsMode stubsMode, Log log, String repositoryUsername,
		String repositoryPassword, String repositoryProxyHost,
		Integer repositoryProxyPort, boolean deleteStubsAfterTest,
		Map<String, String> contractsProperties, boolean failOnNoContracts) {
	this.project = project;
	this.contractDependency = contractDependency;
	this.contractsPath = contractsPath;
	this.contractsRepositoryUrl = contractsRepositoryUrl;
	this.stubsMode = stubsMode;
	this.log = log;
	this.repositoryUsername = repositoryUsername;
	this.repositoryPassword = repositoryPassword;
	this.repositoryProxyHost = repositoryProxyHost;
	this.repositoryProxyPort = repositoryProxyPort;
	this.stubDownloaderBuilderProvider = new StubDownloaderBuilderProvider();
	this.deleteStubsAfterTest = deleteStubsAfterTest;
	this.contractsProperties = contractsProperties;
	this.failOnNoStubs = failOnNoContracts;
}
 
Example #2
Source File: ContractProjectUpdaterTest.java    From spring-cloud-contract with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws Exception {
	GitContractsRepo.CACHED_LOCATIONS.clear();
	this.originalProject = new File(
			GitRepoTests.class.getResource("/git_samples/contract-git").toURI());
	TestUtils.prepareLocalRepo();
	this.gitRepo = new GitRepo(this.tmpFolder);
	this.origin = clonedProject(this.tmp.newFolder(), this.originalProject);
	this.project = this.gitRepo.cloneProject(this.originalProject.toURI());
	this.gitRepo.checkout(this.project, "master");
	setOriginOnProjectToTmp(this.origin, this.project, true);
	StubRunnerOptions options = new StubRunnerOptionsBuilder()
			.withStubRepositoryRoot("file://" + this.project.getAbsolutePath() + "/")
			.withStubsMode(StubRunnerProperties.StubsMode.REMOTE).build();
	this.updater = new ContractProjectUpdater(options);
}
 
Example #3
Source File: GitStubDownloaderTests.java    From spring-cloud-contract with Apache License 2.0 6 votes vote down vote up
@Test
public void should_fail_to_fetch_stubs_when_concrete_version_was_not_specified()
		throws URISyntaxException {
	StubDownloaderBuilder stubDownloaderBuilder = new ScmStubDownloaderBuilder();
	StubDownloader stubDownloader = stubDownloaderBuilder
			.build(new StubRunnerOptionsBuilder()
					.withStubsMode(StubRunnerProperties.StubsMode.REMOTE)
					.withStubRepositoryRoot("git://"
							+ file("/git_samples/contract-git").getAbsolutePath()
							+ "/")
					.withProperties(props()).build());

	try {
		stubDownloader.downloadAndUnpackStubJar(
				new StubConfiguration("foo.bar", "bazService", ""));
	}
	catch (IllegalStateException e) {
		then(e).hasMessageContaining(
				"Concrete version wasn't passed for [foo.bar:bazService::stubs]");
	}
}
 
Example #4
Source File: GitStubDownloaderTests.java    From spring-cloud-contract with Apache License 2.0 6 votes vote down vote up
@Test
public void should_pick_stubs_for_group_and_artifact_with_version_from_a_git_repo()
		throws Exception {
	StubDownloaderBuilder stubDownloaderBuilder = new ScmStubDownloaderBuilder();
	StubDownloader stubDownloader = stubDownloaderBuilder
			.build(new StubRunnerOptionsBuilder()
					.withStubsMode(StubRunnerProperties.StubsMode.REMOTE)
					.withStubRepositoryRoot("git://"
							+ file("/git_samples/contract-git/").getAbsolutePath()
							+ "/")
					.withProperties(props()).build());

	Map.Entry<StubConfiguration, File> entry = stubDownloader
			.downloadAndUnpackStubJar(
					new StubConfiguration("foo.bar:bazService:0.0.1-SNAPSHOT"));

	then(entry).isNotNull();
	then(entry.getValue().getAbsolutePath()).contains("foo.bar" + File.separator
			+ "bazService" + File.separator + "0.0.1-SNAPSHOT");
}
 
Example #5
Source File: ClasspathStubProvider.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@Override
public StubDownloader build(final StubRunnerOptions stubRunnerOptions) {
	if (stubRunnerOptions.stubsMode != StubRunnerProperties.StubsMode.CLASSPATH) {
		return null;
	}
	log.info("Will download stubs from classpath");
	return new ResourceResolvingStubDownloader(stubRunnerOptions, this::repoRoot,
			this::gavPattern);
}
 
Example #6
Source File: PactStubDownloaderBuilder.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@Override
public StubDownloader build(StubRunnerOptions stubRunnerOptions) {
	if (stubRunnerOptions.getStubsMode() == StubRunnerProperties.StubsMode.CLASSPATH
			|| stubRunnerOptions.getStubRepositoryRoot() == null) {
		return null;
	}
	Resource resource = stubRunnerOptions.getStubRepositoryRoot();
	if (!(resource instanceof PactResource)) {
		return null;
	}
	return new PactStubDownloader(stubRunnerOptions);
}
 
Example #7
Source File: ContractVerifierExtension.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@Inject
public ContractVerifierExtension(ProjectLayout layout, ObjectFactory objects) {
	this.testFramework = objects.property(TestFramework.class).convention(TestFramework.JUNIT5);
	this.testMode = objects.property(TestMode.class).convention(TestMode.MOCKMVC);
	this.basePackageForTests = objects.property(String.class);
	this.baseClassForTests = objects.property(String.class);
	this.nameSuffixForTests = objects.property(String.class);
	this.ruleClassForTests = objects.property(String.class);
	this.excludedFiles = objects.listProperty(String.class).convention(new ArrayList<>());
	this.includedFiles = objects.listProperty(String.class).convention(new ArrayList<>());
	this.ignoredFiles = objects.listProperty(String.class).convention(new ArrayList<>());
	this.imports = objects.listProperty(String.class).convention(new ArrayList<>());
	this.staticImports = objects.listProperty(String.class).convention(new ArrayList<>());
	this.contractsDslDir = objects.directoryProperty().convention(layout.getProjectDirectory().dir("src/test/resources/contracts"));
	this.generatedTestSourcesDir = objects.directoryProperty().convention(layout.getBuildDirectory().dir("generated-test-sources/contracts"));
	this.generatedTestResourcesDir = objects.directoryProperty().convention(layout.getBuildDirectory().dir("generated-test-resources/contracts"));
	this.stubsOutputDir = objects.directoryProperty().convention(layout.getBuildDirectory().dir("stubs"));
	this.stubsSuffix = objects.property(String.class).convention("stubs");
	this.assertJsonSize = objects.property(Boolean.class).convention(false);
	this.failOnNoContracts = objects.property(Boolean.class).convention(true);
	this.failOnInProgress = objects.property(Boolean.class).convention(true);
	this.contractRepository = objects.newInstance(ContractRepository.class);
	this.publishStubsToScm = objects.newInstance(PublishStubsToScm.class);
	this.contractDependency = objects.newInstance(Dependency.class);
	this.contractsPath = objects.property(String.class);
	this.contractsMode = objects.property(StubRunnerProperties.StubsMode.class).convention(StubRunnerProperties.StubsMode.CLASSPATH);
	this.packageWithBaseClasses = objects.property(String.class);
	this.baseClassMappings = objects.newInstance(BaseClassMapping.class);
	this.excludeBuildFolders = objects.property(Boolean.class).convention(false);
	this.contractsSnapshotCheckSkip = objects.property(Boolean.class).convention(false);
	this.deleteStubsAfterTest = objects.property(Boolean.class).convention(true);
	this.convertToYaml = objects.property(Boolean.class).convention(false);
	this.contractsProperties = objects.mapProperty(String.class, String.class).convention(new HashMap<>());
	this.disableStubPublication = objects.property(Boolean.class).convention(false);
	this.sourceSet = objects.property(String.class);
	this.objects = objects;
}
 
Example #8
Source File: ContractProjectUpdaterTest.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@Test
public void should_push_changes_to_current_branch_using_root_credentials()
		throws Exception {
	StubRunnerOptions options = new StubRunnerOptionsBuilder()
			.withStubRepositoryRoot("file://" + this.project.getAbsolutePath() + "/")
			.withStubsMode(StubRunnerProperties.StubsMode.REMOTE).withUsername("foo")
			.withPassword("bar").build();
	ContractProjectUpdater updater = new ContractProjectUpdater(options);
	File stubs = new File(
			GitRepoTests.class.getResource("/git_samples/sample_stubs").toURI());

	updater.updateContractProject("hello-world", stubs.toPath());

	// project, not origin, cause we're making one more clone of the local copy
	try (Git git = openGitProject(this.project)) {
		RevCommit revCommit = git.log().call().iterator().next();
		then(revCommit.getShortMessage())
				.isEqualTo("Updating project [hello-world] with stubs");
		// I have no idea but the file gets deleted after pushing
		git.reset().setMode(ResetCommand.ResetType.HARD).call();
	}
	BDDAssertions.then(new File(this.project,
			"META-INF/com.example/hello-world/0.0.2/mappings/someMapping.json"))
			.exists();
	BDDAssertions.then(this.outputCapture.toString()).contains(
			"Passed username and password - will set a custom credentials provider");
}
 
Example #9
Source File: ContractProjectUpdaterTest.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@Test
public void should_push_changes_to_current_branch_using_credentials()
		throws Exception {
	StubRunnerOptions options = new StubRunnerOptionsBuilder()
			.withStubRepositoryRoot("file://" + this.project.getAbsolutePath() + "/")
			.withStubsMode(StubRunnerProperties.StubsMode.REMOTE)
			.withProperties(new HashMap<String, String>() {
				{
					put("git.username", "foo");
					put("git.password", "bar");
				}
			}).build();
	ContractProjectUpdater updater = new ContractProjectUpdater(options);
	File stubs = new File(
			GitRepoTests.class.getResource("/git_samples/sample_stubs").toURI());

	updater.updateContractProject("hello-world", stubs.toPath());

	// project, not origin, cause we're making one more clone of the local copy
	try (Git git = openGitProject(this.project)) {
		RevCommit revCommit = git.log().call().iterator().next();
		then(revCommit.getShortMessage())
				.isEqualTo("Updating project [hello-world] with stubs");
		// I have no idea but the file gets deleted after pushing
		git.reset().setMode(ResetCommand.ResetType.HARD).call();
	}
	BDDAssertions.then(new File(this.project,
			"META-INF/com.example/hello-world/0.0.2/mappings/someMapping.json"))
			.exists();
	BDDAssertions.then(this.outputCapture.toString()).contains(
			"Passed username and password - will set a custom credentials provider");
}
 
Example #10
Source File: ClasspathStubProviderTest.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@Test
public void should_return_null_if_stub_mode_is_not_classpath() {
	StubDownloader stubDownloader = new ClasspathStubProvider()
			.build(new StubRunnerOptionsBuilder()
					.withStubsMode(StubRunnerProperties.StubsMode.REMOTE).build());

	then(stubDownloader).isNull();
}
 
Example #11
Source File: GitStubDownloaderTests.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@Test
public void should_pick_release_folder_when_release_version_set()
		throws URISyntaxException {
	StubDownloaderBuilder stubDownloaderBuilder = new ScmStubDownloaderBuilder();
	StubDownloader stubDownloader = stubDownloaderBuilder
			.build(new StubRunnerOptionsBuilder()
					.withStubsMode(StubRunnerProperties.StubsMode.REMOTE)
					.withStubRepositoryRoot("git://"
							+ file("/git_samples/contract-predefined-names-git/")
									.getAbsolutePath()
							+ "/")
					.withProperties(props()).build());

	Map.Entry<StubConfiguration, File> entry = stubDownloader
			.downloadAndUnpackStubJar(new StubConfiguration(
					"com.example:beer-api-producer-external:release"));

	then(entry).isNotNull();
	then(entry.getValue().getAbsolutePath()).contains("com.example" + File.separator
			+ "beer-api-producer-external" + File.separator + "release");

	entry = stubDownloader.downloadAndUnpackStubJar(
			new StubConfiguration("com.example:beer-api-producer-external:RELEASE"));

	then(entry).isNotNull();
	then(entry.getValue().getAbsolutePath()).contains("com.example" + File.separator
			+ "beer-api-producer-external" + File.separator + "release");
}
 
Example #12
Source File: GitStubDownloaderTests.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@Test
public void should_pick_latest_build_snapshot_stubs_when_latest_version_set_and_latest_folder_exists()
		throws URISyntaxException {
	StubDownloaderBuilder stubDownloaderBuilder = new ScmStubDownloaderBuilder();
	StubDownloader stubDownloader = stubDownloaderBuilder
			.build(new StubRunnerOptionsBuilder()
					.withStubsMode(StubRunnerProperties.StubsMode.REMOTE)
					.withStubRepositoryRoot("git://"
							+ file("/git_samples/contract-predefined-names-git/")
									.getAbsolutePath()
							+ "/")
					.withProperties(props()).build());

	Map.Entry<StubConfiguration, File> entry = stubDownloader
			.downloadAndUnpackStubJar(new StubConfiguration(
					"com.example:beer-api-producer-external:+"));

	then(entry).isNotNull();
	then(entry.getValue().getAbsolutePath()).contains("com.example" + File.separator
			+ "beer-api-producer-external" + File.separator + "latest");

	entry = stubDownloader.downloadAndUnpackStubJar(
			new StubConfiguration("com.example:beer-api-producer-external:latest"));

	then(entry).isNotNull();
	then(entry.getValue().getAbsolutePath()).contains("com.example" + File.separator
			+ "beer-api-producer-external" + File.separator + "latest");

	entry = stubDownloader.downloadAndUnpackStubJar(
			new StubConfiguration("com.example:beer-api-producer-external:LATEST"));

	then(entry).isNotNull();
	then(entry.getValue().getAbsolutePath()).contains("com.example" + File.separator
			+ "beer-api-producer-external" + File.separator + "latest");
}
 
Example #13
Source File: GitStubDownloaderTests.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@Test
public void should_pick_latest_release_stubs_when_release_version_set()
		throws URISyntaxException {
	StubDownloaderBuilder stubDownloaderBuilder = new ScmStubDownloaderBuilder();
	StubDownloader stubDownloader = stubDownloaderBuilder
			.build(new StubRunnerOptionsBuilder()
					.withStubsMode(StubRunnerProperties.StubsMode.REMOTE)
					.withStubRepositoryRoot("git://"
							+ file("/git_samples/contract-git/").getAbsolutePath()
							+ "/")
					.withProperties(props()).build());

	Map.Entry<StubConfiguration, File> entry = stubDownloader
			.downloadAndUnpackStubJar(new StubConfiguration(
					"com.example:beer-api-producer-external:release"));

	then(entry).isNotNull();
	then(entry.getValue().getAbsolutePath()).contains("com.example" + File.separator
			+ "beer-api-producer-external" + File.separator + "1.0.0.RELEASE");

	entry = stubDownloader.downloadAndUnpackStubJar(
			new StubConfiguration("com.example:beer-api-producer-external:RELEASE"));

	then(entry).isNotNull();
	then(entry.getValue().getAbsolutePath()).contains("com.example" + File.separator
			+ "beer-api-producer-external" + File.separator + "1.0.0.RELEASE");
}
 
Example #14
Source File: GitStubDownloaderTests.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@Test
public void should_return_a_null_downloader_for_a_non_git_repo() {
	StubDownloaderBuilder stubDownloaderBuilder = new ScmStubDownloaderBuilder();

	StubDownloader stubDownloader = stubDownloaderBuilder
			.build(new StubRunnerOptionsBuilder()
					.withStubsMode(StubRunnerProperties.StubsMode.REMOTE)
					.withStubRepositoryRoot("http://www.foo.com/")
					.withProperties(props()).build());

	then(stubDownloader).isNull();
}
 
Example #15
Source File: GitStubDownloaderTests.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@Test
public void should_return_a_null_downloader_for_a_empty_repo() {
	StubDownloaderBuilder stubDownloaderBuilder = new ScmStubDownloaderBuilder();

	StubDownloader stubDownloader = stubDownloaderBuilder
			.build(new StubRunnerOptionsBuilder()
					.withStubsMode(StubRunnerProperties.StubsMode.REMOTE)
					.withProperties(props()).build());

	then(stubDownloader).isNull();
}
 
Example #16
Source File: GitStubDownloaderTests.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@Test
public void should_return_a_null_downloader_for_a_classptath_mode() {
	StubDownloaderBuilder stubDownloaderBuilder = new ScmStubDownloaderBuilder();

	StubDownloader stubDownloader = stubDownloaderBuilder
			.build(new StubRunnerOptionsBuilder()
					.withStubsMode(StubRunnerProperties.StubsMode.CLASSPATH)
					.withProperties(props()).build());

	then(stubDownloader).isNull();
}
 
Example #17
Source File: StubRunnerOptions.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
StubRunnerOptions(Integer minPortValue, Integer maxPortValue,
		Resource stubRepositoryRoot, StubRunnerProperties.StubsMode stubsMode,
		String stubsClassifier, Collection<StubConfiguration> dependencies,
		Map<StubConfiguration, Integer> stubIdsToPortMapping, String username,
		String password, final StubRunnerProxyOptions stubRunnerProxyOptions,
		boolean stubsPerConsumer, String consumerName, String mappingsOutputFolder,
		boolean deleteStubsAfterTest, boolean generateStubs, boolean failOnNoStubs,
		Map<String, String> properties,
		Class<? extends HttpServerStubConfigurer> httpServerStubConfigurer,
		String serverId) {
	this.minPortValue = minPortValue;
	this.maxPortValue = maxPortValue;
	this.stubRepositoryRoot = stubRepositoryRoot;
	this.stubsMode = stubsMode != null ? stubsMode
			: StubRunnerProperties.StubsMode.CLASSPATH;
	this.stubsClassifier = stubsClassifier;
	this.dependencies = dependencies;
	this.stubIdsToPortMapping = stubIdsToPortMapping;
	this.username = username;
	this.password = password;
	this.stubRunnerProxyOptions = stubRunnerProxyOptions;
	this.stubsPerConsumer = stubsPerConsumer;
	this.consumerName = consumerName;
	this.mappingsOutputFolder = mappingsOutputFolder;
	this.deleteStubsAfterTest = deleteStubsAfterTest;
	this.generateStubs = generateStubs;
	this.failOnNoStubs = failOnNoStubs;
	this.properties = properties;
	this.httpServerStubConfigurer = httpServerStubConfigurer;
	this.serverId = serverId;
}
 
Example #18
Source File: StubRunnerOptionsBuilder.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
public StubRunnerOptionsBuilder withStubsMode(String stubsMode) {
	if (stubsMode == null) {
		return this;
	}
	this.stubsMode = StubRunnerProperties.StubsMode.valueOf(stubsMode);
	return this;
}
 
Example #19
Source File: StubRunnerOptionsBuilder.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
public StubRunnerOptionsBuilder withStubsMode(
		StubRunnerProperties.StubsMode stubsMode) {
	if (stubsMode == null) {
		return this;
	}
	this.stubsMode = stubsMode;
	return this;
}
 
Example #20
Source File: AetherStubDownloader.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
public AetherStubDownloader(StubRunnerOptions stubRunnerOptions) {
	this.deleteStubsAfterTest = stubRunnerOptions.isDeleteStubsAfterTest();
	if (log.isDebugEnabled()) {
		log.debug("Will be resolving versions for the following options: ["
				+ stubRunnerOptions + "]");
	}
	this.settings = settings();
	this.remoteRepos = remoteRepositories(stubRunnerOptions);
	boolean remoteReposMissing = remoteReposMissing();
	switch (stubRunnerOptions.stubsMode) {
	case LOCAL:
		log.info("Remote repos not passed but the switch to work offline was set. "
				+ "Stubs will be used from your local Maven repository.");
		break;
	case REMOTE:
		if (remoteReposMissing) {
			throw new IllegalStateException(
					"Remote repositories for stubs are not specified and work offline flag wasn't passed");
		}
		break;
	case CLASSPATH:
		throw new UnsupportedOperationException(
				"You can't use Aether downloader when you use classpath to find stubs");
	}
	this.repositorySystem = newRepositorySystem();
	this.workOffline = stubRunnerOptions.stubsMode == StubRunnerProperties.StubsMode.LOCAL;
	this.session = newSession(this.repositorySystem, this.workOffline);
	registerShutdownHook();
}
 
Example #21
Source File: FileStubDownloader.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@Override
public StubDownloader build(StubRunnerOptions stubRunnerOptions) {
	// should work only in remote and local option
	if (stubRunnerOptions.getStubsMode() == StubRunnerProperties.StubsMode.CLASSPATH
			|| stubRunnerOptions.getStubRepositoryRoot() == null) {
		return null;
	}
	Resource resource = stubRunnerOptions.getStubRepositoryRoot();
	// we verify whether the protocol starts with `stubs://`
	if (!(resource instanceof StubsResource)) {
		return null;
	}
	return new StubsStubDownloader(stubRunnerOptions);
}
 
Example #22
Source File: ScmStubDownloaderBuilder.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@Override
public StubDownloader build(StubRunnerOptions stubRunnerOptions) {
	if (stubRunnerOptions.getStubsMode() == StubRunnerProperties.StubsMode.CLASSPATH
			|| stubRunnerOptions.getStubRepositoryRoot() == null) {
		return null;
	}
	Resource resource = stubRunnerOptions.getStubRepositoryRoot();
	if (!(resource instanceof GitResource)) {
		return null;
	}
	return new GitStubDownloader(stubRunnerOptions);
}
 
Example #23
Source File: AetherStubDownloaderBuilder.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@Override
public StubDownloader build(StubRunnerOptions stubRunnerOptions) {
	if (stubRunnerOptions.stubsMode == StubRunnerProperties.StubsMode.CLASSPATH) {
		return null;
	}
	log.info("Will download stubs and contracts via Aether");
	return new AetherStubDownloader(stubRunnerOptions);
}
 
Example #24
Source File: GitStubDownloaderTests.java    From spring-cloud-contract with Apache License 2.0 4 votes vote down vote up
@Test
public void should_pick_latest_build_snapshot_stubs_when_latest_version_set()
		throws URISyntaxException {
	StubDownloaderBuilder stubDownloaderBuilder = new ScmStubDownloaderBuilder();
	StubDownloader stubDownloader = stubDownloaderBuilder
			.build(new StubRunnerOptionsBuilder()
					.withStubsMode(StubRunnerProperties.StubsMode.REMOTE)
					.withStubRepositoryRoot("git://"
							+ file("/git_samples/contract-git/").getAbsolutePath()
							+ "/")
					.withProperties(props()).build());

	Map.Entry<StubConfiguration, File> entry = stubDownloader
			.downloadAndUnpackStubJar(new StubConfiguration(
					"com.example:beer-api-producer-external:+"));

	then(entry).isNotNull();
	then(entry.getValue().getAbsolutePath()).contains("com.example" + File.separator
			+ "beer-api-producer-external" + File.separator + "1.0.0.BUILD-SNAPSHOT");

	entry = stubDownloader.downloadAndUnpackStubJar(
			new StubConfiguration("com.example:beer-api-producer-external:latest"));

	then(entry).isNotNull();
	then(entry.getValue().getAbsolutePath()).contains("com.example" + File.separator
			+ "beer-api-producer-external" + File.separator + "1.0.0.BUILD-SNAPSHOT");

	entry = stubDownloader.downloadAndUnpackStubJar(
			new StubConfiguration("com.example:beer-api-producer-external:LATEST"));

	then(entry).isNotNull();
	then(entry.getValue().getAbsolutePath()).contains("com.example" + File.separator
			+ "beer-api-producer-external" + File.separator + "1.0.0.BUILD-SNAPSHOT");

	entry = stubDownloader.downloadAndUnpackStubJar(
			new StubConfiguration("com.issue1305:beer-api-producer-external:+"));

	then(entry).isNotNull();
	then(entry.getValue().getAbsolutePath()).contains("com.issue1305" + File.separator
			+ "beer-api-producer-external" + File.separator + "0.0.11-SNAPSHOT");
}
 
Example #25
Source File: StubRunnerOptions.java    From spring-cloud-contract with Apache License 2.0 4 votes vote down vote up
public StubRunnerProperties.StubsMode getStubsMode() {
	return this.stubsMode;
}
 
Example #26
Source File: ContractVerifierExtension.java    From spring-cloud-contract with Apache License 2.0 4 votes vote down vote up
public Property<StubRunnerProperties.StubsMode> getContractsMode() {
	return contractsMode;
}
 
Example #27
Source File: ContractVerifierExtension.java    From spring-cloud-contract with Apache License 2.0 4 votes vote down vote up
public void setContractsMode(StubRunnerProperties.StubsMode contractsMode) {
	this.contractsMode.set(contractsMode);
}
 
Example #28
Source File: ContractVerifierExtension.java    From spring-cloud-contract with Apache License 2.0 4 votes vote down vote up
public void setContractsMode(String contractsMode) {
	if (contractsMode != null) {
		this.contractsMode.set(StubRunnerProperties.StubsMode.valueOf(contractsMode.toUpperCase()));
	}
}
 
Example #29
Source File: StubRunnerMain.java    From spring-cloud-contract with Apache License 2.0 4 votes vote down vote up
private StubRunnerMain(String[] args) throws Exception {
	OptionParser parser = new OptionParser();
	try {
		ArgumentAcceptingOptionSpec<Integer> minPortValueOpt = parser.acceptsAll(
				Arrays.asList("minp", "minPort"),
				"Minimum port value to be assigned to the WireMock instance. Defaults to 10000")
				.withRequiredArg().ofType(Integer.class).defaultsTo(10000);
		ArgumentAcceptingOptionSpec<Integer> maxPortValueOpt = parser.acceptsAll(
				Arrays.asList("maxp", "maxPort"),
				"Maximum port value to be assigned to the WireMock instance. Defaults to 15000")
				.withRequiredArg().ofType(Integer.class).defaultsTo(15000);
		ArgumentAcceptingOptionSpec<String> stubsOpt = parser.acceptsAll(
				Arrays.asList("s", "stubs"),
				"Comma separated list of Ivy representation "
						+ "of jars with stubs. Eg. groupid:artifactid1,groupid2:artifactid2:classifier")
				.withRequiredArg();
		ArgumentAcceptingOptionSpec<String> classifierOpt = parser.acceptsAll(
				Arrays.asList("c", "classifier"),
				"Suffix for the jar containing stubs (e.g. 'stubs' "
						+ "if the stub jar would have a 'stubs' classifier for stubs: foobar-stubs ). Defaults to 'stubs'")
				.withRequiredArg().defaultsTo("stubs");
		ArgumentAcceptingOptionSpec<String> rootOpt = parser.acceptsAll(
				Arrays.asList("r", "root"),
				"Location of a Jar containing server where you keep "
						+ "your stubs (e.g. https://nexus.net/content/repositories/repository)")
				.withRequiredArg();
		ArgumentAcceptingOptionSpec<String> usernameOpt = parser
				.acceptsAll(Arrays.asList("u", "username"),
						"Username to user when connecting to repository")
				.withOptionalArg();
		ArgumentAcceptingOptionSpec<String> passwordOpt = parser
				.acceptsAll(Arrays.asList("p", "password"),
						"Password to user when connecting to repository")
				.withOptionalArg();
		ArgumentAcceptingOptionSpec<String> proxyHostOpt = parser
				.acceptsAll(Arrays.asList("phost", "proxyHost"),
						"Proxy host to use for repository requests")
				.withOptionalArg();
		ArgumentAcceptingOptionSpec<Integer> proxyPortOpt = parser
				.acceptsAll(Arrays.asList("pport", "proxyPort"),
						"Proxy port to use for repository requests")
				.withOptionalArg().ofType(Integer.class);
		ArgumentAcceptingOptionSpec<String> stubsMode = parser
				.acceptsAll(Arrays.asList("sm", "stubsMode"),
						"Stubs mode to be used. Acceptable values " + Arrays
								.toString(StubRunnerProperties.StubsMode.values()))
				.withRequiredArg()
				.defaultsTo(StubRunnerProperties.StubsMode.CLASSPATH.toString());
		OptionSet options = parser.parse(args);
		String stubs = options.valueOf(stubsOpt);
		StubRunnerProperties.StubsMode stubsModeValue = StubRunnerProperties.StubsMode
				.valueOf(options.valueOf(stubsMode));
		Integer minPortValue = options.valueOf(minPortValueOpt);
		Integer maxPortValue = options.valueOf(maxPortValueOpt);
		String stubRepositoryRoot = options.valueOf(rootOpt);
		String stubsSuffix = options.valueOf(classifierOpt);
		final String username = options.valueOf(usernameOpt);
		final String password = options.valueOf(passwordOpt);
		final String proxyHost = options.valueOf(proxyHostOpt);
		final Integer proxyPort = options.valueOf(proxyPortOpt);
		final StubRunnerOptionsBuilder builder = new StubRunnerOptionsBuilder()
				.withMinMaxPort(minPortValue, maxPortValue)
				.withStubRepositoryRoot(stubRepositoryRoot)
				.withStubsMode(stubsModeValue).withStubsClassifier(stubsSuffix)
				.withUsername(username).withPassword(password).withStubs(stubs);
		if (proxyHost != null) {
			builder.withProxy(proxyHost, proxyPort);
		}
		StubRunnerOptions stubRunnerOptions = builder.build();
		this.arguments = new Arguments(stubRunnerOptions);
	}
	catch (Exception e) {
		printErrorMessage(e, parser);
		throw e;
	}
}