1 package club.wpia.gigi.pages.wot;
3 import static org.junit.Assert.*;
5 import java.io.IOException;
6 import java.net.MalformedURLException;
10 import club.wpia.gigi.GigiApiException;
11 import club.wpia.gigi.dbObjects.Group;
12 import club.wpia.gigi.dbObjects.User;
13 import club.wpia.gigi.pages.admin.TTPAdminPage;
14 import club.wpia.gigi.testUtils.ClientTest;
16 public class TestTTPAdmin extends ClientTest {
20 public TestTTPAdmin() throws IOException {
21 us2 = User.getById(createVerifiedUser("fn", "ln", createUniqueName() + "@example.com", TEST_PASSWORD));
25 public void testHasRight() throws IOException, GigiApiException {
30 public void testHasNoRight() throws IOException, GigiApiException {
34 public void testTTPAdmin(boolean hasRight) throws IOException, GigiApiException {
36 grant(u, Group.TTP_ASSURER);
38 grant(u, TTPAdminPage.TTP_APPLICANT);
39 cookie = login(u.getEmail(), TEST_PASSWORD);
41 assertEquals( !hasRight ? 403 : 200, fetchStatusCode(TTPAdminPage.PATH));
42 assertEquals( !hasRight ? 403 : 200, fetchStatusCode(TTPAdminPage.PATH + "/"));
43 assertEquals( !hasRight ? 403 : 200, fetchStatusCode(TTPAdminPage.PATH + "/" + u.getId()));
44 assertEquals( !hasRight ? 403 : 404, fetchStatusCode(TTPAdminPage.PATH + "/" + us2.getId()));
45 assertEquals( !hasRight ? 403 : 404, fetchStatusCode(TTPAdminPage.PATH + "/" + 100));
48 private int fetchStatusCode(String path) throws MalformedURLException, IOException {
49 return get(path).getResponseCode();