From df919acfc75cad64ddb7a883c44fe531964f19a4 Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Thu, 26 Jan 2017 12:16:54 +0200 Subject: [PATCH] RM-4619 - fixed unit tests --- .../model/rma/type/FilePlanTypeUnitTest.java | 25 ++++++++ .../rma/type/RecordCategoryTypeUnitTest.java | 25 ++++++++ ...ecordsManagementContainerTypeUnitTest.java | 57 ++----------------- 3 files changed, 55 insertions(+), 52 deletions(-) diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/FilePlanTypeUnitTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/FilePlanTypeUnitTest.java index 607d053242..d25d6ecb19 100644 --- a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/FilePlanTypeUnitTest.java +++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/FilePlanTypeUnitTest.java @@ -27,11 +27,13 @@ package org.alfresco.module.org_alfresco_module_rm.model.rma.type; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import java.util.Arrays; import org.alfresco.model.ContentModel; +import org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock; import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest; import org.alfresco.repo.node.integrity.IntegrityException; import org.alfresco.service.cmr.repository.ChildAssociationRef; @@ -180,6 +182,29 @@ public class FilePlanTypeUnitTest extends BaseUnitTest filePlanType.onCreateChildAssociation(childAssoc, true); } + /** + * Given that we try to add "cm:folder" type to a record category, + * Then operation is successful and the folder is automatically converted to a record folder + */ + @Test + public void testConversionToRecordFolder() throws Exception + { + NodeRef fileplan = AlfMock.generateNodeRef(mockedNodeService, TYPE_FILE_PLAN); + NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_FOLDER, true); + ChildAssociationRef childAssocRef = generateChildAssociationRef(fileplan, nodeRef); + + try + { + filePlanType.onCreateChildAssociation(childAssocRef, true); + } + catch(IntegrityException ex) + { + // this will throw an exception because unit tests can't detect type change + } + + verify(mockedNodeService).setType(nodeRef, TYPE_RECORD_CATEGORY); + } + /** * Helper method that creates a child of the fileplan container with the provided type * @param childType the node type of the child to be created diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordCategoryTypeUnitTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordCategoryTypeUnitTest.java index e32127ff19..ffd6256a2d 100644 --- a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordCategoryTypeUnitTest.java +++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordCategoryTypeUnitTest.java @@ -27,6 +27,7 @@ package org.alfresco.module.org_alfresco_module_rm.model.rma.type; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock; @@ -108,4 +109,28 @@ public class RecordCategoryTypeUnitTest extends BaseUnitTest ChildAssociationRef childAssocRef = generateChildAssociationRef(recordCategoryNodeRef, nodeRef); recordCategoryType.onCreateChildAssociation(childAssocRef, true); } + + /** + * Given that we try to add "cm:folder" type to a record category, + * Then operation is successful and the folder is automatically converted to a record folder + */ + @Test + public void testConversionToRecordFolder() throws Exception + { + NodeRef recordCategoryNodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_RECORD_CATEGORY); + NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_FOLDER, true); + ChildAssociationRef childAssocRef = generateChildAssociationRef(recordCategoryNodeRef, nodeRef); + + try + { + recordCategoryType.onCreateChildAssociation(childAssocRef, true); + } + catch(IntegrityException ex) + { + // this will throw an exception because unit tests can't detect type change + } + + verify(mockedNodeService).setType(nodeRef, TYPE_RECORD_FOLDER); + verify(mockedRecordFolderService).setupRecordFolder(nodeRef); + } } diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordsManagementContainerTypeUnitTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordsManagementContainerTypeUnitTest.java index dfc996c23c..cb12360323 100644 --- a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordsManagementContainerTypeUnitTest.java +++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordsManagementContainerTypeUnitTest.java @@ -26,13 +26,11 @@ */ package org.alfresco.module.org_alfresco_module_rm.model.rma.type; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.model.ContentModel; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest; @@ -52,33 +50,10 @@ public class RecordsManagementContainerTypeUnitTest extends BaseUnitTest /** test object */ private @InjectMocks RecordsManagementContainerType recordManagementContainerType; - /** - * Having the Unfilled Record container and a folder - * When adding a child association between the folder and the container - * Then the folder type shouldn't be renamed - */ - @Test - public void testAddFolderToRMContainer() - { - /* Having a RM container and a folder */ - NodeRef rmContainer = generateRMContainer(); - NodeRef rmFolder = generateFolderNode(false); - - /* - * When adding a child association between the folder and the container - */ - ChildAssociationRef childAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, rmContainer, ContentModel.ASSOC_CONTAINS, rmFolder); - recordManagementContainerType.onCreateChildAssociation(childAssoc, true); - - /* Then the node type should not be changed to TYPE_RECORD_FOLDER */ - verify(mockedNodeService).setType(rmFolder, TYPE_RECORD_FOLDER); - verify(mockedRecordFolderService).setupRecordFolder(rmFolder); - } - /** * Having the Unfilled Record container and a folder having the aspect ASPECT_HIDDEN * When adding a child association between the folder and the container - * Then the folder type shouldn't be renamed + * Then the new folder should not be altered */ @Test public void testAddHiddenFolderToRMContainer() @@ -93,31 +68,9 @@ public class RecordsManagementContainerTypeUnitTest extends BaseUnitTest ChildAssociationRef childAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, rmContainer, ContentModel.ASSOC_CONTAINS, rmFolder); recordManagementContainerType.onCreateChildAssociation(childAssoc, true); - /* Then the node type should not be changed to TYPE_RECORD_FOLDER */ - verify(mockedNodeService, never()).setType(rmFolder, TYPE_RECORD_FOLDER); - verify(mockedRecordFolderService, never()).setupRecordFolder(rmFolder); - } - - /** - * Trying to create a RM folder and its sub-types via SFDC, IMap, WebDav, etc - * Check that exception is thrown on creating child associations - */ - @Test - public void testRM3450() - { - NodeRef rmContainer = generateRMContainer(); - NodeRef nonRmFolder = generateNonRmFolderNode(); - - ChildAssociationRef childAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, rmContainer, TestModel.NOT_RM_FOLDER_TYPE, nonRmFolder); - try - { - recordManagementContainerType.onCreateChildAssociation(childAssoc, true); - fail("Expected to throw exception on create child association."); - } - catch (Throwable e) - { - assertTrue(e instanceof AlfrescoRuntimeException); - } + /* The type should not be changed and no aspects should be added */ + verify(mockedNodeService, never()).setType(any(), any()); + verify(mockedNodeService, never()).addAspect(any(), any(), any()); } /**