|
25 | 25 | import static org.junit.Assert.fail;
|
26 | 26 |
|
27 | 27 | import org.junit.Test;
|
| 28 | +import org.slf4j.Logger; |
| 29 | +import org.slf4j.LoggerFactory; |
28 | 30 |
|
29 | 31 | import com.arangodb.entity.AdminLogEntity;
|
30 | 32 | import com.arangodb.entity.ArangoUnixTime;
|
|
40 | 42 | */
|
41 | 43 | public class ArangoDriverAdminTest extends BaseTest {
|
42 | 44 |
|
43 |
| - public ArangoDriverAdminTest(ArangoConfigure configure, ArangoDriver driver) { |
44 |
| - super(configure, driver); |
45 |
| - } |
| 45 | + private static Logger logger = LoggerFactory.getLogger(ArangoDriverAdminTest.class); |
46 | 46 |
|
47 |
| - @Test |
48 |
| - public void test_version() throws ArangoException { |
| 47 | + public ArangoDriverAdminTest(ArangoConfigure configure, ArangoDriver driver) { |
| 48 | + super(configure, driver); |
| 49 | + } |
49 | 50 |
|
50 |
| - ArangoVersion version = driver.getVersion(); |
51 |
| - assertThat(version.getServer(), is("arango")); |
52 |
| - assertThat(version.getVersion(), startsWith("2.")); |
| 51 | + @Test |
| 52 | + public void test_version() throws ArangoException { |
53 | 53 |
|
54 |
| - } |
| 54 | + ArangoVersion version = driver.getVersion(); |
| 55 | + assertThat(version.getServer(), is("arango")); |
| 56 | + assertThat(version.getVersion(), startsWith("2.")); |
55 | 57 |
|
56 |
| - @Test |
57 |
| - public void test_time() throws ArangoException { |
| 58 | + } |
58 | 59 |
|
59 |
| - ArangoUnixTime time = driver.getTime(); |
60 |
| - assertThat(time.getSecond(), is(not(0))); |
61 |
| - assertThat(time.getMicrosecond(), is(not(0))); |
| 60 | + @Test |
| 61 | + public void test_time() throws ArangoException { |
62 | 62 |
|
63 |
| - System.out.println("unixtime=" + time.getSecond()); |
64 |
| - System.out.println("unixtime_micros=" + time.getMicrosecond()); |
65 |
| - System.out.println("unixtime_millis=" + time.getTimeMillis()); |
| 63 | + ArangoUnixTime time = driver.getTime(); |
| 64 | + assertThat(time.getSecond(), is(not(0))); |
| 65 | + assertThat(time.getMicrosecond(), is(not(0))); |
66 | 66 |
|
67 |
| - } |
| 67 | + logger.debug("unixtime=" + time.getSecond()); |
| 68 | + logger.debug("unixtime_micros=" + time.getMicrosecond()); |
| 69 | + logger.debug("unixtime_millis=" + time.getTimeMillis()); |
68 | 70 |
|
69 |
| - @Test |
70 |
| - public void test_log_all() throws ArangoException { |
| 71 | + } |
71 | 72 |
|
72 |
| - AdminLogEntity entity = driver.getServerLog(null, null, null, null, null, null, null); |
| 73 | + @Test |
| 74 | + public void test_log_all() throws ArangoException { |
73 | 75 |
|
74 |
| - assertThat(entity, is(notNullValue())); |
75 |
| - assertThat(entity.getTotalAmount(), is(not(0))); |
76 |
| - assertThat(entity.getLogs().size(), is(entity.getTotalAmount())); |
| 76 | + AdminLogEntity entity = driver.getServerLog(null, null, null, null, null, null, null); |
77 | 77 |
|
78 |
| - // debug |
79 |
| - for (AdminLogEntity.LogEntry log : entity.getLogs()) { |
80 |
| - System.out |
81 |
| - .printf("%d\t%d\t%tF %<tT\t%s%n", log.getLid(), log.getLevel(), log.getTimestamp(), log.getText()); |
82 |
| - } |
| 78 | + assertThat(entity, is(notNullValue())); |
| 79 | + assertThat(entity.getTotalAmount(), is(not(0))); |
| 80 | + assertThat(entity.getLogs().size(), is(entity.getTotalAmount())); |
83 | 81 |
|
84 |
| - } |
| 82 | + // debug |
| 83 | + for (AdminLogEntity.LogEntry log : entity.getLogs()) { |
| 84 | + logger.debug("%d\t%d\t%tF %<tT\t%s%n", log.getLid(), log.getLevel(), log.getTimestamp(), log.getText()); |
| 85 | + } |
85 | 86 |
|
86 |
| - @Test |
87 |
| - public void test_log_text() throws ArangoException { |
| 87 | + } |
88 | 88 |
|
89 |
| - AdminLogEntity entity = driver.getServerLog(null, null, null, null, null, null, "Fun"); |
| 89 | + @Test |
| 90 | + public void test_log_text() throws ArangoException { |
90 | 91 |
|
91 |
| - assertThat(entity, is(notNullValue())); |
92 |
| - // debug |
93 |
| - for (AdminLogEntity.LogEntry log : entity.getLogs()) { |
94 |
| - System.out |
95 |
| - .printf("%d\t%d\t%tF %<tT\t%s%n", log.getLid(), log.getLevel(), log.getTimestamp(), log.getText()); |
96 |
| - } |
| 92 | + AdminLogEntity entity = driver.getServerLog(null, null, null, null, null, null, "Fun"); |
97 | 93 |
|
98 |
| - } |
| 94 | + assertThat(entity, is(notNullValue())); |
| 95 | + // debug |
| 96 | + for (AdminLogEntity.LogEntry log : entity.getLogs()) { |
| 97 | + logger.debug("%d\t%d\t%tF %<tT\t%s%n", log.getLid(), log.getLevel(), log.getTimestamp(), log.getText()); |
| 98 | + } |
99 | 99 |
|
100 |
| - // TODO テスト増やす |
| 100 | + } |
101 | 101 |
|
102 |
| - @Test |
103 |
| - public void test_statistics() throws ArangoException { |
| 102 | + // TODO テスト増やす |
104 | 103 |
|
105 |
| - StatisticsEntity stat = driver.getStatistics(); |
| 104 | + @Test |
| 105 | + public void test_statistics() throws ArangoException { |
106 | 106 |
|
107 |
| - // debug |
108 |
| - Gson gson = new Gson(); |
109 |
| - assertNotNull(gson.toJson(stat)); |
110 |
| - assertNotNull(gson.toJson(stat.getSystem())); |
111 |
| - assertNotNull(gson.toJson(stat.getClient())); |
112 |
| - assertNotNull(gson.toJson(stat.getServer())); |
| 107 | + StatisticsEntity stat = driver.getStatistics(); |
113 | 108 |
|
114 |
| - } |
| 109 | + // debug |
| 110 | + Gson gson = new Gson(); |
| 111 | + assertNotNull(gson.toJson(stat)); |
| 112 | + assertNotNull(gson.toJson(stat.getSystem())); |
| 113 | + assertNotNull(gson.toJson(stat.getClient())); |
| 114 | + assertNotNull(gson.toJson(stat.getServer())); |
115 | 115 |
|
116 |
| - @Test |
117 |
| - public void test_statistics_description() throws ArangoException { |
| 116 | + } |
118 | 117 |
|
119 |
| - StatisticsDescriptionEntity desc = driver.getStatisticsDescription(); |
| 118 | + @Test |
| 119 | + public void test_statistics_description() throws ArangoException { |
120 | 120 |
|
121 |
| - // debug |
122 |
| - Gson gson = new Gson(); |
123 |
| - assertNotNull(gson.toJson(desc)); |
124 |
| - assertNotNull(gson.toJson(desc.getGroups())); |
125 |
| - assertNotNull(gson.toJson(desc.getFigures())); |
126 |
| - } |
| 121 | + StatisticsDescriptionEntity desc = driver.getStatisticsDescription(); |
127 | 122 |
|
128 |
| - @Test |
129 |
| - public void test_reload_routing() throws ArangoException { |
| 123 | + // debug |
| 124 | + Gson gson = new Gson(); |
| 125 | + assertNotNull(gson.toJson(desc)); |
| 126 | + assertNotNull(gson.toJson(desc.getGroups())); |
| 127 | + assertNotNull(gson.toJson(desc.getFigures())); |
| 128 | + } |
130 | 129 |
|
131 |
| - DefaultEntity entity = driver.reloadRouting(); |
132 |
| - assertThat(entity.getStatusCode(), is(200)); |
133 |
| - assertThat(entity.isError(), is(false)); |
| 130 | + @Test |
| 131 | + public void test_reload_routing() throws ArangoException { |
134 | 132 |
|
135 |
| - } |
| 133 | + DefaultEntity entity = driver.reloadRouting(); |
| 134 | + assertThat(entity.getStatusCode(), is(200)); |
| 135 | + assertThat(entity.isError(), is(false)); |
136 | 136 |
|
137 |
| - @Test |
138 |
| - public void test_execute_do_nothing() throws ArangoException { |
| 137 | + } |
139 | 138 |
|
140 |
| - DefaultEntity entity = driver.executeScript(""); |
141 |
| - assertThat(entity.isError(), is(false)); |
142 |
| - assertThat(entity.getCode(), is(200)); |
143 |
| - assertThat(entity.getStatusCode(), is(200)); |
| 139 | + @Test |
| 140 | + public void test_execute_do_nothing() throws ArangoException { |
144 | 141 |
|
145 |
| - } |
| 142 | + DefaultEntity entity = driver.executeScript(""); |
| 143 | + assertThat(entity.isError(), is(false)); |
| 144 | + assertThat(entity.getCode(), is(200)); |
| 145 | + assertThat(entity.getStatusCode(), is(200)); |
146 | 146 |
|
147 |
| - @Test |
148 |
| - public void test_execute() throws ArangoException { |
| 147 | + } |
149 | 148 |
|
150 |
| - DefaultEntity entity = driver.executeScript("var db = require(\"internal\").db; cols = db._collections();\n" |
151 |
| - + "len = cols.length;\n"); |
152 |
| - assertThat(entity.isError(), is(false)); |
153 |
| - assertThat(entity.getCode(), is(200)); |
154 |
| - assertThat(entity.getStatusCode(), is(200)); |
| 149 | + @Test |
| 150 | + public void test_execute() throws ArangoException { |
155 | 151 |
|
156 |
| - } |
| 152 | + DefaultEntity entity = driver.executeScript( |
| 153 | + "var db = require(\"internal\").db; cols = db._collections();\n" + "len = cols.length;\n"); |
| 154 | + assertThat(entity.isError(), is(false)); |
| 155 | + assertThat(entity.getCode(), is(200)); |
| 156 | + assertThat(entity.getStatusCode(), is(200)); |
157 | 157 |
|
158 |
| - @Test |
159 |
| - public void test_execute_delete_collection() throws ArangoException { |
| 158 | + } |
160 | 159 |
|
161 |
| - DefaultEntity entity1 = driver.executeScript("var db = require(\"internal\").db; db._drop(\"" |
162 |
| - + "col-execute-delete-test" + "\")"); |
163 |
| - assertThat(entity1.isError(), is(false)); |
164 |
| - assertThat(entity1.getCode(), is(200)); |
165 |
| - assertThat(entity1.getStatusCode(), is(200)); |
| 160 | + @Test |
| 161 | + public void test_execute_delete_collection() throws ArangoException { |
166 | 162 |
|
167 |
| - driver.createCollection("col-execute-delete-test"); |
168 |
| - driver.getCollection("col-execute-delete-test"); |
| 163 | + DefaultEntity entity1 = driver |
| 164 | + .executeScript("var db = require(\"internal\").db; db._drop(\"" + "col-execute-delete-test" + "\")"); |
| 165 | + assertThat(entity1.isError(), is(false)); |
| 166 | + assertThat(entity1.getCode(), is(200)); |
| 167 | + assertThat(entity1.getStatusCode(), is(200)); |
169 | 168 |
|
170 |
| - DefaultEntity entity2 = driver.executeScript("var db = require(\"internal\").db; db._drop(\"" |
171 |
| - + "col-execute-delete-test" + "\")"); |
172 |
| - assertThat(entity2.isError(), is(false)); |
173 |
| - assertThat(entity2.getCode(), is(200)); |
174 |
| - assertThat(entity2.getStatusCode(), is(200)); |
175 |
| - |
176 |
| - try { |
177 |
| - driver.getCollection("col-execute-delete-test"); |
178 |
| - fail(); |
179 |
| - } catch (ArangoException e) { |
180 |
| - assertThat(e.getCode(), is(404)); |
181 |
| - assertThat(e.getErrorNumber(), is(1203)); |
182 |
| - } |
183 |
| - } |
| 169 | + driver.createCollection("col-execute-delete-test"); |
| 170 | + driver.getCollection("col-execute-delete-test"); |
184 | 171 |
|
185 |
| - @Test |
186 |
| - public void test_execute_error() throws ArangoException { |
187 |
| - try { |
188 |
| - driver.executeScript("xxx"); |
189 |
| - fail(); |
190 |
| - } catch (ArangoException e) { |
191 |
| - String t = "Internal Server Error: JavaScript exception in file 'undefined' at 1,14: ReferenceError: xxx is not defined\n" |
192 |
| - + "!(function() {xxx}());\n" + "! ^\n" |
193 |
| - + "stacktrace: ReferenceError: xxx is not defined\n"; |
194 |
| - assertThat(e.getErrorMessage(), startsWith(t)); |
195 |
| - assertThat(e.getEntity().getStatusCode(), is(500)); |
196 |
| - } |
| 172 | + DefaultEntity entity2 = driver |
| 173 | + .executeScript("var db = require(\"internal\").db; db._drop(\"" + "col-execute-delete-test" + "\")"); |
| 174 | + assertThat(entity2.isError(), is(false)); |
| 175 | + assertThat(entity2.getCode(), is(200)); |
| 176 | + assertThat(entity2.getStatusCode(), is(200)); |
197 | 177 |
|
198 |
| - } |
| 178 | + try { |
| 179 | + driver.getCollection("col-execute-delete-test"); |
| 180 | + fail(); |
| 181 | + } catch (ArangoException e) { |
| 182 | + assertThat(e.getCode(), is(404)); |
| 183 | + assertThat(e.getErrorNumber(), is(1203)); |
| 184 | + } |
| 185 | + } |
| 186 | + |
| 187 | + @Test |
| 188 | + public void test_execute_error() throws ArangoException { |
| 189 | + try { |
| 190 | + driver.executeScript("xxx"); |
| 191 | + fail(); |
| 192 | + } catch (ArangoException e) { |
| 193 | + String t = "Internal Server Error: JavaScript exception in file 'undefined' at 1,14: ReferenceError: xxx is not defined\n" |
| 194 | + + "!(function() {xxx}());\n" + "! ^\n" |
| 195 | + + "stacktrace: ReferenceError: xxx is not defined\n"; |
| 196 | + assertThat(e.getErrorMessage(), startsWith(t)); |
| 197 | + assertThat(e.getEntity().getStatusCode(), is(500)); |
| 198 | + } |
| 199 | + |
| 200 | + } |
199 | 201 |
|
200 | 202 | }
|
0 commit comments