Search in sources :

Example 26 with AdaptrisMarshaller

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

the class MarshallingBaseCase method testMarshalToFile_NonExistent.

@Test
public void testMarshalToFile_NonExistent() throws Exception {
    AdaptrisMarshaller marshaller = createMarshaller();
    Adapter adapter = createMarshallingObject();
    File dir = File.createTempFile("pfx", ".sfx");
    File nonExistent = new File(dir, new GuidGenerator().getUUID());
    try {
        marshaller.marshal(adapter, nonExistent);
        fail();
    } catch (CoreException expected) {
    } finally {
        FileUtils.deleteQuietly(dir);
    }
}
Also used : CoreException(com.adaptris.core.CoreException) AdaptrisMarshaller(com.adaptris.core.AdaptrisMarshaller) Adapter(com.adaptris.core.Adapter) GuidGenerator(com.adaptris.util.GuidGenerator) File(java.io.File) Test(org.junit.Test)

Example 27 with AdaptrisMarshaller

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

the class MarshallingBaseCase method testUnmarshal_NonExistent.

@Test
public void testUnmarshal_NonExistent() throws Exception {
    AdaptrisMarshaller marshaller = createMarshaller();
    File dir = File.createTempFile("pfx", ".sfx");
    File nonExistent = new File(dir, new GuidGenerator().getUUID());
    try {
        marshaller.unmarshal(nonExistent);
        fail();
    } catch (CoreException expected) {
    } finally {
        FileUtils.deleteQuietly(dir);
    }
}
Also used : CoreException(com.adaptris.core.CoreException) AdaptrisMarshaller(com.adaptris.core.AdaptrisMarshaller) GuidGenerator(com.adaptris.util.GuidGenerator) File(java.io.File) Test(org.junit.Test)

Example 28 with AdaptrisMarshaller

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

the class MarshallingBaseCase method testUnmarshalFromInputStream_WithException.

@Test
public void testUnmarshalFromInputStream_WithException() throws Exception {
    AdaptrisMarshaller marshaller = createMarshaller();
    Adapter adapter = createMarshallingObject();
    String s = marshaller.marshal(adapter);
    InputStream fail = new InputStream() {

        @Override
        public int read() throws IOException {
            throw new IOException("testUnmarshalFromInputStream_WithException");
        }
    };
    try (InputStream in = fail) {
        Adapter adapter2 = (Adapter) marshaller.unmarshal(in);
        fail();
    } catch (CoreException e) {
        assertNotNull(e.getCause());
        assertRootCause("testUnmarshalFromInputStream_WithException", e);
    }
}
Also used : CoreException(com.adaptris.core.CoreException) AdaptrisMarshaller(com.adaptris.core.AdaptrisMarshaller) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Adapter(com.adaptris.core.Adapter) URLString(com.adaptris.util.URLString) IOException(java.io.IOException) Test(org.junit.Test)

Example 29 with AdaptrisMarshaller

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

the class MarshallingBaseCase method testUnmarshalString_InvalidXML.

@Test
public void testUnmarshalString_InvalidXML() throws Exception {
    String xml = "This isn't XML";
    AdaptrisMarshaller marshaller = createMarshaller();
    try {
        marshaller.unmarshal(xml);
        fail();
    } catch (CoreException expected) {
    }
}
Also used : CoreException(com.adaptris.core.CoreException) AdaptrisMarshaller(com.adaptris.core.AdaptrisMarshaller) URLString(com.adaptris.util.URLString) Test(org.junit.Test)

Example 30 with AdaptrisMarshaller

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

the class MarshallingBaseCase method testMarshalToURL.

@Test
public void testMarshalToURL() throws Exception {
    AdaptrisMarshaller marshaller = createMarshaller();
    Adapter adapter = createMarshallingObject();
    File f = new File(testOutputDir, new GuidGenerator().getUUID());
    URL url = f.toURI().toURL();
    try {
        marshaller.marshal(null, (URL) null);
        fail();
    } catch (IllegalArgumentException e) {
    }
    try {
        marshaller.marshal(adapter, (URL) null);
        fail();
    } catch (IllegalArgumentException e) {
    }
    try {
        marshaller.marshal(null, url);
        fail();
    } catch (IllegalArgumentException e) {
    }
    try {
        marshaller.marshal(adapter, new URL("http://development.adaptris.com/bugs"));
        fail();
    } catch (CoreException e) {
        assertEquals("URL protocol must be file:", e.getMessage());
    }
    marshaller.marshal(adapter, url);
}
Also used : CoreException(com.adaptris.core.CoreException) AdaptrisMarshaller(com.adaptris.core.AdaptrisMarshaller) Adapter(com.adaptris.core.Adapter) GuidGenerator(com.adaptris.util.GuidGenerator) File(java.io.File) URL(java.net.URL) 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