Search in sources :

Example 6 with PayloadFactoryMediator

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());
}
Also used : PayloadFactoryMediator(org.apache.synapse.mediators.transform.PayloadFactoryMediator) Test(org.junit.Test)

Example 7 with 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());
}
Also used : SynapseXPath(org.apache.synapse.util.xpath.SynapseXPath) Argument(org.apache.synapse.mediators.transform.Argument) PayloadFactoryMediator(org.apache.synapse.mediators.transform.PayloadFactoryMediator) OMElement(org.apache.axiom.om.OMElement) PayloadFactoryMediator(org.apache.synapse.mediators.transform.PayloadFactoryMediator) Mediator(org.apache.synapse.Mediator) Test(org.junit.Test)

Example 8 with PayloadFactoryMediator

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());
}
Also used : PayloadFactoryMediator(org.apache.synapse.mediators.transform.PayloadFactoryMediator) ArrayList(java.util.ArrayList) MessageContext(org.apache.synapse.MessageContext)

Example 9 with PayloadFactoryMediator

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());
}
Also used : PayloadFactoryMediator(org.apache.synapse.mediators.transform.PayloadFactoryMediator) ArrayList(java.util.ArrayList) MessageContext(org.apache.synapse.MessageContext)

Aggregations

PayloadFactoryMediator (org.apache.synapse.mediators.transform.PayloadFactoryMediator)9 OMElement (org.apache.axiom.om.OMElement)6 Test (org.junit.Test)5 Argument (org.apache.synapse.mediators.transform.Argument)4 Mediator (org.apache.synapse.Mediator)3 ArrayList (java.util.ArrayList)2 MessageContext (org.apache.synapse.MessageContext)2 Value (org.apache.synapse.mediators.Value)2 SynapseXPath (org.apache.synapse.util.xpath.SynapseXPath)2 Iterator (java.util.Iterator)1 QName (javax.xml.namespace.QName)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 OMAttribute (org.apache.axiom.om.OMAttribute)1 JaxenException (org.jaxen.JaxenException)1