summaryrefslogtreecommitdiff
path: root/backend/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'backend/src/test/java')
-rw-r--r--backend/src/test/java/org/luxons/sevenwonders/test/api/ApiLobby.java24
-rw-r--r--backend/src/test/java/org/luxons/sevenwonders/test/api/ApiPlayer.java (renamed from backend/src/test/java/org/luxons/sevenwonders/test/ClientPlayer.java)4
-rw-r--r--backend/src/test/java/org/luxons/sevenwonders/test/api/SevenWondersSession.java61
3 files changed, 87 insertions, 2 deletions
diff --git a/backend/src/test/java/org/luxons/sevenwonders/test/api/ApiLobby.java b/backend/src/test/java/org/luxons/sevenwonders/test/api/ApiLobby.java
new file mode 100644
index 00000000..9ce9a5d7
--- /dev/null
+++ b/backend/src/test/java/org/luxons/sevenwonders/test/api/ApiLobby.java
@@ -0,0 +1,24 @@
+package org.luxons.sevenwonders.test.api;
+
+public class ApiLobby {
+
+ private long id;
+
+ private String name;
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
diff --git a/backend/src/test/java/org/luxons/sevenwonders/test/ClientPlayer.java b/backend/src/test/java/org/luxons/sevenwonders/test/api/ApiPlayer.java
index 4f5eebcf..dcf7ec03 100644
--- a/backend/src/test/java/org/luxons/sevenwonders/test/ClientPlayer.java
+++ b/backend/src/test/java/org/luxons/sevenwonders/test/api/ApiPlayer.java
@@ -1,6 +1,6 @@
-package org.luxons.sevenwonders.test;
+package org.luxons.sevenwonders.test.api;
-public class ClientPlayer {
+public class ApiPlayer {
private String username;
diff --git a/backend/src/test/java/org/luxons/sevenwonders/test/api/SevenWondersSession.java b/backend/src/test/java/org/luxons/sevenwonders/test/api/SevenWondersSession.java
new file mode 100644
index 00000000..4f67c49f
--- /dev/null
+++ b/backend/src/test/java/org/luxons/sevenwonders/test/api/SevenWondersSession.java
@@ -0,0 +1,61 @@
+package org.luxons.sevenwonders.test.api;
+
+import org.luxons.sevenwonders.actions.ChooseNameAction;
+import org.luxons.sevenwonders.actions.CreateGameAction;
+import org.luxons.sevenwonders.actions.JoinGameAction;
+import org.luxons.sevenwonders.test.client.JsonStompSession;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class SevenWondersSession {
+
+ private final JsonStompSession session;
+
+ public SevenWondersSession(JsonStompSession session) {
+ this.session = session;
+ }
+
+ public void disconnect() {
+ session.disconnect();
+ }
+
+ public ApiPlayer chooseName(String displayName) throws Exception {
+ ChooseNameAction action = new ChooseNameAction();
+ action.setPlayerName(displayName);
+
+ ApiPlayer player = session.request("/app/chooseName", action, "/user/queue/nameChoice", ApiPlayer.class);
+ assertNotNull(player);
+ assertEquals(displayName, player.getDisplayName());
+
+ return player;
+ }
+
+ public ApiLobby createGame(String gameName) throws InterruptedException {
+ CreateGameAction action = new CreateGameAction();
+ action.setGameName(gameName);
+
+ ApiLobby lobby = session.request("/app/lobby/create", action, "/user/queue/lobby/joined", ApiLobby.class);
+ assertNotNull(lobby);
+ assertEquals(gameName, lobby.getName());
+ return lobby;
+ }
+
+ public ApiLobby joinGame(long gameId) throws InterruptedException {
+ JoinGameAction action = new JoinGameAction();
+ action.setGameId(gameId);
+
+ ApiLobby lobby = session.request("/app/lobby/join", action, "/user/queue/lobby/joined", ApiLobby.class);
+ assertNotNull(lobby);
+ assertEquals(gameId, lobby.getId());
+ return lobby;
+ }
+
+ public void startGame(long gameId) throws InterruptedException {
+ String sendDestination = "/app/lobby/startGame";
+ String receiveDestination = "/topic/lobby/" + gameId + "/started";
+ boolean received = session.request(sendDestination, null, receiveDestination);
+ assertTrue(received);
+ }
+}
bgstack15