1818
1919import static org .hamcrest .Matchers .is ;
2020import static org .hamcrest .Matchers .not ;
21+ import static org .hamcrest .Matchers .notNullValue ;
22+ import static org .hamcrest .Matchers .nullValue ;
2123import static org .hamcrest .core .StringStartsWith .startsWith ;
2224import static org .junit .Assert .assertFalse ;
2325import static org .junit .Assert .assertThat ;
2628import java .util .List ;
2729import java .util .Map ;
2830
29- import org .junit .Ignore ;
31+ import org .junit .After ;
32+ import org .junit .Before ;
3033import org .junit .Test ;
3134
3235import com .arangodb .entity .CursorEntity ;
4043 */
4144public class ArangoDriverCursorTest extends BaseTest {
4245
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+
4365 @ Test
4466 public void test_validateQuery () throws ArangoException {
4567
@@ -56,7 +78,7 @@ public void test_validateQuery() throws ArangoException {
5678 }
5779
5880 @ Test
59- public void test_validateQuery_400_1 () throws ArangoException {
81+ public void test_validateQuery_400 () throws ArangoException {
6082
6183 // =じゃなくて==じゃないとダメ。文法間違いエラー
6284 try {
@@ -71,22 +93,8 @@ public void test_validateQuery_400_1() throws ArangoException {
7193
7294 }
7395
74- @ Test
75- @ Ignore
76- public void test_validateQuery_400_2 () throws ArangoException {
77- }
78-
7996 @ Test
8097 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-
9098 // テストデータを作る
9199 for (int i = 0 ; i < 100 ; i ++) {
92100 final TestComplexEntity01 value = new TestComplexEntity01 ("user_" + (i % 10 ), "desc" + (i % 10 ), i );
@@ -114,15 +122,6 @@ public void test_executeQuery() throws ArangoException {
114122
115123 @ Test
116124 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-
126125 // テストデータを作る
127126 for (int i = 0 ; i < 100 ; i ++) {
128127 final TestComplexEntity01 value = new TestComplexEntity01 ("user_" + (i % 10 ), "desc" + (i % 10 ), i );
@@ -183,15 +182,6 @@ public void test_executeQuery_2() throws ArangoException {
183182
184183 @ Test
185184 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-
195185 // テストデータを作る
196186 for (int i = 0 ; i < 100 ; i ++) {
197187 final TestComplexEntity01 value = new TestComplexEntity01 ("user_" + (i % 10 ), "desc" + (i % 10 ), i );
@@ -220,15 +210,6 @@ public void test_executeQueryFullCount() throws ArangoException {
220210
221211 @ Test
222212 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-
232213 // テストデータを作る
233214 for (int i = 0 ; i < 100 ; i ++) {
234215 final TestComplexEntity01 value = new TestComplexEntity01 ("user_" + (i % 10 ), "desc" + (i % 10 ), i );
@@ -276,13 +257,6 @@ public void test_executeQueryUniqueResult() throws ArangoException {
276257
277258 @ Test
278259 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-
286260 driver .setDefaultDatabase (null );
287261 final String query = "return _users + 1" ;
288262 final Map <String , Object > bindVars = new HashMap <String , Object >();
@@ -293,4 +267,62 @@ public void test_warning() throws ArangoException {
293267 assertThat (warnings .size (), is (1 ));
294268 }
295269
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+
296328}
0 commit comments