use of org.springframework.integration.jdbc.storedproc.User in project spring-integration by spring-projects.
the class StoredProcMessageHandlerDerbyIntegrationTests method testDerbyStoredProcInsertWithDefaultSqlSourceAndDynamicProcName.
@Test
public void testDerbyStoredProcInsertWithDefaultSqlSourceAndDynamicProcName() throws Exception {
StoredProcExecutor storedProcExecutor = new StoredProcExecutor(embeddedDatabase);
StoredProcMessageHandler messageHandler = new StoredProcMessageHandler(storedProcExecutor);
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();
messageHandler.setBeanFactory(mock(BeanFactory.class));
messageHandler.afterPropertiesSet();
MessageBuilder<User> message = MessageBuilder.withPayload(new User("username", "password", "email"));
message.setHeader("stored_procedure_name", "CREATE_USER");
messageHandler.handleMessage(message.build());
Map<String, Object> map = jdbcTemplate.queryForMap("SELECT * FROM USERS WHERE USERNAME=?", "username");
assertEquals("Wrong username", "username", map.get("USERNAME"));
assertEquals("Wrong password", "password", map.get("PASSWORD"));
assertEquals("Wrong email", "email", map.get("EMAIL"));
}
use of org.springframework.integration.jdbc.storedproc.User in project spring-integration by spring-projects.
the class StoredProcOutboundGatewayWithSpelIntegrationTests method testWithMissingMessageHeader.
@Test
@DirtiesContext
public void testWithMissingMessageHeader() throws Exception {
User user1 = new User("First User", "my first password", "email1");
Message<User> user1Message = MessageBuilder.withPayload(user1).build();
this.channel.send(user1Message);
Message<?> receive = this.startErrorsChannel.receive(10000);
assertNotNull(receive);
assertThat(receive, instanceOf(ErrorMessage.class));
MessageHandlingException exception = (MessageHandlingException) receive.getPayload();
String expectedMessage = "Unable to resolve Stored Procedure/Function name " + "for the provided Expression 'headers['my_stored_procedure']'.";
String actualMessage = exception.getCause().getMessage();
Assert.assertEquals(expectedMessage, actualMessage);
}
use of org.springframework.integration.jdbc.storedproc.User in project spring-integration by spring-projects.
the class StoredProcOutboundGatewayWithNamespaceIntegrationTests method test.
@Test
public void test() throws Exception {
createUser.createUser(new User("myUsername", "myPassword", "myEmail"));
List<Message<Collection<User>>> received = new ArrayList<Message<Collection<User>>>();
received.add(consumer.poll(2000));
Message<Collection<User>> message = received.get(0);
assertNotNull(message);
assertNotNull(message.getPayload());
Collection<User> allUsers = message.getPayload();
assertTrue(allUsers.size() == 1);
User userFromDb = allUsers.iterator().next();
assertEquals("Wrong username", "myUsername", userFromDb.getUsername());
assertEquals("Wrong password", "myPassword", userFromDb.getPassword());
assertEquals("Wrong email", "'myEmail'", userFromDb.getEmail());
}
use of org.springframework.integration.jdbc.storedproc.User in project spring-integration by spring-projects.
the class StoredProcOutboundGatewayWithNamespaceIntegrationTests method testStoredProcOutboundGatewayInsideChain.
// INT-1029
@Test
public void testStoredProcOutboundGatewayInsideChain() throws Exception {
Message<User> requestMessage = MessageBuilder.withPayload(new User("myUsername", "myPassword", "myEmail")).build();
storedProcOutboundGatewayInsideChain.send(requestMessage);
@SuppressWarnings("unchecked") Message<Collection<User>> message = (Message<Collection<User>>) replyChannel.receive();
assertNotNull(message);
assertNotNull(message.getPayload());
Collection<User> allUsers = message.getPayload();
assertTrue(allUsers.size() == 1);
User userFromDb = allUsers.iterator().next();
assertEquals("Wrong username", "myUsername", userFromDb.getUsername());
assertEquals("Wrong password", "myPassword", userFromDb.getPassword());
assertEquals("Wrong email", "myEmail", userFromDb.getEmail());
}
use of org.springframework.integration.jdbc.storedproc.User in project spring-integration by spring-projects.
the class StoredProcOutboundGatewayWithSpringContextIntegrationTests method test.
@Test
public void test() throws Exception {
createUser.createUser(new User("myUsername", "myPassword", "myEmail"));
List<Message<Collection<User>>> received = new ArrayList<Message<Collection<User>>>();
received.add(consumer.poll(2000));
Message<Collection<User>> message = received.get(0);
context.stop();
assertNotNull(message);
assertNotNull(message.getPayload());
assertNotNull(message.getPayload() instanceof Collection<?>);
Collection<User> allUsers = message.getPayload();
assertTrue(allUsers.size() == 1);
}
Aggregations