]> WPIA git - gigi.git/blob - tests/club/wpia/gigi/pages/admin/TestSEAdminPageUserMailSearch.java
chg: create superclass for SE tests
[gigi.git] / tests / club / wpia / gigi / pages / admin / TestSEAdminPageUserMailSearch.java
1 package club.wpia.gigi.pages.admin;
2
3 import static org.hamcrest.CoreMatchers.*;
4 import static org.junit.Assert.*;
5
6 import java.io.IOException;
7 import java.io.UnsupportedEncodingException;
8 import java.net.MalformedURLException;
9 import java.net.URLConnection;
10 import java.net.URLEncoder;
11
12 import org.junit.Test;
13
14 import club.wpia.gigi.GigiApiException;
15 import club.wpia.gigi.dbObjects.User;
16 import club.wpia.gigi.pages.admin.support.FindUserByEmailPage;
17 import club.wpia.gigi.pages.admin.support.SupportUserDetailsPage;
18 import club.wpia.gigi.testUtils.IOUtils;
19 import club.wpia.gigi.testUtils.SEClientTest;
20 import club.wpia.gigi.util.ServerConstants;
21 import club.wpia.gigi.util.ServerConstants.Host;
22
23 public class TestSEAdminPageUserMailSearch extends SEClientTest {
24
25     public TestSEAdminPageUserMailSearch() throws IOException, GigiApiException {}
26
27     @Test
28     public void testFulltextMailSearch() throws MalformedURLException, UnsupportedEncodingException, IOException {
29         String mail = createUniqueName() + "@example.com";
30         int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
31
32         URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode(mail, "UTF-8"), 0);
33         assertEquals("https://" + ServerConstants.getHostNamePortSecure(Host.WWW) + SupportUserDetailsPage.PATH + id + "/", uc.getHeaderField("Location"));
34     }
35
36     @Test
37     public void testWildcardMailSearchSingle() throws MalformedURLException, UnsupportedEncodingException, IOException {
38         String mail = createUniqueName() + "@example.tld";
39         int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
40
41         URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@example.tld", "UTF-8"), 0);
42         assertEquals("https://" + ServerConstants.getHostNamePortSecure(Host.WWW) + SupportUserDetailsPage.PATH + id + "/", uc.getHeaderField("Location"));
43     }
44
45     @Test
46     public void testWildcardMailSearchMultiple() throws MalformedURLException, UnsupportedEncodingException, IOException {
47         String mail = createUniqueName() + "@example.org";
48         int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
49         String mail2 = createUniqueName() + "@example.org";
50         int id2 = createVerifiedUser("Först", "Secönd", mail2, TEST_PASSWORD);
51         URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@example.org", "UTF-8"), 0);
52
53         String res = IOUtils.readURL(uc);
54         assertThat(res, containsString(SupportUserDetailsPage.PATH + id + "/"));
55         assertThat(res, containsString(SupportUserDetailsPage.PATH + id2 + "/"));
56     }
57
58     @Test
59     public void testWildcardMailSearchSingleChar() throws MalformedURLException, UnsupportedEncodingException, IOException {
60         String mail = createUniqueName() + "@example.org";
61         int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
62         String mail2 = createUniqueName() + "@fxample.org";
63         int id2 = createVerifiedUser("Först", "Secönd", mail2, TEST_PASSWORD);
64
65         URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@_xample.org", "UTF-8"), 0);
66
67         String res = IOUtils.readURL(uc);
68         assertThat(res, containsString(SupportUserDetailsPage.PATH + id + "/"));
69         assertThat(res, containsString(SupportUserDetailsPage.PATH + id2 + "/"));
70     }
71
72     @Test
73     public void testWildcardMailSearchNoRes() throws MalformedURLException, UnsupportedEncodingException, IOException {
74         URLConnection uc = post(FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@_humpfelkumpf.org", "UTF-8"));
75         assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
76     }
77
78     @Test
79     public void testFulltextMailSearchNoRes() throws MalformedURLException, UnsupportedEncodingException, IOException {
80         URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode(createUniqueName() + "@example.org", "UTF-8"), 0);
81
82         assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
83     }
84
85     @Test
86     public void testSearchSecondEmailAddress() throws MalformedURLException, UnsupportedEncodingException, IOException, InterruptedException, GigiApiException {
87         String mail = createUniqueName() + "@example1.org";
88         int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
89         User testuser = User.getById(id);
90         String mail2 = createUniqueName() + "@example1.org";
91         createVerifiedEmail(testuser, mail2);
92
93         URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode(mail2, "UTF-8"), 0);
94         assertEquals("https://" + ServerConstants.getHostNamePortSecure(Host.WWW) + SupportUserDetailsPage.PATH + id + "/", uc.getHeaderField("Location"));
95     }
96
97     @Test
98     public void testWildcardMailSearchSecondEmailAddress() throws MalformedURLException, UnsupportedEncodingException, IOException, InterruptedException, GigiApiException {
99         clearCaches();
100         String mail = createUniqueName() + "@example2.org";
101         int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
102         User testuser = User.getById(id);
103         String mail2 = createUniqueName() + "@example2.org";
104         createVerifiedEmail(testuser, mail2);
105
106         URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@example2.org", "UTF-8"), 0);
107
108         String res = IOUtils.readURL(uc);
109         assertThat(res, containsString(mail));
110         assertThat(res, containsString(mail2));
111     }
112
113     @Test
114     public void testWildcardMailSearchMultipleEmailAddressOneAccount() throws MalformedURLException, UnsupportedEncodingException, IOException, InterruptedException, GigiApiException {
115         clearCaches();
116         String mail = createUniqueName() + "@example3.org";
117         int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
118         User testuser = User.getById(id);
119         String mail2 = createUniqueName() + "@test3.org";
120         createVerifiedEmail(testuser, mail2);
121         String mail3 = createUniqueName() + "@test3.org";
122         createVerifiedEmail(testuser, mail3);
123
124         URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@example3.org", "UTF-8"), 0);
125         assertEquals("https://" + ServerConstants.getHostNamePortSecure(Host.WWW) + SupportUserDetailsPage.PATH + id + "/", uc.getHeaderField("Location"));
126
127         uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@test3.org", "UTF-8"), 0);
128
129         String res = IOUtils.readURL(uc);
130         assertThat(res, not(containsString(mail)));
131         assertThat(res, containsString(mail2));
132         assertThat(res, containsString(mail3));
133     }
134
135     @Test
136     public void testWildcardMailSearchMultipleEmailAddressMultipleAccounts() throws MalformedURLException, UnsupportedEncodingException, IOException, InterruptedException, GigiApiException {
137         String mail = createUniqueName() + "1@example4.org";
138         int id = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
139         User testuser = User.getById(id);
140         String mail2 = createUniqueName() + "@test4.org";
141         createVerifiedEmail(testuser, mail2);
142
143         String mail3 = createUniqueName() + "2@example4.org";
144         int id2 = createVerifiedUser("Först", "Secönd", mail3, TEST_PASSWORD);
145         User testuser2 = User.getById(id2);
146         String mail4 = createUniqueName() + "@test4.org";
147         createVerifiedEmail(testuser2, mail4);
148
149         URLConnection uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@example4.org", "UTF-8"), 0);
150
151         String res = IOUtils.readURL(uc);
152         assertThat(res, containsString(mail));
153         assertThat(res, not(containsString(mail2)));
154         assertThat(res, containsString(mail3));
155         assertThat(res, not(containsString(mail4)));
156
157         uc = post(cookie, FindUserByEmailPage.PATH, "process&email=" + URLEncoder.encode("%@test4.org", "UTF-8"), 0);
158
159         res = IOUtils.readURL(uc);
160         assertThat(res, not(containsString(mail)));
161         assertThat(res, containsString(mail2));
162         assertThat(res, not(containsString(mail3)));
163         assertThat(res, containsString(mail4));
164     }
165 }