|
1 | 1 | package com.arangodb.springframework; |
2 | 2 |
|
| 3 | +import com.arangodb.model.DocumentCreateOptions; |
| 4 | +import com.arangodb.model.DocumentReadOptions; |
3 | 5 | import com.arangodb.model.StreamTransactionOptions; |
4 | 6 | import com.arangodb.springframework.core.mapping.testdata.BasicEdgeLazyTestEntity; |
5 | 7 | import com.arangodb.springframework.core.mapping.testdata.BasicEdgeTestEntity; |
6 | 8 | import com.arangodb.springframework.core.mapping.testdata.BasicTestEntity; |
7 | 9 | import org.junit.jupiter.api.AfterEach; |
8 | 10 | import org.junit.jupiter.api.BeforeEach; |
9 | 11 |
|
| 12 | +import java.util.ArrayList; |
10 | 13 | import java.util.Arrays; |
11 | | -import java.util.HashSet; |
12 | | -import java.util.Set; |
| 14 | +import java.util.Collections; |
13 | 15 |
|
14 | 16 | public abstract class AbstractTxTest extends AbstractArangoTest { |
15 | 17 | 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)); |
| 32 | + } |
16 | 33 |
|
17 | 34 | @BeforeEach |
18 | 35 | void beginTx() { |
19 | | - Set<Class<?>> cols = new HashSet<>(Arrays.asList(getClass().getDeclaredClasses())); |
20 | | - cols.add(BasicTestEntity.class); |
21 | | - cols.add(BasicEdgeTestEntity.class); |
22 | | - cols.add(BasicEdgeLazyTestEntity.class); |
23 | | - |
24 | | - String[] txCols = cols.stream() |
| 36 | + String[] txCols = Arrays.stream(collections) |
25 | 37 | .map(it -> template.collection(it).name()) |
26 | 38 | .toArray(String[]::new); |
27 | 39 |
|
28 | 40 | tx = db.beginStreamTransaction(new StreamTransactionOptions() |
29 | 41 | .readCollections(txCols) |
30 | 42 | .writeCollections(txCols) |
31 | 43 | ).getId(); |
| 44 | + |
| 45 | + insertOpts = new DocumentCreateOptions().streamTransactionId(tx); |
| 46 | + findOpts = new DocumentReadOptions().streamTransactionId(tx); |
32 | 47 | } |
33 | 48 |
|
34 | 49 | @AfterEach |
|
0 commit comments