RM-4619 - updated unit tests

This commit is contained in:
Ana Bozianu
2017-02-27 16:17:22 +02:00
parent 7e08ee2f98
commit 950c0028f3
3 changed files with 143 additions and 29 deletions

View File

@@ -137,7 +137,7 @@ public class RecordsManagementContainerType extends BaseBehaviourBean
final NodeRef child = childAssocRef.getChildRef();
if (nodeService.exists(child))
{
QName childType = convertNodeToFileplanComponent(child, nodeService.getType(child), nodeService.getType(childAssocRef.getParentRef()));
QName childType = convertNodeToFileplanComponent(childAssocRef);
// We only care about "folder" or sub-types that are not hidden.
// Some modules use hidden files to store information (see RM-3283)
@@ -211,13 +211,15 @@ public class RecordsManagementContainerType extends BaseBehaviourBean
* The conversion is needed here to be able to generate the identifier
* If there is no conversion rule for the created type nothing happens and the current type is returned
*
* @param child ref to the new child
* @param childType the type of the new child
* @param parentType the type of the parent node
* @param childAssocRef reference to the new association
* @return the new type of the child node
*/
protected QName convertNodeToFileplanComponent(final NodeRef child, final QName childType, final QName parentType)
protected QName convertNodeToFileplanComponent(final ChildAssociationRef childAssocRef)
{
NodeRef child = childAssocRef.getChildRef();
QName childType = nodeService.getType(child);
QName parentType = nodeService.getType(childAssocRef.getParentRef());
if(childType.equals(ContentModel.TYPE_FOLDER))
{
if(parentType.equals(TYPE_FILE_PLAN))

View File

@@ -55,7 +55,8 @@ public class RM4619Test extends BaseRMTestCase
public Void run() throws Exception
{
FileInfo info = fileFolderService.create(filePlan, GUID.generate(), TYPE_FOLDER);
assertEquals(info.getType(), TYPE_RECORD_CATEGORY);
assertEquals(TYPE_RECORD_CATEGORY, info.getType());
assertNotNull(info.getProperties().get(PROP_IDENTIFIER));
return null;
}
@@ -75,7 +76,36 @@ public class RM4619Test extends BaseRMTestCase
public Void run() throws Exception
{
FileInfo info = fileFolderService.create(rmContainer, GUID.generate(), TYPE_FOLDER);
assertEquals(info.getType(), TYPE_RECORD_FOLDER);
assertEquals(TYPE_RECORD_FOLDER, info.getType());
assertNotNull(info.getProperties().get(PROP_IDENTIFIER));
return null;
}
}, ADMIN_USER);
}
/**
* Given the RM site is created
* When we create a regular folder in the unfiled record container
* Then the folder is immediately converted to a unfiled record folder
*
* And when we create another regular folder in that unfiled record folder
* Then the folder is also immediately converted to a unfiled record folder
*/
public void testConvertFolderToUnfiledRecordFolder() throws Exception
{
doTestInTransaction(new Test<Void>()
{
@Override
public Void run() throws Exception
{
FileInfo folder1 = fileFolderService.create(unfiledContainer, GUID.generate(), TYPE_FOLDER);
assertEquals(TYPE_UNFILED_RECORD_FOLDER, folder1.getType());
assertNotNull(folder1.getProperties().get(PROP_IDENTIFIER));
FileInfo folder2 = fileFolderService.create(folder1.getNodeRef(), GUID.generate(), TYPE_FOLDER);
assertEquals(TYPE_UNFILED_RECORD_FOLDER, folder2.getType());
assertNotNull(folder2.getProperties().get(PROP_IDENTIFIER));
return null;
}

View File

@@ -27,6 +27,7 @@
package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -37,7 +38,7 @@ import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
import org.alfresco.module.org_alfresco_module_rm.test.util.TestModel;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
@@ -51,6 +52,21 @@ public class RecordsManagementContainerTypeUnitTest extends BaseUnitTest
/** test object */
private @InjectMocks RecordsManagementContainerType recordManagementContainerType;
@Before
public void before() throws Exception
{
super.before();
when(mockedDictionaryService.isSubClass(ContentModel.TYPE_FOLDER, ContentModel.TYPE_FOLDER)).thenReturn(true);
when(mockedDictionaryService.isSubClass(ContentModel.TYPE_FOLDER, ContentModel.TYPE_SYSTEM_FOLDER)).thenReturn(false);
when(mockedDictionaryService.isSubClass(TestModel.NOT_RM_FOLDER_TYPE, ContentModel.TYPE_FOLDER)).thenReturn(true);
when(mockedDictionaryService.isSubClass(TestModel.NOT_RM_FOLDER_TYPE, ContentModel.TYPE_SYSTEM_FOLDER)).thenReturn(false);
when(mockedDictionaryService.isSubClass(TYPE_RECORD_CATEGORY, ContentModel.TYPE_FOLDER)).thenReturn(true);
when(mockedDictionaryService.isSubClass(TYPE_RECORD_CATEGORY, ContentModel.TYPE_SYSTEM_FOLDER)).thenReturn(false);
}
/**
* Having the Unfilled Record container and a non RM folder subtype node
* When adding a child association between the folder and the container
@@ -63,17 +79,88 @@ public class RecordsManagementContainerTypeUnitTest extends BaseUnitTest
{
/* Having a RM container and a non RM folder subtype node */
NodeRef rmContainer = generateRMContainer();
NodeRef rmFolder = generateNonRmFolderSubtypeNode();
NodeRef folder = generateNonRmFolderSubtypeNode();
/*
* When adding a child association between the folder and the container
*/
ChildAssociationRef childAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, rmContainer, ContentModel.ASSOC_CONTAINS, rmFolder);
ChildAssociationRef childAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, rmContainer, ContentModel.ASSOC_CONTAINS, folder);
recordManagementContainerType.onCreateChildAssociation(childAssoc, true);
/* 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());
}
/**
* Having the fileplan and a non RM folder node
* When adding a child association between the fileplan and the folder
* Then the new folder should be converted to a record category
*/
@Test
public void testAddFolderInFilePlan()
{
NodeRef fileplan = generateNodeRef();
when(mockedNodeService.getType(fileplan)).thenReturn(TYPE_FILE_PLAN);
NodeRef folder = generateNonRmFolderNode();
ChildAssociationRef childAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, fileplan, ContentModel.ASSOC_CONTAINS, folder);
recordManagementContainerType.onCreateChildAssociation(childAssoc, true);
verify(mockedNodeService).setType(folder, TYPE_RECORD_CATEGORY);
}
/**
* Having a record category and a non RM folder node
* When adding a child association between the record category and the folder
* Then the new folder should be converted to a record folder
*/
@Test
public void testAddFolderInRecordCategory()
{
NodeRef category = generateNodeRef();
when(mockedNodeService.getType(category)).thenReturn(TYPE_RECORD_CATEGORY);
NodeRef folder = generateNonRmFolderNode();
ChildAssociationRef childAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, category, ContentModel.ASSOC_CONTAINS, folder);
recordManagementContainerType.onCreateChildAssociation(childAssoc, true);
verify(mockedNodeService).setType(folder, TYPE_RECORD_FOLDER);
}
/**
* Having an unfiled record container and a non RM folder node
* When adding a child association between the container and the folder
* Then the new folder should be converted to a unfiled record folder
*/
@Test
public void testAddFolderInUnfiledRecordContainer()
{
NodeRef unfiledRecordContainer = generateNodeRef();
when(mockedNodeService.getType(unfiledRecordContainer)).thenReturn(TYPE_UNFILED_RECORD_CONTAINER);
NodeRef folder = generateNonRmFolderNode();
ChildAssociationRef childAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, unfiledRecordContainer, ContentModel.ASSOC_CONTAINS, folder);
recordManagementContainerType.onCreateChildAssociation(childAssoc, true);
verify(mockedNodeService).setType(folder, TYPE_UNFILED_RECORD_FOLDER);
}
/**
* Having an unfiled record folder and a non RM folder node
* When adding a child association between the unfiled record folder and the regular folder
* Then the new folder should be converted to a unfiled record folder
*/
@Test
public void testAddFolderInUnfiledRecordFolder()
{
NodeRef unfiledRecordFolder = generateNodeRef();
when(mockedNodeService.getType(unfiledRecordFolder)).thenReturn(TYPE_UNFILED_RECORD_FOLDER);
NodeRef folder = generateNonRmFolderNode();
ChildAssociationRef childAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, unfiledRecordFolder, ContentModel.ASSOC_CONTAINS, folder);
recordManagementContainerType.onCreateChildAssociation(childAssoc, true);
verify(mockedNodeService).setType(folder, TYPE_UNFILED_RECORD_FOLDER);
}
/**
@@ -84,38 +171,33 @@ public class RecordsManagementContainerTypeUnitTest extends BaseUnitTest
{
NodeRef rmContainer = generateNodeRef();
when(mockedNodeService.getType(rmContainer)).thenReturn(RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER);
when(mockedDictionaryService.isSubClass(RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER, TYPE_FILE_PLAN)).thenReturn(false);
return rmContainer;
}
/**
* Generates a folder subtype node
* Generates a non RM folder subtype node
* @return reference to the created folder
*/
private NodeRef generateNonRmFolderSubtypeNode()
{
NodeRef folder = generateNodeRef();
QName folderSubtype = QName.createQName("test", "folderSubtype");
when(mockedDictionaryService.isSubClass(folderSubtype, ContentModel.TYPE_FOLDER)).thenReturn(true);
when(mockedDictionaryService.isSubClass(folderSubtype, ContentModel.TYPE_SYSTEM_FOLDER)).thenReturn(false);
when(mockedNodeService.getType(folder)).thenReturn(folderSubtype);
when(mockedNodeService.exists(folder)).thenReturn(true);
when(mockedNodeService.hasAspect(folder, ASPECT_FILE_PLAN_COMPONENT)).thenReturn(false);
return folder;
NodeRef nonRmFolder = generateNodeRef();
when(mockedNodeService.getType(nonRmFolder)).thenReturn(TestModel.NOT_RM_FOLDER_TYPE);
when(mockedNodeService.exists(nonRmFolder)).thenReturn(true);
when(mockedNodeService.hasAspect(nonRmFolder, ASPECT_FILE_PLAN_COMPONENT)).thenReturn(false);
return nonRmFolder;
}
/**
* Generates a folder node
* Generates a non RM folder node
* @return reference to the created folder
*/
private NodeRef generateNonRmFolderNode()
{
NodeRef nonRmFolder = generateNodeRef();
when(mockedDictionaryService.isSubClass(TestModel.NOT_RM_FOLDER_TYPE, ContentModel.TYPE_FOLDER)).thenReturn(true);
when(mockedNodeService.getType(nonRmFolder)).thenReturn(TestModel.NOT_RM_FOLDER_TYPE);
when(mockedNodeService.exists(nonRmFolder)).thenReturn(true);
when(mockedNodeService.hasAspect(nonRmFolder, ContentModel.ASPECT_HIDDEN)).thenReturn(false);
when(mockedNodeService.hasAspect(nonRmFolder, ASPECT_FILE_PLAN_COMPONENT)).thenReturn(false);
return nonRmFolder;
NodeRef regularFolder = generateNodeRef();
when(mockedNodeService.getType(regularFolder)).thenReturn(ContentModel.TYPE_FOLDER);
when(mockedNodeService.exists(regularFolder)).thenReturn(true);
when(mockedNodeService.hasAspect(regularFolder, ASPECT_FILE_PLAN_COMPONENT)).thenReturn(false);
return regularFolder;
}
}