mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-3216 - added unit test
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
<!-- Extend Imap Service -->
|
<!-- Extend Imap Service -->
|
||||||
<bean id="rm.imapService" abstract="true" class="org.alfresco.repo.imap.ExtendedImapServiceImpl">
|
<bean id="rm.imapService" abstract="true" class="org.alfresco.repo.imap.ExtendedImapServiceImpl">
|
||||||
<property name="dictionaryService" ref="DictionaryService"/>
|
<property name="dictionaryService" ref="DictionaryService"/>
|
||||||
|
<property name="authenticationUtil" ref="AuthenticationUtil"/>
|
||||||
</bean>
|
</bean>
|
||||||
<bean class="org.alfresco.util.BeanExtender">
|
<bean class="org.alfresco.util.BeanExtender">
|
||||||
<property name="beanName" value="imapService" />
|
<property name="beanName" value="imapService" />
|
||||||
|
@@ -28,7 +28,7 @@ package org.alfresco.repo.imap;
|
|||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.repo.policy.BehaviourFilter;
|
import org.alfresco.repo.policy.BehaviourFilter;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||||
import org.alfresco.repo.site.SiteModel;
|
import org.alfresco.repo.site.SiteModel;
|
||||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||||
@@ -47,6 +47,7 @@ public class ExtendedImapServiceImpl extends ImapServiceImpl
|
|||||||
private NodeService nodeService;
|
private NodeService nodeService;
|
||||||
private BehaviourFilter policyBehaviourFilter;
|
private BehaviourFilter policyBehaviourFilter;
|
||||||
private DictionaryService dictionaryService;
|
private DictionaryService dictionaryService;
|
||||||
|
private AuthenticationUtil authenticationUtil;
|
||||||
|
|
||||||
public void setDictionaryService(DictionaryService dictionaryService)
|
public void setDictionaryService(DictionaryService dictionaryService)
|
||||||
{
|
{
|
||||||
@@ -65,11 +66,11 @@ public class ExtendedImapServiceImpl extends ImapServiceImpl
|
|||||||
super.setNodeService(nodeService);
|
super.setNodeService(nodeService);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
/**
|
/**
|
||||||
* Overwrites the core functionality so we can list RM files in IMAP
|
* Overwrites the core functionality so we can list RM files in IMAP
|
||||||
* @see https://issues.alfresco.com/jira/browse/RM-3216
|
* @see https://issues.alfresco.com/jira/browse/RM-3216
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public String getPathFromSites(final NodeRef ref)
|
public String getPathFromSites(final NodeRef ref)
|
||||||
{
|
{
|
||||||
return doAsSystem(new RunAsWork<String>()
|
return doAsSystem(new RunAsWork<String>()
|
||||||
@@ -97,7 +98,7 @@ public class ExtendedImapServiceImpl extends ImapServiceImpl
|
|||||||
policyBehaviourFilter.disableBehaviour(ContentModel.ASPECT_VERSIONABLE);
|
policyBehaviourFilter.disableBehaviour(ContentModel.ASPECT_VERSIONABLE);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return AuthenticationUtil.runAs(work, AuthenticationUtil.getSystemUserName());
|
return authenticationUtil.runAsSystem(work);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@@ -0,0 +1,103 @@
|
|||||||
|
package org.alfresco.repo.imap;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
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.MockAuthenticationUtilHelper;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil;
|
||||||
|
import org.alfresco.repo.policy.BehaviourFilter;
|
||||||
|
import org.alfresco.repo.site.SiteModel;
|
||||||
|
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||||
|
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
|
import org.alfresco.service.cmr.repository.StoreRef;
|
||||||
|
import org.alfresco.service.namespace.QName;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.springframework.extensions.webscripts.GUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit test for ExtendedImapServiceImpl
|
||||||
|
* @author Ana Bozianu
|
||||||
|
*/
|
||||||
|
public class ExtendedImapServiceImplUnitTest
|
||||||
|
{
|
||||||
|
/* service mocks */
|
||||||
|
private @Mock NodeService mockedNodeService;
|
||||||
|
private @Mock BehaviourFilter mockedPolicyBehaviourFilter;
|
||||||
|
private @Mock DictionaryService mockedDictionaryService;
|
||||||
|
private @Mock AuthenticationUtil mockedAuthenticationUtil;
|
||||||
|
|
||||||
|
/* test instance of extended IMAP service implementation */
|
||||||
|
private @InjectMocks ExtendedImapServiceImpl extendedImapServiceImpl;
|
||||||
|
|
||||||
|
/* test data */
|
||||||
|
private NodeRef rmSite = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, GUID.generate());
|
||||||
|
private final String RM_SITE_NAME = "RM";
|
||||||
|
private NodeRef rmFilePlan = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, GUID.generate());
|
||||||
|
private final String RM_FILEPLAN_NAME = "fileplan";
|
||||||
|
private NodeRef rmCategory = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, GUID.generate());
|
||||||
|
private final String RM_CATEGORY_NAME = "C1";
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup()
|
||||||
|
{
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
// setup mocked authentication util
|
||||||
|
MockAuthenticationUtilHelper.setup(mockedAuthenticationUtil);
|
||||||
|
|
||||||
|
// node names
|
||||||
|
when(mockedNodeService.getProperty(rmSite, ContentModel.PROP_NAME)).thenReturn(RM_SITE_NAME);
|
||||||
|
when(mockedNodeService.getProperty(rmCategory, ContentModel.PROP_NAME)).thenReturn(RM_CATEGORY_NAME);
|
||||||
|
when(mockedNodeService.getProperty(rmFilePlan, ContentModel.PROP_NAME)).thenReturn(RM_FILEPLAN_NAME);
|
||||||
|
|
||||||
|
// node types
|
||||||
|
when(mockedNodeService.getType(rmSite)).thenReturn(RecordsManagementModel.TYPE_RM_SITE);
|
||||||
|
when(mockedNodeService.getType(rmFilePlan)).thenReturn(RecordsManagementModel.TYPE_FILE_PLAN);
|
||||||
|
when(mockedNodeService.getType(rmCategory)).thenReturn(RecordsManagementModel.TYPE_RECORD_CATEGORY);
|
||||||
|
|
||||||
|
// type hierarchy
|
||||||
|
when(mockedDictionaryService.isSubClass(RecordsManagementModel.TYPE_RM_SITE, SiteModel.TYPE_SITE)).thenReturn(true);
|
||||||
|
when(mockedDictionaryService.isSubClass(RecordsManagementModel.TYPE_FILE_PLAN, SiteModel.TYPE_SITE)).thenReturn(false);
|
||||||
|
when(mockedDictionaryService.isSubClass(RecordsManagementModel.TYPE_RECORD_CATEGORY, SiteModel.TYPE_SITE)).thenReturn(false);
|
||||||
|
|
||||||
|
// node associations
|
||||||
|
ChildAssociationRef filePlanParentAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, rmSite, QName.createQName(GUID.generate()), rmFilePlan);
|
||||||
|
when(mockedNodeService.getPrimaryParent(rmFilePlan)).thenReturn(filePlanParentAssoc);
|
||||||
|
|
||||||
|
ChildAssociationRef categoryParentAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, rmFilePlan, QName.createQName(GUID.generate()), rmCategory);
|
||||||
|
when(mockedNodeService.getPrimaryParent(rmCategory)).thenReturn(categoryParentAssoc);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* given the method is called on the rm site node
|
||||||
|
* check if the result is the site name
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGetPathFromRMSite()
|
||||||
|
{
|
||||||
|
String rmSitePath = extendedImapServiceImpl.getPathFromSites(rmSite);
|
||||||
|
Assert.assertEquals("Incorrect return value", RM_SITE_NAME.toLowerCase(), rmSitePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* given the method is called on a rm category
|
||||||
|
* check if the result is the full path relative to the rm site
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGetPathFromRMCategory()
|
||||||
|
{
|
||||||
|
String rmCategoryPath = extendedImapServiceImpl.getPathFromSites(rmCategory);
|
||||||
|
Assert.assertEquals("Incorrect return value", (RM_SITE_NAME + "/" + RM_FILEPLAN_NAME + "/" + RM_CATEGORY_NAME).toLowerCase(), rmCategoryPath);
|
||||||
|
|
||||||
|
verify(extendedImapServiceImpl).getPathFromSites(rmSite);
|
||||||
|
verify(extendedImapServiceImpl).getPathFromSites(rmFilePlan);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user