1 package club.wpia.gigi.pages.admin;
3 import static org.junit.Assert.*;
4 import static org.junit.Assume.*;
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;
12 import org.junit.Test;
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;
26 public class TestSEAdminPageUserDomainSearch extends ClientTest {
30 private String domainName;
32 private String unique;
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());
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);
50 public void testDomainSearch() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException {
51 URLConnection uc = post(FindUserByDomainPage.PATH, "process&domain=" + URLEncoder.encode(domainName, "UTF-8"));
53 assertEquals("https://" + ServerConstants.getHostNamePortSecure(Host.WWW) + SupportUserDetailsPage.PATH + tid + "/", uc.getHeaderField("Location"));
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"));
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)));
69 public void testDomainSearchByIdNonExist() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException {
70 int id = (int) (Math.random() * 10000);
72 boolean found = false;
74 while (Domain.getById(id) != null && count < 20) {
76 id = (int) (Math.random() * 10000);
78 } catch (Exception e) {
82 URLConnection uc = post(FindUserByDomainPage.PATH, "process&domain=#" + id);
83 assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));