Browse code

BM-15254 Chore: add unit test to ensure we don't trim folders ending with a space

Thomas Cataldo authored on 04/10/2019 15:16:26
Showing 2 changed files
... ...
@@ -601,6 +601,52 @@ public class ReplicationStackTests extends AbstractRollingReplicationTests {
601 601
 	}
602 602
 
603 603
 	@Test
604
+	public void createFolderEndingWithSpace() throws IMAPException, InterruptedException {
605
+		IServiceProvider clientProv = provider();
606
+		IMailboxFolders mboxesApi = clientProv.instance(IMailboxFolders.class, partition, mboxRoot);
607
+		List<ItemValue<MailboxFolder>> allBoxes = mboxesApi.all();
608
+		ItemValue<MailboxFolder> inbox = null;
609
+		for (ItemValue<MailboxFolder> box : allBoxes) {
610
+			if (box.value.name.equals("INBOX")) {
611
+				inbox = box;
612
+				break;
613
+			}
614
+		}
615
+		assertNotNull(inbox);
616
+		MailboxReplica toCreate = new MailboxReplica();
617
+		long time = System.currentTimeMillis() / 1000;
618
+		toCreate.name = "create" + time + " FĂ©vrier ";
619
+		IOfflineMgmt idAllocator = provider().instance(IOfflineMgmt.class, domainUid, userUid);
620
+		IdRange oneId = idAllocator.allocateOfflineIds(1);
621
+		System.err.println("Create starts...");
622
+		ItemIdentifier created = mboxesApi.createForHierarchy(oneId.globalCounter, toCreate);
623
+		System.out.println("Got a create of version " + created.version);
624
+		ContainerChangeset<Long> changed = mboxesApi.changesetById(created.version - 1);
625
+		long newItemId = changed.created.get(0);
626
+		System.out.println("From changelog: itemId should be " + newItemId);
627
+		ItemValue<MailboxFolder> foundItem = mboxesApi.getCompleteById(newItemId);
628
+		System.out.println("Found " + foundItem.value.name);
629
+
630
+		int newMail = imapAsUser(sc -> {
631
+			int added = sc.append(toCreate.name, testEml(), new FlagsList());
632
+			return added;
633
+		});
634
+		assertTrue(newMail > 0);
635
+
636
+		oneId = idAllocator.allocateOfflineIds(1);
637
+		MailboxReplica sub = new MailboxReplica();
638
+		sub.name = toCreate.name + "/Toto espace ";
639
+		ItemIdentifier createdSub = mboxesApi.createForHierarchy(oneId.globalCounter, sub);
640
+		ItemValue<MailboxFolder> subItem = mboxesApi.getCompleteById(createdSub.id);
641
+		System.err.println("Sub " + subItem.value);
642
+
643
+		assertTrue(foundItem.value.name.endsWith(" "));
644
+		assertTrue(foundItem.value.fullName.endsWith(" "));
645
+		assertTrue(subItem.value.name.endsWith(" "));
646
+		assertTrue(subItem.value.fullName.endsWith(" "));
647
+	}
648
+
649
+	@Test
604 650
 	public void createSubThenUnsub() throws IMAPException, InterruptedException {
605 651
 		IServiceProvider clientProv = provider();
606 652
 		IMailboxFolders mboxesApi = clientProv.instance(IMailboxFolders.class, partition, mboxRoot);
... ...
@@ -169,7 +169,7 @@ public class ImapReplicatedMailboxesService extends BaseReplicatedMailboxesServi
169 169
 		FolderInternalIdCache.storeExpectedRecordId(container, value.fullName, hierId);
170 170
 		final String computedName = newName;
171 171
 		CompletableFuture<ItemIdentifier> future = ReplicationEvents.onSubtreeUpdate(toWatch);
172
-		logger.info("{} Should create {}", root, computedName);
172
+		logger.info("{} Should create '{}'", root, computedName);
173 173
 		return imapContext.withImapClient((sc, fast) -> {
174 174
 			boolean ok = sc.create(computedName);
175 175
 			if (ok) {