use of com.adaptris.core.AdaptrisMessage in project interlok by adaptris.
the class StoredProcedureProducerTest method testMultipleResultSetsMetadataTranslator.
@Test
public void testMultipleResultSetsMetadataTranslator() throws Exception {
if (areTestsEnabled()) {
JdbcStoredProcedureProducer spp = new JdbcStoredProcedureProducer();
spp.setProcedureName(("many_resultsets"));
spp.setResultSetTranslator(new AllRowsMetadataTranslator());
AdaptrisMessage message = createMessage();
assertEquals(0, message.getMetadata().size());
StandaloneProducer producer = configureForTests(spp, true);
try {
start(producer);
producer.doService(message);
assertEquals(30, message.getMetadata().size());
} finally {
stop(producer);
}
}
}
use of com.adaptris.core.AdaptrisMessage in project interlok by adaptris.
the class StoredProcedureProducerTest method testOneConstantParamInOneMetadataOut.
@Test
public void testOneConstantParamInOneMetadataOut() throws Exception {
if (areTestsEnabled()) {
JdbcStoredProcedureProducer spp = new JdbcStoredProcedureProducer();
spp.setProcedureName(("one_in_one_out"));
JdbcConstantParameter inParameter = new JdbcConstantParameter();
inParameter.setConstant("Sold");
inParameter.setName("xType");
inParameter.setType(ParameterValueType.VARCHAR);
InParameters inParameters = new InParameters();
inParameters.add(inParameter);
JdbcMetadataParameter outParameter = new JdbcMetadataParameter();
outParameter.setMetadataKey("result");
outParameter.setName("transferCount");
outParameter.setType(ParameterValueType.INTEGER);
OutParameters outParameters = new OutParameters();
outParameters.add(outParameter);
spp.setInParameters(inParameters);
spp.setOutParameters(outParameters);
AdaptrisMessage message = createMessage();
assertEquals(0, message.getMetadata().size());
StandaloneProducer producer = configureForTests(spp, true);
try {
start(producer);
producer.doService(message);
assertEquals(1, message.getMetadata().size());
assertEquals("15", message.getMetadataValue("result"));
} finally {
stop(producer);
}
}
}
use of com.adaptris.core.AdaptrisMessage in project interlok by adaptris.
the class StoredProcedureProducerTest method testProduce_PooledConnection.
@Test
public void testProduce_PooledConnection() throws Exception {
int maxServices = 5;
final int iterations = 5;
int poolsize = maxServices - 1;
if (areTestsEnabled()) {
List<Service> serviceList = new ArrayList<Service>();
String name = Thread.currentThread().getName();
Thread.currentThread().setName(getName());
JdbcPooledConnection conn = PooledConnectionHelper.createPooledConnection(PROPERTIES.getProperty(JDBC_DRIVER), PROPERTIES.getProperty(JDBC_URL), poolsize);
conn.setUsername(PROPERTIES.getProperty(JDBC_USER));
conn.setPassword(PROPERTIES.getProperty(JDBC_PASSWORD));
try {
for (int i = 0; i < maxServices; i++) {
JdbcStoredProcedureProducer spp = new JdbcStoredProcedureProducer();
spp.setProcedureName(("one_in"));
JdbcStringPayloadParameter inParameter = new JdbcStringPayloadParameter();
inParameter.setName("xType");
inParameter.setType(ParameterValueType.VARCHAR);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("Sold");
InParameters inParameters = new InParameters();
inParameters.add(inParameter);
spp.setInParameters(inParameters);
StandaloneProducer service = configureForTests(spp, false);
service.setConnection(conn);
serviceList.add(service);
start(service);
}
PooledConnectionHelper.executeTest(serviceList, iterations, new PooledConnectionHelper.MessageCreator() {
@Override
public AdaptrisMessage createMsgForPooledConnectionTest() throws Exception {
return createMessage("Sold");
}
});
assertEquals(0, conn.currentBusyConnectionCount());
assertEquals(poolsize, conn.currentIdleConnectionCount());
assertEquals(poolsize, conn.currentConnectionCount());
} finally {
stop(serviceList.toArray(new ComponentLifecycle[0]));
Thread.currentThread().setName(name);
}
}
}
use of com.adaptris.core.AdaptrisMessage in project interlok by adaptris.
the class StoredProcedureProducerTest method testOneMetadataParamInButDoesntExist.
@Test
public void testOneMetadataParamInButDoesntExist() throws Exception {
if (areTestsEnabled()) {
JdbcStoredProcedureProducer spp = new JdbcStoredProcedureProducer();
spp.setProcedureName(("one_in"));
JdbcMetadataParameter inParameter = new JdbcMetadataParameter();
inParameter.setMetadataKey("xType");
inParameter.setName("xType");
inParameter.setType(ParameterValueType.VARCHAR);
InParameters inParameters = new InParameters();
inParameters.add(inParameter);
spp.setInParameters(inParameters);
StandaloneProducer producer = configureForTests(spp, true);
AdaptrisMessage message = createMessage();
try {
start(producer);
producer.doService(message);
fail("Should have thrown ProduceException, because the metadata does not exist in the message.");
} catch (ServiceException ex) {
// pass, expected
} finally {
stop(producer);
}
}
}
use of com.adaptris.core.AdaptrisMessage in project interlok by adaptris.
the class StoredProcedureProducerTest method testOneResultSetFirstRowMetadataTranslator.
@Test
public void testOneResultSetFirstRowMetadataTranslator() throws Exception {
if (areTestsEnabled()) {
JdbcStoredProcedureProducer spp = new JdbcStoredProcedureProducer();
spp.setProcedureName(("one_resultset"));
spp.setResultSetTranslator(new FirstRowMetadataTranslator());
AdaptrisMessage message = createMessage();
assertEquals(0, message.getMetadata().size());
StandaloneProducer producer = configureForTests(spp, true);
try {
start(producer);
producer.doService(message);
assertEquals(3, message.getMetadata().size());
} finally {
stop(producer);
}
}
}
Aggregations