コード例 #1
0
  @Test
  public void testWebSocketInjectionAndInterception() throws Exception {
    AnnotatedClient.reset();
    AnnotatedEndpoint.reset();
    ComponentInterceptor.resetInterceptions();

    final ServerContainer serverContainer =
        (ServerContainer) new InitialContext().lookup(SERVER_CONTAINER_JNDI_NAME);
    serverContainer.connectToServer(
        AnnotatedClient.class,
        new URI(
            "ws",
            "",
            TestSuiteEnvironment.getServerAddress(),
            8080,
            "/websocket/websocket/cruel",
            "",
            ""));

    Assert.assertEquals("Hello cruel World", AnnotatedClient.getMessage());

    Assert.assertTrue("Client endpoint's injection not correct.", AnnotatedClient.injectionOK);
    Assert.assertTrue("Server endpoint's injection not correct.", AnnotatedEndpoint.injectionOK);

    Assert.assertTrue(
        "PostConstruct method on client endpoint instance not called.",
        AnnotatedClient.postConstructCalled);
    Assert.assertTrue(
        "PostConstruct method on server endpoint instance not called.",
        AnnotatedEndpoint.postConstructCalled);

    Assert.assertEquals(
        "AroundConstruct interceptor method not invoked for client endpoint.",
        "AroundConstructInterceptor#Joe#AnnotatedClient",
        AnnotatedClient.getName());
    Assert.assertEquals(
        "AroundConstruct interceptor method not invoked for server endpoint.",
        "AroundConstructInterceptor#Joe#AnnotatedEndpoint",
        AnnotatedEndpoint.getName());

    Assert.assertEquals(2, ComponentInterceptor.getInterceptions().size());
    Assert.assertEquals("open", ComponentInterceptor.getInterceptions().get(0).getMethodName());
    Assert.assertEquals("message", ComponentInterceptor.getInterceptions().get(1).getMethodName());
  }
コード例 #2
0
 private boolean isInterceptorInvoked() {
   List<Interception> interceptions = ComponentInterceptor.getInterceptions();
   return interceptions != null
       && (interceptions.size() == 1)
       && interceptions.get(0).getMethodName().equals("init");
 }