@Test
  public void testConfigureHandlerInterceptor() throws Exception {
    List<Object> interceptors = new ArrayList<Object>();
    interceptors.add(new LoggingHandlerInterceptor());

    reset(httpServer);

    expect(httpServer.getInterceptors()).andReturn(interceptors).once();
    expect(httpServer.getEndpointAdapter()).andReturn(null).once();
    expect(httpServer.getMessageConverter()).andReturn(new HttpMessageConverter()).once();
    expect(httpServer.getWebSockets()).andReturn(new ArrayList<WebSocketEndpoint>()).once();

    replay(httpServer);

    servlet.initStrategies(applicationContext);

    Assert.assertEquals(handlerInterceptor.getInterceptors().size(), 1L);
    Assert.assertEquals(handlerInterceptor.getInterceptors().get(0), interceptors.get(0));
    Assert.assertNotNull(httpMessageController.getEndpointConfiguration().getMessageConverter());

    Assert.assertEquals(
        httpMessageController.getEndpointAdapter().getClass(), EmptyResponseEndpointAdapter.class);

    verify(httpServer);
  }
  @Test
  public void testConfigureMessageController() throws Exception {
    reset(httpServer);

    expect(httpServer.getInterceptors()).andReturn(null).once();
    expect(httpServer.getEndpointAdapter()).andReturn(new TimeoutProducingEndpointAdapter()).once();
    expect(httpServer.getMessageConverter()).andReturn(new HttpMessageConverter()).once();
    expect(httpServer.getWebSockets()).andReturn(new ArrayList<WebSocketEndpoint>()).once();

    replay(httpServer);

    servlet.initStrategies(applicationContext);

    Assert.assertEquals(handlerInterceptor.getInterceptors().size(), 0L);
    Assert.assertEquals(
        httpMessageController.getEndpointAdapter().getClass(),
        TimeoutProducingEndpointAdapter.class);
    Assert.assertNotNull(httpMessageController.getEndpointConfiguration().getMessageConverter());

    verify(httpServer);
  }
  @Test
  public void testConfigureWebSockerHandler() throws Exception {
    WebSocketEndpoint wsEndpoint = EasyMock.createMock(WebSocketEndpoint.class);
    WebSocketEndpointConfiguration wsEndpointConfig =
        EasyMock.createMock(WebSocketEndpointConfiguration.class);
    String wsId = "wsId";
    String endpointUri = "someEndpointUri";

    List<WebSocketEndpoint> webSockets = new ArrayList<>();
    webSockets.add(wsEndpoint);

    reset(httpServer);

    expect(httpServer.getInterceptors()).andReturn(null).once();
    expect(httpServer.getEndpointAdapter()).andReturn(null).once();
    expect(httpServer.getMessageConverter()).andReturn(new HttpMessageConverter()).once();
    expect(httpServer.getWebSockets()).andReturn(webSockets).once();

    expect(wsEndpoint.getEndpointConfiguration()).andReturn(wsEndpointConfig).once();
    expect(wsEndpoint.getName()).andReturn(wsId).once();
    wsEndpoint.setWebSocketHandler(isA(CitrusWebSocketHandler.class));

    expect(wsEndpointConfig.getEndpointUri()).andReturn(endpointUri).once();

    replay(httpServer);
    replay(wsEndpoint);
    replay(wsEndpointConfig);

    servlet.initStrategies(applicationContext);

    Map<String, ?> urlMap = urlHandlerMapping.getUrlMap();
    Assert.assertEquals(urlMap.size(), 1);
    Assert.assertTrue(urlMap.containsKey(endpointUri));
    Assert.assertNotNull(urlMap.get(endpointUri));

    verify(httpServer);
    verify(wsEndpoint);
    verify(wsEndpointConfig);
  }
  @Test
  public void testEndpointAdapter() {
    ApplicationContext beanDefinitionContext = createApplicationContext("adapter");

    Map<String, HttpServer> servers = beanDefinitionContext.getBeansOfType(HttpServer.class);

    Assert.assertEquals(servers.size(), 6);

    // 1st message sender
    HttpServer server = servers.get("httpServer1");
    Assert.assertEquals(server.getName(), "httpServer1");
    Assert.assertEquals(server.getPort(), 8081);
    Assert.assertNotNull(server.getEndpointAdapter());
    Assert.assertEquals(server.getEndpointAdapter().getClass(), ChannelEndpointAdapter.class);
    Assert.assertNotNull(server.getEndpointAdapter().getEndpoint());
    Assert.assertEquals(
        server.getEndpointAdapter().getEndpoint().getEndpointConfiguration().getTimeout(), 10000L);
    Assert.assertEquals(
        ((ChannelEndpointConfiguration)
                server.getEndpointAdapter().getEndpoint().getEndpointConfiguration())
            .getChannelName(),
        "serverChannel");

    // 2nd message sender
    server = servers.get("httpServer2");
    Assert.assertEquals(server.getName(), "httpServer2");
    Assert.assertEquals(server.getPort(), 8082);
    Assert.assertNotNull(server.getEndpointAdapter());
    Assert.assertEquals(server.getEndpointAdapter().getClass(), JmsEndpointAdapter.class);
    Assert.assertNotNull(server.getEndpointAdapter().getEndpoint());
    Assert.assertEquals(
        server.getEndpointAdapter().getEndpoint().getEndpointConfiguration().getTimeout(), 2500);
    Assert.assertEquals(
        ((JmsEndpointConfiguration)
                server.getEndpointAdapter().getEndpoint().getEndpointConfiguration())
            .getDestinationName(),
        "serverQueue");
    Assert.assertEquals(
        ((JmsEndpointConfiguration)
                server.getEndpointAdapter().getEndpoint().getEndpointConfiguration())
            .getConnectionFactory(),
        beanDefinitionContext.getBean("connectionFactory", ConnectionFactory.class));

    // 3rd message sender
    server = servers.get("httpServer3");
    Assert.assertEquals(server.getName(), "httpServer3");
    Assert.assertEquals(server.getPort(), 8083);
    Assert.assertNotNull(server.getEndpointAdapter());
    Assert.assertEquals(server.getEndpointAdapter().getClass(), EmptyResponseEndpointAdapter.class);

    // 4th message sender
    server = servers.get("httpServer4");
    Assert.assertEquals(server.getName(), "httpServer4");
    Assert.assertEquals(server.getPort(), 8084);
    Assert.assertNotNull(server.getEndpointAdapter());
    Assert.assertEquals(
        server.getEndpointAdapter().getClass(), StaticResponseEndpointAdapter.class);
    Assert.assertEquals(
        StringUtils.trimAllWhitespace(
            ((StaticResponseEndpointAdapter) server.getEndpointAdapter()).getMessagePayload()),
        "<TestMessage><Text>Hello!</Text></TestMessage>");
    Assert.assertEquals(
        ((StaticResponseEndpointAdapter) server.getEndpointAdapter())
            .getMessageHeader()
            .get("Operation"),
        "sayHello");

    // 5th message sender
    server = servers.get("httpServer5");
    Assert.assertEquals(server.getName(), "httpServer5");
    Assert.assertEquals(server.getPort(), 8085);
    Assert.assertNotNull(server.getEndpointAdapter());
    Assert.assertEquals(
        server.getEndpointAdapter().getClass(), TimeoutProducingEndpointAdapter.class);

    // 6th message sender
    server = servers.get("httpServer6");
    Assert.assertEquals(server.getName(), "httpServer6");
    Assert.assertEquals(server.getPort(), 8086);
    Assert.assertNotNull(server.getEndpointAdapter());
    Assert.assertEquals(
        server.getEndpointAdapter(),
        beanDefinitionContext.getBean("httpServerAdapter6", EndpointAdapter.class));
  }