Skip to content

Commit a2b947e

Browse files
committed
tests refactoring
1 parent ae1cb39 commit a2b947e

17 files changed

+1374
-2597
lines changed

src/test/java/com/arangodb/springframework/AbstractTxTest.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,32 @@
11
package com.arangodb.springframework;
22

3+
import com.arangodb.model.AqlQueryOptions;
34
import com.arangodb.model.DocumentCreateOptions;
45
import com.arangodb.model.DocumentReadOptions;
56
import com.arangodb.model.StreamTransactionOptions;
6-
import com.arangodb.springframework.core.mapping.testdata.BasicEdgeLazyTestEntity;
7-
import com.arangodb.springframework.core.mapping.testdata.BasicEdgeTestEntity;
8-
import com.arangodb.springframework.core.mapping.testdata.BasicTestEntity;
97
import org.junit.jupiter.api.AfterEach;
108
import org.junit.jupiter.api.BeforeEach;
119

12-
import java.util.ArrayList;
1310
import java.util.Arrays;
14-
import java.util.Collections;
1511

1612
public abstract class AbstractTxTest extends AbstractArangoTest {
1713
protected String tx;
18-
protected DocumentCreateOptions insertOpts;
19-
protected DocumentReadOptions findOpts;
20-
21-
private static Class<?>[] enrichCollections(final Class<?>... collections) {
22-
ArrayList<Class<?>> classes = new ArrayList<>();
23-
Collections.addAll(classes, collections);
24-
classes.add(BasicTestEntity.class);
25-
classes.add(BasicEdgeTestEntity.class);
26-
classes.add(BasicEdgeLazyTestEntity.class);
27-
return classes.toArray(new Class[0]);
28-
}
29-
30-
protected AbstractTxTest(final Class<?>... collections) {
31-
super(enrichCollections(collections));
14+
protected final DocumentCreateOptions insertOpts = new DocumentCreateOptions();
15+
protected final DocumentReadOptions findOpts = new DocumentReadOptions();
16+
protected final AqlQueryOptions queryOpts = new AqlQueryOptions();
17+
private final boolean withinTx;
18+
19+
protected AbstractTxTest(boolean withinTx, Class<?>... collections) {
20+
super(collections);
21+
this.withinTx = withinTx;
3222
}
3323

3424
@BeforeEach
3525
void beginTx() {
26+
if (!withinTx) {
27+
return;
28+
}
29+
3630
String[] txCols = Arrays.stream(collections)
3731
.map(it -> template.collection(it).name())
3832
.toArray(String[]::new);
@@ -42,12 +36,18 @@ void beginTx() {
4236
.writeCollections(txCols)
4337
).getId();
4438

45-
insertOpts = new DocumentCreateOptions().streamTransactionId(tx);
46-
findOpts = new DocumentReadOptions().streamTransactionId(tx);
39+
insertOpts.streamTransactionId(tx);
40+
findOpts.streamTransactionId(tx);
41+
queryOpts
42+
.streamTransactionId(tx)
43+
.batchSize(1);
4744
}
4845

4946
@AfterEach
5047
void abortTx() {
48+
if (!withinTx) {
49+
return;
50+
}
5151
db.abortStreamTransaction(tx);
5252
}
5353

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.arangodb.springframework.core.mapping;
2+
3+
import com.arangodb.springframework.AbstractTxTest;
4+
import com.arangodb.springframework.core.mapping.testdata.BasicEdgeLazyTestEntity;
5+
import com.arangodb.springframework.core.mapping.testdata.BasicEdgeTestEntity;
6+
import com.arangodb.springframework.core.mapping.testdata.BasicTestEntity;
7+
8+
import java.util.ArrayList;
9+
import java.util.Collections;
10+
11+
public class AbstractMappingTxTestAbstract extends AbstractTxTest {
12+
13+
private static Class<?>[] enrichCollections(final Class<?>... collections) {
14+
ArrayList<Class<?>> classes = new ArrayList<>();
15+
Collections.addAll(classes, collections);
16+
classes.add(BasicTestEntity.class);
17+
classes.add(BasicEdgeTestEntity.class);
18+
classes.add(BasicEdgeLazyTestEntity.class);
19+
return classes.toArray(new Class[0]);
20+
}
21+
22+
public AbstractMappingTxTestAbstract(boolean withinTx, final Class<?>... collections) {
23+
super(withinTx, enrichCollections(collections));
24+
}
25+
26+
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/*
2+
* DISCLAIMER
3+
*
4+
* Copyright 2018 ArangoDB GmbH, Cologne, Germany
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
*/
20+
21+
package com.arangodb.springframework.core.mapping;
22+
23+
import com.arangodb.springframework.annotation.From;
24+
import com.arangodb.springframework.annotation.To;
25+
import com.arangodb.springframework.core.mapping.testdata.BasicEdgeLazyTestEntity;
26+
import com.arangodb.springframework.core.mapping.testdata.BasicEdgeTestEntity;
27+
import com.arangodb.springframework.core.mapping.testdata.BasicTestEntity;
28+
import org.junit.jupiter.api.Test;
29+
30+
import static org.hamcrest.MatcherAssert.assertThat;
31+
import static org.hamcrest.Matchers.is;
32+
import static org.hamcrest.Matchers.notNullValue;
33+
34+
/**
35+
* @author Mark Vollmary
36+
*
37+
*/
38+
abstract class EdgeMapping extends AbstractMappingTxTestAbstract {
39+
40+
EdgeMapping(boolean withinTx) {
41+
super(withinTx, EdgeMapping.class.getDeclaredClasses());
42+
}
43+
44+
@Test
45+
public void edgeFromTo() {
46+
final BasicTestEntity e1 = new BasicTestEntity();
47+
template.insert(e1, insertOpts);
48+
final BasicTestEntity e2 = new BasicTestEntity();
49+
template.insert(e2, insertOpts);
50+
final BasicEdgeTestEntity e0 = new BasicEdgeTestEntity(e1, e2);
51+
template.insert(e0, insertOpts);
52+
final BasicEdgeTestEntity document = template.find(e0.id, BasicEdgeTestEntity.class, findOpts).get();
53+
assertThat(document, is(notNullValue()));
54+
assertThat(document.getFrom(), is(notNullValue()));
55+
assertThat(document.getFrom().getId(), is(e1.getId()));
56+
assertThat(document.getTo(), is(notNullValue()));
57+
assertThat(document.getTo().getId(), is(e2.getId()));
58+
}
59+
60+
@Test
61+
public void edgeFromToLazy() {
62+
final BasicTestEntity e1 = new BasicTestEntity();
63+
template.insert(e1, insertOpts);
64+
final BasicTestEntity e2 = new BasicTestEntity();
65+
template.insert(e2, insertOpts);
66+
final BasicEdgeLazyTestEntity e0 = new BasicEdgeLazyTestEntity(e1, e2);
67+
template.insert(e0, insertOpts);
68+
final BasicEdgeLazyTestEntity document = template.find(e0.id, BasicEdgeLazyTestEntity.class, findOpts).get();
69+
assertThat(document, is(notNullValue()));
70+
assertThat(document.getFrom(), is(notNullValue()));
71+
assertThat(document.getFrom().getId(), is(e1.getId()));
72+
assertThat(document.getTo(), is(notNullValue()));
73+
assertThat(document.getTo().getId(), is(e2.getId()));
74+
}
75+
76+
public static class EdgeConstructorWithFromToParamsTestEntity extends BasicEdgeTestEntity {
77+
@From
78+
private final BasicTestEntity from;
79+
@To
80+
private final BasicTestEntity to;
81+
82+
public EdgeConstructorWithFromToParamsTestEntity(final BasicTestEntity from, final BasicTestEntity to) {
83+
super();
84+
this.from = from;
85+
this.to = to;
86+
}
87+
}
88+
89+
@Test
90+
public void edgeConstructorWithFromToParams() {
91+
final BasicTestEntity from = new BasicTestEntity();
92+
final BasicTestEntity to = new BasicTestEntity();
93+
template.insert(from, insertOpts);
94+
template.insert(to, insertOpts);
95+
final EdgeConstructorWithFromToParamsTestEntity edge = new EdgeConstructorWithFromToParamsTestEntity(from, to);
96+
template.insert(edge, insertOpts);
97+
final EdgeConstructorWithFromToParamsTestEntity document = template
98+
.find(edge.id, EdgeConstructorWithFromToParamsTestEntity.class, findOpts).get();
99+
assertThat(document, is(notNullValue()));
100+
assertThat(document.from.id, is(from.id));
101+
assertThat(document.to.id, is(to.id));
102+
}
103+
104+
public static class EdgeConstructorWithFromToLazyParamsTestEntity extends BasicEdgeTestEntity {
105+
@From
106+
private final BasicTestEntity from;
107+
@To
108+
private final BasicTestEntity to;
109+
110+
public EdgeConstructorWithFromToLazyParamsTestEntity(final BasicTestEntity from, final BasicTestEntity to) {
111+
super();
112+
this.from = from;
113+
this.to = to;
114+
}
115+
}
116+
117+
@Test
118+
public void edgeConstructorWithFromToLazyParams() {
119+
final BasicTestEntity from = new BasicTestEntity();
120+
final BasicTestEntity to = new BasicTestEntity();
121+
template.insert(from, insertOpts);
122+
template.insert(to, insertOpts);
123+
final EdgeConstructorWithFromToLazyParamsTestEntity edge = new EdgeConstructorWithFromToLazyParamsTestEntity(
124+
from, to);
125+
template.insert(edge, insertOpts);
126+
final EdgeConstructorWithFromToLazyParamsTestEntity document = template
127+
.find(edge.id, EdgeConstructorWithFromToLazyParamsTestEntity.class, findOpts).get();
128+
assertThat(document, is(notNullValue()));
129+
assertThat(document.from.getId(), is(from.id));
130+
assertThat(document.to.getId(), is(to.id));
131+
}
132+
133+
}
Lines changed: 4 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -1,131 +1,7 @@
1-
/*
2-
* DISCLAIMER
3-
*
4-
* Copyright 2018 ArangoDB GmbH, Cologne, Germany
5-
*
6-
* Licensed under the Apache License, Version 2.0 (the "License");
7-
* you may not use this file except in compliance with the License.
8-
* You may obtain a copy of the License at
9-
*
10-
* http://www.apache.org/licenses/LICENSE-2.0
11-
*
12-
* Unless required by applicable law or agreed to in writing, software
13-
* distributed under the License is distributed on an "AS IS" BASIS,
14-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15-
* See the License for the specific language governing permissions and
16-
* limitations under the License.
17-
*
18-
* Copyright holder is ArangoDB GmbH, Cologne, Germany
19-
*/
20-
211
package com.arangodb.springframework.core.mapping;
222

23-
import static org.hamcrest.MatcherAssert.assertThat;
24-
import static org.hamcrest.Matchers.is;
25-
import static org.hamcrest.Matchers.notNullValue;
26-
27-
import org.junit.jupiter.api.Test;
28-
29-
import com.arangodb.springframework.AbstractArangoTest;
30-
import com.arangodb.springframework.annotation.From;
31-
import com.arangodb.springframework.annotation.To;
32-
import com.arangodb.springframework.core.mapping.testdata.BasicEdgeLazyTestEntity;
33-
import com.arangodb.springframework.core.mapping.testdata.BasicEdgeTestEntity;
34-
import com.arangodb.springframework.core.mapping.testdata.BasicTestEntity;
35-
36-
/**
37-
* @author Mark Vollmary
38-
*
39-
*/
40-
public class EdgeMappingTest extends AbstractArangoTest {
41-
42-
@Test
43-
public void edgeFromTo() {
44-
final BasicTestEntity e1 = new BasicTestEntity();
45-
template.insert(e1);
46-
final BasicTestEntity e2 = new BasicTestEntity();
47-
template.insert(e2);
48-
final BasicEdgeTestEntity e0 = new BasicEdgeTestEntity(e1, e2);
49-
template.insert(e0);
50-
final BasicEdgeTestEntity document = template.find(e0.id, BasicEdgeTestEntity.class).get();
51-
assertThat(document, is(notNullValue()));
52-
assertThat(document.getFrom(), is(notNullValue()));
53-
assertThat(document.getFrom().getId(), is(e1.getId()));
54-
assertThat(document.getTo(), is(notNullValue()));
55-
assertThat(document.getTo().getId(), is(e2.getId()));
56-
}
57-
58-
@Test
59-
public void edgeFromToLazy() {
60-
final BasicTestEntity e1 = new BasicTestEntity();
61-
template.insert(e1);
62-
final BasicTestEntity e2 = new BasicTestEntity();
63-
template.insert(e2);
64-
final BasicEdgeLazyTestEntity e0 = new BasicEdgeLazyTestEntity(e1, e2);
65-
template.insert(e0);
66-
final BasicEdgeLazyTestEntity document = template.find(e0.id, BasicEdgeLazyTestEntity.class).get();
67-
assertThat(document, is(notNullValue()));
68-
assertThat(document.getFrom(), is(notNullValue()));
69-
assertThat(document.getFrom().getId(), is(e1.getId()));
70-
assertThat(document.getTo(), is(notNullValue()));
71-
assertThat(document.getTo().getId(), is(e2.getId()));
72-
}
73-
74-
public static class EdgeConstructorWithFromToParamsTestEntity extends BasicEdgeTestEntity {
75-
@From
76-
private final BasicTestEntity from;
77-
@To
78-
private final BasicTestEntity to;
79-
80-
public EdgeConstructorWithFromToParamsTestEntity(final BasicTestEntity from, final BasicTestEntity to) {
81-
super();
82-
this.from = from;
83-
this.to = to;
84-
}
85-
}
86-
87-
@Test
88-
public void edgeConstructorWithFromToParams() {
89-
final BasicTestEntity from = new BasicTestEntity();
90-
final BasicTestEntity to = new BasicTestEntity();
91-
template.insert(from);
92-
template.insert(to);
93-
final EdgeConstructorWithFromToParamsTestEntity edge = new EdgeConstructorWithFromToParamsTestEntity(from, to);
94-
template.insert(edge);
95-
final EdgeConstructorWithFromToParamsTestEntity document = template
96-
.find(edge.id, EdgeConstructorWithFromToParamsTestEntity.class).get();
97-
assertThat(document, is(notNullValue()));
98-
assertThat(document.from.id, is(from.id));
99-
assertThat(document.to.id, is(to.id));
100-
}
101-
102-
public static class EdgeConstructorWithFromToLazyParamsTestEntity extends BasicEdgeTestEntity {
103-
@From
104-
private final BasicTestEntity from;
105-
@To
106-
private final BasicTestEntity to;
107-
108-
public EdgeConstructorWithFromToLazyParamsTestEntity(final BasicTestEntity from, final BasicTestEntity to) {
109-
super();
110-
this.from = from;
111-
this.to = to;
112-
}
113-
}
114-
115-
@Test
116-
public void edgeConstructorWithFromToLazyParams() {
117-
final BasicTestEntity from = new BasicTestEntity();
118-
final BasicTestEntity to = new BasicTestEntity();
119-
template.insert(from);
120-
template.insert(to);
121-
final EdgeConstructorWithFromToLazyParamsTestEntity edge = new EdgeConstructorWithFromToLazyParamsTestEntity(
122-
from, to);
123-
template.insert(edge);
124-
final EdgeConstructorWithFromToLazyParamsTestEntity document = template
125-
.find(edge.id, EdgeConstructorWithFromToLazyParamsTestEntity.class).get();
126-
assertThat(document, is(notNullValue()));
127-
assertThat(document.from.getId(), is(from.id));
128-
assertThat(document.to.getId(), is(to.id));
129-
}
130-
3+
public class EdgeMappingTest extends EdgeMapping {
4+
EdgeMappingTest() {
5+
super(false);
6+
}
1317
}

0 commit comments

Comments
 (0)