]> WPIA git - gigi.git/blob - tests/club/wpia/gigi/pages/admin/TestSEAdminPageUserDomainSearch.java
chg: create superclass for SE tests
[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.User;
18 import club.wpia.gigi.pages.admin.support.FindUserByDomainPage;
19 import club.wpia.gigi.pages.admin.support.SupportUserDetailsPage;
20 import club.wpia.gigi.testUtils.IOUtils;
21 import club.wpia.gigi.testUtils.SEClientTest;
22 import club.wpia.gigi.util.ServerConstants;
23 import club.wpia.gigi.util.ServerConstants.Host;
24
25 public class TestSEAdminPageUserDomainSearch extends SEClientTest {
26
27     private Domain d;
28
29     private String domainName;
30
31     private String unique;
32
33     private int tid;
34
35     public TestSEAdminPageUserDomainSearch() throws IOException, GigiApiException {
36         String mail = createUniqueName() + "@example.com";
37         tid = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
38         User user = User.getById(tid);
39         unique = createUniqueName();
40         domainName = unique + "pattern.org";
41         this.d = new Domain(user, user, domainName);
42     }
43
44     @Test
45     public void testDomainSearch() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException {
46         URLConnection uc = post(FindUserByDomainPage.PATH, "process&domain=" + URLEncoder.encode(domainName, "UTF-8"));
47
48         assertEquals("https://" + ServerConstants.getHostNamePortSecure(Host.WWW) + SupportUserDetailsPage.PATH + tid + "/", uc.getHeaderField("Location"));
49     }
50
51     @Test
52     public void testDomainSearchById() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException {
53         URLConnection uc = post(FindUserByDomainPage.PATH, "process&domain=#" + d.getId());
54         assertEquals("https://" + ServerConstants.getHostNamePortSecure(Host.WWW) + SupportUserDetailsPage.PATH + tid + "/", uc.getHeaderField("Location"));
55     }
56
57     @Test
58     public void testDomainSearchNonExist() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException {
59         URLConnection uc = post(FindUserByDomainPage.PATH, "process&domain=" + URLEncoder.encode(createUniqueName() + ".de", "UTF-8"));
60         assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
61     }
62
63     @Test
64     public void testDomainSearchByIdNonExist() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException {
65         int id = (int) (Math.random() * 10000);
66         int count = 0;
67         while (Domain.getById(id) != null && count < 20) {
68             count++;
69             id = (int) (Math.random() * 10000);
70         }
71         Assume.assumeThat(Domain.getById(id), CoreMatchers.nullValue());
72         URLConnection uc = post(FindUserByDomainPage.PATH, "process&domain=#" + id);
73         assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
74     }
75 }