Brings back Eureka support, updates samples, removes mocked kafka & rabbit samples
This commit is contained in:
@@ -31,4 +31,9 @@ public class BookReturned implements Serializable {
|
||||
this.bookName = bookName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BookReturned{" + "bookName='" + bookName + '\'' + '}';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,9 +16,10 @@
|
||||
|
||||
package com.example;
|
||||
|
||||
import org.apache.camel.CamelContext;
|
||||
import org.apache.camel.RoutesBuilder;
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
import org.apache.camel.component.activemq.ActiveMQComponent;
|
||||
import org.apache.camel.component.rabbitmq.RabbitMQComponent;
|
||||
import org.apache.camel.model.dataformat.JsonLibrary;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -32,26 +33,25 @@ import org.springframework.context.annotation.Configuration;
|
||||
public class BookRouteConfiguration {
|
||||
|
||||
@Bean
|
||||
ActiveMQComponent activeMQComponent(@Value("${activemq.url:vm://localhost?broker.persistent=false}") String url) {
|
||||
ActiveMQComponent component = new ActiveMQComponent();
|
||||
component.setBrokerURL(url);
|
||||
return component;
|
||||
}
|
||||
|
||||
@Bean
|
||||
RoutesBuilder myRouter(final BookService bookService, final BookDeleter bookDeleter) {
|
||||
RoutesBuilder myRouter(final BookService bookService, final BookDeleter bookDeleter, CamelContext context,
|
||||
@Value("${spring.rabbitmq.port}") int port) {
|
||||
return new RouteBuilder() {
|
||||
|
||||
@Override
|
||||
public void configure() throws Exception {
|
||||
RabbitMQComponent component = context.getComponent("rabbitmq", RabbitMQComponent.class);
|
||||
component.setAddresses("localhost:" + port);
|
||||
|
||||
// scenario 1 - from bean to output
|
||||
from("direct:start").unmarshal().json(JsonLibrary.Jackson, BookReturned.class).bean(bookService)
|
||||
.to("jms:output");
|
||||
.marshal().json(JsonLibrary.Jackson, BookReturned.class).to("rabbitmq:output?queue=output");
|
||||
// scenario 2 - from input to output
|
||||
from("jms:input").unmarshal().json(JsonLibrary.Jackson, BookReturned.class).bean(bookService)
|
||||
.to("jms:output");
|
||||
from("rabbitmq:input?queue=input").unmarshal().json(JsonLibrary.Jackson, BookReturned.class)
|
||||
.bean(bookService).marshal().json(JsonLibrary.Jackson, BookReturned.class)
|
||||
.to("rabbitmq:output");
|
||||
// scenario 3 - from input to no output
|
||||
from("jms:delete").unmarshal().json(JsonLibrary.Jackson, BookDeleted.class).bean(bookDeleter);
|
||||
from("rabbitmq:delete?queue=delete").unmarshal().json(JsonLibrary.Jackson, BookDeleted.class)
|
||||
.bean(bookDeleter);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -23,25 +23,28 @@ import com.jayway.jsonpath.JsonPath
|
||||
import com.toomuchcoding.jsonassert.JsonAssertion
|
||||
import org.apache.camel.Message
|
||||
import org.apache.camel.model.ModelCamelContext
|
||||
import spock.lang.Specification
|
||||
import spock.util.concurrent.PollingConditions
|
||||
import org.awaitility.Awaitility
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.testcontainers.containers.RabbitMQContainer
|
||||
import org.testcontainers.junit.jupiter.Container
|
||||
import org.testcontainers.junit.jupiter.Testcontainers
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.context.SpringBootContextLoader
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.verifier.messaging.MessageVerifier
|
||||
import org.springframework.cloud.contract.verifier.messaging.boot.AutoConfigureMessageVerifier
|
||||
import org.springframework.cloud.contract.verifier.messaging.internal.ContractVerifierObjectMapper
|
||||
import org.springframework.test.context.ContextConfiguration
|
||||
|
||||
import org.springframework.test.context.DynamicPropertyRegistry
|
||||
import org.springframework.test.context.DynamicPropertySource
|
||||
/**
|
||||
* SPIKE ON TESTS FROM NOTES IN MessagingSpec
|
||||
*/
|
||||
// Context configuration would end up in base class
|
||||
@AutoConfigureMessageVerifier
|
||||
@SpringBootTest(classes = CamelMessagingApplication)
|
||||
class CamelMessagingApplicationSpec extends Specification {
|
||||
@SpringBootTest(classes = CamelMessagingApplication, properties = 'camel.component.rabbitmq.declare=true')
|
||||
@Testcontainers
|
||||
class CamelMessagingApplicationSpec {
|
||||
|
||||
// ALL CASES
|
||||
@Autowired
|
||||
@@ -53,11 +56,16 @@ class CamelMessagingApplicationSpec extends Specification {
|
||||
|
||||
ContractVerifierObjectMapper contractVerifierObjectMapper = new ContractVerifierObjectMapper()
|
||||
|
||||
void setupSpec() {
|
||||
System.setProperty("org.apache.activemq.SERIALIZABLE_PACKAGES", "*")
|
||||
@Container
|
||||
static RabbitMQContainer broker = new RabbitMQContainer("rabbitmq:3.7.25-management-alpine");
|
||||
|
||||
@DynamicPropertySource
|
||||
static void setup(DynamicPropertyRegistry registry) {
|
||||
registry.add("spring.rabbitmq.port", () -> broker.getAmqpPort());
|
||||
}
|
||||
|
||||
def "should work for triggered based messaging"() {
|
||||
@Test
|
||||
void "should work for triggered based messaging"() {
|
||||
given:
|
||||
Contract.make {
|
||||
label 'some_label'
|
||||
@@ -65,7 +73,7 @@ class CamelMessagingApplicationSpec extends Specification {
|
||||
triggeredBy('bookReturnedTriggered()')
|
||||
}
|
||||
outputMessage {
|
||||
sentTo('activemq:output')
|
||||
sentTo('rabbitmq:output')
|
||||
body('''{ "bookName" : "foo" }''')
|
||||
headers {
|
||||
header('BOOK-NAME', 'foo')
|
||||
@@ -76,20 +84,21 @@ class CamelMessagingApplicationSpec extends Specification {
|
||||
when:
|
||||
bookReturnedTriggered()
|
||||
then:
|
||||
def response = contractVerifierMessaging.receive('activemq:output')
|
||||
response.headers.get('BOOK-NAME') == 'foo'
|
||||
def response = contractVerifierMessaging.receive('rabbitmq:output')
|
||||
assert response.headers.get('BOOK-NAME') == 'foo'
|
||||
and:
|
||||
DocumentContext parsedJson = JsonPath.
|
||||
parse(contractVerifierObjectMapper.writeValueAsString(response.body))
|
||||
JsonAssertion.assertThat(parsedJson).field('bookName').isEqualTo('foo')
|
||||
}
|
||||
|
||||
def "should generate tests triggered by a message"() {
|
||||
@Test
|
||||
void "should generate tests triggered by a message"() {
|
||||
given:
|
||||
Contract.make {
|
||||
label 'some_label'
|
||||
input {
|
||||
messageFrom('jms:input')
|
||||
messageFrom('rabbitmq:input')
|
||||
messageBody([
|
||||
bookName: 'foo'
|
||||
])
|
||||
@@ -99,7 +108,7 @@ class CamelMessagingApplicationSpec extends Specification {
|
||||
}
|
||||
}
|
||||
outputMessage {
|
||||
sentTo('jms:output')
|
||||
sentTo('rabbitmq:output')
|
||||
body([
|
||||
bookName: 'foo'
|
||||
])
|
||||
@@ -112,22 +121,23 @@ class CamelMessagingApplicationSpec extends Specification {
|
||||
when:
|
||||
contractVerifierMessaging.send(
|
||||
contractVerifierObjectMapper.writeValueAsString([bookName: 'foo']),
|
||||
[sample: 'header'], 'jms:input')
|
||||
[sample: 'header'], 'rabbitmq:input')
|
||||
then:
|
||||
def response = contractVerifierMessaging.receive('jms:output')
|
||||
response.headers.get('BOOK-NAME') == 'foo'
|
||||
def response = contractVerifierMessaging.receive('rabbitmq:output')
|
||||
assert response.headers.get('BOOK-NAME') == 'foo'
|
||||
and:
|
||||
DocumentContext parsedJson = JsonPath.
|
||||
parse(contractVerifierObjectMapper.writeValueAsString(response.body))
|
||||
JsonAssertion.assertThat(parsedJson).field('bookName').isEqualTo('foo')
|
||||
}
|
||||
|
||||
def "should generate tests without destination, triggered by a message"() {
|
||||
@Test
|
||||
void "should generate tests without destination, triggered by a message"() {
|
||||
given:
|
||||
Contract.make {
|
||||
label 'some_label'
|
||||
input {
|
||||
messageFrom('jms:delete')
|
||||
messageFrom('rabbitmq:delete')
|
||||
messageBody([
|
||||
bookName: 'foo'
|
||||
])
|
||||
@@ -141,9 +151,8 @@ class CamelMessagingApplicationSpec extends Specification {
|
||||
when:
|
||||
contractVerifierMessaging.
|
||||
send(contractVerifierObjectMapper.writeValueAsString([bookName: 'foo']),
|
||||
[sample: 'header'], 'jms:delete')
|
||||
[sample: 'header'], 'rabbitmq:delete')
|
||||
then:
|
||||
noExceptionThrown()
|
||||
bookWasDeleted()
|
||||
}
|
||||
|
||||
@@ -152,12 +161,9 @@ class CamelMessagingApplicationSpec extends Specification {
|
||||
sendBody('direct:start', '''{"bookName" : "foo" }''')
|
||||
}
|
||||
|
||||
PollingConditions pollingConditions = new PollingConditions()
|
||||
|
||||
void bookWasDeleted() {
|
||||
pollingConditions.eventually {
|
||||
Awaitility.await().untilAsserted(() -> {
|
||||
assert bookDeleter.bookSuccessfulyDeleted.get()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="STDOUT"/>
|
||||
</root>
|
||||
|
||||
<logger name="org.testcontainers" level="INFO"/>
|
||||
<logger name="com.github.dockerjava" level="WARN"/>
|
||||
<logger name="com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.wire" level="OFF"/>
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user