Search in sources :

Example 1 with JdbcConnection

use of com.adaptris.core.jdbc.JdbcConnection in project interlok by adaptris.

the class ServiceFromDatabaseTest method testGetInputStream.

@Test
public void testGetInputStream() throws Exception {
    DatabaseEntry entry = new DatabaseEntry("mySourcePartner", "myDestinationPartner");
    createDatabase(Arrays.asList(entry));
    JdbcConnection jdbcConn = configure(new JdbcConnection());
    ServiceFromDatabase extractor = new ServiceFromDatabase().withQuery(SELECT_STMT).withConnection(jdbcConn);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    msg.addMetadata("source", "mySourcePartner");
    msg.addMetadata("destination", "myDestinationPartner");
    try {
        LifecycleHelper.initAndStart(extractor);
        try (InputStream in = extractor.getInputStream(msg)) {
            assertNotNull(in);
            assertEquals(ServiceList.class, DefaultMarshaller.getDefaultMarshaller().unmarshal(in).getClass());
        }
    } finally {
        LifecycleHelper.stopAndClose(extractor);
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) InputStream(java.io.InputStream) JdbcConnection(com.adaptris.core.jdbc.JdbcConnection) Test(org.junit.Test)

Example 2 with JdbcConnection

use of com.adaptris.core.jdbc.JdbcConnection in project interlok by adaptris.

the class ServiceFromDatabaseTest method testLifecycle.

@Test
public void testLifecycle() throws Exception {
    JdbcConnection jdbcConn = configure(new JdbcConnection());
    ServiceFromDatabase extractor = new ServiceFromDatabase().withQuery(SELECT_STMT);
    try {
        LifecycleHelper.initAndStart(extractor);
        fail();
    } catch (Exception expected) {
    } finally {
        LifecycleHelper.stopAndClose(extractor);
    }
    extractor.setConnection(jdbcConn);
    try {
        LifecycleHelper.initAndStart(extractor);
    } finally {
        LifecycleHelper.stopAndClose(extractor);
    }
}
Also used : JdbcConnection(com.adaptris.core.jdbc.JdbcConnection) ServiceException(com.adaptris.core.ServiceException) Test(org.junit.Test)

Example 3 with JdbcConnection

use of com.adaptris.core.jdbc.JdbcConnection in project interlok by adaptris.

the class MetadataIdentitySequenceNumberServiceTest method retrieveObjectForSampleConfig.

@Override
protected MetadataIdentitySequenceNumberService retrieveObjectForSampleConfig() {
    JdbcConnection connection = new JdbcConnection();
    connection.setConnectUrl("jdbc:mysql://localhost:3306/mydatabase");
    connection.setConnectionAttempts(2);
    connection.setConnectionRetryInterval(new TimeInterval(3L, "SECONDS"));
    MetadataIdentitySequenceNumberService service = new MetadataIdentitySequenceNumberService();
    service.setMetadataKey("sequence_no");
    service.setNumberFormat(DEFAULT_NUMBER_FORMAT);
    service.setConnection(connection);
    service.setIdentityMetadataKey(DEFAULT_IDENTITY_METADATA_KEY);
    service.setOverflowBehaviour(AbstractJdbcSequenceNumberService.OverflowBehaviour.Continue);
    return service;
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) JdbcConnection(com.adaptris.core.jdbc.JdbcConnection)

Example 4 with JdbcConnection

use of com.adaptris.core.jdbc.JdbcConnection in project interlok by adaptris.

the class MetadataIdentitySequenceNumberServiceTest method configureForTests.

private MetadataIdentitySequenceNumberService configureForTests(MetadataIdentitySequenceNumberService service, boolean addConnection) {
    if (addConnection) {
        service.setConnection(new JdbcConnection(PROPERTIES.getProperty(JDBC_SEQUENCENUMBER_URL), PROPERTIES.getProperty(JDBC_SEQUENCENUMBER_DRIVER)));
    }
    service.setMetadataKey(DEFAULT_METADATA_KEY);
    service.setNumberFormat(DEFAULT_NUMBER_FORMAT);
    service.setIdentityMetadataKey(DEFAULT_IDENTITY_METADATA_KEY);
    return service;
}
Also used : JdbcConnection(com.adaptris.core.jdbc.JdbcConnection)

Example 5 with JdbcConnection

use of com.adaptris.core.jdbc.JdbcConnection in project interlok by adaptris.

the class JdbcServiceListTest method testSetConnection.

@Test
public void testSetConnection() {
    JdbcConnection connection = new JdbcConnection();
    JdbcServiceList list = new JdbcServiceList();
    assertNull(list.getConnection());
    list.setConnection(connection);
    assertEquals(connection, list.connection());
    assertEquals(connection, list.getConnection());
    list.setConnection(null);
    assertEquals(null, list.getConnection());
    assertNull(list.connection());
}
Also used : JdbcConnection(com.adaptris.core.jdbc.JdbcConnection) Test(org.junit.Test)

Aggregations

JdbcConnection (com.adaptris.core.jdbc.JdbcConnection)30 TimeInterval (com.adaptris.util.TimeInterval)6 Test (org.junit.Test)6 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)4 BinaryStreamStatementParameter (com.adaptris.core.services.jdbc.BinaryStreamStatementParameter)3 BytePayloadStatementParameter (com.adaptris.core.services.jdbc.BytePayloadStatementParameter)3 CharacterStreamStatementParameter (com.adaptris.core.services.jdbc.CharacterStreamStatementParameter)3 DateStatementParameter (com.adaptris.core.services.jdbc.DateStatementParameter)3 StatementParameter (com.adaptris.core.services.jdbc.StatementParameter)3 TimeStatementParameter (com.adaptris.core.services.jdbc.TimeStatementParameter)3 TimestampStatementParameter (com.adaptris.core.services.jdbc.TimestampStatementParameter)3 SimpleDateFormat (java.text.SimpleDateFormat)3 ServiceException (com.adaptris.core.ServiceException)2 JdbcService (com.adaptris.core.jdbc.JdbcService)2 KeyValuePair (com.adaptris.util.KeyValuePair)2 KeyValuePairSet (com.adaptris.util.KeyValuePairSet)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 CoreException (com.adaptris.core.CoreException)1 XStreamMarshaller (com.adaptris.core.XStreamMarshaller)1