Skip to content

Commit 4ae9e81

Browse files
committed
repositories tx tests
1 parent a2b947e commit 4ae9e81

19 files changed

+513
-2
lines changed

src/main/java/com/arangodb/springframework/repository/query/ArangoResultConverter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ private GeoResult<T> buildGeoResult(final ArangoJsonNode data) {
160160
private GeoResults<T> buildGeoResults(final ArangoCursor<ArangoJsonNode> cursor) {
161161
final List<GeoResult<T>> list = new LinkedList<>();
162162
cursor.forEachRemaining(o -> list.add(buildGeoResult(o)));
163+
// FIXME: DE-803
164+
// convert geoResults to Metrics.NEUTRAL before
165+
// invoking GeoResults.GeoResults(java.util.List<? extends org.springframework.data.geo.GeoResult<T>>)
163166
return new GeoResults<>(list);
164167
}
165168

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public abstract class AbstractTxTest extends AbstractArangoTest {
1313
protected String tx;
1414
protected final DocumentCreateOptions insertOpts = new DocumentCreateOptions();
1515
protected final DocumentReadOptions findOpts = new DocumentReadOptions();
16-
protected final AqlQueryOptions queryOpts = new AqlQueryOptions();
16+
protected final AqlQueryOptions queryOpts = new AqlQueryOptions().batchSize(1);
1717
private final boolean withinTx;
1818

1919
protected AbstractTxTest(boolean withinTx, Class<?>... collections) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949
@EnableArangoRepositories(basePackages = {
5050
"com.arangodb.springframework.repository",
5151
"com.arangodb.springframework.example.polymorphic.repository",
52-
"com.arangodb.springframework.debug.repository"},
52+
"com.arangodb.springframework.debug.repository",
53+
"com.arangodb.springframework.testdata.chess.repo"},
5354
namedQueriesLocation = "classpath*:arango-named-queries-test.properties")
5455
@EnableArangoAuditing(auditorAwareRef = "auditorProvider")
5556
public class ArangoTestConfiguration implements ArangoConfiguration {
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package com.arangodb.springframework.testdata.chess;
2+
3+
import com.arangodb.springframework.AbstractTxTest;
4+
import com.arangodb.springframework.core.ArangoOperations;
5+
import com.arangodb.springframework.testdata.chess.entity.Player;
6+
import com.arangodb.springframework.testdata.chess.entity.Score;
7+
import com.arangodb.springframework.testdata.chess.entity.Tournament;
8+
import org.junit.jupiter.api.BeforeEach;
9+
import org.springframework.beans.factory.annotation.Autowired;
10+
import org.springframework.data.geo.Point;
11+
12+
import java.time.LocalDate;
13+
import java.util.List;
14+
15+
abstract class AbstractRepositoryTest extends AbstractTxTest {
16+
17+
@Autowired
18+
private ArangoOperations ops;
19+
20+
protected List<Player> players = List.of(
21+
new Player("Magnus Carlsen", 2830, "Norway"),
22+
new Player("Fabiano Caruana", 2803, "US"),
23+
new Player("Maxime Vachier-Lagrave", 2732, "France"),
24+
new Player("Hikaru Nakamura", 2789, "US"),
25+
new Player("Ding Liren", 2762, "China"),
26+
new Player("Wesley So", 2757, "US"),
27+
new Player("Alireza Firouzja", 2760, "France"),
28+
new Player("Anish Giri", 2745, "Netherlands"),
29+
new Player("Ian Nepomniachtchi", 2758, "Russia")
30+
);
31+
32+
protected List<Tournament> tournaments = List.of(
33+
new Tournament(
34+
"Tata Steel 2023",
35+
LocalDate.of(2023, 1, 13),
36+
"Wijk aan Zee",
37+
new Point(4.6, 52.5)
38+
),
39+
new Tournament(
40+
"World Chess Championship 2023",
41+
LocalDate.of(2023, 4, 9),
42+
"Astana",
43+
new Point(71.422222, 51.147222)
44+
),
45+
new Tournament(
46+
"Norway Chess 2023",
47+
LocalDate.of(2023, 5, 30),
48+
"Stavanger",
49+
new Point(5.731389, 58.97)
50+
)
51+
);
52+
53+
protected List<Score> scores = List.of(
54+
new Score(players.get(7), tournaments.get(0), 1),
55+
new Score(players.get(0), tournaments.get(0), 3),
56+
new Score(players.get(5), tournaments.get(0), 4),
57+
new Score(players.get(1), tournaments.get(0), 5),
58+
new Score(players.get(4), tournaments.get(1), 1),
59+
new Score(players.get(8), tournaments.get(1), 2),
60+
new Score(players.get(3), tournaments.get(1), 4),
61+
new Score(players.get(1), tournaments.get(1), 5),
62+
new Score(players.get(6), tournaments.get(1), 6),
63+
new Score(players.get(3), tournaments.get(2), 1),
64+
new Score(players.get(1), tournaments.get(2), 2),
65+
new Score(players.get(7), tournaments.get(2), 4),
66+
new Score(players.get(5), tournaments.get(2), 5),
67+
new Score(players.get(0), tournaments.get(2), 6)
68+
);
69+
70+
protected AbstractRepositoryTest(boolean withinTx) {
71+
super(withinTx, Player.class, Score.class, Tournament.class);
72+
}
73+
74+
@BeforeEach
75+
void importData() {
76+
ops.insertAll(players, insertOpts, Player.class);
77+
ops.insertAll(tournaments, insertOpts, Tournament.class);
78+
ops.insertAll(scores, insertOpts, Score.class);
79+
}
80+
81+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.arangodb.springframework.testdata.chess;
2+
3+
import com.arangodb.springframework.testdata.chess.entity.*;
4+
import com.arangodb.springframework.testdata.chess.repo.PlayerRepository;
5+
import org.junit.jupiter.api.Test;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.data.domain.Page;
8+
import org.springframework.data.domain.PageRequest;
9+
10+
import java.util.Comparator;
11+
import java.util.List;
12+
13+
import static org.assertj.core.api.Assertions.assertThat;
14+
15+
abstract class PlayerRepositoryAbstract extends AbstractRepositoryTest {
16+
17+
@Autowired
18+
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
19+
PlayerRepository repo;
20+
21+
PlayerRepositoryAbstract(boolean withinTx) {
22+
super(withinTx);
23+
}
24+
25+
@Test
26+
void findAllByCountry() {
27+
List<Player> expected = players.stream()
28+
.filter(it -> "US".equals(it.getCountry()))
29+
.toList();
30+
Iterable<Player> found = repo.findAllByCountry("US", queryOpts);
31+
assertThat(found).containsExactlyInAnyOrderElementsOf(expected);
32+
found.forEach(this::checkRefs);
33+
}
34+
35+
@Test
36+
void findAllByRatingGreaterThan() {
37+
int rating = 2780;
38+
List<Player> expected = players.stream()
39+
.filter(it -> it.getRating() > rating)
40+
.sorted(Comparator.comparingInt(Player::getRating).reversed())
41+
.toList();
42+
43+
for (int i = 0; i < expected.size(); i++) {
44+
Page<Player> page = repo.findAllByRatingGreaterThanOrderByRatingDesc(PageRequest.of(i, 1), rating, queryOpts);
45+
assertThat(page.getTotalElements()).isEqualTo(expected.size());
46+
assertThat(page.getTotalPages()).isEqualTo(expected.size());
47+
Player current = page.iterator().next();
48+
assertThat(current).isEqualTo(expected.get(i));
49+
checkRefs(current);
50+
}
51+
}
52+
53+
private void checkRefs(Player p) {
54+
List<Score> expectedScores = scores.stream()
55+
.filter(it -> it.player().equals(p))
56+
.toList();
57+
assertThat(p.getScores()).containsExactlyInAnyOrderElementsOf(expectedScores);
58+
59+
List<Tournament> expectedTournaments = expectedScores.stream()
60+
.map(Score::tournament)
61+
.toList();
62+
assertThat(p.getTournaments()).containsExactlyInAnyOrderElementsOf(expectedTournaments);
63+
}
64+
65+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.arangodb.springframework.testdata.chess;
2+
3+
public class PlayerRepositoryTest extends PlayerRepositoryAbstract {
4+
PlayerRepositoryTest() {
5+
super(false);
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.arangodb.springframework.testdata.chess;
2+
3+
public class PlayerRepositoryTxTest extends PlayerRepositoryAbstract {
4+
PlayerRepositoryTxTest() {
5+
super(true);
6+
}
7+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.arangodb.springframework.testdata.chess;
2+
3+
import com.arangodb.springframework.testdata.chess.repo.ScoreRepository;
4+
import org.junit.jupiter.api.Disabled;
5+
import org.junit.jupiter.api.Test;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
8+
import static org.assertj.core.api.Assertions.assertThat;
9+
10+
abstract class ScoreRepositoryAbstract extends AbstractRepositoryTest {
11+
12+
@Autowired
13+
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
14+
ScoreRepository repo;
15+
16+
ScoreRepositoryAbstract(boolean withinTx) {
17+
super(withinTx);
18+
}
19+
20+
@Test
21+
@Disabled("BTS-1859")
22+
void findAll() {
23+
assertThat(repo.findAll(queryOpts))
24+
.hasSize(scores.size())
25+
.containsExactlyInAnyOrderElementsOf(scores);
26+
}
27+
28+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.arangodb.springframework.testdata.chess;
2+
3+
public class ScoreRepositoryTest extends ScoreRepositoryAbstract {
4+
ScoreRepositoryTest() {
5+
super(false);
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.arangodb.springframework.testdata.chess;
2+
3+
public class ScoreRepositoryTxTest extends ScoreRepositoryAbstract {
4+
ScoreRepositoryTxTest() {
5+
super(true);
6+
}
7+
}

0 commit comments

Comments
 (0)