Skip to content

Commit

Permalink
docs(#206): updated simulations and rest support
Browse files Browse the repository at this point in the history
  • Loading branch information
bbortt committed Dec 7, 2023
1 parent 54520f6 commit 9c321bb
Show file tree
Hide file tree
Showing 14 changed files with 322 additions and 397 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,21 @@ public void run(ScenarioRunner scenario) {
scenario
.receive()
.payload("<mail-message xmlns=\"http://www.citrusframework.org/schema/mail/message\">" +
"<from>[email protected]</from>" +
"<to>[email protected]</to>" +
"<cc></cc>" +
"<bcc></bcc>" +
"<subject>Hello</subject>" +
"<body>" +
"<contentType>text/plain; charset=utf-8</contentType>" +
"<content>Say Hello!</content>" +
"</body>" +
"</mail-message>");
"<from>[email protected]</from>" +
"<to>[email protected]</to>" +
"<cc></cc>" +
"<bcc></bcc>" +
"<subject>Hello</subject>" +
"<body>" +
"<contentType>text/plain; charset=utf-8</contentType>" +
"<content>Say Hello!</content>" +
"</body>" +
"</mail-message>");

scenario
.send()
.payload("<mail-response xmlns=\"http://www.citrusframework.org/schema/mail/message\">" +
.payload(
"<mail-response xmlns=\"http://www.citrusframework.org/schema/mail/message\">" +
"<code>250</code>" +
"<message>OK</message>" +
"</mail-response>");
Expand Down
23 changes: 12 additions & 11 deletions simulator-docs/src/main/asciidoc/endpoint-support.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,21 @@ public class HelloScenario extends AbstractSimulatorScenario {
scenario
.receive()
.payload("<mail-message xmlns=\"http://www.citrusframework.org/schema/mail/message\">" +
"<from>[email protected]</from>" +
"<to>[email protected]</to>" +
"<cc></cc>" +
"<bcc></bcc>" +
"<subject>Hello</subject>" +
"<body>" +
"<contentType>text/plain; charset=utf-8</contentType>" +
"<content>Say Hello!</content>" +
"</body>" +
"</mail-message>");
"<from>[email protected]</from>" +
"<to>[email protected]</to>" +
"<cc></cc>" +
"<bcc></bcc>" +
"<subject>Hello</subject>" +
"<body>" +
"<contentType>text/plain; charset=utf-8</contentType>" +
"<content>Say Hello!</content>" +
"</body>" +
"</mail-message>");
scenario
.send()
.payload("<mail-response xmlns=\"http://www.citrusframework.org/schema/mail/message\">" +
.payload(
"<mail-response xmlns=\"http://www.citrusframework.org/schema/mail/message\">" +
"<code>250</code>" +
"<message>OK</message>" +
"</mail-response>");
Expand Down
22 changes: 13 additions & 9 deletions simulator-docs/src/main/asciidoc/installation.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,24 @@ Additionally, we'll implement a default scenario that will be triggered by incom
----
package org.citrusframework.simulator;
import org.citrusframework.simulator.scenario.*;
import org.citrusframework.simulator.scenario.AbstractSimulatorScenario;
import org.citrusframework.simulator.scenario.Scenario;
import org.citrusframework.simulator.scenario.ScenarioRunner;
import org.springframework.http.HttpStatus;
import org.citrusframework.http.message.HttpMessage;
@Scenario("DEFAULT_SCENARIO")
@Scenario("Default")
public class DefaultScenario extends AbstractSimulatorScenario {
@Override
public void run(ScenarioDesigner designer) {
designer.echo("Default scenario executed!");
designer.send()
.message(new HttpMessage("Welcome to the Citrus simulator")
.status(HttpStatus.OK));
public void run(ScenarioRunner scenario) {
scenario.$(scenario.http()
.receive().post());
scenario.$(scenario.http()
.send()
.response(HttpStatus.OK)
.message()
.body("<DefaultResponse>This is a default response!</DefaultResponse>"));
}
}
----
Expand Down
119 changes: 72 additions & 47 deletions simulator-docs/src/main/asciidoc/intermediate-messages.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,44 @@ To explain this concept, consider the following simple example.
@Scenario("GoodNight")
public class GoodNightScenario extends AbstractSimulatorScenario {
private static final String CORRELATION_ID = "x-correlationid";
@Override
public void run(ScenarioRunner scenario) {
scenario
scenario.$(scenario.http()
.receive()
.payload("<GoodNight xmlns=\"http://citrusframework.org/schemas/hello\">" +
"Go to sleep!" +
"</GoodNight>")
.extractFromHeader("X-CorrelationId", "correlationId");
scenario.correlation().start()
.onHeader("X-CorrelationId", "${correlationId}");
scenario
.post()
.message()
.body("<GoodNight xmlns=\"http://citrusframework.org/schemas/hello\">" +
"Go to sleep!" +
"</GoodNight>")
.extract(fromHeaders().header(CORRELATION_ID, "correlationId")
));
scenario.$(correlation().start()
.onHeader(CORRELATION_ID, "${correlationId}")
);
scenario.$(scenario.http()
.send()
.payload("<GoodNightResponse xmlns=\"http://citrusframework.org/schemas/hello\">" +
"Good Night!" +
"</GoodNightResponse>");
.response(HttpStatus.OK)
.message()
.body("<GoodNightResponse xmlns=\"http://citrusframework.org/schemas/hello\">" +
"Good Night!" +
"</GoodNightResponse>"));
scenario
scenario.$(scenario.http()
.receive()
.payload("<IntermediateRequest>In between!</IntermediateRequest>");
.post()
.selector("x-correlationid = '1${correlationId}'")
.message()
.body("<InterveningRequest>In between!</InterveningRequest>"));
scenario
scenario.$(scenario.http()
.send()
.payload("<IntermediateResponse>In between!</IntermediateResponse>");
.response(HttpStatus.OK)
.message()
.body("<InterveningResponse>In between!</InterveningResponse>"));
}
}
----
Expand All @@ -59,39 +72,51 @@ public class FaxCancelledScenario extends AbstractFaxScenario {
public static final String ROOT_ELEMENT_XPATH = "string:local-name(/*)";
public static final String REFERENCE_ID_XPATH = "//fax:referenceId";
public static final String REFERENCE_ID_VAR = "referenceId";
public static final String REFERENCE_ID_PH = "${referenceId}";
@Override
public void run(ScenarioRunner scenario) {
scenario
.receive()
.xpath(ROOT_ELEMENT_XPATH, "SendFaxMessage")
.extractFromPayload(REFERENCE_ID_XPATH, "referenceId");
scenario.correlation().start()
.onPayload(REFERENCE_ID_XPATH, "${referenceId}");
scenario
.send(getStatusEndpoint())
.payload(
getPayloadHelper().generateFaxStatusMessage("${referenceId}",
FaxStatusEnumType.QUEUED,
"The fax message has been queued and will be sent shortly"),
getPayloadHelper().getMarshaller()
);
scenario
.receive()
.xpath(ROOT_ELEMENT_XPATH, "CancelFaxMessage")
.xpath(REFERENCE_ID_XPATH, "${referenceId}");
scenario
.send(getStatusEndpoint())
.payload(
getPayloadHelper().generateFaxStatusMessage("${referenceId}",
FaxStatusEnumType.CANCELLED,
"The fax message has been cancelled"),
getPayloadHelper().getMarshaller()
);
scenario.$(scenario.receive()
.message()
.validate(xpath().expression(ROOT_ELEMENT_XPATH, "SendFaxMessage"))
.extract(
fromBody().expression(REFERENCE_ID_XPATH, REFERENCE_ID_VAR)));
scenario.$(correlation().start()
.onPayload(REFERENCE_ID_XPATH, REFERENCE_ID_PH));
scenario.$(send()
.endpoint(getStatusEndpoint())
.message()
.body(
new MarshallingPayloadBuilder(
getPayloadHelper().generateFaxStatusMessage(
REFERENCE_ID_PH,
"QUEUED",
"The fax message has been queued and will be send shortly"
),
getPayloadHelper().getMarshaller())
));
scenario.$(scenario.receive()
.message()
.validate(xpath()
.expression(ROOT_ELEMENT_XPATH, "CancelFaxMessage")
.expression(REFERENCE_ID_XPATH, REFERENCE_ID_PH)));
scenario.$(send()
.endpoint(getStatusEndpoint())
.message()
.body(
new MarshallingPayloadBuilder(
getPayloadHelper().generateFaxStatusMessage(
REFERENCE_ID_PH,
"CANCELLED",
"The fax message has been cancelled"
),
getPayloadHelper().getMarshaller())
));
}
}
----
Expand Down
46 changes: 11 additions & 35 deletions simulator-docs/src/main/asciidoc/jms-support.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -190,18 +190,17 @@ public class HelloJmsScenario extends AbstractSimulatorScenario {
@Override
public void run(ScenarioRunner scenario) {
scenario
.receive()
.payload("<Hello xmlns=\"http://citrusframework.org/schemas/hello\">" +
"<user>@ignore@</user>" +
"</Hello>")
.extractFromPayload("/Hello/user", "userName");
scenario
.send(replyEndpoint)
.payload("<HelloResponse xmlns=\"http://citrusframework.org/schemas/hello\">" +
"<text>Hi there ${userName}!</text>" +
"</HelloResponse>");
scenario.$(scenario.receive()
.message()
.body("<Hello xmlns=\"http://citrusframework.org/schemas/hello\">" +
"Say Hello!" +
"</Hello>"));
scenario.$(scenario.send()
.message()
.body("<HelloResponse xmlns=\"http://citrusframework.org/schemas/hello\">" +
"Hi there!" +
"</HelloResponse>"));
}
}
----
Expand All @@ -218,29 +217,6 @@ When dealing with synchronous communication the message producer waits for a rep
within the simulator. So when we have synchronous communication we simply send back a response message using the scenario endpoint. The simulator makes sure that the response is
provided to the waiting producer on the reply destination.

[source,java]
----
@Scenario("Hello")
public class HelloJmsScenario extends AbstractSimulatorScenario {
@Override
public void run(ScenarioRunner scenario) {
scenario
.receive()
.payload("<Hello xmlns=\"http://citrusframework.org/schemas/hello\">" +
"<user>@ignore@</user>" +
"</Hello>")
.extractFromPayload("/Hello/user", "userName");
scenario
.send()
.payload("<HelloResponse xmlns=\"http://citrusframework.org/schemas/hello\">" +
"<text>Hi there ${userName}!</text>" +
"</HelloResponse>");
}
}
----

The synchronous JMS communication needs to be enabled on the JMS simulator adapter.

[source,java]
Expand Down
Loading

0 comments on commit 9c321bb

Please sign in to comment.