Search in sources :

Example 21 with AdaptrisMarshaller

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

the class MarshallingBaseCase method testRoundTripToFile.

@Test
public void testRoundTripToFile() throws Exception {
    AdaptrisMarshaller marshaller = createMarshaller();
    Adapter adapter = createMarshallingObject();
    File f = new File(testOutputDir, new GuidGenerator().getUUID());
    marshaller.marshal(adapter, f);
    assertRoundtripEquality(adapter, marshaller.unmarshal(f));
}
Also used : AdaptrisMarshaller(com.adaptris.core.AdaptrisMarshaller) Adapter(com.adaptris.core.Adapter) GuidGenerator(com.adaptris.util.GuidGenerator) File(java.io.File) Test(org.junit.Test)

Example 22 with AdaptrisMarshaller

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

the class MarshallingBaseCase method testRoundTripToURL.

@Test
public void testRoundTripToURL() throws Exception {
    AdaptrisMarshaller marshaller = createMarshaller();
    Adapter adapter = createMarshallingObject();
    File f = new File(testOutputDir, new GuidGenerator().getUUID());
    marshaller.marshal(adapter, f.toURI().toURL());
    assertRoundtripEquality(adapter, marshaller.unmarshal(f.toURI().toURL()));
}
Also used : AdaptrisMarshaller(com.adaptris.core.AdaptrisMarshaller) Adapter(com.adaptris.core.Adapter) GuidGenerator(com.adaptris.util.GuidGenerator) File(java.io.File) Test(org.junit.Test)

Example 23 with AdaptrisMarshaller

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

the class MarshallingBaseCase method testMarshalToWriter_WithException.

@Test
public void testMarshalToWriter_WithException() throws Exception {
    AdaptrisMarshaller marshaller = createMarshaller();
    Adapter adapter = createMarshallingObject();
    Writer fail = new Writer() {

        @Override
        public void write(char[] cbuf, int off, int len) throws IOException {
            throw new IOException("testMarshalToWriter_WithException");
        }

        @Override
        public void flush() throws IOException {
            throw new IOException("testMarshalToWriter_WithException");
        }

        @Override
        public void close() throws IOException {
        }
    };
    try (Writer out = fail) {
        marshaller.marshal(adapter, out);
        fail();
    } catch (CoreException e) {
        assertNotNull(e.getCause());
        // assertEquals(IOException.class, e.getCause().getClass());
        assertRootCause("testMarshalToWriter_WithException", e);
    }
}
Also used : CoreException(com.adaptris.core.CoreException) AdaptrisMarshaller(com.adaptris.core.AdaptrisMarshaller) Adapter(com.adaptris.core.Adapter) IOException(java.io.IOException) StringWriter(java.io.StringWriter) Writer(java.io.Writer) Test(org.junit.Test)

Example 24 with AdaptrisMarshaller

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

the class MarshallingBaseCase method testUnmarshalFromUrlWithException.

@Test
public void testUnmarshalFromUrlWithException() throws Exception {
    AdaptrisMarshaller marshaller = createMarshaller();
    // Ha, anonymous URLStreamHandler to the rescue.
    URL failingUrl = new URL("http", "development.adaptris.com", 80, "index.html", new URLStreamHandler() {

        @Override
        protected URLConnection openConnection(URL u) throws IOException {
            throw new IOException("testUnmarshalFromUrl");
        }
    });
    try {
        marshaller.unmarshal(failingUrl);
        fail();
    } catch (CoreException e) {
        assertNotNull(e.getCause());
        assertEquals(IOException.class, e.getCause().getClass());
        assertEquals("testUnmarshalFromUrl", e.getCause().getMessage());
    }
}
Also used : URLStreamHandler(java.net.URLStreamHandler) CoreException(com.adaptris.core.CoreException) AdaptrisMarshaller(com.adaptris.core.AdaptrisMarshaller) IOException(java.io.IOException) URL(java.net.URL) URLConnection(java.net.URLConnection) Test(org.junit.Test)

Example 25 with AdaptrisMarshaller

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

the class MarshallingBaseCase method testMarshalToOutputStream.

@Test
public void testMarshalToOutputStream() throws Exception {
    AdaptrisMarshaller marshaller = createMarshaller();
    Adapter adapter = createMarshallingObject();
    try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        marshaller.marshal(adapter, out);
    }
}
Also used : AdaptrisMarshaller(com.adaptris.core.AdaptrisMarshaller) Adapter(com.adaptris.core.Adapter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Aggregations

AdaptrisMarshaller (com.adaptris.core.AdaptrisMarshaller)64 Test (org.junit.Test)57 Adapter (com.adaptris.core.Adapter)43 ObjectName (javax.management.ObjectName)21 NullConnection (com.adaptris.core.NullConnection)17 URLString (com.adaptris.util.URLString)11 CoreException (com.adaptris.core.CoreException)10 GuidGenerator (com.adaptris.util.GuidGenerator)9 File (java.io.File)9 ArrayList (java.util.ArrayList)9 IOException (java.io.IOException)7 Channel (com.adaptris.core.Channel)4 NullService (com.adaptris.core.NullService)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)3 SharedConnection (com.adaptris.core.SharedConnection)3 StandardWorkflow (com.adaptris.core.StandardWorkflow)3 MockServiceWithConnection (com.adaptris.core.stubs.MockServiceWithConnection)3 URL (java.net.URL)3