-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
479 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/test/java/com/arangodb/springframework/testdata/chess/AbstractRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.arangodb.springframework.testdata.chess; | ||
|
||
import com.arangodb.springframework.AbstractArangoTest; | ||
import com.arangodb.springframework.core.ArangoOperations; | ||
import com.arangodb.springframework.testdata.chess.entity.Player; | ||
import com.arangodb.springframework.testdata.chess.entity.Score; | ||
import com.arangodb.springframework.testdata.chess.entity.Tournament; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.geo.Point; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
abstract class AbstractRepositoryTest extends AbstractArangoTest { | ||
|
||
@Autowired | ||
private ArangoOperations ops; | ||
|
||
protected List<Player> players = List.of( | ||
new Player("Magnus Carlsen", 2830, "Norway"), | ||
new Player("Fabiano Caruana", 2803, "US"), | ||
new Player("Maxime Vachier-Lagrave", 2732, "France"), | ||
new Player("Hikaru Nakamura", 2789, "US"), | ||
new Player("Ding Liren", 2762, "China"), | ||
new Player("Wesley So", 2757, "US"), | ||
new Player("Alireza Firouzja", 2760, "France"), | ||
new Player("Anish Giri", 2745, "Netherlands"), | ||
new Player("Ian Nepomniachtchi", 2758, "Russia") | ||
); | ||
|
||
protected List<Tournament> tournaments = List.of( | ||
new Tournament( | ||
"Tata Steel 2023", | ||
LocalDate.of(2023, 1, 13), | ||
"Wijk aan Zee", | ||
new Point(4.6, 52.5) | ||
), | ||
new Tournament( | ||
"World Chess Championship 2023", | ||
LocalDate.of(2023, 4, 9), | ||
"Astana", | ||
new Point(71.422222, 51.147222) | ||
), | ||
new Tournament( | ||
"Norway Chess 2023", | ||
LocalDate.of(2023, 5, 30), | ||
"Stavanger", | ||
new Point(5.731389, 58.97) | ||
) | ||
); | ||
|
||
protected List<Score> scores = List.of( | ||
new Score(players.get(7), tournaments.get(0), 1), | ||
new Score(players.get(0), tournaments.get(0), 3), | ||
new Score(players.get(5), tournaments.get(0), 4), | ||
new Score(players.get(1), tournaments.get(0), 5), | ||
new Score(players.get(4), tournaments.get(1), 1), | ||
new Score(players.get(8), tournaments.get(1), 2), | ||
new Score(players.get(3), tournaments.get(1), 4), | ||
new Score(players.get(1), tournaments.get(1), 5), | ||
new Score(players.get(6), tournaments.get(1), 6), | ||
new Score(players.get(3), tournaments.get(2), 1), | ||
new Score(players.get(1), tournaments.get(2), 2), | ||
new Score(players.get(7), tournaments.get(2), 4), | ||
new Score(players.get(5), tournaments.get(2), 5), | ||
new Score(players.get(0), tournaments.get(2), 6) | ||
); | ||
|
||
protected AbstractRepositoryTest() { | ||
super(Player.class, Score.class, Tournament.class); | ||
} | ||
|
||
@BeforeEach | ||
void importData() { | ||
ops.insertAll(players, Player.class); | ||
ops.insertAll(tournaments, Tournament.class); | ||
ops.insertAll(scores, Score.class); | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
src/test/java/com/arangodb/springframework/testdata/chess/PlayerRepositoryAbstract.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.arangodb.springframework.testdata.chess; | ||
|
||
import com.arangodb.springframework.testdata.chess.entity.*; | ||
import com.arangodb.springframework.testdata.chess.repo.PlayerRepository; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageRequest; | ||
|
||
import java.util.Comparator; | ||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
abstract class PlayerRepositoryAbstract extends AbstractRepositoryTest { | ||
|
||
@Autowired | ||
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") | ||
PlayerRepository repo; | ||
|
||
@Test | ||
void findAllByCountry() { | ||
List<Player> expected = players.stream() | ||
.filter(it -> "US".equals(it.getCountry())) | ||
.toList(); | ||
Iterable<Player> found = repo.findAllByCountry("US"); | ||
assertThat(found).containsExactlyInAnyOrderElementsOf(expected); | ||
found.forEach(this::checkRefs); | ||
} | ||
|
||
@Test | ||
void findAllByRatingGreaterThan() { | ||
int rating = 2780; | ||
List<Player> expected = players.stream() | ||
.filter(it -> it.getRating() > rating) | ||
.sorted(Comparator.comparingInt(Player::getRating).reversed()) | ||
.toList(); | ||
|
||
for (int i = 0; i < expected.size(); i++) { | ||
Page<Player> page = repo.findAllByRatingGreaterThanOrderByRatingDesc(PageRequest.of(i, 1), rating); | ||
assertThat(page.getTotalElements()).isEqualTo(expected.size()); | ||
assertThat(page.getTotalPages()).isEqualTo(expected.size()); | ||
Player current = page.iterator().next(); | ||
assertThat(current).isEqualTo(expected.get(i)); | ||
checkRefs(current); | ||
} | ||
} | ||
|
||
private void checkRefs(Player p) { | ||
List<Score> expectedScores = scores.stream() | ||
.filter(it -> it.player().equals(p)) | ||
.toList(); | ||
assertThat(p.getScores()).containsExactlyInAnyOrderElementsOf(expectedScores); | ||
|
||
List<Tournament> expectedTournaments = expectedScores.stream() | ||
.map(Score::tournament) | ||
.toList(); | ||
assertThat(p.getTournaments()).containsExactlyInAnyOrderElementsOf(expectedTournaments); | ||
} | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
src/test/java/com/arangodb/springframework/testdata/chess/PlayerRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.arangodb.springframework.testdata.chess; | ||
|
||
public class PlayerRepositoryTest extends PlayerRepositoryAbstract { | ||
} |
24 changes: 24 additions & 0 deletions
24
src/test/java/com/arangodb/springframework/testdata/chess/ScoreRepositoryAbstract.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.arangodb.springframework.testdata.chess; | ||
|
||
import com.arangodb.springframework.testdata.chess.repo.ScoreRepository; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
abstract class ScoreRepositoryAbstract extends AbstractRepositoryTest { | ||
|
||
@Autowired | ||
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") | ||
ScoreRepository repo; | ||
|
||
@Test | ||
@Disabled("BTS-1859") | ||
void findAll() { | ||
assertThat(repo.findAll()) | ||
.hasSize(scores.size()) | ||
.containsExactlyInAnyOrderElementsOf(scores); | ||
} | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
src/test/java/com/arangodb/springframework/testdata/chess/ScoreRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.arangodb.springframework.testdata.chess; | ||
|
||
public class ScoreRepositoryTest extends ScoreRepositoryAbstract { | ||
} |
Oops, something went wrong.