Search in sources :

Example 86 with AdaptrisMessage

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

Example 87 with AdaptrisMessage

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

Example 88 with AdaptrisMessage

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);
        }
    }
}
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)

Example 89 with AdaptrisMessage

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

Example 90 with AdaptrisMessage

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

Aggregations

AdaptrisMessage (com.adaptris.core.AdaptrisMessage)1495 Test (org.junit.Test)1362 ServiceException (com.adaptris.core.ServiceException)171 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)158 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)156 StandaloneProducer (com.adaptris.core.StandaloneProducer)125 Channel (com.adaptris.core.Channel)122 MetadataElement (com.adaptris.core.MetadataElement)94 File (java.io.File)89 TimeInterval (com.adaptris.util.TimeInterval)77 CoreException (com.adaptris.core.CoreException)67 Session (javax.jms.Session)62 StandardWorkflow (com.adaptris.core.StandardWorkflow)57 GuidGenerator (com.adaptris.util.GuidGenerator)56 JettyHelper.createChannel (com.adaptris.core.http.jetty.JettyHelper.createChannel)50 StandaloneRequestor (com.adaptris.core.StandaloneRequestor)49 Message (javax.jms.Message)47 XPath (com.adaptris.util.text.xml.XPath)45 ServiceList (com.adaptris.core.ServiceList)43 Document (org.w3c.dom.Document)40