Simplify the messaging APIs a bit
There is no need for users to know about any special contract-specific Message object (payload and headers). Once you see that, it seems like there is no need for it internally either. So this change removes the message wrapper type and cleans up the interfaces it touches.
This commit is contained in:
@@ -18,15 +18,15 @@ package com.example
|
||||
|
||||
import javax.inject.Inject
|
||||
|
||||
import org.apache.camel.Message
|
||||
import org.apache.camel.model.ModelCamelContext
|
||||
import org.junit.BeforeClass
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.context.SpringBootContextLoader
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierObjectMapper
|
||||
import org.springframework.cloud.contract.verifier.messaging.boot.AutoConfigureContractVerifierMessaging;
|
||||
import org.springframework.cloud.contract.verifier.messaging.boot.AutoConfigureContractVerifierMessaging
|
||||
import org.springframework.test.annotation.DirtiesContext
|
||||
import org.springframework.test.context.ContextConfiguration
|
||||
|
||||
@@ -46,7 +46,7 @@ import com.toomuchcoding.jsonassert.JsonAssertion
|
||||
public class CamelMessagingApplicationSpec extends Specification {
|
||||
|
||||
// ALL CASES
|
||||
@Inject ContractVerifierMessaging contractVerifierMessaging
|
||||
@Inject ContractVerifierMessaging<Message> contractVerifierMessaging
|
||||
ContractVerifierObjectMapper contractVerifierObjectMapper = new ContractVerifierObjectMapper()
|
||||
|
||||
@BeforeClass
|
||||
@@ -108,7 +108,7 @@ public class CamelMessagingApplicationSpec extends Specification {
|
||||
// generated test should look like this:
|
||||
|
||||
//given:
|
||||
ContractVerifierMessage inputMessage = contractVerifierMessaging.create(
|
||||
Message inputMessage = contractVerifierMessaging.create(
|
||||
contractVerifierObjectMapper.writeValueAsString([bookName: 'foo']),
|
||||
[sample: 'header']
|
||||
)
|
||||
@@ -141,7 +141,7 @@ public class CamelMessagingApplicationSpec extends Specification {
|
||||
// generated test should look like this:
|
||||
|
||||
//given:
|
||||
ContractVerifierMessage inputMessage = contractVerifierMessaging.create(
|
||||
Message inputMessage = contractVerifierMessaging.create(
|
||||
contractVerifierObjectMapper.writeValueAsString([bookName: 'foo']),
|
||||
[sample: 'header']
|
||||
)
|
||||
|
||||
@@ -21,10 +21,10 @@ import javax.inject.Inject
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.context.SpringBootContextLoader
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierObjectMapper
|
||||
import org.springframework.cloud.contract.verifier.messaging.boot.AutoConfigureContractVerifierMessaging;
|
||||
import org.springframework.cloud.contract.verifier.messaging.boot.AutoConfigureContractVerifierMessaging
|
||||
import org.springframework.messaging.Message
|
||||
import org.springframework.test.annotation.DirtiesContext
|
||||
import org.springframework.test.context.ContextConfiguration
|
||||
|
||||
@@ -40,7 +40,7 @@ import com.toomuchcoding.jsonassert.JsonAssertion
|
||||
public class IntegrationMessagingApplicationSpec extends Specification {
|
||||
|
||||
// ALL CASES
|
||||
@Inject ContractVerifierMessaging contractVerifierMessaging
|
||||
@Inject ContractVerifierMessaging<Message<?>> contractVerifierMessaging
|
||||
ContractVerifierObjectMapper contractVerifierObjectMapper = new ContractVerifierObjectMapper()
|
||||
|
||||
def "should work for triggered based messaging"() {
|
||||
@@ -114,7 +114,7 @@ public class IntegrationMessagingApplicationSpec extends Specification {
|
||||
// generated test should look like this:
|
||||
|
||||
//given:
|
||||
ContractVerifierMessage inputMessage = contractVerifierMessaging.create(
|
||||
Message<?> inputMessage = contractVerifierMessaging.create(
|
||||
contractVerifierObjectMapper.writeValueAsString([bookName: 'foo']),
|
||||
[sample: 'header']
|
||||
)
|
||||
@@ -147,7 +147,7 @@ public class IntegrationMessagingApplicationSpec extends Specification {
|
||||
// generated test should look like this:
|
||||
|
||||
//given:
|
||||
ContractVerifierMessage inputMessage = contractVerifierMessaging.create(
|
||||
Message<?> inputMessage = contractVerifierMessaging.create(
|
||||
contractVerifierObjectMapper.writeValueAsString([bookName: 'foo']),
|
||||
[sample: 'header']
|
||||
)
|
||||
|
||||
@@ -22,10 +22,10 @@ import org.junit.BeforeClass
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.context.SpringBootContextLoader
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierObjectMapper
|
||||
import org.springframework.cloud.contract.verifier.messaging.boot.AutoConfigureContractVerifierMessaging;
|
||||
import org.springframework.cloud.contract.verifier.messaging.boot.AutoConfigureContractVerifierMessaging
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.test.annotation.DirtiesContext
|
||||
import org.springframework.test.context.ContextConfiguration
|
||||
|
||||
@@ -45,7 +45,7 @@ import com.toomuchcoding.jsonassert.JsonAssertion
|
||||
public class SpringApplicationSpec extends Specification {
|
||||
|
||||
// ALL CASES
|
||||
@Inject ContractVerifierMessaging contractVerifierMessaging
|
||||
@Inject ContractVerifierMessaging<Message<?>> contractVerifierMessaging
|
||||
ContractVerifierObjectMapper contractVerifierObjectMapper = new ContractVerifierObjectMapper()
|
||||
|
||||
@BeforeClass
|
||||
@@ -106,7 +106,7 @@ public class SpringApplicationSpec extends Specification {
|
||||
// generated test should look like this:
|
||||
|
||||
//given:
|
||||
ContractVerifierMessage inputMessage = contractVerifierMessaging.create(
|
||||
Message<?> inputMessage = contractVerifierMessaging.create(
|
||||
contractVerifierObjectMapper.writeValueAsString([bookName: 'foo']),
|
||||
[sample: 'header']
|
||||
)
|
||||
@@ -139,7 +139,7 @@ public class SpringApplicationSpec extends Specification {
|
||||
// generated test should look like this:
|
||||
|
||||
//given:
|
||||
ContractVerifierMessage inputMessage = contractVerifierMessaging.create(
|
||||
Message<?> inputMessage = contractVerifierMessaging.create(
|
||||
contractVerifierObjectMapper.writeValueAsString([bookName: 'foo']),
|
||||
[sample: 'header']
|
||||
)
|
||||
|
||||
@@ -22,10 +22,10 @@ import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.context.SpringBootContextLoader
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierObjectMapper
|
||||
import org.springframework.cloud.contract.verifier.messaging.boot.AutoConfigureContractVerifierMessaging;
|
||||
import org.springframework.cloud.contract.verifier.messaging.boot.AutoConfigureContractVerifierMessaging
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.test.annotation.DirtiesContext
|
||||
import org.springframework.test.context.ContextConfiguration
|
||||
|
||||
@@ -45,7 +45,7 @@ import com.toomuchcoding.jsonassert.JsonAssertion
|
||||
public class StreamMessagingApplicationSpec extends Specification {
|
||||
|
||||
// ALL CASES
|
||||
@Inject ContractVerifierMessaging contractVerifierMessaging
|
||||
@Inject ContractVerifierMessaging<Message<?>> contractVerifierMessaging
|
||||
ContractVerifierObjectMapper contractVerifierObjectMapper = new ContractVerifierObjectMapper()
|
||||
|
||||
def "should work for triggered based messaging"() {
|
||||
@@ -101,7 +101,7 @@ public class StreamMessagingApplicationSpec extends Specification {
|
||||
// generated test should look like this:
|
||||
|
||||
//given:
|
||||
ContractVerifierMessage inputMessage = contractVerifierMessaging.create(
|
||||
Message<?> inputMessage = contractVerifierMessaging.create(
|
||||
contractVerifierObjectMapper.writeValueAsString([bookName: 'foo']),
|
||||
[sample: 'header']
|
||||
)
|
||||
@@ -134,7 +134,7 @@ public class StreamMessagingApplicationSpec extends Specification {
|
||||
// generated test should look like this:
|
||||
|
||||
//given:
|
||||
ContractVerifierMessage inputMessage = contractVerifierMessaging.create(
|
||||
Message<?> inputMessage = contractVerifierMessaging.create(
|
||||
contractVerifierObjectMapper.writeValueAsString([bookName: 'foo']),
|
||||
[sample: 'header']
|
||||
)
|
||||
|
||||
@@ -18,22 +18,23 @@ package org.springframework.cloud.contract.stubrunner.messaging.integration
|
||||
|
||||
import groovy.json.JsonOutput
|
||||
import groovy.json.JsonSlurper
|
||||
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
|
||||
import org.springframework.boot.test.context.SpringBootContextLoader
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.stubrunner.StubFinder
|
||||
import org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRunner;
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging
|
||||
import org.springframework.cloud.contract.verifier.messaging.boot.AutoConfigureContractVerifierMessaging;
|
||||
import org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRunner
|
||||
import org.springframework.cloud.contract.verifier.messaging.integration.ContractVerifierIntegrationMessaging
|
||||
import org.springframework.context.annotation.ComponentScan
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.context.annotation.ImportResource
|
||||
import org.springframework.messaging.Message
|
||||
import org.springframework.test.context.ContextConfiguration
|
||||
import spock.lang.Specification
|
||||
|
||||
import java.util.concurrent.TimeUnit
|
||||
import spock.lang.Specification
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
@@ -47,7 +48,7 @@ import java.util.concurrent.TimeUnit
|
||||
class IntegrationStubRunnerSpec extends Specification {
|
||||
|
||||
@Autowired StubFinder stubFinder
|
||||
@Autowired ContractVerifierMessaging messaging
|
||||
@Autowired ContractVerifierIntegrationMessaging messaging
|
||||
|
||||
def setup() {
|
||||
// ensure that message were taken from the queue
|
||||
@@ -61,7 +62,7 @@ class IntegrationStubRunnerSpec extends Specification {
|
||||
// end::client_send[]
|
||||
then:
|
||||
// tag::client_receive[]
|
||||
ContractVerifierMessage receivedMessage = messaging.receiveMessage('outputTest')
|
||||
Message<?> receivedMessage = messaging.receiveMessage('outputTest')
|
||||
// end::client_receive[]
|
||||
and:
|
||||
// tag::client_receive_message[]
|
||||
@@ -78,7 +79,7 @@ class IntegrationStubRunnerSpec extends Specification {
|
||||
// end::client_trigger[]
|
||||
then:
|
||||
// tag::client_trigger_receive[]
|
||||
ContractVerifierMessage receivedMessage = messaging.receiveMessage('outputTest')
|
||||
Message<?> receivedMessage = messaging.receiveMessage('outputTest')
|
||||
// end::client_trigger_receive[]
|
||||
and:
|
||||
// tag::client_trigger_message[]
|
||||
@@ -94,7 +95,7 @@ class IntegrationStubRunnerSpec extends Specification {
|
||||
stubFinder.trigger('org.springframework.cloud.contract.verifier.stubs:integrationService', 'return_book_1')
|
||||
// end::trigger_group_artifact[]
|
||||
then:
|
||||
ContractVerifierMessage receivedMessage = messaging.receiveMessage('outputTest')
|
||||
Message<?> receivedMessage = messaging.receiveMessage('outputTest')
|
||||
and:
|
||||
receivedMessage != null
|
||||
assertJsons(receivedMessage.payload)
|
||||
@@ -107,7 +108,7 @@ class IntegrationStubRunnerSpec extends Specification {
|
||||
stubFinder.trigger('integrationService', 'return_book_1')
|
||||
// end::trigger_artifact[]
|
||||
then:
|
||||
ContractVerifierMessage receivedMessage = messaging.receiveMessage('outputTest')
|
||||
Message<?> receivedMessage = messaging.receiveMessage('outputTest')
|
||||
and:
|
||||
receivedMessage != null
|
||||
assertJsons(receivedMessage.payload)
|
||||
@@ -134,7 +135,7 @@ class IntegrationStubRunnerSpec extends Specification {
|
||||
stubFinder.trigger()
|
||||
// end::trigger_all[]
|
||||
then:
|
||||
ContractVerifierMessage receivedMessage = messaging.receiveMessage('outputTest')
|
||||
Message<?> receivedMessage = messaging.receiveMessage('outputTest')
|
||||
and:
|
||||
receivedMessage != null
|
||||
assertJsons(receivedMessage.payload)
|
||||
@@ -154,7 +155,7 @@ class IntegrationStubRunnerSpec extends Specification {
|
||||
when:
|
||||
messaging.send(new BookReturned('not_matching'), [wrong: 'header_value'], 'input')
|
||||
then:
|
||||
ContractVerifierMessage receivedMessage = messaging.receiveMessage('outputTest', 100, TimeUnit.MILLISECONDS)
|
||||
Message<?> receivedMessage = messaging.receiveMessage('outputTest', 100, TimeUnit.MILLISECONDS)
|
||||
and:
|
||||
receivedMessage == null
|
||||
}
|
||||
|
||||
@@ -18,24 +18,25 @@ package org.springframework.cloud.contract.stubrunner.messaging.stream
|
||||
|
||||
import groovy.json.JsonOutput
|
||||
import groovy.json.JsonSlurper
|
||||
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
|
||||
import org.springframework.boot.test.context.SpringBootContextLoader
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.stubrunner.StubFinder
|
||||
import org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRunner;
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage
|
||||
import org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRunner
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging
|
||||
import org.springframework.cloud.contract.verifier.messaging.boot.AutoConfigureContractVerifierMessaging;
|
||||
import org.springframework.cloud.stream.annotation.EnableBinding
|
||||
import org.springframework.cloud.stream.messaging.Sink
|
||||
import org.springframework.cloud.stream.messaging.Source
|
||||
import org.springframework.context.annotation.ComponentScan
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.messaging.Message
|
||||
import org.springframework.test.context.ContextConfiguration
|
||||
import spock.lang.Specification
|
||||
|
||||
import java.util.concurrent.TimeUnit
|
||||
import spock.lang.Specification
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
@@ -49,7 +50,7 @@ import java.util.concurrent.TimeUnit
|
||||
class StreamStubRunnerSpec extends Specification {
|
||||
|
||||
@Autowired StubFinder stubFinder
|
||||
@Autowired ContractVerifierMessaging messaging
|
||||
@Autowired ContractVerifierMessaging<Message<?>> messaging
|
||||
|
||||
def setup() {
|
||||
// ensure that message were taken from the queue
|
||||
@@ -63,7 +64,7 @@ class StreamStubRunnerSpec extends Specification {
|
||||
// end::client_send[]
|
||||
then:
|
||||
// tag::client_receive[]
|
||||
ContractVerifierMessage receivedMessage = messaging.receiveMessage('returnBook')
|
||||
Message<?> receivedMessage = messaging.receiveMessage('returnBook')
|
||||
// end::client_receive[]
|
||||
and:
|
||||
// tag::client_receive_message[]
|
||||
@@ -80,7 +81,7 @@ class StreamStubRunnerSpec extends Specification {
|
||||
// end::client_trigger[]
|
||||
then:
|
||||
// tag::client_trigger_receive[]
|
||||
ContractVerifierMessage receivedMessage = messaging.receiveMessage('returnBook')
|
||||
Message<?> receivedMessage = messaging.receiveMessage('returnBook')
|
||||
// end::client_trigger_receive[]
|
||||
and:
|
||||
// tag::client_trigger_message[]
|
||||
@@ -96,7 +97,7 @@ class StreamStubRunnerSpec extends Specification {
|
||||
stubFinder.trigger('org.springframework.cloud.contract.verifier.stubs:streamService', 'return_book_1')
|
||||
// end::trigger_group_artifact[]
|
||||
then:
|
||||
ContractVerifierMessage receivedMessage = messaging.receiveMessage('returnBook')
|
||||
Message<?> receivedMessage = messaging.receiveMessage('returnBook')
|
||||
and:
|
||||
receivedMessage != null
|
||||
assertJsons(receivedMessage.payload)
|
||||
@@ -109,7 +110,7 @@ class StreamStubRunnerSpec extends Specification {
|
||||
stubFinder.trigger('streamService', 'return_book_1')
|
||||
// end::trigger_artifact[]
|
||||
then:
|
||||
ContractVerifierMessage receivedMessage = messaging.receiveMessage('returnBook')
|
||||
Message<?> receivedMessage = messaging.receiveMessage('returnBook')
|
||||
and:
|
||||
receivedMessage != null
|
||||
assertJsons(receivedMessage.payload)
|
||||
@@ -136,7 +137,7 @@ class StreamStubRunnerSpec extends Specification {
|
||||
stubFinder.trigger()
|
||||
// end::trigger_all[]
|
||||
then:
|
||||
ContractVerifierMessage receivedMessage = messaging.receiveMessage('returnBook')
|
||||
Message<?> receivedMessage = messaging.receiveMessage('returnBook')
|
||||
and:
|
||||
receivedMessage != null
|
||||
assertJsons(receivedMessage.payload)
|
||||
@@ -156,7 +157,7 @@ class StreamStubRunnerSpec extends Specification {
|
||||
when:
|
||||
messaging.send(new BookReturned('not_matching'), [wrong: 'header_value'], 'bookStorage')
|
||||
then:
|
||||
ContractVerifierMessage receivedMessage = messaging.receiveMessage('returnBook', 100, TimeUnit.MILLISECONDS)
|
||||
Message<?> receivedMessage = messaging.receiveMessage('returnBook', 100, TimeUnit.MILLISECONDS)
|
||||
and:
|
||||
receivedMessage == null
|
||||
}
|
||||
|
||||
@@ -52,13 +52,13 @@ public class StubRunner implements StubRunning {
|
||||
|
||||
public StubRunner(StubRunnerOptions stubRunnerOptions, String repositoryPath,
|
||||
StubConfiguration stubsConfiguration,
|
||||
ContractVerifierMessaging<?, ?> contractVerifierMessaging) {
|
||||
ContractVerifierMessaging<?> contractVerifierMessaging) {
|
||||
this.stubsConfiguration = stubsConfiguration;
|
||||
this.stubRunnerOptions = stubRunnerOptions;
|
||||
this.stubRepository = new StubRepository(new File(repositoryPath));
|
||||
AvailablePortScanner portScanner = new AvailablePortScanner(
|
||||
stubRunnerOptions.getMinPortValue(), stubRunnerOptions.getMaxPortValue());
|
||||
this.localStubRunner = new StubRunnerExecutor(portScanner, (ContractVerifierMessaging<String, Object>) contractVerifierMessaging);
|
||||
this.localStubRunner = new StubRunnerExecutor(portScanner, contractVerifierMessaging);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -32,7 +32,6 @@ import org.springframework.cloud.contract.spec.internal.DslProperty;
|
||||
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.verifier.messaging.ContractVerifierMessage;
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging;
|
||||
import org.springframework.cloud.contract.verifier.messaging.noop.NoOpContractVerifierMessaging;
|
||||
import org.springframework.cloud.contract.verifier.util.BodyExtractor;
|
||||
@@ -46,11 +45,11 @@ public class StubRunnerExecutor implements StubFinder {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(StubRunnerExecutor.class);
|
||||
private final AvailablePortScanner portScanner;
|
||||
private final ContractVerifierMessaging<String, Object> contractVerifierMessaging;
|
||||
private final ContractVerifierMessaging<?> contractVerifierMessaging;
|
||||
private StubServer stubServer;
|
||||
|
||||
public StubRunnerExecutor(AvailablePortScanner portScanner,
|
||||
ContractVerifierMessaging<String, Object> contractVerifierMessaging) {
|
||||
ContractVerifierMessaging<?> contractVerifierMessaging) {
|
||||
this.portScanner = portScanner;
|
||||
this.contractVerifierMessaging = contractVerifierMessaging;
|
||||
}
|
||||
@@ -177,11 +176,10 @@ public class StubRunnerExecutor implements StubFinder {
|
||||
}
|
||||
DslProperty<?> body = outputMessage == null ? null : outputMessage.getBody();
|
||||
Headers headers = outputMessage == null ? null : outputMessage.getHeaders();
|
||||
ContractVerifierMessage<String, Object> message = contractVerifierMessaging
|
||||
.create(JsonOutput.toJson(BodyExtractor.extractClientValueFromBody(
|
||||
contractVerifierMessaging.send(
|
||||
JsonOutput.toJson(BodyExtractor.extractClientValueFromBody(
|
||||
body == null ? null : body.getClientValue())),
|
||||
headers == null ? null : headers.asStubSideMap());
|
||||
contractVerifierMessaging.send(message,
|
||||
headers == null ? null : headers.asStubSideMap(),
|
||||
outputMessage.getSentTo().getClientValue());
|
||||
}
|
||||
|
||||
|
||||
@@ -31,11 +31,11 @@ public class StubRunnerFactory {
|
||||
|
||||
private final StubRunnerOptions stubRunnerOptions;
|
||||
private final StubDownloader stubDownloader;
|
||||
private final ContractVerifierMessaging<?, ?> contractVerifierMessaging;
|
||||
private final ContractVerifierMessaging<?> contractVerifierMessaging;
|
||||
|
||||
public StubRunnerFactory(StubRunnerOptions stubRunnerOptions,
|
||||
StubDownloader stubDownloader,
|
||||
ContractVerifierMessaging<?, ?> contractVerifierMessaging) {
|
||||
ContractVerifierMessaging<?> contractVerifierMessaging) {
|
||||
this.stubRunnerOptions = stubRunnerOptions;
|
||||
this.stubDownloader = stubDownloader;
|
||||
this.contractVerifierMessaging = contractVerifierMessaging;
|
||||
|
||||
@@ -1,33 +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.verifier.messaging.ContractVerifierMessaging;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
class StubRunnerMessagingTrigger {
|
||||
|
||||
private final ContractVerifierMessaging<?,?> contractVerifierMessaging;
|
||||
|
||||
StubRunnerMessagingTrigger(ContractVerifierMessaging<?,?> contractVerifierMessaging) {
|
||||
this.contractVerifierMessaging = contractVerifierMessaging;
|
||||
}
|
||||
|
||||
// def trigger
|
||||
}
|
||||
@@ -32,13 +32,13 @@ public class StubRunnerBackupAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public ContractVerifierMessaging<?,?> noOpContractVerifierMessaging() {
|
||||
public ContractVerifierMessaging<?> noOpContractVerifierMessaging() {
|
||||
return new NoOpContractVerifierMessaging();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public ContractVerifierMessageBuilder<?,?> noOpContractVerifierMessageBuilder() {
|
||||
public ContractVerifierMessageBuilder<?> noOpContractVerifierMessageBuilder() {
|
||||
return new NoOpContractVerifierMessageBuilder();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ import org.springframework.core.io.Resource;
|
||||
public class StubRunnerConfiguration {
|
||||
|
||||
@Autowired(required = false)
|
||||
private ContractVerifierMessaging<?, ?> contractVerifierMessaging;
|
||||
private ContractVerifierMessaging<?> contractVerifierMessaging;
|
||||
@Autowired(required = false)
|
||||
private StubDownloader stubDownloader;
|
||||
@Autowired
|
||||
|
||||
@@ -17,13 +17,14 @@
|
||||
package org.springframework.cloud.contract.stubrunner
|
||||
|
||||
import groovy.json.JsonOutput
|
||||
import org.springframework.cloud.contract.stubrunner.util.StubsParser
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging
|
||||
import spock.lang.Specification
|
||||
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
import org.springframework.cloud.contract.stubrunner.util.StubsParser
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging
|
||||
|
||||
import spock.lang.Specification
|
||||
|
||||
class StubRunnerExecutorSpec extends Specification {
|
||||
|
||||
static final int MIN_PORT = 8999
|
||||
@@ -98,39 +99,34 @@ class StubRunnerExecutorSpec extends Specification {
|
||||
}
|
||||
}
|
||||
|
||||
private class AssertingContractVerifierMessaging implements ContractVerifierMessaging {
|
||||
private class AssertingContractVerifierMessaging implements ContractVerifierMessaging<Object> {
|
||||
|
||||
@Override
|
||||
void send(ContractVerifierMessage message, String destination) {
|
||||
void send(Object message, String destination) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
ContractVerifierMessage receiveMessage(String destination, long timeout, TimeUnit timeUnit) {
|
||||
Object receiveMessage(String destination, long timeout, TimeUnit timeUnit) {
|
||||
return null
|
||||
}
|
||||
|
||||
@Override
|
||||
ContractVerifierMessage receiveMessage(String destination) {
|
||||
Object receiveMessage(String destination) {
|
||||
return null
|
||||
}
|
||||
|
||||
@Override
|
||||
void send(Object o, Map headers, String destination) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
ContractVerifierMessage create(Object o, Map headers) {
|
||||
Object create(Object o, Map headers) {
|
||||
assert !(JsonOutput.toJson(o).contains("serverValue"))
|
||||
assert headers.entrySet().every { !(it.value.toString().contains("serverValue")) }
|
||||
return null
|
||||
}
|
||||
|
||||
@Override
|
||||
ContractVerifierMessage create(Object o) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,56 +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.verifier.messaging.camel;
|
||||
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage;
|
||||
import org.apache.camel.Message;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
public class CamelMessage<T> implements ContractVerifierMessage<T, Message> {
|
||||
|
||||
private final Message delegate;
|
||||
|
||||
public CamelMessage(Message delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public T getPayload() {
|
||||
return (T) delegate.getBody();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getHeaders() {
|
||||
return delegate.getHeaders();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getHeader(String key) {
|
||||
return getHeaders().get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message convert() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.cloud.contract.verifier.messaging.camel;
|
||||
|
||||
import org.apache.camel.CamelContext;
|
||||
import org.apache.camel.Message;
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessageBuilder;
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -28,12 +29,12 @@ import org.springframework.context.annotation.Configuration;
|
||||
@Configuration
|
||||
public class ContractVerifierCamelConfiguration {
|
||||
|
||||
@Bean ContractVerifierMessaging<?,?> contractVerifierMessaging(CamelContext context,
|
||||
ContractVerifierMessageBuilder<?,?> builder) {
|
||||
return new ContractVerifierCamelMessaging<>(context, builder);
|
||||
@Bean ContractVerifierMessaging<Message> contractVerifierMessaging(CamelContext context,
|
||||
ContractVerifierMessageBuilder<Message> builder) {
|
||||
return new ContractVerifierCamelMessaging(context, builder);
|
||||
}
|
||||
|
||||
@Bean ContractVerifierMessageBuilder<?,?> contractVerifierMessageBuilder() {
|
||||
return new ContractVerifierCamelMessageBuilder<>();
|
||||
@Bean ContractVerifierMessageBuilder<Message> contractVerifierMessageBuilder() {
|
||||
return new ContractVerifierCamelMessageBuilder();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,29 +20,20 @@ import java.util.Map;
|
||||
|
||||
import org.apache.camel.Message;
|
||||
import org.apache.camel.impl.DefaultMessage;
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage;
|
||||
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessageBuilder;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
public class ContractVerifierCamelMessageBuilder<T> implements
|
||||
ContractVerifierMessageBuilder<T, Message> {
|
||||
public class ContractVerifierCamelMessageBuilder implements
|
||||
ContractVerifierMessageBuilder<Message> {
|
||||
|
||||
@Override
|
||||
public ContractVerifierMessage<T, Message> create(T payload, Map<String, Object> headers) {
|
||||
public <T> Message create(T payload, Map<String, Object> headers) {
|
||||
DefaultMessage message = new DefaultMessage();
|
||||
message.setBody(payload);
|
||||
message.setHeaders(headers);
|
||||
return new CamelMessage<>(message);
|
||||
return message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContractVerifierMessage<T, Message> create(Message message) {
|
||||
if (message == null) {
|
||||
return null;
|
||||
}
|
||||
return new CamelMessage<>(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,38 +28,36 @@ 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.ContractVerifierMessageBuilder;
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage;
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessageBuilder;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@Component
|
||||
public class ContractVerifierCamelMessaging<T> implements
|
||||
ContractVerifierMessaging<T, Message> {
|
||||
public class ContractVerifierCamelMessaging implements
|
||||
ContractVerifierMessaging<Message> {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(
|
||||
ContractVerifierCamelMessaging.class);
|
||||
|
||||
private final CamelContext context;
|
||||
private final ContractVerifierMessageBuilder builder;
|
||||
private final ContractVerifierMessageBuilder<Message> builder;
|
||||
|
||||
@Autowired
|
||||
@SuppressWarnings("unchecked")
|
||||
public ContractVerifierCamelMessaging(CamelContext context, ContractVerifierMessageBuilder contractVerifierMessageBuilder) {
|
||||
public ContractVerifierCamelMessaging(CamelContext context, ContractVerifierMessageBuilder<Message> contractVerifierMessageBuilder) {
|
||||
this.context = context;
|
||||
this.builder = contractVerifierMessageBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(ContractVerifierMessage<T, Message> message, String destination) {
|
||||
public void send(Message message, String destination) {
|
||||
try {
|
||||
ProducerTemplate producerTemplate = context.createProducerTemplate();
|
||||
Exchange exchange = new DefaultExchange(context);
|
||||
exchange.setIn(message.convert());
|
||||
exchange.setIn(message);
|
||||
producerTemplate.send(destination, exchange);
|
||||
} catch (Exception e) {
|
||||
log.error("Exception occurred while trying to send a message [" + message + "] " +
|
||||
@@ -70,17 +68,17 @@ public class ContractVerifierCamelMessaging<T> implements
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void send(T payload, Map<String, Object> headers, String destination) {
|
||||
public <T> void send(T payload, Map<String, Object> headers, String destination) {
|
||||
send(builder.create(payload, headers), destination);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public ContractVerifierMessage<T, Message> receiveMessage(String destination, long timeout, TimeUnit timeUnit) {
|
||||
public Message receiveMessage(String destination, long timeout, TimeUnit timeUnit) {
|
||||
try {
|
||||
ConsumerTemplate consumerTemplate = context.createConsumerTemplate();
|
||||
Exchange exchange = consumerTemplate.receive(destination, timeUnit.toMillis(timeout));
|
||||
return builder.create(exchange.getIn());
|
||||
return exchange.getIn();
|
||||
} catch (Exception e) {
|
||||
log.error("Exception occurred while trying to read a message from " +
|
||||
" a channel with name [" + destination + "]", e);
|
||||
@@ -89,19 +87,14 @@ public class ContractVerifierCamelMessaging<T> implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContractVerifierMessage<T, Message> receiveMessage(String destination) {
|
||||
public Message receiveMessage(String destination) {
|
||||
return receiveMessage(destination, 5, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public ContractVerifierMessage<T, Message> create(T t, Map<String, Object> headers) {
|
||||
public <T> Message create(T t, Map<String, Object> headers) {
|
||||
return builder.create(t, headers);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public ContractVerifierMessage<T, Message> create(Message message) {
|
||||
return builder.create(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,15 +30,15 @@ import org.springframework.messaging.Message;
|
||||
public class ContractVerifierIntegrationConfiguration<T> {
|
||||
|
||||
@Bean
|
||||
public ContractVerifierMessaging<T, Message<T>> contractVerifierMessaging(
|
||||
public ContractVerifierMessaging<Message<?>> contractVerifierMessaging(
|
||||
ApplicationContext applicationContext,
|
||||
ContractVerifierMessageBuilder<T, Message<T>> contractVerifierMessageBuilder) {
|
||||
return new ContractVerifierIntegrationMessaging<T>(applicationContext,
|
||||
ContractVerifierMessageBuilder<Message<?>> contractVerifierMessageBuilder) {
|
||||
return new ContractVerifierIntegrationMessaging(applicationContext,
|
||||
contractVerifierMessageBuilder);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ContractVerifierMessageBuilder<T, Message<T>> contractVerifierMessageBuilder() {
|
||||
return new ContractVerifierIntegrationMessageBuilder<>();
|
||||
public ContractVerifierMessageBuilder<Message<?>> contractVerifierMessageBuilder() {
|
||||
return new ContractVerifierIntegrationMessageBuilder();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.cloud.contract.verifier.messaging.integration;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage;
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessageBuilder;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
@@ -27,19 +26,12 @@ import org.springframework.messaging.support.MessageBuilder;
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
public class ContractVerifierIntegrationMessageBuilder<T> implements
|
||||
ContractVerifierMessageBuilder<T, Message<T>> {
|
||||
public class ContractVerifierIntegrationMessageBuilder implements
|
||||
ContractVerifierMessageBuilder<Message<?>> {
|
||||
|
||||
@Override
|
||||
public ContractVerifierMessage<T, Message<T>> create(T payload, Map<String, Object> headers) {
|
||||
return new IntegrationMessage<>(MessageBuilder.createMessage(payload, new MessageHeaders(headers)));
|
||||
public <T> Message<T> create(T payload, Map<String, Object> headers) {
|
||||
return MessageBuilder.createMessage(payload, new MessageHeaders(headers));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContractVerifierMessage<T, Message<T>> create(Message<T> message) {
|
||||
if (message == null) {
|
||||
return null;
|
||||
}
|
||||
return new IntegrationMessage<>(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ 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.ContractVerifierMessage;
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessageBuilder;
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -35,31 +34,31 @@ import org.springframework.stereotype.Component;
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@Component
|
||||
public class ContractVerifierIntegrationMessaging<T> implements
|
||||
ContractVerifierMessaging<T, Message<T>> {
|
||||
public class ContractVerifierIntegrationMessaging implements
|
||||
ContractVerifierMessaging<Message<?>> {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(
|
||||
ContractVerifierIntegrationMessaging.class);
|
||||
|
||||
private final ApplicationContext context;
|
||||
private final ContractVerifierMessageBuilder<T, Message<T>> builder;
|
||||
private final ContractVerifierMessageBuilder<Message<?>> builder;
|
||||
|
||||
@Autowired
|
||||
public ContractVerifierIntegrationMessaging(ApplicationContext context, ContractVerifierMessageBuilder<T, Message<T>> contractVerifierMessageBuilder) {
|
||||
public ContractVerifierIntegrationMessaging(ApplicationContext context, ContractVerifierMessageBuilder<Message<?>> contractVerifierMessageBuilder) {
|
||||
this.context = context;
|
||||
this.builder = contractVerifierMessageBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(T payload, Map<String, Object> headers, String destination) {
|
||||
send(builder.create(payload, headers), destination);
|
||||
public <T> void send(T payload, Map<String, Object> headers, String destination) {
|
||||
send(create(payload, headers), destination);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(ContractVerifierMessage<T, Message<T>> message, String destination) {
|
||||
public void send(Message<?> message, String destination) {
|
||||
try {
|
||||
MessageChannel messageChannel = context.getBean(destination, MessageChannel.class);
|
||||
messageChannel.send(message.convert());
|
||||
messageChannel.send(message);
|
||||
} catch (Exception e) {
|
||||
log.error("Exception occurred while trying to send a message [" + message + "] " +
|
||||
"to a channel with name [" + destination + "]", e);
|
||||
@@ -68,11 +67,10 @@ public class ContractVerifierIntegrationMessaging<T> implements
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public ContractVerifierMessage<T, Message<T>> receiveMessage(String destination, long timeout, TimeUnit timeUnit) {
|
||||
public Message<?> receiveMessage(String destination, long timeout, TimeUnit timeUnit) {
|
||||
try {
|
||||
PollableChannel messageChannel = context.getBean(destination, PollableChannel.class);
|
||||
return builder.create((Message<T>) messageChannel.receive(timeUnit.toMillis(timeout)));
|
||||
return messageChannel.receive(timeUnit.toMillis(timeout));
|
||||
} catch (Exception e) {
|
||||
log.error("Exception occurred while trying to read a message from " +
|
||||
" a channel with name [" + destination + "]", e);
|
||||
@@ -81,17 +79,13 @@ public class ContractVerifierIntegrationMessaging<T> implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContractVerifierMessage<T, Message<T>> receiveMessage(String destination) {
|
||||
public Message<?> receiveMessage(String destination) {
|
||||
return receiveMessage(destination, 5, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContractVerifierMessage<T, Message<T>> create(T t, Map<String, Object> headers) {
|
||||
public <T> Message<?> create(T t, Map<String, Object> headers) {
|
||||
return builder.create(t, headers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContractVerifierMessage<T, Message<T>> create(Message<T> message) {
|
||||
return builder.create(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,54 +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.verifier.messaging.integration;
|
||||
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
public class IntegrationMessage<T> implements ContractVerifierMessage<T, Message<T>> {
|
||||
|
||||
private final Message<T> delegate;
|
||||
|
||||
public IntegrationMessage(Message<T> delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getPayload() {
|
||||
return delegate.getPayload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageHeaders getHeaders() {
|
||||
return delegate.getHeaders();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getHeader(String key) {
|
||||
return getHeaders().get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message<T> convert() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,10 +21,10 @@ package org.springframework.cloud.contract.verifier.messaging;
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
public interface ContractVerifierFilter<PAYLOAD, TYPE_TO_CONVERT_INTO> {
|
||||
public interface ContractVerifierFilter<M> {
|
||||
|
||||
/**
|
||||
* @return @{code true} if the message should be passed through, @{code false} if the message should be filtered out,
|
||||
*/
|
||||
boolean matches(ContractVerifierMessage<PAYLOAD, TYPE_TO_CONVERT_INTO> message);
|
||||
boolean matches(M message);
|
||||
}
|
||||
|
||||
@@ -1,48 +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.verifier.messaging;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Describes a message. Contains payload and headers. A message can be converted
|
||||
* to another type (e.g. Spring Messaging Message)
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
public interface ContractVerifierMessage<PAYLOAD, TYPE_TO_CONVERT_INTO> {
|
||||
|
||||
/**
|
||||
* Returns a payload of type {@code PAYLOAD}
|
||||
*/
|
||||
PAYLOAD getPayload();
|
||||
|
||||
/**
|
||||
* Returns a map of headers
|
||||
*/
|
||||
Map<String, Object> getHeaders();
|
||||
|
||||
/**
|
||||
* Returns a header for a given key
|
||||
*/
|
||||
Object getHeader(String key);
|
||||
|
||||
/**
|
||||
* Converts the message to {@code TYPE_TO_CONVERT_INTO} type
|
||||
*/
|
||||
TYPE_TO_CONVERT_INTO convert();
|
||||
}
|
||||
@@ -24,15 +24,11 @@ import java.util.Map;
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
public interface ContractVerifierMessageBuilder<PAYLOAD, TYPE_TO_CONVERT_INTO> {
|
||||
public interface ContractVerifierMessageBuilder<M> {
|
||||
|
||||
/**
|
||||
* Creates a {@link ContractVerifierMessage} from payload and headers
|
||||
*/
|
||||
ContractVerifierMessage<PAYLOAD, TYPE_TO_CONVERT_INTO> create(PAYLOAD payload, Map<String, Object> headers);
|
||||
<T> M create(T payload, Map<String, Object> headers);
|
||||
|
||||
/**
|
||||
* Creates a {@link ContractVerifierMessage} from the {@code TYPE_TO_CONVERT_INTO} type
|
||||
*/
|
||||
ContractVerifierMessage<PAYLOAD, TYPE_TO_CONVERT_INTO> create(TYPE_TO_CONVERT_INTO typeToConvertInto);
|
||||
}
|
||||
|
||||
@@ -26,26 +26,26 @@ import java.util.concurrent.TimeUnit;
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
public interface ContractVerifierMessaging<PAYLOAD, TYPE_TO_CONVERT_INTO> extends
|
||||
ContractVerifierMessageBuilder<PAYLOAD, TYPE_TO_CONVERT_INTO> {
|
||||
public interface ContractVerifierMessaging<M> extends
|
||||
ContractVerifierMessageBuilder<M> {
|
||||
/**
|
||||
* Sends the {@link ContractVerifierMessage} to the given destination.
|
||||
*/
|
||||
void send(ContractVerifierMessage<PAYLOAD, TYPE_TO_CONVERT_INTO> message, String destination);
|
||||
void send(M message, String destination);
|
||||
|
||||
/**
|
||||
* Sends the given payload with headers, to the given destination.
|
||||
*/
|
||||
void send(PAYLOAD payload, Map<String, Object> headers, String destination);
|
||||
<T> void send(T payload, Map<String, Object> headers, String destination);
|
||||
|
||||
/**
|
||||
* Receives the {@link ContractVerifierMessage} from the given destination. You can provide the timeout
|
||||
* for receiving that message.
|
||||
*/
|
||||
ContractVerifierMessage<PAYLOAD, TYPE_TO_CONVERT_INTO> receiveMessage(String destination, long timeout, TimeUnit timeUnit);
|
||||
M receiveMessage(String destination, long timeout, TimeUnit timeUnit);
|
||||
|
||||
/**
|
||||
* Receives the {@link ContractVerifierMessage} from the given destination. A default timeout will be applied.
|
||||
*/
|
||||
ContractVerifierMessage<PAYLOAD, TYPE_TO_CONVERT_INTO> receiveMessage(String destination);
|
||||
M receiveMessage(String destination);
|
||||
}
|
||||
|
||||
@@ -1,46 +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.verifier.messaging.noop;
|
||||
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
public class NoOpContractVerifierMessage implements ContractVerifierMessage {
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getHeaders() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getHeader(String key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object convert() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -18,21 +18,17 @@ package org.springframework.cloud.contract.verifier.messaging.noop;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage;
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessageBuilder;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
public class NoOpContractVerifierMessageBuilder
|
||||
implements ContractVerifierMessageBuilder {
|
||||
@Override
|
||||
public ContractVerifierMessage create(Object o, Map headers) {
|
||||
return new NoOpContractVerifierMessage();
|
||||
}
|
||||
implements ContractVerifierMessageBuilder<Object> {
|
||||
|
||||
@Override
|
||||
public ContractVerifierMessage create(Object o) {
|
||||
return new NoOpContractVerifierMessage();
|
||||
public <T> Object create(T o, Map<String, Object> headers) {
|
||||
return o;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,40 +19,33 @@ package org.springframework.cloud.contract.verifier.messaging.noop;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage;
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
public class NoOpContractVerifierMessaging implements ContractVerifierMessaging {
|
||||
public class NoOpContractVerifierMessaging implements ContractVerifierMessaging<Object> {
|
||||
@Override
|
||||
public void send(ContractVerifierMessage message, String destination) {
|
||||
|
||||
public void send(Object message, String destination) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Object payload, Map headers, String destination) {
|
||||
|
||||
public <T> void send(T payload, Map<String,Object> headers, String destination) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContractVerifierMessage receiveMessage(String destination, long timeout, TimeUnit timeUnit) {
|
||||
public Object receiveMessage(String destination, long timeout, TimeUnit timeUnit) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContractVerifierMessage receiveMessage(String destination) {
|
||||
public Object receiveMessage(String destination) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContractVerifierMessage create(Object o, Map headers) {
|
||||
return null;
|
||||
public <T> Object create(T o, Map<String, Object> headers) {
|
||||
return o;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContractVerifierMessage create(Object o) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,15 +30,15 @@ import org.springframework.messaging.Message;
|
||||
public class ContractVerifierStreamAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
ContractVerifierMessaging<?, ?> contractVerifierMessaging(
|
||||
ContractVerifierMessaging<Message<?>> contractVerifierMessaging(
|
||||
ApplicationContext applicationContext,
|
||||
ContractVerifierMessageBuilder<Object, Message<Object>> contractVerifierMessageBuilder) {
|
||||
return new ContractVerifierStreamMessaging<Object>(applicationContext,
|
||||
ContractVerifierMessageBuilder<Message<?>> contractVerifierMessageBuilder) {
|
||||
return new ContractVerifierStreamMessaging(applicationContext,
|
||||
contractVerifierMessageBuilder);
|
||||
}
|
||||
|
||||
@Bean
|
||||
ContractVerifierMessageBuilder<?, ?> contractVerifierMessageBuilder() {
|
||||
return new ContractVerifierStreamMessageBuilder<>();
|
||||
ContractVerifierMessageBuilder<Message<?>> contractVerifierMessageBuilder() {
|
||||
return new ContractVerifierStreamMessageBuilder();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,24 +23,15 @@ import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
public class ContractVerifierStreamMessageBuilder<T> implements
|
||||
ContractVerifierMessageBuilder<T, Message<T>> {
|
||||
public class ContractVerifierStreamMessageBuilder implements
|
||||
ContractVerifierMessageBuilder<Message<?>> {
|
||||
|
||||
@Override
|
||||
public ContractVerifierMessage<T, Message<T>> create(T payload, Map<String, Object> headers) {
|
||||
return new StreamMessage<>(MessageBuilder.createMessage(payload, new MessageHeaders(headers)));
|
||||
public <T> Message<?> create(T payload, Map<String, Object> headers) {
|
||||
return MessageBuilder.createMessage(payload, new MessageHeaders(headers));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContractVerifierMessage<T, Message<T>> create(Message<T> message) {
|
||||
if (message == null) {
|
||||
return null;
|
||||
}
|
||||
return new StreamMessage<>(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ 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.ContractVerifierMessage;
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessageBuilder;
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging;
|
||||
import org.springframework.cloud.stream.config.BindingProperties;
|
||||
@@ -35,32 +34,32 @@ import org.springframework.messaging.MessageChannel;
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
public class ContractVerifierStreamMessaging<T> implements
|
||||
ContractVerifierMessaging<T, Message<T>> {
|
||||
public class ContractVerifierStreamMessaging implements
|
||||
ContractVerifierMessaging<Message<?>> {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(ContractVerifierStreamMessaging.class);
|
||||
|
||||
private final ApplicationContext context;
|
||||
private final MessageCollector messageCollector;
|
||||
private final ContractVerifierMessageBuilder<T, Message<T>> builder;
|
||||
private final ContractVerifierMessageBuilder<Message<?>> builder;
|
||||
|
||||
@Autowired
|
||||
public ContractVerifierStreamMessaging(ApplicationContext context, ContractVerifierMessageBuilder<T, Message<T>> builder) {
|
||||
public ContractVerifierStreamMessaging(ApplicationContext context, ContractVerifierMessageBuilder<Message<?>> builder) {
|
||||
this.context = context;
|
||||
this.messageCollector = context.getBean(MessageCollector.class);
|
||||
this.builder = builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(T payload, Map<String, Object> headers, String destination) {
|
||||
public <T> void send(T payload, Map<String, Object> headers, String destination) {
|
||||
send(builder.create(payload, headers), destination);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(ContractVerifierMessage<T, Message<T>> message, String destination) {
|
||||
public void send(Message<?> message, String destination) {
|
||||
try {
|
||||
MessageChannel messageChannel = context.getBean(resolvedDestination(destination), MessageChannel.class);
|
||||
messageChannel.send(message.convert());
|
||||
messageChannel.send(message);
|
||||
} catch (Exception e) {
|
||||
log.error("Exception occurred while trying to send a message [" + message + "] " +
|
||||
"to a channel with name [" + destination + "]", e);
|
||||
@@ -69,11 +68,10 @@ public class ContractVerifierStreamMessaging<T> implements
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public ContractVerifierMessage<T, Message<T>> receiveMessage(String destination, long timeout, TimeUnit timeUnit) {
|
||||
public Message<?> receiveMessage(String destination, long timeout, TimeUnit timeUnit) {
|
||||
try {
|
||||
MessageChannel messageChannel = context.getBean(resolvedDestination(destination), MessageChannel.class);
|
||||
return builder.create((Message<T>) messageCollector.forChannel(messageChannel).poll(timeout, timeUnit));
|
||||
return messageCollector.forChannel(messageChannel).poll(timeout, timeUnit);
|
||||
} catch (Exception e) {
|
||||
log.error("Exception occurred while trying to read a message from " +
|
||||
" a channel with name [" + destination + "]", e);
|
||||
@@ -95,17 +93,13 @@ public class ContractVerifierStreamMessaging<T> implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContractVerifierMessage<T, Message<T>> receiveMessage(String destination) {
|
||||
public Message<?> receiveMessage(String destination) {
|
||||
return receiveMessage(destination, 5, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContractVerifierMessage<T, Message<T>> create(T t, Map<String, Object> headers) {
|
||||
public <T> Message<?> create(T t, Map<String, Object> headers) {
|
||||
return builder.create(t, headers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContractVerifierMessage<T, Message<T>> create(Message<T> message) {
|
||||
return builder.create(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,54 +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.verifier.messaging.stream;
|
||||
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
public class StreamMessage<T> implements ContractVerifierMessage<T, Message<T>> {
|
||||
|
||||
private final Message<T> delegate;
|
||||
|
||||
public StreamMessage(Message<T> delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getPayload() {
|
||||
return delegate.getPayload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageHeaders getHeaders() {
|
||||
return delegate.getHeaders();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getHeader(String key) {
|
||||
return getHeaders().get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message<T> convert() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user