-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an integration test going through the API
- Loading branch information
Showing
31 changed files
with
850 additions
and
185 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ spring: | |
- "default_player" | ||
- "default_server" | ||
- "server" | ||
- "fake_player" | ||
- "fake_player" | ||
- inject_default_games |
102 changes: 102 additions & 0 deletions
102
monolith/src/test/java/eu/solven/kumite/app/it/TestTSPLifecycleThroughRouter.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,102 @@ | ||
package eu.solven.kumite.app.it; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.web.server.LocalServerPort; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.TestPropertySource; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
|
||
import eu.solven.kumite.app.IKumiteServer; | ||
import eu.solven.kumite.app.IKumiteSpringProfiles; | ||
import eu.solven.kumite.app.KumiteServerApplication; | ||
import eu.solven.kumite.app.KumiteWebclientServer; | ||
import eu.solven.kumite.contest.ContestSearchParameters; | ||
import eu.solven.kumite.game.GameSearchParameters; | ||
import eu.solven.kumite.player.PlayerRawMovesHolder; | ||
import lombok.extern.slf4j.Slf4j; | ||
import reactor.core.publisher.Mono; | ||
|
||
/** | ||
* This integration-test serves 2 purposes: first it shows how one can chain call to play a game: it can help ensure the | ||
* API is stable and simple; second, it ensures the API is actually functional (e.g. up to serializibility of involved | ||
* classes). | ||
* | ||
* @author Benoit Lacelle | ||
* @see 'TestTSPLifecycle' | ||
*/ | ||
// Should this move to `monolith` module? | ||
@ExtendWith(SpringExtension.class) | ||
@SpringBootTest(classes = KumiteServerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
@ActiveProfiles({ IKumiteSpringProfiles.P_DEFAULT, IKumiteSpringProfiles.P_DEFAULT_FAKE_PLAYER, }) | ||
@TestPropertySource(properties = { "kumite.random.seed=123", | ||
"kumite.server.base-url=http://localhost:LocalServerPort", | ||
"kumite.random.seed=123" }) | ||
@Slf4j | ||
public class TestTSPLifecycleThroughRouter { | ||
|
||
// https://stackoverflow.com/questions/30312058/spring-boot-how-to-get-the-running-port | ||
@LocalServerPort | ||
int randomServerPort; | ||
|
||
@Autowired | ||
Environment env; | ||
|
||
@Test | ||
public void testSinglePlayer() { | ||
IKumiteServer kumiteServer = new KumiteWebclientServer(env, randomServerPort); | ||
|
||
UUID playerId = env.getRequiredProperty("kumite.playerId", UUID.class); | ||
|
||
kumiteServer | ||
// Search for games given a human-friendly pattern | ||
.searchGames(GameSearchParameters.builder().titleRegex(Optional.of(".*Salesman.*")).build()) | ||
// Search for contest | ||
.flatMap(game -> { | ||
log.info("Processing game={}", game); | ||
return kumiteServer.searchContests( | ||
ContestSearchParameters.builder().gameId(Optional.of(game.getGameId())).build()); | ||
}) | ||
// Filter relevant contests | ||
.filter(c -> { | ||
// log.info("c={}", c); | ||
return true; | ||
}) | ||
.filter(c -> c.getDynamicMetadata().isAcceptingPlayers()) | ||
.filter(c -> !c.getDynamicMetadata().isGameOver()) | ||
// Join each relevant contest | ||
.flatMap(contest -> { | ||
log.info("Joining contest={}", contest); | ||
return kumiteServer.joinContest(playerId, contest.getContestId()).flatMap(playerPlayer -> { | ||
log.info("playerPlayer={}", playerPlayer); | ||
|
||
return kumiteServer.loadBoard(playerId, contest.getContestId()).flatMap(joinedContest -> { | ||
log.info("Received board for contest={}", joinedContest.getContestId()); | ||
|
||
Mono<PlayerRawMovesHolder> exampleMoves = | ||
kumiteServer.getExampleMoves(playerId, joinedContest.getContestId()); | ||
|
||
return exampleMoves.flatMap(moves -> { | ||
Optional<Map<String, ?>> someMove = moves.getMoves().values().stream().findAny(); | ||
return Mono.justOrEmpty(someMove); | ||
}).flatMap(move -> { | ||
return kumiteServer.playMove(playerId, joinedContest.getContestId(), move); | ||
}); | ||
}); | ||
}); | ||
}) | ||
|
||
.doOnError(t -> { | ||
log.error("Something went wrong", t); | ||
}) | ||
.then() | ||
.block(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
kumite.playerId: 11111111-1111-1111-1111-111111111111 | ||
kumite.server: | ||
access_token: someAccessTokenForFakePlayer | ||
# See FakePlayerTokens in server module to regenerate this | ||
access_token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMTExMTExMS0xMTExLTExMTEtMTExMS0xMTExMTExMTExMTIiLCJhdWQiOiJLdW1pdGUtU2VydmVyIiwibmJmIjoxNzI2MDYyNTc3LCJtYWluUGxheWVySWQiOiIxMTExMTExMS0xMTExLTExMTEtMTExMS0xMTExMTExMTExMTEiLCJpc3MiOiJodHRwczovL2t1bWl0ZS5jb20iLCJleHAiOjE3NTc1OTg1NzcsImlhdCI6MTcyNjA2MjU3NywianRpIjoiYmIyMGI0NWYtZDRkOS00MTM4LWJkOTMtY2I3OTliMzk3MGJlIn0.u0Vq43b_Vztoy0I-0mgILHi8yoHwQvcKcq9kyKoqWVM' |
22 changes: 13 additions & 9 deletions
22
public/src/main/java/eu/solven/kumite/contest/ContestView.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 |
---|---|---|
@@ -1,30 +1,34 @@ | ||
package eu.solven.kumite.contest; | ||
|
||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
import eu.solven.kumite.board.IKumiteBoardView; | ||
import eu.solven.kumite.player.PlayingPlayer; | ||
import lombok.Builder; | ||
import lombok.NonNull; | ||
import lombok.Value; | ||
import lombok.extern.jackson.Jacksonized; | ||
|
||
/** | ||
* A snapshot of the Contest | ||
* | ||
* @author Benoit Lacelle | ||
* | ||
*/ | ||
@Value | ||
@Builder | ||
@Jacksonized | ||
public class ContestView { | ||
@NonNull | ||
UUID contestId; | ||
UUID playerId; | ||
|
||
ContestDynamicMetadata dynamicMetadata; | ||
|
||
IKumiteBoardView board; | ||
|
||
@NonNull | ||
Boolean playerHasJoined; | ||
PlayingPlayer playingPlayer; | ||
|
||
@NonNull | ||
Boolean playerCanJoin; | ||
ContestDynamicMetadata dynamicMetadata; | ||
|
||
// Could be turned into a IKumiteBoardView by an IGame | ||
@NonNull | ||
Boolean accountIsViewing; | ||
Map<String, ?> board; | ||
} |
Oops, something went wrong.