|
3 | 3 | */ |
4 | 4 | package com.marklogic.client.test; |
5 | 5 |
|
| 6 | +import com.marklogic.client.DatabaseClient; |
6 | 7 | import com.marklogic.client.DatabaseClient.ConnectionResult; |
7 | 8 | import com.marklogic.client.admin.QueryOptionsManager; |
8 | 9 | import com.marklogic.client.alerting.RuleManager; |
9 | | -import com.marklogic.client.document.BinaryDocumentManager; |
10 | | -import com.marklogic.client.document.GenericDocumentManager; |
11 | | -import com.marklogic.client.document.JSONDocumentManager; |
12 | | -import com.marklogic.client.document.TextDocumentManager; |
13 | | -import com.marklogic.client.document.XMLDocumentManager; |
| 10 | +import com.marklogic.client.document.*; |
14 | 11 | import com.marklogic.client.eval.ServerEvaluationCall; |
15 | 12 | import com.marklogic.client.pojo.PojoRepository; |
16 | 13 | import com.marklogic.client.query.QueryManager; |
|
19 | 16 | import org.junit.jupiter.api.BeforeAll; |
20 | 17 | import org.junit.jupiter.api.Test; |
21 | 18 |
|
22 | | -import static org.junit.jupiter.api.Assertions.assertFalse; |
23 | | -import static org.junit.jupiter.api.Assertions.assertNotNull; |
24 | | -import static org.junit.jupiter.api.Assertions.assertTrue; |
25 | | - |
26 | | -public class DatabaseClientTest { |
27 | | - @BeforeAll |
28 | | - public static void beforeClass() { |
29 | | - Common.connect(); |
30 | | - Common.connectRestAdmin(); |
31 | | - } |
32 | | - @AfterAll |
33 | | - public static void afterClass() { |
34 | | - } |
35 | | - |
36 | | - @Test |
37 | | - public void testNewDocument() { |
38 | | - GenericDocumentManager doc = Common.client.newDocumentManager(); |
39 | | - assertNotNull( doc); |
40 | | - } |
41 | | - |
42 | | - @Test |
43 | | - public void testNewBinaryDocument() { |
44 | | - BinaryDocumentManager doc = Common.client.newBinaryDocumentManager(); |
45 | | - assertNotNull( doc); |
46 | | - } |
47 | | - |
48 | | - @Test |
49 | | - public void testNewJSONDocument() { |
50 | | - JSONDocumentManager doc = Common.client.newJSONDocumentManager(); |
51 | | - assertNotNull( doc); |
52 | | - } |
53 | | - |
54 | | - @Test |
55 | | - public void testNewTextDocument() { |
56 | | - TextDocumentManager doc = Common.client.newTextDocumentManager(); |
57 | | - assertNotNull( doc); |
58 | | - } |
59 | | - |
60 | | - @Test |
61 | | - public void testNewXMLDocument() { |
62 | | - XMLDocumentManager doc = Common.client.newXMLDocumentManager(); |
63 | | - assertNotNull( doc); |
64 | | - } |
65 | | - |
66 | | - @Test |
67 | | - public void testNewLogger() { |
68 | | - RequestLogger logger = Common.client.newLogger(System.out); |
69 | | - assertNotNull( logger); |
70 | | - } |
71 | | - |
72 | | - @Test |
73 | | - public void testNewQueryManager() { |
74 | | - QueryManager mgr = Common.client.newQueryManager(); |
75 | | - assertNotNull( mgr); |
76 | | - } |
77 | | - |
78 | | - @Test |
79 | | - public void testNewRuleManager() { |
80 | | - RuleManager mgr = Common.client.newRuleManager(); |
81 | | - assertNotNull( mgr); |
82 | | - } |
83 | | - |
84 | | - @Test |
85 | | - public void testNewPojoRepository() { |
86 | | - PojoRepository<City, Integer> mgr = Common.client.newPojoRepository(City.class, Integer.class); |
87 | | - assertNotNull( mgr); |
88 | | - } |
89 | | - |
90 | | - @Test |
91 | | - public void testNewServerEvaluationCall() { |
92 | | - ServerEvaluationCall mgr = Common.client.newServerEval(); |
93 | | - assertNotNull( mgr); |
94 | | - } |
95 | | - |
96 | | - @Test |
97 | | - public void testNewQueryOptionsManager() { |
98 | | - QueryOptionsManager mgr = Common.restAdminClient.newServerConfigManager().newQueryOptionsManager(); |
99 | | - assertNotNull( mgr); |
100 | | - } |
101 | | - |
102 | | - @Test |
103 | | - public void testGetClientImplementationObject() { |
104 | | - Object impl = Common.client.getClientImplementation(); |
105 | | - assertNotNull( impl); |
106 | | - assertTrue( impl instanceof okhttp3.OkHttpClient); |
107 | | - } |
108 | | - |
109 | | - @Test |
110 | | - public void testCheckConnectionWithValidUser() { |
111 | | - ConnectionResult connResult = Common.newClient().checkConnection(); |
112 | | - assertTrue(connResult.isConnected()); |
113 | | - } |
114 | | - |
115 | | - @Test |
116 | | - public void testCheckConnectionWithInvalidUser() { |
117 | | - ConnectionResult connResult = Common.newClientBuilder().withUsername("invalid").withPassword("invalid").build().checkConnection(); |
118 | | - assertFalse(connResult.isConnected()); |
119 | | - assertTrue(connResult.getStatusCode() == 401); |
120 | | - assertTrue(connResult.getErrorMessage().equalsIgnoreCase("Unauthorized")); |
121 | | - } |
| 19 | +import static org.junit.jupiter.api.Assertions.*; |
| 20 | + |
| 21 | +class DatabaseClientTest { |
| 22 | + |
| 23 | + @BeforeAll |
| 24 | + public static void beforeClass() { |
| 25 | + Common.connect(); |
| 26 | + Common.connectRestAdmin(); |
| 27 | + } |
| 28 | + |
| 29 | + @AfterAll |
| 30 | + public static void afterClass() { |
| 31 | + } |
| 32 | + |
| 33 | + @Test |
| 34 | + void tryWithResource() { |
| 35 | + try (DatabaseClient client = Common.newClient()) { |
| 36 | + ConnectionResult result = client.checkConnection(); |
| 37 | + assertTrue(result.isConnected(), "This test is ensuring that a DatabaseClient, as of 7.1.0, can " + |
| 38 | + "be used in a try-with-resources block without any error being thrown. We don't have a way of " + |
| 39 | + "verifying that release() is actually called on the client though."); |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + @Test |
| 44 | + public void testNewDocument() { |
| 45 | + GenericDocumentManager doc = Common.client.newDocumentManager(); |
| 46 | + assertNotNull(doc); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + public void testNewBinaryDocument() { |
| 51 | + BinaryDocumentManager doc = Common.client.newBinaryDocumentManager(); |
| 52 | + assertNotNull(doc); |
| 53 | + } |
| 54 | + |
| 55 | + @Test |
| 56 | + public void testNewJSONDocument() { |
| 57 | + JSONDocumentManager doc = Common.client.newJSONDocumentManager(); |
| 58 | + assertNotNull(doc); |
| 59 | + } |
| 60 | + |
| 61 | + @Test |
| 62 | + public void testNewTextDocument() { |
| 63 | + TextDocumentManager doc = Common.client.newTextDocumentManager(); |
| 64 | + assertNotNull(doc); |
| 65 | + } |
| 66 | + |
| 67 | + @Test |
| 68 | + public void testNewXMLDocument() { |
| 69 | + XMLDocumentManager doc = Common.client.newXMLDocumentManager(); |
| 70 | + assertNotNull(doc); |
| 71 | + } |
| 72 | + |
| 73 | + @Test |
| 74 | + public void testNewLogger() { |
| 75 | + RequestLogger logger = Common.client.newLogger(System.out); |
| 76 | + assertNotNull(logger); |
| 77 | + } |
| 78 | + |
| 79 | + @Test |
| 80 | + public void testNewQueryManager() { |
| 81 | + QueryManager mgr = Common.client.newQueryManager(); |
| 82 | + assertNotNull(mgr); |
| 83 | + } |
| 84 | + |
| 85 | + @Test |
| 86 | + public void testNewRuleManager() { |
| 87 | + RuleManager mgr = Common.client.newRuleManager(); |
| 88 | + assertNotNull(mgr); |
| 89 | + } |
| 90 | + |
| 91 | + @Test |
| 92 | + public void testNewPojoRepository() { |
| 93 | + PojoRepository<City, Integer> mgr = Common.client.newPojoRepository(City.class, Integer.class); |
| 94 | + assertNotNull(mgr); |
| 95 | + } |
| 96 | + |
| 97 | + @Test |
| 98 | + public void testNewServerEvaluationCall() { |
| 99 | + ServerEvaluationCall mgr = Common.client.newServerEval(); |
| 100 | + assertNotNull(mgr); |
| 101 | + } |
| 102 | + |
| 103 | + @Test |
| 104 | + public void testNewQueryOptionsManager() { |
| 105 | + QueryOptionsManager mgr = Common.restAdminClient.newServerConfigManager().newQueryOptionsManager(); |
| 106 | + assertNotNull(mgr); |
| 107 | + } |
| 108 | + |
| 109 | + @Test |
| 110 | + public void testGetClientImplementationObject() { |
| 111 | + Object impl = Common.client.getClientImplementation(); |
| 112 | + assertNotNull(impl); |
| 113 | + assertTrue(impl instanceof okhttp3.OkHttpClient); |
| 114 | + } |
| 115 | + |
| 116 | + @Test |
| 117 | + public void testCheckConnectionWithValidUser() { |
| 118 | + ConnectionResult connResult = Common.newClient().checkConnection(); |
| 119 | + assertTrue(connResult.isConnected()); |
| 120 | + } |
| 121 | + |
| 122 | + @Test |
| 123 | + public void testCheckConnectionWithInvalidUser() { |
| 124 | + ConnectionResult connResult = Common.newClientBuilder().withUsername("invalid").withPassword("invalid").build().checkConnection(); |
| 125 | + assertFalse(connResult.isConnected()); |
| 126 | + assertTrue(connResult.getStatusCode() == 401); |
| 127 | + assertTrue(connResult.getErrorMessage().equalsIgnoreCase("Unauthorized")); |
| 128 | + } |
122 | 129 |
|
123 | 130 | } |
0 commit comments