mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-4619 - fixed unit tests
This commit is contained in:
@@ -27,11 +27,13 @@
|
|||||||
|
|
||||||
package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
|
package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
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.module.org_alfresco_module_rm.test.util.BaseUnitTest;
|
||||||
import org.alfresco.repo.node.integrity.IntegrityException;
|
import org.alfresco.repo.node.integrity.IntegrityException;
|
||||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||||
@@ -180,6 +182,29 @@ public class FilePlanTypeUnitTest extends BaseUnitTest
|
|||||||
filePlanType.onCreateChildAssociation(childAssoc, true);
|
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
|
* 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
|
* @param childType the node type of the child to be created
|
||||||
|
@@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
|
package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock;
|
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);
|
ChildAssociationRef childAssocRef = generateChildAssociationRef(recordCategoryNodeRef, nodeRef);
|
||||||
recordCategoryType.onCreateChildAssociation(childAssocRef, true);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -26,13 +26,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
|
package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import org.alfresco.error.AlfrescoRuntimeException;
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
|
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
|
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
|
||||||
@@ -52,33 +50,10 @@ public class RecordsManagementContainerTypeUnitTest extends BaseUnitTest
|
|||||||
/** test object */
|
/** test object */
|
||||||
private @InjectMocks RecordsManagementContainerType recordManagementContainerType;
|
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
|
* Having the Unfilled Record container and a folder having the aspect ASPECT_HIDDEN
|
||||||
* When adding a child association between the folder and the container
|
* 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
|
@Test
|
||||||
public void testAddHiddenFolderToRMContainer()
|
public void testAddHiddenFolderToRMContainer()
|
||||||
@@ -93,31 +68,9 @@ public class RecordsManagementContainerTypeUnitTest extends BaseUnitTest
|
|||||||
ChildAssociationRef childAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, rmContainer, ContentModel.ASSOC_CONTAINS, rmFolder);
|
ChildAssociationRef childAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, rmContainer, ContentModel.ASSOC_CONTAINS, rmFolder);
|
||||||
recordManagementContainerType.onCreateChildAssociation(childAssoc, true);
|
recordManagementContainerType.onCreateChildAssociation(childAssoc, true);
|
||||||
|
|
||||||
/* Then the node type should not be changed to TYPE_RECORD_FOLDER */
|
/* The type should not be changed and no aspects should be added */
|
||||||
verify(mockedNodeService, never()).setType(rmFolder, TYPE_RECORD_FOLDER);
|
verify(mockedNodeService, never()).setType(any(), any());
|
||||||
verify(mockedRecordFolderService, never()).setupRecordFolder(rmFolder);
|
verify(mockedNodeService, never()).addAspect(any(), any(), any());
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user