diff options
author | 2022-11-20 20:27:22 +0100 | |
---|---|---|
committer | 2022-11-22 16:40:03 +0100 | |
commit | 802f30714337cef64e3a065e8efe114c68756b82 (patch) | |
tree | ccabf5e10112bdb1f568cb362a04b850704b1427 /subprojects/language-web/src | |
parent | refactor: separate primitive types from nodes (diff) | |
download | refinery-802f30714337cef64e3a065e8efe114c68756b82.tar.gz refinery-802f30714337cef64e3a065e8efe114c68756b82.tar.zst refinery-802f30714337cef64e3a065e8efe114c68756b82.zip |
refactor(test): WebSocket integ test robustness
Diffstat (limited to 'subprojects/language-web/src')
-rw-r--r-- | subprojects/language-web/src/test/java/tools/refinery/language/web/ProblemWebSocketServletIntegrationTest.java | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/subprojects/language-web/src/test/java/tools/refinery/language/web/ProblemWebSocketServletIntegrationTest.java b/subprojects/language-web/src/test/java/tools/refinery/language/web/ProblemWebSocketServletIntegrationTest.java index e6b4b940..652fc13b 100644 --- a/subprojects/language-web/src/test/java/tools/refinery/language/web/ProblemWebSocketServletIntegrationTest.java +++ b/subprojects/language-web/src/test/java/tools/refinery/language/web/ProblemWebSocketServletIntegrationTest.java | |||
@@ -111,7 +111,7 @@ class ProblemWebSocketServletIntegrationTest { | |||
111 | @WebSocket | 111 | @WebSocket |
112 | public static class CloseImmediatelyTestClient extends WebSocketIntegrationTestClient { | 112 | public static class CloseImmediatelyTestClient extends WebSocketIntegrationTestClient { |
113 | @Override | 113 | @Override |
114 | protected void arrange(Session session, int responsesReceived) throws IOException { | 114 | protected void arrange(Session session, int responsesReceived) { |
115 | session.close(); | 115 | session.close(); |
116 | } | 116 | } |
117 | } | 117 | } |
@@ -120,20 +120,23 @@ class ProblemWebSocketServletIntegrationTest { | |||
120 | void subProtocolNegotiationTest() { | 120 | void subProtocolNegotiationTest() { |
121 | startServer(null); | 121 | startServer(null); |
122 | var clientSocket = new CloseImmediatelyTestClient(); | 122 | var clientSocket = new CloseImmediatelyTestClient(); |
123 | var session = connect(clientSocket, null, "<invalid sub-protocol>", XtextWebSocketServlet.XTEXT_SUBPROTOCOL_V1); | 123 | try (var session = connect(clientSocket, null, "<invalid sub-protocol>", |
124 | assertThat(session.getUpgradeResponse().getAcceptedSubProtocol(), | 124 | XtextWebSocketServlet.XTEXT_SUBPROTOCOL_V1)) { |
125 | equalTo(XtextWebSocketServlet.XTEXT_SUBPROTOCOL_V1)); | 125 | assertThat(session.getUpgradeResponse().getAcceptedSubProtocol(), |
126 | clientSocket.waitForTestResult(); | 126 | equalTo(XtextWebSocketServlet.XTEXT_SUBPROTOCOL_V1)); |
127 | assertThat(clientSocket.getCloseStatusCode(), equalTo(StatusCode.NORMAL)); | 127 | clientSocket.waitForTestResult(); |
128 | assertThat(clientSocket.getCloseStatusCode(), equalTo(StatusCode.NORMAL)); | ||
129 | } | ||
128 | } | 130 | } |
129 | 131 | ||
130 | @Test | 132 | @Test |
131 | void invalidJsonTest() { | 133 | void invalidJsonTest() { |
132 | startServer(null); | 134 | startServer(null); |
133 | var clientSocket = new InvalidJsonTestClient(); | 135 | var clientSocket = new InvalidJsonTestClient(); |
134 | connect(clientSocket, null, XtextWebSocketServlet.XTEXT_SUBPROTOCOL_V1); | 136 | try (var ignored = connect(clientSocket, null, XtextWebSocketServlet.XTEXT_SUBPROTOCOL_V1)) { |
135 | clientSocket.waitForTestResult(); | 137 | clientSocket.waitForTestResult(); |
136 | assertThat(clientSocket.getCloseStatusCode(), equalTo(XtextStatusCode.INVALID_JSON)); | 138 | assertThat(clientSocket.getCloseStatusCode(), equalTo(XtextStatusCode.INVALID_JSON)); |
139 | } | ||
137 | } | 140 | } |
138 | 141 | ||
139 | @WebSocket | 142 | @WebSocket |
@@ -149,17 +152,24 @@ class ProblemWebSocketServletIntegrationTest { | |||
149 | void validOriginTest(String origin) { | 152 | void validOriginTest(String origin) { |
150 | startServer("https://refinery.example,https://refinery.example:443"); | 153 | startServer("https://refinery.example,https://refinery.example:443"); |
151 | var clientSocket = new CloseImmediatelyTestClient(); | 154 | var clientSocket = new CloseImmediatelyTestClient(); |
152 | connect(clientSocket, origin, XtextWebSocketServlet.XTEXT_SUBPROTOCOL_V1); | 155 | try (var ignored = connect(clientSocket, origin, XtextWebSocketServlet.XTEXT_SUBPROTOCOL_V1)) { |
153 | clientSocket.waitForTestResult(); | 156 | clientSocket.waitForTestResult(); |
154 | assertThat(clientSocket.getCloseStatusCode(), equalTo(StatusCode.NORMAL)); | 157 | assertThat(clientSocket.getCloseStatusCode(), equalTo(StatusCode.NORMAL)); |
158 | } | ||
155 | } | 159 | } |
156 | 160 | ||
157 | @Test | 161 | @Test |
158 | void invalidOriginTest() { | 162 | void invalidOriginTest() { |
159 | startServer("https://refinery.example,https://refinery.example:443"); | 163 | startServer("https://refinery.example,https://refinery.example:443"); |
160 | var clientSocket = new CloseImmediatelyTestClient(); | 164 | var clientSocket = new CloseImmediatelyTestClient(); |
165 | // We have to put the close statement also into the lambda to ensure that the session is always closed. | ||
166 | @SuppressWarnings("squid:S5778") | ||
161 | var exception = assertThrows(CompletionException.class, | 167 | var exception = assertThrows(CompletionException.class, |
162 | () -> connect(clientSocket, "https://invalid.example", XtextWebSocketServlet.XTEXT_SUBPROTOCOL_V1)); | 168 | () -> { |
169 | var session = connect(clientSocket, "https://invalid.example", | ||
170 | XtextWebSocketServlet.XTEXT_SUBPROTOCOL_V1); | ||
171 | session.close(); | ||
172 | }); | ||
163 | var innerException = exception.getCause(); | 173 | var innerException = exception.getCause(); |
164 | assertThat(innerException, instanceOf(UpgradeException.class)); | 174 | assertThat(innerException, instanceOf(UpgradeException.class)); |
165 | assertThat(((UpgradeException) innerException).getResponseStatusCode(), equalTo(HttpStatus.FORBIDDEN_403)); | 175 | assertThat(((UpgradeException) innerException).getResponseStatusCode(), equalTo(HttpStatus.FORBIDDEN_403)); |