diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/AttachmentList.java b/ccm-cms/src/main/java/org/librecms/contentsection/AttachmentList.java index ec2d5cbf4..372a0227d 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/AttachmentList.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/AttachmentList.java @@ -19,15 +19,17 @@ package org.librecms.contentsection; import org.hibernate.envers.Audited; +import org.libreccm.core.CcmObject; import org.libreccm.core.Identifiable; import org.libreccm.l10n.LocalizedString; -import org.librecms.contentsection.ContentItem; +import org.libreccm.security.InheritsPermissions; import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Objects; +import java.util.Optional; import javax.persistence.AssociationOverride; import javax.persistence.Column; @@ -67,6 +69,7 @@ import static org.librecms.CmsConstants.*; }) public class AttachmentList implements Comparable, Identifiable, + InheritsPermissions, Serializable { private static final long serialVersionUID = -7931234562247075541L; @@ -161,6 +164,15 @@ public class AttachmentList implements Comparable, this.item = item; } + @Override + public Optional getParent() { + if (item == null) { + return Optional.empty(); + } else { + return Optional.of(item); + } + } + public String getName() { return name; } diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/ItemAttachment.java b/ccm-cms/src/main/java/org/librecms/contentsection/ItemAttachment.java index dab03e730..4d025da04 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/ItemAttachment.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/ItemAttachment.java @@ -31,6 +31,8 @@ import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; import javax.persistence.Table; import static org.librecms.CmsConstants.*; @@ -45,6 +47,13 @@ import static org.librecms.CmsConstants.*; @Entity @Table(schema = DB_SCHEMA, name = "ATTACHMENTS") @Audited +@NamedQueries({ + @NamedQuery( + name = "ItemAttachment.countByAssetIdAndList", + query = "SELECT COUNT(i) FROM ItemAttachment i " + + "WHERE i.asset = :asset " + + "AND i.attachmentList = :attachmentList") +}) public class ItemAttachment implements Comparable>, Identifiable, @@ -133,10 +142,10 @@ public class ItemAttachment if (other == null) { throw new NullPointerException(); } - + return Long.compare(sortKey, other.getSortKey()); } - + @Override public int hashCode() { int hash = 3; diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/ItemAttachmentManager.java b/ccm-cms/src/main/java/org/librecms/contentsection/ItemAttachmentManager.java index 20a65986a..bcd2a4325 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/ItemAttachmentManager.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/ItemAttachmentManager.java @@ -18,8 +18,17 @@ */ package org.librecms.contentsection; +import org.libreccm.security.AuthorizationRequired; +import org.libreccm.security.RequiresPrivilege; +import org.librecms.contentsection.privileges.ItemPrivileges; + +import java.util.UUID; import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.persistence.EntityManager; +import javax.persistence.TypedQuery; +import javax.transaction.Transactional; /** * Provides methods for managing the {@link Asset} of an {@link AttachmentList}. @@ -29,15 +38,67 @@ import javax.enterprise.context.RequestScoped; @RequestScoped public class ItemAttachmentManager { + @Inject + private EntityManager entityManager; + + @Inject + private AssetRepository assetRepo; + /** * Adds the provided {@link Asset} to the provided {@link AttachmentList}. * * @param asset The {@link Asset} to add. * @param attachmentList The attachment list to which the asset is added. */ - public void attachAsset(final Asset asset, - final AttachmentList attachmentList) { - throw new UnsupportedOperationException("Not implemented yet"); + @Transactional(Transactional.TxType.REQUIRED) + @AuthorizationRequired + public void attachAsset( + final Asset asset, + @RequiresPrivilege(ItemPrivileges.EDIT) + final AttachmentList attachmentList) { + + if (asset == null) { + throw new IllegalArgumentException("Can't attach asset null."); + } + + if (attachmentList == null) { + throw new IllegalArgumentException( + "Can't attach an asset to attachment list null."); + } + + // For shared assets (we assume that every asset already in the database + // is a shared one here) check of the asset is already attached. + if (asset.getObjectId() == 0) { + saveNonSharedAsset(asset); + } else { + final TypedQuery countQuery = entityManager.createNamedQuery( + "ItemAttachment.countByAssetIdAndList", Long.class); + countQuery.setParameter("asset", asset); + countQuery.setParameter("attachmentList", attachmentList); + + final long count = countQuery.getSingleResult(); + if (count > 0) { + //Asset is already attached. + return; + } + } + + final ItemAttachment itemAttachment = new ItemAttachment<>(); + itemAttachment.setUuid(UUID.randomUUID().toString()); + itemAttachment.setAttachmentList(attachmentList); + itemAttachment.setAsset(asset); + itemAttachment.setSortKey(attachmentList.getAttachments().size()); + asset.addItemAttachment(itemAttachment); + attachmentList.addAttachment(itemAttachment); + + assetRepo.save(asset); + entityManager.merge(attachmentList); + entityManager.persist(itemAttachment); + } + + @Transactional(Transactional.TxType.REQUIRES_NEW) + private void saveNonSharedAsset(final Asset asset) { + assetRepo.save(asset); } /** @@ -82,24 +143,4 @@ public class ItemAttachmentManager { throw new UnsupportedOperationException("Not implemented yet"); } - /** - * Moves the {@link Asset} to the specified position in the provided - * {@link AttachmentList}. - * - * @param asset The asset to move. If the asset is not part of the - * provided {@link AttachmentList} an - * {@link IllegalArgumentException} is thrown. - * @param attachmentList The attachment list in which the item is moved. - * @param position The position to which the asset is moved. The asset - * occupying the provided index is moved down. If the - * provided position is larger than the size of the - * attachment list the item is moved to the end of the - * list. - */ - public void moveTo(final Asset asset, - final AttachmentList attachmentList, - final long position) { - throw new UnsupportedOperationException("Not implemented yet"); - } - } diff --git a/ccm-cms/src/test/java/org/librecms/contentsection/AttachmentListManagerTest.java b/ccm-cms/src/test/java/org/librecms/contentsection/AttachmentListManagerTest.java index 9593497ca..88ce30ffc 100644 --- a/ccm-cms/src/test/java/org/librecms/contentsection/AttachmentListManagerTest.java +++ b/ccm-cms/src/test/java/org/librecms/contentsection/AttachmentListManagerTest.java @@ -18,8 +18,6 @@ */ package org.librecms.contentsection; -import org.librecms.contentsection.AttachmentList; -import org.librecms.contentsection.AttachmentListManager; import static org.libreccm.testutils.DependenciesHelpers.*; @@ -45,9 +43,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.libreccm.security.Shiro; import org.libreccm.tests.categories.IntegrationTest; -import org.librecms.contentsection.Asset; -import org.librecms.contentsection.ContentItem; -import org.librecms.contentsection.ContentItemRepository; import java.util.List; import java.util.Optional; diff --git a/ccm-cms/src/test/java/org/librecms/contentsection/DatasetsTest.java b/ccm-cms/src/test/java/org/librecms/contentsection/DatasetsTest.java index 0320d0cea..da030eb47 100644 --- a/ccm-cms/src/test/java/org/librecms/contentsection/DatasetsTest.java +++ b/ccm-cms/src/test/java/org/librecms/contentsection/DatasetsTest.java @@ -45,7 +45,7 @@ public class DatasetsTest extends DatasetsVerifier { return Arrays.asList(new String[]{ "/datasets/org/librecms/contentsection/AssetRepositoryTest/data.xml", "/datasets/org/librecms/contentsection/AssetRepositoryTest/after-delete.xml", - + "/datasets/org/librecms/contentsection/AssetManagerTest/data.xml", "/datasets/org/librecms/contentsection/AssetManagerTest/after-clean-orphaned.xml", "/datasets/org/librecms/contentsection/AssetManagerTest/after-copy-to-other-contentsection.xml", @@ -54,19 +54,16 @@ public class DatasetsTest extends DatasetsVerifier { "/datasets/org/librecms/contentsection/AssetManagerTest/after-share.xml", "/datasets/org/librecms/contentsection/AssetManagerTest/after-move-to-other-contentsection.xml", "/datasets/org/librecms/contentsection/AssetManagerTest/after-move-to-other-folder.xml", - + "/datasets/org/librecms/contentsection/AttachmentListManagerTest/data.xml", "/datasets/org/librecms/contentsection/AttachmentListManagerTest/after-create-after-last.xml", "/datasets/org/librecms/contentsection/AttachmentListManagerTest/after-create-with-negative-position.xml", "/datasets/org/librecms/contentsection/AttachmentListManagerTest/after-create-with-position.xml", "/datasets/org/librecms/contentsection/AttachmentListManagerTest/after-create.xml", "/datasets/org/librecms/contentsection/AttachmentListManagerTest/after-move-down.xml", - "/datasets/org/librecms/contentsection/AttachmentListManagerTest/after-move-to-first.xml", - "/datasets/org/librecms/contentsection/AttachmentListManagerTest/after-move-to-last.xml", - "/datasets/org/librecms/contentsection/AttachmentListManagerTest/after-move-to.xml", "/datasets/org/librecms/contentsection/AttachmentListManagerTest/after-move-up.xml", "/datasets/org/librecms/contentsection/AttachmentListManagerTest/after-remove.xml", - + "/datasets/org/librecms/contentsection/ContentSectionManagerTest/data.xml", "/datasets/org/librecms/contentsection/ContentSectionManagerTest/after-add-contenttype.xml", "/datasets/org/librecms/contentsection/ContentSectionManagerTest/after-remove-contenttype.xml", @@ -82,7 +79,7 @@ public class DatasetsTest extends DatasetsVerifier { "/datasets/org/librecms/contentsection/ContentItemL10NManagerTest/after-add-language.xml", "/datasets/org/librecms/contentsection/ContentItemL10NManagerTest/after-normalize.xml", "/datasets/org/librecms/contentsection/ContentItemL10NManagerTest/after-remove-language.xml", - + "/datasets/org/librecms/contentsection/ContentItemManagerTest/data.xml", "/datasets/org/librecms/contentsection/ContentItemManagerTest/after-create-contentitem.xml", "/datasets/org/librecms/contentsection/ContentItemManagerTest/after-create-contentitem-with-workflow.xml", @@ -103,7 +100,11 @@ public class DatasetsTest extends DatasetsVerifier { "/datasets/org/librecms/contentsection/FolderManagerTest/after-create-assets-folder.xml", "/datasets/org/librecms/contentsection/FolderManagerTest/after-delete-folder.xml", "/datasets/org/librecms/contentsection/FolderManagerTest/after-move-folder.xml", - "/datasets/org/librecms/contentsection/FolderManagerTest/after-move-folder-same-name.xml",}); + "/datasets/org/librecms/contentsection/FolderManagerTest/after-move-folder-same-name.xml", + + "/datasets/org/librecms/contentsection/ItemAttachmentManagerTest/data.xml", + "/datasets/org/librecms/contentsection/ItemAttachmentManagerTest/after-attach-shared.xml", + "/datasets/org/librecms/contentsection/ItemAttachmentManagerTest/after-attach-nonshared.xml",}); } public DatasetsTest(final String datasetPath) { diff --git a/ccm-cms/src/test/java/org/librecms/contentsection/ItemAttachmentManagerTest.java b/ccm-cms/src/test/java/org/librecms/contentsection/ItemAttachmentManagerTest.java new file mode 100644 index 000000000..04e3bc5ee --- /dev/null +++ b/ccm-cms/src/test/java/org/librecms/contentsection/ItemAttachmentManagerTest.java @@ -0,0 +1,466 @@ +/* + * Copyright (C) 2016 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.librecms.contentsection; + +import static org.libreccm.testutils.DependenciesHelpers.*; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.ShouldThrowException; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.junit.InSequence; +import org.jboss.arquillian.persistence.CreateSchema; +import org.jboss.arquillian.persistence.PersistenceTest; +import org.jboss.arquillian.persistence.ShouldMatchDataSet; +import org.jboss.arquillian.persistence.UsingDataSet; +import org.jboss.arquillian.transaction.api.annotation.TransactionMode; +import org.jboss.arquillian.transaction.api.annotation.Transactional; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.libreccm.security.Shiro; +import org.libreccm.tests.categories.IntegrationTest; +import org.librecms.assets.File; + +import java.util.Optional; + +import javax.activation.MimeType; +import javax.activation.MimeTypeParseException; +import javax.inject.Inject; +import javax.persistence.EntityManager; + +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.*; + +/** + * Tests for the {@link ItemAttachmentManager}. + * + * @author Jens Pelzetter + */ +@org.junit.experimental.categories.Category(IntegrationTest.class) +@RunWith(Arquillian.class) +@PersistenceTest +@Transactional(TransactionMode.COMMIT) +@CreateSchema({"create_ccm_cms_schema.sql"}) +public class ItemAttachmentManagerTest { + + @Inject + private ContentItemRepository itemRepo; + + @Inject + private AssetRepository assetRepo; + + @Inject + private AttachmentListManager listManager; + + @Inject + private ItemAttachmentManager attachmentManager; + + @Inject + private Shiro shiro; + + @Inject + private EntityManager entityManager; + + public ItemAttachmentManagerTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + @Deployment + public static WebArchive createDeployment() { + return ShrinkWrap + .create(WebArchive.class, + "LibreCCM-org.librecms.assets.AssetManagerTest.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.BinaryAsset.class.getPackage()) + .addPackage(org.librecms.contentsection.Asset.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"); + } + + /** + * Verify that all dependencies have injected. + */ + @Test + @InSequence(1) + public void checkInjections() { + assertThat(itemRepo, (is(not(nullValue())))); + assertThat(assetRepo, is(not(nullValue()))); + assertThat(listManager, is(not(nullValue()))); + assertThat(attachmentManager, is(not(nullValue()))); + assertThat(shiro, is(not(nullValue()))); + } + + /** + * Verify that Shiro is working. + */ + @Test + @InSequence(20) + public void checkShiro() { + assertThat(shiro.getSecurityManager(), is(not(nullValue()))); + assertThat(shiro.getSystemUser(), is(not(nullValue()))); + } + + /** + * Tries to attach some {@link Asset}s to some {@link AttachmentList}s using + * {@link ItemAttachmentManager#attachAsset(org.librecms.contentsection.Asset, org.librecms.contentsection.AttachmentList)}. + * + * @throws javax.activation.MimeTypeParseException + */ + @Test + @InSequence(100) + @UsingDataSet("datasets/org/librecms/contentsection/" + + "ItemAttachmentManagerTest/data.xml") + @ShouldMatchDataSet( + value = "datasets/org/librecms/contentsection/" + + "ItemAttachmentManagerTest/after-attach-nonshared.xml", + excludeColumns = {"timestamp", + "uuid", + "attachment_id"}) + public void attachNonSharedAsset() throws MimeTypeParseException { + final Optional item = itemRepo.findById(-510L); + assertThat(item.isPresent(), is(true)); + +// final File file = new File(); +// file.setDisplayName("assets510-2a"); +// file.setFileName("asset-510-2a.pdf"); +// file.setMimeType(new MimeType("application/pdf")); + final Asset file = assetRepo.findById(-720L); + + attachmentManager.attachAsset(file, item.get().getAttachments().get(1)); + } + + /** + * Tries to attach some {@link Asset}s to some {@link AttachmentList}s using + * {@link ItemAttachmentManager#attachAsset(org.librecms.contentsection.Asset, org.librecms.contentsection.AttachmentList)}. + * + * @throws javax.activation.MimeTypeParseException + */ + @Test + @InSequence(100) + @UsingDataSet("datasets/org/librecms/contentsection/" + + "ItemAttachmentManagerTest/data.xml") + @ShouldMatchDataSet( + value = "datasets/org/librecms/contentsection/" + + "ItemAttachmentManagerTest/after-attach-shared.xml", + excludeColumns = {"timestamp", + "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); + + attachmentManager.attachAsset(shared, + item.get().getAttachments().get(1)); + } + + /** + * Verifies that + * {@link ItemAttachmentManager#attachAsset(org.librecms.contentsection.Asset, org.librecms.contentsection.AttachmentList)} + * does nothing when the provided {@code asset} is already part of the + * provided {@code list}. + */ + @Test + @InSequence(110) + @UsingDataSet("datasets/org/librecms/contentsection/" + + "ItemAttachmentManagerTest/data.xml") + @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); + + attachmentManager.attachAsset(shared, + item.get().getAttachments().get(1)); + } + + /** + * Verifies that + * {@link ItemAttachmentManager#attachAsset(org.librecms.contentsection.Asset, org.librecms.contentsection.AttachmentList)} + * throws an {@link IllegalArgumentException} if called with {@code null} + * for the asset to attach. + */ + @Test(expected = IllegalArgumentException.class) + @InSequence(120) + @UsingDataSet("datasets/org/librecms/contentsection/" + + "ItemAttachmentManagerTest/data.xml") + @ShouldMatchDataSet("datasets/org/librecms/contentsection/" + + "ItemAttachmentManagerTest/data.xml") + @ShouldThrowException(IllegalArgumentException.class) + public void attachAssetNull() { + final Optional item = itemRepo.findById(-510L); + assertThat(item.isPresent(), is(true)); + + final Asset asset = null; + + attachmentManager.attachAsset(asset, + item.get().getAttachments().get(1)); + } + + /** + * Verifies that + * {@link ItemAttachmentManager#attachAsset(org.librecms.contentsection.Asset, org.librecms.contentsection.AttachmentList)} + * throws an {@link IllegalArgumentException} if called with {@code null} + * for the list.. + */ + @Test(expected = IllegalArgumentException.class) + @InSequence(130) + @UsingDataSet("datasets/org/librecms/contentsection/" + + "ItemAttachmentManagerTest/data.xml") + @ShouldMatchDataSet("datasets/org/librecms/contentsection/" + + "ItemAttachmentManagerTest/data.xml") + @ShouldThrowException(IllegalArgumentException.class) + public void attachAssetToListNull() { + final AttachmentList list = null; + final Asset shared = assetRepo.findById(-610L); + + attachmentManager.attachAsset(shared, list); + } + + /** + * Tries to unattach several {@link Asset} using + * {@link ItemAttachmentManager#unattachAsset(org.librecms.contentsection.Asset, org.librecms.contentsection.AttachmentList)} + * and verifies that non shared assets are deleted. + */ + @Test + @InSequence(210) + @UsingDataSet("datasets/org/librecms/contentsection/" + + "ItemAttachmentManagerTest/data.xml") + @ShouldMatchDataSet("datasets/org/librecms/contentsection/" + + "ItemAttachmentManagerTest/after-unattach.xml") + public void unattachAsset() { + fail("Not implemented yet"); + } + + /** + * Verifies that + * {@link ItemAttachmentManager#unattachAsset(org.librecms.contentsection.Asset, org.librecms.contentsection.AttachmentList)} + * does nothing if the provided {@code asset} is not part of the provided + * {@code attachmentList}. + */ + @Test + @InSequence(220) + @UsingDataSet("datasets/org/librecms/contentsection/" + + "ItemAttachmentManagerTest/data.xml") + @ShouldMatchDataSet("datasets/org/librecms/contentsection/" + + "ItemAttachmentManagerTest/data.xml") + public void unattachAssetNotAttached() { + fail("Not implemented yet"); + } + + /** + * Verifies that + * {@link ItemAttachmentManager#unattachAsset(org.librecms.contentsection.Asset, org.librecms.contentsection.AttachmentList)} + * throws an {@link IllegalArgumentException} if called with {@code null} + * for the asset to unattach. + */ + @Test(expected = IllegalArgumentException.class) + @InSequence(230) + @UsingDataSet("datasets/org/librecms/contentsection/" + + "ItemAttachmentManagerTest/data.xml") + @ShouldMatchDataSet("datasets/org/librecms/contentsection/" + + "ItemAttachmentManagerTest/data.xml") + @ShouldThrowException(IllegalArgumentException.class) + public void unattachAssetNull() { + fail("Not implemented yet"); + } + + /** + * Verifies that + * {@link ItemAttachmentManager#unattachAsset(org.librecms.contentsection.Asset, org.librecms.contentsection.AttachmentList)} + * throws an {@link IllegalArgumentException} if called with {@code null} + * for the list. + */ + @Test(expected = IllegalArgumentException.class) + @InSequence(240) + @UsingDataSet("datasets/org/librecms/contentsection/" + + "ItemAttachmentManagerTest/data.xml") + @ShouldMatchDataSet("datasets/org/librecms/contentsection/" + + "ItemAttachmentManagerTest/data.xml") + @ShouldThrowException(IllegalArgumentException.class) + public void unattachAssetFromListNull() { + fail("Not implemented yet"); + } + + /** + * Tries to move an {@link Asset} up one position in an + * {@link AttachmentList} using + * {@link ItemAttachmentManager#moveUp(org.librecms.contentsection.Asset, org.librecms.contentsection.AttachmentList)}. + */ + @Test + @InSequence(300) + @UsingDataSet("datasets/org/librecms/contentsection/" + + "ItemAttachmentManagerTest/data.xml") + @ShouldMatchDataSet("datasets/org/librecms/contentsection/" + + "ItemAttachmentManagerTest/after-move-up.xml") + public void moveUp() { + fail("Not implemented yet"); + } + + /** + * Verifies that + * {@link ItemAttachmentManager#moveUp(org.librecms.contentsection.Asset, org.librecms.contentsection.AttachmentList)} + * does nothing if called for the last item in a list. + */ + @Test + @InSequence(310) + @UsingDataSet("datasets/org/librecms/contentsection/" + + "ItemAttachmentManagerTest/data.xml") + @ShouldMatchDataSet("datasets/org/librecms/contentsection/" + + "ItemAttachmentManagerTest/data.xml") + public void moveUpLast() { + fail("Not implemented yet"); + } + + /** + * Verifies that + * {@link ItemAttachmentManager#moveUp(org.librecms.contentsection.Asset, org.librecms.contentsection.AttachmentList)} + * throws an {@link IllegalArgumentException} if called with {@code null} + * for the attachment to move. + */ + @Test(expected = IllegalArgumentException.class) + @InSequence(320) + @UsingDataSet("datasets/org/librecms/contentsection/" + + "ItemAttachmentManagerTest/data.xml") + @ShouldMatchDataSet("datasets/org/librecms/contentsection/" + + "ItemAttachmentManagerTest/data.xml") + @ShouldThrowException(IllegalArgumentException.class) + public void moveUpNull() { + fail("Not implemented yet"); + } + + /** + * Tries to move an {@link Asset} down one position in an + * {@link AttachmentList} using + * {@link ItemAttachmentManager#moveUp(org.librecms.contentsection.Asset, org.librecms.contentsection.AttachmentList)}. + */ + @Test + @InSequence(400) + @UsingDataSet("datasets/org/librecms/contentsection/" + + "ItemAttachmentManagerTest/data.xml") + @ShouldMatchDataSet("datasets/org/librecms/contentsection/" + + "ItemAttachmentManagerTest/after-move-down.xml") + public void moveDown() { + fail("Not implemented yet"); + } + + /** + * Verifies that + * {@link ItemAttachmentManager#moveDown(org.librecms.contentsection.Asset, org.librecms.contentsection.AttachmentList)} + * does nothing if called for the first item in a list. + */ + @Test + @InSequence(410) + @UsingDataSet("datasets/org/librecms/contentsection/" + + "ItemAttachmentManagerTest/data.xml") + @ShouldMatchDataSet("datasets/org/librecms/contentsection/" + + "ItemAttachmentManagerTest/data.xml") + public void moveDownFirst() { + fail("Not implemented yet"); + } + + /** + * Verifies that + * {@link ItemAttachmentManager#moveDown(org.librecms.contentsection.Asset, org.librecms.contentsection.AttachmentList)} + * throws an {@link IllegalArgumentException} if called with {@code null} + * for the attachment to move. + */ + @Test(expected = IllegalArgumentException.class) + @InSequence(420) + @UsingDataSet("datasets/org/librecms/contentsection/" + + "ItemAttachmentManagerTest/data.xml") + @ShouldMatchDataSet("datasets/org/librecms/contentsection/" + + "ItemAttachmentManagerTest/data.xml") + @ShouldThrowException(IllegalArgumentException.class) + public void moveDownNull() { + fail("Not implemented yet"); + } + +} diff --git a/ccm-cms/src/test/resources-wildfly-remote-pgsql/arquillian.xml b/ccm-cms/src/test/resources-wildfly-remote-pgsql/arquillian.xml index 3ee0692f6..5e86db92c 100644 --- a/ccm-cms/src/test/resources-wildfly-remote-pgsql/arquillian.xml +++ b/ccm-cms/src/test/resources-wildfly-remote-pgsql/arquillian.xml @@ -31,9 +31,9 @@ true - + diff --git a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ItemAttachmentManagerTest/after-attach-nonshared.xml b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ItemAttachmentManagerTest/after-attach-nonshared.xml new file mode 100644 index 000000000..5de9848e8 --- /dev/null +++ b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ItemAttachmentManagerTest/after-attach-nonshared.xml @@ -0,0 +1,445 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ItemAttachmentManagerTest/after-attach-shared.xml b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ItemAttachmentManagerTest/after-attach-shared.xml new file mode 100644 index 000000000..d5b30f492 --- /dev/null +++ b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ItemAttachmentManagerTest/after-attach-shared.xml @@ -0,0 +1,410 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ItemAttachmentManagerTest/after-move-down.xml b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ItemAttachmentManagerTest/after-move-down.xml new file mode 100644 index 000000000..809c88e14 --- /dev/null +++ b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ItemAttachmentManagerTest/after-move-down.xml @@ -0,0 +1,376 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ItemAttachmentManagerTest/after-move-up.xml b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ItemAttachmentManagerTest/after-move-up.xml new file mode 100644 index 000000000..809c88e14 --- /dev/null +++ b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ItemAttachmentManagerTest/after-move-up.xml @@ -0,0 +1,376 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ItemAttachmentManagerTest/after-unattach.xml b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ItemAttachmentManagerTest/after-unattach.xml new file mode 100644 index 000000000..809c88e14 --- /dev/null +++ b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ItemAttachmentManagerTest/after-unattach.xml @@ -0,0 +1,376 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ItemAttachmentManagerTest/data.xml b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ItemAttachmentManagerTest/data.xml new file mode 100644 index 000000000..a932a975c --- /dev/null +++ b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ItemAttachmentManagerTest/data.xml @@ -0,0 +1,375 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +