use of com.adaptris.core.StandaloneProducer in project interlok by adaptris.
the class StoredProcedureProducerTest method testMultipleExecutions.
@Test
public void testMultipleExecutions() throws Exception {
if (areTestsEnabled()) {
JdbcStoredProcedureProducer spp = new JdbcStoredProcedureProducer();
spp.setProcedureName(("one_in_one_out"));
AdaptrisMessage message = createMessage(XML_PAYLOAD);
AdaptrisMessage message2 = createMessage(XML_PAYLOAD);
JdbcXPathParameter inParameter = new JdbcXPathParameter();
inParameter.setXpath("/head/body/element1");
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);
StandaloneProducer producer = configureForTests(spp, true);
try {
// INTERLOK-3329 For coverage so the prepare() warning is executed 2x
LifecycleHelper.prepare(producer);
start(producer);
assertEquals(0, message.getMetadata().size());
producer.doService(message);
assertEquals(1, message.getMetadata().size());
assertEquals("15", message.getMetadataValue("result"));
assertEquals(0, message2.getMetadata().size());
producer.doService(message2);
assertEquals(1, message2.getMetadata().size());
assertEquals("15", message2.getMetadataValue("result"));
} finally {
stop(producer);
}
}
}
use of com.adaptris.core.StandaloneProducer in project interlok by adaptris.
the class StoredProcedureProducerTest method testOneObjectMetadataParamIn.
@Test
public void testOneObjectMetadataParamIn() throws Exception {
if (areTestsEnabled()) {
JdbcStoredProcedureProducer spp = new JdbcStoredProcedureProducer();
spp.setProcedureName(("one_in"));
JdbcObjectMetadataParameter inParameter = new JdbcObjectMetadataParameter();
inParameter.setMetadataKey("xType");
inParameter.setName("xType");
inParameter.setType(ParameterValueType.VARCHAR);
AdaptrisMessage message = createMessage();
message.addObjectHeader("xType", "Sold");
InParameters inParameters = new InParameters();
inParameters.add(inParameter);
spp.setInParameters(inParameters);
Map<Object, Object> objectMetadata = message.getObjectHeaders();
assertEquals(1, objectMetadata.size());
StandaloneProducer producer = configureForTests(spp, true);
try {
start(producer);
producer.doService(message);
objectMetadata = message.getObjectHeaders();
assertEquals(1, objectMetadata.size());
} finally {
stop(producer);
}
}
}
use of com.adaptris.core.StandaloneProducer in project interlok by adaptris.
the class StoredProcedureProducerTest method testMultiResultSetXmlTranslator.
@Test
public void testMultiResultSetXmlTranslator() throws Exception {
if (areTestsEnabled()) {
JdbcStoredProcedureProducer spp = new JdbcStoredProcedureProducer();
spp.setProcedureName(("many_resultsets"));
XmlPayloadTranslator xmlPayloadTranslator = new XmlPayloadTranslator();
xmlPayloadTranslator.setPreserveOriginalMessage(true);
spp.setResultSetTranslator(xmlPayloadTranslator);
AdaptrisMessage message = createMessage();
assertEquals(0, message.getMetadata().size());
StandaloneProducer producer = configureForTests(spp, true);
try {
start(producer);
producer.doService(message);
assertEquals("Robbie Fowler", resolveXPath(message, "/Results/Row[1]/player"));
assertEquals("Michael Owen", resolveXPath(message, "/Results/Row[2]/player"));
assertEquals("Stan Collymore", resolveXPath(message, "/Results/Row[3]/player"));
assertEquals("Emile Heskey", resolveXPath(message, "/Results/Row[5]/player"));
assertEquals("Djibril Cisse", resolveXPath(message, "/Results/Row[6]/player"));
assertEquals("Emile Heskey", resolveXPath(message, "/Results/Row[7]/player"));
assertEquals("Xabi Alonso", resolveXPath(message, "/Results/Row[8]/player"));
assertEquals("El-Hadji Diouf", resolveXPath(message, "/Results/Row[9]/player"));
assertEquals("Stan Collymore", resolveXPath(message, "/Results/Row[10]/player"));
assertNull(resolveXPath(message, "/Results/Row[11]/player"));
} finally {
stop(producer);
}
}
}
use of com.adaptris.core.StandaloneProducer in project interlok by adaptris.
the class StoredProcedureProducerTest method testOneConstantParamInOut.
@Test
public void testOneConstantParamInOut() throws Exception {
if (areTestsEnabled()) {
JdbcStoredProcedureProducer spp = new JdbcStoredProcedureProducer();
spp.setProcedureName(("one_inout"));
JdbcConstantParameter inParameter = new JdbcConstantParameter();
inParameter.setName("xSomeAmount");
inParameter.setType(ParameterValueType.VARCHAR);
inParameter.setConstant("100");
InOutParameters inOutParameters = new InOutParameters();
inOutParameters.add(inParameter);
spp.setInOutParameters(inOutParameters);
StandaloneProducer producer = configureForTests(spp, true);
AdaptrisMessage message = createMessage();
try {
start(producer);
producer.doService(message);
fail("Cannot use a constant for InOut parameters");
} catch (ServiceException ex) {
// pass, expected
} finally {
stop(producer);
}
}
}
use of com.adaptris.core.StandaloneProducer in project interlok by adaptris.
the class StoredProcedureProducerTest method configureForTests.
private StandaloneProducer configureForTests(JdbcStoredProcedureProducer p, boolean addConnection) {
if (PROPERTIES.getProperty(JDBC_VENDOR).equals("mysql"))
p.setStatementCreator(new MysqlStatementCreator());
else if (PROPERTIES.getProperty(JDBC_VENDOR).equals("sqlserver"))
p.setStatementCreator(new SqlServerStatementCreator());
else
fail("Vendor for JDBC tests unknown: " + PROPERTIES.getProperty(JDBC_VENDOR));
if (addConnection) {
JdbcConnection jdbcConnection = new JdbcConnection(PROPERTIES.getProperty(JDBC_URL), PROPERTIES.getProperty(JDBC_DRIVER));
jdbcConnection.setUsername(PROPERTIES.getProperty(JDBC_USER));
jdbcConnection.setPassword(PROPERTIES.getProperty(JDBC_PASSWORD));
return new StandaloneProducer(jdbcConnection, p);
}
return new StandaloneProducer(p);
}
Aggregations