Skip to content

Commit 4f7cfce

Browse files
author
Mark
committed
Transaction: add attribute allowImplicit
1 parent b029b51 commit 4f7cfce

File tree

2 files changed

+65
-2
lines changed

2 files changed

+65
-2
lines changed

src/main/java/com/arangodb/entity/TransactionEntity.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,19 @@ public class TransactionEntity extends BaseEntity {
2727

2828
public static class ReadWriteCollections {
2929

30-
List<String> read = new ArrayList<String>();
30+
private List<String> read = new ArrayList<String>();
3131

32-
List<String> write = new ArrayList<String>();
32+
private List<String> write = new ArrayList<String>();
33+
34+
private boolean allowImplicit = true;
35+
36+
public boolean isAllowImplicit() {
37+
return allowImplicit;
38+
}
39+
40+
public void setAllowImplicit(boolean allowImplicit) {
41+
this.allowImplicit = allowImplicit;
42+
}
3343
}
3444

3545
ReadWriteCollections collections = new ReadWriteCollections();
@@ -62,6 +72,15 @@ public void addWriteCollection(String collection) {
6272
this.collections.write.add(collection);
6373
}
6474

75+
/**
76+
* @param allowImplicit
77+
* allows(true)/ disallows(false) read access to other
78+
* collections than specified. Default is true.
79+
*/
80+
public void setAllowImplicit(final boolean allowImplicit) {
81+
collections.setAllowImplicit(allowImplicit);
82+
}
83+
6584
public String getAction() {
6685
return action;
6786
}

src/test/java/com/arangodb/ArangoDriverTransactionTest.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
import static org.junit.Assert.assertThat;
2121

2222
import org.junit.After;
23+
import org.junit.Assert;
2324
import org.junit.Before;
2425
import org.junit.Test;
2526

27+
import com.arangodb.entity.BaseEntity;
2628
import com.arangodb.entity.TransactionEntity;
2729
import com.arangodb.entity.TransactionResultEntity;
2830

@@ -33,6 +35,7 @@
3335
public 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

Comments
 (0)