This commit is contained in:
Marcin Grzejszczak
2016-07-20 19:39:01 +02:00
parent 19092baabd
commit 72e67d6397
45 changed files with 83 additions and 152 deletions

View File

@@ -68,7 +68,7 @@ class AetherFactories {
return result;
}
public static String localRepositoryDirectory() {
private static String localRepositoryDirectory() {
return System.getProperty(MAVEN_LOCAL_REPOSITORY_LOCATION, System.getProperty("user.home") + "/.m2/repository");
}

View File

@@ -21,9 +21,8 @@ package org.springframework.cloud.contract.stubrunner;
*
* @see StubRunner
*/
public class Arguments {
class Arguments {
final private StubRunnerOptions stubRunnerOptions;
final private String context;
final private String repositoryPath;
final private StubConfiguration stub;
@@ -35,7 +34,6 @@ public class Arguments {
StubConfiguration stub) {
this.stubRunnerOptions = stubRunnerOptions;
this.repositoryPath = repositoryPath == null ? "" : repositoryPath;
this.context = null; // eh?
this.stub = stub;
}
@@ -43,10 +41,6 @@ public class Arguments {
return stubRunnerOptions;
}
public String getContext() {
return context;
}
public String getRepositoryPath() {
return repositoryPath;
}

View File

@@ -26,7 +26,7 @@ import org.slf4j.LoggerFactory;
/**
* Tries to execute a closure with an available port from the given range
*/
public class AvailablePortScanner {
class AvailablePortScanner {
private static final Logger log = LoggerFactory.getLogger(AvailablePortScanner.class);
@@ -89,20 +89,20 @@ public class AvailablePortScanner {
@SuppressWarnings("serial")
static class NoPortAvailableException extends RuntimeException {
protected NoPortAvailableException(int lowerBound, int upperBound) {
NoPortAvailableException(int lowerBound, int upperBound) {
super("Could not find available port in range " + lowerBound + ":" + upperBound);
}
}
@SuppressWarnings("serial")
static class InvalidPortRange extends RuntimeException {
protected InvalidPortRange(int lowerBound, int upperBound) {
InvalidPortRange(int lowerBound, int upperBound) {
super("Invalid bounds exceptions, min port [" + lowerBound
+ "] is greater to max port [" + upperBound + "]");
}
}
public static interface PortCallback<T> {
public interface PortCallback<T> {
T call(int port) throws IOException;
}
}

View File

@@ -35,10 +35,6 @@ public class BatchStubRunnerFactory {
this(stubRunnerOptions, new AetherStubDownloader(stubRunnerOptions), new NoOpStubMessages());
}
public BatchStubRunnerFactory(StubRunnerOptions stubRunnerOptions, MessageVerifier contractVerifierMessaging) {
this(stubRunnerOptions, new AetherStubDownloader(stubRunnerOptions), contractVerifierMessaging);
}
public BatchStubRunnerFactory(StubRunnerOptions stubRunnerOptions, StubDownloader stubDownloader) {
this(stubRunnerOptions, stubDownloader, new NoOpStubMessages());
}

View File

@@ -1,35 +0,0 @@
/*
* Copyright 2013-2016 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 org.springframework.cloud.contract.stubrunner;
import org.springframework.cloud.contract.spec.Contract;
/**
* @author Marcin Grzejszczak
*/
class GroovyDslWrapper {
final Contract groovyDsl;
GroovyDslWrapper(Contract groovyDsl) {
this.groovyDsl = groovyDsl;
}
boolean hasHttpPart() {
return groovyDsl.getRequest() != null;
}
}

View File

@@ -26,6 +26,4 @@ public interface StubDownloader {
* If there was no artifact this method will return {@code null}.
*/
Map.Entry<StubConfiguration,File> downloadAndUnpackStubJar(StubRunnerOptions options, StubConfiguration stubConfiguration);
}

View File

@@ -37,7 +37,7 @@ import org.springframework.cloud.contract.verifier.util.ContractVerifierDslConve
/**
* Wraps the folder with WireMock mappings.
*/
public class StubRepository {
class StubRepository {
private static final Logger log = LoggerFactory.getLogger(StubRepository.class);

View File

@@ -54,7 +54,7 @@ class StubRunnerExecutor implements StubFinder {
this.contractVerifierMessaging = contractVerifierMessaging;
}
public StubRunnerExecutor(AvailablePortScanner portScanner) {
protected StubRunnerExecutor(AvailablePortScanner portScanner) {
this(portScanner, new NoOpStubMessages());
}
@@ -114,7 +114,6 @@ class StubRunnerExecutor implements StubFinder {
matchingContracts.addAll(it.getValue());
}
}
;
return triggerForDsls(matchingContracts, labelName);
}

View File

@@ -22,6 +22,7 @@ import org.kohsuke.args4j.Option;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@SuppressWarnings("FieldCanBeLocal")
public class StubRunnerMain {
private static final Logger log = LoggerFactory.getLogger(StubRunnerMain.class);

View File

@@ -30,7 +30,7 @@ class StubServer {
private static final Logger log = LoggerFactory.getLogger(StubServer.class);
private HttpServerStub httpServerStub;
private final HttpServerStub httpServerStub;
final StubConfiguration stubConfiguration;
final Collection<WiremockMappingDescriptor> mappings;
final Collection<Contract> contracts;
@@ -77,10 +77,6 @@ class StubServer {
return stubConfiguration;
}
public Collection<WiremockMappingDescriptor> getMappings() {
return mappings;
}
public Collection<Contract> getContracts() {
return contracts;
}

View File

@@ -43,7 +43,7 @@ public class StubRunnerRule implements TestRule, StubFinder {
private static final String DELIMITER = ":";
private static final String LATEST_VERSION = "+";
private StubRunnerOptionsBuilder stubRunnerOptionsBuilder = new StubRunnerOptionsBuilder(defaultStubRunnerOptions());
private final StubRunnerOptionsBuilder stubRunnerOptionsBuilder = new StubRunnerOptionsBuilder(defaultStubRunnerOptions());
private BatchStubRunner stubFinder;
@Override

View File

@@ -39,8 +39,7 @@ import com.toomuchcoding.jsonassert.JsonVerifiable;
*
* @author Marcin Grzejszczak
*/
public class StubRunnerCamelPredicate implements Predicate {
class StubRunnerCamelPredicate implements Predicate {
private final Contract groovyDsl;
private final ContractVerifierObjectMapper objectMapper = new ContractVerifierObjectMapper();

View File

@@ -34,15 +34,12 @@ import com.jayway.jsonpath.JsonPath;
import com.toomuchcoding.jsonassert.JsonAssertion;
import com.toomuchcoding.jsonassert.JsonVerifiable;
import groovy.transform.CompileStatic;
/**
* Passes through a message that matches the one defined in the DSL
*
* @author Marcin Grzejszczak
*/
@CompileStatic
public class StubRunnerIntegrationMessageSelector implements MessageSelector {
class StubRunnerIntegrationMessageSelector implements MessageSelector {
private final Contract groovyDsl;
private final ContractVerifierObjectMapper objectMapper = new ContractVerifierObjectMapper();

View File

@@ -30,7 +30,7 @@ import org.springframework.messaging.support.MessageBuilder;
*
* @author Marcin Grzejszczak
*/
public class StubRunnerIntegrationTransformer implements GenericTransformer<Message<?>, Message<?>> {
class StubRunnerIntegrationTransformer implements GenericTransformer<Message<?>, Message<?>> {
private final Contract groovyDsl;

View File

@@ -123,7 +123,6 @@ public class StubRunnerStreamConfiguration {
String destination) {
ChannelBindingServiceProperties channelBindingServiceProperties = context
.getBean(ChannelBindingServiceProperties.class);
String resolvedDestination = destination;
for (Map.Entry<String, BindingProperties> entry : channelBindingServiceProperties
.getBindings().entrySet()) {
if (entry.getValue().getDestination().equals(destination)) {
@@ -135,12 +134,11 @@ public class StubRunnerStreamConfiguration {
log.debug(
"No destination named [{}] was found. Assuming that the destination equals the channel name",
destination);
return resolvedDestination;
return destination;
}
protected static class DummyMessageHandler {
public void handle(Message<?> message) {
}
private static class DummyMessageHandler {
public void handle(Message<?> message) {}
}
static class FlowRegistrar {

View File

@@ -39,7 +39,7 @@ import com.toomuchcoding.jsonassert.JsonVerifiable;
*
* @author Marcin Grzejszczak
*/
public class StubRunnerStreamMessageSelector implements MessageSelector {
class StubRunnerStreamMessageSelector implements MessageSelector {
private final Contract groovyDsl;
private final ContractVerifierObjectMapper objectMapper = new ContractVerifierObjectMapper();
@@ -87,7 +87,7 @@ public class StubRunnerStreamMessageSelector implements MessageSelector {
String name = it.getName();
Object value = it.getClientValue();
Object valueInHeader = headers.get(name);
boolean matches = true;
boolean matches;
if (value instanceof Pattern) {
Pattern pattern = (Pattern) value;
matches = pattern.matcher(valueInHeader.toString()).matches();
@@ -95,7 +95,7 @@ public class StubRunnerStreamMessageSelector implements MessageSelector {
matches = valueInHeader!=null && valueInHeader.equals(value);
}
if (!matches) {
return matches;
return false;
}
}
return true;

View File

@@ -30,7 +30,7 @@ import org.springframework.messaging.support.MessageBuilder;
*
* @author Marcin Grzejszczak
*/
public class StubRunnerStreamTransformer implements GenericTransformer<Message<?>, Message<?>> {
class StubRunnerStreamTransformer implements GenericTransformer<Message<?>, Message<?>> {
private final Contract groovyDsl;

View File

@@ -27,7 +27,7 @@ import org.springframework.context.annotation.Configuration;
* @author Marcin Grzejszczak
*/
@Configuration
public class StubRunnerBackupAutoConfiguration {
class StubRunnerBackupAutoConfiguration {
@Bean
@ConditionalOnMissingBean

View File

@@ -38,7 +38,7 @@ import org.springframework.cloud.contract.stubrunner.util.StringUtils;
*
* @since 1.0.0
*/
public class StubRunnerDiscoveryClient implements DiscoveryClient {
class StubRunnerDiscoveryClient implements DiscoveryClient {
private final DiscoveryClient delegate;
private final StubFinder stubFinder;

View File

@@ -29,7 +29,7 @@ import org.springframework.cloud.client.ServiceInstance;
*
* @since 1.0.0
*/
public class StubRunnerServiceInstance implements ServiceInstance {
class StubRunnerServiceInstance implements ServiceInstance {
private final String serviceId;
private final String host;

View File

@@ -21,16 +21,16 @@ import java.util.Collection;
import java.util.List;
import java.util.Map;
import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ServerList;
import org.springframework.cloud.contract.stubrunner.RunningStubs;
import org.springframework.cloud.contract.stubrunner.StubConfiguration;
import org.springframework.cloud.contract.stubrunner.StubFinder;
import org.springframework.cloud.contract.stubrunner.spring.cloud.StubMapperProperties;
import org.springframework.cloud.contract.stubrunner.util.StringUtils;
import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ServerList;
/**
* Stub Runner representation of a server list
*
@@ -46,7 +46,7 @@ class StubRunnerRibbonServerList implements ServerList {
StubRunnerRibbonServerList(final StubFinder stubFinder,
final StubMapperProperties stubMapperProperties,
final IClientConfig clientConfig,
final ServerList<?> delegate) {;
final ServerList<?> delegate) {
String serviceName = clientConfig.getClientName();
String mappedServiceName = StringUtils
.hasText(stubMapperProperties.fromServiceIdToIvyNotation(serviceName)) ?

View File

@@ -22,8 +22,8 @@ package org.springframework.cloud.contract.stubrunner.util;
* @author Marcin Grzejszczak
*/
public class StringUtils {
public static final String EMPTY = "";
private static int INDEX_NOT_FOUND = -1;
private static final String EMPTY = "";
private static final int INDEX_NOT_FOUND = -1;
// Empty checks
// -----------------------------------------------------------------------
@@ -48,11 +48,11 @@ public class StringUtils {
* @param str the String to check, may be null
* @return <code>true</code> if the String is empty or null
*/
public static boolean isEmpty(String str) {
private static boolean isEmpty(String str) {
return str == null || str.length() == 0;
}
public static boolean isNotEmpty(String string) {
private static boolean isNotEmpty(String string) {
return string != null && !string.isEmpty();
}

View File

@@ -16,11 +16,9 @@
package org.springframework.cloud.contract.stubrunner.util;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -46,11 +44,6 @@ public class StubsParser {
*
* "a:b,c:d:e"
*/
public static Set<StubConfiguration> fromString(String list, String defaultClassifier) {
List<String> splitList = Arrays.asList(list.split(","));
return fromString(splitList, defaultClassifier);
}
public static Set<StubConfiguration> fromString(Collection<String> collection, String defaultClassifier) {
Set<StubConfiguration> stubs = new LinkedHashSet<>();
for (String config : collection) {
@@ -89,8 +82,8 @@ public class StubsParser {
private static class StubSpecification {
private StubConfiguration stub;
private Integer port;
private final StubConfiguration stub;
private final Integer port;
public StubSpecification(StubConfiguration stub, Integer port) {
this.stub = stub;
@@ -98,7 +91,7 @@ public class StubsParser {
}
public boolean hasPort() {
return port!=null;
return port != null;
}
private static StubSpecification parse(String id, String defaultClassifier) {