18
18
19
19
import static org .hamcrest .Matchers .is ;
20
20
import static org .hamcrest .Matchers .not ;
21
+ import static org .hamcrest .Matchers .notNullValue ;
22
+ import static org .hamcrest .Matchers .nullValue ;
21
23
import static org .hamcrest .core .StringStartsWith .startsWith ;
22
24
import static org .junit .Assert .assertFalse ;
23
25
import static org .junit .Assert .assertThat ;
26
28
import java .util .List ;
27
29
import java .util .Map ;
28
30
29
- import org .junit .Ignore ;
31
+ import org .junit .After ;
32
+ import org .junit .Before ;
30
33
import org .junit .Test ;
31
34
32
35
import com .arangodb .entity .CursorEntity ;
40
43
*/
41
44
public class ArangoDriverCursorTest extends BaseTest {
42
45
46
+ final static String collectionName = "unit_test_query_test" ;
47
+
48
+ @ Before
49
+ public void setup () throws ArangoException {
50
+ try {
51
+ driver .createCollection (collectionName );
52
+ } catch (final ArangoException e ) {
53
+ }
54
+ driver .truncateCollection (collectionName );
55
+ }
56
+
57
+ @ After
58
+ public void tearDown () {
59
+ try {
60
+ driver .deleteCollection (collectionName );
61
+ } catch (final ArangoException e ) {
62
+ }
63
+ }
64
+
43
65
@ Test
44
66
public void test_validateQuery () throws ArangoException {
45
67
@@ -56,7 +78,7 @@ public void test_validateQuery() throws ArangoException {
56
78
}
57
79
58
80
@ Test
59
- public void test_validateQuery_400_1 () throws ArangoException {
81
+ public void test_validateQuery_400 () throws ArangoException {
60
82
61
83
// =じゃなくて==じゃないとダメ。文法間違いエラー
62
84
try {
@@ -71,22 +93,8 @@ public void test_validateQuery_400_1() throws ArangoException {
71
93
72
94
}
73
95
74
- @ Test
75
- @ Ignore
76
- public void test_validateQuery_400_2 () throws ArangoException {
77
- }
78
-
79
96
@ Test
80
97
public void test_executeQuery () throws ArangoException {
81
-
82
- // Collectionを作る
83
- final String collectionName = "unit_test_query_test" ;
84
- try {
85
- driver .createCollection (collectionName );
86
- } catch (final ArangoException e ) {
87
- }
88
- driver .truncateCollection (collectionName );
89
-
90
98
// テストデータを作る
91
99
for (int i = 0 ; i < 100 ; i ++) {
92
100
final TestComplexEntity01 value = new TestComplexEntity01 ("user_" + (i % 10 ), "desc" + (i % 10 ), i );
@@ -114,15 +122,6 @@ public void test_executeQuery() throws ArangoException {
114
122
115
123
@ Test
116
124
public void test_executeQuery_2 () throws ArangoException {
117
-
118
- // Collectionを作る
119
- final String collectionName = "unit_test_query_test" ;
120
- try {
121
- driver .createCollection (collectionName );
122
- } catch (final ArangoException e ) {
123
- }
124
- driver .truncateCollection (collectionName );
125
-
126
125
// テストデータを作る
127
126
for (int i = 0 ; i < 100 ; i ++) {
128
127
final TestComplexEntity01 value = new TestComplexEntity01 ("user_" + (i % 10 ), "desc" + (i % 10 ), i );
@@ -183,15 +182,6 @@ public void test_executeQuery_2() throws ArangoException {
183
182
184
183
@ Test
185
184
public void test_executeQueryFullCount () throws ArangoException {
186
-
187
- // Collectionを作る
188
- final String collectionName = "unit_test_query_test" ;
189
- try {
190
- driver .createCollection (collectionName );
191
- } catch (final ArangoException e ) {
192
- }
193
- driver .truncateCollection (collectionName );
194
-
195
185
// テストデータを作る
196
186
for (int i = 0 ; i < 100 ; i ++) {
197
187
final TestComplexEntity01 value = new TestComplexEntity01 ("user_" + (i % 10 ), "desc" + (i % 10 ), i );
@@ -220,15 +210,6 @@ public void test_executeQueryFullCount() throws ArangoException {
220
210
221
211
@ Test
222
212
public void test_executeQueryUniqueResult () throws ArangoException {
223
-
224
- // Collectionを作る
225
- final String collectionName = "unit_test_query_test" ;
226
- try {
227
- driver .createCollection (collectionName );
228
- } catch (final ArangoException e ) {
229
- }
230
- driver .truncateCollection (collectionName );
231
-
232
213
// テストデータを作る
233
214
for (int i = 0 ; i < 100 ; i ++) {
234
215
final TestComplexEntity01 value = new TestComplexEntity01 ("user_" + (i % 10 ), "desc" + (i % 10 ), i );
@@ -276,13 +257,6 @@ public void test_executeQueryUniqueResult() throws ArangoException {
276
257
277
258
@ Test
278
259
public void test_warning () throws ArangoException {
279
- final String collectionName = "unit_test_query_test" ;
280
- try {
281
- driver .createCollection (collectionName );
282
- } catch (final ArangoException e ) {
283
- }
284
- driver .truncateCollection (collectionName );
285
-
286
260
driver .setDefaultDatabase (null );
287
261
final String query = "return _users + 1" ;
288
262
final Map <String , Object > bindVars = new HashMap <String , Object >();
@@ -293,4 +267,62 @@ public void test_warning() throws ArangoException {
293
267
assertThat (warnings .size (), is (1 ));
294
268
}
295
269
270
+ @ Test
271
+ public void test_CursorResult_profile () throws ArangoException {
272
+ driver .setDefaultDatabase (null );
273
+ final Map <String , Object > bindVars = new HashMap <String , Object >();
274
+ final AqlQueryOptions aqlQueryOptions = new AqlQueryOptions ();
275
+ {
276
+ // without profiling
277
+ aqlQueryOptions .setProfile (false );
278
+ final String query = "for p in _users return p._key" ;
279
+ final CursorResult <String > cursor = driver .executeAqlQuery (query , bindVars , aqlQueryOptions , String .class );
280
+ Map <String , Object > extra = cursor .getExtra ();
281
+ assertThat (extra , is (notNullValue ()));
282
+ Object object = extra .get ("profile" );
283
+ // extra.profile has to be null
284
+ assertThat (object , is (nullValue ()));
285
+ }
286
+ {
287
+ // with profiling
288
+ aqlQueryOptions .setProfile (true );
289
+ final String query = "for p in _users return p._id" ;
290
+ final CursorResult <String > cursor = driver .executeAqlQuery (query , bindVars , aqlQueryOptions , String .class );
291
+ Map <String , Object > extra = cursor .getExtra ();
292
+ assertThat (extra , is (notNullValue ()));
293
+ Object object = extra .get ("profile" );
294
+ assertThat (object , is (notNullValue ()));
295
+ }
296
+ }
297
+
298
+ @ Test
299
+ public void test_DocumentCursor_profile () throws ArangoException {
300
+ driver .setDefaultDatabase (null );
301
+ final Map <String , Object > bindVars = new HashMap <String , Object >();
302
+ final AqlQueryOptions aqlQueryOptions = new AqlQueryOptions ();
303
+ {
304
+ // without profiling
305
+ aqlQueryOptions .setProfile (false );
306
+ final String query = "for p in _users return p._key" ;
307
+ final DocumentCursor <String > cursor = driver .executeDocumentQuery (query , bindVars , aqlQueryOptions ,
308
+ String .class );
309
+ Map <String , Object > extra = cursor .getExtra ();
310
+ assertThat (extra , is (notNullValue ()));
311
+ Object object = extra .get ("profile" );
312
+ // extra.profile has to be null
313
+ assertThat (object , is (nullValue ()));
314
+ }
315
+ {
316
+ // with profiling
317
+ aqlQueryOptions .setProfile (true );
318
+ final String query = "for p in _users return p._id" ;
319
+ final DocumentCursor <String > cursor = driver .executeDocumentQuery (query , bindVars , aqlQueryOptions ,
320
+ String .class );
321
+ Map <String , Object > extra = cursor .getExtra ();
322
+ assertThat (extra , is (notNullValue ()));
323
+ Object object = extra .get ("profile" );
324
+ assertThat (object , is (notNullValue ()));
325
+ }
326
+ }
327
+
296
328
}
0 commit comments