]> WPIA git - gigi.git/blobdiff - tests/club/wpia/gigi/pages/wot/TestTTPAdmin.java
upd: rename package name and all references to it
[gigi.git] / tests / club / wpia / gigi / pages / wot / TestTTPAdmin.java
diff --git a/tests/club/wpia/gigi/pages/wot/TestTTPAdmin.java b/tests/club/wpia/gigi/pages/wot/TestTTPAdmin.java
new file mode 100644 (file)
index 0000000..2e3c386
--- /dev/null
@@ -0,0 +1,51 @@
+package club.wpia.gigi.pages.wot;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+
+import org.junit.Test;
+
+import club.wpia.gigi.GigiApiException;
+import club.wpia.gigi.dbObjects.Group;
+import club.wpia.gigi.dbObjects.User;
+import club.wpia.gigi.pages.admin.TTPAdminPage;
+import club.wpia.gigi.testUtils.ClientTest;
+
+public class TestTTPAdmin extends ClientTest {
+
+    User us2;
+
+    public TestTTPAdmin() throws IOException {
+        us2 = User.getById(createVerifiedUser("fn", "ln", createUniqueName() + "@example.com", TEST_PASSWORD));
+    }
+
+    @Test
+    public void testHasRight() throws IOException, GigiApiException {
+        testTTPAdmin(true);
+    }
+
+    @Test
+    public void testHasNoRight() throws IOException, GigiApiException {
+        testTTPAdmin(false);
+    }
+
+    public void testTTPAdmin(boolean hasRight) throws IOException, GigiApiException {
+        if (hasRight) {
+            grant(u, Group.TTP_ASSURER);
+        }
+        grant(u, TTPAdminPage.TTP_APPLICANT);
+        cookie = login(u.getEmail(), TEST_PASSWORD);
+
+        assertEquals( !hasRight ? 403 : 200, fetchStatusCode(TTPAdminPage.PATH));
+        assertEquals( !hasRight ? 403 : 200, fetchStatusCode(TTPAdminPage.PATH + "/"));
+        assertEquals( !hasRight ? 403 : 200, fetchStatusCode(TTPAdminPage.PATH + "/" + u.getId()));
+        assertEquals( !hasRight ? 403 : 404, fetchStatusCode(TTPAdminPage.PATH + "/" + us2.getId()));
+        assertEquals( !hasRight ? 403 : 404, fetchStatusCode(TTPAdminPage.PATH + "/" + 100));
+    }
+
+    private int fetchStatusCode(String path) throws MalformedURLException, IOException {
+        return get(path).getResponseCode();
+    }
+}