use of org.springframework.integration.core.MessagingTemplate in project spring-integration by spring-projects.
the class FileOutboundGatewayParserTests method gatewayWithIgnoreMode.
/**
* Test uses the Ignore Mode of the File OutboundGateway. When persisting
* a payload using the File Outbound Gateway and the mode is set to IGNORE,
* then the destination file will be created and written if it does not yet exist,
* BUT if it exists it will not be overwritten. Instead the Message Payload will
* be silently ignored. The reply message will contain the pre-existing destination
* {@link File} as its payload.
*/
@Test
public void gatewayWithIgnoreMode() throws Exception {
final MessagingTemplate messagingTemplate = new MessagingTemplate();
messagingTemplate.setDefaultDestination(this.gatewayWithIgnoreModeChannel);
final String expectedFileContent = "Initial File Content:";
final File testFile = new File("test/fileToAppend.txt");
if (testFile.exists()) {
testFile.delete();
}
messagingTemplate.sendAndReceive(new GenericMessage<String>("Initial File Content:"));
Message<?> replyMessage = messagingTemplate.sendAndReceive(new GenericMessage<String>("String content:"));
String actualFileContent = new String(FileCopyUtils.copyToByteArray(testFile));
assertEquals(expectedFileContent, actualFileContent);
assertTrue(replyMessage.getPayload() instanceof File);
File replyPayload = (File) replyMessage.getPayload();
assertEquals(expectedFileContent, new String(FileCopyUtils.copyToByteArray(replyPayload)));
}
use of org.springframework.integration.core.MessagingTemplate in project spring-integration by spring-projects.
the class StoredProcJavaConfigTests method test.
@Test
public void test() {
Message<?> received = fooChannel.receive(10000);
assertNotNull(received);
Collection<?> primes = (Collection<?>) received.getPayload();
assertThat(primes, Matchers.<Object>contains(2, 3, 5, 7));
received = fooChannel.receive(100);
// verify maxMessagesPerPoll == 1
assertNull(received);
MessagingTemplate template = new MessagingTemplate(this.control);
template.convertAndSend("@'storedProcJavaConfigTests.Config.storedProc.inboundChannelAdapter'.stop()");
assertFalse(template.convertSendAndReceive("@'storedProcJavaConfigTests.Config.storedProc.inboundChannelAdapter'.isRunning()", Boolean.class));
}
use of org.springframework.integration.core.MessagingTemplate in project spring-integration by spring-projects.
the class StoredProcOutboundGatewayParserTests method testReplyTimeoutIsSet.
@Test
public void testReplyTimeoutIsSet() throws Exception {
setUp("storedProcOutboundGatewayParserTest.xml", getClass());
DirectFieldAccessor accessor = new DirectFieldAccessor(this.outboundGateway);
Object source = accessor.getPropertyValue("handler");
accessor = new DirectFieldAccessor(source);
source = accessor.getPropertyValue("messagingTemplate");
MessagingTemplate messagingTemplate = (MessagingTemplate) source;
accessor = new DirectFieldAccessor(messagingTemplate);
Long sendTimeout = (Long) accessor.getPropertyValue("sendTimeout");
assertEquals("Wrong sendTimeout", Long.valueOf(555L), sendTimeout);
}
use of org.springframework.integration.core.MessagingTemplate in project spring-integration by spring-projects.
the class JdbcOutboundGatewayParserTests method setupMessagingTemplate.
protected void setupMessagingTemplate() {
PollableChannel pollableChannel = this.context.getBean("output", PollableChannel.class);
this.messagingTemplate = new MessagingTemplate();
this.messagingTemplate.setDefaultDestination(pollableChannel);
this.messagingTemplate.setReceiveTimeout(10000);
}
use of org.springframework.integration.core.MessagingTemplate in project spring-integration by spring-projects.
the class MonitorTests method testStats.
@Test
public void testStats() throws InterruptedException {
final CountDownLatch afterSendLatch = new CountDownLatch(1);
DefaultMessageChannelMetrics channelMetrics = TestUtils.getPropertyValue(this.next, "channelMetrics", DefaultMessageChannelMetrics.class);
channelMetrics = Mockito.spy(channelMetrics);
Mockito.doAnswer(invocation -> {
Object result = invocation.callRealMethod();
afterSendLatch.countDown();
return result;
}).when(channelMetrics).afterSend(Mockito.any(MetricsContext.class), Mockito.eq(Boolean.TRUE));
new DirectFieldAccessor(this.next).setPropertyValue("channelMetrics", channelMetrics);
MessagingTemplate messagingTemplate = new MessagingTemplate(this.input);
messagingTemplate.setReceiveTimeout(10000);
Integer active = messagingTemplate.convertSendAndReceive("foo", Integer.class);
assertEquals(1, active.intValue());
assertTrue(afterSendLatch.await(10, TimeUnit.SECONDS));
assertEquals(0, this.handler.getActiveCount());
assertEquals(1, this.handler.getHandleCount());
assertThat(this.handler.getDuration().getMax(), greaterThan(99.0));
assertThat(this.handler.getDuration().getMax(), lessThan(10000.0));
assertEquals(1, this.input.getSendCount());
assertEquals(1, this.input.getReceiveCount());
assertEquals(1, this.next.getSendCount());
assertThat(this.next.getSendDuration().getMax(), greaterThan(99.0));
assertThat(this.next.getSendDuration().getMax(), lessThan(10000.0));
Message<?> fromInbound = this.output.receive(10000);
assertNotNull(fromInbound);
assertEquals(0, fromInbound.getPayload());
fromInbound = this.output.receive(10000);
assertNotNull(fromInbound);
assertEquals(1, fromInbound.getPayload());
assertThat(this.source.getMessageCount(), greaterThanOrEqualTo(2));
assertThat(this.nullChannel.getSendCount(), greaterThanOrEqualTo(2));
assertThat(this.pubsub.getSendCount(), greaterThanOrEqualTo(2));
}
Aggregations