]> WPIA git - gigi.git/blobdiff - tests/club/wpia/gigi/testUtils/ClientTest.java
upd: rename package name and all references to it
[gigi.git] / tests / club / wpia / gigi / testUtils / ClientTest.java
diff --git a/tests/club/wpia/gigi/testUtils/ClientTest.java b/tests/club/wpia/gigi/testUtils/ClientTest.java
new file mode 100644 (file)
index 0000000..1cd12d2
--- /dev/null
@@ -0,0 +1,54 @@
+package club.wpia.gigi.testUtils;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+
+import club.wpia.gigi.dbObjects.User;
+
+/**
+ * Superclass for testsuites in a scenario where there is an registered member,
+ * who is already logged on.
+ */
+public abstract class ClientTest extends ManagedTest {
+
+    /**
+     * Email of the member.
+     */
+    protected String email = createUniqueName() + "@example.org";
+
+    /**
+     * Id of the member
+     */
+    protected int id = createVerifiedUser("a", "b", email, TEST_PASSWORD);
+
+    /**
+     * {@link User} object of the member
+     */
+    protected User u = User.getById(id);
+
+    /**
+     * Session cookie of the member.
+     */
+    protected String cookie;
+
+    public ClientTest() {
+        try {
+            cookie = login(email, TEST_PASSWORD);
+        } catch (IOException e) {
+            throw new Error(e);
+        }
+    }
+
+    public HttpURLConnection post(String path, String query) throws IOException {
+        return post(path, query, 0);
+    }
+
+    public HttpURLConnection post(String path, String query, int formIndex) throws IOException {
+        return post(cookie, path, query, formIndex);
+    }
+
+    public HttpURLConnection get(String path) throws IOException {
+        return get(cookie, path);
+    }
+
+}