From 3521d30ec1d371e08e292a4aafdc83cf1ccf26ac Mon Sep 17 00:00:00 2001 From: jensp Date: Fri, 14 Jul 2017 14:59:16 +0000 Subject: [PATCH] CCM NG/ccm-cms: Fixed several test failures git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4870 8810af33-2d31-482b-a856-94f89814c4df --- .../contentsection/ContentItemManager.java | 1 + .../contentsection/AssetManagerTest.java | 11 +- .../ContentItemL10NManagerTest.java | 304 ++++++------ .../ContentItemManagerTest.java | 433 +++++++++++------- .../ItemAttachmentManagerTest.java | 225 +++++---- ...after-create-contentitem-with-workflow.xml | 7 +- .../after-create-contentitem.xml | 16 +- 7 files changed, 592 insertions(+), 405 deletions(-) diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemManager.java b/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemManager.java index 4f3883494..9aea00137 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemManager.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemManager.java @@ -1278,6 +1278,7 @@ public class ContentItemManager { .createNamedQuery( "ContentItem.findLiveVersion", ContentItem.class); query.setParameter("uuid", item.getItemUuid()); + contentItemRepo.setAuthorizationParameters(query); final ContentItem result = query.getSingleResult(); if (type.isAssignableFrom(result.getClass())) { diff --git a/ccm-cms/src/test/java/org/librecms/contentsection/AssetManagerTest.java b/ccm-cms/src/test/java/org/librecms/contentsection/AssetManagerTest.java index 4cd876730..4962c21aa 100644 --- a/ccm-cms/src/test/java/org/librecms/contentsection/AssetManagerTest.java +++ b/ccm-cms/src/test/java/org/librecms/contentsection/AssetManagerTest.java @@ -202,7 +202,7 @@ public class AssetManagerTest { "datasets/org/librecms/contentsection/AssetManagerTest/data.xml") @ShouldMatchDataSet( value - = "datasets/org/librecms/contentsection/AssetManagerTest/after-share.xml", + = "datasets/org/librecms/contentsection/AssetManagerTest/after-share.xml", excludeColumns = {"asset_id", "categorization_id", "id", @@ -465,11 +465,14 @@ public class AssetManagerTest { "categorization_id", "object_order"}) public void copyAssetToSameFolder() { - final Asset asset = assetRepo.findById(-1100L).get(); - final Folder targetFolder = folderRepo.findById(-420L).get(); + shiro.getSystemUser().execute(() -> { + final Asset asset = assetRepo.findById(-1100L).get(); - assetManager.copy(asset, targetFolder); + final Folder targetFolder = folderRepo.findById(-420L).get(); + + assetManager.copy(asset, targetFolder); + }); } /** diff --git a/ccm-cms/src/test/java/org/librecms/contentsection/ContentItemL10NManagerTest.java b/ccm-cms/src/test/java/org/librecms/contentsection/ContentItemL10NManagerTest.java index c59537713..c49368d3b 100644 --- a/ccm-cms/src/test/java/org/librecms/contentsection/ContentItemL10NManagerTest.java +++ b/ccm-cms/src/test/java/org/librecms/contentsection/ContentItemL10NManagerTest.java @@ -100,67 +100,67 @@ public class ContentItemL10NManagerTest { @Deployment public static WebArchive createDeployment() { return ShrinkWrap - .create(WebArchive.class, - "LibreCCM-org.librecms.contentsection.ContentItemManagerTest.war"). - addPackage(org.libreccm.auditing.CcmRevision.class.getPackage()) - .addPackage(org.libreccm.categorization.Categorization.class - .getPackage()) - .addPackage(org.libreccm.cdi.utils.CdiUtil.class.getPackage()) - .addPackage(org.libreccm.configuration.Configuration.class - .getPackage()) - .addPackage(org.libreccm.core.CcmCore.class.getPackage()) - .addPackage(org.libreccm.jpa.EntityManagerProducer.class - .getPackage()) - .addPackage(org.libreccm.jpa.utils.MimeTypeConverter.class - .getPackage()) - .addPackage(org.libreccm.l10n.LocalizedString.class - .getPackage()) - .addClass(org.libreccm.portation.Portable.class) - .addPackage(org.libreccm.security.Permission.class.getPackage()) - .addPackage(org.libreccm.web.CcmApplication.class.getPackage()) - .addPackage(org.libreccm.workflow.Workflow.class.getPackage()) - .addPackage(com.arsdigita.bebop.Component.class.getPackage()) - .addPackage(com.arsdigita.bebop.util.BebopConstants.class - .getPackage()) - .addClass(com.arsdigita.kernel.KernelConfig.class) - .addClass(com.arsdigita.runtime.CCMResourceManager.class) - .addClass(com.arsdigita.dispatcher.RequestContext.class) - .addClass(com.arsdigita.dispatcher.AccessDeniedException.class) - .addClass( - com.arsdigita.cms.dispatcher.ContentItemDispatcher.class). - addClass(com.arsdigita.dispatcher.Dispatcher.class) - .addClass( - com.arsdigita.ui.admin.applications.AbstractAppInstanceForm.class). - addClass( - com.arsdigita.ui.admin.applications.AbstractAppSettingsPane.class). - addClass( - com.arsdigita.ui.admin.applications.DefaultApplicationInstanceForm.class). - addClass( - com.arsdigita.ui.admin.applications.DefaultApplicationSettingsPane.class). - addClass(org.librecms.dispatcher.ItemResolver.class) - .addPackage(com.arsdigita.util.Lockable.class.getPackage()) - .addPackage(com.arsdigita.web.BaseServlet.class.getPackage()) - .addPackage(org.librecms.Cms.class.getPackage()) - .addPackage(org.librecms.contentsection.Asset.class.getPackage()). - addPackage(org.librecms.contentsection.AttachmentList.class - .getPackage()) - .addPackage(org.librecms.lifecycle.Lifecycle.class.getPackage()) - .addPackage(org.librecms.contentsection.ContentSection.class - .getPackage()) - .addPackage(org.librecms.contenttypes.Article.class.getPackage()). - addClass(com.arsdigita.kernel.security.SecurityConfig.class) - .addPackage(org.libreccm.tests.categories.IntegrationTest.class - .getPackage()) - // .addAsLibraries(getModuleDependencies()) - .addAsLibraries(getCcmCoreDependencies()) - .addAsResource("configs/shiro.ini", "shiro.ini") - .addAsResource( - "configs/org/librecms/contentsection/ContentItemManagerTest/log4j2.xml", - "log4j2.xml") - .addAsResource("test-persistence.xml", - "META-INF/persistence.xml") - .addAsWebInfResource("test-web.xml", "web.xml") - .addAsWebInfResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml"); + .create(WebArchive.class, + "LibreCCM-org.librecms.contentsection.ContentItemManagerTest.war") + .addPackage(org.libreccm.auditing.CcmRevision.class.getPackage()) + .addPackage(org.libreccm.categorization.Categorization.class + .getPackage()) + .addPackage(org.libreccm.cdi.utils.CdiUtil.class.getPackage()) + .addPackage(org.libreccm.configuration.Configuration.class + .getPackage()) + .addPackage(org.libreccm.core.CcmCore.class.getPackage()) + .addPackage(org.libreccm.jpa.EntityManagerProducer.class + .getPackage()) + .addPackage(org.libreccm.jpa.utils.MimeTypeConverter.class + .getPackage()) + .addPackage(org.libreccm.l10n.LocalizedString.class + .getPackage()) + .addClass(org.libreccm.portation.Portable.class) + .addPackage(org.libreccm.security.Permission.class.getPackage()) + .addPackage(org.libreccm.web.CcmApplication.class.getPackage()) + .addPackage(org.libreccm.workflow.Workflow.class.getPackage()) + .addPackage(com.arsdigita.bebop.Component.class.getPackage()) + .addPackage(com.arsdigita.bebop.util.BebopConstants.class + .getPackage()) + .addClass(com.arsdigita.kernel.KernelConfig.class) + .addClass(com.arsdigita.runtime.CCMResourceManager.class) + .addClass(com.arsdigita.dispatcher.RequestContext.class) + .addClass(com.arsdigita.dispatcher.AccessDeniedException.class) + .addClass( + com.arsdigita.cms.dispatcher.ContentItemDispatcher.class). + addClass(com.arsdigita.dispatcher.Dispatcher.class) + .addClass( + com.arsdigita.ui.admin.applications.AbstractAppInstanceForm.class) + .addClass( + com.arsdigita.ui.admin.applications.AbstractAppSettingsPane.class) + .addClass( + com.arsdigita.ui.admin.applications.DefaultApplicationInstanceForm.class) + .addClass( + com.arsdigita.ui.admin.applications.DefaultApplicationSettingsPane.class) + .addClass(org.librecms.dispatcher.ItemResolver.class) + .addPackage(com.arsdigita.util.Lockable.class.getPackage()) + .addPackage(com.arsdigita.web.BaseServlet.class.getPackage()) + .addPackage(org.librecms.Cms.class.getPackage()) + .addPackage(org.librecms.contentsection.Asset.class.getPackage()). + addPackage(org.librecms.contentsection.AttachmentList.class + .getPackage()) + .addPackage(org.librecms.lifecycle.Lifecycle.class.getPackage()) + .addPackage(org.librecms.contentsection.ContentSection.class + .getPackage()) + .addPackage(org.librecms.contenttypes.Article.class.getPackage()). + addClass(com.arsdigita.kernel.security.SecurityConfig.class) + .addPackage(org.libreccm.tests.categories.IntegrationTest.class + .getPackage()) + // .addAsLibraries(getModuleDependencies()) + .addAsLibraries(getCcmCoreDependencies()) + .addAsResource("configs/shiro.ini", "shiro.ini") + .addAsResource( + "configs/org/librecms/contentsection/ContentItemManagerTest/log4j2.xml", + "log4j2.xml") + .addAsResource("test-persistence.xml", + "META-INF/persistence.xml") + .addAsWebInfResource("test-web.xml", "web.xml") + .addAsWebInfResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml"); } @Test @@ -179,7 +179,7 @@ public class ContentItemL10NManagerTest { @Test @InSequence(10) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemL10NManagerTest/data.xml") + + "ContentItemL10NManagerTest/data.xml") public void verifyHasLanguage() { shiro.getSystemUser().execute(() -> { final Optional item = itemRepo.findById(-10100L); @@ -204,7 +204,7 @@ public class ContentItemL10NManagerTest { @Test(expected = IllegalArgumentException.class) @InSequence(20) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemL10NManagerTest/data.xml") + + "ContentItemL10NManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void hasLanguageItemIsNull() { final ContentItem item = null; @@ -221,14 +221,17 @@ public class ContentItemL10NManagerTest { @Test(expected = IllegalArgumentException.class) @InSequence(30) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemL10NManagerTest/data.xml") + + "ContentItemL10NManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void hasLanguageLanguageIsNull() { - final Optional item = itemRepo.findById(-10100L); - assertThat(item.isPresent(), is(true)); - assertThat(l10nManager.hasLanguage(item.get(), null), - is(true)); + shiro.getSystemUser().execute(() -> { + final Optional item = itemRepo.findById(-10100L); + assertThat(item.isPresent(), is(true)); + + assertThat(l10nManager.hasLanguage(item.get(), null), + is(true)); + }); } @@ -239,16 +242,19 @@ public class ContentItemL10NManagerTest { @Test @InSequence(40) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemL10NManagerTest/data.xml") + + "ContentItemL10NManagerTest/data.xml") @ShouldMatchDataSet( - value = "datasets/org/librecms/contentsection/" - + "ContentItemL10NManagerTest/after-add-language.xml", - excludeColumns = {"timestamp"}) + value = "datasets/org/librecms/contentsection/" + + "ContentItemL10NManagerTest/after-add-language.xml", + excludeColumns = {"timestamp"}) public void addLanguage() { - final Optional item = itemRepo.findById(-10100L); - assertThat(item.isPresent(), is(true)); - l10nManager.addLanguage(item.get(), Locale.GERMAN); + shiro.getSystemUser().execute(() -> { + final Optional item = itemRepo.findById(-10100L); + assertThat(item.isPresent(), is(true)); + + l10nManager.addLanguage(item.get(), Locale.GERMAN); + }); } /** @@ -259,15 +265,18 @@ public class ContentItemL10NManagerTest { @Test @InSequence(50) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemL10NManagerTest/data.xml") + + "ContentItemL10NManagerTest/data.xml") @ShouldMatchDataSet( - value = "datasets/org/librecms/contentsection/" - + "ContentItemL10NManagerTest/data.xml") + value = "datasets/org/librecms/contentsection/" + + "ContentItemL10NManagerTest/data.xml") public void addLanguageAlreadyPresent() { - final Optional item = itemRepo.findById(-10100L); - assertThat(item.isPresent(), is(true)); - l10nManager.addLanguage(item.get(), Locale.FRENCH); + shiro.getSystemUser().execute(() -> { + final Optional item = itemRepo.findById(-10100L); + assertThat(item.isPresent(), is(true)); + + l10nManager.addLanguage(item.get(), Locale.FRENCH); + }); } @@ -279,15 +288,18 @@ public class ContentItemL10NManagerTest { @Test(expected = IllegalArgumentException.class) @InSequence(60) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemL10NManagerTest/data.xml") + + "ContentItemL10NManagerTest/data.xml") @ShouldMatchDataSet( - value = "datasets/org/librecms/contentsection/" - + "ContentItemL10NManagerTest/data.xml") + value = "datasets/org/librecms/contentsection/" + + "ContentItemL10NManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void addLanguageItemIsNull() { - final ContentItem item = null; - l10nManager.addLanguage(item, Locale.GERMAN); + shiro.getSystemUser().execute(() -> { + final ContentItem item = null; + + l10nManager.addLanguage(item, Locale.GERMAN); + }); } /** @@ -298,16 +310,19 @@ public class ContentItemL10NManagerTest { @Test(expected = IllegalArgumentException.class) @InSequence(20) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemL10NManagerTest/data.xml") + + "ContentItemL10NManagerTest/data.xml") @ShouldMatchDataSet( - value = "datasets/org/librecms/contentsection/" - + "ContentItemL10NManagerTest/data.xml") + value = "datasets/org/librecms/contentsection/" + + "ContentItemL10NManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void addLanguageLanguageIsNull() { - final Optional item = itemRepo.findById(-10100L); - assertThat(item.isPresent(), is(true)); - l10nManager.addLanguage(item.get(), null); + shiro.getSystemUser().execute(() -> { + final Optional item = itemRepo.findById(-10100L); + assertThat(item.isPresent(), is(true)); + + l10nManager.addLanguage(item.get(), null); + }); } /** @@ -317,16 +332,19 @@ public class ContentItemL10NManagerTest { @Test @InSequence(70) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemL10NManagerTest/data.xml") + + "ContentItemL10NManagerTest/data.xml") @ShouldMatchDataSet( - value = "datasets/org/librecms/contentsection/" - + "ContentItemL10NManagerTest/after-remove-language.xml", - excludeColumns = {"timestamp"}) + value = "datasets/org/librecms/contentsection/" + + "ContentItemL10NManagerTest/after-remove-language.xml", + excludeColumns = {"timestamp"}) public void removeLanguage() { - final Optional item = itemRepo.findById(-10100L); - assertThat(item.isPresent(), is(true)); - l10nManager.removeLanguage(item.get(), Locale.FRENCH); + shiro.getSystemUser().execute(() -> { + final Optional item = itemRepo.findById(-10100L); + assertThat(item.isPresent(), is(true)); + + l10nManager.removeLanguage(item.get(), Locale.FRENCH); + }); } /** @@ -337,15 +355,18 @@ public class ContentItemL10NManagerTest { @Test @InSequence(80) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemL10NManagerTest/data.xml") + + "ContentItemL10NManagerTest/data.xml") @ShouldMatchDataSet( - value = "datasets/org/librecms/contentsection/" - + "ContentItemL10NManagerTest/data.xml") + value = "datasets/org/librecms/contentsection/" + + "ContentItemL10NManagerTest/data.xml") public void removeNotPresentLanguage() { - final Optional item = itemRepo.findById(-10100L); - assertThat(item.isPresent(), is(true)); - l10nManager.removeLanguage(item.get(), Locale.GERMAN); + shiro.getSystemUser().execute(() -> { + final Optional item = itemRepo.findById(-10100L); + assertThat(item.isPresent(), is(true)); + + l10nManager.removeLanguage(item.get(), Locale.GERMAN); + }); } /** @@ -357,15 +378,18 @@ public class ContentItemL10NManagerTest { @Test(expected = IllegalArgumentException.class) @InSequence(90) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemL10NManagerTest/data.xml") + + "ContentItemL10NManagerTest/data.xml") @ShouldMatchDataSet( - value = "datasets/org/librecms/contentsection/" - + "ContentItemL10NManagerTest/data.xml") + value = "datasets/org/librecms/contentsection/" + + "ContentItemL10NManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void removeLanguageItemIsNull() { - final ContentItem item = null; - l10nManager.removeLanguage(item, Locale.GERMAN); + shiro.getSystemUser().execute(() -> { + final ContentItem item = null; + + l10nManager.removeLanguage(item, Locale.GERMAN); + }); } /** @@ -377,16 +401,19 @@ public class ContentItemL10NManagerTest { @Test(expected = IllegalArgumentException.class) @InSequence(100) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemL10NManagerTest/data.xml") + + "ContentItemL10NManagerTest/data.xml") @ShouldMatchDataSet( - value = "datasets/org/librecms/contentsection/" - + "ContentItemL10NManagerTest/data.xml") + value = "datasets/org/librecms/contentsection/" + + "ContentItemL10NManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void removeLanguageLanguageIsNull() { - final Optional item = itemRepo.findById(-10100L); - assertThat(item.isPresent(), is(true)); - l10nManager.removeLanguage(item.get(), null); + shiro.getSystemUser().execute(() -> { + final Optional item = itemRepo.findById(-10100L); + assertThat(item.isPresent(), is(true)); + + l10nManager.removeLanguage(item.get(), null); + }); } @@ -397,16 +424,19 @@ public class ContentItemL10NManagerTest { @Test @InSequence(120) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemL10NManagerTest/data.xml") + + "ContentItemL10NManagerTest/data.xml") @ShouldMatchDataSet( - value = "datasets/org/librecms/contentsection/" - + "ContentItemL10NManagerTest/after-normalize.xml", - excludeColumns = {"timestamp"}) + value = "datasets/org/librecms/contentsection/" + + "ContentItemL10NManagerTest/after-normalize.xml", + excludeColumns = {"timestamp"}) public void normalizeItem() { - final Optional item = itemRepo.findById(-10200L); - assertThat(item.isPresent(), is(true)); - l10nManager.normalizeLanguages(item.get()); + shiro.getSystemUser().execute(() -> { + final Optional item = itemRepo.findById(-10200L); + assertThat(item.isPresent(), is(true)); + + l10nManager.normalizeLanguages(item.get()); + }); } /** @@ -417,15 +447,18 @@ public class ContentItemL10NManagerTest { @Test @InSequence(130) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemL10NManagerTest/data.xml") + + "ContentItemL10NManagerTest/data.xml") @ShouldMatchDataSet( - value = "datasets/org/librecms/contentsection/" - + "ContentItemL10NManagerTest/data.xml") + value = "datasets/org/librecms/contentsection/" + + "ContentItemL10NManagerTest/data.xml") public void normalizeItemAlreadyNormalized() { - final Optional item = itemRepo.findById(-10100L); - assertThat(item.isPresent(), is(true)); - l10nManager.normalizeLanguages(item.get()); + shiro.getSystemUser().execute(() -> { + final Optional item = itemRepo.findById(-10100L); + assertThat(item.isPresent(), is(true)); + + l10nManager.normalizeLanguages(item.get()); + }); } @@ -438,15 +471,18 @@ public class ContentItemL10NManagerTest { @Test(expected = IllegalArgumentException.class) @InSequence(140) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemL10NManagerTest/data.xml") + + "ContentItemL10NManagerTest/data.xml") @ShouldMatchDataSet( - value = "datasets/org/librecms/contentsection/" - + "ContentItemL10NManagerTest/data.xml") + value = "datasets/org/librecms/contentsection/" + + "ContentItemL10NManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void normalizeItemNull() { - final ContentItem item = null; - l10nManager.normalizeLanguages(item); + shiro.getSystemUser().execute(() -> { + final ContentItem item = null; + + l10nManager.normalizeLanguages(item); + }); } } 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 3b7da3b69..f190b85f9 100644 --- a/ccm-cms/src/test/java/org/librecms/contentsection/ContentItemManagerTest.java +++ b/ccm-cms/src/test/java/org/librecms/contentsection/ContentItemManagerTest.java @@ -228,6 +228,7 @@ public class ContentItemManagerTest { "object_order", "phase_id", "rev", + "task_assignment_id", "task_id", "uuid", "timestamp", @@ -259,7 +260,7 @@ public class ContentItemManagerTest { final TypedQuery query = entityManager.createQuery( "SELECT COUNT(w) FROM Workflow w", Long.class); final long workflowCount = query.getSingleResult(); - assertThat("Expected three workflows in database.", + assertThat("Expected four workflows in database.", workflowCount, is(4L)); }); } @@ -278,16 +279,19 @@ public class ContentItemManagerTest { + "ContentItemManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void createItemTypeNotInSection() { - final ContentSection section = sectionRepo - .findByLabel("info") - .get(); - final Folder folder = section.getRootDocumentsFolder(); - itemManager.createContentItem("Test", - section, - folder, - Event.class, - Locale.ENGLISH); + shiro.getSystemUser().execute(() -> { + final ContentSection section = sectionRepo + .findByLabel("info") + .get(); + final Folder folder = section.getRootDocumentsFolder(); + + itemManager.createContentItem("Test", + section, + folder, + Event.class, + Locale.ENGLISH); + }); } /** @@ -303,15 +307,16 @@ public class ContentItemManagerTest { + "ContentItemManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void createItemNameIsNull() { + shiro.getSystemUser().execute(() -> { final ContentSection section = sectionRepo .findByLabel("info") .get(); final Folder folder = section.getRootDocumentsFolder(); - itemManager.createContentItem(null, - section, - folder, + itemManager.createContentItem(null, + section, + folder, Article.class, Locale.ENGLISH); }); @@ -330,6 +335,7 @@ public class ContentItemManagerTest { + "ContentItemManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void createItemNameIsEmpty() { + shiro.getSystemUser().execute(() -> { final ContentSection section = sectionRepo .findByLabel("info") @@ -337,8 +343,8 @@ public class ContentItemManagerTest { final Folder folder = section.getRootDocumentsFolder(); itemManager.createContentItem(" ", - section, - folder, + section, + folder, Article.class, Locale.ENGLISH); }); @@ -358,14 +364,15 @@ public class ContentItemManagerTest { + "ContentItemManagerTest/data.xml") @ShouldThrowException(NullPointerException.class) public void createItemFolderIsNull() { + shiro.getSystemUser().execute(() -> { final ContentSection section = sectionRepo .findByLabel("info") .get(); - itemManager.createContentItem("Test", - section, - null, + itemManager.createContentItem("Test", + section, + null, Article.class, Locale.ENGLISH); }); @@ -392,11 +399,13 @@ public class ContentItemManagerTest { "phase_id", "rev", "task_id", + "task_assignment_id", "timestamp", "uuid", "workflow_id" }) public void createContentItemWithWorkflow() { + shiro.getSystemUser().execute(() -> { final ContentSection section = sectionRepo .findByLabel("info") @@ -477,6 +486,7 @@ public class ContentItemManagerTest { + "ContentItemManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void createItemNameIsNullWithWorkflow() { + shiro.getSystemUser().execute(() -> { final ContentSection section = sectionRepo .findByLabel("info") @@ -509,6 +519,7 @@ public class ContentItemManagerTest { + "ContentItemManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void createItemNameIsNullWorkflowIsNull() { + shiro.getSystemUser().execute(() -> { final ContentSection section = sectionRepo .findByLabel("info") @@ -538,6 +549,7 @@ public class ContentItemManagerTest { + "ContentItemManagerTest/data.xml") @ShouldThrowException(NullPointerException.class) public void createItemFolderIsNullWithWorkflow() { + shiro.getSystemUser().execute(() -> { final ContentSection section = sectionRepo .findByLabel("info") @@ -577,13 +589,15 @@ public class ContentItemManagerTest { }) public void moveItem() { - final Optional item = itemRepo.findById(-10100L); - assertThat(item.isPresent(), is(true)); + shiro.getSystemUser().execute(() -> { + final Optional item = itemRepo.findById(-10100L); + assertThat(item.isPresent(), is(true)); - final Folder targetFolder = folderRepo.findById(-2120L).get(); - assertThat(targetFolder, is(not(nullValue()))); + final Folder targetFolder = folderRepo.findById(-2120L).get(); + assertThat(targetFolder, is(not(nullValue()))); - itemManager.move(item.get(), targetFolder); + itemManager.move(item.get(), targetFolder); + }); } /** @@ -607,18 +621,21 @@ public class ContentItemManagerTest { "workflow_id" }) public void moveItemToOtherContentSection() { - final Optional item = itemRepo.findById(-10100L); - final Folder targetFolder = folderRepo.findById(-2300L).get(); - assertThat(item.isPresent(), is(true)); - assertThat(targetFolder, is(not(nullValue()))); + shiro.getSystemUser().execute(() -> { + final Optional item = itemRepo.findById(-10100L); + final Folder targetFolder = folderRepo.findById(-2300L).get(); - itemManager.move(item.get(), targetFolder); + assertThat(item.isPresent(), is(true)); + assertThat(targetFolder, is(not(nullValue()))); + + itemManager.move(item.get(), targetFolder); + }); } /** - * Verifies that null null null null null null null null null null null null - * null null null null null null null null null null {@link ContentItemManager#move(org.librecms.contentsection.ContentItem, org.librecms.contentsection.Folder) + * Verifies that + * {@link ContentItemManager#move(org.librecms.contentsection.ContentItem, org.librecms.contentsection.Folder)} * throws an {@link IllegalArgumentException} if the type of the item to * copy has not been registered in content section to which the target * folder belongs. @@ -631,13 +648,16 @@ public class ContentItemManagerTest { + "ContentItemManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void moveToOtherContentSectionTypeNotPresent() { - final Optional item = itemRepo.findById(-10400L); - final Folder targetFolder = folderRepo.findById(-2300L).get(); - assertThat(item.isPresent(), is(true)); - assertThat(targetFolder, is(not(nullValue()))); + shiro.getSystemUser().execute(() -> { + final Optional item = itemRepo.findById(-10400L); + final Folder targetFolder = folderRepo.findById(-2300L).get(); - itemManager.move(item.get(), targetFolder); + assertThat(item.isPresent(), is(true)); + assertThat(targetFolder, is(not(nullValue()))); + + itemManager.move(item.get(), targetFolder); + }); } /** @@ -654,10 +674,13 @@ public class ContentItemManagerTest { + "ContentItemManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void moveItemNull() { - final Folder targetFolder = folderRepo.findById(-2120L).get(); - assertThat(targetFolder, is(not(nullValue()))); - itemManager.move(null, targetFolder); + shiro.getSystemUser().execute(() -> { + final Folder targetFolder = folderRepo.findById(-2120L).get(); + assertThat(targetFolder, is(not(nullValue()))); + + itemManager.move(null, targetFolder); + }); } /** @@ -674,10 +697,13 @@ public class ContentItemManagerTest { + "ContentItemManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void moveItemTargetFolderIsNull() { - final Optional item = itemRepo.findById(-10100L); - assertThat(item.isPresent(), is(true)); - itemManager.move(item.get(), null); + shiro.getSystemUser().execute(() -> { + final Optional item = itemRepo.findById(-10100L); + assertThat(item.isPresent(), is(true)); + + itemManager.move(item.get(), null); + }); } /** @@ -709,13 +735,16 @@ public class ContentItemManagerTest { "workflow_id" }) public void copyToOtherFolder() { - final Optional item = itemRepo.findById(-10100L); - assertThat(item.isPresent(), is(true)); - final Folder targetFolder = folderRepo.findById(-2120L).get(); - assertThat(targetFolder, is(not(nullValue()))); + shiro.getSystemUser().execute(() -> { + final Optional item = itemRepo.findById(-10100L); + assertThat(item.isPresent(), is(true)); - itemManager.copy(item.get(), targetFolder); + final Folder targetFolder = folderRepo.findById(-2120L).get(); + assertThat(targetFolder, is(not(nullValue()))); + + itemManager.copy(item.get(), targetFolder); + }); } /** @@ -747,16 +776,21 @@ public class ContentItemManagerTest { "workflow_id" }) public void copyToFolderInOtherSection() { - final Optional source = itemRepo.findById(-10100L); - final Folder targetFolder = folderRepo.findById(-2300L).get(); - assertThat(source.isPresent(), is(true)); - assertThat(targetFolder, is(not(nullValue()))); + shiro.getSystemUser().execute(() -> { + final Optional source = itemRepo.findById(-10100L); + final Folder targetFolder = folderRepo.findById(-2300L).get(); - final ContentItem target = itemManager.copy(source.get(), targetFolder); + assertThat(source.isPresent(), is(true)); + assertThat(targetFolder, is(not(nullValue()))); - assertThat(target.getUuid(), is(not(equalTo(source.get().getUuid())))); - assertThat(target.getItemUuid(), is(equalTo(target.getUuid()))); + final ContentItem target = itemManager.copy(source.get(), + targetFolder); + + assertThat(target.getUuid(), + is(not(equalTo(source.get().getUuid())))); + assertThat(target.getItemUuid(), is(equalTo(target.getUuid()))); + }); } /** @@ -774,13 +808,16 @@ public class ContentItemManagerTest { + "ContentItemManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void copyToFolderInOtherSectionTypeNotPresent() { - final Optional source = itemRepo.findById(-10400L); - final Folder targetFolder = folderRepo.findById(-2300L).get(); - assertThat(source.isPresent(), is(true)); - assertThat(targetFolder, is(not(nullValue()))); + shiro.getSystemUser().execute(() -> { + final Optional source = itemRepo.findById(-10400L); + final Folder targetFolder = folderRepo.findById(-2300L).get(); - itemManager.copy(source.get(), targetFolder); + assertThat(source.isPresent(), is(true)); + assertThat(targetFolder, is(not(nullValue()))); + + itemManager.copy(source.get(), targetFolder); + }); } /** @@ -814,13 +851,16 @@ public class ContentItemManagerTest { "workflow_id" }) public void copyToSameFolder() { - final Optional item = itemRepo.findById(-10100L); - assertThat(item.isPresent(), is(true)); - final Folder targetFolder = folderRepo.findById(-2110L).get(); - assertThat(targetFolder, is(not(nullValue()))); + shiro.getSystemUser().execute(() -> { + final Optional item = itemRepo.findById(-10100L); + assertThat(item.isPresent(), is(true)); - itemManager.copy(item.get(), targetFolder); + final Folder targetFolder = folderRepo.findById(-2110L).get(); + assertThat(targetFolder, is(not(nullValue()))); + + itemManager.copy(item.get(), targetFolder); + }); } /** @@ -838,10 +878,13 @@ public class ContentItemManagerTest { + "ContentItemManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void copyItemNull() { - final Folder targetFolder = folderRepo.findById(-2120L).get(); - assertThat(targetFolder, is(not(nullValue()))); - itemManager.copy(null, targetFolder); + shiro.getSystemUser().execute(() -> { + final Folder targetFolder = folderRepo.findById(-2120L).get(); + assertThat(targetFolder, is(not(nullValue()))); + + itemManager.copy(null, targetFolder); + }); } /** @@ -859,10 +902,13 @@ public class ContentItemManagerTest { + "ContentItemManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void copyItemToFolderNull() { - final Optional item = itemRepo.findById(-10100L); - assertThat(item.isPresent(), is(true)); - itemManager.copy(item.get(), null); + shiro.getSystemUser().execute(() -> { + final Optional item = itemRepo.findById(-10100L); + assertThat(item.isPresent(), is(true)); + + itemManager.copy(item.get(), null); + }); } /** @@ -897,12 +943,15 @@ public class ContentItemManagerTest { "workflow_id" }) public void publishItem() { - final Optional item = itemRepo.findById(-10100L); - assertThat(item.isPresent(), is(true)); - final ContentItem live = itemManager.publish(item.get()); - assertThat(live, is(not(nullValue()))); - assertThat(live.getVersion(), is(ContentItemVersion.LIVE)); + shiro.getSystemUser().execute(() -> { + final Optional item = itemRepo.findById(-10100L); + assertThat(item.isPresent(), is(true)); + + final ContentItem live = itemManager.publish(item.get()); + assertThat(live, is(not(nullValue()))); + assertThat(live.getVersion(), is(ContentItemVersion.LIVE)); + }); } /** @@ -937,15 +986,19 @@ public class ContentItemManagerTest { "workflow_id" }) public void publishItemWithLifecycle() { - final Optional item = itemRepo.findById(-10100L); - final LifecycleDefinition lifecycleDef = lifecycleDefinitionRepo - .findById(-200L).get(); - assertThat(item.isPresent(), is(true)); - assertThat(lifecycleDef, is(not(nullValue()))); - final ContentItem live = itemManager.publish(item.get(), lifecycleDef); - assertThat(live, is(not(nullValue()))); - assertThat(live.getVersion(), is(ContentItemVersion.LIVE)); + shiro.getSystemUser().execute(() -> { + final Optional item = itemRepo.findById(-10100L); + final LifecycleDefinition lifecycleDef = lifecycleDefinitionRepo + .findById(-200L).get(); + assertThat(item.isPresent(), is(true)); + assertThat(lifecycleDef, is(not(nullValue()))); + + final ContentItem live = itemManager.publish(item.get(), + lifecycleDef); + assertThat(live, is(not(nullValue()))); + assertThat(live.getVersion(), is(ContentItemVersion.LIVE)); + }); } /** @@ -971,18 +1024,21 @@ public class ContentItemManagerTest { "uuid", "workflow_id"}) public void republishItem() { - final Optional item = itemRepo.findById(-10200L); - assertThat(item.isPresent(), is(true)); - item.get().getName().addValue(Locale.ENGLISH, "article2-edited"); - item.get().getTitle() - .addValue(Locale.ENGLISH, "Article has been edited"); - itemRepo.save(item.get()); + shiro.getSystemUser().execute(() -> { + final Optional item = itemRepo.findById(-10200L); + assertThat(item.isPresent(), is(true)); - final Optional draft = itemRepo.findById(-10200L); - assertThat(draft.get().getName().getValue(Locale.ENGLISH), - is(equalTo("article2-edited"))); - itemManager.publish(draft.get()); + item.get().getName().addValue(Locale.ENGLISH, "article2-edited"); + item.get().getTitle() + .addValue(Locale.ENGLISH, "Article has been edited"); + itemRepo.save(item.get()); + + final Optional draft = itemRepo.findById(-10200L); + assertThat(draft.get().getName().getValue(Locale.ENGLISH), + is(equalTo("article2-edited"))); + itemManager.publish(draft.get()); + }); } /** @@ -999,9 +1055,12 @@ public class ContentItemManagerTest { + "ContentItemManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void publishItemNull() { - final ContentItem item = null; - itemManager.publish(item); + shiro.getSystemUser().execute(() -> { + final ContentItem item = null; + + itemManager.publish(item); + }); } /** @@ -1018,9 +1077,12 @@ public class ContentItemManagerTest { + "ContentItemManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void publishItemLifecycleIsNull() { - final Optional draft = itemRepo.findById(-10200L); - itemManager.publish(draft.get(), null); + shiro.getSystemUser().execute(() -> { + final Optional draft = itemRepo.findById(-10200L); + + itemManager.publish(draft.get(), null); + }); } /** @@ -1047,10 +1109,13 @@ public class ContentItemManagerTest { "uuid", "workflow_id"}) public void unpublishItem() { - final Optional item = itemRepo.findById(-10200L); - assertThat(item.isPresent(), is(true)); - itemManager.unpublish(item.get()); + shiro.getSystemUser().execute(() -> { + final Optional item = itemRepo.findById(-10200L); + assertThat(item.isPresent(), is(true)); + + itemManager.unpublish(item.get()); + }); } /** @@ -1065,10 +1130,13 @@ public class ContentItemManagerTest { @ShouldMatchDataSet("datasets/org/librecms/contentsection/" + "ContentItemManagerTest/data.xml") public void unpublishNonLiveItem() { - final Optional item = itemRepo.findById(-10300L); - assertThat(item.isPresent(), is(true)); - itemManager.unpublish(item.get()); + shiro.getSystemUser().execute(() -> { + final Optional item = itemRepo.findById(-10300L); + assertThat(item.isPresent(), is(true)); + + itemManager.unpublish(item.get()); + }); } /** @@ -1085,8 +1153,11 @@ public class ContentItemManagerTest { + "ContentItemManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void unpublishItemNull() { - final ContentItem item = null; - itemManager.unpublish(item); + + shiro.getSystemUser().execute(() -> { + final ContentItem item = null; + itemManager.unpublish(item); + }); } /** @@ -1101,20 +1172,23 @@ public class ContentItemManagerTest { @ShouldMatchDataSet("datasets/org/librecms/contentsection/" + "ContentItemManagerTest/data.xml") public void isLive() { - 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)); - assertThat(item3.isPresent(), is(true)); - assertThat(item4.isPresent(), is(true)); + 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); - assertThat(itemManager.isLive(item1.get()), is(false)); - assertThat(itemManager.isLive(item2.get()), is(true)); - assertThat(itemManager.isLive(item3.get()), is(false)); - assertThat(itemManager.isLive(item4.get()), is(false)); + assertThat(item1.isPresent(), is(true)); + assertThat(item2.isPresent(), is(true)); + assertThat(item3.isPresent(), is(true)); + assertThat(item4.isPresent(), is(true)); + + assertThat(itemManager.isLive(item1.get()), is(false)); + assertThat(itemManager.isLive(item2.get()), is(true)); + assertThat(itemManager.isLive(item3.get()), is(false)); + assertThat(itemManager.isLive(item4.get()), is(false)); + }); } /** @@ -1131,43 +1205,46 @@ public class ContentItemManagerTest { @ShouldMatchDataSet("datasets/org/librecms/contentsection/" + "ContentItemManagerTest/data.xml") public void getLiveVersion() { - 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); + 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); - assertThat(itemManager.getLiveVersion(draft1.get(), - ContentItem.class).isPresent(), - is(false)); - final Optional
liveVersion = itemManager.getLiveVersion( - draft2.get(), Article.class); - assertThat(liveVersion.isPresent(), - is(true)); - assertThat(liveVersion.get().getObjectId(), - is(-99200L)); - assertThat(liveVersion.get().getItemUuid(), - is(equalTo("acae860f-2ffa-450d-b486-054292f0dae6"))); - assertThat(liveVersion.get().getVersion(), - is(ContentItemVersion.LIVE)); - assertThat(itemManager.getLiveVersion(draft3.get(), - ContentItem.class).isPresent(), - is(false)); - assertThat(itemManager.getLiveVersion(draft4.get(), - ContentItem.class).isPresent(), - is(false)); + final Optional live2 = itemRepo.findById(-99200L); - final Optional fromLive = itemManager.getLiveVersion( - live2.get(), ContentItem.class); - assertThat(fromLive.isPresent(), - is(true)); - assertThat(fromLive.get().getObjectId(), - is(-99200L)); - assertThat(fromLive.get().getItemUuid(), - is(equalTo("acae860f-2ffa-450d-b486-054292f0dae6"))); - assertThat(fromLive.get().getVersion(), - is(ContentItemVersion.LIVE)); + assertThat(itemManager.getLiveVersion(draft1.get(), + ContentItem.class).isPresent(), + is(false)); + final Optional
liveVersion = itemManager.getLiveVersion( + draft2.get(), Article.class); + assertThat(liveVersion.isPresent(), + is(true)); + assertThat(liveVersion.get().getObjectId(), + is(-99200L)); + assertThat(liveVersion.get().getItemUuid(), + is(equalTo("acae860f-2ffa-450d-b486-054292f0dae6"))); + assertThat(liveVersion.get().getVersion(), + is(ContentItemVersion.LIVE)); + assertThat(itemManager.getLiveVersion(draft3.get(), + ContentItem.class).isPresent(), + is(false)); + assertThat(itemManager.getLiveVersion(draft4.get(), + ContentItem.class).isPresent(), + is(false)); + + final Optional fromLive = itemManager.getLiveVersion( + live2.get(), ContentItem.class); + assertThat(fromLive.isPresent(), + is(true)); + assertThat(fromLive.get().getObjectId(), + is(-99200L)); + assertThat(fromLive.get().getItemUuid(), + is(equalTo("acae860f-2ffa-450d-b486-054292f0dae6"))); + assertThat(fromLive.get().getVersion(), + is(ContentItemVersion.LIVE)); + }); } /** @@ -1183,36 +1260,42 @@ public class ContentItemManagerTest { + "ContentItemManagerTest/data.xml") // getDraftVersion public void getDraftVersion() { - 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)); - assertThat(itemManager.getDraftVersion(draft2.get(), - ContentItem.class).getObjectId(), - is(-10200L)); - assertThat(itemManager.getDraftVersion(draft3.get(), - ContentItem.class).getObjectId(), - is(-10300L)); - assertThat(itemManager.getDraftVersion(draft4.get(), - ContentItem.class).getObjectId(), - is(-10400L)); + 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 live2 = itemRepo.findById(-99200L); + assertThat(itemManager.getDraftVersion(draft1.get(), + ContentItem.class) + .getObjectId(), + is(-10100L)); + assertThat(itemManager.getDraftVersion(draft2.get(), + ContentItem.class) + .getObjectId(), + is(-10200L)); + assertThat(itemManager.getDraftVersion(draft3.get(), + ContentItem.class) + .getObjectId(), + is(-10300L)); + assertThat(itemManager.getDraftVersion(draft4.get(), + ContentItem.class) + .getObjectId(), + is(-10400L)); - final ContentItem draftVersion = itemManager.getDraftVersion( - live2.get(), ContentItem.class); + final Optional live2 = itemRepo.findById(-99200L); - assertThat(draftVersion, is(not(nullValue()))); - assertThat(draftVersion.getObjectId(), is(-10200L)); - assertThat(draftVersion.getItemUuid(), - is(equalTo("acae860f-2ffa-450d-b486-054292f0dae6"))); - assertThat(draftVersion.getVersion(), - is(ContentItemVersion.DRAFT)); + final ContentItem draftVersion = itemManager.getDraftVersion( + live2.get(), ContentItem.class); + assertThat(draftVersion, is(not(nullValue()))); + assertThat(draftVersion.getObjectId(), is(-10200L)); + assertThat(draftVersion.getItemUuid(), + is(equalTo("acae860f-2ffa-450d-b486-054292f0dae6"))); + assertThat(draftVersion.getVersion(), + is(ContentItemVersion.DRAFT)); + }); } } diff --git a/ccm-cms/src/test/java/org/librecms/contentsection/ItemAttachmentManagerTest.java b/ccm-cms/src/test/java/org/librecms/contentsection/ItemAttachmentManagerTest.java index 15183c13e..37de64c44 100644 --- a/ccm-cms/src/test/java/org/librecms/contentsection/ItemAttachmentManagerTest.java +++ b/ccm-cms/src/test/java/org/librecms/contentsection/ItemAttachmentManagerTest.java @@ -206,12 +206,16 @@ public class ItemAttachmentManagerTest { "uuid", "attachment_id"}) public void attachNonSharedAsset() throws MimeTypeParseException { - final Optional item = itemRepo.findById(-510L); - assertThat(item.isPresent(), is(true)); - final Asset file = assetRepo.findById(-720L).get(); + shiro.getSystemUser().execute(() -> { + final Optional item = itemRepo.findById(-510L); + assertThat(item.isPresent(), is(true)); - attachmentManager.attachAsset(file, item.get().getAttachments().get(1)); + final Asset file = assetRepo.findById(-720L).get(); + + attachmentManager.attachAsset(file, item.get().getAttachments().get( + 1)); + }); } /** @@ -231,13 +235,16 @@ public class ItemAttachmentManagerTest { "uuid", "attachment_id"}) public void attachSharedAsset() throws MimeTypeParseException { - final Optional item = itemRepo.findById(-510L); - assertThat(item.isPresent(), is(true)); - final Asset shared = assetRepo.findById(-610L).get(); + shiro.getSystemUser().execute(() -> { + final Optional item = itemRepo.findById(-510L); + assertThat(item.isPresent(), is(true)); - attachmentManager.attachAsset(shared, - item.get().getAttachments().get(1)); + final Asset shared = assetRepo.findById(-610L).get(); + + attachmentManager.attachAsset(shared, + item.get().getAttachments().get(1)); + }); } /** @@ -253,13 +260,16 @@ public class ItemAttachmentManagerTest { @ShouldMatchDataSet("datasets/org/librecms/contentsection/" + "ItemAttachmentManagerTest/data.xml") public void attachAssetAlreadyAttached() { - final Optional item = itemRepo.findById(-510L); - assertThat(item.isPresent(), is(true)); - final Asset shared = assetRepo.findById(-620L).get(); + shiro.getSystemUser().execute(() -> { + final Optional item = itemRepo.findById(-510L); + assertThat(item.isPresent(), is(true)); - attachmentManager.attachAsset(shared, - item.get().getAttachments().get(1)); + final Asset shared = assetRepo.findById(-620L).get(); + + attachmentManager.attachAsset(shared, + item.get().getAttachments().get(1)); + }); } /** @@ -276,13 +286,16 @@ public class ItemAttachmentManagerTest { + "ItemAttachmentManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void attachAssetNull() { - final Optional item = itemRepo.findById(-510L); - assertThat(item.isPresent(), is(true)); - final Asset asset = null; + shiro.getSystemUser().execute(() -> { + final Optional item = itemRepo.findById(-510L); + assertThat(item.isPresent(), is(true)); - attachmentManager.attachAsset(asset, - item.get().getAttachments().get(1)); + final Asset asset = null; + + attachmentManager.attachAsset(asset, + item.get().getAttachments().get(1)); + }); } /** @@ -299,10 +312,13 @@ public class ItemAttachmentManagerTest { + "ItemAttachmentManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void attachAssetToListNull() { - final AttachmentList list = null; - final Asset shared = assetRepo.findById(-610L).get(); - attachmentManager.attachAsset(shared, list); + shiro.getSystemUser().execute(() -> { + final AttachmentList list = null; + final Asset shared = assetRepo.findById(-610L).get(); + + attachmentManager.attachAsset(shared, list); + }); } /** @@ -319,15 +335,18 @@ public class ItemAttachmentManagerTest { + "after-unattach-shared.xml", excludeColumns = {"timestamp"}) public void unattachSharedAsset() { - final Asset asset = assetRepo.findById(-610L).get(); - final Optional item = itemRepo.findById(-510L); - assertThat(asset, is(not(nullValue()))); - assertThat(item.isPresent(), is(true)); + shiro.getSystemUser().execute(() -> { + final Asset asset = assetRepo.findById(-610L).get(); + final Optional item = itemRepo.findById(-510L); - final AttachmentList list = item.get().getAttachments().get(0); + assertThat(asset, is(not(nullValue()))); + assertThat(item.isPresent(), is(true)); - attachmentManager.unattachAsset(asset, list); + final AttachmentList list = item.get().getAttachments().get(0); + + attachmentManager.unattachAsset(asset, list); + }); } /** @@ -346,15 +365,18 @@ public class ItemAttachmentManagerTest { + "after-unattach-nonshared.xml", excludeColumns = {"timestamp"}) public void unattachNonSharedAsset() { - final Asset asset = assetRepo.findById(-720L).get(); - final Optional item = itemRepo.findById(-510L); - assertThat(asset, is(not(nullValue()))); - assertThat(item.isPresent(), is(true)); + shiro.getSystemUser().execute(() -> { + final Asset asset = assetRepo.findById(-720L).get(); + final Optional item = itemRepo.findById(-510L); - final AttachmentList list = item.get().getAttachments().get(0); + assertThat(asset, is(not(nullValue()))); + assertThat(item.isPresent(), is(true)); - attachmentManager.unattachAsset(asset, list); + final AttachmentList list = item.get().getAttachments().get(0); + + attachmentManager.unattachAsset(asset, list); + }); } /** @@ -370,15 +392,18 @@ public class ItemAttachmentManagerTest { @ShouldMatchDataSet("datasets/org/librecms/contentsection/" + "ItemAttachmentManagerTest/data.xml") public void unattachAssetNotAttached() { - final Asset asset = assetRepo.findById(-720L).get(); - final Optional item = itemRepo.findById(-510L); - assertThat(asset, is(not(nullValue()))); - assertThat(item.isPresent(), is(true)); + shiro.getSystemUser().execute(() -> { + final Asset asset = assetRepo.findById(-720L).get(); + final Optional item = itemRepo.findById(-510L); - final AttachmentList list = item.get().getAttachments().get(1); + assertThat(asset, is(not(nullValue()))); + assertThat(item.isPresent(), is(true)); - attachmentManager.unattachAsset(asset, list); + final AttachmentList list = item.get().getAttachments().get(1); + + attachmentManager.unattachAsset(asset, list); + }); } /** @@ -395,14 +420,17 @@ public class ItemAttachmentManagerTest { + "ItemAttachmentManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void unattachAssetNull() { - final Asset asset = null; - final Optional item = itemRepo.findById(-510L); - assertThat(item.isPresent(), is(true)); + shiro.getSystemUser().execute(() -> { + final Asset asset = null; - final AttachmentList list = item.get().getAttachments().get(0); + final Optional item = itemRepo.findById(-510L); + assertThat(item.isPresent(), is(true)); - attachmentManager.unattachAsset(asset, list); + final AttachmentList list = item.get().getAttachments().get(0); + + attachmentManager.unattachAsset(asset, list); + }); } /** @@ -419,12 +447,15 @@ public class ItemAttachmentManagerTest { + "ItemAttachmentManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void unattachAssetFromListNull() { - final Asset asset = assetRepo.findById(-720L).get(); - assertThat(asset, is(not(nullValue()))); - final AttachmentList list = null; + shiro.getSystemUser().execute(() -> { + final Asset asset = assetRepo.findById(-720L).get(); + assertThat(asset, is(not(nullValue()))); - attachmentManager.unattachAsset(asset, list); + final AttachmentList list = null; + + attachmentManager.unattachAsset(asset, list); + }); } /** @@ -441,13 +472,16 @@ public class ItemAttachmentManagerTest { + "ItemAttachmentManagerTest/after-move-up.xml", excludeColumns = {"timestamp"}) public void moveUp() { - final Optional item = itemRepo.findById(-510L); - assertThat(item.isPresent(), is(true)); - final AttachmentList list = item.get().getAttachments().get(0); + shiro.getSystemUser().execute(() -> { + final Optional item = itemRepo.findById(-510L); + assertThat(item.isPresent(), is(true)); - attachmentManager.moveUp(list.getAttachments().get(0).getAsset(), - list); + final AttachmentList list = item.get().getAttachments().get(0); + + attachmentManager.moveUp(list.getAttachments().get(0).getAsset(), + list); + }); } /** @@ -462,13 +496,16 @@ public class ItemAttachmentManagerTest { @ShouldMatchDataSet("datasets/org/librecms/contentsection/" + "ItemAttachmentManagerTest/data.xml") public void moveUpLast() { - final Optional item = itemRepo.findById(-510L); - assertThat(item.isPresent(), is(true)); - final AttachmentList list = item.get().getAttachments().get(0); + shiro.getSystemUser().execute(() -> { + final Optional item = itemRepo.findById(-510L); + assertThat(item.isPresent(), is(true)); - attachmentManager.moveUp(list.getAttachments().get(2).getAsset(), - list); + final AttachmentList list = item.get().getAttachments().get(0); + + attachmentManager.moveUp(list.getAttachments().get(2).getAsset(), + list); + }); } /** @@ -485,12 +522,15 @@ public class ItemAttachmentManagerTest { + "ItemAttachmentManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void moveUpNull() { - final Optional item = itemRepo.findById(-510L); - assertThat(item.isPresent(), is(true)); - final AttachmentList list = item.get().getAttachments().get(0); + shiro.getSystemUser().execute(() -> { + final Optional item = itemRepo.findById(-510L); + assertThat(item.isPresent(), is(true)); - attachmentManager.moveUp(null, list); + final AttachmentList list = item.get().getAttachments().get(0); + + attachmentManager.moveUp(null, list); + }); } /** @@ -507,12 +547,15 @@ public class ItemAttachmentManagerTest { + "ItemAttachmentManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void moveUpInListNull() { - final Asset asset = assetRepo.findById(-720L).get(); - assertThat(asset, is(not(nullValue()))); - final AttachmentList list = null; + shiro.getSystemUser().execute(() -> { + final Asset asset = assetRepo.findById(-720L).get(); + assertThat(asset, is(not(nullValue()))); - attachmentManager.moveUp(asset, list); + final AttachmentList list = null; + + attachmentManager.moveUp(asset, list); + }); } /** @@ -529,13 +572,16 @@ public class ItemAttachmentManagerTest { + "ItemAttachmentManagerTest/after-move-down.xml", excludeColumns = {"timestamp"}) public void moveDown() { - final Optional item = itemRepo.findById(-510L); - assertThat(item.isPresent(), is(true)); - final AttachmentList list = item.get().getAttachments().get(0); + shiro.getSystemUser().execute(() -> { + final Optional item = itemRepo.findById(-510L); + assertThat(item.isPresent(), is(true)); - attachmentManager.moveDown(list.getAttachments().get(2).getAsset(), - list); + final AttachmentList list = item.get().getAttachments().get(0); + + attachmentManager.moveDown(list.getAttachments().get(2).getAsset(), + list); + }); } /** @@ -550,13 +596,16 @@ public class ItemAttachmentManagerTest { @ShouldMatchDataSet("datasets/org/librecms/contentsection/" + "ItemAttachmentManagerTest/data.xml") public void moveDownFirst() { - final Optional item = itemRepo.findById(-510L); - assertThat(item.isPresent(), is(true)); - final AttachmentList list = item.get().getAttachments().get(0); + shiro.getSystemUser().execute(() -> { + final Optional item = itemRepo.findById(-510L); + assertThat(item.isPresent(), is(true)); - attachmentManager.moveDown(list.getAttachments().get(0).getAsset(), - list); + final AttachmentList list = item.get().getAttachments().get(0); + + attachmentManager.moveDown(list.getAttachments().get(0).getAsset(), + list); + }); } /** @@ -573,12 +622,15 @@ public class ItemAttachmentManagerTest { + "ItemAttachmentManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void moveDownNull() { - final Optional item = itemRepo.findById(-510L); - assertThat(item.isPresent(), is(true)); - final AttachmentList list = item.get().getAttachments().get(0); + shiro.getSystemUser().execute(() -> { + final Optional item = itemRepo.findById(-510L); + assertThat(item.isPresent(), is(true)); - attachmentManager.moveDown(null, list); + final AttachmentList list = item.get().getAttachments().get(0); + + attachmentManager.moveDown(null, list); + }); } /** @@ -595,12 +647,15 @@ public class ItemAttachmentManagerTest { + "ItemAttachmentManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void moveDownInListNull() { - final Asset asset = assetRepo.findById(-720L).get(); - assertThat(asset, is(not(nullValue()))); - final AttachmentList list = null; + shiro.getSystemUser().execute(() -> { + final Asset asset = assetRepo.findById(-720L).get(); + assertThat(asset, is(not(nullValue()))); - attachmentManager.moveDown(asset, list); + final AttachmentList list = null; + + attachmentManager.moveDown(asset, list); + }); } } diff --git a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-create-contentitem-with-workflow.xml b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-create-contentitem-with-workflow.xml index af1b3ff48..8951ebd33 100644 --- a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-create-contentitem-with-workflow.xml +++ b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-create-contentitem-with-workflow.xml @@ -12,7 +12,7 @@ active="false" /> + active="true" /> + diff --git a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-create-contentitem.xml b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-create-contentitem.xml index f6f797b3d..f9511a7c9 100644 --- a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-create-contentitem.xml +++ b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-create-contentitem.xml @@ -12,7 +12,7 @@ active="false" /> + active="true" /> - + +