RM-2130 (Check classification after method execution, filtering results where appropriate)

+review RM-94

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/DEV/ENFORCE@106552 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tuna Aksoy
2015-06-19 12:39:04 +00:00
parent d8f71fba18
commit e79b4a9d8f
3 changed files with 89 additions and 7 deletions

View File

@@ -18,10 +18,15 @@
*/
package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor;
import static com.google.common.collect.ImmutableList.copyOf;
import static com.google.common.collect.Lists.newArrayList;
import static java.util.Collections.unmodifiableCollection;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
import static org.springframework.extensions.webscripts.GUID.generate;
import java.util.ArrayList;
import org.alfresco.module.org_alfresco_module_rm.classification.ContentClassificationService;
import org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.ClassificationPostMethodInvocationException.NotSupportedClassTypeException;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
@@ -59,7 +64,6 @@ public class NodeRefPostMethodInvocationProcessorUnitTest extends BaseUnitTest
{
NodeRef nodeRef = new NodeRef(generate() + "://" + generate() + "/");
when(mockedNodeService.getType(nodeRef)).thenReturn(TYPE_CONTENT);
when(mockedDictionaryService.isSubClass(mockedNodeService.getType(nodeRef), TYPE_CONTENT)).thenReturn(true);
when(mockedContentClassificationService.hasClearance(nodeRef)).thenReturn(true);
@@ -71,7 +75,6 @@ public class NodeRefPostMethodInvocationProcessorUnitTest extends BaseUnitTest
{
NodeRef nodeRef = generateNodeRef();
when(mockedNodeService.getType(nodeRef)).thenReturn(TYPE_CONTENT);
when(mockedDictionaryService.isSubClass(mockedNodeService.getType(nodeRef), TYPE_CONTENT)).thenReturn(false);
when(mockedContentClassificationService.hasClearance(nodeRef)).thenReturn(true);
@@ -83,7 +86,6 @@ public class NodeRefPostMethodInvocationProcessorUnitTest extends BaseUnitTest
{
NodeRef nodeRef = generateNodeRef();
when(mockedNodeService.getType(nodeRef)).thenReturn(TYPE_CONTENT);
when(mockedDictionaryService.isSubClass(mockedNodeService.getType(nodeRef), TYPE_CONTENT)).thenReturn(true);
when(mockedContentClassificationService.hasClearance(nodeRef)).thenReturn(true);
@@ -95,10 +97,90 @@ public class NodeRefPostMethodInvocationProcessorUnitTest extends BaseUnitTest
{
NodeRef nodeRef = generateNodeRef();
when(mockedNodeService.getType(nodeRef)).thenReturn(TYPE_CONTENT);
when(mockedDictionaryService.isSubClass(mockedNodeService.getType(nodeRef), TYPE_CONTENT)).thenReturn(true);
when(mockedContentClassificationService.hasClearance(nodeRef)).thenReturn(false);
assertEquals(null, nodeRefPostMethodInvocationProcessor.process(nodeRef));
}
@Test
public void testCollection_bothNodesConent_userClearedForBoth()
{
NodeRef nodeRef1 = generateNodeRef();
NodeRef nodeRef2 = generateNodeRef();
ArrayList<NodeRef> nodeRefs = newArrayList(nodeRef1, nodeRef2);
when(mockedDictionaryService.isSubClass(mockedNodeService.getType(nodeRef1), TYPE_CONTENT)).thenReturn(true);
when(mockedContentClassificationService.hasClearance(nodeRef1)).thenReturn(true);
when(mockedDictionaryService.isSubClass(mockedNodeService.getType(nodeRef2), TYPE_CONTENT)).thenReturn(true);
when(mockedContentClassificationService.hasClearance(nodeRef2)).thenReturn(true);
assertEquals(nodeRefs, nodeRefPostMethodInvocationProcessor.process(nodeRefs));
}
@Test
public void testCollection_bothNodesContent_userClearedForOne()
{
NodeRef nodeRef1 = generateNodeRef();
NodeRef nodeRef2 = generateNodeRef();
ArrayList<NodeRef> nodeRefs = newArrayList(nodeRef1, nodeRef2);
when(mockedDictionaryService.isSubClass(mockedNodeService.getType(nodeRef1), TYPE_CONTENT)).thenReturn(true);
when(mockedContentClassificationService.hasClearance(nodeRef1)).thenReturn(true);
when(mockedDictionaryService.isSubClass(mockedNodeService.getType(nodeRef2), TYPE_CONTENT)).thenReturn(true);
when(mockedContentClassificationService.hasClearance(nodeRef2)).thenReturn(false);
assertEquals(newArrayList(nodeRef1), nodeRefPostMethodInvocationProcessor.process(nodeRefs));
}
@SuppressWarnings("rawtypes")
@Test
public void testCollection_bothNodesContent_userClearedForNone()
{
NodeRef nodeRef1 = generateNodeRef();
NodeRef nodeRef2 = generateNodeRef();
ArrayList<NodeRef> nodeRefs = newArrayList(nodeRef1, nodeRef2);
when(mockedDictionaryService.isSubClass(mockedNodeService.getType(nodeRef1), TYPE_CONTENT)).thenReturn(true);
when(mockedContentClassificationService.hasClearance(nodeRef1)).thenReturn(false);
when(mockedDictionaryService.isSubClass(mockedNodeService.getType(nodeRef2), TYPE_CONTENT)).thenReturn(true);
when(mockedContentClassificationService.hasClearance(nodeRef2)).thenReturn(false);
assertEquals(new ArrayList(), nodeRefPostMethodInvocationProcessor.process(unmodifiableCollection(nodeRefs)));
}
@Test
public void testCollection_onlyOneNodeContent_userClearedForBoth()
{
NodeRef nodeRef1 = generateNodeRef();
NodeRef nodeRef2 = generateNodeRef();
ArrayList<NodeRef> nodeRefs = newArrayList(nodeRef1, nodeRef2);
when(mockedDictionaryService.isSubClass(mockedNodeService.getType(nodeRef1), TYPE_CONTENT)).thenReturn(false);
when(mockedContentClassificationService.hasClearance(nodeRef1)).thenReturn(true);
when(mockedDictionaryService.isSubClass(mockedNodeService.getType(nodeRef2), TYPE_CONTENT)).thenReturn(true);
when(mockedContentClassificationService.hasClearance(nodeRef2)).thenReturn(true);
assertEquals(nodeRefs, nodeRefPostMethodInvocationProcessor.process(copyOf(nodeRefs)));
}
@Test
public void testCollection_bothNodesNotContent_userClearedForBoth()
{
NodeRef nodeRef1 = generateNodeRef();
NodeRef nodeRef2 = generateNodeRef();
ArrayList<NodeRef> nodeRefs = newArrayList(nodeRef1, nodeRef2);
when(mockedDictionaryService.isSubClass(mockedNodeService.getType(nodeRef1), TYPE_CONTENT)).thenReturn(false);
when(mockedContentClassificationService.hasClearance(nodeRef1)).thenReturn(true);
when(mockedDictionaryService.isSubClass(mockedNodeService.getType(nodeRef2), TYPE_CONTENT)).thenReturn(false);
when(mockedContentClassificationService.hasClearance(nodeRef2)).thenReturn(true);
assertEquals(nodeRefs, nodeRefPostMethodInvocationProcessor.process(copyOf(nodeRefs)));
}
}