From b3d7ab3e758f58d0f4104979b9fd8ccd0ac50986 Mon Sep 17 00:00:00 2001 From: djmil Date: Sat, 14 Oct 2023 19:03:46 +0200 Subject: [PATCH] springboot: rename GameState to GameView - update tests to use myColor instead of opponentColor --- .../main/java/djmil/cordacheckers/Joke.java | 4 -- .../GameProposalController.java | 25 ++------- .../api/GameStateController.java | 6 +-- .../cordaclient/CordaClient.java | 28 +++++----- .../dao/{GameState.java => GameView.java} | 5 +- .../cordaclient/dao/flow/arguments/Rsp.java | 6 +-- .../dao/flow/arguments/RspGameState.java | 6 +-- .../dao/flow/arguments/RspGameStateList.java | 6 +-- .../cordaclient/GameBoardTests.java | 54 +++++++++---------- .../cordaclient/GameProposalTests.java | 42 +++++++-------- .../cordaclient/GameStateTests.java | 14 ++--- .../cordaclient/RankingTests.java | 8 +-- 12 files changed, 93 insertions(+), 111 deletions(-) delete mode 100644 backend/src/main/java/djmil/cordacheckers/Joke.java rename backend/src/main/java/djmil/cordacheckers/{gameproposal => api}/GameProposalController.java (75%) rename backend/src/main/java/djmil/cordacheckers/cordaclient/dao/{GameState.java => GameView.java} (97%) diff --git a/backend/src/main/java/djmil/cordacheckers/Joke.java b/backend/src/main/java/djmil/cordacheckers/Joke.java deleted file mode 100644 index e9e12cc..0000000 --- a/backend/src/main/java/djmil/cordacheckers/Joke.java +++ /dev/null @@ -1,4 +0,0 @@ -package djmil.cordacheckers; - -public record Joke(String joke) { -} diff --git a/backend/src/main/java/djmil/cordacheckers/gameproposal/GameProposalController.java b/backend/src/main/java/djmil/cordacheckers/api/GameProposalController.java similarity index 75% rename from backend/src/main/java/djmil/cordacheckers/gameproposal/GameProposalController.java rename to backend/src/main/java/djmil/cordacheckers/api/GameProposalController.java index 7f387b7..65a12a4 100644 --- a/backend/src/main/java/djmil/cordacheckers/gameproposal/GameProposalController.java +++ b/backend/src/main/java/djmil/cordacheckers/api/GameProposalController.java @@ -1,4 +1,4 @@ -package djmil.cordacheckers.gameproposal; +package djmil.cordacheckers.api; import java.net.URI; import java.util.List; @@ -17,7 +17,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import djmil.cordacheckers.cordaclient.CordaClient; -import djmil.cordacheckers.cordaclient.dao.GameState; +import djmil.cordacheckers.cordaclient.dao.GameView; import djmil.cordacheckers.cordaclient.dao.HoldingIdentity; import djmil.cordacheckers.cordaclient.dao.Stone; import djmil.cordacheckers.cordaclient.dao.flow.arguments.ReqGameProposalCreate; @@ -26,7 +26,7 @@ import djmil.cordacheckers.user.User; @RestController -@RequestMapping("gameproposal") +@RequestMapping("api/gameproposal") public class GameProposalController { @Autowired @@ -34,21 +34,6 @@ public class GameProposalController { @Autowired HoldingIdentityResolver holdingIdentityResolver; - - @GetMapping - public ResponseEntity findAllUnconsumed( - @AuthenticationPrincipal User player - ) { - List gsList = cordaClient.gameStateList(player.getHoldingIdentity()); - - return ResponseEntity.ok(gsList.toString()); - } - - // @PostMapping() - // public ResponseEntity gameproposalSend(@AuthenticationPrincipal ApiUserDetails user) { - - // return ResponseEntity.ok(""); - // } @PostMapping() public ResponseEntity createGameProposal( @@ -62,7 +47,7 @@ public class GameProposalController { final Stone.Color gpReceiverColor = gpRequest.opponentColor(); // TODO handle expectionns here - GameState gameStateView = cordaClient.gameProposalCreate( + GameView gameStateView = cordaClient.gameProposalCreate( gpSender, gpReceiver, gpReceiverColor, @@ -70,7 +55,7 @@ public class GameProposalController { ); URI locationOfNewGameProposal = ucb - .path("gameproposal/{id}") + .path("api/gameproposal/{id}") .buildAndExpand(gameStateView) .toUri(); diff --git a/backend/src/main/java/djmil/cordacheckers/api/GameStateController.java b/backend/src/main/java/djmil/cordacheckers/api/GameStateController.java index e550fc6..a128272 100644 --- a/backend/src/main/java/djmil/cordacheckers/api/GameStateController.java +++ b/backend/src/main/java/djmil/cordacheckers/api/GameStateController.java @@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import djmil.cordacheckers.cordaclient.CordaClient; -import djmil.cordacheckers.cordaclient.dao.GameState; +import djmil.cordacheckers.cordaclient.dao.GameView; import djmil.cordacheckers.user.HoldingIdentityResolver; import djmil.cordacheckers.user.User; @@ -26,10 +26,10 @@ public class GameStateController { HoldingIdentityResolver holdingIdentityResolver; @GetMapping - public ResponseEntity> gameStateList( + public ResponseEntity> gameStateList( @AuthenticationPrincipal User player ) { - final List gsList = cordaClient.gameStateList(player.getHoldingIdentity()); + final List gsList = cordaClient.gameStateList(player.getHoldingIdentity()); return ResponseEntity.ok(gsList); } diff --git a/backend/src/main/java/djmil/cordacheckers/cordaclient/CordaClient.java b/backend/src/main/java/djmil/cordacheckers/cordaclient/CordaClient.java index f481387..5bfed8a 100644 --- a/backend/src/main/java/djmil/cordacheckers/cordaclient/CordaClient.java +++ b/backend/src/main/java/djmil/cordacheckers/cordaclient/CordaClient.java @@ -18,7 +18,7 @@ import org.springframework.web.client.RestTemplate; import com.fasterxml.jackson.databind.ObjectMapper; -import djmil.cordacheckers.cordaclient.dao.GameState; +import djmil.cordacheckers.cordaclient.dao.GameView; import djmil.cordacheckers.cordaclient.dao.HoldingIdentity; import djmil.cordacheckers.cordaclient.dao.Stone; import djmil.cordacheckers.cordaclient.dao.Rank; @@ -81,7 +81,7 @@ public class CordaClient { * @param holdingIdentity * @return list of unconsumed (active) GameStateViews */ - public List gameStateList(HoldingIdentity holdingIdentity) { + public List gameStateList(HoldingIdentity holdingIdentity) { final RequestBody requestBody = new RequestBody( "gs.list-" + UUID.randomUUID(), "djmil.cordacheckers.gamestate.ListFlow", @@ -91,7 +91,7 @@ public class CordaClient { .getResponce(requestBody); } - public GameState gameStateGet(HoldingIdentity holdingIdentity, UUID gameUuid) { + public GameView gameStateGet(HoldingIdentity holdingIdentity, UUID gameUuid) { final RequestBody requestBody = new RequestBody( "gs.get-" + UUID.randomUUID(), "djmil.cordacheckers.gamestate.GetFlow", @@ -101,13 +101,13 @@ public class CordaClient { .getResponce(requestBody); } - public GameState gameProposalCreate(HoldingIdentity issuer, HoldingIdentity acquier, Stone.Color acquierColor, + public GameView gameProposalCreate(HoldingIdentity issuer, HoldingIdentity acquier, Stone.Color acquierColor, String message) { - return gameProposalCreate(issuer, acquier, acquierColor, GameState.defaultGameBoard, message); + return gameProposalCreate(issuer, acquier, acquierColor, GameView.defaultGameBoard, message); } - public GameState gameProposalCreate(HoldingIdentity issuer, HoldingIdentity acquier, Stone.Color acquierColor, + public GameView gameProposalCreate(HoldingIdentity issuer, HoldingIdentity acquier, Stone.Color acquierColor, Map board, String message) { final RequestBody requestBody = new RequestBody( "gp.create-" + UUID.randomUUID(), @@ -122,7 +122,7 @@ public class CordaClient { .getResponce(requestBody); } - public GameState gameProposalReject(HoldingIdentity holdingIdentity, UUID gameUuid) { + public GameView gameProposalReject(HoldingIdentity holdingIdentity, UUID gameUuid) { final RequestBody requestBody = new RequestBody( "gp.reject-" +UUID.randomUUID(), "djmil.cordacheckers.gameproposal.RejectFlow", @@ -132,7 +132,7 @@ public class CordaClient { .getResponce(requestBody); } - public GameState gameProposalCancel(HoldingIdentity holdingIdentity, UUID gameUuid) { + public GameView gameProposalCancel(HoldingIdentity holdingIdentity, UUID gameUuid) { final RequestBody requestBody = new RequestBody( "gp.reject-" +UUID.randomUUID(), "djmil.cordacheckers.gameproposal.CancelFlow", @@ -142,7 +142,7 @@ public class CordaClient { .getResponce(requestBody); } - public GameState gameProposalAccept(HoldingIdentity holdingIdentity, UUID gameUuid) { + public GameView gameProposalAccept(HoldingIdentity holdingIdentity, UUID gameUuid) { final RequestBody requestBody = new RequestBody( "gp.accept-" +UUID.randomUUID(), "djmil.cordacheckers.gameproposal.AcceptFlow", @@ -152,7 +152,7 @@ public class CordaClient { .getResponce(requestBody); } - public GameState gameBoardSurrender(HoldingIdentity holdingIdentity, UUID gameUuid) { + public GameView gameBoardSurrender(HoldingIdentity holdingIdentity, UUID gameUuid) { final RequestBody requestBody = new RequestBody( "gb.surrender-" +UUID.randomUUID(), "djmil.cordacheckers.gameboard.SurrenderFlow", @@ -162,7 +162,7 @@ public class CordaClient { .getResponce(requestBody); } - public GameState gameBoardMove(HoldingIdentity holdingIdentity, UUID gameUuid, List move, + public GameView gameBoardMove(HoldingIdentity holdingIdentity, UUID gameUuid, List move, String message) { final RequestBody requestBody = new RequestBody( "gb.move-" +UUID.randomUUID(), @@ -174,7 +174,7 @@ public class CordaClient { .getResponce(requestBody); } - public GameState gameDrawRequest(HoldingIdentity holdingIdentity, UUID gameUuid) { + public GameView gameDrawRequest(HoldingIdentity holdingIdentity, UUID gameUuid) { final RequestBody requestBody = new RequestBody( "gd.request-" +UUID.randomUUID(), "djmil.cordacheckers.gameboard.DrawRequestFlow", @@ -184,7 +184,7 @@ public class CordaClient { .getResponce(requestBody); } - public GameState gameDrawAccept(HoldingIdentity holdingIdentity, UUID gameUuid) { + public GameView gameDrawAccept(HoldingIdentity holdingIdentity, UUID gameUuid) { final RequestBody requestBody = new RequestBody( "gd.accept-" +UUID.randomUUID(), "djmil.cordacheckers.gameboard.DrawAcceptFlow", @@ -194,7 +194,7 @@ public class CordaClient { .getResponce(requestBody); } - public GameState gameDrawReject(HoldingIdentity holdingIdentity, UUID gameUuid) { + public GameView gameDrawReject(HoldingIdentity holdingIdentity, UUID gameUuid) { final RequestBody requestBody = new RequestBody( "gd.reject-" +UUID.randomUUID(), "djmil.cordacheckers.gameboard.DrawRejectFlow", diff --git a/backend/src/main/java/djmil/cordacheckers/cordaclient/dao/GameState.java b/backend/src/main/java/djmil/cordacheckers/cordaclient/dao/GameView.java similarity index 97% rename from backend/src/main/java/djmil/cordacheckers/cordaclient/dao/GameState.java rename to backend/src/main/java/djmil/cordacheckers/cordaclient/dao/GameView.java index 4793917..0ee6956 100644 --- a/backend/src/main/java/djmil/cordacheckers/cordaclient/dao/GameState.java +++ b/backend/src/main/java/djmil/cordacheckers/cordaclient/dao/GameView.java @@ -4,10 +4,11 @@ import java.util.List; import java.util.Map; import java.util.UUID; -public record GameState( +public record GameView( Status status, + + Stone.Color myColor, String opponentName, - Stone.Color opponentColor, Map board, Integer moveNumber, diff --git a/backend/src/main/java/djmil/cordacheckers/cordaclient/dao/flow/arguments/Rsp.java b/backend/src/main/java/djmil/cordacheckers/cordaclient/dao/flow/arguments/Rsp.java index 35b718c..d884930 100644 --- a/backend/src/main/java/djmil/cordacheckers/cordaclient/dao/flow/arguments/Rsp.java +++ b/backend/src/main/java/djmil/cordacheckers/cordaclient/dao/flow/arguments/Rsp.java @@ -1,6 +1,6 @@ package djmil.cordacheckers.cordaclient.dao.flow.arguments; -import djmil.cordacheckers.cordaclient.dao.GameState; +import djmil.cordacheckers.cordaclient.dao.GameView; import djmil.cordacheckers.cordaclient.dao.flow.RequestBody; public interface Rsp { @@ -10,8 +10,8 @@ public interface Rsp { public default T getResponce(RequestBody requestBody) { if (failureStatus() == null) { final var responce = successStatus(); - final String gameUuid = (responce instanceof GameState) - ? "GameUUID " +((GameState)responce).uuid().toString() + final String gameUuid = (responce instanceof GameView) + ? "GameUUID " +((GameView)responce).uuid().toString() : ""; System.out.println(requestBody.clientRequestId() +" [OK] " +gameUuid); diff --git a/backend/src/main/java/djmil/cordacheckers/cordaclient/dao/flow/arguments/RspGameState.java b/backend/src/main/java/djmil/cordacheckers/cordaclient/dao/flow/arguments/RspGameState.java index f712911..a97132e 100644 --- a/backend/src/main/java/djmil/cordacheckers/cordaclient/dao/flow/arguments/RspGameState.java +++ b/backend/src/main/java/djmil/cordacheckers/cordaclient/dao/flow/arguments/RspGameState.java @@ -1,10 +1,10 @@ package djmil.cordacheckers.cordaclient.dao.flow.arguments; -import djmil.cordacheckers.cordaclient.dao.GameState; +import djmil.cordacheckers.cordaclient.dao.GameView; public record RspGameState( - GameState successStatus, + GameView successStatus, String transactionId, - String failureStatus) implements Rsp { + String failureStatus) implements Rsp { } diff --git a/backend/src/main/java/djmil/cordacheckers/cordaclient/dao/flow/arguments/RspGameStateList.java b/backend/src/main/java/djmil/cordacheckers/cordaclient/dao/flow/arguments/RspGameStateList.java index cc88041..bc22c2e 100644 --- a/backend/src/main/java/djmil/cordacheckers/cordaclient/dao/flow/arguments/RspGameStateList.java +++ b/backend/src/main/java/djmil/cordacheckers/cordaclient/dao/flow/arguments/RspGameStateList.java @@ -2,10 +2,10 @@ package djmil.cordacheckers.cordaclient.dao.flow.arguments; import java.util.List; -import djmil.cordacheckers.cordaclient.dao.GameState; +import djmil.cordacheckers.cordaclient.dao.GameView; public record RspGameStateList( - List successStatus, - String failureStatus) implements Rsp> { + List successStatus, + String failureStatus) implements Rsp> { } diff --git a/backend/src/test/java/djmil/cordacheckers/cordaclient/GameBoardTests.java b/backend/src/test/java/djmil/cordacheckers/cordaclient/GameBoardTests.java index 0e0238d..b7f43c5 100644 --- a/backend/src/test/java/djmil/cordacheckers/cordaclient/GameBoardTests.java +++ b/backend/src/test/java/djmil/cordacheckers/cordaclient/GameBoardTests.java @@ -11,8 +11,8 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import djmil.cordacheckers.cordaclient.dao.GameState; -import djmil.cordacheckers.cordaclient.dao.GameState.Status; +import djmil.cordacheckers.cordaclient.dao.GameView; +import djmil.cordacheckers.cordaclient.dao.GameView.Status; import djmil.cordacheckers.cordaclient.dao.Stone; import djmil.cordacheckers.user.HoldingIdentityResolver; @@ -48,21 +48,21 @@ public class GameBoardTests { final var hiWhite = holdingIdentityResolver.getByUsername(whitePlayerName); final var hiBlack = holdingIdentityResolver.getByUsername(blackPlayerName); - final GameState game = cordaClient.gameProposalCreate( + final GameView game = cordaClient.gameProposalCreate( hiWhite, hiBlack, Stone.Color.BLACK, "GameBoard SURRENDER test"); - final GameState acceptedGameBlackView = cordaClient.gameProposalAccept( + final GameView acceptedGameBlackView = cordaClient.gameProposalAccept( hiBlack, game.uuid()); - assertThat(acceptedGameBlackView.opponentColor()).isEqualByComparingTo(Stone.Color.WHITE); + assertThat(acceptedGameBlackView.myColor()).isEqualByComparingTo(Stone.Color.BLACK); assertThat(acceptedGameBlackView.status()).isEqualByComparingTo(Status.GAME_BOARD_WAIT_FOR_OPPONENT); // Black shall be able to surrender, even if it is not his turn - final GameState surrendererGameView = cordaClient.gameBoardSurrender( + final GameView surrendererGameView = cordaClient.gameBoardSurrender( hiBlack, game.uuid()); + assertThat(surrendererGameView.myColor()).isEqualByComparingTo(Stone.Color.BLACK); assertThat(surrendererGameView.opponentName()).isEqualToIgnoringCase(whitePlayerName); - assertThat(surrendererGameView.opponentColor()).isEqualByComparingTo(Stone.Color.WHITE); assertThat(surrendererGameView.status()).isEqualByComparingTo(Status.GAME_RESULT_YOU_LOOSE); assertThat(surrendererGameView.moveNumber() == 0); @@ -71,11 +71,11 @@ public class GameBoardTests { hiWhite, game.uuid()); }); - final GameState winnerGameView = cordaClient.gameStateGet( + final GameView winnerGameView = cordaClient.gameStateGet( hiWhite, game.uuid()); + assertThat(winnerGameView.myColor()).isEqualByComparingTo(Stone.Color.WHITE); assertThat(winnerGameView.opponentName()).isEqualToIgnoringCase(blackPlayerName); - assertThat(winnerGameView.opponentColor()).isEqualByComparingTo(Stone.Color.BLACK); assertThat(winnerGameView.status()).isEqualByComparingTo(Status.GAME_RESULT_YOU_WON); assertThat(winnerGameView.moveNumber() == 0); } @@ -85,7 +85,7 @@ public class GameBoardTests { final var hiWhite = holdingIdentityResolver.getByUsername(whitePlayerName); final var hiBlack = holdingIdentityResolver.getByUsername(blackPlayerName); - final GameState game = cordaClient.gameProposalCreate( + final GameView game = cordaClient.gameProposalCreate( hiWhite, hiBlack, Stone.Color.BLACK, "GameBoard MOVE test"); final var m0 = cordaClient.gameProposalAccept(hiBlack, game.uuid()); @@ -197,10 +197,10 @@ public class GameBoardTests { final var hiWhite = holdingIdentityResolver.getByUsername(whitePlayerName); final var hiBlack = holdingIdentityResolver.getByUsername(blackPlayerName); - final GameState game = cordaClient.gameProposalCreate(hiBlack, hiWhite, Stone.Color.WHITE, + final GameView game = cordaClient.gameProposalCreate(hiBlack, hiWhite, Stone.Color.WHITE, victoryTestBoard1, "GameBoard Vitcory test 1"); - final GameState m0 = cordaClient.gameProposalAccept(hiWhite, game.uuid()); + final GameView m0 = cordaClient.gameProposalAccept(hiWhite, game.uuid()); assertThat(m0.status()).isEqualByComparingTo(Status.GAME_BOARD_WAIT_FOR_YOU); assertThat(m0.board()).containsAllEntriesOf(victoryTestBoard1); @@ -221,10 +221,10 @@ public class GameBoardTests { final var hiWhite = holdingIdentityResolver.getByUsername(whitePlayerName); final var hiBlack = holdingIdentityResolver.getByUsername(blackPlayerName); - final GameState game = cordaClient.gameProposalCreate(hiWhite, hiBlack, Stone.Color.BLACK, + final GameView game = cordaClient.gameProposalCreate(hiWhite, hiBlack, Stone.Color.BLACK, victoryTestBoard2, "GameBoard Vitcory test 2"); - final GameState m0 = cordaClient.gameProposalAccept(hiBlack, game.uuid()); + final GameView m0 = cordaClient.gameProposalAccept(hiBlack, game.uuid()); assertThat(m0.status()).isEqualByComparingTo(Status.GAME_BOARD_WAIT_FOR_OPPONENT); assertThat(m0.board()).containsAllEntriesOf(victoryTestBoard2); @@ -245,7 +245,7 @@ public class GameBoardTests { final var hiWhite = holdingIdentityResolver.getByUsername(whitePlayerName); final var hiBlack = holdingIdentityResolver.getByUsername(blackPlayerName); - final GameState game = cordaClient.gameProposalCreate(hiWhite, hiBlack, Stone.Color.BLACK, + final GameView game = cordaClient.gameProposalCreate(hiWhite, hiBlack, Stone.Color.BLACK, "Test draw request"); assertThat(cordaClient.gameProposalAccept(hiBlack, game.uuid()) @@ -255,10 +255,10 @@ public class GameBoardTests { cordaClient.gameDrawRequest(hiBlack, game.uuid()); }); - final GameState drawReqIssuerView = cordaClient.gameDrawRequest(hiWhite, game.uuid()); + final GameView drawReqIssuerView = cordaClient.gameDrawRequest(hiWhite, game.uuid()); assertThat(drawReqIssuerView.status()).isEqualByComparingTo(Status.DRAW_REQUEST_WAIT_FOR_OPPONENT); - final GameState drawReqAcquierView = cordaClient.gameStateGet(hiBlack, game.uuid()); + final GameView drawReqAcquierView = cordaClient.gameStateGet(hiBlack, game.uuid()); assertThat(drawReqAcquierView.status()).isEqualByComparingTo(Status.DRAW_REQUEST_WAIT_FOR_YOU); assertThat(drawReqAcquierView.board()).containsAllEntriesOf(drawReqIssuerView.board()); @@ -279,7 +279,7 @@ public class GameBoardTests { final var hiWhite = holdingIdentityResolver.getByUsername(whitePlayerName); final var hiBlack = holdingIdentityResolver.getByUsername(blackPlayerName); - final GameState game = cordaClient.gameProposalCreate(hiBlack, hiWhite, Stone.Color.WHITE, + final GameView game = cordaClient.gameProposalCreate(hiBlack, hiWhite, Stone.Color.WHITE, "Draw ACCEPT test"); assertThat(cordaClient.gameProposalAccept(hiWhite, game.uuid()) @@ -289,24 +289,24 @@ public class GameBoardTests { cordaClient.gameDrawRequest(hiBlack, game.uuid()); }); - final GameState drawReqIssuerView = cordaClient.gameDrawRequest(hiWhite, game.uuid()); + final GameView drawReqIssuerView = cordaClient.gameDrawRequest(hiWhite, game.uuid()); assertThat(drawReqIssuerView.status()).isEqualByComparingTo(Status.DRAW_REQUEST_WAIT_FOR_OPPONENT); assertThatThrownBy(() -> { // White shall not be able to accept own Draw Request cordaClient.gameDrawAccept(hiWhite, game.uuid()); }); - final GameState drawReqAcquierView = cordaClient.gameStateGet(hiBlack, game.uuid()); + final GameView drawReqAcquierView = cordaClient.gameStateGet(hiBlack, game.uuid()); assertThat(drawReqAcquierView.status()).isEqualByComparingTo(Status.DRAW_REQUEST_WAIT_FOR_YOU); assertThatThrownBy(() -> { // Black shall not be able to send counter Draw Request cordaClient.gameDrawRequest(hiBlack, game.uuid()); }); - final GameState drawAcceptBlackView = cordaClient.gameDrawAccept(hiBlack, game.uuid()); + final GameView drawAcceptBlackView = cordaClient.gameDrawAccept(hiBlack, game.uuid()); assertThat(drawAcceptBlackView.status()).isEqualByComparingTo(Status.GAME_RESULT_DRAW); - final GameState drawAcceptWhiteView = cordaClient.gameStateGet(hiWhite, game.uuid()); + final GameView drawAcceptWhiteView = cordaClient.gameStateGet(hiWhite, game.uuid()); assertThat(drawAcceptWhiteView.status()).isEqualByComparingTo(Status.GAME_RESULT_DRAW); } @@ -315,30 +315,30 @@ public class GameBoardTests { final var hiWhite = holdingIdentityResolver.getByUsername(whitePlayerName); final var hiBlack = holdingIdentityResolver.getByUsername(blackPlayerName); - final GameState game = cordaClient.gameProposalCreate(hiWhite, hiBlack, Stone.Color.BLACK, + final GameView game = cordaClient.gameProposalCreate(hiWhite, hiBlack, Stone.Color.BLACK, "Draw REJECT test"); assertThat(cordaClient.gameProposalAccept(hiBlack, game.uuid()) .status()).isEqualByComparingTo(Status.GAME_BOARD_WAIT_FOR_OPPONENT); - final GameState drawReqIssuerView = cordaClient.gameDrawRequest(hiWhite, game.uuid()); + final GameView drawReqIssuerView = cordaClient.gameDrawRequest(hiWhite, game.uuid()); assertThat(drawReqIssuerView.status()).isEqualByComparingTo(Status.DRAW_REQUEST_WAIT_FOR_OPPONENT); assertThatThrownBy(() -> { // White shall not be able to reject own Draw Request cordaClient.gameDrawReject(hiWhite, game.uuid()); }); - final GameState drawReqAcquierView = cordaClient.gameStateGet(hiBlack, game.uuid()); + final GameView drawReqAcquierView = cordaClient.gameStateGet(hiBlack, game.uuid()); assertThat(drawReqAcquierView.status()).isEqualByComparingTo(Status.DRAW_REQUEST_WAIT_FOR_YOU); assertThatThrownBy(() -> { // Black shall not be able to send counter Draw Request cordaClient.gameDrawRequest(hiBlack, game.uuid()); }); - final GameState drawRejectBlackView = cordaClient.gameDrawReject(hiBlack, game.uuid()); + final GameView drawRejectBlackView = cordaClient.gameDrawReject(hiBlack, game.uuid()); assertThat(drawRejectBlackView.status()).isEqualByComparingTo(Status.GAME_BOARD_WAIT_FOR_OPPONENT); - final GameState drawRejectWhiteView = cordaClient.gameStateGet(hiWhite, game.uuid()); + final GameView drawRejectWhiteView = cordaClient.gameStateGet(hiWhite, game.uuid()); assertThat(drawRejectWhiteView.status()).isEqualByComparingTo(Status.GAME_BOARD_WAIT_FOR_YOU); } diff --git a/backend/src/test/java/djmil/cordacheckers/cordaclient/GameProposalTests.java b/backend/src/test/java/djmil/cordacheckers/cordaclient/GameProposalTests.java index c1c5143..35e7f3b 100644 --- a/backend/src/test/java/djmil/cordacheckers/cordaclient/GameProposalTests.java +++ b/backend/src/test/java/djmil/cordacheckers/cordaclient/GameProposalTests.java @@ -8,8 +8,8 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import djmil.cordacheckers.cordaclient.dao.GameState; -import djmil.cordacheckers.cordaclient.dao.GameState.Status; +import djmil.cordacheckers.cordaclient.dao.GameView; +import djmil.cordacheckers.cordaclient.dao.GameView.Status; import djmil.cordacheckers.cordaclient.dao.Stone; import djmil.cordacheckers.user.HoldingIdentityResolver; @@ -31,16 +31,16 @@ public class GameProposalTests { final var hiAcquier = holdingIdentityResolver.getByUsername(acquier); final String message = "GameProposal CREATE test"; - final GameState issuerGameView = cordaClient.gameProposalCreate( + final GameView issuerGameView = cordaClient.gameProposalCreate( hiIssuer, hiAcquier, acquierColor, message); /* * Issuers perspective on a newly created GameProposal */ assertThat(issuerGameView.status()).isEqualByComparingTo(Status.GAME_PROPOSAL_WAIT_FOR_OPPONENT); + assertThat(issuerGameView.myColor()).isEqualByComparingTo(acquierColor.opposite()); assertThat(issuerGameView.opponentName()).isEqualToIgnoringCase(acquier); - assertThat(issuerGameView.opponentColor()).isEqualByComparingTo(acquierColor); - assertThat(issuerGameView.board()).containsAllEntriesOf(GameState.defaultGameBoard); + assertThat(issuerGameView.board()).containsAllEntriesOf(GameView.defaultGameBoard); assertThat(issuerGameView.previousMove()).isNull(); assertThat(issuerGameView.moveNumber() == 0); assertThat(issuerGameView.message()).isEqualToIgnoringCase(message); @@ -49,7 +49,7 @@ public class GameProposalTests { /* * Acquier shall be able to find newly created GameProposal */ - GameState acquierGameView = assertDoesNotThrow( () -> { + GameView acquierGameView = assertDoesNotThrow( () -> { return cordaClient.gameStateList(hiAcquier) .stream() .filter(gameView -> gameView.uuid().compareTo(issuerGameView.uuid()) == 0) @@ -58,9 +58,9 @@ public class GameProposalTests { }); assertThat(acquierGameView.status()).isEqualByComparingTo(Status.GAME_PROPOSAL_WAIT_FOR_YOU); + assertThat(acquierGameView.myColor()).isEqualByComparingTo(acquierColor); assertThat(acquierGameView.opponentName()).isEqualToIgnoringCase(issuer); - assertThat(acquierGameView.opponentColor()).isEqualByComparingTo(acquierColor.opposite()); - assertThat(acquierGameView.board()).containsAllEntriesOf(GameState.defaultGameBoard); + assertThat(acquierGameView.board()).containsAllEntriesOf(GameView.defaultGameBoard); assertThat(acquierGameView.previousMove()).isNull(); assertThat(acquierGameView.moveNumber() == 0); assertThat(acquierGameView.message()).isEqualToIgnoringCase(message); @@ -72,7 +72,7 @@ public class GameProposalTests { final var hiIssuer = holdingIdentityResolver.getByUsername(issuer); final var hiAcquier = holdingIdentityResolver.getByUsername(acquier); - final GameState game = cordaClient.gameProposalCreate( + final GameView game = cordaClient.gameProposalCreate( hiIssuer, hiAcquier, acquierColor, "GameProposal REJECT test"); assertThatThrownBy(() -> { // Issuer can not reject @@ -80,12 +80,12 @@ public class GameProposalTests { hiIssuer, game.uuid()); }); - final GameState pendingGameView = cordaClient.gameStateGet( + final GameView pendingGameView = cordaClient.gameStateGet( hiAcquier, game.uuid()); assertThat(pendingGameView.status()).isEqualByComparingTo(Status.GAME_PROPOSAL_WAIT_FOR_YOU); assertThat(pendingGameView.uuid()).isEqualByComparingTo(game.uuid()); - final GameState rejectedGameView = cordaClient.gameProposalReject( + final GameView rejectedGameView = cordaClient.gameProposalReject( hiAcquier, game.uuid()); assertThat(rejectedGameView.status()).isEqualByComparingTo(Status.GAME_PROPOSAL_REJECTED); assertThat(rejectedGameView.uuid()).isEqualByComparingTo(game.uuid()); @@ -101,7 +101,7 @@ public class GameProposalTests { final var hiIssuer = holdingIdentityResolver.getByUsername(issuer); final var hiAcquier = holdingIdentityResolver.getByUsername(acquier); - final GameState game = cordaClient.gameProposalCreate( + final GameView game = cordaClient.gameProposalCreate( hiIssuer, hiAcquier, acquierColor, "GameProposal CANCEL test"); assertThatThrownBy(() -> { // Acquier can not cancel @@ -109,12 +109,12 @@ public class GameProposalTests { hiAcquier, game.uuid()); }); - final GameState pendingGameView = cordaClient.gameStateGet( + final GameView pendingGameView = cordaClient.gameStateGet( hiIssuer, game.uuid()); assertThat(pendingGameView.status()).isEqualByComparingTo(Status.GAME_PROPOSAL_WAIT_FOR_OPPONENT); assertThat(pendingGameView.uuid()).isEqualByComparingTo(game.uuid()); - final GameState canceledGameView = cordaClient.gameProposalCancel( + final GameView canceledGameView = cordaClient.gameProposalCancel( hiIssuer, game.uuid()); assertThat(canceledGameView.status()).isEqualByComparingTo(Status.GAME_PROPOSAL_CANCELED); assertThat(canceledGameView.uuid()).isEqualByComparingTo(game.uuid()); @@ -130,19 +130,19 @@ public class GameProposalTests { final var hiIssuer = holdingIdentityResolver.getByUsername(issuer); final var hiAcquier = holdingIdentityResolver.getByUsername(acquier); - final GameState game = cordaClient.gameProposalCreate( + final GameView game = cordaClient.gameProposalCreate( hiIssuer, hiAcquier, acquierColor, "GameProposal ACCEPT test"); assertThatThrownBy(() -> { // Issuer can not accept cordaClient.gameProposalAccept(hiIssuer, game.uuid()); }); - final GameState acceptedGameAcquierView = cordaClient.gameProposalAccept( + final GameView acceptedGameAcquierView = cordaClient.gameProposalAccept( hiAcquier, game.uuid()); + assertThat(acceptedGameAcquierView.myColor()).isEqualByComparingTo(acquierColor); assertThat(acceptedGameAcquierView.opponentName()).isEqualToIgnoringCase(issuer); - assertThat(acceptedGameAcquierView.opponentColor()).isEqualByComparingTo(acquierColor.opposite()); - assertThat(acceptedGameAcquierView.board()).containsAllEntriesOf(GameState.defaultGameBoard); + assertThat(acceptedGameAcquierView.board()).containsAllEntriesOf(GameView.defaultGameBoard); assertThat(acceptedGameAcquierView.previousMove()).isNull(); assertThat(acceptedGameAcquierView.moveNumber() == 0); assertThat(acceptedGameAcquierView.status()).isEqualByComparingTo(Status.GAME_BOARD_WAIT_FOR_YOU); @@ -153,12 +153,12 @@ public class GameProposalTests { hiIssuer, game.uuid()); }); - final GameState acceptedGameIssuerView = cordaClient.gameStateGet( + final GameView acceptedGameIssuerView = cordaClient.gameStateGet( hiIssuer, game.uuid()); + assertThat(acceptedGameIssuerView.myColor()).isEqualByComparingTo(acquierColor.opposite()); assertThat(acceptedGameIssuerView.opponentName()).isEqualToIgnoringCase(acquier); - assertThat(acceptedGameIssuerView.opponentColor()).isEqualByComparingTo(acquierColor); - assertThat(acceptedGameIssuerView.board()).containsAllEntriesOf(GameState.defaultGameBoard); + assertThat(acceptedGameIssuerView.board()).containsAllEntriesOf(GameView.defaultGameBoard); assertThat(acceptedGameIssuerView.previousMove()).isNull(); assertThat(acceptedGameIssuerView.moveNumber() == 0); assertThat(acceptedGameIssuerView.status()).isEqualByComparingTo(Status.GAME_BOARD_WAIT_FOR_OPPONENT); diff --git a/backend/src/test/java/djmil/cordacheckers/cordaclient/GameStateTests.java b/backend/src/test/java/djmil/cordacheckers/cordaclient/GameStateTests.java index b8b230b..8b30c51 100644 --- a/backend/src/test/java/djmil/cordacheckers/cordaclient/GameStateTests.java +++ b/backend/src/test/java/djmil/cordacheckers/cordaclient/GameStateTests.java @@ -10,7 +10,7 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import djmil.cordacheckers.cordaclient.dao.GameState; +import djmil.cordacheckers.cordaclient.dao.GameView; import djmil.cordacheckers.cordaclient.dao.Stone.Color; import djmil.cordacheckers.user.HoldingIdentityResolver; @@ -30,7 +30,7 @@ public class GameStateTests { final var hiPlayer1 = holdingIdentityResolver.getByUsername(player1); final var hiPlayer2 = holdingIdentityResolver.getByUsername(player2); - final GameState p1GameView = cordaClient.gameProposalCreate( + final GameView p1GameView = cordaClient.gameProposalCreate( hiPlayer1, hiPlayer2, Color.BLACK, "GameState List test"); final UUID gameUuid = p1GameView.uuid(); @@ -38,8 +38,8 @@ public class GameStateTests { /* * Both players shall be able to find newly created GameProposal within GameList */ - final List p1GameList = cordaClient.gameStateList(hiPlayer1); - final List p2GameList = cordaClient.gameStateList(hiPlayer2); + final List p1GameList = cordaClient.gameStateList(hiPlayer1); + final List p2GameList = cordaClient.gameStateList(hiPlayer2); assertThat(findGameStateById(p1GameList, gameUuid)).isNotNull(); assertThat(findGameStateById(p2GameList, gameUuid)).isNotNull(); @@ -56,17 +56,17 @@ public class GameStateTests { ); }); - final GameState p1GameView = cordaClient.gameProposalCreate( + final GameView p1GameView = cordaClient.gameProposalCreate( hiPlayer1, hiPlayer2, Color.WHITE, "GameState Get test"); final UUID gameUuid = p1GameView.uuid(); - final GameState p2GameView = cordaClient.gameStateGet(hiPlayer2, gameUuid); + final GameView p2GameView = cordaClient.gameStateGet(hiPlayer2, gameUuid); assertThat(p1GameView.message()).isEqualTo(p2GameView.message()); } - GameState findGameStateById(List gameStateList, UUID gameUuid) { + GameView findGameStateById(List gameStateList, UUID gameUuid) { return gameStateList .stream() .filter(gameView -> gameView.uuid().compareTo(gameUuid) == 0) diff --git a/backend/src/test/java/djmil/cordacheckers/cordaclient/RankingTests.java b/backend/src/test/java/djmil/cordacheckers/cordaclient/RankingTests.java index ae34f5c..ff41b3b 100644 --- a/backend/src/test/java/djmil/cordacheckers/cordaclient/RankingTests.java +++ b/backend/src/test/java/djmil/cordacheckers/cordaclient/RankingTests.java @@ -12,7 +12,7 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import djmil.cordacheckers.cordaclient.dao.GameState; +import djmil.cordacheckers.cordaclient.dao.GameView; import djmil.cordacheckers.cordaclient.dao.Rank; import djmil.cordacheckers.cordaclient.dao.Stone; import djmil.cordacheckers.user.HoldingIdentityResolver; @@ -50,7 +50,7 @@ public class RankingTests { final var winnerName = hiWinner.getName(); final var losserName = hiLooser.getName(); - final GameState game = cordaClient.gameProposalCreate(hiWinner, hiLooser, Stone.Color.WHITE, + final GameView game = cordaClient.gameProposalCreate(hiWinner, hiLooser, Stone.Color.WHITE, "GameBoard GLOBAL_RANKING surrender test"); cordaClient.gameProposalAccept(hiLooser, game.uuid()); @@ -79,7 +79,7 @@ public class RankingTests { final var winnerName = hiWinner.getName(); final var losserName = hiLooser.getName(); - final GameState game = cordaClient.gameProposalCreate(hiWinner, hiLooser, Stone.Color.BLACK, + final GameView game = cordaClient.gameProposalCreate(hiWinner, hiLooser, Stone.Color.BLACK, board1, "GameBoard GLOBAL_RANKING victory test"); cordaClient.gameProposalAccept(hiLooser, game.uuid()); @@ -104,7 +104,7 @@ public class RankingTests { final var hiPlayer1 = holdingIdentityResolver.getByUsername(player1); final var hiPlayer2 = holdingIdentityResolver.getByUsername(player2); - final GameState game = cordaClient.gameProposalCreate(hiPlayer1, hiPlayer2, Stone.Color.WHITE, + final GameView game = cordaClient.gameProposalCreate(hiPlayer1, hiPlayer2, Stone.Color.WHITE, "GameBoard GLOBAL_RANKING draw test"); cordaClient.gameProposalAccept(hiPlayer2, game.uuid());