Rebranding (#287)
This commit is contained in:
committed by
GitHub
parent
a562775980
commit
817c232d3f
@@ -1,26 +0,0 @@
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
maven {
|
||||
url "http://repo.spring.io/snapshot"
|
||||
}
|
||||
maven {
|
||||
url "http://repo.spring.io/milestone"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile project(':accurest-core')
|
||||
compile "org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}"
|
||||
compile "org.apache.camel:camel-spring-boot-starter:${camelVersion}"
|
||||
compile "org.apache.camel:camel-jms:${camelVersion}"
|
||||
compile 'org.apache.activemq:activemq-camel:5.12.1'
|
||||
compile 'org.apache.activemq:activemq-pool:5.12.1'
|
||||
compile "org.apache.camel:camel-jackson:${camelVersion}"
|
||||
|
||||
testCompile project(':accurest-messaging-root:accurest-messaging-camel')
|
||||
testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}"
|
||||
testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') {
|
||||
exclude(group: 'org.codehaus.groovy')
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package io.codearte.accurest.samples.camel
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator
|
||||
import groovy.transform.CompileStatic
|
||||
|
||||
@CompileStatic
|
||||
class BookDeleted implements Serializable {
|
||||
final String bookName
|
||||
|
||||
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
|
||||
BookDeleted(String bookName) {
|
||||
this.bookName = bookName
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package io.codearte.accurest.samples.camel
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator
|
||||
import groovy.transform.CompileStatic
|
||||
|
||||
@CompileStatic
|
||||
class BookReturned implements Serializable {
|
||||
final String bookName
|
||||
|
||||
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
|
||||
BookReturned(String bookName) {
|
||||
this.bookName = bookName
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package io.codearte.accurest.samples.camel
|
||||
|
||||
import org.springframework.boot.SpringApplication
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
|
||||
@SpringBootApplication
|
||||
class CamelMessagingApplication {
|
||||
|
||||
static void main(String[] args) {
|
||||
SpringApplication.run(CamelMessagingApplication.class, args)
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
maven {
|
||||
url "http://repo.spring.io/snapshot"
|
||||
}
|
||||
maven {
|
||||
url "http://repo.spring.io/milestone"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile project(':accurest-core')
|
||||
compile "org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}"
|
||||
compile "org.springframework.boot:spring-boot-starter-integration:${springBootVersion}"
|
||||
|
||||
testCompile project(':accurest-messaging-root:accurest-messaging-integration')
|
||||
testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}"
|
||||
testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') {
|
||||
exclude(group: 'org.codehaus.groovy')
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package io.codearte.accurest.samples.messaging
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator
|
||||
import groovy.transform.CompileStatic
|
||||
|
||||
@CompileStatic
|
||||
class BookDeleted {
|
||||
final String bookName
|
||||
|
||||
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
|
||||
BookDeleted(String bookName) {
|
||||
this.bookName = bookName
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package io.codearte.accurest.samples.messaging
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator
|
||||
import groovy.transform.CompileStatic
|
||||
|
||||
@CompileStatic
|
||||
class BookReturned {
|
||||
final String bookName
|
||||
|
||||
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
|
||||
BookReturned(String bookName) {
|
||||
this.bookName = bookName
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package io.codearte.accurest.samples.messaging
|
||||
|
||||
import org.springframework.boot.SpringApplication
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
import org.springframework.context.annotation.ImportResource
|
||||
|
||||
@SpringBootApplication
|
||||
@ImportResource("classpath*:integration-context.xml")
|
||||
class IntegrationMessagingApplication {
|
||||
|
||||
static void main(String[] args) {
|
||||
SpringApplication.run(IntegrationMessagingApplication.class, args)
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
maven {
|
||||
url "http://repo.spring.io/snapshot"
|
||||
}
|
||||
maven {
|
||||
url "http://repo.spring.io/milestone"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile project(':accurest-core')
|
||||
compile "org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}"
|
||||
compile "org.springframework:spring-jms:${springVersion}"
|
||||
|
||||
compile 'org.apache.activemq:activemq-broker:5.12.1'
|
||||
compile 'org.apache.activemq:activemq-pool:5.12.1'
|
||||
|
||||
testCompile project(':accurest-messaging-root:accurest-messaging-core')
|
||||
testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}"
|
||||
testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') {
|
||||
exclude(group: 'org.codehaus.groovy')
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package io.codearte.accurest.samples.spring
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator
|
||||
import groovy.transform.CompileStatic
|
||||
|
||||
@CompileStatic
|
||||
class BookDeleted implements Serializable {
|
||||
final String bookName
|
||||
|
||||
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
|
||||
BookDeleted(String bookName) {
|
||||
this.bookName = bookName
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package io.codearte.accurest.samples.spring
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator
|
||||
import groovy.transform.CompileStatic
|
||||
|
||||
@CompileStatic
|
||||
class BookReturned implements Serializable {
|
||||
String bookName
|
||||
|
||||
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
|
||||
BookReturned(String bookName) {
|
||||
this.bookName = bookName
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package io.codearte.accurest.samples.spring
|
||||
|
||||
import org.springframework.boot.SpringApplication
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
import org.springframework.jms.annotation.EnableJms
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableJms
|
||||
class SpringMessagingApplication {
|
||||
|
||||
static void main(String[] args) {
|
||||
SpringApplication.run(SpringMessagingApplication.class, args)
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package io.codearte.accurest.samples.spring.config
|
||||
|
||||
import io.codearte.accurest.messaging.AccurestMessage
|
||||
import io.codearte.accurest.messaging.AccurestMessageBuilder
|
||||
import org.springframework.jms.core.MessageCreator
|
||||
|
||||
import javax.jms.JMSException
|
||||
import javax.jms.Message
|
||||
import javax.jms.Session
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
public class AccurestSpringMessageBuilder<T extends Serializable> implements AccurestMessageBuilder<T, Message> {
|
||||
|
||||
@Override
|
||||
public AccurestMessage<T, Message> create(final T payload, final Map<String, Object> headers) {
|
||||
MessageCreator messageCreator = new MessageCreator() {
|
||||
@Override
|
||||
public Message createMessage(Session session) throws JMSException {
|
||||
Message message = session.createObjectMessage(payload);
|
||||
headers.entrySet().each { Map.Entry<String, Object> entry ->
|
||||
message.setObjectProperty(entry.key, entry.value)
|
||||
}
|
||||
return message
|
||||
}
|
||||
};
|
||||
|
||||
return new SpringMessage<>(messageCreator)
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccurestMessage<T, Message> create(Message message) {
|
||||
return new SpringMessage<>(message);
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
package io.codearte.accurest.samples.spring.config
|
||||
|
||||
import io.codearte.accurest.messaging.AccurestMessage
|
||||
import io.codearte.accurest.messaging.AccurestMessageBuilder
|
||||
import io.codearte.accurest.messaging.AccurestMessaging
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.jms.core.JmsTemplate
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
import javax.jms.Message
|
||||
import java.util.concurrent.TimeUnit
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@Component
|
||||
public class AccurestSpringMessaging<T> implements AccurestMessaging<T, Message> {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(AccurestSpringMessaging.class);
|
||||
|
||||
private final JmsTemplate jmsTemplate;
|
||||
private final AccurestMessageBuilder builder;
|
||||
|
||||
@Autowired
|
||||
@SuppressWarnings("unchecked")
|
||||
public AccurestSpringMessaging(AccurestMessageBuilder builder, JmsTemplate jmsTemplate) {
|
||||
this.builder = builder
|
||||
this.jmsTemplate = jmsTemplate
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void send(T payload, Map<String, Object> headers, String destination) {
|
||||
send(builder.create(payload, headers), destination);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(AccurestMessage<T, Message> message, String destination) {
|
||||
try {
|
||||
jmsTemplate.send(destination, ((SpringMessage) message).messageCreator)
|
||||
} catch (Exception e) {
|
||||
log.error("Exception occurred while trying to send a message [" + message + "] " +
|
||||
"to a channel with name [" + destination + "]", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public AccurestMessage<T, Message> receiveMessage(String destination, long timeout, TimeUnit timeUnit) {
|
||||
try {
|
||||
return builder.create(jmsTemplate.receive(destination));
|
||||
} catch (Exception e) {
|
||||
log.error("Exception occurred while trying to read a message from " +
|
||||
" a channel with name [" + destination + "]", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccurestMessage<T, Message> receiveMessage(String destination) {
|
||||
return receiveMessage(destination, 5, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public AccurestMessage<T, Message> create(T t, Map<String, Object> headers) {
|
||||
return builder.create(t, headers);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public AccurestMessage<T, Message> create(Message message) {
|
||||
return builder.create(message);
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package io.codearte.accurest.samples.spring.config
|
||||
|
||||
import io.codearte.accurest.messaging.AccurestMessaging
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.jms.core.JmsTemplate
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@Configuration
|
||||
class ManualAccurestConfiguration {
|
||||
|
||||
@Bean
|
||||
AccurestMessaging accurestMessaging(JmsTemplate jmsTemplate) {
|
||||
return new AccurestSpringMessaging(new AccurestSpringMessageBuilder(), jmsTemplate);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
maven {
|
||||
url "http://repo.spring.io/snapshot"
|
||||
}
|
||||
maven {
|
||||
url "http://repo.spring.io/milestone"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile project(':accurest-core')
|
||||
compile "org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}"
|
||||
compile "org.springframework.cloud:spring-cloud-stream-binder-rabbit:${springStreamVersion}"
|
||||
|
||||
testCompile project(':accurest-messaging-root:accurest-messaging-stream')
|
||||
testCompile "org.springframework.cloud:spring-cloud-stream-test-support:${springStreamVersion}"
|
||||
testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') {
|
||||
exclude(group: 'org.codehaus.groovy')
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package io.codearte.accurest.samples.messaging
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator
|
||||
import groovy.transform.CompileStatic
|
||||
|
||||
@CompileStatic
|
||||
class BookDeleted {
|
||||
final String bookName
|
||||
|
||||
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
|
||||
BookDeleted(String bookName) {
|
||||
this.bookName = bookName
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package io.codearte.accurest.samples.messaging
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator
|
||||
import groovy.transform.CompileStatic
|
||||
|
||||
@CompileStatic
|
||||
class BookReturned {
|
||||
final String bookName
|
||||
|
||||
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
|
||||
BookReturned(String bookName) {
|
||||
this.bookName = bookName
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package io.codearte.accurest.samples.messaging
|
||||
|
||||
import org.springframework.cloud.stream.annotation.Input
|
||||
import org.springframework.cloud.stream.messaging.Sink
|
||||
import org.springframework.messaging.SubscribableChannel
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
interface DeleteSink extends Sink {
|
||||
|
||||
String INPUT = "delete";
|
||||
|
||||
@Input(DeleteSink.INPUT)
|
||||
SubscribableChannel delete();
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package io.codearte.accurest.samples.messaging;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.stream.annotation.EnableBinding
|
||||
import org.springframework.cloud.stream.messaging.Sink;
|
||||
import org.springframework.cloud.stream.messaging.Source;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableBinding([Source, Sink])
|
||||
class StreamMessagingApplication {
|
||||
|
||||
static void main(String[] args) {
|
||||
SpringApplication.run(StreamMessagingApplication.class, args)
|
||||
}
|
||||
}
|
||||
44
samples/samples-messaging-camel/build.gradle
Normal file
44
samples/samples-messaging-camel/build.gradle
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
maven {
|
||||
url "http://repo.spring.io/snapshot"
|
||||
}
|
||||
maven {
|
||||
url "http://repo.spring.io/milestone"
|
||||
}
|
||||
}
|
||||
|
||||
String verifier = "spring-cloud-contract-verifier"
|
||||
|
||||
dependencies {
|
||||
compile project(":$verifier-root:$verifier-core")
|
||||
compile "org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}"
|
||||
compile "org.apache.camel:camel-spring-boot-starter:${camelVersion}"
|
||||
compile "org.apache.camel:camel-jms:${camelVersion}"
|
||||
compile 'org.apache.activemq:activemq-camel:5.12.1'
|
||||
compile 'org.apache.activemq:activemq-pool:5.12.1'
|
||||
compile "org.apache.camel:camel-jackson:${camelVersion}"
|
||||
|
||||
testCompile project(":$verifier-root:$verifier-messaging-root:$verifier-camel")
|
||||
testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}"
|
||||
testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') {
|
||||
exclude(group: 'org.codehaus.groovy')
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.samples.camel
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator
|
||||
import groovy.transform.CompileStatic
|
||||
|
||||
@CompileStatic
|
||||
class BookDeleted implements Serializable {
|
||||
final String bookName
|
||||
|
||||
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
|
||||
BookDeleted(String bookName) {
|
||||
this.bookName = bookName
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,20 @@
|
||||
package io.codearte.accurest.samples.camel
|
||||
/*
|
||||
* 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.samples.camel
|
||||
|
||||
import groovy.transform.CompileStatic
|
||||
import groovy.util.logging.Slf4j
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.samples.camel
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator
|
||||
import groovy.transform.CompileStatic
|
||||
|
||||
@CompileStatic
|
||||
class BookReturned implements Serializable {
|
||||
final String bookName
|
||||
|
||||
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
|
||||
BookReturned(String bookName) {
|
||||
this.bookName = bookName
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,20 @@
|
||||
package io.codearte.accurest.samples.camel
|
||||
/*
|
||||
* 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.samples.camel
|
||||
|
||||
import org.apache.activemq.camel.component.ActiveMQComponent
|
||||
import org.apache.camel.RoutesBuilder
|
||||
@@ -1,4 +1,20 @@
|
||||
package io.codearte.accurest.samples.camel
|
||||
/*
|
||||
* 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.samples.camel
|
||||
|
||||
import groovy.transform.CompileStatic
|
||||
import groovy.util.logging.Slf4j
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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.samples.camel
|
||||
|
||||
import org.springframework.boot.SpringApplication
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
|
||||
@SpringBootApplication
|
||||
class CamelMessagingApplication {
|
||||
|
||||
static void main(String[] args) {
|
||||
SpringApplication.run(CamelMessagingApplication.class, args)
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,31 @@
|
||||
package io.codearte.accurest.samples.camel
|
||||
/*
|
||||
* 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.samples.camel
|
||||
|
||||
import com.jayway.jsonpath.DocumentContext
|
||||
import com.jayway.jsonpath.JsonPath
|
||||
import com.toomuchcoding.jsonassert.JsonAssertion
|
||||
import io.codearte.accurest.dsl.GroovyDsl
|
||||
import io.codearte.accurest.messaging.AccurestMessage
|
||||
import io.codearte.accurest.messaging.AccurestMessaging
|
||||
import io.codearte.accurest.messaging.AccurestObjectMapper
|
||||
import org.springframework.cloud.contract.verifier.dsl.Contract
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage
|
||||
import org.apache.camel.model.ModelCamelContext
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.SpringApplicationContextLoader
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierObjectMapper
|
||||
import org.springframework.test.context.ContextConfiguration
|
||||
import spock.lang.Specification
|
||||
import spock.util.concurrent.PollingConditions
|
||||
@@ -23,12 +39,12 @@ import javax.inject.Inject
|
||||
public class CamelMessagingApplicationSpec extends Specification {
|
||||
|
||||
// ALL CASES
|
||||
@Inject AccurestMessaging accurestMessaging
|
||||
AccurestObjectMapper accurestObjectMapper = new AccurestObjectMapper()
|
||||
@Inject ContractVerifierMessaging contractVerifierMessaging
|
||||
ContractVerifierObjectMapper contractVerifierObjectMapper = new ContractVerifierObjectMapper()
|
||||
|
||||
def "should work for triggered based messaging"() {
|
||||
given:
|
||||
def dsl = GroovyDsl.make {
|
||||
def dsl = Contract.make {
|
||||
label 'some_label'
|
||||
input {
|
||||
triggeredBy('bookReturnedTriggered()')
|
||||
@@ -45,16 +61,16 @@ public class CamelMessagingApplicationSpec extends Specification {
|
||||
when:
|
||||
bookReturnedTriggered()
|
||||
then:
|
||||
def response = accurestMessaging.receiveMessage('activemq:output')
|
||||
def response = contractVerifierMessaging.receiveMessage('activemq:output')
|
||||
response.headers.get('BOOK-NAME') == 'foo'
|
||||
and:
|
||||
DocumentContext parsedJson = JsonPath.parse(accurestObjectMapper.writeValueAsString(response.payload))
|
||||
DocumentContext parsedJson = JsonPath.parse(contractVerifierObjectMapper.writeValueAsString(response.payload))
|
||||
JsonAssertion.assertThat(parsedJson).field('bookName').isEqualTo('foo')
|
||||
}
|
||||
|
||||
def "should generate tests triggered by a message"() {
|
||||
given:
|
||||
def dsl = GroovyDsl.make {
|
||||
def dsl = Contract.make {
|
||||
label 'some_label'
|
||||
input {
|
||||
messageFrom('jms:input')
|
||||
@@ -80,23 +96,23 @@ public class CamelMessagingApplicationSpec extends Specification {
|
||||
// generated test should look like this:
|
||||
|
||||
//given:
|
||||
AccurestMessage inputMessage = accurestMessaging.create(
|
||||
accurestObjectMapper.writeValueAsString([bookName: 'foo']),
|
||||
ContractVerifierMessage inputMessage = contractVerifierMessaging.create(
|
||||
contractVerifierObjectMapper.writeValueAsString([bookName: 'foo']),
|
||||
[sample: 'header']
|
||||
)
|
||||
when:
|
||||
accurestMessaging.send(inputMessage, 'jms:input')
|
||||
contractVerifierMessaging.send(inputMessage, 'jms:input')
|
||||
then:
|
||||
def response = accurestMessaging.receiveMessage('jms:output')
|
||||
def response = contractVerifierMessaging.receiveMessage('jms:output')
|
||||
response.headers.get('BOOK-NAME') == 'foo'
|
||||
and:
|
||||
DocumentContext parsedJson = JsonPath.parse(accurestObjectMapper.writeValueAsString(response.payload))
|
||||
DocumentContext parsedJson = JsonPath.parse(contractVerifierObjectMapper.writeValueAsString(response.payload))
|
||||
JsonAssertion.assertThat(parsedJson).field('bookName').isEqualTo('foo')
|
||||
}
|
||||
|
||||
def "should generate tests without destination, triggered by a message"() {
|
||||
given:
|
||||
def dsl = GroovyDsl.make {
|
||||
def dsl = Contract.make {
|
||||
label 'some_label'
|
||||
input {
|
||||
messageFrom('jms:delete')
|
||||
@@ -113,12 +129,12 @@ public class CamelMessagingApplicationSpec extends Specification {
|
||||
// generated test should look like this:
|
||||
|
||||
//given:
|
||||
AccurestMessage inputMessage = accurestMessaging.create(
|
||||
accurestObjectMapper.writeValueAsString([bookName: 'foo']),
|
||||
ContractVerifierMessage inputMessage = contractVerifierMessaging.create(
|
||||
contractVerifierObjectMapper.writeValueAsString([bookName: 'foo']),
|
||||
[sample: 'header']
|
||||
)
|
||||
when:
|
||||
accurestMessaging.send(inputMessage, 'jms:delete')
|
||||
contractVerifierMessaging.send(inputMessage, 'jms:delete')
|
||||
then:
|
||||
noExceptionThrown()
|
||||
bookWasDeleted()
|
||||
40
samples/samples-messaging-integration/build.gradle
Normal file
40
samples/samples-messaging-integration/build.gradle
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
maven {
|
||||
url "http://repo.spring.io/snapshot"
|
||||
}
|
||||
maven {
|
||||
url "http://repo.spring.io/milestone"
|
||||
}
|
||||
}
|
||||
|
||||
String verifier = "spring-cloud-contract-verifier"
|
||||
|
||||
dependencies {
|
||||
compile project(":$verifier-root:$verifier-core")
|
||||
compile "org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}"
|
||||
compile "org.springframework.boot:spring-boot-starter-integration:${springBootVersion}"
|
||||
|
||||
testCompile project(":$verifier-root:$verifier-messaging-root:$verifier-integration")
|
||||
testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}"
|
||||
testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') {
|
||||
exclude(group: 'org.codehaus.groovy')
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.samples.messaging
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator
|
||||
import groovy.transform.CompileStatic
|
||||
|
||||
@CompileStatic
|
||||
class BookDeleted {
|
||||
final String bookName
|
||||
|
||||
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
|
||||
BookDeleted(String bookName) {
|
||||
this.bookName = bookName
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,20 @@
|
||||
package io.codearte.accurest.samples.messaging
|
||||
/*
|
||||
* 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.samples.messaging
|
||||
|
||||
import groovy.transform.CompileStatic
|
||||
import groovy.util.logging.Slf4j
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.samples.messaging
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator
|
||||
import groovy.transform.CompileStatic
|
||||
|
||||
@CompileStatic
|
||||
class BookReturned {
|
||||
final String bookName
|
||||
|
||||
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
|
||||
BookReturned(String bookName) {
|
||||
this.bookName = bookName
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,20 @@
|
||||
package io.codearte.accurest.samples.messaging
|
||||
/*
|
||||
* 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.samples.messaging
|
||||
|
||||
import groovy.transform.CompileStatic
|
||||
import groovy.util.logging.Slf4j
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.samples.messaging
|
||||
|
||||
import org.springframework.boot.SpringApplication
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
import org.springframework.context.annotation.ImportResource
|
||||
|
||||
@SpringBootApplication
|
||||
@ImportResource("classpath*:integration-context.xml")
|
||||
class IntegrationMessagingApplication {
|
||||
|
||||
static void main(String[] args) {
|
||||
SpringApplication.run(IntegrationMessagingApplication.class, args)
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
@@ -16,17 +32,17 @@
|
||||
ref="bookListener"
|
||||
method="returnBook"/>
|
||||
|
||||
<json-to-object-transformer input-channel="input" type="io.codearte.accurest.samples.messaging.BookReturned"
|
||||
<json-to-object-transformer input-channel="input" type="org.springframework.cloud.contract.verifier.samples.messaging.BookReturned"
|
||||
output-channel="inputChannel"/>
|
||||
|
||||
<service-activator input-channel="deleteChannel"
|
||||
ref="bookListener"
|
||||
method="bookDeleted"/>
|
||||
|
||||
<json-to-object-transformer input-channel="delete" type="io.codearte.accurest.samples.messaging.BookDeleted"
|
||||
<json-to-object-transformer input-channel="delete" type="org.springframework.cloud.contract.verifier.samples.messaging.BookDeleted"
|
||||
output-channel="deleteChannel"/>
|
||||
|
||||
<beans:bean id="bookListener" class="io.codearte.accurest.samples.messaging.BookListener"/>
|
||||
<beans:bean id="bookListener" class="org.springframework.cloud.contract.verifier.samples.messaging.BookListener"/>
|
||||
|
||||
|
||||
<!-- REQUIRED FOR TESTING -->
|
||||
@@ -1,14 +1,30 @@
|
||||
package io.codearte.accurest.samples.messaging
|
||||
/*
|
||||
* 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.samples.messaging
|
||||
|
||||
import com.jayway.jsonpath.DocumentContext
|
||||
import com.jayway.jsonpath.JsonPath
|
||||
import com.toomuchcoding.jsonassert.JsonAssertion
|
||||
import io.codearte.accurest.dsl.GroovyDsl
|
||||
import io.codearte.accurest.messaging.AccurestMessage
|
||||
import io.codearte.accurest.messaging.AccurestMessaging
|
||||
import io.codearte.accurest.messaging.AccurestObjectMapper
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.SpringApplicationContextLoader
|
||||
import org.springframework.cloud.contract.verifier.dsl.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.test.context.ContextConfiguration
|
||||
import spock.lang.Specification
|
||||
|
||||
@@ -18,13 +34,13 @@ import javax.inject.Inject
|
||||
public class IntegrationMessagingApplicationSpec extends Specification {
|
||||
|
||||
// ALL CASES
|
||||
@Inject AccurestMessaging accurestMessaging
|
||||
AccurestObjectMapper accurestObjectMapper = new AccurestObjectMapper()
|
||||
@Inject ContractVerifierMessaging contractVerifierMessaging
|
||||
ContractVerifierObjectMapper contractVerifierObjectMapper = new ContractVerifierObjectMapper()
|
||||
|
||||
def "should work for triggered based messaging"() {
|
||||
given:
|
||||
// tag::method_trigger[]
|
||||
def dsl = GroovyDsl.make {
|
||||
def dsl = Contract.make {
|
||||
// Human readable description
|
||||
description 'Some description'
|
||||
// Label by means of which the output message can be triggered
|
||||
@@ -51,17 +67,17 @@ public class IntegrationMessagingApplicationSpec extends Specification {
|
||||
when:
|
||||
bookReturnedTriggered()
|
||||
then:
|
||||
def response = accurestMessaging.receiveMessage('output')
|
||||
def response = contractVerifierMessaging.receiveMessage('output')
|
||||
response.headers.get('BOOK-NAME') == 'foo'
|
||||
and:
|
||||
DocumentContext parsedJson = JsonPath.parse(accurestObjectMapper.writeValueAsString(response.payload))
|
||||
DocumentContext parsedJson = JsonPath.parse(contractVerifierObjectMapper.writeValueAsString(response.payload))
|
||||
JsonAssertion.assertThat(parsedJson).field('bookName').isEqualTo('foo')
|
||||
}
|
||||
|
||||
def "should generate tests triggered by a message"() {
|
||||
given:
|
||||
// tag::message_trigger[]
|
||||
def dsl = GroovyDsl.make {
|
||||
def dsl = Contract.make {
|
||||
description 'Some Description'
|
||||
label 'some_label'
|
||||
// input is a message
|
||||
@@ -92,23 +108,23 @@ public class IntegrationMessagingApplicationSpec extends Specification {
|
||||
// generated test should look like this:
|
||||
|
||||
//given:
|
||||
AccurestMessage inputMessage = accurestMessaging.create(
|
||||
accurestObjectMapper.writeValueAsString([bookName: 'foo']),
|
||||
ContractVerifierMessage inputMessage = contractVerifierMessaging.create(
|
||||
contractVerifierObjectMapper.writeValueAsString([bookName: 'foo']),
|
||||
[sample: 'header']
|
||||
)
|
||||
when:
|
||||
accurestMessaging.send(inputMessage, 'input')
|
||||
contractVerifierMessaging.send(inputMessage, 'input')
|
||||
then:
|
||||
def response = accurestMessaging.receiveMessage('output')
|
||||
def response = contractVerifierMessaging.receiveMessage('output')
|
||||
response.headers.get('BOOK-NAME') == 'foo'
|
||||
and:
|
||||
DocumentContext parsedJson = JsonPath.parse(accurestObjectMapper.writeValueAsString(response.payload))
|
||||
DocumentContext parsedJson = JsonPath.parse(contractVerifierObjectMapper.writeValueAsString(response.payload))
|
||||
JsonAssertion.assertThat(parsedJson).field('bookName').isEqualTo('foo')
|
||||
}
|
||||
|
||||
def "should generate tests without destination, triggered by a message"() {
|
||||
given:
|
||||
def dsl = GroovyDsl.make {
|
||||
def dsl = Contract.make {
|
||||
label 'some_label'
|
||||
input {
|
||||
messageFrom('delete')
|
||||
@@ -125,12 +141,12 @@ public class IntegrationMessagingApplicationSpec extends Specification {
|
||||
// generated test should look like this:
|
||||
|
||||
//given:
|
||||
AccurestMessage inputMessage = accurestMessaging.create(
|
||||
accurestObjectMapper.writeValueAsString([bookName: 'foo']),
|
||||
ContractVerifierMessage inputMessage = contractVerifierMessaging.create(
|
||||
contractVerifierObjectMapper.writeValueAsString([bookName: 'foo']),
|
||||
[sample: 'header']
|
||||
)
|
||||
when:
|
||||
accurestMessaging.send(inputMessage, 'delete')
|
||||
contractVerifierMessaging.send(inputMessage, 'delete')
|
||||
then:
|
||||
noExceptionThrown()
|
||||
bookWasDeleted()
|
||||
43
samples/samples-messaging-spring/build.gradle
Normal file
43
samples/samples-messaging-spring/build.gradle
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
maven {
|
||||
url "http://repo.spring.io/snapshot"
|
||||
}
|
||||
maven {
|
||||
url "http://repo.spring.io/milestone"
|
||||
}
|
||||
}
|
||||
|
||||
String verifier = "spring-cloud-contract-verifier"
|
||||
|
||||
dependencies {
|
||||
compile project(":$verifier-root:$verifier-core")
|
||||
compile "org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}"
|
||||
compile "org.springframework:spring-jms:${springVersion}"
|
||||
|
||||
compile 'org.apache.activemq:activemq-broker:5.12.1'
|
||||
compile 'org.apache.activemq:activemq-pool:5.12.1'
|
||||
|
||||
testCompile project(":$verifier-root:$verifier-messaging-root:$verifier-messaging-core")
|
||||
testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}"
|
||||
testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') {
|
||||
exclude(group: 'org.codehaus.groovy')
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.samples.spring
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator
|
||||
import groovy.transform.CompileStatic
|
||||
|
||||
@CompileStatic
|
||||
class BookDeleted implements Serializable {
|
||||
final String bookName
|
||||
|
||||
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
|
||||
BookDeleted(String bookName) {
|
||||
this.bookName = bookName
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,20 @@
|
||||
package io.codearte.accurest.samples.spring
|
||||
/*
|
||||
* 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.samples.spring
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import groovy.transform.CompileStatic
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.samples.spring
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator
|
||||
import groovy.transform.CompileStatic
|
||||
|
||||
@CompileStatic
|
||||
class BookReturned implements Serializable {
|
||||
String bookName
|
||||
|
||||
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
|
||||
BookReturned(String bookName) {
|
||||
this.bookName = bookName
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,20 @@
|
||||
package io.codearte.accurest.samples.spring
|
||||
/*
|
||||
* 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.samples.spring
|
||||
|
||||
import groovy.transform.CompileStatic
|
||||
import groovy.util.logging.Slf4j
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.samples.spring
|
||||
|
||||
import org.springframework.boot.SpringApplication
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
import org.springframework.jms.annotation.EnableJms
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableJms
|
||||
class SpringMessagingApplication {
|
||||
|
||||
static void main(String[] args) {
|
||||
SpringApplication.run(SpringMessagingApplication.class, args)
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,30 @@
|
||||
package io.codearte.accurest.samples.spring
|
||||
/*
|
||||
* 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.samples.spring
|
||||
|
||||
import com.jayway.jsonpath.DocumentContext
|
||||
import com.jayway.jsonpath.JsonPath
|
||||
import com.toomuchcoding.jsonassert.JsonAssertion
|
||||
import io.codearte.accurest.dsl.GroovyDsl
|
||||
import io.codearte.accurest.messaging.AccurestMessage
|
||||
import io.codearte.accurest.messaging.AccurestMessaging
|
||||
import io.codearte.accurest.messaging.AccurestObjectMapper
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.SpringApplicationContextLoader
|
||||
import org.springframework.cloud.contract.verifier.dsl.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.test.context.ContextConfiguration
|
||||
import spock.lang.Specification
|
||||
import spock.util.concurrent.PollingConditions
|
||||
@@ -22,12 +38,12 @@ import javax.inject.Inject
|
||||
public class SpringApplicationSpec extends Specification {
|
||||
|
||||
// ALL CASES
|
||||
@Inject AccurestMessaging accurestMessaging
|
||||
AccurestObjectMapper accurestObjectMapper = new AccurestObjectMapper()
|
||||
@Inject ContractVerifierMessaging contractVerifierMessaging
|
||||
ContractVerifierObjectMapper contractVerifierObjectMapper = new ContractVerifierObjectMapper()
|
||||
|
||||
def "should work for triggered based messaging"() {
|
||||
given:
|
||||
def dsl = GroovyDsl.make {
|
||||
def dsl = Contract.make {
|
||||
label 'some_label'
|
||||
input {
|
||||
triggeredBy('bookReturnedTriggered()')
|
||||
@@ -44,16 +60,16 @@ public class SpringApplicationSpec extends Specification {
|
||||
when:
|
||||
bookReturnedTriggered()
|
||||
then:
|
||||
def response = accurestMessaging.receiveMessage('output')
|
||||
def response = contractVerifierMessaging.receiveMessage('output')
|
||||
response.headers.get('BOOK-NAME') == 'foo'
|
||||
and:
|
||||
DocumentContext parsedJson = JsonPath.parse(accurestObjectMapper.writeValueAsString(response.payload))
|
||||
DocumentContext parsedJson = JsonPath.parse(contractVerifierObjectMapper.writeValueAsString(response.payload))
|
||||
JsonAssertion.assertThat(parsedJson).field('bookName').isEqualTo('foo')
|
||||
}
|
||||
|
||||
def "should generate tests triggered by a message"() {
|
||||
given:
|
||||
def dsl = GroovyDsl.make {
|
||||
def dsl = Contract.make {
|
||||
label 'some_label'
|
||||
input {
|
||||
messageFrom('input')
|
||||
@@ -78,23 +94,23 @@ public class SpringApplicationSpec extends Specification {
|
||||
// generated test should look like this:
|
||||
|
||||
//given:
|
||||
AccurestMessage inputMessage = accurestMessaging.create(
|
||||
accurestObjectMapper.writeValueAsString([bookName: 'foo']),
|
||||
ContractVerifierMessage inputMessage = contractVerifierMessaging.create(
|
||||
contractVerifierObjectMapper.writeValueAsString([bookName: 'foo']),
|
||||
[sample: 'header']
|
||||
)
|
||||
when:
|
||||
accurestMessaging.send(inputMessage, 'input')
|
||||
contractVerifierMessaging.send(inputMessage, 'input')
|
||||
then:
|
||||
def response = accurestMessaging.receiveMessage('output')
|
||||
def response = contractVerifierMessaging.receiveMessage('output')
|
||||
response.headers.get('BOOK-NAME') == 'foo'
|
||||
and:
|
||||
DocumentContext parsedJson = JsonPath.parse(accurestObjectMapper.writeValueAsString(response.payload))
|
||||
DocumentContext parsedJson = JsonPath.parse(contractVerifierObjectMapper.writeValueAsString(response.payload))
|
||||
JsonAssertion.assertThat(parsedJson).field('bookName').isEqualTo('foo')
|
||||
}
|
||||
|
||||
def "should generate tests without destination, triggered by a message"() {
|
||||
given:
|
||||
def dsl = GroovyDsl.make {
|
||||
def dsl = Contract.make {
|
||||
label 'some_label'
|
||||
input {
|
||||
messageFrom('delete')
|
||||
@@ -111,12 +127,12 @@ public class SpringApplicationSpec extends Specification {
|
||||
// generated test should look like this:
|
||||
|
||||
//given:
|
||||
AccurestMessage inputMessage = accurestMessaging.create(
|
||||
accurestObjectMapper.writeValueAsString([bookName: 'foo']),
|
||||
ContractVerifierMessage inputMessage = contractVerifierMessaging.create(
|
||||
contractVerifierObjectMapper.writeValueAsString([bookName: 'foo']),
|
||||
[sample: 'header']
|
||||
)
|
||||
when:
|
||||
accurestMessaging.send(inputMessage, 'delete')
|
||||
contractVerifierMessaging.send(inputMessage, 'delete')
|
||||
then:
|
||||
noExceptionThrown()
|
||||
bookWasDeleted()
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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.samples.spring.config
|
||||
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessageBuilder
|
||||
import org.springframework.jms.core.MessageCreator
|
||||
|
||||
import javax.jms.JMSException
|
||||
import javax.jms.Message
|
||||
import javax.jms.Session
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
public class ContractVerifierSpringMessageBuilder<T extends Serializable> implements ContractVerifierMessageBuilder<T, Message> {
|
||||
|
||||
@Override
|
||||
public ContractVerifierMessage<T, Message> create(final T payload, final Map<String, Object> headers) {
|
||||
MessageCreator messageCreator = new MessageCreator() {
|
||||
@Override
|
||||
public Message createMessage(Session session) throws JMSException {
|
||||
Message message = session.createObjectMessage(payload);
|
||||
headers.entrySet().each { Map.Entry<String, Object> entry ->
|
||||
message.setObjectProperty(entry.key, entry.value)
|
||||
}
|
||||
return message
|
||||
}
|
||||
};
|
||||
|
||||
return new SpringMessage<>(messageCreator)
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContractVerifierMessage<T, Message> create(Message message) {
|
||||
return new SpringMessage<>(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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.samples.spring.config
|
||||
|
||||
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.jms.core.JmsTemplate
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
import javax.jms.Message
|
||||
import java.util.concurrent.TimeUnit
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@Component
|
||||
public class ContractVerifierSpringMessaging<T> implements ContractVerifierMessaging<T, Message> {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(ContractVerifierSpringMessaging.class);
|
||||
|
||||
private final JmsTemplate jmsTemplate;
|
||||
private final ContractVerifierMessageBuilder builder;
|
||||
|
||||
@Autowired
|
||||
@SuppressWarnings("unchecked")
|
||||
public ContractVerifierSpringMessaging(ContractVerifierMessageBuilder builder, JmsTemplate jmsTemplate) {
|
||||
this.builder = builder
|
||||
this.jmsTemplate = jmsTemplate
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void send(T payload, Map<String, Object> headers, String destination) {
|
||||
send(builder.create(payload, headers), destination);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(ContractVerifierMessage<T, Message> message, String destination) {
|
||||
try {
|
||||
jmsTemplate.send(destination, ((SpringMessage) message).messageCreator)
|
||||
} catch (Exception e) {
|
||||
log.error("Exception occurred while trying to send a message [" + message + "] " +
|
||||
"to a channel with name [" + destination + "]", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public ContractVerifierMessage<T, Message> receiveMessage(String destination, long timeout, TimeUnit timeUnit) {
|
||||
try {
|
||||
return builder.create(jmsTemplate.receive(destination));
|
||||
} catch (Exception e) {
|
||||
log.error("Exception occurred while trying to read a message from " +
|
||||
" a channel with name [" + destination + "]", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContractVerifierMessage<T, Message> receiveMessage(String destination) {
|
||||
return receiveMessage(destination, 5, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public ContractVerifierMessage<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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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.samples.spring.config
|
||||
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.jms.core.JmsTemplate
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@Configuration
|
||||
class ManualContractVerifierConfiguration {
|
||||
|
||||
@Bean
|
||||
ContractVerifierMessaging contractVerifierMessaging(JmsTemplate jmsTemplate) {
|
||||
return new ContractVerifierSpringMessaging(new ContractVerifierSpringMessageBuilder(), jmsTemplate);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,22 @@
|
||||
package io.codearte.accurest.samples.spring.config
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import io.codearte.accurest.messaging.AccurestMessage
|
||||
package org.springframework.cloud.contract.verifier.samples.spring.config
|
||||
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage
|
||||
import org.springframework.jms.core.MessageCreator
|
||||
|
||||
import javax.jms.Message
|
||||
@@ -8,7 +24,7 @@ import javax.jms.ObjectMessage
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
public class SpringMessage<T> implements AccurestMessage<T, Message> {
|
||||
public class SpringMessage<T> implements ContractVerifierMessage<T, Message> {
|
||||
|
||||
private final ObjectMessage messageDelegate;
|
||||
final MessageCreator messageCreator;
|
||||
40
samples/samples-messaging-stream/build.gradle
Normal file
40
samples/samples-messaging-stream/build.gradle
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
maven {
|
||||
url "http://repo.spring.io/snapshot"
|
||||
}
|
||||
maven {
|
||||
url "http://repo.spring.io/milestone"
|
||||
}
|
||||
}
|
||||
|
||||
String verifier = "spring-cloud-contract-verifier"
|
||||
|
||||
dependencies {
|
||||
compile project(":$verifier-root:$verifier-core")
|
||||
compile "org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}"
|
||||
compile "org.springframework.cloud:spring-cloud-stream-binder-rabbit:${springStreamVersion}"
|
||||
|
||||
testCompile project(":$verifier-root:$verifier-messaging-root:$verifier-stream")
|
||||
testCompile "org.springframework.cloud:spring-cloud-stream-test-support:${springStreamVersion}"
|
||||
testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') {
|
||||
exclude(group: 'org.codehaus.groovy')
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.samples.messaging
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator
|
||||
import groovy.transform.CompileStatic
|
||||
|
||||
@CompileStatic
|
||||
class BookDeleted {
|
||||
final String bookName
|
||||
|
||||
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
|
||||
BookDeleted(String bookName) {
|
||||
this.bookName = bookName
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,20 @@
|
||||
package io.codearte.accurest.samples.messaging
|
||||
/*
|
||||
* 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.samples.messaging
|
||||
|
||||
import groovy.transform.CompileStatic
|
||||
import groovy.util.logging.Slf4j
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.samples.messaging
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator
|
||||
import groovy.transform.CompileStatic
|
||||
|
||||
@CompileStatic
|
||||
class BookReturned {
|
||||
final String bookName
|
||||
|
||||
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
|
||||
BookReturned(String bookName) {
|
||||
this.bookName = bookName
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,20 @@
|
||||
package io.codearte.accurest.samples.messaging
|
||||
/*
|
||||
* 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.samples.messaging
|
||||
|
||||
import groovy.transform.CompileStatic
|
||||
import groovy.util.logging.Slf4j
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.samples.messaging
|
||||
|
||||
import org.springframework.cloud.stream.annotation.Input
|
||||
import org.springframework.cloud.stream.messaging.Sink
|
||||
import org.springframework.messaging.SubscribableChannel
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
interface DeleteSink extends Sink {
|
||||
|
||||
String INPUT = "delete";
|
||||
|
||||
@Input(DeleteSink.INPUT)
|
||||
SubscribableChannel delete();
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.samples.messaging;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.stream.annotation.EnableBinding
|
||||
import org.springframework.cloud.stream.messaging.Sink;
|
||||
import org.springframework.cloud.stream.messaging.Source;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableBinding([Source, Sink])
|
||||
class StreamMessagingApplication {
|
||||
|
||||
static void main(String[] args) {
|
||||
SpringApplication.run(StreamMessagingApplication.class, args)
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,30 @@
|
||||
package io.codearte.accurest.samples.messaging
|
||||
/*
|
||||
* 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.samples.messaging
|
||||
|
||||
import com.jayway.jsonpath.DocumentContext
|
||||
import com.jayway.jsonpath.JsonPath
|
||||
import com.toomuchcoding.jsonassert.JsonAssertion
|
||||
import io.codearte.accurest.dsl.GroovyDsl
|
||||
import io.codearte.accurest.messaging.AccurestMessage
|
||||
import io.codearte.accurest.messaging.AccurestMessaging
|
||||
import io.codearte.accurest.messaging.AccurestObjectMapper
|
||||
import org.springframework.cloud.contract.verifier.dsl.Contract
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.SpringApplicationContextLoader
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierObjectMapper
|
||||
import org.springframework.test.context.ContextConfiguration
|
||||
import spock.lang.Specification
|
||||
|
||||
@@ -21,12 +37,12 @@ import javax.inject.Inject
|
||||
public class StreamMessagingApplicationSpec extends Specification {
|
||||
|
||||
// ALL CASES
|
||||
@Inject AccurestMessaging accurestMessaging
|
||||
AccurestObjectMapper accurestObjectMapper = new AccurestObjectMapper()
|
||||
@Inject ContractVerifierMessaging contractVerifierMessaging
|
||||
ContractVerifierObjectMapper contractVerifierObjectMapper = new ContractVerifierObjectMapper()
|
||||
|
||||
def "should work for triggered based messaging"() {
|
||||
given:
|
||||
def dsl = GroovyDsl.make {
|
||||
def dsl = Contract.make {
|
||||
label 'some_label'
|
||||
input {
|
||||
triggeredBy('bookReturnedTriggered()')
|
||||
@@ -43,16 +59,16 @@ public class StreamMessagingApplicationSpec extends Specification {
|
||||
when:
|
||||
bookReturnedTriggered()
|
||||
then:
|
||||
def response = accurestMessaging.receiveMessage('output')
|
||||
def response = contractVerifierMessaging.receiveMessage('output')
|
||||
response.headers.get('BOOK-NAME') == 'foo'
|
||||
and:
|
||||
DocumentContext parsedJson = JsonPath.parse(accurestObjectMapper.writeValueAsString(response.payload))
|
||||
DocumentContext parsedJson = JsonPath.parse(contractVerifierObjectMapper.writeValueAsString(response.payload))
|
||||
JsonAssertion.assertThat(parsedJson).field('bookName').isEqualTo('foo')
|
||||
}
|
||||
|
||||
def "should generate tests triggered by a message"() {
|
||||
given:
|
||||
def dsl = GroovyDsl.make {
|
||||
def dsl = Contract.make {
|
||||
label 'some_label'
|
||||
input {
|
||||
messageFrom('input')
|
||||
@@ -77,23 +93,23 @@ public class StreamMessagingApplicationSpec extends Specification {
|
||||
// generated test should look like this:
|
||||
|
||||
//given:
|
||||
AccurestMessage inputMessage = accurestMessaging.create(
|
||||
accurestObjectMapper.writeValueAsString([bookName: 'foo']),
|
||||
ContractVerifierMessage inputMessage = contractVerifierMessaging.create(
|
||||
contractVerifierObjectMapper.writeValueAsString([bookName: 'foo']),
|
||||
[sample: 'header']
|
||||
)
|
||||
when:
|
||||
accurestMessaging.send(inputMessage, 'input')
|
||||
contractVerifierMessaging.send(inputMessage, 'input')
|
||||
then:
|
||||
def response = accurestMessaging.receiveMessage('output')
|
||||
def response = contractVerifierMessaging.receiveMessage('output')
|
||||
response.headers.get('BOOK-NAME') == 'foo'
|
||||
and:
|
||||
DocumentContext parsedJson = JsonPath.parse(accurestObjectMapper.writeValueAsString(response.payload))
|
||||
DocumentContext parsedJson = JsonPath.parse(contractVerifierObjectMapper.writeValueAsString(response.payload))
|
||||
JsonAssertion.assertThat(parsedJson).field('bookName').isEqualTo('foo')
|
||||
}
|
||||
|
||||
def "should generate tests without destination, triggered by a message"() {
|
||||
given:
|
||||
def dsl = GroovyDsl.make {
|
||||
def dsl = Contract.make {
|
||||
label 'some_label'
|
||||
input {
|
||||
messageFrom('delete')
|
||||
@@ -110,12 +126,12 @@ public class StreamMessagingApplicationSpec extends Specification {
|
||||
// generated test should look like this:
|
||||
|
||||
//given:
|
||||
AccurestMessage inputMessage = accurestMessaging.create(
|
||||
accurestObjectMapper.writeValueAsString([bookName: 'foo']),
|
||||
ContractVerifierMessage inputMessage = contractVerifierMessaging.create(
|
||||
contractVerifierObjectMapper.writeValueAsString([bookName: 'foo']),
|
||||
[sample: 'header']
|
||||
)
|
||||
when:
|
||||
accurestMessaging.send(inputMessage, 'delete')
|
||||
contractVerifierMessaging.send(inputMessage, 'delete')
|
||||
then:
|
||||
noExceptionThrown()
|
||||
bookWasDeleted()
|
||||
Reference in New Issue
Block a user