Browse code

BM-13989 Fix: missing user lastname in some tests

kladier authored on 26/11/2019 16:31:58
Showing 7 changed files
... ...
@@ -39,6 +39,7 @@ import org.vertx.java.core.Handler;
39 39
 
40 40
 import com.google.common.collect.Lists;
41 41
 
42
+import net.bluemind.addressbook.api.VCard;
42 43
 import net.bluemind.core.api.Email;
43 44
 import net.bluemind.core.api.fault.ErrorCode;
44 45
 import net.bluemind.core.api.fault.ServerFault;
... ...
@@ -176,6 +177,8 @@ public class DirectoryTests {
176 177
 				domainUid);
177 178
 		User admin = new User();
178 179
 		admin.login = "test";
180
+		admin.contactInfos = new VCard();
181
+		admin.contactInfos.identification.name.familyNames = "myName";
179 182
 		admin.password = "test";
180 183
 		admin.routing = Mailbox.Routing.none;
181 184
 
... ...
@@ -283,6 +286,8 @@ public class DirectoryTests {
283 286
 				domainUid);
284 287
 		User admin = new User();
285 288
 		admin.login = "test";
289
+		admin.contactInfos = new VCard();
290
+		admin.contactInfos.identification.name.familyNames = "myName";
286 291
 		admin.password = "test";
287 292
 		admin.routing = Mailbox.Routing.none;
288 293
 
... ...
@@ -306,6 +311,8 @@ public class DirectoryTests {
306 311
 				domainUid);
307 312
 		User u = new User();
308 313
 		u.login = "logn" + UUID.randomUUID();
314
+		u.contactInfos = new VCard();
315
+		u.contactInfos.identification.name.familyNames = "myName";
309 316
 		u.password = "password";
310 317
 		u.routing = Mailbox.Routing.none;
311 318
 		u.dataLocation = PopulateHelper.FAKE_CYRUS_IP;
... ...
@@ -240,7 +240,7 @@ public class ExternalUserServiceTests {
240 240
 			getExternalUserService().create(extUserItemUid, externalUser);
241 241
 			fail("can't create an external user whose right part is a domain alias already used by an user.");
242 242
 		} catch (ServerFault sf) {
243
-			assertEquals(ErrorCode.ALREADY_EXISTS, sf.getCode());
243
+			assertEquals(ErrorCode.EMAIL_ALREADY_USED, sf.getCode());
244 244
 		}
245 245
 	}
246 246
 
... ...
@@ -257,7 +257,7 @@ public class ExternalUserServiceTests {
257 257
 			getExternalUserService().create(itemUid2, eu2);
258 258
 			fail("can't create an external user with same email than an existing external user.");
259 259
 		} catch (ServerFault sf) {
260
-			assertEquals(ErrorCode.ALREADY_EXISTS, sf.getCode());
260
+			assertEquals(ErrorCode.EMAIL_ALREADY_USED, sf.getCode());
261 261
 		}
262 262
 	}
263 263
 
... ...
@@ -370,8 +370,9 @@ public class ExternalUserServiceTests {
370 370
 		String itemUid = UUID.randomUUID().toString();
371 371
 		ExternalUser eu = new ExternalUser();
372 372
 		String myEmail = "mail@external.com";
373
+		String myName = "myName";
373 374
 		eu.contactInfos = new VCard();
374
-		eu.contactInfos.identification.formatedName = VCard.Identification.FormatedName.create("myName");
375
+		eu.contactInfos.identification.name.familyNames = myName;
375 376
 		eu.contactInfos.communications.emails = new ArrayList<>();
376 377
 		eu.contactInfos.communications.emails.add(VCard.Communications.Email.create(myEmail));
377 378
 		eu.hidden = true;
... ...
@@ -384,9 +385,9 @@ public class ExternalUserServiceTests {
384 385
 		ExternalUser created = externalUserService.getComplete(itemUid).value;
385 386
 
386 387
 		assertEquals(1, created.contactInfos.communications.emails.size());
387
-		assertEquals(myEmail, created.contactInfos.communications.emails.iterator().next().value);
388
-		assertEquals(eu.contactInfos.identification.formatedName.value,
389
-				created.contactInfos.identification.formatedName.value);
388
+		assertEquals(myEmail, created.contactInfos.defaultMail());
389
+		assertEquals(myName, created.contactInfos.identification.name.familyNames);
390
+		assertEquals(myName, created.contactInfos.identification.formatedName.value);
390 391
 	}
391 392
 
392 393
 	private Group createGroup(String name, String desc, String groupUid) {
... ...
@@ -22,6 +22,7 @@ import org.vertx.java.core.Handler;
22 22
 
23 23
 import com.google.common.base.Strings;
24 24
 
25
+import net.bluemind.addressbook.api.VCard;
25 26
 import net.bluemind.core.api.AsyncHandler;
26 27
 import net.bluemind.core.api.Email;
27 28
 import net.bluemind.core.api.fault.ServerFault;
... ...
@@ -163,6 +164,8 @@ public class C2ProviderTests {
163 164
 		User user = new User();
164 165
 		user.login = userLogin;
165 166
 		user.routing = Routing.internal;
167
+		user.contactInfos = new VCard();
168
+		user.contactInfos.identification.name.familyNames = "myName";
166 169
 		user.archived = true;
167 170
 
168 171
 		String emailAlias = String.format("mail.%s@%s", userLogin, domainUid);
... ...
@@ -196,6 +199,8 @@ public class C2ProviderTests {
196 199
 
197 200
 		User user = new User();
198 201
 		user.login = userLogin;
202
+		user.contactInfos = new VCard();
203
+		user.contactInfos.identification.name.familyNames = "myName";
199 204
 		user.routing = Routing.internal;
200 205
 
201 206
 		String emailAlias = String.format("mail.%s@%s", userLogin, domainUid);
... ...
@@ -229,6 +234,8 @@ public class C2ProviderTests {
229 234
 
230 235
 		User user = new User();
231 236
 		user.login = userLogin;
237
+		user.contactInfos = new VCard();
238
+		user.contactInfos.identification.name.familyNames = "myName";
232 239
 		user.routing = Routing.internal;
233 240
 
234 241
 		String emailAlias = String.format("mail.%s@%s", userLogin, domainUid);
... ...
@@ -262,6 +269,8 @@ public class C2ProviderTests {
262 269
 
263 270
 		User user = new User();
264 271
 		user.login = userLogin;
272
+		user.contactInfos = new VCard();
273
+		user.contactInfos.identification.name.familyNames = "myName";
265 274
 		user.routing = Routing.none;
266 275
 
267 276
 		String userUid = UUID.randomUUID().toString();
... ...
@@ -181,6 +181,7 @@ public class ImportLoginValidationTests {
181 181
 				user.value.login = "login-" + System.nanoTime();
182 182
 				user.value.routing = Routing.internal;
183 183
 				user.value.contactInfos = new VCard();
184
+				user.value.contactInfos.identification.name.familyNames = "myName";
184 185
 			}
185 186
 
186 187
 			@Override
... ...
@@ -317,6 +317,7 @@ public class LdapExportServiceTests {
317 317
 		ldapCon.modify(modifyRequest);
318 318
 
319 319
 		user.value.contactInfos = new VCard();
320
+		user.value.contactInfos.identification.name.familyNames = "myName";
320 321
 		user.value.contactInfos.explanatory.note = "Updated description";
321 322
 		userService.update(user.uid, user.value);
322 323
 
... ...
@@ -41,15 +41,15 @@ public class UserValidatorTest {
41 41
 		String l5 = "0-.-__test1";
42 42
 
43 43
 		user.login = l1;
44
-		validator.validate(user);
44
+		validator.validateLogin(user);
45 45
 		user.login = l2;
46
-		validator.validate(user);
46
+		validator.validateLogin(user);
47 47
 		user.login = l3;
48
-		validator.validate(user);
48
+		validator.validateLogin(user);
49 49
 		user.login = l4;
50
-		validator.validate(user);
50
+		validator.validateLogin(user);
51 51
 		user.login = l5;
52
-		validator.validate(user);
52
+		validator.validateLogin(user);
53 53
 	}
54 54
 
55 55
 	@Test
... ...
@@ -76,7 +76,7 @@ public class UserValidatorTest {
76 76
 		try {
77 77
 			User user = new User();
78 78
 			user.login = login;
79
-			validator.validate(user);
79
+			validator.validateLogin(user);
80 80
 			fail();
81 81
 		} catch (Exception e) {
82 82
 		}
... ...
@@ -44,13 +44,17 @@ public class UserValidator implements IValidator<User> {
44 44
 		ParametersValidator.notNullAndNotEmpty(user.login);
45 45
 		ParametersValidator.notNull(user.routing);
46 46
 
47
-		if (!Regex.LOGIN.validate(user.login)) {
48
-			throw new ServerFault("Login is invalid", ErrorCode.INVALID_PARAMETER);
49
-		}
47
+		validateLogin(user);
50 48
 
51 49
 		String familyName = user.contactInfos.identification.name.familyNames;
52 50
 		if (Strings.isNullOrEmpty(familyName)) {
53 51
 			throw new ServerFault("A user should have a last name.", ErrorCode.EMPTY_LASTNAME);
54 52
 		}
55 53
 	}
54
+
55
+	void validateLogin(User user) {
56
+		if (!Regex.LOGIN.validate(user.login)) {
57
+			throw new ServerFault("Login is invalid", ErrorCode.INVALID_PARAMETER);
58
+		}
59
+	}
56 60
 }