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