1 package org.cacert.gigi.pages.account;
3 import static org.hamcrest.CoreMatchers.*;
4 import static org.junit.Assert.*;
6 import java.io.IOException;
8 import java.net.URLConnection;
10 import org.cacert.gigi.testUtils.IOUtils;
11 import org.cacert.gigi.testUtils.ManagedTest;
12 import org.junit.Test;
14 public class TestContactInformation extends ManagedTest {
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"));
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));