2424
2525import java .util .Collections ;
2626
27+ import org .junit .AfterClass ;
2728import org .junit .Before ;
2829import org .junit .Test ;
2930
3738 */
3839public class ArangoDriverDatabaseTest extends BaseTest {
3940
40- public ArangoDriverDatabaseTest (ArangoConfigure configure , ArangoDriver driver ) {
41+ private static final String DB_NAME = "abcdefghi1abcdefghi2abcdefghi3abcdefghi4abcdefghi5abcdefghi61234" ;
42+ private static final String [] DATABASES = new String [] { "db-1" , "db_2" , "db-_-3" , "mydb" , // other
43+ // testcase
44+ "mydb2" , // other testcase
45+ "repl_scenario_test1" , // other test case
46+ "unitTestDatabase" , // other test case
47+ };
48+
49+ public ArangoDriverDatabaseTest (final ArangoConfigure configure , final ArangoDriver driver ) {
4150 super (configure , driver );
4251 }
4352
@@ -46,12 +55,26 @@ public void before() {
4655
4756 }
4857
58+ @ AfterClass
59+ public static void _afterClass () {
60+ try {
61+ driver .deleteDatabase (DB_NAME );
62+ } catch (final ArangoException e ) {
63+ }
64+ for (final String database : DATABASES ) {
65+ try {
66+ driver .deleteDatabase (database );
67+ } catch (final ArangoException e ) {
68+ }
69+ }
70+ }
71+
4972 @ Test
5073 public void test_invalid_dbname1 () throws ArangoException {
5174 try {
5275 driver .createDatabase (null );
5376 fail ();
54- } catch (ArangoException e ) {
77+ } catch (final ArangoException e ) {
5578 assertThat (e .getMessage (), is ("invalid format database:null" ));
5679 }
5780 }
@@ -61,7 +84,7 @@ public void test_invalid_dbname2() throws ArangoException {
6184 try {
6285 driver .createDatabase ("0" );
6386 fail ();
64- } catch (ArangoException e ) {
87+ } catch (final ArangoException e ) {
6588 assertThat (e .getMessage (), is ("invalid format database:0" ));
6689 }
6790 }
@@ -71,7 +94,7 @@ public void test_invalid_dbname3() throws ArangoException {
7194 try {
7295 driver .createDatabase ("abcdefghi1abcdefghi2abcdefghi3abcdefghi4abcdefghi5abcdefghi612345" ); // len=65
7396 fail ();
74- } catch (ArangoException e ) {
97+ } catch (final ArangoException e ) {
7598 assertThat (e .getMessage (),
7699 is ("invalid format database:abcdefghi1abcdefghi2abcdefghi3abcdefghi4abcdefghi5abcdefghi612345" ));
77100 }
@@ -82,7 +105,7 @@ public void test_invalid_dbname_for_delete() throws ArangoException {
82105 try {
83106 driver .deleteDatabase ("abcdefghi1abcdefghi2abcdefghi3abcdefghi4abcdefghi5abcdefghi612345" ); // len=65
84107 fail ();
85- } catch (ArangoException e ) {
108+ } catch (final ArangoException e ) {
86109 assertThat (e .getMessage (),
87110 is ("invalid format database:abcdefghi1abcdefghi2abcdefghi3abcdefghi4abcdefghi5abcdefghi612345" ));
88111 }
@@ -91,7 +114,7 @@ public void test_invalid_dbname_for_delete() throws ArangoException {
91114 @ Test
92115 public void test_current_database () throws ArangoException {
93116
94- DatabaseEntity entity = driver .getCurrentDatabase ();
117+ final DatabaseEntity entity = driver .getCurrentDatabase ();
95118 assertThat (entity .isError (), is (false ));
96119 assertThat (entity .getCode (), is (200 ));
97120 assertThat (entity .getName (), is ("_system" ));
@@ -104,35 +127,35 @@ public void test_current_database() throws ArangoException {
104127 @ Test
105128 public void test_createDatabase () throws ArangoException {
106129
107- String database = "abcdefghi1abcdefghi2abcdefghi3abcdefghi4abcdefghi5abcdefghi61234" ;
130+ final String database = DB_NAME ;
108131
109132 try {
110133 driver .deleteDatabase (database );
111- } catch (ArangoException e ) {
134+ } catch (final ArangoException e ) {
112135 }
113136
114- BooleanResultEntity entity = driver .createDatabase (database ); // len=64
137+ final BooleanResultEntity entity = driver .createDatabase (database ); // len=64
115138 assertThat (entity .getResult (), is (true ));
116139
117140 }
118141
119142 @ Test
120143 public void test_createDatabase_duplicate () throws ArangoException {
121144
122- String database = "abcdefghi1abcdefghi2abcdefghi3abcdefghi4abcdefghi5abcdefghi61234" ;
145+ final String database = DB_NAME ;
123146
124147 try {
125148 driver .deleteDatabase (database );
126- } catch (ArangoException e ) {
149+ } catch (final ArangoException e ) {
127150 }
128151
129- BooleanResultEntity entity = driver .createDatabase (database ); // len=64
152+ final BooleanResultEntity entity = driver .createDatabase (database ); // len=64
130153 assertThat (entity .getResult (), is (true ));
131154
132155 try {
133156 driver .createDatabase (database );
134157 fail ();
135- } catch (ArangoException e ) {
158+ } catch (final ArangoException e ) {
136159 assertThat (e .getCode (), is (409 ));
137160 assertThat (e .getErrorNumber (), is (1207 ));
138161 }
@@ -142,11 +165,11 @@ public void test_createDatabase_duplicate() throws ArangoException {
142165 @ Test
143166 public void test_delete () throws ArangoException {
144167
145- String database = "abcdefghi1abcdefghi2abcdefghi3abcdefghi4abcdefghi5abcdefghi61234" ;
168+ final String database = DB_NAME ;
146169
147170 try {
148171 driver .deleteDatabase (database );
149- } catch (ArangoException e ) {
172+ } catch (final ArangoException e ) {
150173 }
151174
152175 BooleanResultEntity entity = driver .createDatabase (database ); // len=64
@@ -164,17 +187,17 @@ public void test_delete() throws ArangoException {
164187 @ Test
165188 public void test_delete_404 () throws ArangoException {
166189
167- String database = "abcdefghi1abcdefghi2abcdefghi3abcdefghi4abcdefghi5abcdefghi61234" ;
190+ final String database = DB_NAME ;
168191
169192 try {
170193 driver .deleteDatabase (database );
171- } catch (ArangoException e ) {
194+ } catch (final ArangoException e ) {
172195 }
173196
174197 try {
175198 driver .deleteDatabase (database );
176199 fail ();
177- } catch (ArangoException e ) {
200+ } catch (final ArangoException e ) {
178201 assertThat (e .getCode (), is (404 ));
179202 assertThat (e .getErrorNumber (), is (1228 ));
180203 }
@@ -184,25 +207,18 @@ public void test_delete_404() throws ArangoException {
184207 @ Test
185208 public void test_get_databases () throws ArangoException {
186209
187- String [] databases = new String [] { "db-1" , "db_2" , "db-_-3" , "mydb" , // other
188- // testcase
189- "mydb2" , // other testcase
190- "repl_scenario_test1" , // other test case
191- "unitTestDatabase" , // other test case
192- };
193-
194- for (String database : databases ) {
210+ for (final String database : DATABASES ) {
195211 try {
196212 driver .deleteDatabase (database );
197- } catch (ArangoException e ) {
213+ } catch (final ArangoException e ) {
198214 }
199215 try {
200216 driver .createDatabase (database );
201- } catch (ArangoException e ) {
217+ } catch (final ArangoException e ) {
202218 }
203219 }
204220
205- StringsResultEntity entity = driver .getDatabases ();
221+ final StringsResultEntity entity = driver .getDatabases ();
206222 assertThat (entity .isError (), is (false ));
207223 assertThat (entity .getCode (), is (200 ));
208224
@@ -215,7 +231,6 @@ public void test_get_databases() throws ArangoException {
215231 assertThat (entity .getResult ().indexOf ("mydb2" ), not (-1 ));
216232 assertThat (entity .getResult ().indexOf ("repl_scenario_test1" ), not (-1 ));
217233 assertThat (entity .getResult ().indexOf ("unitTestDatabase" ), not (-1 ));
218-
219234 }
220235
221236}
0 commit comments