RM-4326 : added some more unit tests for RmSiteType and did some code

cleanup in this class
This commit is contained in:
Silviu Dinuta
2016-11-10 11:04:34 +02:00
parent b67a8878a9
commit 35fa9c1e0d

View File

@@ -33,7 +33,7 @@ import static org.mockito.Mockito.when;
import java.security.InvalidParameterException;
import java.util.ArrayList;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.dod5015.DOD5015Model;
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.MockAuthenticationUtilHelper;
@@ -58,7 +58,7 @@ import com.google.common.collect.Sets;
* @since 2.6
*
*/
public class RmSiteTypeUnitTest extends BaseUnitTest
public class RmSiteTypeUnitTest extends BaseUnitTest implements DOD5015Model
{
@Mock
private AuthenticationUtil mockAuthenticationUtil;
@@ -110,10 +110,10 @@ public class RmSiteTypeUnitTest extends BaseUnitTest
when(mockedSiteService.getSite(rmSiteNodeRef)).thenReturn(mockedSiteInfo);
when(mockedApplicationContext.getBean("dbNodeService")).thenReturn(mockedNodeService);
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, ContentModel.TYPE_FOLDER);
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_FOLDER);
ChildAssociationRef mockedChildAssoc = generateChildAssociationRef(rmSiteNodeRef, nodeRef);
assocs.add(mockedChildAssoc);
when(mockedNodeService.getChildAssocs(rmSiteNodeRef, Sets.newHashSet(ContentModel.TYPE_FOLDER))).thenReturn(assocs);
when(mockedNodeService.getChildAssocs(rmSiteNodeRef, Sets.newHashSet(TYPE_FOLDER))).thenReturn(assocs);
rmSiteType.onCreateChildAssociation(mockedChildAssoc, true);
}
@@ -133,17 +133,17 @@ public class RmSiteTypeUnitTest extends BaseUnitTest
when(mockedApplicationContext.getBean("dbNodeService")).thenReturn(mockedNodeService);
//create first folder
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, ContentModel.TYPE_FOLDER);
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_FOLDER);
ChildAssociationRef mockedChildAssoc = generateChildAssociationRef(rmSiteNodeRef, nodeRef);
assocs.add(mockedChildAssoc);
when(mockedNodeService.getChildAssocs(rmSiteNodeRef, Sets.newHashSet(ContentModel.TYPE_FOLDER))).thenReturn(assocs);
when(mockedNodeService.getChildAssocs(rmSiteNodeRef, Sets.newHashSet(TYPE_FOLDER))).thenReturn(assocs);
rmSiteType.onCreateChildAssociation(mockedChildAssoc, true);
//create second cm:folder
nodeRef = AlfMock.generateNodeRef(mockedNodeService, ContentModel.TYPE_FOLDER);
nodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_FOLDER);
mockedChildAssoc = generateChildAssociationRef(rmSiteNodeRef, nodeRef);
assocs.add(mockedChildAssoc);
when(mockedNodeService.getChildAssocs(rmSiteNodeRef, Sets.newHashSet(ContentModel.TYPE_FOLDER))).thenReturn(assocs);
when(mockedNodeService.getChildAssocs(rmSiteNodeRef, Sets.newHashSet(TYPE_FOLDER))).thenReturn(assocs);
rmSiteType.onCreateChildAssociation(mockedChildAssoc, true);
}
@@ -160,27 +160,27 @@ public class RmSiteTypeUnitTest extends BaseUnitTest
SiteInfo mockedSiteInfo = mock(SiteInfo.class);
when(mockedSiteService.getSite(rmSiteNodeRef)).thenReturn(mockedSiteInfo);
when(mockedApplicationContext.getBean("dbNodeService")).thenReturn(mockedNodeService);
when(mockedNodeService.getChildAssocs(rmSiteNodeRef, Sets.newHashSet(ContentModel.TYPE_FOLDER))).thenReturn(new ArrayList<ChildAssociationRef>());
when(mockedNodeService.getChildAssocs(rmSiteNodeRef, Sets.newHashSet(TYPE_FOLDER))).thenReturn(new ArrayList<ChildAssociationRef>());
//create first folder
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, ContentModel.TYPE_FOLDER);
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_FOLDER);
ChildAssociationRef mockedChildAssoc = generateChildAssociationRef(rmSiteNodeRef, nodeRef);
rmSiteType.onCreateChildAssociation(mockedChildAssoc, true);
assocs.add(mockedChildAssoc);
when(mockedNodeService.getChildAssocs(rmSiteNodeRef, Sets.newHashSet(ContentModel.TYPE_FOLDER))).thenReturn(assocs);
when(mockedNodeService.getChildAssocs(rmSiteNodeRef, Sets.newHashSet(TYPE_FOLDER))).thenReturn(assocs);
//create second cm:folder
nodeRef = AlfMock.generateNodeRef(mockedNodeService, ContentModel.TYPE_FOLDER);
nodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_FOLDER);
mockedChildAssoc = generateChildAssociationRef(rmSiteNodeRef, nodeRef);
assocs.add(mockedChildAssoc);
when(mockedNodeService.getChildAssocs(rmSiteNodeRef, Sets.newHashSet(ContentModel.TYPE_FOLDER))).thenReturn(assocs);
when(mockedNodeService.getChildAssocs(rmSiteNodeRef, Sets.newHashSet(TYPE_FOLDER))).thenReturn(assocs);
rmSiteType.onCreateChildAssociation(mockedChildAssoc, true);
//create third cm:folder
nodeRef = AlfMock.generateNodeRef(mockedNodeService, ContentModel.TYPE_FOLDER);
nodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_FOLDER);
mockedChildAssoc = generateChildAssociationRef(rmSiteNodeRef, nodeRef);
assocs.add(mockedChildAssoc);
when(mockedNodeService.getChildAssocs(rmSiteNodeRef, Sets.newHashSet(ContentModel.TYPE_FOLDER))).thenReturn(assocs);
when(mockedNodeService.getChildAssocs(rmSiteNodeRef, Sets.newHashSet(TYPE_FOLDER))).thenReturn(assocs);
rmSiteType.onCreateChildAssociation(mockedChildAssoc, true);
}
@@ -206,6 +206,23 @@ public class RmSiteTypeUnitTest extends BaseUnitTest
rmSiteType.onCreateChildAssociation(mockedChildAssoc, true);
}
/**
* Given that we try to add one dod:filePlan to standard rm site,
* Then InvalidParameterException is thrown.
*/
@Test(expected = InvalidParameterException.class)
public void testAddDODFilePlanTypeToStandardRmSite()
{
NodeRef rmSiteNodeRef = generateNodeRef(TYPE_RM_SITE, true);
SiteInfo mockedSiteInfo = mock(SiteInfo.class);
when(mockedSiteService.getSite(rmSiteNodeRef)).thenReturn(mockedSiteInfo);
when(mockedApplicationContext.getBean("dbNodeService")).thenReturn(mockedNodeService);
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_DOD_5015_FILE_PLAN);
ChildAssociationRef mockedChildAssoc = generateChildAssociationRef(rmSiteNodeRef, nodeRef);
rmSiteType.onCreateChildAssociation(mockedChildAssoc, true);
}
/**
* Given that we try to add more than one rma:filePlan to rm site,
* Then InvalidParameterException is thrown.
@@ -234,4 +251,88 @@ public class RmSiteTypeUnitTest extends BaseUnitTest
when(mockedNodeService.getChildAssocs(rmSiteNodeRef, Sets.newHashSet(TYPE_FILE_PLAN))).thenReturn(assocs);
rmSiteType.onCreateChildAssociation(mockedChildAssoc, true);
}
/**
* Given that we try to add one dod:filePlan to rm site,
* Then operation is successful.
*/
@Test
public void testAddOneDODFilePlanTypeToRmSite()
{
NodeRef rmSiteNodeRef = generateNodeRef(TYPE_DOD_5015_SITE, true);
ArrayList<ChildAssociationRef> assocs = new ArrayList<ChildAssociationRef>();
SiteInfo mockedSiteInfo = mock(SiteInfo.class);
when(mockedSiteInfo.getNodeRef()).thenReturn(rmSiteNodeRef);
when(mockedSiteService.getSite(rmSiteNodeRef)).thenReturn(mockedSiteInfo);
when(mockedApplicationContext.getBean("dbNodeService")).thenReturn(mockedNodeService);
when(mockedDictionaryService.isSubClass(TYPE_DOD_5015_SITE, TYPE_RM_SITE)).thenReturn(true);
when(mockedDictionaryService.isSubClass(TYPE_DOD_5015_FILE_PLAN, TYPE_FILE_PLAN)).thenReturn(true);
rmSiteType.registerFilePlanType(TYPE_DOD_5015_SITE, TYPE_DOD_5015_FILE_PLAN);
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_DOD_5015_FILE_PLAN);
ChildAssociationRef mockedChildAssoc = generateChildAssociationRef(rmSiteNodeRef, nodeRef);
assocs.add(mockedChildAssoc);
when(mockedNodeService.getChildAssocs(rmSiteNodeRef, Sets.newHashSet(TYPE_DOD_5015_FILE_PLAN))).thenReturn(assocs);
rmSiteType.onCreateChildAssociation(mockedChildAssoc, true);
}
/**
* Given that we try to add more than one dod:filePlan to rm site,
* Then InvalidParameterException is thrown.
*/
@Test(expected = InvalidParameterException.class)
public void testAddMoreThanOneDODFilePlanTypeToRmSite()
{
NodeRef rmSiteNodeRef = generateNodeRef(TYPE_DOD_5015_SITE, true);
ArrayList<ChildAssociationRef> assocs = new ArrayList<ChildAssociationRef>();
SiteInfo mockedSiteInfo = mock(SiteInfo.class);
when(mockedSiteInfo.getNodeRef()).thenReturn(rmSiteNodeRef);
when(mockedSiteService.getSite(rmSiteNodeRef)).thenReturn(mockedSiteInfo);
when(mockedApplicationContext.getBean("dbNodeService")).thenReturn(mockedNodeService);
when(mockedDictionaryService.isSubClass(TYPE_DOD_5015_SITE, TYPE_RM_SITE)).thenReturn(true);
when(mockedDictionaryService.isSubClass(TYPE_DOD_5015_FILE_PLAN, TYPE_FILE_PLAN)).thenReturn(true);
rmSiteType.registerFilePlanType(TYPE_DOD_5015_SITE, TYPE_DOD_5015_FILE_PLAN);
//first dod:filePlan creation
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_DOD_5015_FILE_PLAN);
ChildAssociationRef mockedChildAssoc = generateChildAssociationRef(rmSiteNodeRef, nodeRef);
assocs.add(mockedChildAssoc);
when(mockedNodeService.getChildAssocs(rmSiteNodeRef, Sets.newHashSet(TYPE_DOD_5015_FILE_PLAN))).thenReturn(assocs);
rmSiteType.onCreateChildAssociation(mockedChildAssoc, true);
//second dod:filePlan creation
nodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_DOD_5015_FILE_PLAN);
mockedChildAssoc = generateChildAssociationRef(rmSiteNodeRef, nodeRef);
assocs.add(mockedChildAssoc);
when(mockedNodeService.getChildAssocs(rmSiteNodeRef, Sets.newHashSet(TYPE_DOD_5015_FILE_PLAN))).thenReturn(assocs);
rmSiteType.onCreateChildAssociation(mockedChildAssoc, true);
}
/**
* Given that we try to add one rma:filePlan to DOD rm site,
* Then InvalidParameterException is thrown.
*/
@Test(expected = InvalidParameterException.class)
public void testAddStandardFilePlanTypeToDODRmSite()
{
NodeRef rmSiteNodeRef = generateNodeRef(TYPE_DOD_5015_SITE, true);
SiteInfo mockedSiteInfo = mock(SiteInfo.class);
when(mockedSiteInfo.getNodeRef()).thenReturn(rmSiteNodeRef);
when(mockedSiteService.getSite(rmSiteNodeRef)).thenReturn(mockedSiteInfo);
when(mockedApplicationContext.getBean("dbNodeService")).thenReturn(mockedNodeService);
when(mockedDictionaryService.isSubClass(TYPE_DOD_5015_SITE, TYPE_RM_SITE)).thenReturn(true);
when(mockedDictionaryService.isSubClass(TYPE_DOD_5015_FILE_PLAN, TYPE_FILE_PLAN)).thenReturn(true);
rmSiteType.registerFilePlanType(TYPE_DOD_5015_SITE, TYPE_DOD_5015_FILE_PLAN);
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_FILE_PLAN);
ChildAssociationRef mockedChildAssoc = generateChildAssociationRef(rmSiteNodeRef, nodeRef);
rmSiteType.onCreateChildAssociation(mockedChildAssoc, true);
}
}