Search in sources :

Example 41 with AdaptrisMarshaller

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

the class MarshallingBaseCase method testUnmarshalFromReader_WithException.

@Test
public void testUnmarshalFromReader_WithException() throws Exception {
    AdaptrisMarshaller marshaller = createMarshaller();
    Adapter adapter = createMarshallingObject();
    String s = marshaller.marshal(adapter);
    Reader fail = new FilterReader(new StringReader(s)) {

        @Override
        public int read() throws IOException {
            throw new IOException("testUnmarshalFromReader_WithException");
        }

        @Override
        public int read(char[] cbuf, int off, int len) throws IOException {
            throw new IOException("testUnmarshalFromReader_WithException");
        }
    };
    try (Reader in = fail) {
        Adapter adapter2 = (Adapter) marshaller.unmarshal(in);
        fail();
    } catch (CoreException e) {
        assertNotNull(e.getCause());
        // assertEquals(IOException.class, e.getCause().getClass());
        assertRootCause("testUnmarshalFromReader_WithException", e);
    }
}
Also used : CoreException(com.adaptris.core.CoreException) AdaptrisMarshaller(com.adaptris.core.AdaptrisMarshaller) StringReader(java.io.StringReader) FilterReader(java.io.FilterReader) Reader(java.io.Reader) StringReader(java.io.StringReader) Adapter(com.adaptris.core.Adapter) URLString(com.adaptris.util.URLString) IOException(java.io.IOException) FilterReader(java.io.FilterReader) Test(org.junit.Test)

Example 42 with AdaptrisMarshaller

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

the class MarshallingBaseCase method testUnmarshalFromURLString.

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

Example 43 with AdaptrisMarshaller

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

the class MarshallingBaseCase method testUnmarshalFromUrlStringClasspath.

@Test
public void testUnmarshalFromUrlStringClasspath() throws Exception {
    AdaptrisMarshaller marshaller = createMarshaller();
    StandaloneProducer o1 = (StandaloneProducer) marshaller.unmarshal(new URLString(getClasspathXmlFilename()));
    assertEquals("unique-id", o1.getUniqueId());
    String unknownLoc = "zzzz-does-not-exist.xml";
    try {
        o1 = (StandaloneProducer) marshaller.unmarshal(new URLString(unknownLoc));
        fail("Success unmarshal of something that doesn't exist");
    } catch (CoreException e) {
        assertNotNull(e.getCause());
        assertTrue(IOException.class.isAssignableFrom(e.getCause().getClass()));
    }
}
Also used : CoreException(com.adaptris.core.CoreException) AdaptrisMarshaller(com.adaptris.core.AdaptrisMarshaller) URLString(com.adaptris.util.URLString) URLString(com.adaptris.util.URLString) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 44 with AdaptrisMarshaller

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

the class JmsConnection method cloneForTesting.

@Override
public JmsConnection cloneForTesting() throws CoreException {
    AdaptrisMarshaller m = DefaultMarshaller.getDefaultMarshaller();
    JmsConnection copy = (JmsConnection) m.unmarshal(m.marshal(this));
    // Set the client id to be null.
    copy.setClientId(null);
    return copy;
}
Also used : AdaptrisMarshaller(com.adaptris.core.AdaptrisMarshaller)

Example 45 with AdaptrisMarshaller

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

the class AdapterManagerTest method testMBean_AddAndBindSharedConnection.

@Test
public void testMBean_AddAndBindSharedConnection() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName);
    AdapterManager adapterManager = new AdapterManager(adapter);
    ObjectName adapterObj = adapterManager.createObjectName();
    AdaptrisMarshaller m = DefaultMarshaller.getDefaultMarshaller();
    List<BaseComponentMBean> mBeans = new ArrayList<BaseComponentMBean>();
    mBeans.add(adapterManager);
    mBeans.addAll(adapterManager.getAllDescendants());
    try {
        register(mBeans);
        adapterManager.requestStart();
        AdapterManagerMBean amp = JMX.newMBeanProxy(mBeanServer, adapterObj, AdapterManagerMBean.class);
        amp.addAndBindSharedConnection(m.marshal(new NullConnection(getName())));
        Adapter marshalledAdapter = (Adapter) m.unmarshal(amp.getConfiguration());
        assertEquals(1, marshalledAdapter.getSharedComponents().getConnections().size());
        assertEquals(getName(), marshalledAdapter.getSharedComponents().getConnections().get(0).getUniqueId());
        assertTrue(amp.getSharedConnectionIds().contains(getName()));
        assertTrue(amp.containsSharedConnection(getName()));
    } finally {
        adapterManager.requestClose();
    }
}
Also used : AdaptrisMarshaller(com.adaptris.core.AdaptrisMarshaller) ArrayList(java.util.ArrayList) Adapter(com.adaptris.core.Adapter) NullConnection(com.adaptris.core.NullConnection) ObjectName(javax.management.ObjectName) 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