Fixed NPE, added consumer producer to DSL

This commit is contained in:
Marcin Grzejszczak
2016-04-25 17:40:02 +02:00
parent 819e35bd88
commit e75bbaafbc
8 changed files with 35 additions and 15 deletions

View File

@@ -28,7 +28,7 @@ class JUnitMessagingMethodBodyBuilder extends MessagingMethodBodyBuilder {
if (request.triggeredBy) {
return request.triggeredBy.executionCommand
}
return "accurestMessaging.send(inputMessage, \"${request.messageFrom}\")"
return "accurestMessaging.send(inputMessage, \"${request.messageFrom.serverValue}\")"
}
@Override

View File

@@ -26,7 +26,7 @@ class SpockMessagingMethodBodyBuilder extends MessagingMethodBodyBuilder {
if (request.triggeredBy) {
return request.triggeredBy.executionCommand
}
return "accurestMessaging.send(inputMessage, '${request.messageFrom}')"
return "accurestMessaging.send(inputMessage, '${request.messageFrom.serverValue}')"
}
@Override

View File

@@ -10,7 +10,7 @@ import groovy.transform.TypeChecked
@ToString(includePackage = false, includeNames = true)
class Input extends Common {
String messageFrom
DslProperty<String> messageFrom
ExecutionProperty triggeredBy
Headers messageHeaders
BodyType messageBody
@@ -24,7 +24,19 @@ class Input extends Common {
this.messageBody = input.messageBody
}
ServerDslProperty producer(Object clientValue) {
return new ServerDslProperty(clientValue)
}
ClientDslProperty consumer(Object clientValue) {
return new ClientDslProperty(clientValue)
}
void messageFrom(String messageFrom) {
this.messageFrom = new DslProperty<>(messageFrom)
}
void messageFrom(DslProperty messageFrom) {
this.messageFrom = messageFrom
}

View File

@@ -31,6 +31,14 @@ class OutputMessage extends Common {
this.sentTo = sentTo
}
ServerDslProperty producer(Object clientValue) {
return new ServerDslProperty(clientValue)
}
ClientDslProperty consumer(Object clientValue) {
return new ClientDslProperty(clientValue)
}
void body(Object bodyAsValue) {
this.body = new DslProperty(bodyAsValue)
}

View File

@@ -23,8 +23,8 @@ class StubRunnerCamelConfiguration {
@Override
public void configure() throws Exception {
Map<StubConfiguration, Collection<GroovyDsl>> accurestContracts = batchStubRunner.accurestContracts
(accurestContracts.values().flatten() as Collection<GroovyDsl>).findAll { it?.input?.messageFrom && it?.outputMessage?.sentTo }.each {
from(it.input.messageFrom)
(accurestContracts.values().flatten() as Collection<GroovyDsl>).findAll { it?.input?.messageFrom?.clientValue && it?.outputMessage?.sentTo }.each {
from(it.input.messageFrom.clientValue)
.filter(new StubRunnerCamelPredicate(it))
.process(new StubRunnerCamelProcessor(it))
.to(it.outputMessage.sentTo.clientValue)

View File

@@ -32,12 +32,12 @@ class StubRunnerIntegrationConfiguration {
Map<StubConfiguration, Collection<GroovyDsl>> accurestContracts = batchStubRunner.accurestContracts
accurestContracts.each { StubConfiguration key, Collection<GroovyDsl> value ->
String name = "${key.groupId}_${key.artifactId}"
value.findAll { it?.input?.messageFrom }.each { GroovyDsl dsl ->
value.findAll { it?.input?.messageFrom?.clientValue }.each { GroovyDsl dsl ->
String flowName = "${name}_${dsl.label}_${dsl.hashCode()}"
IntegrationFlowBuilder builder = IntegrationFlows.from(dsl.input.messageFrom)
IntegrationFlowBuilder builder = IntegrationFlows.from(dsl.input.messageFrom.clientValue)
.filter(new StubRunnerIntegrationMessageSelector(dsl), { FilterEndpointSpec e -> e.id("${flowName}.filter") } )
.transform(new StubRunnerIntegrationTransformer(dsl), { GenericEndpointSpec e -> e.id("${flowName}.transformer") })
if (dsl.outputMessage) {
if (dsl.outputMessage?.sentTo) {
builder = builder.channel(dsl.outputMessage.sentTo.clientValue)
} else {
builder = builder.handle(new DummyMessageHandler(), "handle")

View File

@@ -36,12 +36,12 @@ class StubRunnerStreamConfiguration {
Map<StubConfiguration, Collection<GroovyDsl>> accurestContracts = batchStubRunner.accurestContracts
accurestContracts.each { StubConfiguration key, Collection<GroovyDsl> value ->
String name = "${key.groupId}_${key.artifactId}"
value.findAll { it?.input?.messageFrom }.each { GroovyDsl dsl ->
value.findAll { it?.input?.messageFrom?.clientValue }.each { GroovyDsl dsl ->
String flowName = "${name}_${dsl.label}_${dsl.hashCode()}"
IntegrationFlowBuilder builder = IntegrationFlows.from(dsl.input.messageFrom)
IntegrationFlowBuilder builder = IntegrationFlows.from(dsl.input.messageFrom.clientValue)
.filter(new StubRunnerStreamMessageSelector(dsl), { FilterEndpointSpec e -> e.id("${flowName}.filter") } )
.transform(new StubRunnerStreamTransformer(dsl), { GenericEndpointSpec e -> e.id("${flowName}.transformer") })
if (dsl.outputMessage) {
if (dsl.outputMessage?.sentTo) {
builder = builder.channel(dsl.outputMessage.sentTo.clientValue)
} else {
builder = builder.handle(new DummyMessageHandler(), "handle")
@@ -49,8 +49,8 @@ class StubRunnerStreamConfiguration {
beanFactory.initializeBean(builder.get(), flowName)
beanFactory.getBean("${flowName}.filter", Lifecycle.class).start();
beanFactory.getBean("${flowName}.transformer", Lifecycle.class).start();
channelBindingService.bindConsumer(beanFactory.getBean(dsl.input.messageFrom, MessageChannel.class), dsl.input.messageFrom)
if (dsl.outputMessage) {
channelBindingService.bindConsumer(beanFactory.getBean(dsl.input.messageFrom.clientValue, MessageChannel.class), dsl.input.messageFrom.clientValue)
if (dsl.outputMessage?.sentTo) {
channelBindingService.bindProducer(beanFactory.getBean(dsl.outputMessage.sentTo.clientValue, MessageChannel.class), dsl.outputMessage.sentTo.clientValue)
}
}

View File

@@ -98,8 +98,8 @@ class StubRunnerExecutor implements StubFinder {
if (!groovyDsl.outputMessage) {
return
}
AccurestMessage message = accurestMessaging.create(groovyDsl.outputMessage.body.clientValue,
groovyDsl.outputMessage.headers.asStubSideMap())
AccurestMessage message = accurestMessaging.create(groovyDsl.outputMessage?.body?.clientValue,
groovyDsl.outputMessage?.headers?.asStubSideMap())
accurestMessaging.send(message, groovyDsl.outputMessage.sentTo.clientValue)
}