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