|
20 | 20 | import com.marklogic.client.DatabaseClientFactory; |
21 | 21 | import com.marklogic.client.DatabaseClientFactory.SSLHostnameVerifier; |
22 | 22 | import com.marklogic.client.DatabaseClientFactory.SecurityContext; |
| 23 | +import com.marklogic.client.MarkLogicIOException; |
23 | 24 | import com.marklogic.client.ResourceNotFoundException; |
24 | 25 | import com.marklogic.client.Transaction; |
25 | 26 | import com.marklogic.client.alerting.RuleDefinition; |
|
46 | 47 | import com.marklogic.client.query.ValuesDefinition; |
47 | 48 | import com.marklogic.client.query.ValuesListDefinition; |
48 | 49 | import org.custommonkey.xmlunit.exceptions.XpathException; |
| 50 | +import org.junit.jupiter.api.Assertions; |
49 | 51 | import org.junit.jupiter.api.Test; |
50 | 52 | import org.w3c.dom.Document; |
51 | 53 | import org.xml.sax.SAXException; |
@@ -167,35 +169,18 @@ public X509Certificate[] getAcceptedIssuers() { |
167 | 169 | } |
168 | 170 |
|
169 | 171 |
|
170 | | - @Test |
171 | | - public void testDatabaseClientConnectionInvalidPort() throws IOException |
172 | | - { |
173 | | - System.out.println("Running testDatabaseClientConnectionInvalidPort"); |
174 | | - |
175 | | - String filename = "facebook-10443244874876159931"; |
176 | | - |
177 | | - DatabaseClient client = newDatabaseClientBuilder().withPort(8033).build(); |
178 | | - |
179 | | - String expectedException = null; |
180 | | - String exception = ""; |
181 | | - if (IsSecurityEnabled()) |
182 | | - expectedException = "Failed to connect"; |
183 | | - else |
184 | | - expectedException = "com.marklogic.client.MarkLogicIOException"; |
185 | | - |
186 | | - // write doc |
187 | | - try { |
188 | | - writeDocumentUsingStringHandle(client, filename, "/write-text-doc/", "Text"); |
189 | | - } catch (Exception e) { |
190 | | - exception = e.toString(); |
191 | | - System.out.println("Exception is " + exception); |
192 | | - } |
193 | | - |
194 | | - assertTrue(exception.contains(expectedException)); |
| 172 | + @Test |
| 173 | + void invalidPort() { |
| 174 | + int assumedInvalidPort = 60123; |
| 175 | + DatabaseClient client = newDatabaseClientBuilder().withPort(assumedInvalidPort).build(); |
195 | 176 |
|
196 | | - // release client |
197 | | - client.release(); |
198 | | - } |
| 177 | + MarkLogicIOException ex = Assertions.assertThrows(MarkLogicIOException.class, () -> client.checkConnection()); |
| 178 | + String expected = "Error occurred while calling http://localhost:60123/v1/ping; java.net.ConnectException: " + |
| 179 | + "Failed to connect to localhost/127.0.0.1:60123 ; possible reasons for the error include " + |
| 180 | + "that a MarkLogic app server may not be listening on the port, or MarkLogic was stopped " + |
| 181 | + "or restarted during the request; check the MarkLogic server logs for more information."; |
| 182 | + assertEquals(expected, ex.getMessage()); |
| 183 | + } |
199 | 184 |
|
200 | 185 | @Test |
201 | 186 | public void testDatabaseClientConnectionInvalidUser() throws IOException, KeyManagementException, NoSuchAlgorithmException |
|
0 commit comments