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
Former-commit-id: 46ff680193
pull/2/head
parent
871669496e
commit
7b50e1b830
|
|
@ -432,20 +432,36 @@ public class ContentItem extends CcmObject implements Serializable {
|
|||
}
|
||||
|
||||
public Date getCreationDate() {
|
||||
if (creationDate == null) {
|
||||
return null;
|
||||
} else {
|
||||
return new Date(creationDate.getTime());
|
||||
}
|
||||
}
|
||||
|
||||
public void setCreationDate(final Date creationDate) {
|
||||
if (creationDate == null) {
|
||||
this.creationDate = null;
|
||||
} else {
|
||||
this.creationDate = new Date(creationDate.getTime());
|
||||
}
|
||||
}
|
||||
|
||||
public Date getLastModified() {
|
||||
if (lastModified == null) {
|
||||
return null;
|
||||
} else {
|
||||
return new Date(lastModified.getTime());
|
||||
}
|
||||
}
|
||||
|
||||
public void setLastModified(final Date lastModified) {
|
||||
if (lastModified == null) {
|
||||
this.lastModified = null;
|
||||
} else {
|
||||
this.lastModified = new Date(lastModified.getTime());
|
||||
}
|
||||
}
|
||||
|
||||
public String getCreationUserName() {
|
||||
return creationUserName;
|
||||
|
|
|
|||
|
|
@ -72,6 +72,8 @@ import javax.transaction.Transactional;
|
|||
import org.libreccm.security.PermissionChecker;
|
||||
import org.librecms.contentsection.privileges.TypePrivileges;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Manager class providing several methods to manipulate {@link ContentItem}s.
|
||||
*
|
||||
|
|
@ -389,6 +391,9 @@ public class ContentItemManager {
|
|||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
// final String uuid = UUID.randomUUID().toString();
|
||||
// copy.setUuid(uuid);
|
||||
// copy.setItemUuid(uuid);
|
||||
copy.setContentType(contentType.get());
|
||||
|
||||
if (draftItem.getWorkflow() != null) {
|
||||
|
|
@ -399,26 +404,6 @@ public class ContentItemManager {
|
|||
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()) {
|
||||
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))) {
|
||||
final long number = contentItemRepo.countFilterByFolderAndName(
|
||||
targetFolder, String.format("%s_copy",
|
||||
|
|
@ -546,8 +549,6 @@ public class ContentItemManager {
|
|||
index));
|
||||
}
|
||||
|
||||
contentItemRepo.save(copy);
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -372,7 +372,12 @@ public class ContentItemRepository
|
|||
public void save(final ContentItem item) {
|
||||
final Date now = new Date();
|
||||
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)) {
|
||||
item.setCreationDate(now);
|
||||
|
|
@ -405,7 +410,6 @@ public class ContentItemRepository
|
|||
removeCategoryFromItem(item, category);
|
||||
}
|
||||
|
||||
|
||||
super.delete(draft);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -146,7 +146,8 @@ public class ContentItemRepositoryTest {
|
|||
.addAsLibraries(getCcmCoreDependencies())
|
||||
.addAsResource("test-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");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -514,7 +514,7 @@
|
|||
<ccm_core.categorizations categorization_id="-30400"
|
||||
category_id="-1600"
|
||||
object_id="-900"
|
||||
category_order="1"
|
||||
category_order="2"
|
||||
object_order="4"
|
||||
category_index="false"
|
||||
type="folder" />
|
||||
|
|
|
|||
|
|
@ -514,7 +514,7 @@
|
|||
<ccm_core.categorizations categorization_id="-30400"
|
||||
category_id="-410"
|
||||
object_id="-900"
|
||||
category_order="1"
|
||||
category_order="2"
|
||||
object_order="4"
|
||||
category_index="false"
|
||||
type="folder" />
|
||||
|
|
|
|||
|
|
@ -682,7 +682,7 @@
|
|||
<ccm_core.categorizations categorization_id="-30110"
|
||||
category_id="-2300"
|
||||
object_id="-10110"
|
||||
category_order="1"
|
||||
category_order="2"
|
||||
object_order="1"
|
||||
category_index="false"
|
||||
type="folder" />
|
||||
|
|
|
|||
|
|
@ -676,7 +676,7 @@
|
|||
<ccm_core.categorizations categorization_id="-30500"
|
||||
category_id="-2120"
|
||||
object_id="-10500"
|
||||
category_order="1"
|
||||
category_order="2"
|
||||
object_order="1"
|
||||
category_index="false"
|
||||
type="folder" />
|
||||
|
|
|
|||
|
|
@ -647,7 +647,7 @@
|
|||
<ccm_core.categorizations categorization_id="-30100"
|
||||
category_id="-2110"
|
||||
object_id="-10100"
|
||||
category_order="1"
|
||||
category_order="2"
|
||||
object_order="1"
|
||||
category_index="false"
|
||||
type="folder" />
|
||||
|
|
|
|||
|
|
@ -566,7 +566,7 @@
|
|||
<ccm_core.categorizations categorization_id="-30100"
|
||||
category_id="-2300"
|
||||
object_id="-10100"
|
||||
category_order="1"
|
||||
category_order="2"
|
||||
object_order="1"
|
||||
category_index="false"
|
||||
type="folder" />
|
||||
|
|
|
|||
|
|
@ -567,7 +567,7 @@
|
|||
<ccm_core.categorizations categorization_id="-30100"
|
||||
category_id="-2120"
|
||||
object_id="-10100"
|
||||
category_order="1"
|
||||
category_order="2"
|
||||
object_order="1"
|
||||
category_index="false"
|
||||
type="folder" />
|
||||
|
|
|
|||
|
|
@ -629,7 +629,7 @@
|
|||
<ccm_core.categorizations categorization_id="-30200"
|
||||
category_id="-2100"
|
||||
object_id="-10200"
|
||||
category_order="1"
|
||||
category_order="2"
|
||||
object_order="2"
|
||||
category_index="false"
|
||||
type="folder" />
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ package org.libreccm.auditing;
|
|||
|
||||
import org.apache.shiro.subject.Subject;
|
||||
|
||||
|
||||
import org.hibernate.envers.RevisionListener;
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.security.Shiro;
|
||||
|
|
@ -46,7 +45,11 @@ public class CcmRevisionListener implements RevisionListener {
|
|||
final Shiro shiro = cdiUtil.findBean(Shiro.class);
|
||||
|
||||
final Subject subject = shiro.getSubject();
|
||||
if (subject == null || subject.getPrincipal() == null) {
|
||||
revision.setUserName("");
|
||||
} else {
|
||||
revision.setUserName(subject.getPrincipal().toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -277,9 +277,9 @@ public class CategoryManager {
|
|||
query.setParameter("category", category);
|
||||
query.setParameter("object", object);
|
||||
|
||||
final Categorization categorization;
|
||||
final List<Categorization> categorizations;
|
||||
try {
|
||||
categorization = query.getSingleResult();
|
||||
categorizations = query.getResultList();
|
||||
} catch (NoResultException ex) {
|
||||
LOGGER.warn(String.format(
|
||||
"No categorization for category %s and object %s found."
|
||||
|
|
@ -290,7 +290,7 @@ public class CategoryManager {
|
|||
return;
|
||||
}
|
||||
|
||||
entityManager.remove(categorization);
|
||||
categorizations.forEach(entityManager::remove);
|
||||
|
||||
// shiro.getSystemUser().execute(() -> {
|
||||
// object.removeCategory(categorization);
|
||||
|
|
|
|||
|
|
@ -101,8 +101,8 @@ public class CcmObjectRepositoryTest {
|
|||
public static WebArchive createDeployment() {
|
||||
return ShrinkWrap
|
||||
.create(WebArchive.class,
|
||||
"LibreCCM-org.libreccm.core.CcmObjectRepositoryTest.war").
|
||||
addPackage(org.libreccm.auditing.CcmRevision.class.getPackage())
|
||||
"LibreCCM-org.libreccm.core.CcmObjectRepositoryTest.war")
|
||||
.addPackage(org.libreccm.auditing.CcmRevision.class.getPackage())
|
||||
.addPackage(org.libreccm.categorization.Categorization.class
|
||||
.getPackage())
|
||||
.addPackage(org.libreccm.configuration.Configuration.class.
|
||||
|
|
@ -112,9 +112,16 @@ public class CcmObjectRepositoryTest {
|
|||
.getPackage())
|
||||
.addPackage(org.libreccm.jpa.utils.MimeTypeConverter.class
|
||||
.getPackage())
|
||||
.addPackage(org.libreccm.l10n.LocalizedString.class.getPackage()).
|
||||
addPackage(org.libreccm.security.PermissionChecker.class
|
||||
.addPackage(org.libreccm.l10n.LocalizedString.class.getPackage())
|
||||
.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())
|
||||
.addPackage(org.libreccm.cdi.utils.CdiUtil.class.getPackage())
|
||||
.addPackage(org.libreccm.testutils.EqualsVerifier.class.
|
||||
getPackage())
|
||||
.addPackage(org.libreccm.tests.categories.IntegrationTest.class
|
||||
|
|
@ -122,10 +129,13 @@ public class CcmObjectRepositoryTest {
|
|||
.addPackage(org.libreccm.web.CcmApplication.class.getPackage())
|
||||
.addPackage(org.libreccm.workflow.Workflow.class.getPackage())
|
||||
.addClass(org.libreccm.portation.Portable.class)
|
||||
.addPackage(com.arsdigita.kernel.security.SecurityConfig.class
|
||||
.getPackage())
|
||||
.addAsLibraries(getModuleDependencies())
|
||||
.addAsResource("test-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");
|
||||
}
|
||||
|
||||
|
|
@ -343,8 +353,10 @@ public class CcmObjectRepositoryTest {
|
|||
* a {@link IllegalArgumentException} if called with {@link null} for the
|
||||
* object to delete.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@ShouldThrowException(IllegalArgumentException.class)
|
||||
@Test(expected = NullPointerException.class)
|
||||
@ShouldThrowException(NullPointerException.class)
|
||||
@UsingDataSet("datasets/org/libreccm/core/CcmObjectRepositoryTest/data.yml")
|
||||
@ShouldMatchDataSet("datasets/org/libreccm/core/CcmObjectRepositoryTest/data.yml")
|
||||
@InSequence(700)
|
||||
public void deleteNullValue() {
|
||||
ccmObjectRepository.delete(null);
|
||||
|
|
|
|||
|
|
@ -269,8 +269,11 @@ public class PartyRepositoryTest {
|
|||
shiro.getSystemUser().execute(() -> partyRepository.delete(user));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@ShouldThrowException(IllegalArgumentException.class)
|
||||
@Test(expected = NullPointerException.class)
|
||||
@ShouldThrowException(NullPointerException.class)
|
||||
@UsingDataSet("datasets/org/libreccm/security/PartyRepositoryTest/data.yml")
|
||||
@ShouldMatchDataSet(
|
||||
"datasets/org/libreccm/security/PartyRepositoryTest/data.yml")
|
||||
@InSequence(700)
|
||||
public void deleteNullValue() {
|
||||
shiro.getSystemUser().execute(() -> partyRepository.delete(null));
|
||||
|
|
|
|||
Loading…
Reference in New Issue