use of org.apache.synapse.mediators.transform.PayloadFactoryMediator in project wso2-synapse by wso2.
the class PayloadFactoryMediatorSerializerTest method testSerializeSpecificMediator.
/**
* Test SerializeSpecificMediator method with payloadFactory mediator, with no format set.
*/
@Test
public void testSerializeSpecificMediator() {
exception.expect(SynapseException.class);
exception.expectMessage("Invalid payloadFactory mediator, format is required");
PayloadFactoryMediatorSerializer serializer = new PayloadFactoryMediatorSerializer();
serializer.serializeSpecificMediator(new PayloadFactoryMediator());
}
use of org.apache.synapse.mediators.transform.PayloadFactoryMediator in project wso2-synapse by wso2.
the class PayloadFactoryMediatorSerializerTest method testSerializeSpecificMediator5.
/**
* Test SerializeSpecificMediator method with PathArgument with expression added for payloadFactory mediator
* and assert that expression is added.
*/
@Test
public void testSerializeSpecificMediator5() throws JaxenException {
PayloadFactoryMediatorSerializer serializer = new PayloadFactoryMediatorSerializer();
PayloadFactoryMediator payloadFactoryMediator = new PayloadFactoryMediator();
Argument argument = new Argument();
argument.setExpression(new SynapseXPath("//name"));
payloadFactoryMediator.addPathArgument(argument);
payloadFactoryMediator.setFormat(format);
OMElement element = serializer.serializeSpecificMediator(payloadFactoryMediator);
MediatorFactory mediatorFactory = new PayloadFactoryMediatorFactory();
Mediator mediator = mediatorFactory.createMediator(element, null);
Assert.assertNotNull(element);
Assert.assertEquals("Expression added for path argument is not serialized", "//name", ((PayloadFactoryMediator) mediator).getPathArgumentList().get(0).getExpression().toString());
}
use of org.apache.synapse.mediators.transform.PayloadFactoryMediator in project wso2-synapse by wso2.
the class EnrichMediatorTest method testEnrichingEnvelopeUsingUnclonedProperty.
public void testEnrichingEnvelopeUsingUnclonedProperty() throws Exception {
String xml1 = "<p:echoInt xmlns:p=\"http://echo.services.core.carbon.wso2.org\">" + " <!--0 to 1 occurrence-->" + "<in>35</in>" + "</p:echoInt>";
String format = "<p:echoInt xmlns:p=\"http://echo.services.core.carbon.wso2.org\">" + "<in>1</in></p:echoInt>";
// name of the property
String key = "envelope";
// create a message context from xml1
MessageContext msgCtxt1 = TestUtils.createLightweightSynapseMessageContext(xml1);
// enrich the envelope to a property
EnrichMediator enrichMediator1 = createEnvelopeToPropertyEnrichMediator(key, false);
enrichMediator1.mediate(msgCtxt1);
String expectedPropVal = "<?xml version='1.0' encoding='utf-8'?>" + "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<soapenv:Body>" + xml1 + "</soapenv:Body></soapenv:Envelope>";
// assert the property
assertEquals(expectedPropVal, ((ArrayList) msgCtxt1.getProperty(key)).get(0).toString());
PayloadFactoryMediator payloadFacMediator = new PayloadFactoryMediator();
payloadFacMediator.setType("xml");
payloadFacMediator.setFormat(format);
payloadFacMediator.mediate(msgCtxt1);
String expectedPayload = "<soapenv:Body xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">" + format + "</soapenv:Body>";
// assert the new payload
assertEquals(expectedPayload, msgCtxt1.getEnvelope().getBody().toString());
// expected property
expectedPropVal = expectedPropVal.replaceFirst(xml1, format);
// assert the property again - since the property was created using an
// uncloned message, it should change
assertEquals(expectedPropVal, ((ArrayList) msgCtxt1.getProperty(key)).get(0).toString());
}
use of org.apache.synapse.mediators.transform.PayloadFactoryMediator in project wso2-synapse by wso2.
the class EnrichMediatorTest method testEnrichingEnvelopeUsingClonedProperty.
public void testEnrichingEnvelopeUsingClonedProperty() throws Exception {
String xml1 = "<p:echoInt xmlns:p=\"http://echo.services.core.carbon.wso2.org\">" + " <!--0 to 1 occurrence-->" + "<in>35</in>" + "</p:echoInt>";
String format = "<p:echoInt xmlns:p=\"http://echo.services.core.carbon.wso2.org\">" + "<in>1</in></p:echoInt>";
// name of the property
String key = "envelope";
// create a message context from xml1
MessageContext msgCtxt1 = TestUtils.createLightweightSynapseMessageContext(xml1);
// enrich the envelope to a property
EnrichMediator enrichMediator1 = createEnvelopeToPropertyEnrichMediator(key, true);
enrichMediator1.mediate(msgCtxt1);
String expectedPropVal = "<?xml version='1.0' encoding='utf-8'?>" + "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<soapenv:Body>" + xml1 + "</soapenv:Body></soapenv:Envelope>";
// assert the property
assertEquals(expectedPropVal, ((ArrayList) msgCtxt1.getProperty(key)).get(0).toString());
PayloadFactoryMediator payloadFacMediator = new PayloadFactoryMediator();
payloadFacMediator.setType("xml");
payloadFacMediator.setFormat(format);
payloadFacMediator.mediate(msgCtxt1);
String expectedPayload = "<soapenv:Body xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">" + format + "</soapenv:Body>";
// assert the new payload
assertEquals(expectedPayload, msgCtxt1.getEnvelope().getBody().toString());
// assert the property again - since the property was created using a
// cloned message, it should not change
assertEquals(expectedPropVal, ((ArrayList) msgCtxt1.getProperty(key)).get(0).toString());
}
Aggregations