Search in sources :

Example 41 with DefaultMessageFactory

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

the class XmlTransformServiceTest method testObtainUrlWithEmptyMetadataValueInMessage.

@Test
public void testObtainUrlWithEmptyMetadataValueInMessage() throws Exception {
    XmlTransformService service = new XmlTransformService();
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage();
    msg.addMetadata("key", "");
    try {
        service.setUrl("url");
        service.setMetadataKey("key");
        LifecycleHelper.init(service);
        assertTrue(service.obtainUrlToUse(msg).equals("url"));
    } finally {
        LifecycleHelper.close(service);
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 42 with DefaultMessageFactory

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

the class XmlTransformServiceTest method testObtainUrlWithNoMetadataValue.

@Test
public void testObtainUrlWithNoMetadataValue() throws Exception {
    XmlTransformService service = new XmlTransformService();
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage();
    try {
        service.setUrl("url");
        service.setMetadataKey("key");
        service.setAllowOverride(true);
        LifecycleHelper.init(service);
        assertTrue(service.obtainUrlToUse(msg).equals("url"));
    } finally {
        LifecycleHelper.close(service);
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 43 with DefaultMessageFactory

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

the class XmlTransformServiceTest method testIssue2641_NoOutputMessageEncoding.

@Test
public void testIssue2641_NoOutputMessageEncoding() throws Exception {
    DefaultMessageFactory factory = new DefaultMessageFactory();
    factory.setDefaultCharEncoding("ISO-8859-1");
    AdaptrisMessage msg = MessageHelper.createMessage(factory, PROPERTIES.getProperty(KEY_ISSUE2641_INPUT));
    Document srcXml = createDocument(msg.getPayload());
    XPath srcXpath = new XPath();
    String srcValue = srcXpath.selectSingleTextItem(srcXml, ISSUE2641_SRC_XPATH);
    assertEquals("ISO-8859-1", msg.getContentEncoding());
    XmlTransformService service = new XmlTransformService();
    service.setUrl(PROPERTIES.getProperty(KEY_ISSUE2641_TRANSFORM_URL));
    execute(service, msg);
    assertEquals("ISO-8859-1", msg.getContentEncoding());
    // We're using UTF-8 as the encoding; get bytes will give us the right thing.
    Document destXml = createDocument(msg.getPayload());
    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 : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) XPath(com.adaptris.util.text.xml.XPath) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 44 with DefaultMessageFactory

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

the class XmlTransformServiceTest method testObtainUrlWithNullMetadataValueInMessage.

@Test
public void testObtainUrlWithNullMetadataValueInMessage() throws Exception {
    XmlTransformService service = new XmlTransformService();
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage();
    try {
        service.setUrl("url");
        service.setMetadataKey("key");
        LifecycleHelper.init(service);
        assertTrue(service.obtainUrlToUse(msg).equals("url"));
    } finally {
        LifecycleHelper.close(service);
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 45 with DefaultMessageFactory

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

the class XmlTransformServiceTest method testIssue2641.

@Test
public void testIssue2641() throws Exception {
    DefaultMessageFactory factory = new DefaultMessageFactory();
    factory.setDefaultCharEncoding("ISO-8859-1");
    AdaptrisMessage msg = MessageHelper.createMessage(factory, PROPERTIES.getProperty(KEY_ISSUE2641_INPUT));
    Document srcXml = createDocument(msg.getPayload());
    XPath srcXpath = new XPath();
    String srcValue = srcXpath.selectSingleTextItem(srcXml, ISSUE2641_SRC_XPATH);
    assertEquals("ISO-8859-1", msg.getContentEncoding());
    XmlTransformService service = new XmlTransformService();
    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());
    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 : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) XPath(com.adaptris.util.text.xml.XPath) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Document(org.w3c.dom.Document) Test(org.junit.Test)

Aggregations

DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)170 Test (org.junit.Test)163 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)158 Channel (com.adaptris.core.Channel)37 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)36 HttpConsumerTest (com.adaptris.core.http.jetty.HttpConsumerTest)30 JettyHelper.createChannel (com.adaptris.core.http.jetty.JettyHelper.createChannel)30 StandaloneProducer (com.adaptris.core.StandaloneProducer)27 ServiceException (com.adaptris.core.ServiceException)26 File (java.io.File)26 ServiceList (com.adaptris.core.ServiceList)18 HttpConnection (com.adaptris.core.http.jetty.HttpConnection)18 JettyMessageConsumer (com.adaptris.core.http.jetty.JettyMessageConsumer)18 StandardResponseProducer (com.adaptris.core.http.jetty.StandardResponseProducer)18 GuidGenerator (com.adaptris.util.GuidGenerator)18 StandaloneRequestor (com.adaptris.core.StandaloneRequestor)15 ValidationStage (com.adaptris.transform.validate.ValidationStage)15 ConfiguredRequestMethodProvider (com.adaptris.core.http.client.ConfiguredRequestMethodProvider)12 PayloadFromTemplateService (com.adaptris.core.services.metadata.PayloadFromTemplateService)11 StandardWorkflow (com.adaptris.core.StandardWorkflow)10