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;
25 public class TestSEAdminPageUserDomainSearch extends ClientTest {
29 private String domainName;
31 private String unique;
35 public TestSEAdminPageUserDomainSearch() throws IOException, GigiApiException {
36 grant(u, Group.SUPPORTER);
37 cookie = login(email, TEST_PASSWORD);
38 assertEquals(302, post(cookie, SupportEnterTicketPage.PATH, "ticketno=a20140808.8&setTicket=action", 0).getResponseCode());
40 String mail = createUniqueName() + "@example.com";
41 tid = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
42 User user = User.getById(tid);
43 unique = createUniqueName();
44 domainName = unique + "pattern.org";
45 this.d = new Domain(user, user, domainName);
49 public void testDomainSearch() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException {
50 URLConnection uc = post(FindUserByDomainPage.PATH, "process&domain=" + URLEncoder.encode(domainName, "UTF-8"));
52 assertEquals("https://" + ServerConstants.getWwwHostNamePortSecure() + SupportUserDetailsPage.PATH + tid + "/", uc.getHeaderField("Location"));
56 public void testDomainSearchById() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException {
57 URLConnection uc = post(FindUserByDomainPage.PATH, "process&domain=#" + d.getId());
58 assertEquals("https://" + ServerConstants.getWwwHostNamePortSecure() + SupportUserDetailsPage.PATH + tid + "/", uc.getHeaderField("Location"));
62 public void testDomainSearchNonExist() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException {
63 URLConnection uc = post(FindUserByDomainPage.PATH, "process&domain=" + URLEncoder.encode(createUniqueName() + ".de", "UTF-8"));
64 assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
68 public void testDomainSearchByIdNonExist() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException {
69 int id = (int) (Math.random() * 10000);
71 boolean found = false;
73 while (Domain.getById(id) != null && count < 20) {
75 id = (int) (Math.random() * 10000);
77 } catch (Exception e) {
81 URLConnection uc = post(FindUserByDomainPage.PATH, "process&domain=#" + id);
82 assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));