From 4b10a64d47b03558563fb3e562b8f57ae7a45df0 Mon Sep 17 00:00:00 2001 From: jensp Date: Fri, 3 May 2019 18:22:38 +0000 Subject: [PATCH] CCM NG: Fixed test failures in ContentItemManagerTest git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@6006 8810af33-2d31-482b-a856-94f89814c4df --- .../ContentItemManagerTest.java | 103 +++++++++--------- .../workflow/AssignableTaskManager.java | 3 + 2 files changed, 55 insertions(+), 51 deletions(-) diff --git a/ccm-cms/src/test/java/org/librecms/contentsection/ContentItemManagerTest.java b/ccm-cms/src/test/java/org/librecms/contentsection/ContentItemManagerTest.java index 895df8a50..0ff98d00f 100644 --- a/ccm-cms/src/test/java/org/librecms/contentsection/ContentItemManagerTest.java +++ b/ccm-cms/src/test/java/org/librecms/contentsection/ContentItemManagerTest.java @@ -168,6 +168,7 @@ public class ContentItemManagerTest { .addClass( com.arsdigita.ui.admin.applications.DefaultApplicationSettingsPane.class) .addClass(org.librecms.dispatcher.ItemResolver.class) + .addClass(org.libreccm.imexport.Exportable.class) .addPackage(com.arsdigita.util.Lockable.class.getPackage()) .addPackage(com.arsdigita.web.BaseServlet.class.getPackage()) .addPackage(org.librecms.Cms.class.getPackage()) @@ -430,7 +431,7 @@ public class ContentItemManagerTest { final Folder folder = section.getRootDocumentsFolder(); final Workflow workflowTemplate = workflowRepo - .findById(-110L) + .findById(110L) .get(); final Article article = itemManager.createContentItem( @@ -479,7 +480,7 @@ public class ContentItemManagerTest { final Folder folder = section.getRootDocumentsFolder(); final Workflow workflowTemplate = workflowRepo - .findById(-110L) + .findById(110L) .get(); itemManager.createContentItem("Test", @@ -513,7 +514,7 @@ public class ContentItemManagerTest { final Folder folder = section.getRootDocumentsFolder(); final Workflow workflowTemplate = workflowRepo - .findById(-110L) + .findById(110L) .get(); itemManager.createContentItem(null, @@ -576,7 +577,7 @@ public class ContentItemManagerTest { .get(); final Workflow workflowTemplate = workflowRepo - .findById(-110L) + .findById(110L) .get(); itemManager.createContentItem("Test", @@ -611,10 +612,10 @@ public class ContentItemManagerTest { public void moveItem() { shiro.getSystemUser().execute(() -> { - final Optional item = itemRepo.findById(-10100L); + final Optional item = itemRepo.findById(10100L); assertThat(item.isPresent(), is(true)); - final Folder targetFolder = folderRepo.findById(-2120L).get(); + final Folder targetFolder = folderRepo.findById(2120L).get(); assertThat(targetFolder, is(not(nullValue()))); itemManager.move(item.get(), targetFolder); @@ -644,8 +645,8 @@ public class ContentItemManagerTest { public void moveItemToOtherContentSection() { shiro.getSystemUser().execute(() -> { - final Optional item = itemRepo.findById(-10100L); - final Folder targetFolder = folderRepo.findById(-2300L).get(); + final Optional item = itemRepo.findById(10100L); + final Folder targetFolder = folderRepo.findById(2300L).get(); assertThat(item.isPresent(), is(true)); assertThat(targetFolder, is(not(nullValue()))); @@ -671,8 +672,8 @@ public class ContentItemManagerTest { public void moveToOtherContentSectionTypeNotPresent() { shiro.getSystemUser().execute(() -> { - final Optional item = itemRepo.findById(-10400L); - final Folder targetFolder = folderRepo.findById(-2300L).get(); + final Optional item = itemRepo.findById(10400L); + final Folder targetFolder = folderRepo.findById(2300L).get(); assertThat(item.isPresent(), is(true)); assertThat(targetFolder, is(not(nullValue()))); @@ -697,7 +698,7 @@ public class ContentItemManagerTest { public void moveItemNull() { shiro.getSystemUser().execute(() -> { - final Folder targetFolder = folderRepo.findById(-2120L).get(); + final Folder targetFolder = folderRepo.findById(2120L).get(); assertThat(targetFolder, is(not(nullValue()))); itemManager.move(null, targetFolder); @@ -720,7 +721,7 @@ public class ContentItemManagerTest { public void moveItemTargetFolderIsNull() { shiro.getSystemUser().execute(() -> { - final Optional item = itemRepo.findById(-10100L); + final Optional item = itemRepo.findById(10100L); assertThat(item.isPresent(), is(true)); itemManager.move(item.get(), null); @@ -758,10 +759,10 @@ public class ContentItemManagerTest { public void copyToOtherFolder() { shiro.getSystemUser().execute(() -> { - final Optional item = itemRepo.findById(-10100L); + final Optional item = itemRepo.findById(10100L); assertThat(item.isPresent(), is(true)); - final Folder targetFolder = folderRepo.findById(-2120L).get(); + final Folder targetFolder = folderRepo.findById(2120L).get(); assertThat(targetFolder, is(not(nullValue()))); itemManager.copy(item.get(), targetFolder); @@ -799,8 +800,8 @@ public class ContentItemManagerTest { public void copyToFolderInOtherSection() { shiro.getSystemUser().execute(() -> { - final Optional source = itemRepo.findById(-10100L); - final Folder targetFolder = folderRepo.findById(-2300L).get(); + final Optional source = itemRepo.findById(10100L); + final Folder targetFolder = folderRepo.findById(2300L).get(); assertThat(source.isPresent(), is(true)); assertThat(targetFolder, is(not(nullValue()))); @@ -831,8 +832,8 @@ public class ContentItemManagerTest { public void copyToFolderInOtherSectionTypeNotPresent() { shiro.getSystemUser().execute(() -> { - final Optional source = itemRepo.findById(-10400L); - final Folder targetFolder = folderRepo.findById(-2300L).get(); + final Optional source = itemRepo.findById(10400L); + final Folder targetFolder = folderRepo.findById(2300L).get(); assertThat(source.isPresent(), is(true)); assertThat(targetFolder, is(not(nullValue()))); @@ -874,10 +875,10 @@ public class ContentItemManagerTest { public void copyToSameFolder() { shiro.getSystemUser().execute(() -> { - final Optional item = itemRepo.findById(-10100L); + final Optional item = itemRepo.findById(10100L); assertThat(item.isPresent(), is(true)); - final Folder targetFolder = folderRepo.findById(-2110L).get(); + final Folder targetFolder = folderRepo.findById(2110L).get(); assertThat(targetFolder, is(not(nullValue()))); itemManager.copy(item.get(), targetFolder); @@ -901,7 +902,7 @@ public class ContentItemManagerTest { public void copyItemNull() { shiro.getSystemUser().execute(() -> { - final Folder targetFolder = folderRepo.findById(-2120L).get(); + final Folder targetFolder = folderRepo.findById(2120L).get(); assertThat(targetFolder, is(not(nullValue()))); itemManager.copy(null, targetFolder); @@ -925,7 +926,7 @@ public class ContentItemManagerTest { public void copyItemToFolderNull() { shiro.getSystemUser().execute(() -> { - final Optional item = itemRepo.findById(-10100L); + final Optional item = itemRepo.findById(10100L); assertThat(item.isPresent(), is(true)); itemManager.copy(item.get(), null); @@ -966,7 +967,7 @@ public class ContentItemManagerTest { public void publishItem() { shiro.getSystemUser().execute(() -> { - final Optional item = itemRepo.findById(-10100L); + final Optional item = itemRepo.findById(10100L); assertThat(item.isPresent(), is(true)); final ContentItem live = itemManager.publish(item.get()); @@ -1009,9 +1010,9 @@ public class ContentItemManagerTest { public void publishItemWithLifecycle() { shiro.getSystemUser().execute(() -> { - final Optional item = itemRepo.findById(-10100L); + final Optional item = itemRepo.findById(10100L); final LifecycleDefinition lifecycleDef = lifecycleDefinitionRepo - .findById(-200L).get(); + .findById(200L).get(); assertThat(item.isPresent(), is(true)); assertThat(lifecycleDef, is(not(nullValue()))); @@ -1047,7 +1048,7 @@ public class ContentItemManagerTest { public void republishItem() { shiro.getSystemUser().execute(() -> { - final Optional item = itemRepo.findById(-10200L); + final Optional item = itemRepo.findById(10200L); assertThat(item.isPresent(), is(true)); item.get().getName().addValue(Locale.ENGLISH, "article2-edited"); @@ -1055,7 +1056,7 @@ public class ContentItemManagerTest { .addValue(Locale.ENGLISH, "Article has been edited"); itemRepo.save(item.get()); - final Optional draft = itemRepo.findById(-10200L); + final Optional draft = itemRepo.findById(10200L); assertThat(draft.get().getName().getValue(Locale.ENGLISH), is(equalTo("article2-edited"))); itemManager.publish(draft.get()); @@ -1100,7 +1101,7 @@ public class ContentItemManagerTest { public void publishItemLifecycleIsNull() { shiro.getSystemUser().execute(() -> { - final Optional draft = itemRepo.findById(-10200L); + final Optional draft = itemRepo.findById(10200L); itemManager.publish(draft.get(), null); }); @@ -1132,7 +1133,7 @@ public class ContentItemManagerTest { public void unpublishItem() { shiro.getSystemUser().execute(() -> { - final Optional item = itemRepo.findById(-10200L); + final Optional item = itemRepo.findById(10200L); assertThat(item.isPresent(), is(true)); itemManager.unpublish(item.get()); @@ -1153,7 +1154,7 @@ public class ContentItemManagerTest { public void unpublishNonLiveItem() { shiro.getSystemUser().execute(() -> { - final Optional item = itemRepo.findById(-10300L); + final Optional item = itemRepo.findById(10300L); assertThat(item.isPresent(), is(true)); itemManager.unpublish(item.get()); @@ -1195,10 +1196,10 @@ public class ContentItemManagerTest { public void isLive() { shiro.getSystemUser().execute(() -> { - final Optional item1 = itemRepo.findById(-10100L); - final Optional item2 = itemRepo.findById(-10200L); - final Optional item3 = itemRepo.findById(-10300L); - final Optional item4 = itemRepo.findById(-10400L); + final Optional item1 = itemRepo.findById(10100L); + final Optional item2 = itemRepo.findById(10200L); + final Optional item3 = itemRepo.findById(10300L); + final Optional item4 = itemRepo.findById(10400L); assertThat(item1.isPresent(), is(true)); assertThat(item2.isPresent(), is(true)); @@ -1228,12 +1229,12 @@ public class ContentItemManagerTest { public void getLiveVersion() { shiro.getSystemUser().execute(() -> { - final Optional draft1 = itemRepo.findById(-10100L); - final Optional draft2 = itemRepo.findById(-10200L); - final Optional draft3 = itemRepo.findById(-10300L); - final Optional draft4 = itemRepo.findById(-10400L); + final Optional draft1 = itemRepo.findById(10100L); + final Optional draft2 = itemRepo.findById(10200L); + final Optional draft3 = itemRepo.findById(10300L); + final Optional draft4 = itemRepo.findById(10400L); - final Optional live2 = itemRepo.findById(-99200L); + final Optional live2 = itemRepo.findById(99200L); assertThat(itemManager.getLiveVersion(draft1.get(), ContentItem.class).isPresent(), @@ -1243,7 +1244,7 @@ public class ContentItemManagerTest { assertThat(liveVersion.isPresent(), is(true)); assertThat(liveVersion.get().getObjectId(), - is(-99200L)); + is(99200L)); assertThat(liveVersion.get().getItemUuid(), is(equalTo("acae860f-2ffa-450d-b486-054292f0dae6"))); assertThat(liveVersion.get().getVersion(), @@ -1260,7 +1261,7 @@ public class ContentItemManagerTest { assertThat(fromLive.isPresent(), is(true)); assertThat(fromLive.get().getObjectId(), - is(-99200L)); + is(99200L)); assertThat(fromLive.get().getItemUuid(), is(equalTo("acae860f-2ffa-450d-b486-054292f0dae6"))); assertThat(fromLive.get().getVersion(), @@ -1283,35 +1284,35 @@ public class ContentItemManagerTest { public void getDraftVersion() { shiro.getSystemUser().execute(() -> { - final Optional draft1 = itemRepo.findById(-10100L); - final Optional draft2 = itemRepo.findById(-10200L); - final Optional draft3 = itemRepo.findById(-10300L); - final Optional draft4 = itemRepo.findById(-10400L); + final Optional draft1 = itemRepo.findById(10100L); + final Optional draft2 = itemRepo.findById(10200L); + final Optional draft3 = itemRepo.findById(10300L); + final Optional draft4 = itemRepo.findById(10400L); assertThat(itemManager.getDraftVersion(draft1.get(), ContentItem.class) .getObjectId(), - is(-10100L)); + is(10100L)); assertThat(itemManager.getDraftVersion(draft2.get(), ContentItem.class) .getObjectId(), - is(-10200L)); + is(10200L)); assertThat(itemManager.getDraftVersion(draft3.get(), ContentItem.class) .getObjectId(), - is(-10300L)); + is(10300L)); assertThat(itemManager.getDraftVersion(draft4.get(), ContentItem.class) .getObjectId(), - is(-10400L)); + is(10400L)); - final Optional live2 = itemRepo.findById(-99200L); + final Optional live2 = itemRepo.findById(99200L); final ContentItem draftVersion = itemManager.getDraftVersion( live2.get(), ContentItem.class); assertThat(draftVersion, is(not(nullValue()))); - assertThat(draftVersion.getObjectId(), is(-10200L)); + assertThat(draftVersion.getObjectId(), is(10200L)); assertThat(draftVersion.getItemUuid(), is(equalTo("acae860f-2ffa-450d-b486-054292f0dae6"))); assertThat(draftVersion.getVersion(), diff --git a/ccm-core/src/main/java/org/libreccm/workflow/AssignableTaskManager.java b/ccm-core/src/main/java/org/libreccm/workflow/AssignableTaskManager.java index eb84bc34b..80797e22d 100644 --- a/ccm-core/src/main/java/org/libreccm/workflow/AssignableTaskManager.java +++ b/ccm-core/src/main/java/org/libreccm/workflow/AssignableTaskManager.java @@ -26,10 +26,12 @@ import javax.inject.Inject; import javax.persistence.EntityManager; import javax.persistence.TypedQuery; import javax.transaction.Transactional; + import java.io.Serializable; import java.util.List; import java.util.Objects; import java.util.Optional; +import java.util.UUID; import java.util.stream.Collectors; /** @@ -78,6 +80,7 @@ public class AssignableTaskManager implements Serializable { final TaskAssignment assignment = new TaskAssignment(); assignment.setTask(task); assignment.setRole(role); + assignment.setUuid(UUID.randomUUID().toString()); task.addAssignment(assignment); role.addAssignedTask(assignment);