title: Junit for Spring Integration Components
body: <p>I have following configuration setup for calling a REST service.</p>
  
  <pre><code>@Bean
  public MessageChannel requestChannel() {
      SubscribableChannel requestChannel= new DirectChannel();
      return requestChannel;
  }
  
  @Bean
  public MessageChannel responseChannel() {
      SubscribableChannel responseChannel = new DirectChannel();
      return responseChannel;
  }
  
  @Bean
  @ServiceActivator(inputChannel = "requestChannel")
  public MessageHandler httResponseMessageHandler(MessageChannel responseChannel,
          HeaderMapper&lt;HttpHeaders&gt; headerMapper, RequestHandlerRetryAdvice retryAdvice) {
      List&lt;Advice&gt; list = new ArrayList&lt;&gt;();
      list.add(retryAdvice);
      HttpRequestExecutingMessageHandler handler = new HttpRequestExecutingMessageHandler("https://localhost:8080/myrest/service/");
      handler.setHttpMethod(HttpMethod.POST);
      handler.setHeaderMapper(headerMapper);
      handler.setOutputChannel(responseChannel);
      handler.setExpectedResponseType(RtpResponse.class);
      handler.setAdviceChain(list);
      return handler;
  }
  </code></pre>
  
  <p>Below is the configuration of gateway and service activator to send request and fetch response.</p>
  
  <pre><code>@Override
  @ServiceActivator(inputChannel="responseChannel")
  public void receiveResponse(Message&lt;RtpResponse&gt; message) {
      LOGGER.info("Message: " + message);
      LOGGER.info("Message: " + message.getPayload());
      LOGGER.info(message.getClass().getCanonicalName());
  }
  
  @Override
  @Gateway(requestChannel = "requestChannel")
  public void sendRequest(RtpRequestBody requestBody) {
      requestChannel
      .send(
              MessageBuilder.withPayload(requestBody)
              .setHeader("Accept","application/json")
              .setHeader(MessageHeaders.CONTENT_TYPE,"application/json")
              .setHeader(MessageHeaders.ERROR_CHANNEL,errorChannel)
              .build()
          );
  }
  </code></pre>
  
  <p>I am stuck on how to write Junit for this flow. I am not sure if I need to restructure this flow into IntegrationFlow that would help with writing Junit tests for this. Advise needed. </p>