Search in sources :

Example 6 with MessageSelector

use of org.springframework.integration.core.MessageSelector in project spring-integration by spring-projects.

the class MessageSelectingInterceptorTests method testSingleSelectorAccepts.

@Test
public void testSingleSelectorAccepts() {
    final AtomicInteger counter = new AtomicInteger();
    MessageSelector selector = new TestMessageSelector(true, counter);
    MessageSelectingInterceptor interceptor = new MessageSelectingInterceptor(selector);
    QueueChannel channel = new QueueChannel();
    channel.addInterceptor(interceptor);
    assertTrue(channel.send(new GenericMessage<String>("test1")));
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) QueueChannel(org.springframework.integration.channel.QueueChannel) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MessageSelector(org.springframework.integration.core.MessageSelector) Test(org.junit.Test)

Example 7 with MessageSelector

use of org.springframework.integration.core.MessageSelector in project spring-integration by spring-projects.

the class GroovyFilterTests method testInt2433VerifyRiddingOfMessageProcessorsWrapping.

@Test
public void testInt2433VerifyRiddingOfMessageProcessorsWrapping() {
    assertTrue(this.groovyFilterMessageHandler instanceof MessageFilter);
    MessageSelector selector = TestUtils.getPropertyValue(this.groovyFilterMessageHandler, "selector", MethodInvokingSelector.class);
    @SuppressWarnings("rawtypes") MessageProcessor messageProcessor = TestUtils.getPropertyValue(selector, "messageProcessor", MessageProcessor.class);
    // before it was MethodInvokingMessageProcessor
    assertTrue(messageProcessor instanceof GroovyScriptExecutingMessageProcessor);
}
Also used : MessageProcessor(org.springframework.integration.handler.MessageProcessor) GroovyScriptExecutingMessageProcessor(org.springframework.integration.groovy.GroovyScriptExecutingMessageProcessor) GroovyScriptExecutingMessageProcessor(org.springframework.integration.groovy.GroovyScriptExecutingMessageProcessor) MessageSelector(org.springframework.integration.core.MessageSelector) MessageFilter(org.springframework.integration.filter.MessageFilter) Test(org.junit.Test)

Example 8 with MessageSelector

use of org.springframework.integration.core.MessageSelector in project spring-integration by spring-projects.

the class MethodInvokingSelectorParserTests method configOK.

@SuppressWarnings("unchecked")
@Test
public void configOK() throws Exception {
    DirectFieldAccessor accessor = new DirectFieldAccessor(chain);
    List<MessageSelector> selectors = (List<MessageSelector>) accessor.getPropertyValue("selectors");
    assertThat(selectors.get(0), is(instanceOf(MethodInvokingSelector.class)));
}
Also used : DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) List(java.util.List) MessageSelector(org.springframework.integration.core.MessageSelector) Test(org.junit.Test)

Example 9 with MessageSelector

use of org.springframework.integration.core.MessageSelector in project spring-integration by spring-projects.

the class SelectorChainParserTests method selectorChain.

@Test
public void selectorChain() {
    MessageSelector selector1 = (MessageSelector) context.getBean("selector1");
    MessageSelector selector2 = (MessageSelector) context.getBean("selector2");
    MessageSelectorChain chain = (MessageSelectorChain) context.getBean("selectorChain");
    List<MessageSelector> selectors = this.getSelectors(chain);
    assertEquals(VotingStrategy.ALL, this.getStrategy(chain));
    assertEquals(selector1, selectors.get(0));
    assertEquals(selector2, selectors.get(1));
    assertTrue(chain.accept(new GenericMessage<String>("test")));
    assertTrue(this.context.containsBean("pojoSelector"));
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) MessageSelectorChain(org.springframework.integration.selector.MessageSelectorChain) MessageSelector(org.springframework.integration.core.MessageSelector) Test(org.junit.Test)

Example 10 with MessageSelector

use of org.springframework.integration.core.MessageSelector in project spring-integration by spring-projects.

the class SelectorChainParserTests method nestedSelectorChain.

@Test
public void nestedSelectorChain() {
    MessageSelector selector1 = (MessageSelector) context.getBean("selector1");
    MessageSelector selector2 = (MessageSelector) context.getBean("selector2");
    MessageSelector selector3 = (MessageSelector) context.getBean("selector3");
    MessageSelector selector4 = (MessageSelector) context.getBean("selector4");
    MessageSelector selector5 = (MessageSelector) context.getBean("selector5");
    MessageSelector selector6 = (MessageSelector) context.getBean("selector6");
    MessageSelectorChain chain1 = (MessageSelectorChain) context.getBean("nestedSelectorChain");
    assertEquals(VotingStrategy.MAJORITY, this.getStrategy(chain1));
    List<MessageSelector> selectorList1 = this.getSelectors(chain1);
    assertEquals(selector1, selectorList1.get(0));
    assertTrue(selectorList1.get(1) instanceof MessageSelectorChain);
    MessageSelectorChain chain2 = (MessageSelectorChain) selectorList1.get(1);
    assertEquals(VotingStrategy.ALL, this.getStrategy(chain2));
    List<MessageSelector> selectorList2 = this.getSelectors(chain2);
    assertEquals(selector2, selectorList2.get(0));
    assertTrue(selectorList2.get(1) instanceof MessageSelectorChain);
    MessageSelectorChain chain3 = (MessageSelectorChain) selectorList2.get(1);
    assertEquals(VotingStrategy.ANY, this.getStrategy(chain3));
    List<MessageSelector> selectorList3 = this.getSelectors(chain3);
    assertEquals(selector3, selectorList3.get(0));
    assertEquals(selector4, selectorList3.get(1));
    assertEquals(selector5, selectorList2.get(2));
    assertTrue(selectorList1.get(2) instanceof MessageSelectorChain);
    MessageSelectorChain chain4 = (MessageSelectorChain) selectorList1.get(2);
    assertEquals(VotingStrategy.MAJORITY_OR_TIE, this.getStrategy(chain4));
    List<MessageSelector> selectorList4 = this.getSelectors(chain4);
    assertEquals(selector6, selectorList4.get(0));
    assertTrue(chain1.accept(new GenericMessage<String>("test1")));
    assertTrue(chain2.accept(new GenericMessage<String>("test2")));
    assertTrue(chain3.accept(new GenericMessage<String>("test3")));
    assertTrue(chain4.accept(new GenericMessage<String>("test4")));
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) MessageSelectorChain(org.springframework.integration.selector.MessageSelectorChain) MessageSelector(org.springframework.integration.core.MessageSelector) Test(org.junit.Test)

Aggregations

MessageSelector (org.springframework.integration.core.MessageSelector)15 Test (org.junit.Test)9 GenericMessage (org.springframework.messaging.support.GenericMessage)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 QueueChannel (org.springframework.integration.channel.QueueChannel)4 MethodInvokingSelector (org.springframework.integration.filter.MethodInvokingSelector)4 MessageFilter (org.springframework.integration.filter.MessageFilter)3 LambdaMessageProcessor (org.springframework.integration.handler.LambdaMessageProcessor)3 MessageSelectorChain (org.springframework.integration.selector.MessageSelectorChain)2 List (java.util.List)1 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 Bean (org.springframework.context.annotation.Bean)1 ExpressionEvaluatingSelector (org.springframework.integration.filter.ExpressionEvaluatingSelector)1 GroovyScriptExecutingMessageProcessor (org.springframework.integration.groovy.GroovyScriptExecutingMessageProcessor)1 MessageProcessor (org.springframework.integration.handler.MessageProcessor)1 ManagedOperation (org.springframework.jmx.export.annotation.ManagedOperation)1 MessageChannel (org.springframework.messaging.MessageChannel)1 MessageDeliveryException (org.springframework.messaging.MessageDeliveryException)1