1 package club.wpia.gigi.pages.admin;
3 import static org.junit.Assert.*;
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;
11 import org.hamcrest.CoreMatchers;
12 import org.junit.Assume;
13 import org.junit.Test;
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;
25 public class TestSEAdminPageUserDomainSearch extends SEClientTest {
29 private String domainName;
31 private String unique;
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);
45 public void testDomainSearch() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException {
46 URLConnection uc = post(FindUserByDomainPage.PATH, "process&domain=" + URLEncoder.encode(domainName, "UTF-8"));
48 assertEquals("https://" + ServerConstants.getHostNamePortSecure(Host.WWW) + SupportUserDetailsPage.PATH + tid + "/", uc.getHeaderField("Location"));
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"));
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)));
64 public void testDomainSearchByIdNonExist() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException {
65 int id = (int) (Math.random() * 10000);
67 while (Domain.getById(id) != null && count < 20) {
69 id = (int) (Math.random() * 10000);
71 Assume.assumeThat(Domain.getById(id), CoreMatchers.nullValue());
72 URLConnection uc = post(FindUserByDomainPage.PATH, "process&domain=#" + id);
73 assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));