]> WPIA git - gigi.git/blob - tests/org/cacert/gigi/pages/account/TestContactInformation.java
UPD: use more advanced hamcrest matchers where possible.
[gigi.git] / tests / org / cacert / gigi / pages / account / TestContactInformation.java
1 package org.cacert.gigi.pages.account;
2
3 import static org.hamcrest.CoreMatchers.*;
4 import static org.junit.Assert.*;
5
6 import java.io.IOException;
7 import java.net.URL;
8 import java.net.URLConnection;
9
10 import org.cacert.gigi.testUtils.IOUtils;
11 import org.cacert.gigi.testUtils.ManagedTest;
12 import org.junit.Test;
13
14 public class TestContactInformation extends ManagedTest {
15
16     @Test
17     public void testDirectoryListingToggle() throws IOException {
18         String email = createUniqueName() + "@e.fg";
19         createVerifiedUser("Kurti", createUniqueName(), email, TEST_PASSWORD);
20         String cookie = login(email, TEST_PASSWORD);
21         assertNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "listme=1&contactinfo=&processContact", 1));
22         URLConnection url = new URL("https://" + getServerName() + MyDetails.PATH).openConnection();
23         url.setRequestProperty("Cookie", cookie);
24         String res = IOUtils.readURL(url);
25         res = res.split(java.util.regex.Pattern.quote("</table>"))[1];
26         assertThat(res, containsString("value=\"1\" selected"));
27         assertNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "listme=0&contactinfo=&processContact", 1));
28         url = new URL("https://" + getServerName() + MyDetails.PATH).openConnection();
29         url.setRequestProperty("Cookie", cookie);
30         res = IOUtils.readURL(url);
31         res = res.split(java.util.regex.Pattern.quote("</table>"))[1];
32         assertTrue(res.contains("value=\"0\" selected"));
33     }
34
35     @Test
36     public void testContactinfoSet() throws IOException {
37         String email = createUniqueName() + "@e.fg";
38         createVerifiedUser("Kurti", createUniqueName(), email, TEST_PASSWORD);
39         String cookie = login(email, TEST_PASSWORD);
40         String text = createUniqueName();
41         assertNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "listme=1&contactinfo=" + text + "&processContact", 1));
42         URLConnection url = new URL("https://" + getServerName() + MyDetails.PATH).openConnection();
43         url.setRequestProperty("Cookie", cookie);
44         String res = IOUtils.readURL(url);
45         res = res.split(java.util.regex.Pattern.quote("</table>"))[1];
46         assertThat(res, containsString(text));
47     }
48 }