Messaging polyglot support (#1472)
added support for AMQP, KAFKA and standalone options
This commit is contained in:
committed by
GitHub
parent
c5d3456d3a
commit
a915cf102b
@@ -39,7 +39,10 @@ import org.springframework.cloud.contract.spec.internal.Headers;
|
||||
import org.springframework.cloud.contract.spec.internal.OutputMessage;
|
||||
import org.springframework.cloud.contract.stubrunner.AvailablePortScanner.PortCallback;
|
||||
import org.springframework.cloud.contract.stubrunner.provider.wiremock.WireMockHttpServerStub;
|
||||
import org.springframework.cloud.contract.verifier.converter.YamlContract;
|
||||
import org.springframework.cloud.contract.verifier.converter.YamlContractConverter;
|
||||
import org.springframework.cloud.contract.verifier.messaging.MessageVerifier;
|
||||
import org.springframework.cloud.contract.verifier.messaging.internal.ContractVerifierMessageMetadata;
|
||||
import org.springframework.cloud.contract.verifier.messaging.noop.NoOpStubMessages;
|
||||
import org.springframework.cloud.contract.verifier.util.BodyExtractor;
|
||||
|
||||
@@ -61,6 +64,8 @@ class StubRunnerExecutor implements StubFinder {
|
||||
|
||||
private StubServer stubServer;
|
||||
|
||||
private final YamlContractConverter yamlContractConverter = new YamlContractConverter();
|
||||
|
||||
StubRunnerExecutor(AvailablePortScanner portScanner,
|
||||
MessageVerifier<?> contractVerifierMessaging,
|
||||
List<HttpServerStub> serverStubs) {
|
||||
@@ -251,12 +256,22 @@ class StubRunnerExecutor implements StubFinder {
|
||||
OutputMessage outputMessage = groovyDsl.getOutputMessage();
|
||||
DslProperty<?> body = outputMessage.getBody();
|
||||
Headers headers = outputMessage.getHeaders();
|
||||
List<YamlContract> yamlContracts = yamlContractConverter
|
||||
.convertTo(Collections.singleton(groovyDsl));
|
||||
YamlContract contract = yamlContracts.get(0);
|
||||
setMessageType(contract, ContractVerifierMessageMetadata.MessageType.OUTPUT);
|
||||
// TODO: Json is harcoded here
|
||||
this.contractVerifierMessaging.send(
|
||||
JsonOutput.toJson(BodyExtractor.extractClientValueFromBody(
|
||||
body == null ? null : body.getClientValue())),
|
||||
headers == null ? null : headers.asStubSideMap(),
|
||||
outputMessage.getSentTo().getClientValue());
|
||||
outputMessage.getSentTo().getClientValue(), contract);
|
||||
}
|
||||
|
||||
private void setMessageType(YamlContract contract,
|
||||
ContractVerifierMessageMetadata.MessageType output) {
|
||||
contract.metadata.put(ContractVerifierMessageMetadata.METADATA_KEY,
|
||||
new ContractVerifierMessageMetadata(output));
|
||||
}
|
||||
|
||||
private URL returnStubUrlIfMatches(boolean condition) {
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.cloud.contract.stubrunner.junit;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.cloud.contract.verifier.converter.YamlContract;
|
||||
import org.springframework.cloud.contract.verifier.messaging.MessageVerifier;
|
||||
|
||||
/**
|
||||
@@ -30,22 +31,24 @@ class ExceptionThrowingMessageVerifier implements MessageVerifier {
|
||||
private static final String EXCEPTION_MESSAGE = "Please provide a custom MessageVerifier to use this feature";
|
||||
|
||||
@Override
|
||||
public void send(Object message, String destination) {
|
||||
public void send(Object message, String destination, YamlContract contract) {
|
||||
throw new UnsupportedOperationException(EXCEPTION_MESSAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object receive(String destination, long timeout, TimeUnit timeUnit) {
|
||||
public Object receive(String destination, long timeout, TimeUnit timeUnit,
|
||||
YamlContract contract) {
|
||||
throw new UnsupportedOperationException(EXCEPTION_MESSAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object receive(String destination) {
|
||||
public Object receive(String destination, YamlContract contract) {
|
||||
throw new UnsupportedOperationException(EXCEPTION_MESSAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Object payload, Map headers, String destination) {
|
||||
public void send(Object payload, Map headers, String destination,
|
||||
YamlContract contract) {
|
||||
throw new UnsupportedOperationException(EXCEPTION_MESSAGE);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.springframework.cloud.contract.stubrunner.StubConfiguration;
|
||||
import org.springframework.cloud.contract.stubrunner.StubDownloaderBuilderProvider;
|
||||
import org.springframework.cloud.contract.stubrunner.StubRunnerOptions;
|
||||
import org.springframework.cloud.contract.stubrunner.StubRunnerOptionsBuilder;
|
||||
import org.springframework.cloud.contract.verifier.converter.YamlContract;
|
||||
import org.springframework.cloud.contract.verifier.messaging.MessageVerifier;
|
||||
import org.springframework.cloud.contract.verifier.messaging.noop.NoOpStubMessages;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -193,23 +194,25 @@ class LazyMessageVerifier implements MessageVerifier {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Object message, String destination) {
|
||||
messageVerifier().send(message, destination);
|
||||
public void send(Object message, String destination, YamlContract contract) {
|
||||
messageVerifier().send(message, destination, contract);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object receive(String destination, long timeout, TimeUnit timeUnit) {
|
||||
return messageVerifier().receive(destination, timeout, timeUnit);
|
||||
public Object receive(String destination, long timeout, TimeUnit timeUnit,
|
||||
YamlContract contract) {
|
||||
return messageVerifier().receive(destination, timeout, timeUnit, contract);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object receive(String destination) {
|
||||
return messageVerifier().receive(destination);
|
||||
public Object receive(String destination, YamlContract contract) {
|
||||
return messageVerifier().receive(destination, contract);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Object payload, Map headers, String destination) {
|
||||
messageVerifier().send(payload, headers, destination);
|
||||
public void send(Object payload, Map headers, String destination,
|
||||
YamlContract contract) {
|
||||
messageVerifier().send(payload, headers, destination, contract);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import groovy.json.JsonOutput
|
||||
import spock.lang.Specification
|
||||
|
||||
import org.springframework.cloud.contract.stubrunner.util.StubsParser
|
||||
import org.springframework.cloud.contract.verifier.converter.YamlContract
|
||||
import org.springframework.cloud.contract.verifier.messaging.MessageVerifier
|
||||
import org.springframework.util.SocketUtils
|
||||
|
||||
@@ -168,22 +169,22 @@ class StubRunnerExecutorSpec extends Specification {
|
||||
boolean called
|
||||
|
||||
@Override
|
||||
void send(Object message, String destination) {
|
||||
void send(Object message, String destination, YamlContract contract) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
Object receive(String destination, long timeout, TimeUnit timeUnit) {
|
||||
Object receive(String destination, long timeout, TimeUnit timeUnit, YamlContract contract) {
|
||||
return null
|
||||
}
|
||||
|
||||
@Override
|
||||
Object receive(String destination) {
|
||||
Object receive(String destination, YamlContract contract) {
|
||||
return null
|
||||
}
|
||||
|
||||
@Override
|
||||
void send(Object payload, Map headers, String destination) {
|
||||
void send(Object payload, Map headers, String destination, YamlContract contract) {
|
||||
this.called = true
|
||||
println "Body <${payload}>"
|
||||
assert !payload.toString().contains("cursor")
|
||||
@@ -201,23 +202,23 @@ class StubRunnerExecutorSpec extends Specification {
|
||||
private class AssertingStubMessages implements MessageVerifier<Object> {
|
||||
|
||||
@Override
|
||||
void send(Object message, String destination) {
|
||||
void send(Object message, String destination, YamlContract contract) {
|
||||
throw new UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@Override
|
||||
<T> void send(T payload, Map<String, Object> headers, String destination) {
|
||||
<T> void send(T payload, Map<String, Object> headers, String destination, YamlContract contract) {
|
||||
assert !(JsonOutput.toJson(payload).contains("serverValue"))
|
||||
assert headers.entrySet().every { !(it.value.toString().contains("serverValue")) }
|
||||
}
|
||||
|
||||
@Override
|
||||
Object receive(String destination, long timeout, TimeUnit timeUnit) {
|
||||
Object receive(String destination, long timeout, TimeUnit timeUnit, YamlContract contract) {
|
||||
throw new UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@Override
|
||||
Object receive(String destination) {
|
||||
Object receive(String destination, YamlContract contract) {
|
||||
throw new UnsupportedOperationException()
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import spock.lang.Shared
|
||||
import spock.lang.Specification
|
||||
|
||||
import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties
|
||||
import org.springframework.cloud.contract.verifier.converter.YamlContract
|
||||
import org.springframework.cloud.contract.verifier.messaging.MessageVerifier
|
||||
|
||||
/**
|
||||
@@ -68,22 +69,22 @@ class StubRunnerRuleCustomMsgVerifierSpec extends Specification {
|
||||
static class MyMessageVerifier implements MessageVerifier {
|
||||
|
||||
@Override
|
||||
void send(Object message, String destination) {
|
||||
void send(Object message, String destination, YamlContract contract) {
|
||||
throw new IllegalStateException("Failed to send a message")
|
||||
}
|
||||
|
||||
@Override
|
||||
Object receive(String destination, long timeout, TimeUnit timeUnit) {
|
||||
Object receive(String destination, long timeout, TimeUnit timeUnit, YamlContract contract) {
|
||||
throw new IllegalStateException("Failed to receive a message with timeout")
|
||||
}
|
||||
|
||||
@Override
|
||||
Object receive(String destination) {
|
||||
Object receive(String destination, YamlContract contract) {
|
||||
throw new IllegalStateException("Failed to receive a message")
|
||||
}
|
||||
|
||||
@Override
|
||||
void send(Object payload, Map headers, String destination) {
|
||||
void send(Object payload, Map headers, String destination, YamlContract contract) {
|
||||
throw new IllegalStateException("Failed to send a message with headers")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties;
|
||||
import org.springframework.cloud.contract.verifier.converter.YamlContract;
|
||||
import org.springframework.cloud.contract.verifier.messaging.MessageVerifier;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -82,22 +83,24 @@ class StubRunnerJUnit5ExtensionCustomMessageVerifierTests {
|
||||
static class MyMessageVerifier implements MessageVerifier {
|
||||
|
||||
@Override
|
||||
public void send(Object message, String destination) {
|
||||
public void send(Object message, String destination, YamlContract contract) {
|
||||
throw new IllegalStateException("Failed to send a message");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object receive(String destination, long timeout, TimeUnit timeUnit) {
|
||||
public Object receive(String destination, long timeout, TimeUnit timeUnit,
|
||||
YamlContract contract) {
|
||||
throw new IllegalStateException("Failed to receive a message with timeout");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object receive(String destination) {
|
||||
public Object receive(String destination, YamlContract contract) {
|
||||
throw new IllegalStateException("Failed to receive a message");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Object payload, Map headers, String destination) {
|
||||
public void send(Object payload, Map headers, String destination,
|
||||
YamlContract contract) {
|
||||
throw new IllegalStateException("Failed to send a message with headers");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user