Package org.springframework.batch.integration.chunk

Source Code of org.springframework.batch.integration.chunk.MessageSourcePollerInterceptorTests

package org.springframework.batch.integration.chunk;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import org.junit.Test;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.core.MessageSource;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.GenericMessage;

public class MessageSourcePollerInterceptorTests {

  @Test(expected = IllegalStateException.class)
  public void testMandatoryPropertiesUnset() throws Exception {
    MessageSourcePollerInterceptor interceptor = new MessageSourcePollerInterceptor();
    interceptor.afterPropertiesSet();
  }

  @Test
  public void testMandatoryPropertiesSetViaConstructor() throws Exception {
    MessageSourcePollerInterceptor interceptor = new MessageSourcePollerInterceptor(new TestMessageSource("foo"));
    interceptor.afterPropertiesSet();
  }

  @Test
  public void testMandatoryPropertiesSet() throws Exception {
    MessageSourcePollerInterceptor interceptor = new MessageSourcePollerInterceptor();
    interceptor.setMessageSource(new TestMessageSource("foo"));
    interceptor.afterPropertiesSet();
  }

  @Test
  public void testPreReceive() throws Exception {
    MessageSourcePollerInterceptor interceptor = new MessageSourcePollerInterceptor(new TestMessageSource("foo"));
    QueueChannel channel = new QueueChannel();
    assertTrue(interceptor.preReceive(channel));
    assertEquals("foo", channel.receive(10L).getPayload());
  }

  private static class TestMessageSource implements MessageSource<String> {

    private final String payload;

    public TestMessageSource(String payload) {
      super();
      this.payload = payload;
    }

    public Message<String> receive() {
      return new GenericMessage<String>(payload);
    }
  }

}
TOP

Related Classes of org.springframework.batch.integration.chunk.MessageSourcePollerInterceptorTests

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.