Updated docs

This commit is contained in:
Marcin Grzejszczak
2016-04-24 12:01:28 +02:00
parent 8007508e19
commit 91dc576436
5 changed files with 88 additions and 29 deletions

View File

@@ -50,6 +50,36 @@ include::../../../../stub-runner/stub-runner/src/main/groovy/io/codearte/accures
For convenience the `StubFinder` interface extends `StubTrigger` so it's enough to use only one in your tests.
`StubTrigger` gives you the following options to trigger a message:
===== Trigger by label
[source,groovy]
----
include::../../../../stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/test/groovy/io/codearte/accurest/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=client_trigger,indent=0]
----
===== Trigger by group and artifact ids
[source,groovy]
----
include::../../../../stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/test/groovy/io/codearte/accurest/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=trigger_group_artifact,indent=0]
----
===== Trigger by artifact ids
[source,groovy]
----
include::../../../../stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/test/groovy/io/codearte/accurest/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=trigger_artifact,indent=0]
----
===== Trigger all messages
[source,groovy]
----
include::../../../../stub-runner/stub-runner-messaging/stub-runner-messaging-camel/src/test/groovy/io/codearte/accurest/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=trigger_all,indent=0]
----
include::../../../../stub-runner/stub-runner-messaging/stub-runner-messaging-camel/README.adoc[]
include::../../../../stub-runner/stub-runner-messaging/stub-runner-messaging-integration/README.adoc[]

View File

@@ -171,16 +171,16 @@ public class AccurestRule implements TestRule, StubFinder {
@Override
public void trigger(String ivyNotation, String labelName) {
throw new UnsupportedOperationException("Feature not yet supported");
stubFinder.trigger(ivyNotation, labelName);
}
@Override
public void trigger(String labelName) {
throw new UnsupportedOperationException("Feature not yet supported");
stubFinder.trigger(labelName);
}
@Override
public void trigger() {
throw new UnsupportedOperationException("Feature not yet supported");
stubFinder.trigger();
}
}

View File

@@ -113,34 +113,11 @@ And the received message would pass the following assertions
include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=client_receive_message,indent=0]
----
===== Custom triggers
===== Scenario 3 (input with no output)
`StubTrigger` gives you the following options to trigger a message:
===== Trigger by label
Since the route is set for you it's enough to just send a message to the `{output_name}` destination.
[source,groovy]
----
include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=client_trigger,indent=0]
include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=trigger_no_output,indent=0]
----
===== Trigger by group and artifact ids
[source,groovy]
----
include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=trigger_group_artifact,indent=0]
----
===== Trigger by artifact ids
[source,groovy]
----
include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=trigger_artifact,indent=0]
----
===== Trigger all messages
[source,groovy]
----
include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=trigger_all,indent=0]
----

View File

@@ -119,6 +119,24 @@ class CamelStubRunnerSpec extends Specification {
receivedMessage.in.headers.get('BOOK-NAME') == 'foo'
}
def 'should trigger a label with no output message'() {
when:
// tag::trigger_no_output[]
camelContext.createProducerTemplate().sendBodyAndHeaders('jms:delete', new BookReturned('foo'), [sample: 'header'])
// end::trigger_no_output[]
then:
noExceptionThrown()
}
def 'should not trigger a message that does not match input'() {
when:
camelContext.createProducerTemplate().sendBodyAndHeaders('jms:input', new BookReturned('notmatching'), [wrong: 'header_value'])
then:
Exchange receivedMessage = camelContext.createConsumerTemplate().receive('jms:output', 100)
and:
receivedMessage == null
}
private boolean assertThatBodyContainsBookNameFoo(Object payload) {
String objectAsString = payload instanceof String ? payload :
JsonOutput.toJson(payload)
@@ -126,6 +144,11 @@ class CamelStubRunnerSpec extends Specification {
return json.bookName == 'foo'
}
def setup() {
// ensure that message were taken from the queue
camelContext.createConsumerTemplate().receive('jms:output', 100)
}
@Bean
ActiveMQComponent activeMQComponent(@Value('${activemq.url:vm://localhost?broker.persistent=false}') String url) {
return new ActiveMQComponent(brokerURL: url)
@@ -172,4 +195,21 @@ class CamelStubRunnerSpec extends Specification {
}
}
// end::sample_dsl_2[]
GroovyDsl dsl3 =
// tag::sample_dsl_3[]
io.codearte.accurest.dsl.GroovyDsl.make {
label 'delete_book'
input {
messageFrom('jms:delete')
messageBody([
bookName: 'foo'
])
messageHeaders {
header('sample', 'header')
}
assertThat('bookWasDeleted()')
}
}
// end::sample_dsl_3[]
}

View File

@@ -0,0 +1,12 @@
package io.codearte.accurest.stubrunner
import groovy.transform.InheritConstructors
/**
* Exception thrown when message is not matched
*
* @author Marcin Grzejszczak
*/
@InheritConstructors
class MessageNotMatchingException extends RuntimeException {
}