コード例 #1
0
  @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);
  }
コード例 #2
0
  @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);
  }
コード例 #3
0
  @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);
  }
コード例 #4
0
  @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);
  }