summaryrefslogtreecommitdiff
path: root/backend/src/test
diff options
context:
space:
mode:
authorjbion <joffrey.bion@amadeus.com>2017-05-25 03:24:39 +0200
committerjbion <joffrey.bion@amadeus.com>2017-05-25 03:24:39 +0200
commit91f5dc539958743b6a2a110681e76cd9c3a250f3 (patch)
tree822ba2944d4e1b91239e31a566bcc83ef5f5950b /backend/src/test
parentAdd a simple JSON+STOMP client (to be extracted as lib) (diff)
downloadseven-wonders-91f5dc539958743b6a2a110681e76cd9c3a250f3.tar.gz
seven-wonders-91f5dc539958743b6a2a110681e76cd9c3a250f3.tar.bz2
seven-wonders-91f5dc539958743b6a2a110681e76cd9c3a250f3.zip
Add a java API for SevenWonders using the simple JSON/STOMP client
This API is intended to be used for integration tests, but could later be extracted and used for AI actions or machine learning.
Diffstat (limited to 'backend/src/test')
-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