1 package club.wpia.gigi.dbObjects;
3 import static org.junit.Assert.*;
5 import java.io.IOException;
6 import java.security.GeneralSecurityException;
9 import org.hamcrest.CoreMatchers;
10 import org.junit.Test;
12 import club.wpia.gigi.GigiApiException;
13 import club.wpia.gigi.dbObjects.CATS.CATSType;
14 import club.wpia.gigi.dbObjects.NamePart.NamePartType;
15 import club.wpia.gigi.testUtils.ArrayContains;
16 import club.wpia.gigi.testUtils.ClientBusinessTest;
18 public class TestUser extends ClientBusinessTest {
21 public void testGetInitials() throws GigiApiException {
22 User u0 = User.getById(createVerificationUser("Kurti", "Hansel", createUniqueName() + "@email.com", TEST_PASSWORD));
24 assertEquals("KH", u0.getInitials());
26 // single name as preferred name
27 Name sName = new Name(u0, new NamePart(NamePartType.SINGLE_NAME, "SingleName"));
28 u0.setPreferredName(sName);
29 assertEquals("S", u0.getInitials());
31 // second western style name as preferred name
33 new NamePart(NamePartType.FIRST_NAME, "John"), new NamePart(NamePartType.FIRST_NAME, "Walker"), new NamePart(NamePartType.LAST_NAME, "Hansel")
35 sName = new Name(u0, np);
36 u0.setPreferredName(sName);
37 assertEquals("JWH", u0.getInitials());
38 // second western style name as preferred name
41 new NamePart(NamePartType.FIRST_NAME, "Dieter"), new NamePart(NamePartType.LAST_NAME, "Hansel"), new NamePart(NamePartType.LAST_NAME, "von"), new NamePart(NamePartType.LAST_NAME, "Hof"), new NamePart(NamePartType.SUFFIX, "Meister")
43 sName = new Name(u0, np1);
44 u0.setPreferredName(sName);
45 assertEquals("DHVHM", u0.getInitials());
47 // western style name with dash as preferred name (Hans-Peter)
49 new NamePart(NamePartType.FIRST_NAME, "Hans-Peter"), new NamePart(NamePartType.LAST_NAME, "Hansel")
51 sName = new Name(u0, np2);
52 u0.setPreferredName(sName);
53 assertEquals("HH", u0.getInitials());
55 // western style name with dash as separate entry as preferred name
58 new NamePart(NamePartType.FIRST_NAME, "Hans"), new NamePart(NamePartType.FIRST_NAME, "-"), new NamePart(NamePartType.FIRST_NAME, "Joachim"), new NamePart(NamePartType.LAST_NAME, "Hansel")
60 sName = new Name(u0, np3);
61 u0.setPreferredName(sName);
62 assertEquals("HJH", u0.getInitials());
64 // western style name with / as separate entry as preferred name
67 new NamePart(NamePartType.FIRST_NAME, "Hans"), new NamePart(NamePartType.FIRST_NAME, "/"), new NamePart(NamePartType.FIRST_NAME, "Peter"), new NamePart(NamePartType.LAST_NAME, "Hansel")
69 sName = new Name(u0, np4);
70 u0.setPreferredName(sName);
71 assertEquals("HPH", u0.getInitials());
75 public void testValidCATS() throws IOException, GeneralSecurityException {
76 Date min11month = new Date(System.currentTimeMillis() - 24L * 60 * 60 * 11 * 31 * 1000L);
77 Date min12month = new Date(System.currentTimeMillis() - 24L * 60 * 60 * 12 * 31 * 1000L);
79 assertFalse(u.hasValidRAChallenge());
80 CATS.enterResult(u, CATSType.AGENT_CHALLENGE, min12month, "en_US", "1");
81 assertFalse(u.hasValidRAChallenge());
82 CATS.enterResult(u, CATSType.AGENT_CHALLENGE, min11month, "en_US", "1");
83 assertTrue(u.hasValidRAChallenge());
85 assertFalse(u.hasValidSupportChallenge());
86 CATS.enterResult(u, CATSType.SUPPORT_DP_CHALLENGE_NAME, min12month, "en_US", "1");
87 assertFalse(u.hasValidSupportChallenge());
88 CATS.enterResult(u, CATSType.SUPPORT_DP_CHALLENGE_NAME, min11month, "en_US", "1");
89 assertTrue(u.hasValidSupportChallenge());
91 assertFalse(u.hasValidOrgAdminChallenge());
92 CATS.enterResult(u, CATSType.ORG_ADMIN_DP_CHALLENGE_NAME, min12month, "en_US", "1");
93 assertFalse(u.hasValidOrgAdminChallenge());
94 CATS.enterResult(u, CATSType.ORG_ADMIN_DP_CHALLENGE_NAME, min11month, "en_US", "1");
95 assertTrue(u.hasValidOrgAdminChallenge());
97 assertFalse(u.hasValidOrgAgentChallenge());
98 CATS.enterResult(u, CATSType.ORG_AGENT_CHALLENGE, min12month, "en_US", "1");
99 assertFalse(u.hasValidOrgAgentChallenge());
100 CATS.enterResult(u, CATSType.ORG_AGENT_CHALLENGE, min11month, "en_US", "1");
101 assertTrue(u.hasValidOrgAgentChallenge());
103 assertFalse(u.hasValidTTPAgentChallenge());
104 CATS.enterResult(u, CATSType.TTP_AGENT_CHALLENGE, min12month, "en_US", "1");
105 assertFalse(u.hasValidTTPAgentChallenge());
106 CATS.enterResult(u, CATSType.TTP_AGENT_CHALLENGE, min11month, "en_US", "1");
107 assertTrue(u.hasValidTTPAgentChallenge());
111 public void testHasContract() throws GigiApiException {
112 assertEquals(false, Contract.hasSignedContract(u, Contract.ContractType.RA_AGENT_CONTRACT));
114 Contract c = new Contract(u, Contract.ContractType.RA_AGENT_CONTRACT);
115 getMailReceiver().receive(u.getEmail());
116 assertEquals(true, Contract.hasSignedContract(u, Contract.ContractType.RA_AGENT_CONTRACT));
119 getMailReceiver().receive(u.getEmail());
120 assertEquals(false, Contract.hasSignedContract(u, Contract.ContractType.RA_AGENT_CONTRACT));
124 public void testWriteUserLog() throws GigiApiException {
125 String type = "Log test";
126 u.writeUserLog(u, type);
127 String[] result = u.getAdminLog();
128 assertThat(result, ArrayContains.contains(CoreMatchers.equalTo(type)));
130 String type1 = "Log test1";
131 u.writeUserLog(u, type1);
132 result = u.getAdminLog();
133 assertThat(result, ArrayContains.contains(CoreMatchers.equalTo(type1)));
134 assertThat(result, ArrayContains.contains(CoreMatchers.equalTo(type)));
138 public void testValidVerification() throws GigiApiException {
139 User u0 = User.getById(createVerifiedUser("f", "l", createUniqueName() + "@email.com", TEST_PASSWORD));
140 assertFalse(u0.isValidNameVerification(u0.getPreferredName().toString()));
142 add100Points(u0.getId());
143 assertTrue(u0.isValidNameVerification(u0.getPreferredName().toString()));
145 setVerificationDateToPast(u0.getPreferredName());
146 assertFalse(u0.isValidNameVerification(u0.getPreferredName().toString()));
148 add100Points(u0.getId());
149 assertTrue(u0.isValidNameVerification(u0.getPreferredName().toString()));