@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 testNoBeansInContext() throws Exception {
    reset(httpServer);

    expect(httpServer.getWebSockets()).andReturn(new ArrayList<WebSocketEndpoint>()).once();

    replay(httpServer);

    GenericApplicationContext applicationContext = new GenericApplicationContext();
    applicationContext.refresh();

    servlet.initStrategies(applicationContext);

    verify(httpServer);
  }
  @Test
  public void testHttpServerParser() {
    Map<String, HttpServer> servers = beanDefinitionContext.getBeansOfType(HttpServer.class);

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

    // 1st message sender
    HttpServer server = servers.get("httpServer1");
    Assert.assertNull(server.getConnector());
    Assert.assertNull(server.getServletHandler());
    Assert.assertNull(server.getSecurityHandler());
    Assert.assertEquals(server.getConnectors().length, 0);
    Assert.assertEquals(server.getFilters().size(), 0);
    Assert.assertEquals(server.getFilterMappings().size(), 0);
    Assert.assertEquals(server.getName(), "httpServer1");
    Assert.assertEquals(server.getPort(), 8081);
    Assert.assertEquals(
        server.getContextConfigLocation(),
        "classpath:com/consol/citrus/http/citrus-servlet-context.xml");
    Assert.assertEquals(server.getResourceBase(), "src/main/resources");
    Assert.assertFalse(server.isAutoStart());
    Assert.assertFalse(server.isUseRootContextAsParent());
    Assert.assertEquals(server.getContextPath(), "/");
    Assert.assertEquals(server.getServletName(), "httpServer1-servlet");
    Assert.assertEquals(server.getServletMappingPath(), "/*");

    // 2nd message sender
    server = servers.get("httpServer2");
    Assert.assertNotNull(server.getConnector());
    Assert.assertEquals(
        server.getMessageConverter(), beanDefinitionContext.getBean("messageConverter"));
    Assert.assertEquals(server.getConnector(), beanDefinitionContext.getBean("connector"));
    Assert.assertEquals(server.getConnectors().length, 0);
    Assert.assertEquals(server.getName(), "httpServer2");
    Assert.assertEquals(server.getPort(), 8082);
    Assert.assertEquals(
        server.getContextConfigLocation(), "classpath:com/consol/citrus/http/servlet-context.xml");
    Assert.assertEquals(server.getResourceBase(), "src/it/resources");
    Assert.assertFalse(server.isAutoStart());
    Assert.assertTrue(server.isUseRootContextAsParent());
    Assert.assertEquals(server.getContextPath(), "/citrus");
    Assert.assertEquals(server.getServletName(), "citrus-http");
    Assert.assertEquals(server.getServletMappingPath(), "/foo");

    // 3rd message sender
    server = servers.get("httpServer3");
    Assert.assertNull(server.getConnector());
    Assert.assertNotNull(server.getConnectors());
    Assert.assertEquals(
        server.getConnectors().length,
        beanDefinitionContext.getBean("connectors", List.class).size());
    Assert.assertNotNull(server.getFilters());
    Assert.assertEquals(
        server.getFilters().size(), beanDefinitionContext.getBean("filters", Map.class).size());
    Assert.assertNotNull(server.getFilterMappings());
    Assert.assertEquals(
        server.getFilterMappings().size(),
        beanDefinitionContext.getBean("filterMappings", Map.class).size());
    Assert.assertEquals(server.getName(), "httpServer3");
    Assert.assertEquals(server.getPort(), 8083);
    Assert.assertEquals(
        server.getContextConfigLocation(),
        "classpath:com/consol/citrus/http/citrus-servlet-context.xml");
    Assert.assertEquals(server.getResourceBase(), "src/main/resources");
    Assert.assertFalse(server.isAutoStart());
    Assert.assertFalse(server.isUseRootContextAsParent());
    Assert.assertEquals(server.getServletName(), "httpServer3-servlet");

    // 4th message sender
    server = servers.get("httpServer4");
    Assert.assertNull(server.getConnector());
    Assert.assertNotNull(server.getServletHandler());
    Assert.assertEquals(
        server.getServletHandler(), beanDefinitionContext.getBean("servletHandler"));
    Assert.assertEquals(server.getName(), "httpServer4");
    Assert.assertEquals(server.getPort(), 8084);
    Assert.assertEquals(
        server.getContextConfigLocation(),
        "classpath:com/consol/citrus/http/citrus-servlet-context.xml");
    Assert.assertEquals(server.getResourceBase(), "src/main/resources");
    Assert.assertFalse(server.isAutoStart());
    Assert.assertFalse(server.isUseRootContextAsParent());
    Assert.assertEquals(server.getServletName(), "httpServer4-servlet");
    Assert.assertNotNull(server.getInterceptors());
    Assert.assertEquals(server.getInterceptors().size(), 0L);

    // 5th message sender
    server = servers.get("httpServer5");
    Assert.assertNull(server.getConnector());
    Assert.assertNotNull(server.getSecurityHandler());
    Assert.assertEquals(
        server.getSecurityHandler(), beanDefinitionContext.getBean("securityHandler"));
    Assert.assertEquals(server.getName(), "httpServer5");
    Assert.assertEquals(server.getPort(), 8085);
    Assert.assertEquals(
        server.getContextConfigLocation(),
        "classpath:com/consol/citrus/http/citrus-servlet-context.xml");
    Assert.assertEquals(server.getResourceBase(), "src/main/resources");
    Assert.assertFalse(server.isAutoStart());
    Assert.assertFalse(server.isUseRootContextAsParent());
    Assert.assertEquals(server.getServletName(), "httpServer5-servlet");
    Assert.assertNotNull(server.getInterceptors());
    Assert.assertEquals(server.getInterceptors().size(), 2L);
  }
  @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));
  }