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