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@106283 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tuna Aksoy
2015-06-16 14:30:37 +00:00
parent 4357be8ef4
commit d79c6c2105
8 changed files with 207 additions and 0 deletions

View File

@@ -0,0 +1,104 @@
/*
* Copyright (C) 2005-2015 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* 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/>.
*/
package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
import static org.springframework.extensions.webscripts.GUID.generate;
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;
import org.alfresco.service.cmr.repository.NodeRef;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
/**
* NodeRef Post Method Invocation Processor Unit Test
*
* @author Tuna Aksoy
* @since 3.0
*/
public class NodeRefPostMethodInvocationProcessorUnitTest extends BaseUnitTest
{
@InjectMocks private NodeRefPostMethodInvocationProcessor nodeRefPostMethodInvocationProcessor;
@Mock private ContentClassificationService mockedContentClassificationService;
@Test (expected = IllegalArgumentException.class)
public void testProcessingNull()
{
nodeRefPostMethodInvocationProcessor.process(null);
}
@Test (expected = NotSupportedClassTypeException.class)
public void testProccessingAnotherClassType()
{
NodeRef nodeRef = generateNodeRef();
nodeRefPostMethodInvocationProcessor.process(nodeRef.getStoreRef());
}
@Test
public void testProcessingNonExistingNode()
{
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);
assertEquals(nodeRef, nodeRefPostMethodInvocationProcessor.process(nodeRef));
}
@Test
public void testProcessingNonContent()
{
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);
assertEquals(nodeRef, nodeRefPostMethodInvocationProcessor.process(nodeRef));
}
@Test
public void testExistingNodeWithUserClearance()
{
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);
assertEquals(nodeRef, nodeRefPostMethodInvocationProcessor.process(nodeRef));
}
@Test
public void testExistingNodeWithNoUserClearance()
{
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));
}
}