Search in sources :

Example 31 with StandaloneProducer

use of com.adaptris.core.StandaloneProducer in project interlok by adaptris.

the class StoredProcedureProducerTest method testOneObjectMetadataParamOut.

@Test
public void testOneObjectMetadataParamOut() throws Exception {
    if (areTestsEnabled()) {
        JdbcStoredProcedureProducer spp = new JdbcStoredProcedureProducer();
        spp.setProcedureName(("one_out"));
        JdbcObjectMetadataParameter outParameter = new JdbcObjectMetadataParameter();
        outParameter.setMetadataKey("transferCount");
        outParameter.setName("transferCount");
        outParameter.setType(ParameterValueType.INTEGER);
        OutParameters outParameters = new OutParameters();
        outParameters.add(outParameter);
        spp.setOutParameters(outParameters);
        AdaptrisMessage message = createMessage();
        Map<Object, Object> objectMetadata = message.getObjectHeaders();
        assertEquals(0, objectMetadata.size());
        StandaloneProducer producer = configureForTests(spp, true);
        try {
            start(producer);
            producer.doService(message);
            objectMetadata = message.getObjectHeaders();
            assertEquals(1, objectMetadata.size());
            assertTrue("31".equals(objectMetadata.get("transferCount").toString()));
        } finally {
            stop(producer);
        }
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 32 with StandaloneProducer

use of com.adaptris.core.StandaloneProducer in project interlok by adaptris.

the class StoredProcedureProducerTest method testBytePayloadParamIn.

@Test
public void testBytePayloadParamIn() throws Exception {
    if (areTestsEnabled()) {
        JdbcStoredProcedureProducer spp = new JdbcStoredProcedureProducer();
        spp.setProcedureName(("one_in"));
        JdbcBytePayloadParameter inParameter = new JdbcBytePayloadParameter();
        inParameter.setName("xType");
        inParameter.setType(ParameterValueType.VARCHAR);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("Sold");
        InParameters inParameters = new InParameters();
        inParameters.add(inParameter);
        spp.setInParameters(inParameters);
        StandaloneProducer producer = configureForTests(spp, true);
        try {
            start(producer);
            producer.doService(msg);
        } finally {
            stop(producer);
        }
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 33 with StandaloneProducer

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

Example 34 with StandaloneProducer

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

Example 35 with StandaloneProducer

use of com.adaptris.core.StandaloneProducer 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);
        }
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ArrayList(java.util.ArrayList) Service(com.adaptris.core.Service) ServiceException(com.adaptris.core.ServiceException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) IOException(java.io.IOException) ComponentLifecycle(com.adaptris.core.ComponentLifecycle) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

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