Search in sources :

Example 26 with StandaloneProducer

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);
        }
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 27 with StandaloneProducer

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);
        }
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 28 with StandaloneProducer

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);
        }
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) XmlPayloadTranslator(com.adaptris.core.services.jdbc.XmlPayloadTranslator) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 29 with StandaloneProducer

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);
        }
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 30 with StandaloneProducer

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);
}
Also used : MysqlStatementCreator(com.adaptris.jdbc.MysqlStatementCreator) SqlServerStatementCreator(com.adaptris.jdbc.SqlServerStatementCreator) StandaloneProducer(com.adaptris.core.StandaloneProducer)

Aggregations

StandaloneProducer (com.adaptris.core.StandaloneProducer)266 Test (org.junit.Test)238 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)125 StandaloneConsumer (com.adaptris.core.StandaloneConsumer)91 MockMessageListener (com.adaptris.core.stubs.MockMessageListener)91 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)68 Channel (com.adaptris.core.Channel)64 PtpProducer (com.adaptris.core.jms.PtpProducer)46 ServiceList (com.adaptris.core.ServiceList)39 PasProducer (com.adaptris.core.jms.PasProducer)34 JettyHelper.createChannel (com.adaptris.core.http.jetty.JettyHelper.createChannel)32 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)27 HttpConsumerTest (com.adaptris.core.http.jetty.HttpConsumerTest)23 PtpConsumer (com.adaptris.core.jms.PtpConsumer)23 TimeInterval (com.adaptris.util.TimeInterval)23 MockChannel (com.adaptris.core.stubs.MockChannel)22 ServiceException (com.adaptris.core.ServiceException)20 StandardWorkflow (com.adaptris.core.StandardWorkflow)20 HttpConnection (com.adaptris.core.http.jetty.HttpConnection)20 JettyMessageConsumer (com.adaptris.core.http.jetty.JettyMessageConsumer)20