]> WPIA git - gigi.git/blobdiff - tests/club/wpia/gigi/pages/admin/TestSEAdminPageUserDomainSearch.java
chg: enable support to find organisation domains
[gigi.git] / tests / club / wpia / gigi / pages / admin / TestSEAdminPageUserDomainSearch.java
index f662532ff1ac8c92499cd78d2f2dfb6d4a0dee27..d820a1d18cc464f35d38ddad25bae17ab36c9a26 100644 (file)
@@ -1,28 +1,35 @@
 package club.wpia.gigi.pages.admin;
 
+import static org.hamcrest.CoreMatchers.*;
 import static org.junit.Assert.*;
-import static org.junit.Assume.*;
 
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
+import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
 import java.net.URLConnection;
 import java.net.URLEncoder;
 
+import org.hamcrest.CoreMatchers;
+import org.junit.Assume;
 import org.junit.Test;
 
 import club.wpia.gigi.GigiApiException;
+import club.wpia.gigi.dbObjects.Country;
+import club.wpia.gigi.dbObjects.Country.CountryCodeType;
 import club.wpia.gigi.dbObjects.Domain;
 import club.wpia.gigi.dbObjects.Group;
+import club.wpia.gigi.dbObjects.Organisation;
 import club.wpia.gigi.dbObjects.User;
 import club.wpia.gigi.pages.admin.support.FindUserByDomainPage;
-import club.wpia.gigi.pages.admin.support.SupportEnterTicketPage;
+import club.wpia.gigi.pages.admin.support.SupportOrgDomainPage;
 import club.wpia.gigi.pages.admin.support.SupportUserDetailsPage;
-import club.wpia.gigi.testUtils.ClientTest;
 import club.wpia.gigi.testUtils.IOUtils;
+import club.wpia.gigi.testUtils.SEClientTest;
 import club.wpia.gigi.util.ServerConstants;
+import club.wpia.gigi.util.ServerConstants.Host;
 
-public class TestSEAdminPageUserDomainSearch extends ClientTest {
+public class TestSEAdminPageUserDomainSearch extends SEClientTest {
 
     private Domain d;
 
@@ -33,10 +40,6 @@ public class TestSEAdminPageUserDomainSearch extends ClientTest {
     private int tid;
 
     public TestSEAdminPageUserDomainSearch() throws IOException, GigiApiException {
-        grant(u, Group.SUPPORTER);
-        cookie = login(email, TEST_PASSWORD);
-        assertEquals(302, post(cookie, SupportEnterTicketPage.PATH, "ticketno=a20140808.8&setTicket=action", 0).getResponseCode());
-
         String mail = createUniqueName() + "@example.com";
         tid = createVerifiedUser("Först", "Secönd", mail, TEST_PASSWORD);
         User user = User.getById(tid);
@@ -49,13 +52,13 @@ public class TestSEAdminPageUserDomainSearch extends ClientTest {
     public void testDomainSearch() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException {
         URLConnection uc = post(FindUserByDomainPage.PATH, "process&domain=" + URLEncoder.encode(domainName, "UTF-8"));
 
-        assertEquals("https://" + ServerConstants.getWwwHostNamePortSecure() + SupportUserDetailsPage.PATH + tid + "/", uc.getHeaderField("Location"));
+        assertEquals("https://" + ServerConstants.getHostNamePortSecure(Host.WWW) + SupportUserDetailsPage.PATH + tid + "/", uc.getHeaderField("Location"));
     }
 
     @Test
     public void testDomainSearchById() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException {
         URLConnection uc = post(FindUserByDomainPage.PATH, "process&domain=#" + d.getId());
-        assertEquals("https://" + ServerConstants.getWwwHostNamePortSecure() + SupportUserDetailsPage.PATH + tid + "/", uc.getHeaderField("Location"));
+        assertEquals("https://" + ServerConstants.getHostNamePortSecure(Host.WWW) + SupportUserDetailsPage.PATH + tid + "/", uc.getHeaderField("Location"));
     }
 
     @Test
@@ -68,17 +71,46 @@ public class TestSEAdminPageUserDomainSearch extends ClientTest {
     public void testDomainSearchByIdNonExist() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException {
         int id = (int) (Math.random() * 10000);
         int count = 0;
-        boolean found = false;
-        try {
-            while (Domain.getById(id) != null && count < 20) {
-                count++;
-                id = (int) (Math.random() * 10000);
-            }
-        } catch (Exception e) {
-            found = true;
+        while (Domain.getById(id) != null && count < 20) {
+            count++;
+            id = (int) (Math.random() * 10000);
         }
-        assumeTrue(found);
+        Assume.assumeThat(Domain.getById(id), CoreMatchers.nullValue());
         URLConnection uc = post(FindUserByDomainPage.PATH, "process&domain=#" + id);
         assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
     }
+
+    @Test
+    public void testOrgDomainSearch() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException {
+        // generate organisation with domain
+        u.grantGroup(getSupporter(), Group.ORG_AGENT);
+        Organisation o1 = new Organisation(createUniqueName(), Country.getCountryByCode("DE", CountryCodeType.CODE_2_CHARS), "pr", "city", "test@example.com", "", "", u);
+        String dom = createUniqueName() + ".de";
+        Domain d = new Domain(u, o1, dom);
+
+        // test
+        URLConnection uc = post(FindUserByDomainPage.PATH, "process&domain=" + URLEncoder.encode(dom, "UTF-8"));
+
+        assertEquals("https://" + ServerConstants.getHostNamePortSecure(Host.WWW) + SupportOrgDomainPage.PATH + d.getId(), uc.getHeaderField("Location"));
+
+        String s = IOUtils.readURL(get(cookie, SupportOrgDomainPage.PATH + d.getId()));
+        assertThat(s, containsString(dom));
+        assertThat(s, containsString(o1.getName()));
+
+        // test malformated id
+        HttpURLConnection uc1 = get(SupportOrgDomainPage.PATH + d.getId() + "a");
+        assertEquals(400, uc1.getResponseCode());
+
+        // test non existing id
+        uc1 = get(SupportOrgDomainPage.PATH + "5000");
+        assertEquals(400, uc1.getResponseCode());
+
+    }
+
+    @Test
+    public void testDomainSearchByMalformatedId() throws MalformedURLException, UnsupportedEncodingException, IOException, GigiApiException {
+        URLConnection uc = post(FindUserByDomainPage.PATH, "process&domain=#" + d.getId() + "a");
+        assertNotNull(fetchStartErrorMessage(IOUtils.readURL(uc)));
+    }
+
 }