import static org.junit.Assert.*;
import java.io.IOException;
+import java.net.URLEncoder;
import java.sql.Date;
import java.util.Arrays;
import java.util.Calendar;
import java.util.TimeZone;
import org.cacert.gigi.GigiApiException;
+import org.cacert.gigi.dbObjects.Group;
import org.cacert.gigi.dbObjects.Name;
import org.cacert.gigi.dbObjects.NamePart;
import org.cacert.gigi.dbObjects.NamePart.NamePartType;
public void testAddName() throws IOException {
int startn = User.getById(id).getNames().length;
String newName = createUniqueName();
- assertNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "fname=" + newName + "&lname=Hansel&action=addName", 0));
+ assertNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "name-type=western&fname=" + newName + "&lname=Hansel&action=addName", 0));
User u = User.getById(id);
NamePart[] parts = u.getNames()[startn].getParts();
c.add(Calendar.DAY_OF_MONTH, -1);
assertNotNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "day=" + c.get(Calendar.DAY_OF_MONTH) + "&month=" + (c.get(Calendar.MONTH) + 1) + "&year=" + c.get(Calendar.YEAR) + "&action=updateDoB", 0));
}
+
+ @Test
+ public void testChangeResidenceCountry() throws IOException {
+ assertNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "residenceCountry=DE&action=updateResidenceCountry", 0));
+ User user = User.getById(id);
+ assertEquals("DE", user.getResidenceCountry().getCode());
+ }
+
+ @Test
+ public void testChangeResidenceCountryToNull() throws IOException {
+ User user = User.getById(id);
+ assertNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "residenceCountry=invalid&action=updateResidenceCountry", 0));
+ assertEquals(null, user.getResidenceCountry());
+ }
+
+ @Test
+ public void testModifyUserGroup() throws IOException {
+ User user = User.getById(id);
+ // test add group
+ assertNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "action=addGroup&groupToModify=" + URLEncoder.encode(Group.LOCATE_AGENT.getDBName(), "UTF-8"), 0));
+
+ user = User.getById(id);
+ user.refreshGroups();
+ assertTrue(user.isInGroup(Group.LOCATE_AGENT));
+
+ // test remove group
+ assertNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "action=removeGroup&groupToModify=" + URLEncoder.encode(Group.LOCATE_AGENT.getDBName(), "UTF-8"), 0));
+
+ user = User.getById(id);
+ user.refreshGroups();
+ assertFalse(user.isInGroup(Group.LOCATE_AGENT));
+
+ // test add group that only support can add
+ assertNotNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "action=addGroup&groupToModify=" + URLEncoder.encode(Group.SUPPORTER.getDBName(), "UTF-8"), 0));
+
+ user = User.getById(id);
+ user.refreshGroups();
+ assertFalse(user.isInGroup(Group.SUPPORTER));
+
+ // test add invalid group
+ assertNotNull(executeBasicWebInteraction(cookie, MyDetails.PATH, "action=addGroup&groupToModify=non-existing", 0));
+ }
}