33 */
44package org .javaee7 .websocket .binary .test ;
55
6-
76import java .io .File ;
87import java .io .IOException ;
98import java .net .URI ;
1413import javax .websocket .Session ;
1514import javax .websocket .WebSocketContainer ;
1615
17- import static junit .framework .Assert .assertNull ;
18-
1916import org .javaee7 .websocket .binary .MyEndpointByteArray ;
2017import org .javaee7 .websocket .binary .MyEndpointByteBuffer ;
2118import org .javaee7 .websocket .binary .MyEndpointClient ;
2522import org .jboss .arquillian .junit .Arquillian ;
2623import org .jboss .shrinkwrap .api .ShrinkWrap ;
2724import org .jboss .shrinkwrap .api .spec .WebArchive ;
25+ import static org .junit .Assert .*;
2826import org .junit .Test ;
2927import org .junit .runner .RunWith ;
3028
3129/**
3230 * @author Nikos Ballas
3331 * @author Arun Gupta
3432 */
35- @ RunWith (Arquillian .class )
33+ // @RunWith(Arquillian.class)
3634public class WebsocketBinaryEndpointTest {
3735
3836 private static final String WEBAPP_SRC = "src/main/webapp" ;
37+ private static final String RESPONSE = "Hello World!" ;
3938
4039 /**
4140 * Arquillian specific method for creating a file which can be deployed
@@ -45,14 +44,13 @@ public class WebsocketBinaryEndpointTest {
4544 * arquillian.xml file.
4645 */
4746 @ Deployment (testable = false )
48- @ TargetsContainer ("wildfly-arquillian" )
47+ // @TargetsContainer("wildfly-arquillian")
4948 public static WebArchive createDeployment () {
5049 WebArchive war = ShrinkWrap .create (WebArchive .class )
5150 .addClass (MyEndpointByteBuffer .class )
5251 .addClass (MyEndpointByteArray .class )
5352 .addClass (MyEndpointInputStream .class )
5453 .addClass (MyEndpointClient .class )
55- .addAsWebResource (new File (WEBAPP_SRC , "index.jsp" ))
5654 .addAsWebResource (new File (WEBAPP_SRC , "websocket.js" ));
5755 return war ;
5856 }
@@ -65,9 +63,13 @@ public static WebArchive createDeployment() {
6563 * @throws IOException
6664 */
6765 @ Test
68- public void testEndpointByteBuffer () throws URISyntaxException , DeploymentException , IOException {
66+ public void testEndpointByteBuffer () throws URISyntaxException , DeploymentException , IOException , InterruptedException {
6967 Session session = connectToServer ("bytebuffer" );
70- assertNull (session );
68+ assertNotNull (session );
69+ System .out .println ("Waiting for 2 seconds to receive response" );
70+ Thread .sleep (2000 );
71+ assertNotNull (MyEndpointClient .response );
72+ assertArrayEquals (RESPONSE .getBytes (), MyEndpointClient .response );
7173 }
7274
7375 /**
@@ -80,9 +82,13 @@ public void testEndpointByteBuffer() throws URISyntaxException, DeploymentExcept
8082 * @throws URISyntaxException
8183 */
8284 @ Test
83- public void testEndpointByteArray () throws DeploymentException , IOException , URISyntaxException {
85+ public void testEndpointByteArray () throws DeploymentException , IOException , URISyntaxException , InterruptedException {
8486 Session session = connectToServer ("bytearray" );
85- assertNull (session );
87+ assertNotNull (session );
88+ System .out .println ("Waiting for 2 seconds to receive response" );
89+ Thread .sleep (2000 );
90+ assertNotNull (MyEndpointClient .response );
91+ assertArrayEquals (RESPONSE .getBytes (), MyEndpointClient .response );
8692 }
8793
8894 /**
@@ -95,9 +101,13 @@ public void testEndpointByteArray() throws DeploymentException, IOException, URI
95101 * @throws URISyntaxException
96102 */
97103 @ Test
98- public void testEndpointInputStream () throws DeploymentException , IOException , URISyntaxException {
104+ public void testEndpointInputStream () throws DeploymentException , IOException , URISyntaxException , InterruptedException {
99105 Session session = connectToServer ("inputstream" );
100- assertNull (session );
106+ assertNotNull (session );
107+ System .out .println ("Waiting for 2 seconds to receive response" );
108+ Thread .sleep (2000 );
109+ assertNotNull (MyEndpointClient .response );
110+ assertArrayEquals (RESPONSE .getBytes (), MyEndpointClient .response );
101111 }
102112
103113 /**
@@ -111,7 +121,7 @@ public void testEndpointInputStream() throws DeploymentException, IOException, U
111121 * @throws URISyntaxException
112122 */
113123 public Session connectToServer (String endpoint ) throws DeploymentException , IOException , URISyntaxException {
114- WebSocketContainer wSocketContainer = ContainerProvider .getWebSocketContainer ();
115- return wSocketContainer .connectToServer (MyEndpointClient .class , new URI ("ws://localhost:8080/binary/" + endpoint ));
124+ WebSocketContainer container = ContainerProvider .getWebSocketContainer ();
125+ return container .connectToServer (MyEndpointClient .class , new URI ("ws://localhost:8080/binary/" + endpoint ));
116126 }
117127}
0 commit comments