Skip to content

Commit 6a162c0

Browse files
author
a-brandt
committed
added examples for new AQL traversal functions (since ArangoDB 2.8)
1 parent 6c15af8 commit 6a162c0

File tree

9 files changed

+453
-47
lines changed

9 files changed

+453
-47
lines changed

src/test/java/com/arangodb/ArangoDriverDocumentCursorTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.arangodb.entity.QueryCachePropertiesEntity;
3333
import com.arangodb.util.AqlQueryOptions;
3434
import com.arangodb.util.MapBuilder;
35+
import com.arangodb.util.TestUtils;
3536

3637
/**
3738
* @author tamtam180 - kirscheless at gmail.com
@@ -154,7 +155,7 @@ public void test3_BatchSize5() throws ArangoException {
154155

155156
@Test
156157
public void test_withCache() throws ArangoException {
157-
if (isMinimumVersion(VERSION_2_7)) {
158+
if (isMinimumVersion(TestUtils.VERSION_2_7)) {
158159
// start caching
159160
QueryCachePropertiesEntity properties = new QueryCachePropertiesEntity();
160161
properties.setMode("on");

src/test/java/com/arangodb/ArangoDriverQueryCacheTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import com.arangodb.entity.DefaultEntity;
2626
import com.arangodb.entity.QueryCachePropertiesEntity;
27+
import com.arangodb.util.TestUtils;
2728

2829
/**
2930
* @author tamtam180 - kirscheless at gmail.com
@@ -41,7 +42,7 @@ public void setup() throws ArangoException {
4142

4243
@Test
4344
public void test_deleteQueryCache() throws ArangoException {
44-
if (isMinimumVersion(VERSION_2_7)) {
45+
if (isMinimumVersion(TestUtils.VERSION_2_7)) {
4546
DefaultEntity ret = driver.deleteQueryCache();
4647
assertEquals(200, ret.getStatusCode());
4748
assertEquals(200, ret.getCode());
@@ -51,7 +52,7 @@ public void test_deleteQueryCache() throws ArangoException {
5152

5253
@Test
5354
public void test_getQueryCacheProperties() throws ArangoException {
54-
if (isMinimumVersion(VERSION_2_7)) {
55+
if (isMinimumVersion(TestUtils.VERSION_2_7)) {
5556
QueryCachePropertiesEntity ret = driver.getQueryCacheProperties();
5657
assertEquals(200, ret.getStatusCode());
5758
assertNotNull(ret.getMode());
@@ -64,7 +65,7 @@ public void test_setQueryCacheProperties() throws ArangoException {
6465
String on = "on";
6566
String off = "off";
6667

67-
if (isMinimumVersion(VERSION_2_7)) {
68+
if (isMinimumVersion(TestUtils.VERSION_2_7)) {
6869
QueryCachePropertiesEntity properties = new QueryCachePropertiesEntity();
6970
properties.setMode(on);
7071
properties.setMaxResults(100L);

src/test/java/com/arangodb/BaseTest.java

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.junit.runners.Parameterized.Parameters;
2828

2929
import com.arangodb.entity.ArangoVersion;
30+
import com.arangodb.util.TestUtils;
3031

3132
/**
3233
* @author tamtam180 - kirscheless at gmail.com
@@ -35,8 +36,6 @@
3536
@RunWith(Parameterized.class)
3637
public abstract class BaseTest {
3738

38-
protected static final String VERSION_2_7 = "2.7";
39-
4039
protected static final String DATABASE_NAME = "unitTestDatabase";
4140

4241
protected static ArangoConfigure configure;
@@ -108,47 +107,8 @@ public static void __shutdown() {
108107

109108
public boolean isMinimumVersion(String version) throws ArangoException {
110109
ArangoVersion ver = driver.getVersion();
111-
int b = compareVersion(ver.getVersion(), version);
110+
int b = TestUtils.compareVersion(ver.getVersion(), version);
112111
return b > -1;
113112
}
114113

115-
private int compareVersion(String version1, String version2) {
116-
String[] v1s = version1.split("\\.");
117-
String[] v2s = version2.split("\\.");
118-
119-
int minLength = Math.min(v1s.length, v2s.length);
120-
int i = 0;
121-
for (; i < minLength; i++) {
122-
int i1 = getIntegerValueOfString(v1s[i]);
123-
int i2 = getIntegerValueOfString(v2s[i]);
124-
if (i1 > i2)
125-
return 1;
126-
else if (i1 < i2)
127-
return -1;
128-
}
129-
int sum1 = 0;
130-
for (int j = 0; j < v1s.length; j++) {
131-
sum1 += getIntegerValueOfString(v1s[j]);
132-
}
133-
int sum2 = 0;
134-
for (int j = 0; j < v2s.length; j++) {
135-
sum2 += getIntegerValueOfString(v2s[j]);
136-
}
137-
if (sum1 == sum2)
138-
return 0;
139-
return v1s.length > v2s.length ? 1 : -1;
140-
}
141-
142-
private int getIntegerValueOfString(String str) {
143-
try {
144-
return Integer.valueOf(str);
145-
} catch (NumberFormatException e) {
146-
if (str.contains("-")) {
147-
str = str.substring(0, str.indexOf('-'));
148-
return Integer.valueOf(str);
149-
}
150-
}
151-
return 0;
152-
}
153-
154114
}

src/test/java/com/arangodb/example/graph/BaseExample.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@
2424
import com.arangodb.ArangoConfigure;
2525
import com.arangodb.ArangoDriver;
2626
import com.arangodb.ArangoException;
27+
import com.arangodb.entity.ArangoVersion;
2728
import com.arangodb.entity.BooleanResultEntity;
2829
import com.arangodb.entity.CollectionEntity;
2930
import com.arangodb.entity.CollectionOptions;
3031
import com.arangodb.entity.CollectionType;
3132
import com.arangodb.entity.EdgeDefinitionEntity;
3233
import com.arangodb.entity.GraphEntity;
34+
import com.arangodb.util.TestUtils;
3335

3436
public class BaseExample {
3537

@@ -154,4 +156,10 @@ public void createGraph(
154156
Assert.assertEquals(grapName, createGraph.getName());
155157
}
156158

159+
public boolean isMinimumVersion(ArangoDriver arangoDriver, String version) throws ArangoException {
160+
ArangoVersion ver = arangoDriver.getVersion();
161+
int b = TestUtils.compareVersion(ver.getVersion(), version);
162+
return b > -1;
163+
}
164+
157165
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Copyright (C) 2015 ArangoDB GmbH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.arangodb.example.graph;
18+
19+
import com.arangodb.entity.BaseDocument;
20+
import com.google.gson.annotations.SerializedName;
21+
22+
/**
23+
* A person class.
24+
*
25+
* The document person class has attributes to store the document key, id and
26+
* revision.
27+
*
28+
* @author a-brandt
29+
*
30+
*/
31+
public class Circle {
32+
33+
@SerializedName(BaseDocument.ID)
34+
private String documentHandle;
35+
36+
@SerializedName(BaseDocument.KEY)
37+
private String documentKey;
38+
39+
@SerializedName(BaseDocument.REV)
40+
private Long documentRevision;
41+
42+
private String label;
43+
44+
public Circle() {
45+
46+
}
47+
48+
public Circle(String documentKey, String label) {
49+
this.documentKey = documentKey;
50+
this.label = label;
51+
}
52+
53+
public String getLabel() {
54+
return label;
55+
}
56+
57+
public void setLabel(String label) {
58+
this.label = label;
59+
}
60+
61+
public String getDocumentHandle() {
62+
return documentHandle;
63+
}
64+
65+
public void setDocumentHandle(String documentHandle) {
66+
this.documentHandle = documentHandle;
67+
}
68+
69+
public String getDocumentKey() {
70+
return documentKey;
71+
}
72+
73+
public void setDocumentKey(String documentKey) {
74+
this.documentKey = documentKey;
75+
}
76+
77+
public Long getDocumentRevision() {
78+
return documentRevision;
79+
}
80+
81+
public void setDocumentRevision(Long documentRevision) {
82+
this.documentRevision = documentRevision;
83+
}
84+
85+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
* Copyright (C) 2015 ArangoDB GmbH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.arangodb.example.graph;
18+
19+
import com.arangodb.entity.BaseDocument;
20+
import com.google.gson.annotations.SerializedName;
21+
22+
public class CircleEdge {
23+
24+
@SerializedName(BaseDocument.ID)
25+
private String documentHandle;
26+
27+
@SerializedName(BaseDocument.KEY)
28+
private String documentKey;
29+
30+
@SerializedName(BaseDocument.REV)
31+
private long documentRevision;
32+
33+
@SerializedName(BaseDocument.FROM)
34+
String fromVertexHandle;
35+
36+
@SerializedName(BaseDocument.TO)
37+
String toVertexHandle;
38+
39+
private Boolean theFalse;
40+
private Boolean theTruth;
41+
private String label;
42+
43+
public CircleEdge() {
44+
}
45+
46+
public CircleEdge(Boolean theFalse, Boolean theTruth, String label) {
47+
this.theFalse = theFalse;
48+
this.theTruth = theTruth;
49+
this.label = label;
50+
}
51+
52+
public Boolean getTheFalse() {
53+
return theFalse;
54+
}
55+
56+
public void setTheFalse(Boolean theFalse) {
57+
this.theFalse = theFalse;
58+
}
59+
60+
public Boolean getTheTruth() {
61+
return theTruth;
62+
}
63+
64+
public void setTheTruth(Boolean theTruth) {
65+
this.theTruth = theTruth;
66+
}
67+
68+
public String getLabel() {
69+
return label;
70+
}
71+
72+
public void setLabel(String label) {
73+
this.label = label;
74+
}
75+
76+
public String getDocumentHandle() {
77+
return documentHandle;
78+
}
79+
80+
public void setDocumentHandle(String documentHandle) {
81+
this.documentHandle = documentHandle;
82+
}
83+
84+
public String getDocumentKey() {
85+
return documentKey;
86+
}
87+
88+
public void setDocumentKey(String documentKey) {
89+
this.documentKey = documentKey;
90+
}
91+
92+
public long getDocumentRevision() {
93+
return documentRevision;
94+
}
95+
96+
public void setDocumentRevision(long documentRevision) {
97+
this.documentRevision = documentRevision;
98+
}
99+
100+
public String getFromVertexHandle() {
101+
return fromVertexHandle;
102+
}
103+
104+
public String getToVertexHandle() {
105+
return toVertexHandle;
106+
}
107+
108+
public void setFromVertexHandle(String fromVertexHandle) {
109+
this.fromVertexHandle = fromVertexHandle;
110+
}
111+
112+
public void setToVertexHandle(String toVertexHandle) {
113+
this.toVertexHandle = toVertexHandle;
114+
}
115+
116+
}

0 commit comments

Comments
 (0)