2020import static org .junit .Assert .assertThat ;
2121
2222import org .junit .After ;
23+ import org .junit .Assert ;
2324import org .junit .Before ;
2425import org .junit .Test ;
2526
27+ import com .arangodb .entity .BaseEntity ;
2628import com .arangodb .entity .TransactionEntity ;
2729import com .arangodb .entity .TransactionResultEntity ;
2830
3335public class ArangoDriverTransactionTest extends BaseTest {
3436
3537 private static final String SOME_COLLECTION = "someCollection" ;
38+ private static final String SOME_OTHER_COLLECTION = "someOtherCollection" ;
3639
3740 public class ParamObject {
3841 private String a = "a" ;
@@ -77,6 +80,16 @@ public void setup() throws ArangoException {
7780 driver .createCollection (SOME_COLLECTION );
7881 } catch (final ArangoException e ) {
7982
83+ }
84+ try {
85+ driver .deleteCollection (SOME_OTHER_COLLECTION );
86+ } catch (final ArangoException e ) {
87+
88+ }
89+ try {
90+ driver .createCollection (SOME_OTHER_COLLECTION );
91+ } catch (final ArangoException e ) {
92+
8093 }
8194 }
8295
@@ -86,6 +99,11 @@ public void teardown() throws ArangoException {
8699 driver .deleteCollection (SOME_COLLECTION );
87100 } catch (final ArangoException e ) {
88101
102+ }
103+ try {
104+ driver .deleteCollection (SOME_OTHER_COLLECTION );
105+ } catch (final ArangoException e ) {
106+
89107 }
90108 }
91109
@@ -137,4 +155,30 @@ public void test_Transaction() throws ArangoException {
137155
138156 }
139157
158+ @ Test
159+ public void allowImplicit () throws ArangoException {
160+ TransactionEntity transaction = driver
161+ .createTransaction ("function (params) {" + "var db = require('internal').db;"
162+ + "return {'a':db.someCollection.all().toArray()[0], 'b':db.someOtherCollection.all().toArray()[0]};"
163+ + "}" );
164+ transaction .addReadCollection (SOME_COLLECTION );
165+ {
166+ TransactionResultEntity result = driver .executeTransaction (transaction );
167+ assertThat (result .getStatusCode (), is (200 ));
168+ assertThat (result .getCode (), is (200 ));
169+ assertThat (result .isError (), is (false ));
170+ }
171+ {
172+ transaction .setAllowImplicit (false );
173+ try {
174+ driver .executeTransaction (transaction );
175+ Assert .fail ();
176+ } catch (ArangoException e ) {
177+ final BaseEntity result = e .getEntity ();
178+ assertThat (result .getStatusCode (), is (400 ));
179+ assertThat (result .getCode (), is (400 ));
180+ assertThat (result .isError (), is (true ));
181+ }
182+ }
183+ }
140184}
0 commit comments