]> WPIA git - gigi.git/blob - tests/org/cacert/gigi/testUtils/ClientTest.java
add: more strict ticket handling. User history page
[gigi.git] / tests / org / cacert / gigi / testUtils / ClientTest.java
1 package org.cacert.gigi.testUtils;
2
3 import java.io.IOException;
4 import java.net.HttpURLConnection;
5 import java.net.URL;
6 import java.net.URLConnection;
7
8 import org.cacert.gigi.dbObjects.User;
9
10 /**
11  * Superclass for testsuites in a scenario where there is an registered member,
12  * who is already logged on.
13  */
14 public abstract class ClientTest extends ManagedTest {
15
16     /**
17      * Email of the member.
18      */
19     protected String email = createUniqueName() + "@example.org";
20
21     /**
22      * Id of the member
23      */
24     protected int id = createVerifiedUser("a", "b", email, TEST_PASSWORD);
25
26     /**
27      * {@link User} object of the member
28      */
29     protected User u = User.getById(id);
30
31     /**
32      * Session cookie of the member.
33      */
34     protected String cookie;
35
36     public ClientTest() {
37         try {
38             cookie = login(email, TEST_PASSWORD);
39         } catch (IOException e) {
40             throw new Error(e);
41         }
42     }
43
44     public HttpURLConnection post(String path, String query) throws IOException {
45         return post(path, query, 0);
46     }
47
48     public HttpURLConnection post(String path, String query, int formIndex) throws IOException {
49         return post(cookie, path, query, formIndex);
50     }
51
52     public HttpURLConnection get(String path) throws IOException {
53         return get(path, 0);
54     }
55
56     public HttpURLConnection get(String path, int formIndex) throws IOException {
57         URLConnection uc = new URL("https://" + getServerName() + path).openConnection();
58         uc.addRequestProperty("Cookie", cookie);
59         return (HttpURLConnection) uc;
60     }
61
62 }