Search in sources :

Example 6 with XStreamMarshaller

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

the class ViolationHandlerTest method testAsMetadata.

@Test
public void testAsMetadata() throws Exception {
    ViolationsAsMetadata handler = new ViolationsAsMetadata().withMetadataKey(DEFAULT_KEY);
    List<SAXParseException> exceptions = Arrays.asList(createException("first"), createException("second"));
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    handler.handle(exceptions, msg);
    assertTrue(msg.headersContainsKey(DEFAULT_KEY));
    SchemaViolations v = (SchemaViolations) new XStreamMarshaller().unmarshal(msg.getMetadataValue(DEFAULT_KEY));
    assertEquals(2, v.getViolations().size());
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) SAXParseException(org.xml.sax.SAXParseException) XStreamMarshaller(com.adaptris.core.XStreamMarshaller) Test(org.junit.Test)

Example 7 with XStreamMarshaller

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

the class ViolationHandlerTest method testAsPayload.

@Test
public void testAsPayload() throws Exception {
    OverwritePayload handler = new OverwritePayload();
    List<SAXParseException> exceptions = Arrays.asList(createException("first"), createException("second"));
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    handler.handle(exceptions, msg);
    assertFalse(msg.headersContainsKey(DEFAULT_KEY));
    SchemaViolations v = (SchemaViolations) new XStreamMarshaller().unmarshal(msg.getContent());
    assertEquals(2, v.getViolations().size());
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) SAXParseException(org.xml.sax.SAXParseException) XStreamMarshaller(com.adaptris.core.XStreamMarshaller) Test(org.junit.Test)

Example 8 with XStreamMarshaller

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

the class JdbcServiceCase method testBackReferences.

protected <T extends JdbcService> void testBackReferences(T testObject) throws Exception {
    JdbcConnection conn = new JdbcConnection();
    conn.setConnectUrl("jdbc:derby:memory:" + GUID.safeUUID() + ";create=true");
    conn.setDriverImp("org.apache.derby.jdbc.EmbeddedDriver");
    testObject.setConnection(conn);
    // redmineID #4536, exception listener is set in .init()
    testObject.init();
    assertEquals(conn, testObject.getConnection());
    assertEquals(1, conn.retrieveExceptionListeners().size());
    assertTrue(testObject == conn.retrieveExceptionListeners().toArray()[0]);
    testObject.start();
    testObject.stop();
    testObject.close();
    // Now marshall and see if it's the same.
    XStreamMarshaller m = new XStreamMarshaller();
    String xml = m.marshal(testObject);
    @SuppressWarnings("unchecked") T testObject2 = (T) m.unmarshal(xml);
    // redmineID #4536, exception listener now must simply be set in .init()
    testObject2.init();
    // If the setter has been used, then these two will be "true"
    assertNotNull(testObject2.getConnection());
    assertEquals(1, testObject2.getConnection().retrieveExceptionListeners().size());
    assertTrue(testObject2 == testObject2.getConnection().retrieveExceptionListeners().toArray()[0]);
    testObject2.start();
    testObject2.stop();
    testObject2.close();
}
Also used : JdbcConnection(com.adaptris.core.jdbc.JdbcConnection) XStreamMarshaller(com.adaptris.core.XStreamMarshaller)

Example 9 with XStreamMarshaller

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

the class XmlExceptionReport method create.

@Override
public Document create(Exception e, String workflow, String location) throws Exception {
    // Just use XStream as the marshaller, if we let them configure it, someone might configure
    // a XStreamJSON which would be quite bad.
    AdaptrisMarshaller m = new XStreamMarshaller();
    ExceptionReport report = createReportObject(e, workflow, location);
    return createDocument(m.marshal(report), (DocumentBuilderFactoryBuilder) null);
}
Also used : AdaptrisMarshaller(com.adaptris.core.AdaptrisMarshaller) XStreamMarshaller(com.adaptris.core.XStreamMarshaller)

Example 10 with XStreamMarshaller

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

the class ChannelManagerTest method testGetConfiguration.

@Test
public void testGetConfiguration() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName, 0, 0);
    AdapterManager am1 = new AdapterManager(adapter);
    Channel channel = createChannel("c1", 1);
    ChannelManager cm1 = new ChannelManager(channel, am1);
    Channel marshalledCopy = (Channel) new XStreamMarshaller().unmarshal(cm1.getConfiguration());
    assertRoundtripEquality(channel, marshalledCopy);
}
Also used : Channel(com.adaptris.core.Channel) Adapter(com.adaptris.core.Adapter) XStreamMarshaller(com.adaptris.core.XStreamMarshaller) Test(org.junit.Test)

Aggregations

XStreamMarshaller (com.adaptris.core.XStreamMarshaller)10 Test (org.junit.Test)8 Adapter (com.adaptris.core.Adapter)4 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)4 Channel (com.adaptris.core.Channel)3 SAXParseException (org.xml.sax.SAXParseException)2 AdaptrisMarshaller (com.adaptris.core.AdaptrisMarshaller)1 MetadataElement (com.adaptris.core.MetadataElement)1 PoolingWorkflow (com.adaptris.core.PoolingWorkflow)1 Service (com.adaptris.core.Service)1 ServiceList (com.adaptris.core.ServiceList)1 StandardWorkflow (com.adaptris.core.StandardWorkflow)1 Workflow (com.adaptris.core.Workflow)1 JdbcConnection (com.adaptris.core.jdbc.JdbcConnection)1 LogMessageService (com.adaptris.core.services.LogMessageService)1 AddMetadataService (com.adaptris.core.services.metadata.AddMetadataService)1 XmlValidationService (com.adaptris.core.transform.XmlValidationService)1