springboot: rename GameState to GameView

- update tests to use myColor instead of opponentColor
This commit is contained in:
djmil 2023-10-14 19:03:46 +02:00
parent 5f23c4c766
commit b3d7ab3e75
12 changed files with 93 additions and 111 deletions

View File

@ -1,4 +0,0 @@
package djmil.cordacheckers;
public record Joke(String joke) {
}

View File

@ -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
@ -35,21 +35,6 @@ public class GameProposalController {
@Autowired
HoldingIdentityResolver holdingIdentityResolver;
@GetMapping
public ResponseEntity<String> findAllUnconsumed(
@AuthenticationPrincipal User player
) {
List<GameState> gsList = cordaClient.gameStateList(player.getHoldingIdentity());
return ResponseEntity.ok(gsList.toString());
}
// @PostMapping()
// public ResponseEntity<String> gameproposalSend(@AuthenticationPrincipal ApiUserDetails user) {
// return ResponseEntity.ok("");
// }
@PostMapping()
public ResponseEntity<Void> createGameProposal(
@AuthenticationPrincipal User sender,
@ -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();

View File

@ -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<List<GameState>> gameStateList(
public ResponseEntity<List<GameView>> gameStateList(
@AuthenticationPrincipal User player
) {
final List<GameState> gsList = cordaClient.gameStateList(player.getHoldingIdentity());
final List<GameView> gsList = cordaClient.gameStateList(player.getHoldingIdentity());
return ResponseEntity.ok(gsList);
}

View File

@ -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<GameState> gameStateList(HoldingIdentity holdingIdentity) {
public List<GameView> 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<Integer, Stone> 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<Integer> move,
public GameView gameBoardMove(HoldingIdentity holdingIdentity, UUID gameUuid, List<Integer> 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",

View File

@ -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<Integer, Stone> board,
Integer moveNumber,

View File

@ -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 <T> {
@ -10,8 +10,8 @@ public interface Rsp <T> {
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);

View File

@ -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<GameState> {
String failureStatus) implements Rsp<GameView> {
}

View File

@ -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<GameState> successStatus,
String failureStatus) implements Rsp<List<GameState>> {
List<GameView> successStatus,
String failureStatus) implements Rsp<List<GameView>> {
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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<GameState> p1GameList = cordaClient.gameStateList(hiPlayer1);
final List<GameState> p2GameList = cordaClient.gameStateList(hiPlayer2);
final List<GameView> p1GameList = cordaClient.gameStateList(hiPlayer1);
final List<GameView> 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<GameState> gameStateList, UUID gameUuid) {
GameView findGameStateById(List<GameView> gameStateList, UUID gameUuid) {
return gameStateList
.stream()
.filter(gameView -> gameView.uuid().compareTo(gameUuid) == 0)

View File

@ -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());