|
10 | 10 |
|
11 | 11 | import javax.websocket.ContainerProvider; |
12 | 12 | import javax.websocket.DeploymentException; |
| 13 | +import javax.websocket.Session; |
13 | 14 | import javax.websocket.WebSocketContainer; |
14 | 15 |
|
| 16 | +import junit.framework.Assert; |
| 17 | + |
15 | 18 | import org.javaee7.websocket.binary.MyEndpointByteArray; |
16 | 19 | import org.javaee7.websocket.binary.MyEndpointByteBuffer; |
17 | 20 | import org.javaee7.websocket.binary.MyEndpointClient; |
|
25 | 28 | import org.junit.runner.RunWith; |
26 | 29 |
|
27 | 30 | /** |
28 | | - * @author Nikos "cirix" Ballas |
29 | | - * |
| 31 | + * @author Nikos Ballas |
| 32 | + * |
30 | 33 | */ |
31 | 34 | @RunWith(Arquillian.class) |
32 | 35 | public class WebsocketByteBufferEndpointTest { |
33 | 36 | private static final String WEBAPP_SRC = "src/main/webapp"; |
34 | | - |
| 37 | + |
35 | 38 | /** |
36 | | - * Arquillian specific method for creating a file which can be deployed while executing the test. |
37 | | - * @return a war file |
| 39 | + * Arquillian specific method for creating a file which can be deployed |
| 40 | + * while executing the test. |
| 41 | + * |
| 42 | + * @return a war file deployable in the jboss instance configuraed in arquillian.xml file. |
38 | 43 | */ |
39 | | - @Deployment(testable = false) @TargetsContainer("wildfly-arquillian") |
40 | | - public static WebArchive createDeployment(){ |
41 | | - WebArchive war = ShrinkWrap.create(WebArchive.class). |
42 | | - addClass(MyEndpointByteBuffer.class). |
43 | | - addClass(MyEndpointByteArray.class). |
44 | | - addClass(MyEndpointInputStream.class). |
45 | | - addAsWebResource(new File(WEBAPP_SRC,"index.jsp")). |
46 | | - addAsWebResource(new File(WEBAPP_SRC,"websocket.js")); |
| 44 | + @Deployment(testable = false) |
| 45 | + @TargetsContainer("wildfly-arquillian") |
| 46 | + public static WebArchive createDeployment() { |
| 47 | + WebArchive war = ShrinkWrap.create(WebArchive.class) |
| 48 | + .addClass(MyEndpointByteBuffer.class) |
| 49 | + .addClass(MyEndpointByteArray.class) |
| 50 | + .addClass(MyEndpointInputStream.class) |
| 51 | + .addAsWebResource(new File(WEBAPP_SRC, "index.jsp")) |
| 52 | + .addAsWebResource(new File(WEBAPP_SRC, "websocket.js")); |
47 | 53 | return war; |
48 | 54 | } |
49 | | - |
| 55 | + |
50 | 56 | /** |
51 | 57 | * The basic test method for the class {@link MyEndpointByteBuffer} |
| 58 | + * |
52 | 59 | * @throws URISyntaxException |
53 | 60 | * @throws DeploymentException |
54 | 61 | * @throws IOException |
55 | 62 | */ |
56 | | - @Test |
57 | | - public void testEndPointByteBuffer() throws URISyntaxException, DeploymentException,IOException{ |
| 63 | + @Test |
| 64 | + public void testEndpointByteBuffer() throws URISyntaxException,DeploymentException, IOException { |
| 65 | + Session session = connectToServer("bytebuffer"); |
| 66 | + Assert.assertNull(session); |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * The basic test method for the class {@MyEndpointByteArray |
| 71 | + * } |
| 72 | + * |
| 73 | + * @throws DeploymentException |
| 74 | + * @throws IOException |
| 75 | + * @throws URISyntaxException |
| 76 | + */ |
| 77 | + @Test |
| 78 | + public void testEndpointByteArray() throws DeploymentException,IOException, URISyntaxException { |
| 79 | + Session session = connectToServer("bytearray"); |
| 80 | + Assert.assertNull(session); |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * The basic test method for the class {@MyEndpointInputStream |
| 85 | + * } |
| 86 | + * |
| 87 | + * @throws DeploymentException |
| 88 | + * @throws IOException |
| 89 | + * @throws URISyntaxException |
| 90 | + */ |
| 91 | + @Test |
| 92 | + public void testEndpointInputStream() throws DeploymentException,IOException, URISyntaxException { |
| 93 | + Session session = connectToServer("inputstream"); |
| 94 | + Assert.assertNull(session); |
| 95 | + } |
| 96 | + |
| 97 | + /** |
| 98 | + * Method used to supply connection to the server by passing the naming of |
| 99 | + * the websocket endpoint |
| 100 | + * |
| 101 | + * @param endpoint |
| 102 | + * @return |
| 103 | + * @throws DeploymentException |
| 104 | + * @throws IOException |
| 105 | + * @throws URISyntaxException |
| 106 | + */ |
| 107 | + public Session connectToServer(String endpoint) throws DeploymentException, IOException, URISyntaxException { |
58 | 108 | WebSocketContainer wSocketContainer = ContainerProvider.getWebSocketContainer(); |
59 | | - wSocketContainer.connectToServer(MyEndpointClient.class, new URI("ws://localhost:8080/binary/websockeet")); |
| 109 | + return wSocketContainer.connectToServer(MyEndpointClient.class, new URI("ws://localhost:8080/binary/" + endpoint)); |
60 | 110 | } |
61 | 111 | } |
0 commit comments