RM-4619 - fixed unit tests

This commit is contained in:
Ana Bozianu
2017-01-26 12:16:54 +02:00
parent f1d6e5a7b6
commit df919acfc7
3 changed files with 55 additions and 52 deletions

View File

@@ -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

View File

@@ -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);
}
}

View File

@@ -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());
}
/**