use of org.apache.synapse.MessageContext 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.MessageContext 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.MessageContext 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());
}
}
use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class AnnotatedCommandMediatorTest method testBasicExecute.
public void testBasicExecute() throws Exception {
AnnotatedCommandMediator m = new AnnotatedCommandMediator();
m.setCommand(AnnotatedCommand.class);
Mediator pcm = MediatorFactoryFinder.getInstance().getMediator(createOMElement("<annotatedCommand name='org.apache.synapse.mediators.ext.AnnotatedCommand2' xmlns='http://ws.apache.org/ns/synapse'/>"), new Properties());
MessageContext mc = TestUtils.getTestContext("<m:getQuote xmlns:m=\"http://services.samples/xsd\"><m:request><m:symbol>IBM</m:symbol></m:request></m:getQuote>");
pcm.mediate(mc);
assertEquals("IBM", AnnotatedCommand2.fieldResult);
assertEquals("IBM", AnnotatedCommand2.methodResult);
}
use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class Axis2MessageContextTest method testMessageContextGetStringValueEnvelope.
public void testMessageContextGetStringValueEnvelope() throws Exception {
SynapseXPath axiomXpath = new SynapseXPath("/s11:Envelope/s11:Body/ns1:a/ns1:c");
axiomXpath.addNamespace("s11", nsSoapEnv);
axiomXpath.addNamespace("ns1", nsNamespace1);
MessageContext synCtx = TestUtils.getTestContext(sampleBody);
String result = axiomXpath.stringValueOf(synCtx);
assertEquals("second", result);
}
Aggregations