use of org.apache.synapse.Mediator in project wso2-synapse by wso2.
the class POJOCommandMediatorTest method testPojoWithStaticPropertiesCommandImpl.
public void testPojoWithStaticPropertiesCommandImpl() throws Exception {
Mediator pcm = MediatorFactoryFinder.getInstance().getMediator(createOMElement("<pojoCommand name='org.apache.synapse.mediators.ext.POJOCommandTestImplementedMediator' " + "xmlns='http://ws.apache.org/ns/synapse'><property name=\"testProp\" " + "value=\"Test Property\"/></pojoCommand>"), new Properties());
POJOCommandTestHelper.reset();
TestMessageContext msgContext = new TestMessageContext();
msgContext.setEnvironment(new Axis2SynapseEnvironment(new SynapseConfiguration()));
pcm.mediate(msgContext);
assertEquals("Test Property", POJOCommandTestHelper.getInstance().getChangedProperty());
assertTrue(POJOCommandTestHelper.getInstance().isExecuted());
}
use of org.apache.synapse.Mediator in project wso2-synapse by wso2.
the class SwitchMediatorTest method setUp.
public void setUp() throws Exception {
ibmMediator = new TestMediator();
ibmMediator.setHandler(new TestMediateHandler() {
public void handle(MessageContext synCtx) {
setExecutedCase("IBM");
}
});
msftMediator = new TestMediator();
msftMediator.setHandler(new TestMediateHandler() {
public void handle(MessageContext synCtx) {
setExecutedCase("MSFT");
}
});
defaultMediator = new TestMediator();
defaultMediator.setHandler(new TestMediateHandler() {
public void handle(MessageContext synCtx) {
setExecutedCase("DEFAULT");
}
});
// create a new switch mediator
switchMediator = new SwitchMediator();
// set xpath condition to select symbol
SynapseXPath xpath = new SynapseXPath("//wsx:symbol");
xpath.addNamespace("wsx", "http://www.webserviceX.NET/");
switchMediator.setSource(xpath);
SwitchCase caseOne = new SwitchCase();
caseOne.setRegex(Pattern.compile("IBM"));
AnonymousListMediator mediatorOne = new AnonymousListMediator();
mediatorOne.addAll(Arrays.asList(new Mediator[] { ibmMediator }));
caseOne.setCaseMediator(mediatorOne);
SwitchCase caseTwo = new SwitchCase();
caseTwo.setRegex(Pattern.compile("MSFT"));
AnonymousListMediator mediatorTwo = new AnonymousListMediator();
mediatorTwo.addAll(Arrays.asList(new Mediator[] { msftMediator }));
caseTwo.setCaseMediator(mediatorTwo);
SwitchCase caseDefault = new SwitchCase();
AnonymousListMediator mediatorDefault = new AnonymousListMediator();
mediatorDefault.addAll(Arrays.asList(new Mediator[] { defaultMediator }));
caseDefault.setCaseMediator(mediatorDefault);
// set ibm mediator to be called for IBM, msft for MSFT and default for others..
switchMediator.addCase(caseOne);
switchMediator.addCase(caseTwo);
switchMediator.setDefaultCase(caseDefault);
}
use of org.apache.synapse.Mediator in project wso2-synapse by wso2.
the class CloneMediatorTest method testClonningWithContinueParent.
public void testClonningWithContinueParent() throws Exception {
Mediator clone = fac.createMediator(createOMElement("<clone continueParent=\"true\" " + "xmlns=\"http://ws.apache.org/ns/synapse\"><target soapAction=\"urn:clone\" " + "sequence=\"seqRef\"/><target to=\"http://test\"><sequence><sequence " + "key=\"seqRef\"/></sequence></target></clone>"), new Properties());
assertTrue(clone.mediate(testCtx));
while (helperMediator.getMediatedContext(1) == null) {
Thread.sleep(100);
}
MessageContext mediatedCtx = helperMediator.getMediatedContext(0);
assertTrue(mediatedCtx.getEnvelope().getBody().getFirstElement() == null);
String formerSAction = mediatedCtx.getSoapAction();
mediatedCtx = helperMediator.getMediatedContext(1);
if ("urn:clone".equals(formerSAction)) {
assertEquals(mediatedCtx.getSoapAction(), "urn:test");
assertEquals(mediatedCtx.getTo().getAddress(), "http://test");
} else {
assertEquals(mediatedCtx.getSoapAction(), "urn:clone");
}
assertEquals(testCtx.getSoapAction(), "urn:test");
assertEquals(testCtx.getTo(), null);
}
use of org.apache.synapse.Mediator in project wso2-synapse by wso2.
the class CloneMediatorTest method testDeepClonedOMTypeProperty.
public void testDeepClonedOMTypeProperty() throws InterruptedException {
String propName = "testProp";
Mediator clone = fac.createMediator(createOMElement("<clone " + "xmlns=\"http://ws.apache.org/ns/synapse\"><target soapAction=\"urn:clone\" " + "sequence=\"seqRef\"/><target to=\"http://test\"><sequence><sequence " + "key=\"seqRef\"/></sequence></target></clone>"), new Properties());
PropertyMediator propertyMediator = new PropertyMediator();
propertyMediator.setName(propName);
propertyMediator.setValueElement(TestUtils.createOMElement("<a><b>asdf</b></a>"));
propertyMediator.setScope("default");
propertyMediator.mediate(testCtx);
clone.mediate(testCtx);
while (helperMediator.getMediatedContext(1) == null) {
Thread.sleep(100);
}
MessageContext mediatedCtx = helperMediator.getMediatedContext(0);
Object obj = mediatedCtx.getProperty(propName);
Assert.assertNotNull(obj);
Assert.assertTrue(obj instanceof OMElement);
OMElement omElement = (OMElement) obj;
String cloneStr = omElement.getParent().toString();
OMElement omElement1 = (OMElement) testCtx.getProperty(propName);
String parentID = omElement1.getParent().toString();
Assert.assertTrue(!cloneStr.equals(parentID));
}
use of org.apache.synapse.Mediator in project wso2-synapse by wso2.
the class IterateMediatorTest method testIterationWithPreservePayload.
public void testIterationWithPreservePayload() throws Exception {
Mediator iterate = fac.createMediator(createOMElement("<iterate " + "expression=\"//original/itr\" preservePayload=\"true\" attachPath=\"//original\" " + "xmlns=\"http://ws.apache.org/ns/synapse\"><target soapAction=\"urn:iterate\" " + "sequence=\"seqRef\"/></iterate>"), new Properties());
iterate.mediate(testCtx);
while (helperMediator.getMediatedContext(1) == null) {
Thread.sleep(100);
}
MessageContext mediatedCtx = helperMediator.getMediatedContext(0);
assertEquals(mediatedCtx.getSoapAction(), "urn:iterate");
OMElement formerBody = mediatedCtx.getEnvelope().getBody().getFirstElement();
mediatedCtx = helperMediator.getMediatedContext(1);
assertEquals(mediatedCtx.getSoapAction(), "urn:iterate");
if (formerBody == null) {
assertEquals(mediatedCtx.getEnvelope().getBody().getFirstElement().getFirstElement().getText(), helperMediator.getCheckString());
}
}
Aggregations