use of com.adaptris.core.jdbc.JdbcConnection 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();
}
use of com.adaptris.core.jdbc.JdbcConnection in project interlok by adaptris.
the class JdbcStoredProcedureTest method setUp.
@Before
public void setUp() throws Exception {
Assume.assumeTrue(areTestsEnabled());
jdbcConnection = new JdbcConnection(PROPERTIES.getProperty(JDBC_URL), PROPERTIES.getProperty(JDBC_DRIVER));
jdbcConnection.setUsername(PROPERTIES.getProperty(JDBC_USER));
jdbcConnection.setPassword(PROPERTIES.getProperty(JDBC_PASSWORD));
LifecycleHelper.initAndStart(jdbcConnection);
if (PROPERTIES.getProperty(JDBC_VENDOR).equals("mysql"))
statementCreator = new MysqlStatementCreator();
else if (PROPERTIES.getProperty(JDBC_VENDOR).equals("sqlserver"))
statementCreator = new SqlServerStatementCreator();
else
fail("Vendor for JDBC tests unknown: " + PROPERTIES.getProperty(JDBC_VENDOR));
connection = jdbcConnection.connect();
storedProcedure = new StoredProcedure();
storedProcedure.setConnection(connection);
storedProcedure.setStatementCreator(statementCreator);
storedProcedure.setStatementExecutor(new ExecuteCallableStatementExecutor());
}
use of com.adaptris.core.jdbc.JdbcConnection in project interlok by adaptris.
the class FirstRowMetadataTranslatorTest method testDateStatementParameter.
@Test
public void testDateStatementParameter() throws Exception {
createDatabase();
Date yesterday = yesterday();
List<AdapterTypeVersion> dbItems = generate(10, yesterday);
AdapterTypeVersion entry = dbItems.get(0);
entry.setDate(new Date());
populateDatabase(dbItems, true);
JdbcDataQueryService service = new JdbcDataQueryService();
service.setConnection(new JdbcConnection(PROPERTIES.getProperty(JDBC_QUERYSERVICE_URL), PROPERTIES.getProperty(JDBC_QUERYSERVICE_DRIVER)));
service.setStatementCreator(new ConfiguredSQLStatement(DATE_QUERY_SQL));
DateStatementParameter tsp = new DateStatementParameter();
tsp.setDateFormat(DATE_FORMAT);
tsp.setQueryType(StatementParameter.QueryType.metadata);
tsp.setQueryString(METADATA_KEY_DATE);
service.setStatementParameters(new StatementParameterList(Arrays.asList(new JdbcStatementParameter[] { tsp })));
FirstRowMetadataTranslator t = new FirstRowMetadataTranslator();
service.setResultSetTranslator(t);
AdaptrisMessage msg = createMessage(entry);
msg.addMetadata(METADATA_KEY_DATE, dateToString(yesterday));
execute(service, msg);
assertEquals(XML_PAYLOAD_PREFIX + entry.getUniqueId() + XML_PAYLOAD_SUFFIX, msg.getContent());
assertTrue(msg.containsKey(t.getMetadataKeyPrefix() + t.getSeparator() + COLUMN_VERSION));
assertEquals(entry.getVersion(), msg.getMetadataValue(t.getMetadataKeyPrefix() + t.getSeparator() + COLUMN_VERSION));
assertTrue(msg.containsKey(t.getMetadataKeyPrefix() + t.getSeparator() + COLUMN_TYPE));
assertEquals(entry.getTranslatorType(), msg.getMetadataValue(t.getMetadataKeyPrefix() + t.getSeparator() + COLUMN_TYPE));
assertFalse(msg.containsKey(JdbcDataQueryService.class.getCanonicalName()));
}
use of com.adaptris.core.jdbc.JdbcConnection in project interlok by adaptris.
the class ServiceFromDatabaseTest method testNotFound.
@Test(expected = ServiceException.class)
public void testNotFound() 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", "anotherSourcePartner");
msg.addMetadata("destination", "anotherDestinationPartner");
try {
LifecycleHelper.initAndStart(extractor);
// Since there's no resultSet.next(), should throw a ServiceException.
InputStream in = extractor.getInputStream(msg);
} finally {
LifecycleHelper.stopAndClose(extractor);
}
}
use of com.adaptris.core.jdbc.JdbcConnection in project interlok by adaptris.
the class JdbcQueryServiceCase method createMultiService.
protected static JdbcDataQueryService createMultiService() {
JdbcDataQueryService service = new JdbcDataQueryService();
JdbcConnection connection = new JdbcConnection(PROPERTIES.getProperty(JDBC_QUERYSERVICE_URL), PROPERTIES.getProperty(JDBC_QUERYSERVICE_DRIVER));
service.setConnection(connection);
service.setStatementCreator(new ConfiguredSQLStatement(QUERY_SQL_MULTI_RESULT));
return service;
}
Aggregations