Search in sources :

Example 1 with DelayHandler

use of org.springframework.integration.handler.DelayHandler in project spring-integration by spring-projects.

the class DelayerParserTests method customScheduler.

@Test
public void customScheduler() {
    Object endpoint = context.getBean("delayerWithCustomScheduler");
    assertEquals(EventDrivenConsumer.class, endpoint.getClass());
    Object handler = TestUtils.getPropertyValue(endpoint, "handler");
    assertEquals(DelayHandler.class, handler.getClass());
    DelayHandler delayHandler = (DelayHandler) handler;
    assertEquals(Ordered.LOWEST_PRECEDENCE, delayHandler.getOrder());
    DirectFieldAccessor accessor = new DirectFieldAccessor(delayHandler);
    assertEquals(context.getBean("output"), accessor.getPropertyValue("outputChannel"));
    assertEquals(new Long(0), accessor.getPropertyValue("defaultDelay"));
    assertEquals(context.getBean("testScheduler"), accessor.getPropertyValue("taskScheduler"));
    assertNotNull(accessor.getPropertyValue("taskScheduler"));
    assertEquals(Boolean.TRUE, new DirectFieldAccessor(accessor.getPropertyValue("taskScheduler")).getPropertyValue("waitForTasksToCompleteOnShutdown"));
}
Also used : DelayHandler(org.springframework.integration.handler.DelayHandler) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Example 2 with DelayHandler

use of org.springframework.integration.handler.DelayHandler in project spring-integration by spring-projects.

the class DelayerParserTests method customMessageStore.

@Test
public void customMessageStore() {
    Object endpoint = context.getBean("delayerWithCustomMessageStore");
    assertEquals(EventDrivenConsumer.class, endpoint.getClass());
    Object handler = TestUtils.getPropertyValue(endpoint, "handler");
    assertEquals(DelayHandler.class, handler.getClass());
    DelayHandler delayHandler = (DelayHandler) handler;
    DirectFieldAccessor accessor = new DirectFieldAccessor(delayHandler);
    assertEquals(context.getBean("testMessageStore"), accessor.getPropertyValue("messageStore"));
}
Also used : DelayHandler(org.springframework.integration.handler.DelayHandler) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Example 3 with DelayHandler

use of org.springframework.integration.handler.DelayHandler in project spring-integration by spring-projects.

the class DelayerParserTests method transactionalSubElement.

// INT-2649
@Test
public void transactionalSubElement() throws Exception {
    Object endpoint = context.getBean("delayerWithTransactional");
    DelayHandler delayHandler = TestUtils.getPropertyValue(endpoint, "handler", DelayHandler.class);
    List<?> adviceChain = TestUtils.getPropertyValue(delayHandler, "delayedAdviceChain", List.class);
    assertEquals(1, adviceChain.size());
    Object advice = adviceChain.get(0);
    assertTrue(advice instanceof TransactionInterceptor);
    TransactionAttributeSource transactionAttributeSource = ((TransactionInterceptor) advice).getTransactionAttributeSource();
    assertTrue(transactionAttributeSource instanceof MatchAlwaysTransactionAttributeSource);
    Method method = MessageHandler.class.getMethod("handleMessage", Message.class);
    TransactionDefinition definition = transactionAttributeSource.getTransactionAttribute(method, null);
    assertEquals(TransactionDefinition.PROPAGATION_REQUIRED, definition.getPropagationBehavior());
    assertEquals(TransactionDefinition.ISOLATION_DEFAULT, definition.getIsolationLevel());
    assertEquals(TransactionDefinition.TIMEOUT_DEFAULT, definition.getTimeout());
    assertFalse(definition.isReadOnly());
}
Also used : NameMatchTransactionAttributeSource(org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource) TransactionAttributeSource(org.springframework.transaction.interceptor.TransactionAttributeSource) MatchAlwaysTransactionAttributeSource(org.springframework.transaction.interceptor.MatchAlwaysTransactionAttributeSource) TransactionDefinition(org.springframework.transaction.TransactionDefinition) DelayHandler(org.springframework.integration.handler.DelayHandler) TransactionInterceptor(org.springframework.transaction.interceptor.TransactionInterceptor) Method(java.lang.reflect.Method) MatchAlwaysTransactionAttributeSource(org.springframework.transaction.interceptor.MatchAlwaysTransactionAttributeSource) Test(org.junit.Test)

Example 4 with DelayHandler

use of org.springframework.integration.handler.DelayHandler in project spring-integration by spring-projects.

the class DelayerParserTests method testInt2243ExpressionSubElement.

@Test
public void testInt2243ExpressionSubElement() {
    DelayHandler delayHandler = context.getBean("delayerWithExpressionSubElement.handler", DelayHandler.class);
    assertEquals("headers.timestamp + 1000", TestUtils.getPropertyValue(delayHandler, "delayExpression", Expression.class).getExpressionString());
}
Also used : DelayHandler(org.springframework.integration.handler.DelayHandler) Test(org.junit.Test)

Example 5 with DelayHandler

use of org.springframework.integration.handler.DelayHandler in project spring-integration by spring-projects.

the class DelayerParserTests method defaultScheduler.

@Test
public void defaultScheduler() {
    DelayHandler delayHandler = context.getBean("delayerWithDefaultScheduler.handler", DelayHandler.class);
    assertEquals(99, delayHandler.getOrder());
    assertEquals(context.getBean("output"), TestUtils.getPropertyValue(delayHandler, "outputChannel"));
    assertEquals(new Long(1234), TestUtils.getPropertyValue(delayHandler, "defaultDelay", Long.class));
    // INT-2243
    assertNotNull(TestUtils.getPropertyValue(delayHandler, "delayExpression"));
    assertEquals("headers.foo", TestUtils.getPropertyValue(delayHandler, "delayExpression", Expression.class).getExpressionString());
    assertEquals(new Long(987), TestUtils.getPropertyValue(delayHandler, "messagingTemplate.sendTimeout", Long.class));
    assertNull(TestUtils.getPropertyValue(delayHandler, "taskScheduler"));
}
Also used : DelayHandler(org.springframework.integration.handler.DelayHandler) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 DelayHandler (org.springframework.integration.handler.DelayHandler)7 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)2 MatchAlwaysTransactionAttributeSource (org.springframework.transaction.interceptor.MatchAlwaysTransactionAttributeSource)2 NameMatchTransactionAttributeSource (org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource)2 TransactionAttributeSource (org.springframework.transaction.interceptor.TransactionAttributeSource)2 TransactionInterceptor (org.springframework.transaction.interceptor.TransactionInterceptor)2 Method (java.lang.reflect.Method)1 TransactionDefinition (org.springframework.transaction.TransactionDefinition)1