Search in sources :

Example 6 with MultiPayloadMessageFactory

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

the class MultiPayloadXmlTransformServiceTest method testObtainUrlWithEmptyMetadataValueInMessage.

@Test
public void testObtainUrlWithEmptyMetadataValueInMessage() throws Exception {
    MultiPayloadXmlTransformService service = new MultiPayloadXmlTransformService();
    MultiPayloadAdaptrisMessage msg = (MultiPayloadAdaptrisMessage) new MultiPayloadMessageFactory().newMessage();
    msg.addMetadata("key", "");
    try {
        service.setUrl(URL);
        service.setMetadataKey("key");
        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)

Example 7 with MultiPayloadMessageFactory

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

the class MultiPayloadStreamInputParameterTest method testExtract.

@Test
public void testExtract() throws Exception {
    MultiPayloadStreamInputParameter parameter = new MultiPayloadStreamInputParameter();
    parameter.setPayloadId(ID);
    MultiPayloadAdaptrisMessage message = (MultiPayloadAdaptrisMessage) new MultiPayloadMessageFactory().newMessage(ID, PAYLOAD);
    try (InputStream stream = parameter.extract(message)) {
        for (byte b : PAYLOAD) {
            assertEquals(b, stream.read());
        }
    }
    try (InputStream stream = parameter.extract(ID, message)) {
        for (byte b : PAYLOAD) {
            assertEquals(b, stream.read());
        }
    }
    try (InputStream stream = parameter.extract(null, message)) {
        for (byte b : PAYLOAD) {
            assertEquals(b, stream.read());
        }
    }
}
Also used : MultiPayloadMessageFactory(com.adaptris.core.MultiPayloadMessageFactory) InputStream(java.io.InputStream) MultiPayloadAdaptrisMessage(com.adaptris.core.MultiPayloadAdaptrisMessage) Test(org.junit.Test)

Example 8 with MultiPayloadMessageFactory

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

the class MultiPayloadStreamOutputParameterTest method testInsertNullStream.

@Test
public void testInsertNullStream() throws Exception {
    MultiPayloadMessageFactory messageFactory = new MultiPayloadMessageFactory();
    MultiPayloadAdaptrisMessage message = (MultiPayloadAdaptrisMessage) messageFactory.newMessage();
    try {
        InputStreamWithEncoding stream = new InputStreamWithEncoding(null, ENCODING);
        MultiPayloadStreamOutputParameter parameter = new MultiPayloadStreamOutputParameter();
        parameter.insert(stream, ID, message);
    } catch (Exception e) {
    // expected
    }
}
Also used : MultiPayloadMessageFactory(com.adaptris.core.MultiPayloadMessageFactory) MultiPayloadAdaptrisMessage(com.adaptris.core.MultiPayloadAdaptrisMessage) Test(org.junit.Test)

Example 9 with MultiPayloadMessageFactory

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

the class MultiPayloadStreamOutputParameterTest method testInsert.

@Test
public void testInsert() throws Exception {
    MultiPayloadAdaptrisMessage message = (MultiPayloadAdaptrisMessage) new MultiPayloadMessageFactory().newMessage();
    try (InputStream in = new ByteArrayInputStream(PAYLOAD.getBytes())) {
        InputStreamWithEncoding stream = new InputStreamWithEncoding(in, ENCODING);
        MultiPayloadStreamOutputParameter parameter = new MultiPayloadStreamOutputParameter();
        parameter.insert(stream, ID, message);
    }
    assertEquals(PAYLOAD, message.getContent(ID));
}
Also used : MultiPayloadMessageFactory(com.adaptris.core.MultiPayloadMessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MultiPayloadAdaptrisMessage(com.adaptris.core.MultiPayloadAdaptrisMessage) Test(org.junit.Test)

Example 10 with MultiPayloadMessageFactory

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

the class MultiPayloadStreamOutputParameterTest method testInsertUseDefaultId.

@Test
public void testInsertUseDefaultId() throws Exception {
    MultiPayloadMessageFactory messageFactory = new MultiPayloadMessageFactory();
    MultiPayloadAdaptrisMessage message = (MultiPayloadAdaptrisMessage) messageFactory.newMessage();
    try (InputStream in = new ByteArrayInputStream(PAYLOAD.getBytes())) {
        InputStreamWithEncoding stream = new InputStreamWithEncoding(in, ENCODING);
        MultiPayloadStreamOutputParameter parameter = new MultiPayloadStreamOutputParameter();
        parameter.insert(stream, null, message);
    }
    assertEquals(PAYLOAD, message.getContent(messageFactory.getDefaultPayloadId()));
}
Also used : MultiPayloadMessageFactory(com.adaptris.core.MultiPayloadMessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MultiPayloadAdaptrisMessage(com.adaptris.core.MultiPayloadAdaptrisMessage) Test(org.junit.Test)

Aggregations

MultiPayloadMessageFactory (com.adaptris.core.MultiPayloadMessageFactory)26 MultiPayloadAdaptrisMessage (com.adaptris.core.MultiPayloadAdaptrisMessage)24 Test (org.junit.Test)23 InputStream (java.io.InputStream)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Before (org.junit.Before)2 ServiceException (com.adaptris.core.ServiceException)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1