Moved instanceOf method from ServiceBaseImpl class to a utility class

This commit is contained in:
cagache
2019-08-14 17:04:04 +03:00
parent 947b293c76
commit f972c54efb
14 changed files with 173 additions and 87 deletions

View File

@@ -253,6 +253,10 @@
<property name="behaviourFilter" ref="policyBehaviourFilter"/>
</bean>
<bean name="nodeTypeUtility" class="org.alfresco.module.org_alfresco_module_rm.util.NodeTypeUtility">
<property name="dictionaryService" ref="DictionaryService"/>
</bean>
<!-- Prevent ghosted records being renditioned -->
<bean id="noRenditionsForGhosts" parent="baseRenditionPreventionClass">
<constructor-arg value="rma:ghosted"/>

View File

@@ -46,6 +46,7 @@
<property name="transactionalResourceHelper" ref="rm.transactionalResourceHelper" />
<property name="renditionService" ref="RenditionService" />
<property name="contentService" ref="ContentService" />
<property name="nodeTypeUtility" ref="nodeTypeUtility" />
</bean>
<!-- Records Management Service Registry -->
@@ -870,9 +871,7 @@
<!-- Freeze Service -->
<bean id="freezeService" class="org.alfresco.module.org_alfresco_module_rm.freeze.FreezeServiceImpl">
<property name="nodeService" ref="nodeService" />
<property name="dictionaryService" ref="DictionaryService" />
<bean id="freezeService" class="org.alfresco.module.org_alfresco_module_rm.freeze.FreezeServiceImpl" parent="baseService">
<property name="filePlanService" ref="FilePlanService" />
<property name="holdService" ref="HoldService" />
</bean>
@@ -1003,10 +1002,9 @@
<!-- Record Folder Service -->
<bean id="recordFolderService" class="org.alfresco.module.org_alfresco_module_rm.recordfolder.RecordFolderServiceImpl">
<property name="nodeService" ref="NodeService"/>
<bean id="recordFolderService"
class="org.alfresco.module.org_alfresco_module_rm.recordfolder.RecordFolderServiceImpl" parent="baseService">
<property name="dispositionService" ref="DispositionService" />
<property name="dictionaryService" ref="DictionaryService" />
<property name="filePlanService" ref="FilePlanService" />
<property name="recordService" ref="RecordService" />
</bean>

View File

@@ -633,7 +633,7 @@
<property name="recordService" ref="RecordService" />
<property name="recordFolderService" ref="RecordFolderService" />
<property name="nodeService" ref="NodeService" />
<property name="dictionaryService" ref="DictionaryService" />
<property name="nodeTypeUtility" ref="nodeTypeUtility" />
</bean>
<!-- REST impl for POST Hold -->

View File

@@ -37,7 +37,7 @@ import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.hold.HoldService;
import org.alfresco.module.org_alfresco_module_rm.record.RecordService;
import org.alfresco.module.org_alfresco_module_rm.recordfolder.RecordFolderService;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.module.org_alfresco_module_rm.util.NodeTypeUtility;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.json.JSONArray;
@@ -70,8 +70,8 @@ public abstract class BaseHold extends DeclarativeWebScript
/** node service */
private NodeService nodeService;
/** Dictionary service */
private DictionaryService dictionaryService;
/** Node type utility */
private NodeTypeUtility nodeTypeUtility;
/**
* Set the hold service
@@ -108,11 +108,11 @@ public abstract class BaseHold extends DeclarativeWebScript
}
/**
* @param dictionaryService dictionary service
* @param nodeTypeUtility node type utility
*/
public void setDictionaryService(DictionaryService dictionaryService)
public void setNodeTypeUtility(NodeTypeUtility nodeTypeUtility)
{
this.dictionaryService = dictionaryService;
this.nodeTypeUtility = nodeTypeUtility;
}
/**
@@ -220,7 +220,7 @@ public abstract class BaseHold extends DeclarativeWebScript
// ensure that the node we are adding to the hold is a record or record folder or active content
if (!recordService.isRecord(nodeRef) && !recordFolderService.isRecordFolder(nodeRef) &&
!dictionaryService.isSubClass(nodeService.getType(nodeRef), ContentModel.TYPE_CONTENT))
!nodeTypeUtility.instanceOf(nodeService.getType(nodeRef), ContentModel.TYPE_CONTENT))
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Items added to a hold must be either a record, a record folder or active content.");
}

View File

@@ -0,0 +1,89 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2019 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* -
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* -
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.module.org_alfresco_module_rm.util;
import java.util.Map;
import java.util.WeakHashMap;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.ParameterCheck;
/**
* Utility class to check if a node type is instance of another type
*
* @author Claudia Agache
* @since 3.2
*/
public class NodeTypeUtility
{
/** Dictionary service */
private DictionaryService dictionaryService;
private static Map<String, Boolean> instanceOfCache = new WeakHashMap<>();
/**
* @param dictionaryService dictionary service
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
/**
* Utility method to quickly determine whether one class is equal to or sub of another.
*
* @param className class name
* @param ofClassName class name to check against
* @return boolean true if equal to or sub, false otherwise
*/
public boolean instanceOf(QName className, QName ofClassName)
{
ParameterCheck.mandatory("className", className);
ParameterCheck.mandatory("ofClassName", ofClassName);
boolean result = false;
String key = className.toString() + "|" + ofClassName.toString();
if (instanceOfCache.containsKey(key))
{
result = instanceOfCache.get(key);
}
else
{
if (ofClassName.equals(className) ||
dictionaryService.isSubClass(className, ofClassName))
{
result = true;
}
instanceOfCache.put(key, result);
}
return result;
}
}

View File

@@ -29,7 +29,6 @@ package org.alfresco.module.org_alfresco_module_rm.util;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanComponentKind;
@@ -80,6 +79,9 @@ public class ServiceBaseImpl implements RecordsManagementModel, ApplicationConte
/** Content service */
protected ContentService contentService;
/** Node type utility */
protected NodeTypeUtility nodeTypeUtility;
/**
* @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
*/
@@ -121,6 +123,14 @@ public class ServiceBaseImpl implements RecordsManagementModel, ApplicationConte
this.authenticationUtil = authenticationUtil;
}
/**
* @param nodeTypeUtility node type utility
*/
public void setNodeTypeUtility(NodeTypeUtility nodeTypeUtility)
{
this.nodeTypeUtility = nodeTypeUtility;
}
/**
* @param transactionalResourceHelper transactional resource helper
*/
@@ -470,8 +480,6 @@ public class ServiceBaseImpl implements RecordsManagementModel, ApplicationConte
return instanceOf(className, ofClassName);
}
private static Map<String, Boolean> instanceOfCache = new WeakHashMap<>();
/**
* Utility method to quickly determine whether one class is equal to or sub of another.
*
@@ -481,28 +489,7 @@ public class ServiceBaseImpl implements RecordsManagementModel, ApplicationConte
*/
protected boolean instanceOf(QName className, QName ofClassName)
{
ParameterCheck.mandatory("className", className);
ParameterCheck.mandatory("ofClassName", ofClassName);
boolean result = false;
String key = className.toString() + "|" + ofClassName.toString();
if (instanceOfCache.containsKey(key))
{
result = instanceOfCache.get(key);
}
else
{
if (ofClassName.equals(className) ||
dictionaryService.isSubClass(className, ofClassName))
{
result = true;
}
instanceOfCache.put(key, result);
}
return result;
return nodeTypeUtility.instanceOf(className, ofClassName);
}
/**

View File

@@ -114,7 +114,7 @@ public class HoldServiceImplUnitTest extends BaseUnitTest
activeContent = generateNodeRef();
QName contentSubtype = QName.createQName("contentSubtype", "contentSubtype");
when(mockedNodeService.getType(activeContent)).thenReturn(contentSubtype);
when(mockedDictionaryService.isSubClass(contentSubtype, ContentModel.TYPE_CONTENT)).thenReturn(true);
when(mockedNodeTypeUtility.instanceOf(contentSubtype, ContentModel.TYPE_CONTENT)).thenReturn(true);
// setup interactions
doReturn(holdContainer).when(mockedFilePlanService).getHoldContainer(filePlan);

View File

@@ -34,7 +34,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.module.org_alfresco_module_rm.util.NodeTypeUtility;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
@@ -62,7 +62,7 @@ public class FrozenAspectUnitTest
private ChildAssociationRef mockChildAssociationRef;
@Mock
private DictionaryService mockDictionaryService;
private NodeTypeUtility mockedNodeTypeUtility;
@InjectMocks
private FrozenAspect frozenAspect;
@@ -103,6 +103,7 @@ public class FrozenAspectUnitTest
{
when(mockNodeService.hasAspect(content, ASPECT_RECORD)).thenReturn(false);
when(mockNodeService.getType(content)).thenReturn(ContentModel.TYPE_CONTENT);
when(mockedNodeTypeUtility.instanceOf(mockNodeService.getType(content), ContentModel.TYPE_CONTENT)).thenReturn(true);
when(mockNodeService.getPrimaryParent(content)).thenReturn(mockChildAssociationRef);
when(mockChildAssociationRef.getParentRef()).thenReturn(folder);
frozenAspect.onRemoveAspect(content, null);
@@ -117,7 +118,7 @@ public class FrozenAspectUnitTest
{
when(mockNodeService.hasAspect(content, ASPECT_RECORD)).thenReturn(false);
when(mockNodeService.getType(content)).thenReturn(ContentModel.TYPE_FOLDER);
when(mockDictionaryService.isSubClass(ContentModel.TYPE_FOLDER, ContentModel.TYPE_CONTENT)).thenReturn(false);
when(mockedNodeTypeUtility.instanceOf(ContentModel.TYPE_FOLDER, ContentModel.TYPE_CONTENT)).thenReturn(false);
frozenAspect.onRemoveAspect(content, null);
verify(mockNodeService, times(0)).setProperty(folder, PROP_HELD_CHILDREN_COUNT, 0);
}

View File

@@ -57,7 +57,7 @@ public class HoldContainerTypeUnitTest extends BaseUnitTest
public void testAddNonHoldTypeToHoldContainer()
{
QName type = AlfMock.generateQName();
when(mockedDictionaryService.isSubClass(type, TYPE_HOLD)).thenReturn(false);
when(mockedNodeTypeUtility.instanceOf(type, TYPE_HOLD)).thenReturn(false);
NodeRef nodeRef= AlfMock.generateNodeRef(mockedNodeService, type);
NodeRef holdContainer = generateNodeRef(TYPE_HOLD_CONTAINER, true);
@@ -75,7 +75,7 @@ public class HoldContainerTypeUnitTest extends BaseUnitTest
public void testAddHoldTypeToHoldContainer()
{
QName type = AlfMock.generateQName();
when(mockedDictionaryService.isSubClass(type, TYPE_HOLD)).thenReturn(true);
when(mockedNodeTypeUtility.instanceOf(type, TYPE_HOLD)).thenReturn(true);
NodeRef holdFolder= AlfMock.generateNodeRef(mockedNodeService, type);
NodeRef holdContainer = generateNodeRef(TYPE_HOLD_CONTAINER, true);

View File

@@ -79,7 +79,7 @@ public class RecordFolderTypeUnitTest extends BaseUnitTest
{
NodeRef recordFolderNodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_RECORD_FOLDER);
QName type = AlfMock.generateQName();
when(mockedDictionaryService.isSubClass(type, TYPE_TRANSFER)).thenReturn(true);
when(mockedNodeTypeUtility.instanceOf(type, TYPE_TRANSFER)).thenReturn(true);
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, type, true);
ChildAssociationRef childAssocRef = generateChildAssociationRef(recordFolderNodeRef, nodeRef);
recordFolderType.onCreateChildAssociation(childAssocRef, true);
@@ -94,7 +94,7 @@ public class RecordFolderTypeUnitTest extends BaseUnitTest
{
NodeRef recordFolderNodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_RECORD_FOLDER);
QName type = AlfMock.generateQName();
when(mockedDictionaryService.isSubClass(type, TYPE_RECORD_FOLDER)).thenReturn(true);
when(mockedNodeTypeUtility.instanceOf(type, TYPE_RECORD_FOLDER)).thenReturn(true);
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, type, true);
ChildAssociationRef childAssocRef = generateChildAssociationRef(recordFolderNodeRef, nodeRef);
recordFolderType.onCreateChildAssociation(childAssocRef, true);
@@ -109,7 +109,7 @@ public class RecordFolderTypeUnitTest extends BaseUnitTest
{
NodeRef recordFolderNodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_RECORD_FOLDER);
QName type = AlfMock.generateQName();
when(mockedDictionaryService.isSubClass(type, TYPE_RECORDS_MANAGEMENT_CONTAINER)).thenReturn(true);
when(mockedNodeTypeUtility.instanceOf(type, TYPE_RECORDS_MANAGEMENT_CONTAINER)).thenReturn(true);
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, type, true);
ChildAssociationRef childAssocRef = generateChildAssociationRef(recordFolderNodeRef, nodeRef);
recordFolderType.onCreateChildAssociation(childAssocRef, true);
@@ -124,7 +124,7 @@ public class RecordFolderTypeUnitTest extends BaseUnitTest
{
NodeRef recordFolderNodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_RECORD_FOLDER);
QName type = AlfMock.generateQName();
when(mockedDictionaryService.isSubClass(type, TYPE_FOLDER)).thenReturn(true);
when(mockedNodeTypeUtility.instanceOf(type, TYPE_FOLDER)).thenReturn(true);
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, type, true);
ChildAssociationRef childAssocRef = generateChildAssociationRef(recordFolderNodeRef, nodeRef);
recordFolderType.onCreateChildAssociation(childAssocRef, true);
@@ -139,7 +139,7 @@ public class RecordFolderTypeUnitTest extends BaseUnitTest
{
NodeRef recordFolderNodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_RECORD_FOLDER);
QName type = AlfMock.generateQName();
when(mockedDictionaryService.isSubClass(type, TYPE_FOLDER)).thenReturn(false);
when(mockedNodeTypeUtility.instanceOf(type, TYPE_FOLDER)).thenReturn(false);
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, type, true);
ChildAssociationRef childAssocRef = generateChildAssociationRef(recordFolderNodeRef, nodeRef);
recordFolderType.onCreateChildAssociation(childAssocRef, true);
@@ -153,7 +153,7 @@ public class RecordFolderTypeUnitTest extends BaseUnitTest
{
NodeRef recordFolderNodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_RECORD_FOLDER);
QName type = AlfMock.generateQName();
when(mockedDictionaryService.isSubClass(type, TYPE_CONTENT)).thenReturn(true);
when(mockedNodeTypeUtility.instanceOf(type, TYPE_CONTENT)).thenReturn(true);
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, type, true);
ChildAssociationRef childAssocRef = generateChildAssociationRef(recordFolderNodeRef, nodeRef);
recordFolderType.onCreateChildAssociation(childAssocRef, true);
@@ -168,8 +168,8 @@ public class RecordFolderTypeUnitTest extends BaseUnitTest
{
NodeRef recordFolderNodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_RECORD_FOLDER);
QName type = AlfMock.generateQName();
when(mockedDictionaryService.isSubClass(type, TYPE_CONTENT)).thenReturn(false);
when(mockedDictionaryService.isSubClass(type, TYPE_FOLDER)).thenReturn(false);
when(mockedNodeTypeUtility.instanceOf(type, TYPE_CONTENT)).thenReturn(false);
when(mockedNodeTypeUtility.instanceOf(type, TYPE_FOLDER)).thenReturn(false);
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, type, true);
ChildAssociationRef childAssocRef = generateChildAssociationRef(recordFolderNodeRef, nodeRef);
recordFolderType.onCreateChildAssociation(childAssocRef, true);
@@ -184,7 +184,7 @@ public class RecordFolderTypeUnitTest extends BaseUnitTest
{
NodeRef recordFolderNodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_RECORD_FOLDER);
QName type = AlfMock.generateQName();
when(mockedDictionaryService.isSubClass(type, TYPE_FOLDER)).thenReturn(true);
when(mockedNodeTypeUtility.instanceOf(type, TYPE_FOLDER)).thenReturn(true);
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, type, true);
ChildAssociationRef childAssocRef = generateChildAssociationRef(recordFolderNodeRef, nodeRef);
recordFolderType.onCreateChildAssociationOnCommit(childAssocRef, true);
@@ -201,7 +201,7 @@ public class RecordFolderTypeUnitTest extends BaseUnitTest
QName type = AlfMock.generateQName();
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, type, true);
when(mockedDictionaryService.isSubClass(type, TYPE_FOLDER)).thenReturn(true);
when(mockedNodeTypeUtility.instanceOf(type, TYPE_FOLDER)).thenReturn(true);
when(mockedNodeService.hasAspect(nodeRef, ASPECT_HIDDEN)).thenReturn(true);
ChildAssociationRef mockedPrimaryParentAssoc = mock(ChildAssociationRef.class);
@@ -222,7 +222,7 @@ public class RecordFolderTypeUnitTest extends BaseUnitTest
QName type = AlfMock.generateQName();
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, type, true);
when(mockedDictionaryService.isSubClass(type, TYPE_FOLDER)).thenReturn(false);
when(mockedNodeTypeUtility.instanceOf(type, TYPE_FOLDER)).thenReturn(false);
ChildAssociationRef mockedPrimaryParentAssoc = mock(ChildAssociationRef.class);
when(mockedNodeService.getPrimaryParent(nodeRef)).thenReturn(mockedPrimaryParentAssoc);

View File

@@ -59,9 +59,9 @@ public class UnfiledRecordContainerTypeUnitTest extends BaseUnitTest
public void testAddNonAcceptedTypeToUnfiledRecordContainer()
{
QName type = AlfMock.generateQName();
when(mockedDictionaryService.isSubClass(type, TYPE_UNFILED_RECORD_FOLDER)).thenReturn(false);
when(mockedDictionaryService.isSubClass(type, ContentModel.TYPE_CONTENT)).thenReturn(false);
when(mockedDictionaryService.isSubClass(type, TYPE_NON_ELECTRONIC_DOCUMENT)).thenReturn(false);
when(mockedNodeTypeUtility.instanceOf(type, TYPE_UNFILED_RECORD_FOLDER)).thenReturn(false);
when(mockedNodeTypeUtility.instanceOf(type, ContentModel.TYPE_CONTENT)).thenReturn(false);
when(mockedNodeTypeUtility.instanceOf(type, TYPE_NON_ELECTRONIC_DOCUMENT)).thenReturn(false);
NodeRef nodeRef= AlfMock.generateNodeRef(mockedNodeService, type);
@@ -80,9 +80,9 @@ public class UnfiledRecordContainerTypeUnitTest extends BaseUnitTest
public void testAddUnfiledRecordFolderTypeToUnfiledRecordContainer()
{
QName type = AlfMock.generateQName();
when(mockedDictionaryService.isSubClass(type, TYPE_UNFILED_RECORD_FOLDER)).thenReturn(true);
when(mockedDictionaryService.isSubClass(type, ContentModel.TYPE_CONTENT)).thenReturn(false);
when(mockedDictionaryService.isSubClass(type, TYPE_NON_ELECTRONIC_DOCUMENT)).thenReturn(false);
when(mockedNodeTypeUtility.instanceOf(type, TYPE_UNFILED_RECORD_FOLDER)).thenReturn(true);
when(mockedNodeTypeUtility.instanceOf(type, ContentModel.TYPE_CONTENT)).thenReturn(false);
when(mockedNodeTypeUtility.instanceOf(type, TYPE_NON_ELECTRONIC_DOCUMENT)).thenReturn(false);
NodeRef nodeRef= AlfMock.generateNodeRef(mockedNodeService, type);
@@ -101,9 +101,9 @@ public class UnfiledRecordContainerTypeUnitTest extends BaseUnitTest
public void testAddContentTypeToUnfiledRecordContainer()
{
QName type = AlfMock.generateQName();
when(mockedDictionaryService.isSubClass(type, TYPE_UNFILED_RECORD_FOLDER)).thenReturn(false);
when(mockedDictionaryService.isSubClass(type, ContentModel.TYPE_CONTENT)).thenReturn(true);
when(mockedDictionaryService.isSubClass(type, TYPE_NON_ELECTRONIC_DOCUMENT)).thenReturn(false);
when(mockedNodeTypeUtility.instanceOf(type, TYPE_UNFILED_RECORD_FOLDER)).thenReturn(false);
when(mockedNodeTypeUtility.instanceOf(type, ContentModel.TYPE_CONTENT)).thenReturn(true);
when(mockedNodeTypeUtility.instanceOf(type, TYPE_NON_ELECTRONIC_DOCUMENT)).thenReturn(false);
NodeRef nodeRef= AlfMock.generateNodeRef(mockedNodeService, type);
@@ -122,9 +122,9 @@ public class UnfiledRecordContainerTypeUnitTest extends BaseUnitTest
public void testNonElectronicDocumentTypeToUnfiledRecordContainer()
{
QName type = AlfMock.generateQName();
when(mockedDictionaryService.isSubClass(type, TYPE_UNFILED_RECORD_FOLDER)).thenReturn(false);
when(mockedDictionaryService.isSubClass(type, ContentModel.TYPE_CONTENT)).thenReturn(false);
when(mockedDictionaryService.isSubClass(type, TYPE_NON_ELECTRONIC_DOCUMENT)).thenReturn(true);
when(mockedNodeTypeUtility.instanceOf(type, TYPE_UNFILED_RECORD_FOLDER)).thenReturn(false);
when(mockedNodeTypeUtility.instanceOf(type, ContentModel.TYPE_CONTENT)).thenReturn(false);
when(mockedNodeTypeUtility.instanceOf(type, TYPE_NON_ELECTRONIC_DOCUMENT)).thenReturn(true);
NodeRef nodeRef= AlfMock.generateNodeRef(mockedNodeService, type);

View File

@@ -59,9 +59,9 @@ public class UnfiledRecordFolderTypeUnitTest extends BaseUnitTest
public void testAddNonAcceptedTypeToUnfiledRecordFolder()
{
QName type = AlfMock.generateQName();
when(mockedDictionaryService.isSubClass(type, TYPE_UNFILED_RECORD_FOLDER)).thenReturn(false);
when(mockedDictionaryService.isSubClass(type, ContentModel.TYPE_CONTENT)).thenReturn(false);
when(mockedDictionaryService.isSubClass(type, TYPE_NON_ELECTRONIC_DOCUMENT)).thenReturn(false);
when(mockedNodeTypeUtility.instanceOf(type, TYPE_UNFILED_RECORD_FOLDER)).thenReturn(false);
when(mockedNodeTypeUtility.instanceOf(type, ContentModel.TYPE_CONTENT)).thenReturn(false);
when(mockedNodeTypeUtility.instanceOf(type, TYPE_NON_ELECTRONIC_DOCUMENT)).thenReturn(false);
NodeRef nodeRef= AlfMock.generateNodeRef(mockedNodeService, type);
@@ -80,9 +80,9 @@ public class UnfiledRecordFolderTypeUnitTest extends BaseUnitTest
public void testAddUnfiledRecordFolderTypeToUnfiledRecordFolder()
{
QName type = AlfMock.generateQName();
when(mockedDictionaryService.isSubClass(type, TYPE_UNFILED_RECORD_FOLDER)).thenReturn(true);
when(mockedDictionaryService.isSubClass(type, ContentModel.TYPE_CONTENT)).thenReturn(false);
when(mockedDictionaryService.isSubClass(type, TYPE_NON_ELECTRONIC_DOCUMENT)).thenReturn(false);
when(mockedNodeTypeUtility.instanceOf(type, TYPE_UNFILED_RECORD_FOLDER)).thenReturn(true);
when(mockedNodeTypeUtility.instanceOf(type, ContentModel.TYPE_CONTENT)).thenReturn(false);
when(mockedNodeTypeUtility.instanceOf(type, TYPE_NON_ELECTRONIC_DOCUMENT)).thenReturn(false);
NodeRef nodeRef= AlfMock.generateNodeRef(mockedNodeService, type);
@@ -101,9 +101,9 @@ public class UnfiledRecordFolderTypeUnitTest extends BaseUnitTest
public void testAddContentTypeToUnfiledRecordFolder()
{
QName type = AlfMock.generateQName();
when(mockedDictionaryService.isSubClass(type, TYPE_UNFILED_RECORD_FOLDER)).thenReturn(false);
when(mockedDictionaryService.isSubClass(type, ContentModel.TYPE_CONTENT)).thenReturn(true);
when(mockedDictionaryService.isSubClass(type, TYPE_NON_ELECTRONIC_DOCUMENT)).thenReturn(false);
when(mockedNodeTypeUtility.instanceOf(type, TYPE_UNFILED_RECORD_FOLDER)).thenReturn(false);
when(mockedNodeTypeUtility.instanceOf(type, ContentModel.TYPE_CONTENT)).thenReturn(true);
when(mockedNodeTypeUtility.instanceOf(type, TYPE_NON_ELECTRONIC_DOCUMENT)).thenReturn(false);
NodeRef nodeRef= AlfMock.generateNodeRef(mockedNodeService, type);
@@ -122,9 +122,9 @@ public class UnfiledRecordFolderTypeUnitTest extends BaseUnitTest
public void testNonElectronicDocumentTypeToUnfiledRecordFolder()
{
QName type = AlfMock.generateQName();
when(mockedDictionaryService.isSubClass(type, TYPE_UNFILED_RECORD_FOLDER)).thenReturn(false);
when(mockedDictionaryService.isSubClass(type, ContentModel.TYPE_CONTENT)).thenReturn(false);
when(mockedDictionaryService.isSubClass(type, TYPE_NON_ELECTRONIC_DOCUMENT)).thenReturn(true);
when(mockedNodeTypeUtility.instanceOf(type, TYPE_UNFILED_RECORD_FOLDER)).thenReturn(false);
when(mockedNodeTypeUtility.instanceOf(type, ContentModel.TYPE_CONTENT)).thenReturn(false);
when(mockedNodeTypeUtility.instanceOf(type, TYPE_NON_ELECTRONIC_DOCUMENT)).thenReturn(true);
NodeRef nodeRef= AlfMock.generateNodeRef(mockedNodeService, type);

View File

@@ -58,6 +58,7 @@ import org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService;
import org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService;
import org.alfresco.module.org_alfresco_module_rm.util.AlfrescoTransactionSupport;
import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil;
import org.alfresco.module.org_alfresco_module_rm.util.NodeTypeUtility;
import org.alfresco.module.org_alfresco_module_rm.util.TransactionalResourceHelper;
import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionService;
import org.alfresco.repo.policy.BehaviourFilter;
@@ -151,6 +152,8 @@ public class BaseUnitTest implements RecordsManagementModel, ContentModel
/** application context mock */
@Mock(name="applicationContext") protected ApplicationContext mockedApplicationContext;
@Mock protected NodeTypeUtility mockedNodeTypeUtility;
/** expected exception rule */
@Rule
public ExpectedException exception = ExpectedException.none();
@@ -313,6 +316,7 @@ public class BaseUnitTest implements RecordsManagementModel, ContentModel
if (type != null)
{
when(mockedNodeService.getType(eq(nodeRef))).thenReturn(type);
when(mockedNodeTypeUtility.instanceOf(type, type)).thenReturn(true);
}
return nodeRef;
}

View File

@@ -35,7 +35,6 @@ import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.junit.Before;
@@ -55,10 +54,14 @@ public class ServiceBaseImplUnitTest
{
@InjectMocks private ServiceBaseImpl serviceBase;
@Mock(name="nodeService") private NodeService mockedNodeService;
@Mock(name="dictionaryService") private DictionaryService mockedDictionaryService;
@Mock(name="transactionalResourceHelper") private TransactionalResourceHelper mockedTransactionalResourceHelper;
@Mock(name="applicationContext") protected ApplicationContext mockedApplicationContext;
@Mock (name = "nodeService")
private NodeService mockedNodeService;
@Mock (name = "transactionalResourceHelper")
private TransactionalResourceHelper mockedTransactionalResourceHelper;
@Mock (name = "applicationContext")
protected ApplicationContext mockedApplicationContext;
@Mock (name = "nodeTypeUtility")
protected NodeTypeUtility mockedNodeTypeUtility;
@Mock private Map<Object, Object> mockedCache;
/**
@@ -85,7 +88,7 @@ public class ServiceBaseImplUnitTest
when(mockedNodeService.getType(nodeRef))
.thenReturn(ContentModel.TYPE_CONTENT);
when(mockedDictionaryService.isSubClass(ContentModel.TYPE_CONTENT, RecordsManagementModel.TYPE_FILE_PLAN))
when(mockedNodeTypeUtility.instanceOf(ContentModel.TYPE_CONTENT, RecordsManagementModel.TYPE_FILE_PLAN))
.thenReturn(false);
when(mockedTransactionalResourceHelper.getMap("rm.servicebase.getFilePlan"))
.thenReturn(mockedCache);