Search in sources :

Example 36 with Session

use of javax.websocket.Session in project javaee7-samples by javaee-samples.

the class MyEndpointTest method testEndpointByteBuffer.

@Test
public void testEndpointByteBuffer() throws URISyntaxException, DeploymentException, IOException, InterruptedException {
    MyEndpointByteBufferClient.latch = new CountDownLatch(1);
    Session session = connectToServer(MyEndpointByteBufferClient.class, "bytebuffer");
    assertNotNull(session);
    assertTrue(MyEndpointByteBufferClient.latch.await(2, TimeUnit.SECONDS));
    assertArrayEquals(TEXT.getBytes(), MyEndpointByteBufferClient.response);
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) Session(javax.websocket.Session) Test(org.junit.Test)

Example 37 with Session

use of javax.websocket.Session in project javaee7-samples by javaee-samples.

the class MyEndpointTest method testTextEndpoint.

@Test
public void testTextEndpoint() throws URISyntaxException, DeploymentException, IOException, InterruptedException {
    MyEndpointTextClient.latch = new CountDownLatch(1);
    Session session = connectToServer(MyEndpointTextClient.class, "text");
    assertNotNull(session);
    assertTrue(MyEndpointTextClient.latch.await(2, TimeUnit.SECONDS));
    assertEquals(TEXT, MyEndpointTextClient.response);
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) Session(javax.websocket.Session) Test(org.junit.Test)

Example 38 with Session

use of javax.websocket.Session in project javaee7-samples by javaee-samples.

the class MyEndpointTest method testEndpointByteArray.

@Test
public void testEndpointByteArray() throws DeploymentException, IOException, URISyntaxException, InterruptedException {
    MyEndpointByteArrayClient.latch = new CountDownLatch(1);
    Session session = connectToServer(MyEndpointByteArrayClient.class, "bytearray");
    assertNotNull(session);
    assertTrue(MyEndpointByteArrayClient.latch.await(2, TimeUnit.SECONDS));
    assertNotNull(MyEndpointByteArrayClient.response);
    assertArrayEquals(TEXT.getBytes(), MyEndpointByteArrayClient.response);
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) Session(javax.websocket.Session) Test(org.junit.Test)

Example 39 with Session

use of javax.websocket.Session in project spring-framework by spring-projects.

the class StandardWebSocketSessionTests method getPrincipalNone.

@Test
@SuppressWarnings("resource")
public void getPrincipalNone() {
    Session nativeSession = Mockito.mock(Session.class);
    given(nativeSession.getUserPrincipal()).willReturn(null);
    StandardWebSocketSession session = new StandardWebSocketSession(this.headers, this.attributes, null, null);
    session.initializeNativeSession(nativeSession);
    reset(nativeSession);
    assertNull(session.getPrincipal());
    verifyNoMoreInteractions(nativeSession);
}
Also used : Session(javax.websocket.Session) Test(org.junit.Test)

Example 40 with Session

use of javax.websocket.Session in project spring-framework by spring-projects.

the class StandardWebSocketSessionTests method getPrincipalWithNativeSession.

@Test
@SuppressWarnings("resource")
public void getPrincipalWithNativeSession() {
    TestPrincipal user = new TestPrincipal("joe");
    Session nativeSession = Mockito.mock(Session.class);
    given(nativeSession.getUserPrincipal()).willReturn(user);
    StandardWebSocketSession session = new StandardWebSocketSession(this.headers, this.attributes, null, null);
    session.initializeNativeSession(nativeSession);
    assertSame(user, session.getPrincipal());
}
Also used : TestPrincipal(org.springframework.web.socket.handler.TestPrincipal) Session(javax.websocket.Session) Test(org.junit.Test)

Aggregations

Session (javax.websocket.Session)115 Test (org.junit.Test)92 URI (java.net.URI)73 WebSocketContainer (javax.websocket.WebSocketContainer)42 Endpoint (javax.websocket.Endpoint)39 CountDownLatch (java.util.concurrent.CountDownLatch)34 Context (org.apache.catalina.Context)31 DefaultServlet (org.apache.catalina.servlets.DefaultServlet)31 Tomcat (org.apache.catalina.startup.Tomcat)31 EndpointConfig (javax.websocket.EndpointConfig)29 ClientEndpointConfig (javax.websocket.ClientEndpointConfig)27 UndertowSession (io.undertow.websockets.jsr.UndertowSession)25 ServerEndpointConfig (javax.websocket.server.ServerEndpointConfig)23 ServerEndpoint (javax.websocket.server.ServerEndpoint)20 ServerWebSocketContainer (io.undertow.websockets.jsr.ServerWebSocketContainer)16 IOException (java.io.IOException)16 AnnotatedClientEndpoint (io.undertow.websockets.jsr.test.annotated.AnnotatedClientEndpoint)15 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)15 AtomicReference (java.util.concurrent.atomic.AtomicReference)15 FrameChecker (io.undertow.websockets.utils.FrameChecker)14