CCM NG: Fixed several test failures due to recent changes.

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4594 8810af33-2d31-482b-a856-94f89814c4df
jensp 2017-02-22 20:40:07 +00:00
parent 207aea48ea
commit 46ff680193
16 changed files with 239 additions and 199 deletions

View File

@ -432,20 +432,36 @@ public class ContentItem extends CcmObject implements Serializable {
} }
public Date getCreationDate() { public Date getCreationDate() {
if (creationDate == null) {
return null;
} else {
return new Date(creationDate.getTime()); return new Date(creationDate.getTime());
} }
}
public void setCreationDate(final Date creationDate) { public void setCreationDate(final Date creationDate) {
if (creationDate == null) {
this.creationDate = null;
} else {
this.creationDate = new Date(creationDate.getTime()); this.creationDate = new Date(creationDate.getTime());
} }
}
public Date getLastModified() { public Date getLastModified() {
if (lastModified == null) {
return null;
} else {
return new Date(lastModified.getTime()); return new Date(lastModified.getTime());
} }
}
public void setLastModified(final Date lastModified) { public void setLastModified(final Date lastModified) {
if (lastModified == null) {
this.lastModified = null;
} else {
this.lastModified = new Date(lastModified.getTime()); this.lastModified = new Date(lastModified.getTime());
} }
}
public String getCreationUserName() { public String getCreationUserName() {
return creationUserName; return creationUserName;

View File

@ -72,6 +72,8 @@ import javax.transaction.Transactional;
import org.libreccm.security.PermissionChecker; import org.libreccm.security.PermissionChecker;
import org.librecms.contentsection.privileges.TypePrivileges; import org.librecms.contentsection.privileges.TypePrivileges;
import java.util.Objects;
/** /**
* Manager class providing several methods to manipulate {@link ContentItem}s. * Manager class providing several methods to manipulate {@link ContentItem}s.
* *
@ -389,6 +391,9 @@ public class ContentItemManager {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
// final String uuid = UUID.randomUUID().toString();
// copy.setUuid(uuid);
// copy.setItemUuid(uuid);
copy.setContentType(contentType.get()); copy.setContentType(contentType.get());
if (draftItem.getWorkflow() != null) { if (draftItem.getWorkflow() != null) {
@ -399,26 +404,6 @@ public class ContentItemManager {
copy.setWorkflow(copyWorkflow); copy.setWorkflow(copyWorkflow);
} }
contentItemRepo.save(copy);
draftItem.getCategories().forEach(categorization -> categoryManager
.addObjectToCategory(copy, categorization.getCategory()));
final Optional<Folder> itemFolder = getItemFolder(draftItem);
if (itemFolder.isPresent()) {
try {
categoryManager.removeObjectFromCategory(
copy, getItemFolder(draftItem).get());
} catch (ObjectNotAssignedToCategoryException ex) {
throw new RuntimeException(ex);
}
}
categoryManager.addObjectToCategory(
copy,
targetFolder,
CATEGORIZATION_TYPE_FOLDER);
for (AttachmentList attachmentList : item.getAttachments()) { for (AttachmentList attachmentList : item.getAttachments()) {
copyAttachmentList(attachmentList, copy); copyAttachmentList(attachmentList, copy);
} }
@ -536,6 +521,24 @@ public class ContentItemManager {
} }
} }
contentItemRepo.save(copy);
draftItem.getCategories().forEach(categorization -> categoryManager
.addObjectToCategory(copy, categorization.getCategory()));
final Optional<Folder> itemFolder = getItemFolder(draftItem);
if (itemFolder.isPresent()) {
try {
categoryManager.removeObjectFromCategory(
copy, getItemFolder(draftItem).get());
} catch (ObjectNotAssignedToCategoryException ex) {
throw new RuntimeException(ex);
}
}
categoryManager.addObjectToCategory(
copy,
targetFolder,
CATEGORIZATION_TYPE_FOLDER);
if (targetFolder.equals(getItemFolder(item).orElse(null))) { if (targetFolder.equals(getItemFolder(item).orElse(null))) {
final long number = contentItemRepo.countFilterByFolderAndName( final long number = contentItemRepo.countFilterByFolderAndName(
targetFolder, String.format("%s_copy", targetFolder, String.format("%s_copy",
@ -546,8 +549,6 @@ public class ContentItemManager {
index)); index));
} }
contentItemRepo.save(copy);
return copy; return copy;
} }

View File

@ -372,7 +372,12 @@ public class ContentItemRepository
public void save(final ContentItem item) { public void save(final ContentItem item) {
final Date now = new Date(); final Date now = new Date();
final Subject subject = shiro.getSubject(); final Subject subject = shiro.getSubject();
final String userName = subject.getPrincipal().toString(); final String userName;
if (subject == null || subject.getPrincipal() == null) {
userName = "";
} else {
userName = subject.getPrincipal().toString();
}
if (isNew(item)) { if (isNew(item)) {
item.setCreationDate(now); item.setCreationDate(now);
@ -405,7 +410,6 @@ public class ContentItemRepository
removeCategoryFromItem(item, category); removeCategoryFromItem(item, category);
} }
super.delete(draft); super.delete(draft);
} }

View File

@ -146,7 +146,8 @@ public class ContentItemRepositoryTest {
.addAsLibraries(getCcmCoreDependencies()) .addAsLibraries(getCcmCoreDependencies())
.addAsResource("test-persistence.xml", .addAsResource("test-persistence.xml",
"META-INF/persistence.xml") "META-INF/persistence.xml")
.addAsWebInfResource("test-web.xml", "WEB-INF/web.xml") .addAsResource("configs/shiro.ini", "shiro.ini")
.addAsWebInfResource("test-web.xml", "web.xml")
.addAsWebInfResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml"); .addAsWebInfResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml");
} }

View File

@ -514,7 +514,7 @@
<ccm_core.categorizations categorization_id="-30400" <ccm_core.categorizations categorization_id="-30400"
category_id="-1600" category_id="-1600"
object_id="-900" object_id="-900"
category_order="1" category_order="2"
object_order="4" object_order="4"
category_index="false" category_index="false"
type="folder" /> type="folder" />

View File

@ -514,7 +514,7 @@
<ccm_core.categorizations categorization_id="-30400" <ccm_core.categorizations categorization_id="-30400"
category_id="-410" category_id="-410"
object_id="-900" object_id="-900"
category_order="1" category_order="2"
object_order="4" object_order="4"
category_index="false" category_index="false"
type="folder" /> type="folder" />

View File

@ -682,7 +682,7 @@
<ccm_core.categorizations categorization_id="-30110" <ccm_core.categorizations categorization_id="-30110"
category_id="-2300" category_id="-2300"
object_id="-10110" object_id="-10110"
category_order="1" category_order="2"
object_order="1" object_order="1"
category_index="false" category_index="false"
type="folder" /> type="folder" />

View File

@ -676,7 +676,7 @@
<ccm_core.categorizations categorization_id="-30500" <ccm_core.categorizations categorization_id="-30500"
category_id="-2120" category_id="-2120"
object_id="-10500" object_id="-10500"
category_order="1" category_order="2"
object_order="1" object_order="1"
category_index="false" category_index="false"
type="folder" /> type="folder" />

View File

@ -647,7 +647,7 @@
<ccm_core.categorizations categorization_id="-30100" <ccm_core.categorizations categorization_id="-30100"
category_id="-2110" category_id="-2110"
object_id="-10100" object_id="-10100"
category_order="1" category_order="2"
object_order="1" object_order="1"
category_index="false" category_index="false"
type="folder" /> type="folder" />

View File

@ -566,7 +566,7 @@
<ccm_core.categorizations categorization_id="-30100" <ccm_core.categorizations categorization_id="-30100"
category_id="-2300" category_id="-2300"
object_id="-10100" object_id="-10100"
category_order="1" category_order="2"
object_order="1" object_order="1"
category_index="false" category_index="false"
type="folder" /> type="folder" />

View File

@ -567,7 +567,7 @@
<ccm_core.categorizations categorization_id="-30100" <ccm_core.categorizations categorization_id="-30100"
category_id="-2120" category_id="-2120"
object_id="-10100" object_id="-10100"
category_order="1" category_order="2"
object_order="1" object_order="1"
category_index="false" category_index="false"
type="folder" /> type="folder" />

View File

@ -629,7 +629,7 @@
<ccm_core.categorizations categorization_id="-30200" <ccm_core.categorizations categorization_id="-30200"
category_id="-2100" category_id="-2100"
object_id="-10200" object_id="-10200"
category_order="1" category_order="2"
object_order="2" object_order="2"
category_index="false" category_index="false"
type="folder" /> type="folder" />

View File

@ -20,7 +20,6 @@ package org.libreccm.auditing;
import org.apache.shiro.subject.Subject; import org.apache.shiro.subject.Subject;
import org.hibernate.envers.RevisionListener; import org.hibernate.envers.RevisionListener;
import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.security.Shiro; import org.libreccm.security.Shiro;
@ -46,7 +45,11 @@ public class CcmRevisionListener implements RevisionListener {
final Shiro shiro = cdiUtil.findBean(Shiro.class); final Shiro shiro = cdiUtil.findBean(Shiro.class);
final Subject subject = shiro.getSubject(); final Subject subject = shiro.getSubject();
if (subject == null || subject.getPrincipal() == null) {
revision.setUserName("");
} else {
revision.setUserName(subject.getPrincipal().toString()); revision.setUserName(subject.getPrincipal().toString());
} }
}
} }

View File

@ -277,9 +277,9 @@ public class CategoryManager {
query.setParameter("category", category); query.setParameter("category", category);
query.setParameter("object", object); query.setParameter("object", object);
final Categorization categorization; final List<Categorization> categorizations;
try { try {
categorization = query.getSingleResult(); categorizations = query.getResultList();
} catch (NoResultException ex) { } catch (NoResultException ex) {
LOGGER.warn(String.format( LOGGER.warn(String.format(
"No categorization for category %s and object %s found." "No categorization for category %s and object %s found."
@ -290,7 +290,7 @@ public class CategoryManager {
return; return;
} }
entityManager.remove(categorization); categorizations.forEach(entityManager::remove);
// shiro.getSystemUser().execute(() -> { // shiro.getSystemUser().execute(() -> {
// object.removeCategory(categorization); // object.removeCategory(categorization);

View File

@ -101,8 +101,8 @@ public class CcmObjectRepositoryTest {
public static WebArchive createDeployment() { public static WebArchive createDeployment() {
return ShrinkWrap return ShrinkWrap
.create(WebArchive.class, .create(WebArchive.class,
"LibreCCM-org.libreccm.core.CcmObjectRepositoryTest.war"). "LibreCCM-org.libreccm.core.CcmObjectRepositoryTest.war")
addPackage(org.libreccm.auditing.CcmRevision.class.getPackage()) .addPackage(org.libreccm.auditing.CcmRevision.class.getPackage())
.addPackage(org.libreccm.categorization.Categorization.class .addPackage(org.libreccm.categorization.Categorization.class
.getPackage()) .getPackage())
.addPackage(org.libreccm.configuration.Configuration.class. .addPackage(org.libreccm.configuration.Configuration.class.
@ -112,9 +112,16 @@ public class CcmObjectRepositoryTest {
.getPackage()) .getPackage())
.addPackage(org.libreccm.jpa.utils.MimeTypeConverter.class .addPackage(org.libreccm.jpa.utils.MimeTypeConverter.class
.getPackage()) .getPackage())
.addPackage(org.libreccm.l10n.LocalizedString.class.getPackage()). .addPackage(org.libreccm.l10n.LocalizedString.class.getPackage())
addPackage(org.libreccm.security.PermissionChecker.class .addClass(org.libreccm.modules.CcmModule.class)
.addClass(org.libreccm.modules.ModuleEvent.class)
.addClass(org.libreccm.modules.InitEvent.class)
.addClass(org.libreccm.modules.InstallEvent.class)
.addClass(org.libreccm.modules.UnInstallEvent.class)
.addClass(org.libreccm.modules.ShutdownEvent.class)
.addPackage(org.libreccm.security.PermissionChecker.class
.getPackage()) .getPackage())
.addPackage(org.libreccm.cdi.utils.CdiUtil.class.getPackage())
.addPackage(org.libreccm.testutils.EqualsVerifier.class. .addPackage(org.libreccm.testutils.EqualsVerifier.class.
getPackage()) getPackage())
.addPackage(org.libreccm.tests.categories.IntegrationTest.class .addPackage(org.libreccm.tests.categories.IntegrationTest.class
@ -122,10 +129,13 @@ public class CcmObjectRepositoryTest {
.addPackage(org.libreccm.web.CcmApplication.class.getPackage()) .addPackage(org.libreccm.web.CcmApplication.class.getPackage())
.addPackage(org.libreccm.workflow.Workflow.class.getPackage()) .addPackage(org.libreccm.workflow.Workflow.class.getPackage())
.addClass(org.libreccm.portation.Portable.class) .addClass(org.libreccm.portation.Portable.class)
.addPackage(com.arsdigita.kernel.security.SecurityConfig.class
.getPackage())
.addAsLibraries(getModuleDependencies()) .addAsLibraries(getModuleDependencies())
.addAsResource("test-persistence.xml", .addAsResource("test-persistence.xml",
"META-INF/persistence.xml") "META-INF/persistence.xml")
.addAsWebInfResource("test-web.xml", "WEB-INF/web.xml") .addAsResource("configs/shiro.ini", "shiro.ini")
.addAsWebInfResource("test-web.xml", "web.xml")
.addAsWebInfResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml"); .addAsWebInfResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml");
} }
@ -343,8 +353,10 @@ public class CcmObjectRepositoryTest {
* a {@link IllegalArgumentException} if called with {@link null} for the * a {@link IllegalArgumentException} if called with {@link null} for the
* object to delete. * object to delete.
*/ */
@Test(expected = IllegalArgumentException.class) @Test(expected = NullPointerException.class)
@ShouldThrowException(IllegalArgumentException.class) @ShouldThrowException(NullPointerException.class)
@UsingDataSet("datasets/org/libreccm/core/CcmObjectRepositoryTest/data.yml")
@ShouldMatchDataSet("datasets/org/libreccm/core/CcmObjectRepositoryTest/data.yml")
@InSequence(700) @InSequence(700)
public void deleteNullValue() { public void deleteNullValue() {
ccmObjectRepository.delete(null); ccmObjectRepository.delete(null);

View File

@ -269,8 +269,11 @@ public class PartyRepositoryTest {
shiro.getSystemUser().execute(() -> partyRepository.delete(user)); shiro.getSystemUser().execute(() -> partyRepository.delete(user));
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = NullPointerException.class)
@ShouldThrowException(IllegalArgumentException.class) @ShouldThrowException(NullPointerException.class)
@UsingDataSet("datasets/org/libreccm/security/PartyRepositoryTest/data.yml")
@ShouldMatchDataSet(
"datasets/org/libreccm/security/PartyRepositoryTest/data.yml")
@InSequence(700) @InSequence(700)
public void deleteNullValue() { public void deleteNullValue() {
shiro.getSystemUser().execute(() -> partyRepository.delete(null)); shiro.getSystemUser().execute(() -> partyRepository.delete(null));