From 74176ecf4582bc89f0755b86152ad1b48cea9cd0 Mon Sep 17 00:00:00 2001 From: djmil Date: Fri, 22 Sep 2023 14:55:53 +0200 Subject: [PATCH] HoldingIdentityResolver Test --- .../HoldingIdentityResolverTests.java | 67 +++++++++++++++++++ .../cordaclient/GameBoardTests.java | 36 ---------- .../cordaclient/GameStateTests.java | 21 ++---- 3 files changed, 73 insertions(+), 51 deletions(-) create mode 100644 backend/src/test/java/djmil/cordacheckers/HoldingIdentityResolverTests.java diff --git a/backend/src/test/java/djmil/cordacheckers/HoldingIdentityResolverTests.java b/backend/src/test/java/djmil/cordacheckers/HoldingIdentityResolverTests.java new file mode 100644 index 0000000..b39a7e7 --- /dev/null +++ b/backend/src/test/java/djmil/cordacheckers/HoldingIdentityResolverTests.java @@ -0,0 +1,67 @@ +package djmil.cordacheckers; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import djmil.cordacheckers.user.HoldingIdentityResolver; + +@SpringBootTest +public class HoldingIdentityResolverTests { + + @Autowired + HoldingIdentityResolver holdingIdentityResolver; + + /* + * The test is expecting that CSDE static-network-config.json to look like stated below. + * Important bits: + * - the contents of 'CN', 'OU', 'O' fields + * - there shall be only one Custodian + */ +/* + [ + { + "x500Name" : "CN=Alice, OU=Player, O=Checkers, L=Zug, C=CH", + "cpi" : "CordaCheckers" + }, + { + "x500Name" : "CN=Bob, OU=Player, O=Checkers, L=Kyiv, C=UA", + "cpi" : "CordaCheckers" + }, + { + "x500Name" : "CN=Charlie, OU=Player, O=Checkers, L=London, C=GB", + "cpi" : "CordaCheckers" + }, + { + "x500Name" : "CN=Kumar, OU=Custodian, O=Checkers, L=Mumbai, C=IN", + "cpi" : "CordaCheckers" + }, + { + "x500Name" : "CN=NotaryRep1, OU=Test Dept, O=R3, L=London, C=GB", + "cpi" : "NotaryServer", + "serviceX500Name": "CN=NotaryService, OU=Test Dept, O=R3, L=London, C=GB" + } + ] +*/ + + @Test + void testCheckUsers() { + assertDoesNotThrow( () -> { + holdingIdentityResolver.getByUsername("alice"); + holdingIdentityResolver.getByUsername("BOB"); + holdingIdentityResolver.getByUsername("Charlie"); + }); + + assertThat(holdingIdentityResolver.getByUsername("SomeRundomName")).isNull(); + } + + @Test + void testCustodian() { + assertThat(holdingIdentityResolver.getByUsername("Kumar")).isNull(); + assertThat(holdingIdentityResolver.getCustodian()).isNotNull(); + } + +} diff --git a/backend/src/test/java/djmil/cordacheckers/cordaclient/GameBoardTests.java b/backend/src/test/java/djmil/cordacheckers/cordaclient/GameBoardTests.java index 6bc74a8..6a8437c 100644 --- a/backend/src/test/java/djmil/cordacheckers/cordaclient/GameBoardTests.java +++ b/backend/src/test/java/djmil/cordacheckers/cordaclient/GameBoardTests.java @@ -60,40 +60,4 @@ public class GameBoardTests { assertThat(winnerGameView.status()).isEqualByComparingTo(Status.GAME_RESULT_YOU_WON); } - // @Test - // void testGameBoardMove() throws JsonMappingException, JsonProcessingException, InvalidNameException { - // final var hiAlice = holdingIdentityResolver.getByUsername("alice"); - // final var hiBob = holdingIdentityResolver.getByUsername("bob"); - // final var bobColor = Piece.Color.WHITE; - - // final UUID gpUuid = cordaClient.gameProposalCreate( - // hiAlice, hiBob, - // bobColor, "GameBoard MOVE test" - // ); - - // System.out.println("New GameProposal UUID "+ gpUuid); - - // final GameBoard gbState = cordaClient.gameProposalAccept( - // hiBob, gpUuid - // ); - - // System.out.println("New GameBoard UUID "+ gbState.gameUuid()); - - // assertThatThrownBy(() -> { // Alice can not move, since it is Bob's turn - // cordaClient.gameBoardMove( - // hiAlice, gbState.gameUuid(), - // Arrays.asList(1, 2)); - // }); - - // final GameBoard gameBoard = cordaClient.gameBoardMove( - // hiBob, gbState.gameUuid(), Arrays.asList(1, 2)); - // } - - // private T findByUuid(List statesList, UUID uuid) { - // for (T state : statesList) { - // if (state.uuid().compareTo(uuid) == 0) - // return state; - // }; - // return null; - // } } diff --git a/backend/src/test/java/djmil/cordacheckers/cordaclient/GameStateTests.java b/backend/src/test/java/djmil/cordacheckers/cordaclient/GameStateTests.java index 1c2f740..d466705 100644 --- a/backend/src/test/java/djmil/cordacheckers/cordaclient/GameStateTests.java +++ b/backend/src/test/java/djmil/cordacheckers/cordaclient/GameStateTests.java @@ -1,20 +1,14 @@ package djmil.cordacheckers.cordaclient; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.List; import java.util.UUID; -import javax.naming.InvalidNameException; - import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import com.fasterxml.jackson.core.JsonProcessingException; - import djmil.cordacheckers.cordaclient.dao.GameState; -import djmil.cordacheckers.cordaclient.dao.VirtualNode; +import djmil.cordacheckers.cordaclient.dao.Piece; import djmil.cordacheckers.user.HoldingIdentityResolver; @SpringBootTest @@ -25,15 +19,12 @@ public class GameStateTests { @Autowired HoldingIdentityResolver holdingIdentityResolver; - @Test - void testGetVirtualNodeList() throws InvalidNameException { - List vNodes = cordaClient.getVirtualNodeList(); - - assertThat(vNodes.size()).isEqualTo(5); // default vNode config for CSDE - } + final String issuer = "alice"; + final String acquier = "bob"; + final Piece.Color acquierColor = Piece.Color.WHITE; @Test - void testList() throws JsonProcessingException { + void testList() { List gsList = cordaClient.gameStateList( holdingIdentityResolver.getByUsername("bob")); @@ -41,7 +32,7 @@ public class GameStateTests { } @Test - void testGet() throws JsonProcessingException { + void testGet() { GameState gameStateView = cordaClient.gameStateGet( holdingIdentityResolver.getByUsername("bob"), UUID.fromString("cf357d0a-8f64-4599-b9b5-d263163812d4")