From 325c6fbc80991ac0f068fcb088995c00e46596fd Mon Sep 17 00:00:00 2001 From: jensp Date: Wed, 12 Oct 2016 13:03:02 +0000 Subject: [PATCH] CCM NG/ccm-cms: JavaDoc for the ContentItemManagerTest git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4372 8810af33-2d31-482b-a856-94f89814c4df --- .../ContentItemManagerTest.java | 722 +++++++++++------- 1 file changed, 463 insertions(+), 259 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 798b49cc4..400c4d9a4 100644 --- a/ccm-cms/src/test/java/org/librecms/contentsection/ContentItemManagerTest.java +++ b/ccm-cms/src/test/java/org/librecms/contentsection/ContentItemManagerTest.java @@ -79,9 +79,6 @@ public class ContentItemManagerTest { @Inject private ContentItemManager itemManager; - @Inject - private CategoryRepository categoryRepo; - @Inject private FolderRepository folderRepo; @@ -119,71 +116,82 @@ public class ContentItemManagerTest { @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()) - .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.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(com.arsdigita.cms.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.assets.Asset.class.getPackage()) - .addPackage(org.librecms.attachments.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()) + .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.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(com.arsdigita.cms.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.assets.Asset.class.getPackage()) + .addPackage(org.librecms.attachments.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"); } + /** + * Checks if the injection points work. + */ @Test @InSequence(10) public void checkInjections() { assertThat(sectionRepo, is(not(nullValue()))); + assertThat(itemRepo, is(not(nullValue()))); assertThat(itemManager, is(not(nullValue()))); + assertThat(folderRepo, is(not(nullValue()))); assertThat(shiro, is(not(nullValue()))); + assertThat(workflowTemplateRepo, is(not(nullValue()))); + assertThat(lifecycleDefinitionRepo, is(not(nullValue()))); + assertThat(entityManager, is(not(nullValue()))); } + /** + * Verify that Shiro is working. + */ @Test @InSequence(20) public void checkShiro() { @@ -191,26 +199,30 @@ public class ContentItemManagerTest { assertThat(shiro.getSystemUser(), is(not(nullValue()))); } + /** + * Tries to create a new content item using + * {@link ContentItemManager#createContentItem(java.lang.String, org.librecms.contentsection.ContentSection, org.librecms.contentsection.Folder, java.lang.Class)}. + */ @Test @InSequence(1100) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldMatchDataSet( - value = "datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/after-create-contentitem.xml", - excludeColumns = {"categorization_id", - "id", - "item_uuid", - "lifecycle_id", - "object_id", - "object_order", - "phase_id", - "rev", - "task_id", - "uuid", - "timestamp", - "workflow_id" - }) + value = "datasets/org/librecms/contentsection/" + + "ContentItemManagerTest/after-create-contentitem.xml", + excludeColumns = {"categorization_id", + "id", + "item_uuid", + "lifecycle_id", + "object_id", + "object_order", + "phase_id", + "rev", + "task_id", + "uuid", + "timestamp", + "workflow_id" + }) public void createContentItem() { final ContentSection section = sectionRepo.findByLabel("info"); final Folder folder = section.getRootDocumentsFolder(); @@ -230,23 +242,24 @@ public class ContentItemManagerTest { article.getWorkflow(), is(not(nullValue()))); final TypedQuery query = entityManager.createQuery( - "SELECT COUNT(w) FROM Workflow w", Long.class); + "SELECT COUNT(w) FROM Workflow w", Long.class); final long workflowCount = query.getSingleResult(); assertThat("Expected three workflows in database.", workflowCount, is(3L)); } /** - * Checks if an {@link IllegalArgumentException} is thrown when the content - * type of the item to create is not registered with the provided content - * section. + * Checks if an {@link IllegalArgumentException} is thrown if + * {@link ContentItemManager#createContentItem(java.lang.String, org.librecms.contentsection.ContentSection, org.librecms.contentsection.Folder, java.lang.Class)} + * is called for a content type which is not registered for the provided + * content section. */ @Test(expected = IllegalArgumentException.class) @InSequence(1200) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldMatchDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void createItemTypeNotInSection() { final ContentSection section = sectionRepo.findByLabel("info"); @@ -255,12 +268,17 @@ public class ContentItemManagerTest { itemManager.createContentItem("Test", section, folder, Event.class); } + /** + * Verifies that an {@link IllegalArgumentException} is thrown if + * {@link ContentItemManager#createContentItem(java.lang.String, org.librecms.contentsection.ContentSection, org.librecms.contentsection.Folder, java.lang.Class)} + * is called with {@code null} for the name of the new item. + */ @Test(expected = IllegalArgumentException.class) @InSequence(1300) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldMatchDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void createItemNameIsNull() { final ContentSection section = sectionRepo.findByLabel("info"); @@ -269,26 +287,37 @@ public class ContentItemManagerTest { itemManager.createContentItem(null, section, folder, Article.class); } + /** + * Verifies that an {@link IllegalArgumentException} is thrown if + * {@link ContentItemManager#createContentItem(java.lang.String, org.librecms.contentsection.ContentSection, org.librecms.contentsection.Folder, java.lang.Class)} + * is called with an empty string for the name of the new content item. + */ @Test(expected = IllegalArgumentException.class) @InSequence(1400) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldMatchDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void createItemNameIsEmpty() { final ContentSection section = sectionRepo.findByLabel("info"); final Folder folder = section.getRootDocumentsFolder(); - itemManager.createContentItem("", section, folder, Article.class); + itemManager.createContentItem(" ", section, folder, Article.class); } + /** + * Verifies that an {@link IllegalArgumentException} is thrown if + * {@link ContentItemManager#createContentItem(java.lang.String, org.librecms.contentsection.ContentSection, org.librecms.contentsection.Folder, java.lang.Class)} + * is called with {@code null} for the folder in which the new item is + * created. + */ @Test(expected = IllegalArgumentException.class) @InSequence(1500) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldMatchDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void createItemFolderIsNull() { final ContentSection section = sectionRepo.findByLabel("info"); @@ -296,40 +325,44 @@ public class ContentItemManagerTest { itemManager.createContentItem("Test", section, null, Article.class); } + /** + * Tries to create a new content item with an alternative workflow using + * {@link ContentItemManager#createContentItem(java.lang.String, org.librecms.contentsection.ContentSection, org.librecms.contentsection.Folder, org.libreccm.workflow.WorkflowTemplate, java.lang.Class)}. + */ @Test @InSequence(2100) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldMatchDataSet( - value = "datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/" - + "after-create-contentitem-with-workflow.xml", - excludeColumns = {"categorization_id", - "id", - "item_uuid", - "lifecycle_id", - "object_id", - "object_order", - "phase_id", - "rev", - "task_id", - "timestamp", - "uuid", - "workflow_id" - }) + value = "datasets/org/librecms/contentsection/" + + "ContentItemManagerTest/" + + "after-create-contentitem-with-workflow.xml", + excludeColumns = {"categorization_id", + "id", + "item_uuid", + "lifecycle_id", + "object_id", + "object_order", + "phase_id", + "rev", + "task_id", + "timestamp", + "uuid", + "workflow_id" + }) public void createContentItemWithWorkflow() { final ContentSection section = sectionRepo.findByLabel("info"); final Folder folder = section.getRootDocumentsFolder(); final WorkflowTemplate workflowTemplate = workflowTemplateRepo - .findById(-110L); + .findById(-110L); final Article article = itemManager.createContentItem( - "new-article", - section, - folder, - workflowTemplate, - Article.class); + "new-article", + section, + folder, + workflowTemplate, + Article.class); assertThat("DisplayName has not the expected value.", article.getDisplayName(), is(equalTo("new-article"))); @@ -341,30 +374,31 @@ public class ContentItemManagerTest { article.getWorkflow(), is(not(nullValue()))); final TypedQuery query = entityManager.createQuery( - "SELECT COUNT(w) FROM Workflow w", Long.class); + "SELECT COUNT(w) FROM Workflow w", Long.class); final long workflowCount = query.getSingleResult(); assertThat("Expected three workflows in database.", workflowCount, is(3L)); } /** - * Checks if an {@link IllegalArgumentException} is thrown when the content - * type of the item to create is not registered with the provided content - * section. + * Verifies that + * {@link ContentItemManager#createContentItem(java.lang.String, org.librecms.contentsection.ContentSection, org.librecms.contentsection.Folder, org.libreccm.workflow.WorkflowTemplate, java.lang.Class)} + * throws an {@link IllegalArgumentException} if the provided type of the + * item to create is not registered with the provided content section. */ @Test(expected = IllegalArgumentException.class) @InSequence(2200) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldMatchDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void createItemTypeNotInSectionWithWorkflow() { final ContentSection section = sectionRepo.findByLabel("info"); final Folder folder = section.getRootDocumentsFolder(); final WorkflowTemplate workflowTemplate = workflowTemplateRepo - .findById(-110L); + .findById(-110L); itemManager.createContentItem("Test", section, @@ -373,19 +407,25 @@ public class ContentItemManagerTest { Event.class); } + /** + * Verifies that + * {@link ContentItemManager#createContentItem(java.lang.String, org.librecms.contentsection.ContentSection, org.librecms.contentsection.Folder, org.libreccm.workflow.WorkflowTemplate, java.lang.Class)} + * throws an {@link IllegalArgumentException} if called with {@code null} + * for the name of the new item. + */ @Test(expected = IllegalArgumentException.class) @InSequence(2300) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldMatchDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void createItemNameIsNullWithWorkflow() { final ContentSection section = sectionRepo.findByLabel("info"); final Folder folder = section.getRootDocumentsFolder(); final WorkflowTemplate workflowTemplate = workflowTemplateRepo - .findById(-110L); + .findById(-110L); itemManager.createContentItem(null, section, @@ -394,12 +434,18 @@ public class ContentItemManagerTest { Article.class); } + /** + * Verifies that + * {@link ContentItemManager#createContentItem(java.lang.String, org.librecms.contentsection.ContentSection, org.librecms.contentsection.Folder, org.libreccm.workflow.WorkflowTemplate, java.lang.Class)} + * throws an {@link IllegalArgumentException} if called with {@code null} + * for the name of the new item and for thw workflow of the new item. + */ @Test(expected = IllegalArgumentException.class) @InSequence(2400) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldMatchDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void createItemNameIsNullWorkflowIsNull() { final ContentSection section = sectionRepo.findByLabel("info"); @@ -412,18 +458,24 @@ public class ContentItemManagerTest { Article.class); } + /** + * Verifies that + * {@link ContentItemManager#createContentItem(java.lang.String, org.librecms.contentsection.ContentSection, org.librecms.contentsection.Folder, org.libreccm.workflow.WorkflowTemplate, java.lang.Class)} + * throws an {@link IllegalArgumentException} if called with {@code null} + * for the folder in which the new item is created. + */ @Test(expected = IllegalArgumentException.class) @InSequence(2600) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldMatchDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void createItemFolderIsNullWithWorkflow() { final ContentSection section = sectionRepo.findByLabel("info"); final WorkflowTemplate workflowTemplate = workflowTemplateRepo - .findById(-110L); + .findById(-110L); itemManager.createContentItem("Test", section, @@ -432,22 +484,26 @@ public class ContentItemManagerTest { Article.class); } + /** + * Tries to move an item a folder in the same content section using + * {@link ContentItemManager#move(org.librecms.contentsection.ContentItem, org.librecms.contentsection.Folder)}. + */ @Test @InSequence(3100) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldMatchDataSet( - value = "datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/after-move.xml", - excludeColumns = {"categorization_id", - "lifecycle_id", - "object_id", - "object_order", - "phase_id", - "task_id", - "uuid", - "workflow_id" - }) + value = "datasets/org/librecms/contentsection/" + + "ContentItemManagerTest/after-move.xml", + excludeColumns = {"categorization_id", + "lifecycle_id", + "object_id", + "object_order", + "phase_id", + "task_id", + "uuid", + "workflow_id" + }) public void moveItem() { final Optional item = itemRepo.findById(-10100L); assertThat(item.isPresent(), is(true)); @@ -458,12 +514,42 @@ public class ContentItemManagerTest { itemManager.move(item.get(), targetFolder); } + /** + * Tries to move an item a folder in another content section using + * {@link ContentItemManager#move(org.librecms.contentsection.ContentItem, org.librecms.contentsection.Folder)}. + */ + @Test + @InSequence(3110) + @UsingDataSet("datasets/org/librecms/contentsection/" + + "ContentItemManagerTest/data.xml") + @ShouldMatchDataSet( + value = "datasets/org/librecms/contentsection/" + + "ContentItemManagerTest/after-move-to-other-section.xml", + excludeColumns = {"categorization_id", + "lifecycle_id", + "object_id", + "object_order", + "phase_id", + "task_id", + "uuid", + "workflow_id" + }) + public void moveToOtherContentSection() { + fail("Not implemented yet"); + } + + /** + * Verifies that + * {@link ContentItemManager#move(org.librecms.contentsection.ContentItem, org.librecms.contentsection.Folder)} + * throws an {@link IllegalArgumentException} if called with {@code null} + * for the item to move. + */ @Test(expected = IllegalArgumentException.class) @InSequence(3200) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldMatchDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void moveItemNull() { final Folder targetFolder = folderRepo.findById(-2120L); @@ -472,12 +558,18 @@ public class ContentItemManagerTest { itemManager.move(null, targetFolder); } + /** + * Verifies that + * {@link ContentItemManager#move(org.librecms.contentsection.ContentItem, org.librecms.contentsection.Folder)} + * throws an {@link IllegalArgumentException} if called with {@code null} + * for target folder. + */ @Test(expected = IllegalArgumentException.class) @InSequence(3200) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldMatchDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void moveItemFolderNull() { final Optional item = itemRepo.findById(-10100L); @@ -486,26 +578,30 @@ public class ContentItemManagerTest { itemManager.move(item.get(), null); } + /** + * Tries to copy an item to another folder in the same content section using + * {@link ContentItemManager#copy(org.librecms.contentsection.ContentItem, org.librecms.contentsection.Folder)}. + */ @Test @InSequence(4100) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldMatchDataSet( - value = "datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/after-copy-to-other-folder.xml", - excludeColumns = {"categorization_id", - "id", - "item_uuid", - "lifecycle_id", - "object_id", - "object_order", - "phase_id", - "rev", - "task_id", - "uuid", - "timestamp", - "workflow_id" - }) + value = "datasets/org/librecms/contentsection/" + + "ContentItemManagerTest/after-copy-to-other-folder.xml", + excludeColumns = {"categorization_id", + "id", + "item_uuid", + "lifecycle_id", + "object_id", + "object_order", + "phase_id", + "rev", + "task_id", + "uuid", + "timestamp", + "workflow_id" + }) public void copyToOtherFolder() { final Optional item = itemRepo.findById(-10100L); assertThat(item.isPresent(), is(true)); @@ -516,26 +612,60 @@ public class ContentItemManagerTest { itemManager.copy(item.get(), targetFolder); } + /** + * Tries to copy an item to another folder in another content section using + * {@link ContentItemManager#copy(org.librecms.contentsection.ContentItem, org.librecms.contentsection.Folder)}. + */ + @Test + @InSequence(4110) + @UsingDataSet("datasets/org/librecms/contentsection/" + + "ContentItemManagerTest/data.xml") + @ShouldMatchDataSet( + value = "datasets/org/librecms/contentsection/" + + "ContentItemManagerTest/after-copy-to-folder-in-other-section.xml", + excludeColumns = {"categorization_id", + "id", + "item_uuid", + "lifecycle_id", + "object_id", + "object_order", + "phase_id", + "rev", + "task_id", + "uuid", + "timestamp", + "workflow_id" + }) + public void copyToFolderInOtherSection() { + fail(); + } + + /** + * Tries to create a copy of an item it its folder by using + * {@link ContentItemManager#copy(org.librecms.contentsection.ContentItem, org.librecms.contentsection.Folder)}. + * The method should append a number as suffix to the name of the item to + * make the name unique inside the folder. + */ @Test @InSequence(4200) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldMatchDataSet( - value = "datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/after-copy-to-same-folder.xml", - excludeColumns = {"categorization_id", - "id", - "item_uuid", - "lifecycle_id", - "object_id", - "object_order", - "phase_id", - "rev", - "task_id", - "timestamp", - "uuid", - "workflow_id" - }) + value = "datasets/org/librecms/contentsection/" + + "ContentItemManagerTest/after-copy-to-same-folder.xml", + excludeColumns = {"categorization_id", + "id", + "item_uuid", + "lifecycle_id", + "object_id", + "object_order", + "phase_id", + "rev", + "task_id", + "timestamp", + "uuid", + "workflow_id" + }) public void copyToSameFolder() { final Optional item = itemRepo.findById(-10100L); assertThat(item.isPresent(), is(true)); @@ -546,13 +676,19 @@ public class ContentItemManagerTest { itemManager.copy(item.get(), targetFolder); } + /** + * Verifies that + * {@link ContentItemManager#move(org.librecms.contentsection.ContentItem, org.librecms.contentsection.Folder)} + * throws an {@link IllegalArgumentException} if called with {@code null} + * for the item to copy. + */ @Test(expected = IllegalArgumentException.class) @InSequence(4300) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldMatchDataSet( - value = "datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + value = "datasets/org/librecms/contentsection/" + + "ContentItemManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void copyItemNull() { final Folder targetFolder = folderRepo.findById(-2120L); @@ -561,13 +697,19 @@ public class ContentItemManagerTest { itemManager.copy(null, targetFolder); } + /** + * Verifies that + * {@link ContentItemManager#move(org.librecms.contentsection.ContentItem, org.librecms.contentsection.Folder)} + * throws an {@link IllegalArgumentException} if called with {@code null} + * for the target folder. + */ @Test(expected = IllegalArgumentException.class) @InSequence(4400) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldMatchDataSet( - value = "datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + value = "datasets/org/librecms/contentsection/" + + "ContentItemManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void copyItemToFolderNull() { final Optional item = itemRepo.findById(-10100L); @@ -576,25 +718,32 @@ public class ContentItemManagerTest { itemManager.copy(item.get(), null); } + /** + * Tries to publish an item using + * {@link ContentItemManager#publish(org.librecms.contentsection.ContentItem)}. + * This test only verifies to basic functionality of the {@code publish} + * method. For complex content items it is recommended to create additional + * tests to verify that the item is published correctly. + */ @Test @InSequence(5100) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldMatchDataSet( - value = "datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/after-publish.xml", - excludeColumns = {"categorization_id", - "id", - "lifecycle_id", - "object_id", - "object_order", - "phase_id", - "rev", - "task_id", - "timestamp", - "uuid", - "workflow_id" - }) + value = "datasets/org/librecms/contentsection/" + + "ContentItemManagerTest/after-publish.xml", + excludeColumns = {"categorization_id", + "id", + "lifecycle_id", + "object_id", + "object_order", + "phase_id", + "rev", + "task_id", + "timestamp", + "uuid", + "workflow_id" + }) public void publishItem() { final Optional item = itemRepo.findById(-10100L); assertThat(item.isPresent(), is(true)); @@ -604,29 +753,36 @@ public class ContentItemManagerTest { assertThat(live.getVersion(), is(ContentItemVersion.LIVE)); } + /** + * Tries to publish an item with an alternative lifecycle using + * {@link ContentItemManager#publish(org.librecms.contentsection.ContentItem, org.librecms.lifecycle.LifecycleDefinition)}. + * This test only verifies to basic functionality of the {@code publish} + * method. For complex content items it is recommended to create additional + * tests to verify that the item is published correctly. + */ @Test @InSequence(5200) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldMatchDataSet( - value = "datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/after-publish.xml", - excludeColumns = {"categorization_id", - "id", - "lifecycle_id", - "object_id", - "object_order", - "phase_id", - "rev", - "task_id", - "timestamp", - "uuid", - "workflow_id" - }) + value = "datasets/org/librecms/contentsection/" + + "ContentItemManagerTest/after-publish.xml", + excludeColumns = {"categorization_id", + "id", + "lifecycle_id", + "object_id", + "object_order", + "phase_id", + "rev", + "task_id", + "timestamp", + "uuid", + "workflow_id" + }) public void publishItemWithLifecycle() { final Optional item = itemRepo.findById(-10100L); final LifecycleDefinition lifecycleDef = lifecycleDefinitionRepo - .findById(-200L); + .findById(-200L); assertThat(item.isPresent(), is(true)); assertThat(lifecycleDef, is(not(nullValue()))); @@ -635,32 +791,36 @@ public class ContentItemManagerTest { assertThat(live.getVersion(), is(ContentItemVersion.LIVE)); } + /** + * Tries to republish an item using + * {@link ContentItemManager#publish(org.librecms.contentsection.ContentItem)}. + */ @Test @InSequence(5300) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldMatchDataSet( - value = "datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/after-republish.xml", - excludeColumns = {"categorization_id", - "id", - "lifecycle_id", - "object_id", - "object_order", - "phase_id", - "rev", - "revend", - "task_id", - "timestamp", - "uuid", - "workflow_id"}) + value = "datasets/org/librecms/contentsection/" + + "ContentItemManagerTest/after-republish.xml", + excludeColumns = {"categorization_id", + "id", + "lifecycle_id", + "object_id", + "object_order", + "phase_id", + "rev", + "revend", + "task_id", + "timestamp", + "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"); + .addValue(Locale.ENGLISH, "Article has been edited"); itemRepo.save(item.get()); final Optional draft = itemRepo.findById(-10200L); @@ -669,25 +829,37 @@ public class ContentItemManagerTest { itemManager.publish(draft.get()); } + /** + * Verifies that + * {@link ContentItemManager#publish(org.librecms.contentsection.ContentItem)} + * throws an {@link IllegalArgumentException} if called with {@code null} + * for the item to publish. + */ @Test(expected = IllegalArgumentException.class) @InSequence(5400) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldMatchDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void publishItemNull() { final ContentItem item = null; - + itemManager.publish(item); } + /** + * Verifies that + * {@link ContentItemManager#publish(org.librecms.contentsection.ContentItem, org.librecms.lifecycle.LifecycleDefinition)} + * throws an {@link IllegalArgumentException} if called with {@code null} + * for the lifecycle to use. + */ @Test(expected = IllegalArgumentException.class) @InSequence(5500) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldMatchDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void publishItemLifecycleNull() { final Optional draft = itemRepo.findById(-10200L); @@ -695,25 +867,29 @@ public class ContentItemManagerTest { itemManager.publish(draft.get(), null); } + /** + * Tries to unpublish (delete the live version) an item using + * {@link ContentItemManager#unpublish(org.librecms.contentsection.ContentItem)}. + */ @Test @InSequence(6000) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldMatchDataSet( - value = "datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/after-unpublish.xml", - excludeColumns = {"categorization_id", - "id", - "lifecycle_id", - "object_id", - "object_order", - "phase_id", - "rev", - "revend", - "task_id", - "timestamp", - "uuid", - "workflow_id"}) + value = "datasets/org/librecms/contentsection/" + + "ContentItemManagerTest/after-unpublish.xml", + excludeColumns = {"categorization_id", + "id", + "lifecycle_id", + "object_id", + "object_order", + "phase_id", + "rev", + "revend", + "task_id", + "timestamp", + "uuid", + "workflow_id"}) public void unpublishItem() { final Optional item = itemRepo.findById(-10200L); assertThat(item.isPresent(), is(true)); @@ -721,12 +897,17 @@ public class ContentItemManagerTest { itemManager.unpublish(item.get()); } + /** + * Verifies that + * {@link ContentItemManager#unpublish(org.librecms.contentsection.ContentItem)} + * does nothing if called for an item which is not live. + */ @Test @InSequence(6100) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldMatchDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") public void unpublishNonLiveItem() { final Optional item = itemRepo.findById(-10300L); assertThat(item.isPresent(), is(true)); @@ -734,24 +915,35 @@ public class ContentItemManagerTest { itemManager.unpublish(item.get()); } + /** + * Verifies that + * {@link ContentItemManager#unpublish(org.librecms.contentsection.ContentItem)} + * throws an {@link IllegalArgumentException} if called with {@code null} + * for the item to unpublish. + */ @Test(expected = IllegalArgumentException.class) @InSequence(6200) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldMatchDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldThrowException(IllegalArgumentException.class) public void unpublishItemNull() { final ContentItem item = null; itemManager.unpublish(item); } + /** + * Verifies that + * {@link ContentItemManager#isLive(org.librecms.contentsection.ContentItem)} + * returns the expected value for the items in the test database. + */ @Test @InSequence(7000) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldMatchDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") public void isLive() { final Optional item1 = itemRepo.findById(-10100L); final Optional item2 = itemRepo.findById(-10200L); @@ -769,12 +961,19 @@ public class ContentItemManagerTest { assertThat(itemManager.isLive(item4.get()), is(false)); } + /** + * Tries to retrieve the live versions of the items in the test database + * using + * {@link ContentItemManager#getLiveVersion(org.librecms.contentsection.ContentItem, java.lang.Class)}. + * The method returns an {@link Optional} which is empty if there is not + * live version. + */ @Test @InSequence(8000) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldMatchDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") public void getLiveVersion() { final Optional draft1 = itemRepo.findById(-10100L); final Optional draft2 = itemRepo.findById(-10200L); @@ -787,7 +986,7 @@ public class ContentItemManagerTest { ContentItem.class).isPresent(), is(false)); final Optional
liveVersion = itemManager.getLiveVersion( - draft2.get(), Article.class); + draft2.get(), Article.class); assertThat(liveVersion.isPresent(), is(true)); assertThat(liveVersion.get().getObjectId(), @@ -804,7 +1003,7 @@ public class ContentItemManagerTest { is(false)); final Optional fromLive = itemManager.getLiveVersion( - live2.get(), ContentItem.class); + live2.get(), ContentItem.class); assertThat(fromLive.isPresent(), is(true)); assertThat(fromLive.get().getObjectId(), @@ -815,12 +1014,17 @@ public class ContentItemManagerTest { is(ContentItemVersion.LIVE)); } + /** + * Tries to retrieve the draft version of the items in the test database + * from draft or live versions of the items in the test database using + * {@link ContentItemManager#getDraftVersion(org.librecms.contentsection.ContentItem, java.lang.Class)}. + */ @Test @InSequence(8100) @UsingDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") @ShouldMatchDataSet("datasets/org/librecms/contentsection/" - + "ContentItemManagerTest/data.xml") + + "ContentItemManagerTest/data.xml") // getDraftVersion public void getDraftVersion() { final Optional draft1 = itemRepo.findById(-10100L); @@ -844,7 +1048,7 @@ public class ContentItemManagerTest { final Optional live2 = itemRepo.findById(-99200L); final ContentItem draftVersion = itemManager.getDraftVersion( - live2.get(), ContentItem.class); + live2.get(), ContentItem.class); assertThat(draftVersion, is(not(nullValue()))); assertThat(draftVersion.getObjectId(), is(-10200L));