]> WPIA git - gigi.git/blob - tests/club/wpia/gigi/pages/wot/TestTTPAdmin.java
Merge "upd: terminology in API"
[gigi.git] / tests / club / wpia / gigi / pages / wot / TestTTPAdmin.java
1 package club.wpia.gigi.pages.wot;
2
3 import static org.junit.Assert.*;
4
5 import java.io.IOException;
6 import java.net.MalformedURLException;
7
8 import org.junit.Test;
9
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;
15
16 public class TestTTPAdmin extends ClientTest {
17
18     User us2;
19
20     public TestTTPAdmin() throws IOException {
21         us2 = User.getById(createVerifiedUser("fn", "ln", createUniqueName() + "@example.com", TEST_PASSWORD));
22     }
23
24     @Test
25     public void testHasRight() throws IOException, GigiApiException {
26         testTTPAdmin(true);
27     }
28
29     @Test
30     public void testHasNoRight() throws IOException, GigiApiException {
31         testTTPAdmin(false);
32     }
33
34     public void testTTPAdmin(boolean hasRight) throws IOException, GigiApiException {
35         if (hasRight) {
36             grant(u, Group.TTP_AGENT);
37         }
38         grant(u, TTPAdminPage.TTP_APPLICANT);
39         cookie = login(u.getEmail(), TEST_PASSWORD);
40
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));
46     }
47
48     private int fetchStatusCode(String path) throws MalformedURLException, IOException {
49         return get(path).getResponseCode();
50     }
51 }