Search in sources :

Example 6 with ExpressionFactoryBean

use of org.springframework.integration.config.ExpressionFactoryBean in project spring-integration by spring-projects.

the class StoredProcExecutorTests method testStoredProcExecutorWithNonResolvingExpression.

@Test
public void testStoredProcExecutorWithNonResolvingExpression() throws Exception {
    final DataSource datasource = mock(DataSource.class);
    final StoredProcExecutor storedProcExecutor = new StoredProcExecutor(datasource);
    final ExpressionFactoryBean efb = new ExpressionFactoryBean("headers['stored_procedure_name']");
    efb.afterPropertiesSet();
    final Expression expression = efb.getObject();
    storedProcExecutor.setStoredProcedureNameExpression(expression);
    storedProcExecutor.setBeanFactory(mock(BeanFactory.class));
    storedProcExecutor.afterPropertiesSet();
    this.mockTheOperationsCache(storedProcExecutor);
    // This should work
    storedProcExecutor.executeStoredProcedure(MessageBuilder.withPayload("test").setHeader("stored_procedure_name", "123").build());
    try {
        storedProcExecutor.executeStoredProcedure(MessageBuilder.withPayload("test").setHeader("some_other_header", "123").build());
    } catch (IllegalArgumentException e) {
        assertEquals("Unable to resolve Stored Procedure/Function name for the provided Expression 'headers['stored_procedure_name']'.", e.getMessage());
        return;
    }
    fail("IllegalArgumentException expected.");
}
Also used : ExpressionFactoryBean(org.springframework.integration.config.ExpressionFactoryBean) Expression(org.springframework.expression.Expression) BeanFactory(org.springframework.beans.factory.BeanFactory) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 7 with ExpressionFactoryBean

use of org.springframework.integration.config.ExpressionFactoryBean in project spring-integration by spring-projects.

the class StoredProcExecutorTests method testStoredProcExecutorJdbcCallOperationsCache.

@Test
public void testStoredProcExecutorJdbcCallOperationsCache() throws Exception {
    final DataSource datasource = mock(DataSource.class);
    final StoredProcExecutor storedProcExecutor = new StoredProcExecutor(datasource);
    final ExpressionFactoryBean efb = new ExpressionFactoryBean("headers['stored_procedure_name']");
    efb.afterPropertiesSet();
    final Expression expression = efb.getObject();
    storedProcExecutor.setStoredProcedureNameExpression(expression);
    storedProcExecutor.setBeanFactory(mock(BeanFactory.class));
    storedProcExecutor.afterPropertiesSet();
    this.mockTheOperationsCache(storedProcExecutor);
    for (int i = 1; i <= 3; i++) {
        storedProcExecutor.executeStoredProcedure(MessageBuilder.withPayload("test").setHeader("stored_procedure_name", "123").build());
    }
    final CacheStats stats = (CacheStats) storedProcExecutor.getJdbcCallOperationsCacheStatistics();
    LOGGER.info(stats);
    LOGGER.info(stats.totalLoadTime() / 1000 / 1000);
    assertEquals(stats.hitCount(), 2);
    assertEquals(stats.missCount(), 1);
    assertEquals(stats.loadCount(), 1);
}
Also used : ExpressionFactoryBean(org.springframework.integration.config.ExpressionFactoryBean) Expression(org.springframework.expression.Expression) BeanFactory(org.springframework.beans.factory.BeanFactory) CacheStats(com.google.common.cache.CacheStats) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 8 with ExpressionFactoryBean

use of org.springframework.integration.config.ExpressionFactoryBean in project spring-integration by spring-projects.

the class StoredProcExecutorTests method testGetStoredProcedureNameExpressionAsString.

@Test
public void testGetStoredProcedureNameExpressionAsString() throws Exception {
    DataSource datasource = mock(DataSource.class);
    StoredProcExecutor storedProcExecutor = new StoredProcExecutor(datasource);
    final ExpressionFactoryBean efb = new ExpressionFactoryBean("headers['stored_procedure_name']");
    efb.afterPropertiesSet();
    final Expression expression = efb.getObject();
    storedProcExecutor.setStoredProcedureNameExpression(expression);
    storedProcExecutor.setBeanFactory(mock(BeanFactory.class));
    storedProcExecutor.afterPropertiesSet();
    assertEquals("headers['stored_procedure_name']", storedProcExecutor.getStoredProcedureNameExpressionAsString());
}
Also used : ExpressionFactoryBean(org.springframework.integration.config.ExpressionFactoryBean) Expression(org.springframework.expression.Expression) BeanFactory(org.springframework.beans.factory.BeanFactory) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 BeanFactory (org.springframework.beans.factory.BeanFactory)8 Expression (org.springframework.expression.Expression)8 ExpressionFactoryBean (org.springframework.integration.config.ExpressionFactoryBean)8 DataSource (javax.sql.DataSource)4 CacheStats (com.google.common.cache.CacheStats)2 HashMap (java.util.HashMap)2 LiteralExpression (org.springframework.expression.common.LiteralExpression)2 QueueChannel (org.springframework.integration.channel.QueueChannel)2 User (org.springframework.integration.jdbc.storedproc.User)2 Message (org.springframework.messaging.Message)2 PeriodicTrigger (org.springframework.scheduling.support.PeriodicTrigger)2 ArrayList (java.util.ArrayList)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 SpelExpressionParser (org.springframework.expression.spel.standard.SpelExpressionParser)1 DirectChannel (org.springframework.integration.channel.DirectChannel)1 NullChannel (org.springframework.integration.channel.NullChannel)1 TestErrorHandler (org.springframework.integration.config.TestErrorHandler)1 PollingConsumer (org.springframework.integration.endpoint.PollingConsumer)1 AbstractReplyProducingMessageHandler (org.springframework.integration.handler.AbstractReplyProducingMessageHandler)1