Search in sources :

Example 36 with MultiPayloadAdaptrisMessage

use of com.adaptris.core.MultiPayloadAdaptrisMessage in project interlok by adaptris.

the class MultiPayloadXmlTransformServiceTest method testXSLT_FatalError.

@Test
public void testXSLT_FatalError() throws Exception {
    MultiPayloadAdaptrisMessage m1 = MessageHelper.createMultiPayloadMessage(PAYLOAD_ID_SOURCE, PROPERTIES.getProperty(KEY_XML_TEST_INPUT));
    MultiPayloadXmlTransformService service = createBaseExample();
    service.setUrl(PROPERTIES.getProperty(KEY_XML_TEST_FATAL_TRANSFORM_URL));
    try {
        execute(service, m1);
        fail();
    } catch (ServiceException expected) {
        assertExceptionCause(expected, TransformerException.class, UncheckedXPathException.class);
    }
}
Also used : UncheckedXPathException(net.sf.saxon.trans.UncheckedXPathException) ServiceException(com.adaptris.core.ServiceException) MultiPayloadAdaptrisMessage(com.adaptris.core.MultiPayloadAdaptrisMessage) TransformerException(javax.xml.transform.TransformerException) Test(org.junit.Test)

Example 37 with MultiPayloadAdaptrisMessage

use of com.adaptris.core.MultiPayloadAdaptrisMessage in project interlok by adaptris.

the class MultiPayloadXmlTransformServiceTest method testObtainUrlWithNoMetadataValueNoUrl.

@Test
public void testObtainUrlWithNoMetadataValueNoUrl() throws Exception {
    MultiPayloadAdaptrisMessage msg = (MultiPayloadAdaptrisMessage) new MultiPayloadMessageFactory().newMessage();
    MultiPayloadXmlTransformService service = new MultiPayloadXmlTransformService();
    try {
        service.setMetadataKey("key");
        service.setAllowOverride(true);
        LifecycleHelper.init(service);
        try {
            service.obtainUrlToUse(msg);
            fail();
        } catch (ServiceException expected) {
        // expected
        }
    } finally {
        LifecycleHelper.close(service);
    }
}
Also used : MultiPayloadMessageFactory(com.adaptris.core.MultiPayloadMessageFactory) ServiceException(com.adaptris.core.ServiceException) MultiPayloadAdaptrisMessage(com.adaptris.core.MultiPayloadAdaptrisMessage) Test(org.junit.Test)

Example 38 with MultiPayloadAdaptrisMessage

use of com.adaptris.core.MultiPayloadAdaptrisMessage in project interlok by adaptris.

the class MultiPayloadXmlTransformServiceTest method testIssue2641.

@Test
public void testIssue2641() throws Exception {
    MultiPayloadAdaptrisMessage msg = MessageHelper.createMultiPayloadMessage(PAYLOAD_ID_SOURCE, PROPERTIES.getProperty(KEY_ISSUE2641_INPUT), "ISO-8859-1");
    Document srcXml = createDocument(msg.getPayload(PAYLOAD_ID_SOURCE));
    XPath srcXpath = new XPath();
    String srcValue = srcXpath.selectSingleTextItem(srcXml, ISSUE2641_SRC_XPATH);
    assertEquals("ISO-8859-1", msg.getContentEncoding());
    MultiPayloadXmlTransformService service = createBaseExample();
    service.setUrl(PROPERTIES.getProperty(KEY_ISSUE2641_TRANSFORM_URL));
    service.setOutputMessageEncoding("UTF-8");
    execute(service, msg);
    assertEquals("UTF-8", msg.getContentEncoding());
    Document destXml = createDocument(msg.getPayload(PAYLOAD_ID_OUTPUT));
    XPath destXpath = new XPath();
    String destValue = destXpath.selectSingleTextItem(destXml, ISSUE2641_DEST_XPATH);
    log.debug("testIssue2641:: srcValue  = [" + srcValue + "]");
    log.debug("testIssue2641:: destValue = [" + destValue + "]");
    // All things being equal, they should be the same.
    assertEquals(srcValue, destValue);
}
Also used : XPath(com.adaptris.util.text.xml.XPath) MultiPayloadAdaptrisMessage(com.adaptris.core.MultiPayloadAdaptrisMessage) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 39 with MultiPayloadAdaptrisMessage

use of com.adaptris.core.MultiPayloadAdaptrisMessage in project interlok by adaptris.

the class MultiPayloadXmlTransformServiceTest method testObtainUrlWithMetadataValueInMessageAllowOverride.

@Test
public void testObtainUrlWithMetadataValueInMessageAllowOverride() throws Exception {
    MultiPayloadAdaptrisMessage msg = (MultiPayloadAdaptrisMessage) new MultiPayloadMessageFactory().newMessage();
    MultiPayloadXmlTransformService service = new MultiPayloadXmlTransformService();
    msg.addMetadata("key", "val");
    try {
        service.setUrl(URL);
        service.setMetadataKey("key");
        service.setAllowOverride(true);
        LifecycleHelper.init(service);
        // allow override is false
        assertEquals("val", service.obtainUrlToUse(msg));
    } finally {
        LifecycleHelper.close(service);
    }
}
Also used : MultiPayloadMessageFactory(com.adaptris.core.MultiPayloadMessageFactory) MultiPayloadAdaptrisMessage(com.adaptris.core.MultiPayloadAdaptrisMessage) Test(org.junit.Test)

Example 40 with MultiPayloadAdaptrisMessage

use of com.adaptris.core.MultiPayloadAdaptrisMessage in project interlok by adaptris.

the class MultiPayloadXmlTransformServiceTest method testObtainUrlWithNoMetadataValue.

@Test
public void testObtainUrlWithNoMetadataValue() throws Exception {
    MultiPayloadXmlTransformService service = new MultiPayloadXmlTransformService();
    MultiPayloadAdaptrisMessage msg = (MultiPayloadAdaptrisMessage) new MultiPayloadMessageFactory().newMessage();
    try {
        service.setUrl(URL);
        service.setMetadataKey("key");
        service.setAllowOverride(true);
        LifecycleHelper.init(service);
        assertEquals(URL, service.obtainUrlToUse(msg));
    } finally {
        LifecycleHelper.close(service);
    }
}
Also used : MultiPayloadMessageFactory(com.adaptris.core.MultiPayloadMessageFactory) MultiPayloadAdaptrisMessage(com.adaptris.core.MultiPayloadAdaptrisMessage) Test(org.junit.Test)

Aggregations

MultiPayloadAdaptrisMessage (com.adaptris.core.MultiPayloadAdaptrisMessage)48 Test (org.junit.Test)44 MultiPayloadMessageFactory (com.adaptris.core.MultiPayloadMessageFactory)24 ServiceException (com.adaptris.core.ServiceException)5 InputStream (java.io.InputStream)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)3 StxTransformerFactory (com.adaptris.util.text.xml.StxTransformerFactory)3 XsltTransformerFactory (com.adaptris.util.text.xml.XsltTransformerFactory)3 TransformerException (javax.xml.transform.TransformerException)3 KeyValuePair (com.adaptris.util.KeyValuePair)2 XPath (com.adaptris.util.text.xml.XPath)2 UncheckedXPathException (net.sf.saxon.trans.UncheckedXPathException)2 Document (org.w3c.dom.Document)2 CoreException (com.adaptris.core.CoreException)1 KeyValuePairList (com.adaptris.util.KeyValuePairList)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 ArrayList (java.util.ArrayList)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1