Polish
This commit is contained in:
@@ -43,7 +43,7 @@ class Service {
|
||||
@Value("${app.baseUrl:http://example.org}")
|
||||
private String base;
|
||||
|
||||
private RestTemplate restTemplate;
|
||||
private final RestTemplate restTemplate;
|
||||
|
||||
public Service(RestTemplate restTemplate) {
|
||||
this.restTemplate = restTemplate;
|
||||
|
||||
@@ -43,7 +43,7 @@ class Service {
|
||||
@Value("${app.baseUrl:http://example.org}")
|
||||
private String base;
|
||||
|
||||
private RestTemplate restTemplate;
|
||||
private final RestTemplate restTemplate;
|
||||
|
||||
public Service(RestTemplate restTemplate) {
|
||||
this.restTemplate = restTemplate;
|
||||
|
||||
@@ -43,7 +43,7 @@ class Service {
|
||||
@Value("${app.baseUrl:http://example.org}")
|
||||
private String base;
|
||||
|
||||
private RestTemplate restTemplate;
|
||||
private final RestTemplate restTemplate;
|
||||
|
||||
public Service(RestTemplate restTemplate) {
|
||||
this.restTemplate = restTemplate;
|
||||
|
||||
@@ -43,7 +43,7 @@ class Service {
|
||||
@Value("${app.baseUrl:http://example.org}")
|
||||
private String base;
|
||||
|
||||
private RestTemplate restTemplate;
|
||||
private final RestTemplate restTemplate;
|
||||
|
||||
public Service(RestTemplate restTemplate) {
|
||||
this.restTemplate = restTemplate;
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@Configuration
|
||||
public class StubRunnerBackupAutoConfiguration {
|
||||
class StubRunnerBackupAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)) ?
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.apache.maven.shared.filtering.MavenResourcesFiltering;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class CopyContracts {
|
||||
class CopyContracts {
|
||||
private static final Logger log = LoggerFactory
|
||||
.getLogger(MethodHandles.lookup().lookupClass());
|
||||
private final MavenProject project;
|
||||
|
||||
@@ -20,17 +20,18 @@ import java.util.List;
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.codehaus.groovy.runtime.DefaultGroovyMethods;
|
||||
import org.codehaus.plexus.archiver.jar.Manifest;
|
||||
import org.codehaus.plexus.archiver.jar.ManifestException;
|
||||
|
||||
public class ManifestCreator {
|
||||
class ManifestCreator {
|
||||
public static Manifest createManifest(MavenProject project) throws ManifestException {
|
||||
Manifest manifest = new Manifest();
|
||||
Plugin verifierMavenPlugin = findMavenPlugin(project.getBuildPlugins());
|
||||
manifest.addConfiguredAttribute(new Manifest.Attribute(
|
||||
"Spring-Cloud-Contract-Verifier-Maven-Plugin-Version", verifierMavenPlugin.getVersion()));
|
||||
if (DefaultGroovyMethods.asBoolean(verifierMavenPlugin.getDependencies())) {
|
||||
if (verifierMavenPlugin != null) {
|
||||
manifest.addConfiguredAttribute(new Manifest.Attribute(
|
||||
"Spring-Cloud-Contract-Verifier-Maven-Plugin-Version", verifierMavenPlugin.getVersion()));
|
||||
}
|
||||
if (verifierMavenPlugin != null && !verifierMavenPlugin.getDependencies().isEmpty()) {
|
||||
Dependency verifierDependency = findVerifierDependency(verifierMavenPlugin.getDependencies());
|
||||
if (verifierDependency != null) {
|
||||
String verifierVersion = verifierDependency.getVersion();
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.springframework.cloud.contract.stubrunner.StubRunnerOptionsBuilder;
|
||||
|
||||
import static com.google.common.base.Strings.isNullOrEmpty;
|
||||
|
||||
@SuppressWarnings("FieldCanBeLocal")
|
||||
@Mojo(name = "run", requiresProject = false, requiresDependencyResolution = ResolutionScope.RUNTIME)
|
||||
public class RunMojo extends AbstractMojo {
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import groovy.transform.Canonical
|
||||
import groovy.transform.EqualsAndHashCode
|
||||
import groovy.transform.PackageScope
|
||||
import groovy.util.logging.Slf4j
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
|
||||
import org.springframework.cloud.contract.verifier.config.TestFramework
|
||||
import org.springframework.cloud.contract.verifier.file.ContractMetadata
|
||||
@@ -130,7 +131,7 @@ class SingleTestGenerator {
|
||||
@EqualsAndHashCode
|
||||
private static class ParsedDsl {
|
||||
ContractMetadata contract
|
||||
org.springframework.cloud.contract.spec.Contract groovyDsl
|
||||
Contract groovyDsl
|
||||
File stubsFile
|
||||
}
|
||||
|
||||
@@ -139,10 +140,10 @@ class SingleTestGenerator {
|
||||
}
|
||||
|
||||
private boolean isScenarioClass(Collection<ContractMetadata> listOfFiles) {
|
||||
listOfFiles.find({ it.order != null }) != null
|
||||
return listOfFiles.find({ it.order != null }) != null
|
||||
}
|
||||
|
||||
private ClassBuilder addJsonPathRelatedImports(ClassBuilder clazz) {
|
||||
private void addJsonPathRelatedImports(ClassBuilder clazz) {
|
||||
clazz.addImport(['com.jayway.jsonpath.DocumentContext',
|
||||
'com.jayway.jsonpath.JsonPath',
|
||||
])
|
||||
@@ -151,7 +152,7 @@ class SingleTestGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
private ClassBuilder addMessagingRelatedEntries(ClassBuilder clazz) {
|
||||
private void addMessagingRelatedEntries(ClassBuilder clazz) {
|
||||
clazz.addField(['@Inject ContractVerifierMessaging contractVerifierMessaging',
|
||||
'ContractVerifierObjectMapper contractVerifierObjectMapper = new ContractVerifierObjectMapper()'
|
||||
])
|
||||
|
||||
@@ -62,7 +62,7 @@ class WireMockRequestStubStrategy extends BaseWireMockStubStrategy {
|
||||
|
||||
private RequestPatternBuilder appendMethodAndUrl() {
|
||||
if(!request.method) {
|
||||
return
|
||||
return null
|
||||
}
|
||||
RequestMethod requestMethod = RequestMethod.fromString(request.method.clientValue?.toString())
|
||||
UrlPattern urlPattern = urlPattern()
|
||||
|
||||
@@ -23,7 +23,7 @@ package org.springframework.cloud.contract.verifier.util;
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public interface MethodBuffering {
|
||||
interface MethodBuffering {
|
||||
|
||||
String method();
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.apache.camel.impl.DefaultMessage;
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
public class ContractVerifierCamelMessageBuilder {
|
||||
class ContractVerifierCamelMessageBuilder {
|
||||
|
||||
public <T> Message create(T payload, Map<String, Object> headers) {
|
||||
DefaultMessage message = new DefaultMessage();
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.springframework.messaging.support.MessageBuilder;
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
public class ContractVerifierIntegrationMessageBuilder {
|
||||
class ContractVerifierIntegrationMessageBuilder {
|
||||
|
||||
public <T> Message<T> create(T payload, Map<String, Object> headers) {
|
||||
return MessageBuilder.createMessage(payload, new MessageHeaders(headers));
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.cloud.contract.verifier.messaging.MessageVerifier;
|
||||
*/
|
||||
public class ContractVerifierMessaging<M> {
|
||||
|
||||
private MessageVerifier<M> exchange;
|
||||
private final MessageVerifier<M> exchange;
|
||||
|
||||
public ContractVerifierMessaging(MessageVerifier<M> exchange) {
|
||||
this.exchange = exchange;
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.springframework.messaging.support.MessageBuilder;
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
public class ContractVerifierStreamMessageBuilder {
|
||||
class ContractVerifierStreamMessageBuilder {
|
||||
|
||||
public <T> Message<?> create(T payload, Map<String, Object> headers) {
|
||||
return MessageBuilder.createMessage(payload, new MessageHeaders(headers));
|
||||
|
||||
@@ -83,7 +83,6 @@ public class StreamStubMessages implements MessageVerifier<Message<?>> {
|
||||
private String resolvedDestination(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)) {
|
||||
@@ -95,7 +94,7 @@ public class StreamStubMessages implements MessageVerifier<Message<?>> {
|
||||
log.debug(
|
||||
"No destination named [{}] was found. Assuming that the destination equals the channel name",
|
||||
destination);
|
||||
return resolvedDestination;
|
||||
return destination;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -76,7 +76,7 @@ import io.undertow.Undertow.Builder;
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class SpringBootHttpServerFactory implements HttpServerFactory {
|
||||
class SpringBootHttpServerFactory implements HttpServerFactory {
|
||||
|
||||
@Override
|
||||
public HttpServer buildHttpServer(Options options,
|
||||
|
||||
@@ -31,7 +31,7 @@ import com.github.tomakehurst.wiremock.core.Options;
|
||||
*
|
||||
*/
|
||||
@Configuration
|
||||
public class WireMockConfiguration implements SmartLifecycle {
|
||||
class WireMockConfiguration implements SmartLifecycle {
|
||||
|
||||
private volatile boolean running;
|
||||
|
||||
|
||||
@@ -16,9 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.contract.wiremock;
|
||||
|
||||
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
|
||||
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
@@ -32,13 +29,16 @@ import org.springframework.web.client.RestTemplate;
|
||||
import com.github.tomakehurst.wiremock.common.Json;
|
||||
import com.github.tomakehurst.wiremock.stubbing.StubMapping;
|
||||
|
||||
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
|
||||
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class WireMockExpectations {
|
||||
|
||||
private PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
|
||||
private final PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
|
||||
|
||||
private String prefix = "classpath:/stubs/";
|
||||
|
||||
@@ -85,8 +85,7 @@ public class WireMockExpectations {
|
||||
}
|
||||
|
||||
public static WireMockExpectations with(RestTemplate restTemplate) {
|
||||
WireMockExpectations result = new WireMockExpectations(restTemplate);
|
||||
return result;
|
||||
return new WireMockExpectations(restTemplate);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -43,20 +43,23 @@ import com.toomuchcoding.jsonassert.JsonAssertion
|
||||
@ContextConfiguration(classes = [CamelMessagingApplication], loader = SpringBootContextLoader)
|
||||
@DirtiesContext
|
||||
@AutoConfigureMessageVerifier
|
||||
public class CamelMessagingApplicationSpec extends Specification {
|
||||
class CamelMessagingApplicationSpec extends Specification {
|
||||
|
||||
// ALL CASES
|
||||
@Autowired ModelCamelContext camelContext
|
||||
@Autowired BookDeleter bookDeleter
|
||||
@Inject MessageVerifier<Message> contractVerifierMessaging
|
||||
|
||||
ContractVerifierObjectMapper contractVerifierObjectMapper = new ContractVerifierObjectMapper()
|
||||
|
||||
|
||||
@BeforeClass
|
||||
void init() {
|
||||
static void init() {
|
||||
System.setProperty("org.apache.activemq.SERIALIZABLE_PACKAGES", "*")
|
||||
}
|
||||
|
||||
def "should work for triggered based messaging"() {
|
||||
given:
|
||||
def dsl = Contract.make {
|
||||
Contract.make {
|
||||
label 'some_label'
|
||||
input {
|
||||
triggeredBy('bookReturnedTriggered()')
|
||||
@@ -82,7 +85,7 @@ public class CamelMessagingApplicationSpec extends Specification {
|
||||
|
||||
def "should generate tests triggered by a message"() {
|
||||
given:
|
||||
def dsl = Contract.make {
|
||||
Contract.make {
|
||||
label 'some_label'
|
||||
input {
|
||||
messageFrom('jms:input')
|
||||
@@ -104,9 +107,7 @@ public class CamelMessagingApplicationSpec extends Specification {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// generated test should look like this:
|
||||
|
||||
when:
|
||||
contractVerifierMessaging.send(
|
||||
contractVerifierObjectMapper.writeValueAsString([bookName: 'foo']),
|
||||
@@ -121,7 +122,7 @@ public class CamelMessagingApplicationSpec extends Specification {
|
||||
|
||||
def "should generate tests without destination, triggered by a message"() {
|
||||
given:
|
||||
def dsl = Contract.make {
|
||||
Contract.make {
|
||||
label 'some_label'
|
||||
input {
|
||||
messageFrom('jms:delete')
|
||||
@@ -134,9 +135,7 @@ public class CamelMessagingApplicationSpec extends Specification {
|
||||
assertThat('bookWasDeleted()')
|
||||
}
|
||||
}
|
||||
|
||||
// generated test should look like this:
|
||||
|
||||
when:
|
||||
contractVerifierMessaging.send(contractVerifierObjectMapper.writeValueAsString([bookName: 'foo']),
|
||||
[sample: 'header'], 'jms:delete')
|
||||
@@ -145,11 +144,6 @@ public class CamelMessagingApplicationSpec extends Specification {
|
||||
bookWasDeleted()
|
||||
}
|
||||
|
||||
// BASE CLASS WOULD HAVE THIS:
|
||||
|
||||
@Autowired ModelCamelContext camelContext
|
||||
@Autowired BookDeleter bookDeleter
|
||||
|
||||
void bookReturnedTriggered() {
|
||||
camelContext.createProducerTemplate().sendBody('direct:start', '''{"bookName" : "foo" }''')
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ import org.springframework.messaging.support.MessageBuilder;
|
||||
|
||||
public class BookListener {
|
||||
|
||||
public AtomicBoolean bookSuccessfullyDeleted = new AtomicBoolean(false);
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(BookListener.class);
|
||||
|
||||
/**
|
||||
@@ -34,7 +36,7 @@ public class BookListener {
|
||||
* upon receiving message on the output messageFrom
|
||||
*/
|
||||
public Message<BookReturned> returnBook(BookReturned bookReturned) {
|
||||
log.info("Returning book [$bookReturned]");
|
||||
log.info("Returning book [" + bookReturned + "]");
|
||||
return MessageBuilder.withPayload(bookReturned)
|
||||
.setHeader("BOOK-NAME", bookReturned.bookName).build();
|
||||
}
|
||||
@@ -46,9 +48,7 @@ public class BookListener {
|
||||
* upon receiving message on the output messageFrom
|
||||
*/
|
||||
public void bookDeleted(BookDeleted bookDeleted) {
|
||||
log.info("Deleting book [$bookDeleted]");
|
||||
bookSuccessfulyDeleted.set(true);
|
||||
log.info("Deleting book [ "+ bookDeleted + "]");
|
||||
bookSuccessfullyDeleted.set(true);
|
||||
}
|
||||
|
||||
public AtomicBoolean bookSuccessfulyDeleted = new AtomicBoolean(false);
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ public class IntegrationMessagingApplicationSpec extends Specification {
|
||||
}
|
||||
|
||||
void bookWasDeleted() {
|
||||
assert bookListener.bookSuccessfulyDeleted.get()
|
||||
assert bookListener.bookSuccessfullyDeleted.get()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,7 +25,7 @@ import org.springframework.messaging.SubscribableChannel;
|
||||
*/
|
||||
interface DeleteSink extends Sink {
|
||||
|
||||
static String INPUT = "delete";
|
||||
String INPUT = "delete";
|
||||
|
||||
@Input(DeleteSink.INPUT)
|
||||
SubscribableChannel delete();
|
||||
|
||||
Reference in New Issue
Block a user