Allow empty classifier (#134)
This commit is contained in:
committed by
Marcin Grzejszczak
parent
137100c1f7
commit
ca1cb9fdf6
@@ -67,7 +67,7 @@ public class StubConfiguration {
|
||||
|
||||
private String[] parsedPathEmptyByDefault(String path, String delimiter,
|
||||
String defaultClassifier) {
|
||||
String[] splitPath = path.split(delimiter);
|
||||
String[] splitPath = path.split(delimiter, -1);
|
||||
String stubsGroupId = "";
|
||||
String stubsArtifactId = "";
|
||||
String stubsVersion = "";
|
||||
@@ -162,20 +162,20 @@ public class StubConfiguration {
|
||||
}
|
||||
|
||||
public boolean matchesIvyNotation(String ivyNotationAsString) {
|
||||
String[] strings = ivyNotationAsString.split(":");
|
||||
String[] strings = ivyNotationAsString.split(":", -1);
|
||||
if (strings.length == 1) {
|
||||
return this.artifactId.equals(ivyNotationAsString);
|
||||
}
|
||||
else if (strings.length == 2) {
|
||||
return this.groupId.equals(strings[0]) && this.artifactId.equals(strings[1]);
|
||||
if (strings.length >= 2 && !(this.groupId.equals(strings[0]) && this.artifactId.equals(strings[1]))) {
|
||||
return false;
|
||||
}
|
||||
else if (strings.length == 3) {
|
||||
return this.groupId.equals(strings[0]) && this.artifactId.equals(strings[1])
|
||||
&& (strings[2].equals(DEFAULT_VERSION) || this.version.equals(strings[2]));
|
||||
if (strings.length >= 3 && !(this.version.equals(strings[2]) || DEFAULT_VERSION.equals(strings[2]))) {
|
||||
return false;
|
||||
}
|
||||
return this.groupId.equals(strings[0]) && this.artifactId.equals(strings[1])
|
||||
&& (strings[2].equals(DEFAULT_VERSION) || this.version.equals(strings[2]))
|
||||
&& this.classifier.equals(strings[3]);
|
||||
if (strings.length == 4 && !(this.classifier.equals(strings[3]) || DEFAULT_CLASSIFIER.equals(strings[3]))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private String[] ivyNotationFrom(String ivyNotation) {
|
||||
|
||||
@@ -102,7 +102,7 @@ class StubRunnerExecutor implements StubFinder {
|
||||
|
||||
@Override
|
||||
public URL findStubUrl(String ivyNotation) {
|
||||
String[] splitString = ivyNotation.split(":");
|
||||
String[] splitString = ivyNotation.split(":", -1);
|
||||
if (splitString.length > 4) {
|
||||
throw new IllegalArgumentException("[" + ivyNotation + "] is an invalid notation. Pass [groupId]:artifactId[:version][:classifier].");
|
||||
} else if (splitString.length == 1) {
|
||||
@@ -120,8 +120,8 @@ class StubRunnerExecutor implements StubFinder {
|
||||
}
|
||||
|
||||
private boolean groupIdArtifactVersionMatches(String[] splitString) {
|
||||
return this.stubServer.stubConfiguration.artifactId.equals(splitString[0])
|
||||
&& this.stubServer.stubConfiguration.groupId.equals(splitString[1])
|
||||
return this.stubServer.stubConfiguration.groupId.equals(splitString[0])
|
||||
&& this.stubServer.stubConfiguration.artifactId.equals(splitString[1])
|
||||
&& this.stubServer.stubConfiguration.version.equals(splitString[2]);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,30 +17,32 @@
|
||||
package org.springframework.cloud.contract.stubrunner
|
||||
|
||||
import spock.lang.Specification
|
||||
import spock.lang.Unroll
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
class StubConfigurationSpec extends Specification {
|
||||
|
||||
def 'should parse ivy notation'() {
|
||||
given:
|
||||
String ivy = 'group:artifact:version:classifier'
|
||||
@Unroll
|
||||
def 'should parse (#ivy) and match ivy notation'() {
|
||||
when:
|
||||
StubConfiguration stubConfiguration = new StubConfiguration(ivy)
|
||||
then:
|
||||
stubConfiguration.artifactId == 'artifact'
|
||||
stubConfiguration.groupId == 'group'
|
||||
stubConfiguration.classifier == 'classifier'
|
||||
stubConfiguration.version == 'version'
|
||||
stubConfiguration.artifactId == artifactId
|
||||
stubConfiguration.groupId == groupId
|
||||
stubConfiguration.classifier == classifier
|
||||
stubConfiguration.version == version
|
||||
and:
|
||||
stubConfiguration.toColonSeparatedDependencyNotation() == ivyNotation
|
||||
and:
|
||||
stubConfiguration.matchesIvyNotation(ivy)
|
||||
where:
|
||||
ivy || ivyNotation | artifactId | groupId | classifier | version
|
||||
'group:artifact:version:classifier' || 'group:artifact:version:classifier' | 'artifact' | 'group' | 'classifier' | 'version'
|
||||
'group:artifact:version:' || 'group:artifact:version:' | 'artifact' | 'group' | '' | 'version'
|
||||
'group:artifact:version' || 'group:artifact:version:stubs' | 'artifact' | 'group' | 'stubs' | 'version'
|
||||
|
||||
}
|
||||
|
||||
def 'should return ivy notation'() {
|
||||
given:
|
||||
String ivy = 'group:artifact:version:classifier'
|
||||
when:
|
||||
StubConfiguration stubConfiguration = new StubConfiguration(ivy)
|
||||
then:
|
||||
stubConfiguration.toColonSeparatedDependencyNotation() == ivy
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,6 +95,24 @@ class StubRunnerExecutorSpec extends Specification {
|
||||
executor.shutdown()
|
||||
}
|
||||
|
||||
def 'should match stub with empty classifier'() {
|
||||
given:
|
||||
def stubConf = new StubConfiguration('groupX', 'artifactX', 'versionX', '')
|
||||
StubRunnerExecutor executor = new StubRunnerExecutor(portScanner)
|
||||
when:
|
||||
executor.runStubs(stubRunnerOptions, repository, stubConf)
|
||||
then:
|
||||
URL url = executor.findStubUrl('groupX:artifactX:versionX:')
|
||||
url.port >= MIN_PORT
|
||||
url.port <= MAX_PORT
|
||||
and:
|
||||
executor.findAllRunningStubs().isPresent('artifactX')
|
||||
executor.findAllRunningStubs().isPresent('groupX', 'artifactX')
|
||||
executor.findAllRunningStubs().isPresent('groupX:artifactX')
|
||||
cleanup:
|
||||
executor.shutdown()
|
||||
}
|
||||
|
||||
Map<StubConfiguration, Integer> stubIdsWithPortsFromString(String stubIdsToPortMapping) {
|
||||
return stubIdsToPortMapping.split(',').collectEntries { String entry ->
|
||||
return StubsParser.fromStringWithPort(entry)
|
||||
|
||||
Reference in New Issue
Block a user