]> WPIA git - gigi.git/blob - tests/org/cacert/gigi/pages/account/TestMyDetailsEdit.java
af6cecb34c292597d2db2922910caef4df58bdb8
[gigi.git] / tests / org / cacert / gigi / pages / account / TestMyDetailsEdit.java
1 package org.cacert.gigi.pages.account;
2
3 import static org.junit.Assert.*;
4
5 import java.io.IOException;
6 import java.sql.Date;
7 import java.util.Calendar;
8 import java.util.TimeZone;
9
10 import org.cacert.gigi.dbObjects.User;
11 import org.cacert.gigi.testUtils.ManagedTest;
12 import org.junit.Test;
13
14 public class TestMyDetailsEdit extends ManagedTest {
15
16     String email = createUniqueName() + "@e.de";
17
18     int id = createVerifiedUser("Kurti", "Hansel", email, TEST_PASSWORD);
19
20     String cookie = login(email, TEST_PASSWORD);
21
22     public TestMyDetailsEdit() throws IOException {}
23
24     @Test
25     public void testChangeFnameValid() throws IOException {
26         String newName = createUniqueName();
27         assertNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "fname=" + newName + "&lname=Hansel&mname=&suffix=&day=1&month=1&year=2000&processDetails", 0));
28         User u = User.getById(id);
29         assertEquals(newName, u.getFname());
30     }
31
32     @Test
33     public void testChangeLnameValid() throws IOException {
34         String newName = createUniqueName();
35         assertNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "lname=" + newName + "&fname=Kurti&mname=&suffix=&day=1&month=1&year=2000&processDetails", 0));
36         User u = User.getById(id);
37         assertEquals(newName, u.getLname());
38     }
39
40     @Test
41     public void testChangeMnameValid() throws IOException {
42         String newName = createUniqueName();
43         assertNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "mname=" + newName + "&fname=Kurti&lname=Hansel&suffix=&day=1&month=1&year=2000&processDetails", 0));
44         User u = User.getById(id);
45         assertEquals(newName, u.getMname());
46     }
47
48     @Test
49     public void testChangeSuffixValid() throws IOException {
50         String newName = createUniqueName();
51         assertNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "mname=&fname=Kurti&lname=Hansel&suffix=" + newName + "&day=1&month=1&year=2000&processDetails", 0));
52         User u = User.getById(id);
53         assertEquals(newName, u.getSuffix());
54     }
55
56     @Test
57     public void testUnsetSuffix() throws IOException {
58         String newName = createUniqueName();
59         assertNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "mname=&fname=Kurti&lname=Hansel&suffix=" + newName + "&day=1&month=1&year=2000&processDetails", 0));
60         User u = User.getById(id);
61         assertEquals(newName, u.getSuffix());
62         assertNotNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "mname=&fname=Kurti&lname=Hansel&suffix=&day=1&month=1&year=2000&processDetails", 0));
63         u = User.getById(id);
64         assertEquals(newName, u.getSuffix());
65     }
66
67     @Test
68     public void testUnsetFname() throws IOException {
69         assertNotNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "fname=&lname=Hansel&mname=&suffix=&day=1&month=1&year=2000&processDetails", 0));
70         User u = User.getById(id);
71         assertEquals("Kurti", u.getFname());
72
73     }
74
75     @Test
76     public void testUnsetLname() throws IOException {
77         assertNotNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "lname=&fname=Kurti&mname=&suffix=&day=1&month=1&year=2000&processDetails", 0));
78         User u = User.getById(id);
79         assertEquals("Hansel", u.getLname());
80     }
81
82     @Test
83     public void testUnsetMname() throws IOException {
84         String newName = createUniqueName();
85         assertNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "mname=" + newName + "&fname=Kurti&lname=Hansel&suffix=&day=1&month=1&year=2000&processDetails", 0));
86         User u = User.getById(id);
87         assertEquals(newName, u.getMname());
88         assertNotNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "lname=Hansel&fname=Kurti&mname=&suffix=&day=1&month=1&year=2000&processDetails", 0));
89         u = User.getById(id);
90         assertEquals(newName, u.getMname());
91
92     }
93
94     @Test
95     public void testChangeDOBValid() throws IOException {
96         assertNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "lname=Hansel&fname=Kurti&mname=&suffix=&day=1&month=2&year=2000&processDetails", 0));
97         User u = User.getById(id);
98         Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
99         cal.set(Calendar.YEAR, 2000);
100         cal.set(Calendar.DAY_OF_MONTH, Calendar.FEBRUARY);
101         cal.set(Calendar.MONTH, 1);
102         Date d = new Date(cal.getTimeInMillis());
103         assertEquals(d.toString(), u.getDob().toString());
104     }
105
106     @Test
107     public void testChangeDOBInvalid() throws IOException {
108         assertNotNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "lname=Hansel&fname=Kurti&mname=&suffix=&day=1&month=1&year=test&processDetails", 0));
109     }
110 }