diff --git a/fh.fd.ci.server/src/main/java/de/fd/fh/server/game/GameRepository.java b/fh.fd.ci.server/src/main/java/de/fd/fh/server/game/GameRepository.java index a66eb54..977ae8c 100644 --- a/fh.fd.ci.server/src/main/java/de/fd/fh/server/game/GameRepository.java +++ b/fh.fd.ci.server/src/main/java/de/fd/fh/server/game/GameRepository.java @@ -29,4 +29,10 @@ public class GameRepository { return datastore.save(access); } + + Game findByGameId(final GameId gameId) + { + return datastore.createQuery(Game.class) + .field("id.identifier").equal(gameId.getIdentifier()).first(); + } } diff --git a/fh.fd.ci.server/src/test/java/de/fd/fh/server/game/GameRepositoryTest.java b/fh.fd.ci.server/src/test/java/de/fd/fh/server/game/GameRepositoryTest.java index a585d5b..fec9db6 100644 --- a/fh.fd.ci.server/src/test/java/de/fd/fh/server/game/GameRepositoryTest.java +++ b/fh.fd.ci.server/src/test/java/de/fd/fh/server/game/GameRepositoryTest.java @@ -71,4 +71,27 @@ class GameRepositoryTest assertNotNull(result.getId()); assertEquals(2, result.getFields().size()); } + + @Test + void findByGameIdTest() + { + final Set fields = new HashSet<>(); + fields.add(new Field(0, 0, Field.Color.BLACK, new Figure(Figure.Type.BISHOP, UserId.of("12345")))); + fields.add(new Field(0, 2, Field.Color.WHITE, new Figure(Figure.Type.BISHOP, UserId.of("98765")))); + + final Game game = new Game(GameId.of("4242"), UserId.of("12345"), UserId.of("98765"), UserId.of("12345"), fields, UserId.of("12345")); + + ds.save(game); + + final Game result = repository.findByGameId(GameId.of("4242")); + + assertNotNull(result); + assertEquals("12345", result.getWhitePlayer().getIdentifier()); + assertEquals("12345", result.getCurrentPlayer().getIdentifier()); + assertEquals("98765", result.getBlackPlayer().getIdentifier()); + assertEquals("12345", result.getWinner().getIdentifier()); + assertNotNull(result.getId()); + assertEquals(2, result.getFields().size()); + } + } \ No newline at end of file