1616
1717package org .citrusframework .simulator .sample .scenario ;
1818
19- import org .citrusframework .exceptions .TestCaseFailedException ;
2019import org .citrusframework .simulator .scenario .AbstractSimulatorScenario ;
2120import org .citrusframework .simulator .scenario .Scenario ;
2221import org .citrusframework .simulator .scenario .ScenarioRunner ;
22+ import org .citrusframework .ws .message .SoapMessage ;
2323import org .slf4j .Logger ;
2424import org .slf4j .LoggerFactory ;
25- import org .xml .sax .SAXParseException ;
2625
27- import java .util .Objects ;
26+ import java .util .concurrent . atomic . AtomicBoolean ;
2827
2928/**
3029 * @author Christoph Deppisch
@@ -36,40 +35,29 @@ public class DefaultScenario extends AbstractSimulatorScenario {
3635
3736 @ Override
3837 public void run (ScenarioRunner scenario ) {
39- boolean isSoap = false ;
40- try {
41- scenario .$ (scenario .receive ());
42- } catch (TestCaseFailedException e ) {
43- if (getRootCause (e ) instanceof SAXParseException saxParseException ) {
44- logger .warn ("Default Scenario request parsing failed, assuming unmatched SOAP request!" , e );
45- scenario .$ (
46- scenario .soap ()
47- .sendFault ()
48- .message ()
49- .faultActor ("SERVER" )
50- .faultCode ("{http://localhost:8080/HelloService/v1}CITRUS:SIM-1100" )
51- .faultString ("No matching scenario found" )
52- );
53- isSoap = true ;
54- }
55- }
38+ final AtomicBoolean isSoap = new AtomicBoolean (false );
39+
40+ scenario .$ (scenario .receive ().message ().validate ((message , context ) -> {
41+ isSoap .set (message instanceof SoapMessage );
42+ }));
5643
57- if (! isSoap ) {
44+ if (isSoap . get () ) {
5845 scenario .$ (
59- scenario .send ()
46+ scenario .soap ()
47+ .sendFault ()
6048 .message ()
61- .body ("<DefaultResponse>This is a default response!</DefaultResponse>" )
49+ .faultActor ("SERVER" )
50+ .faultCode ("{http://localhost:8080/HelloService/v1}CITRUS:SIM-1100" )
51+ .faultString ("No matching scenario found" )
6252 );
63- }
64- }
65-
66- private Throwable getRootCause (Exception e ) {
67- Throwable cause = e ;
6853
69- while (!Objects .isNull (cause .getCause ())) {
70- cause = cause .getCause ();
54+ return ;
7155 }
7256
73- return cause ;
57+ scenario .$ (
58+ scenario .send ()
59+ .message ()
60+ .body ("<DefaultResponse>This is a default response!</DefaultResponse>" )
61+ );
7462 }
7563}
0 commit comments