]> WPIA git - gigi.git/blob - tests/club/wpia/gigi/pages/admin/TestSEAdminPageUserDomainSearch.java
75741650aeecfe25f11df1f94b049e7ebc9f34c5
[gigi.git] / tests / club / wpia / gigi / pages / admin / TestSEAdminPageUserDomainSearch.java
1 package club.wpia.gigi.pages.admin;
2
3 import static org.junit.Assert.*;
4
5 import java.io.IOException;
6 import java.io.UnsupportedEncodingException;
7 import java.net.MalformedURLException;
8 import java.net.URLConnection;
9 import java.net.URLEncoder;
10
11 import org.hamcrest.CoreMatchers;
12 import org.junit.Assume;
13 import org.junit.Test;
14
15 import club.wpia.gigi.GigiApiException;
16 import club.wpia.gigi.dbObjects.Domain;
17 import club.wpia.gigi.dbObjects.Group;
18 import club.wpia.gigi.dbObjects.User;
19 import club.wpia.gigi.pages.admin.support.FindUserByDomainPage;
20 import club.wpia.gigi.pages.admin.support.SupportEnterTicketPage;
21 import club.wpia.gigi.pages.admin.support.SupportUserDetailsPage;
22 import club.wpia.gigi.testUtils.ClientTest;
23 import club.wpia.gigi.testUtils.IOUtils;
24 import club.wpia.gigi.util.ServerConstants;
25 import club.wpia.gigi.util.ServerConstants.Host;
26
27 public class TestSEAdminPageUserDomainSearch extends ClientTest {
28
29     private Domain d;
30
31     private String domainName;
32
33     private String unique;
34
35     private int tid;
36
37     public TestSEAdminPageUserDomainSearch() throws IOException, GigiApiException {
38         grant(u, Group.SUPPORTER);
39         cookie = login(email, TEST_PASSWORD);
40         assertEquals(302, post(cookie, SupportEnterTicketPage.PATH, "ticketno=a20140808.8&setTicket=action", 0).getResponseCode());
41
42         String mail = createUniqueName() + "@example.com";
43         tid = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
44         User user = User.getById(tid);
45         unique = createUniqueName();
46         domainName = unique + "pattern.org";
47         this.d = new Domain(user, user, domainName);
48     }
49
50     @Test
51     public void testDomainSearch() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException {
52         URLConnection uc = post(FindUserByDomainPage.PATH, "process&domain=" + URLEncoder.encode(domainName, "UTF-8"));
53
54         assertEquals("https://" + ServerConstants.getHostNamePortSecure(Host.WWW) + SupportUserDetailsPage.PATH + tid + "/", uc.getHeaderField("Location"));
55     }
56
57     @Test
58     public void testDomainSearchById() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException {
59         URLConnection uc = post(FindUserByDomainPage.PATH, "process&domain=#" + d.getId());
60         assertEquals("https://" + ServerConstants.getHostNamePortSecure(Host.WWW) + SupportUserDetailsPage.PATH + tid + "/", uc.getHeaderField("Location"));
61     }
62
63     @Test
64     public void testDomainSearchNonExist() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException {
65         URLConnection uc = post(FindUserByDomainPage.PATH, "process&domain=" + URLEncoder.encode(createUniqueName() + ".de", "UTF-8"));
66         assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
67     }
68
69     @Test
70     public void testDomainSearchByIdNonExist() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException {
71         int id = (int) (Math.random() * 10000);
72         int count = 0;
73         while (Domain.getById(id) != null && count < 20) {
74             count++;
75             id = (int) (Math.random() * 10000);
76         }
77         Assume.assumeThat(Domain.getById(id), CoreMatchers.nullValue());
78         URLConnection uc = post(FindUserByDomainPage.PATH, "process&domain=#" + id);
79         assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
80     }
81 }