Revert "Merge branch 'master' into 2.0.x"
This reverts commit63a1981f54, reversing changes made to0cca942e86.
This commit is contained in:
@@ -391,7 +391,6 @@ abstract class MethodBodyBuilder {
|
||||
protected void methodForEqualityCheck(BodyMatcher bodyMatcher, BlockBuilder bb, Object copiedBody) {
|
||||
String path = quotedAndEscaped(bodyMatcher.path())
|
||||
Object retrievedValue = value(copiedBody, bodyMatcher)
|
||||
retrievedValue = retrievedValue instanceof Pattern ? ((Pattern) retrievedValue).pattern() : retrievedValue
|
||||
String valueAsParam = retrievedValue instanceof String ? quotedAndEscaped(retrievedValue.toString()) : retrievedValue.toString()
|
||||
if (arrayRelated(path) && MatchingType.regexRelated(bodyMatcher.matchingType())) {
|
||||
buildCustomMatchingConditionForEachElement(bb, path, valueAsParam)
|
||||
|
||||
@@ -96,7 +96,9 @@ abstract class BaseWireMockStubStrategy {
|
||||
*/
|
||||
String parseBody(Map map, ContentType contentType) {
|
||||
def transformedMap = MapConverter.getStubSideValues(map)
|
||||
transformedMap = transformMapIfRequestPresent(transformedMap)
|
||||
String responseSideBody = toJson(MapConverter.getTestSideValues(contract.request.body))
|
||||
DocumentContext context = JsonPath.parse(responseSideBody)
|
||||
transformedMap = processEntriesForTemplating(transformedMap, context)
|
||||
String json = toJson(transformedMap)
|
||||
// the space is important cause at the end of the json body you also have a }
|
||||
// you can't have 4 } next to each other
|
||||
@@ -104,17 +106,6 @@ abstract class BaseWireMockStubStrategy {
|
||||
return parseBody(unquotedJson, contentType)
|
||||
}
|
||||
|
||||
private Object transformMapIfRequestPresent(Object transformedMap) {
|
||||
def requestBody = contract.request.body
|
||||
if (requestBody == null) {
|
||||
return transformedMap
|
||||
}
|
||||
String testSideBody = toJson(
|
||||
MapConverter.getTestSideValues(requestBody))
|
||||
DocumentContext context = JsonPath.parse(testSideBody)
|
||||
return processEntriesForTemplating(transformedMap, context)
|
||||
}
|
||||
|
||||
private Object processEntriesForTemplating(transformedMap, DocumentContext context) {
|
||||
return transformValues(transformedMap, {
|
||||
if (it instanceof String && processor.containsJsonPathTemplateEntry(it)) {
|
||||
|
||||
@@ -94,17 +94,15 @@ class ContractFileScanner {
|
||||
if (!files) {
|
||||
return
|
||||
}
|
||||
File[] sortedFiles = files.sort() as File[]
|
||||
for (int i = 0; i < sortedFiles.length; i++) {
|
||||
File file = sortedFiles[i]
|
||||
files.sort().eachWithIndex { File file, int index ->
|
||||
boolean excluded = matchesPattern(file, excludeMatchers)
|
||||
if (!excluded) {
|
||||
boolean contractFile = isContractFile(file)
|
||||
boolean included = includeMatcher ? file.absolutePath.matches(includeMatcher) : true
|
||||
if (contractFile && included) {
|
||||
addContractToTestGeneration(result, files, file, i, ContractVerifierDslConverter.convertAsCollection(baseDir, file))
|
||||
addContractToTestGeneration(result, files, file, index, ContractVerifierDslConverter.convertAsCollection(baseDir, file))
|
||||
} else if (!contractFile && included) {
|
||||
addContractToTestGeneration(converters, result, files, file, i)
|
||||
addContractToTestGeneration(converters, result, files, file, index)
|
||||
} else {
|
||||
appendRecursively(file, result)
|
||||
if (log.isDebugEnabled()) {
|
||||
|
||||
@@ -64,9 +64,8 @@ public class SpringAmqpStubMessages implements
|
||||
|
||||
@Autowired
|
||||
public SpringAmqpStubMessages(RabbitTemplate rabbitTemplate, MessageListenerAccessor messageListenerAccessor) {
|
||||
Assert.notNull(rabbitTemplate, "RabbitTemplate must be set");
|
||||
Assert.isTrue(mockingDetails(rabbitTemplate).isSpy() || mockingDetails(rabbitTemplate).isMock(),
|
||||
"StubRunner AMQP will work only if RabbiTemplate is a spy"); //we get send messages by capturing arguments on the spy
|
||||
Assert.notNull(rabbitTemplate);
|
||||
Assert.isTrue(mockingDetails(rabbitTemplate).isSpy() || mockingDetails(rabbitTemplate).isMock()); //we get send messages by capturing arguments on the spy
|
||||
this.rabbitTemplate = rabbitTemplate;
|
||||
this.messageListenerAccessor = messageListenerAccessor;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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 org.springframework.cloud.contract.verifier.messaging.camel;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.camel.CamelContext;
|
||||
import org.apache.camel.ConsumerTemplate;
|
||||
import org.apache.camel.Exchange;
|
||||
import org.apache.camel.Message;
|
||||
import org.apache.camel.ProducerTemplate;
|
||||
import org.apache.camel.impl.DefaultExchange;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.contract.verifier.messaging.MessageVerifier;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@Component
|
||||
public class CamelStubMessages implements MessageVerifier<Message> {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(
|
||||
CamelStubMessages.class);
|
||||
|
||||
private final CamelContext context;
|
||||
private final ContractVerifierCamelMessageBuilder builder = new ContractVerifierCamelMessageBuilder();
|
||||
|
||||
@Autowired
|
||||
public CamelStubMessages(CamelContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Message message, String destination) {
|
||||
try {
|
||||
ProducerTemplate producerTemplate = this.context.createProducerTemplate();
|
||||
Exchange exchange = new DefaultExchange(this.context);
|
||||
exchange.setIn(message);
|
||||
producerTemplate.send(destination, exchange);
|
||||
} catch (Exception e) {
|
||||
log.error("Exception occurred while trying to send a message [" + message + "] " +
|
||||
"to a channel with name [" + destination + "]", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void send(T payload, Map<String, Object> headers, String destination) {
|
||||
send(this.builder.create(payload, headers), destination);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message receive(String destination, long timeout, TimeUnit timeUnit) {
|
||||
try {
|
||||
ConsumerTemplate consumerTemplate = this.context.createConsumerTemplate();
|
||||
Exchange exchange = consumerTemplate.receive(destination, timeUnit.toMillis(timeout));
|
||||
return exchange.getIn();
|
||||
} catch (Exception e) {
|
||||
log.error("Exception occurred while trying to read a message from " +
|
||||
" a channel with name [" + destination + "]", e);
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message receive(String destination) {
|
||||
return receive(destination, 5, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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 org.springframework.cloud.contract.verifier.messaging.camel;
|
||||
|
||||
import org.apache.camel.CamelContext;
|
||||
import org.apache.camel.Message;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.cloud.contract.verifier.messaging.MessageVerifier;
|
||||
import org.springframework.cloud.contract.verifier.messaging.internal.ContractVerifierMessage;
|
||||
import org.springframework.cloud.contract.verifier.messaging.internal.ContractVerifierMessaging;
|
||||
import org.springframework.cloud.contract.verifier.messaging.noop.NoOpContractVerifierAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass(Message.class)
|
||||
@AutoConfigureBefore(NoOpContractVerifierAutoConfiguration.class)
|
||||
public class ContractVerifierCamelConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
MessageVerifier<Message> contractVerifierMessageExchange(
|
||||
CamelContext context) {
|
||||
return new CamelStubMessages(context);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public ContractVerifierMessaging<Message> contractVerifierMessaging(
|
||||
MessageVerifier<Message> exchange) {
|
||||
return new ContractVerifierCamelHelper(exchange);
|
||||
}
|
||||
}
|
||||
|
||||
class ContractVerifierCamelHelper extends ContractVerifierMessaging<Message> {
|
||||
|
||||
public ContractVerifierCamelHelper(
|
||||
MessageVerifier<Message> exchange) {
|
||||
super(exchange);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ContractVerifierMessage convert(Message receive) {
|
||||
return new ContractVerifierMessage(receive.getBody(), receive.getHeaders());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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 org.springframework.cloud.contract.verifier.messaging.camel;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.camel.Message;
|
||||
import org.apache.camel.impl.DefaultMessage;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
class ContractVerifierCamelMessageBuilder {
|
||||
|
||||
public <T> Message create(T payload, Map<String, Object> headers) {
|
||||
DefaultMessage message = new DefaultMessage();
|
||||
message.setBody(payload);
|
||||
message.setHeaders(headers);
|
||||
return message;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.contract.verifier.messaging.MessageVerifier;
|
||||
import org.springframework.cloud.stream.config.BindingProperties;
|
||||
import org.springframework.cloud.stream.config.BindingServiceProperties;
|
||||
@@ -40,6 +41,7 @@ public class StreamStubMessages implements MessageVerifier<Message<?>> {
|
||||
private final MessageCollector messageCollector;
|
||||
private final ContractVerifierStreamMessageBuilder builder = new ContractVerifierStreamMessageBuilder();
|
||||
|
||||
@Autowired
|
||||
public StreamStubMessages(ApplicationContext context) {
|
||||
this.context = context;
|
||||
this.messageCollector = context.getBean(MessageCollector.class);
|
||||
|
||||
@@ -4,4 +4,5 @@ org.springframework.cloud.contract.verifier.messaging.stream.ContractVerifierStr
|
||||
org.springframework.cloud.contract.verifier.messaging.integration.ContractVerifierIntegrationConfiguration,\
|
||||
org.springframework.cloud.contract.verifier.messaging.amqp.ContractVerifierAmqpAutoConfiguration,\
|
||||
org.springframework.cloud.contract.verifier.messaging.amqp.RabbitMockConnectionFactoryAutoConfiguration,\
|
||||
org.springframework.cloud.contract.verifier.messaging.camel.ContractVerifierCamelConfiguration,\
|
||||
org.springframework.cloud.contract.verifier.messaging.noop.NoOpContractVerifierAutoConfiguration
|
||||
@@ -16,20 +16,19 @@
|
||||
|
||||
package org.springframework.cloud.contract.verifier.builder
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
import org.codehaus.groovy.control.MultipleCompilationErrorsException
|
||||
import org.junit.Rule
|
||||
import spock.lang.Issue
|
||||
import spock.lang.Shared
|
||||
import spock.lang.Specification
|
||||
import spock.util.environment.RestoreSystemProperties
|
||||
|
||||
import org.springframework.boot.test.rule.OutputCapture
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
|
||||
import org.springframework.cloud.contract.verifier.dsl.WireMockStubVerifier
|
||||
import org.springframework.cloud.contract.verifier.util.SyntaxChecker
|
||||
import spock.lang.Issue
|
||||
import spock.lang.Shared
|
||||
import spock.lang.Specification
|
||||
import spock.util.environment.RestoreSystemProperties
|
||||
|
||||
import java.util.regex.Pattern
|
||||
/**
|
||||
* @author Jakub Kubrynski, codearte.io
|
||||
*/
|
||||
|
||||
@@ -406,7 +406,7 @@ class SingleTestGeneratorSpec extends Specification {
|
||||
// tag::context_path_baseclass[]
|
||||
import io.restassured.RestAssured;
|
||||
import org.junit.Before;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.boot.context.embedded.LocalServerPort;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest(classes = ContextPathTestingBaseClass.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
|
||||
@@ -1,57 +1,35 @@
|
||||
package org.springframework.cloud.contract.verifier.util
|
||||
|
||||
import java.lang.reflect.Method
|
||||
import javax.inject.Inject
|
||||
import javax.ws.rs.client.Entity
|
||||
import javax.ws.rs.client.WebTarget
|
||||
import javax.ws.rs.core.Response
|
||||
|
||||
import com.jayway.jsonpath.DocumentContext
|
||||
import com.jayway.jsonpath.JsonPath
|
||||
import com.toomuchcoding.jsonassert.JsonAssertion
|
||||
import groovy.transform.CompileStatic
|
||||
import io.restassured.RestAssured
|
||||
import io.restassured.module.mockmvc.RestAssuredMockMvc
|
||||
import io.restassured.response.ResponseOptions
|
||||
import org.codehaus.groovy.control.CompilerConfiguration
|
||||
import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer
|
||||
import org.codehaus.groovy.control.customizers.ImportCustomizer
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.mdkt.compiler.InMemoryJavaCompiler
|
||||
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.verifier.assertion.SpringCloudContractAssertions
|
||||
import org.springframework.cloud.contract.verifier.messaging.internal.ContractVerifierMessage
|
||||
import org.springframework.cloud.contract.verifier.messaging.internal.ContractVerifierMessaging
|
||||
import org.springframework.cloud.contract.verifier.messaging.internal.ContractVerifierObjectMapper
|
||||
import org.springframework.cloud.contract.verifier.messaging.util.ContractVerifierMessagingUtil
|
||||
import org.springframework.util.ReflectionUtils
|
||||
|
||||
import java.lang.reflect.Method
|
||||
|
||||
/**
|
||||
* checking the syntax of produced scripts
|
||||
*/
|
||||
@CompileStatic
|
||||
class SyntaxChecker {
|
||||
|
||||
WebTarget webTarget
|
||||
Entity entity
|
||||
|
||||
private static final String[] DEFAULT_IMPORTS = [
|
||||
Contract.name,
|
||||
ResponseOptions.name,
|
||||
"org.springframework.cloud.contract.spec.Contract",
|
||||
"io.restassured.response.ResponseOptions",
|
||||
"io.restassured.module.mockmvc.specification.*",
|
||||
"io.restassured.module.mockmvc.*",
|
||||
Test.name,
|
||||
Rule.name,
|
||||
DocumentContext.name,
|
||||
JsonPath.name,
|
||||
Inject.name,
|
||||
ContractVerifierObjectMapper.name,
|
||||
ContractVerifierMessage.name,
|
||||
ContractVerifierMessaging.name,
|
||||
WebTarget.name,
|
||||
Response.name
|
||||
"org.junit.Test",
|
||||
"org.junit.Rule",
|
||||
"com.jayway.jsonpath.DocumentContext",
|
||||
"com.jayway.jsonpath.JsonPath",
|
||||
"javax.inject.Inject",
|
||||
"org.springframework.cloud.contract.verifier.messaging.internal.ContractVerifierObjectMapper",
|
||||
"org.springframework.cloud.contract.verifier.messaging.internal.ContractVerifierMessage",
|
||||
"org.springframework.cloud.contract.verifier.messaging.internal.ContractVerifierMessaging",
|
||||
"javax.ws.rs.client.WebTarget",
|
||||
"javax.ws.rs.core.Response"
|
||||
]
|
||||
|
||||
private static final String DEFAULT_IMPORTS_AS_STRING = DEFAULT_IMPORTS.collect {
|
||||
@@ -59,13 +37,13 @@ class SyntaxChecker {
|
||||
}.join("\n")
|
||||
|
||||
private static final String STATIC_IMPORTS = [
|
||||
"${RestAssuredMockMvc.name}.given",
|
||||
"${RestAssuredMockMvc.name}.when",
|
||||
"${RestAssured.name}.*",
|
||||
"${Entity.name}.*",
|
||||
"${ContractVerifierMessagingUtil.name}.headers",
|
||||
"${JsonAssertion.name}.assertThatJson",
|
||||
"${SpringCloudContractAssertions.name}.assertThat"
|
||||
"io.restassured.module.mockmvc.RestAssuredMockMvc.given",
|
||||
"io.restassured.module.mockmvc.RestAssuredMockMvc.when",
|
||||
"io.restassured.RestAssured.*",
|
||||
"javax.ws.rs.client.Entity.*",
|
||||
"org.springframework.cloud.contract.verifier.messaging.util.ContractVerifierMessagingUtil.headers",
|
||||
"com.toomuchcoding.jsonassert.JsonAssertion.assertThatJson",
|
||||
"org.springframework.cloud.contract.verifier.assertion.SpringCloudContractAssertions.assertThat"
|
||||
].collect { "import static ${it};"}.join("\n")
|
||||
|
||||
static void tryToCompile(String builderName, String test) {
|
||||
|
||||
Reference in New Issue
Block a user