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.");
}
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);
}
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());
}
Aggregations