diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ArrayPostMethodInvocationProcessor.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ArrayPostMethodInvocationProcessor.java index 1584276c36..a93c1992d5 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ArrayPostMethodInvocationProcessor.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ArrayPostMethodInvocationProcessor.java @@ -49,7 +49,7 @@ public class ArrayPostMethodInvocationProcessor extends BasePostMethodInvocation */ @SuppressWarnings({ "unchecked", "rawtypes" }) @Override - public T process(T object) + protected T process(T object) { T result = object; diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/AssociationRefPostMethodInvocationProcessor.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/AssociationRefPostMethodInvocationProcessor.java index e7e83dfe8b..8b6ef1e0b0 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/AssociationRefPostMethodInvocationProcessor.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/AssociationRefPostMethodInvocationProcessor.java @@ -44,7 +44,7 @@ public class AssociationRefPostMethodInvocationProcessor extends BasePostMethodI * @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#process(java.lang.Object) */ @Override - public T process(T object) + protected T process(T object) { T result = object; diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/BasePostMethodInvocationProcessor.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/BasePostMethodInvocationProcessor.java index 9024286533..8870b632a8 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/BasePostMethodInvocationProcessor.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/BasePostMethodInvocationProcessor.java @@ -97,51 +97,11 @@ public abstract class BasePostMethodInvocationProcessor return this.postMethodInvocationProcessor; } - /** - * @param nodeService the nodeService to set - */ - public void setNodeService(NodeService nodeService) - { - this.nodeService = nodeService; - } - - /** - * @param dictionaryService the dictionaryService to set - */ - public void setDictionaryService(DictionaryService dictionaryService) - { - this.dictionaryService = dictionaryService; - } - - /** - * @param contentClassificationService the contentClassificationService to set - */ - public void setContentClassificationService(ContentClassificationService contentClassificationService) - { - this.contentClassificationService = contentClassificationService; - } - - /** - * @param securityClearanceService the securityClearanceService to set - */ - public void setSecurityClearanceService(SecurityClearanceService securityClearanceService) - { - this.securityClearanceService = securityClearanceService; - } - - /** - * @param postMethodInvocationProcessor the postMethodInvocationProcessor to set - */ - public void setPostMethodInvocationProcessor(PostMethodInvocationProcessor postMethodInvocationProcessor) - { - this.postMethodInvocationProcessor = postMethodInvocationProcessor; - } - /** * Registers the post method invocation processors */ @PostConstruct - public void register() + private void register() { getPostMethodInvocationProcessor().register(this); } diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ChildAssociationRefPostMethodInvocationProcessor.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ChildAssociationRefPostMethodInvocationProcessor.java index 741e0d06f6..d1eca242a5 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ChildAssociationRefPostMethodInvocationProcessor.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ChildAssociationRefPostMethodInvocationProcessor.java @@ -44,7 +44,7 @@ public class ChildAssociationRefPostMethodInvocationProcessor extends BasePostMe * @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#process(java.lang.Object) */ @Override - public T process(T object) + protected T process(T object) { T result = object; diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/CollectionPostMethodInvocationProcessor.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/CollectionPostMethodInvocationProcessor.java index af099d9994..0f30bc6da9 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/CollectionPostMethodInvocationProcessor.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/CollectionPostMethodInvocationProcessor.java @@ -35,8 +35,9 @@ public class CollectionPostMethodInvocationProcessor extends BasePostMethodInvoc /** * @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#getClassName() */ + @SuppressWarnings("rawtypes") @Override - protected Class getClassName() + protected Class getClassName() { return Collection.class; } @@ -46,79 +47,38 @@ public class CollectionPostMethodInvocationProcessor extends BasePostMethodInvoc */ @SuppressWarnings({ "rawtypes", "unchecked" }) @Override - public T process(T object) + protected T process(T object) { - Collection collection = ((Collection) object); + T result = object; - if (collection != null) + if (result != null) { - BasePostMethodInvocationProcessor processor = pickProcessor(collection); - if (processor != null) - { - object = (T) processCollection(collection, processor); - } - } + BasePostMethodInvocationProcessor processor = null; + Collection collection = getClassName().cast(object); + Iterator iterator = collection.iterator(); - return object; - } - - /** - * Process a collection using the supplied processor. - * - * @param collection The collection to be processed. - * @param processor A collection suitable for access by someone with the current security clearance. - */ - protected Collection processCollection(Collection collection, BasePostMethodInvocationProcessor processor) - { - Iterator iterator = collection.iterator(); - while (iterator.hasNext()) - { - Object next = iterator.next(); - Object processed = processor.process(next); - try + while (iterator.hasNext()) { - if (processed == null) + Object element = iterator.next(); + if (processor == null) + { + processor = getPostMethodInvocationProcessor().getProcessor(element); + if (processor == null) + { + break; + } + } + + Object processedElement = processor.process(element); + if (processedElement == null) { iterator.remove(); } - else if (!processed.equals(next)) - { - // Modifying members of this type of collection is not supported, so filter the whole collection. - return null; - } } - catch (UnsupportedOperationException e) - { - // If the collection cannot be modified and it contains classified data then the whole thing must be filtered. - return null; - } - } - return collection; - } - /** - * Pick a suitable processor for the members of the collection. We assume that all the elements of a collection can - * be processed by the same processor. - * - * @param collection The collection to be processed. - * @return The chosen processor, or {@code null} if no suitable processor could be found. - */ - @SuppressWarnings("rawtypes") - private BasePostMethodInvocationProcessor pickProcessor(Collection collection) - { - Iterator iterator = collection.iterator(); - while (iterator.hasNext()) - { - Object next = iterator.next(); - if (next != null) - { - BasePostMethodInvocationProcessor processor = getPostMethodInvocationProcessor().getProcessor(next); - if (processor != null) - { - return processor; - } - } + result = (T) collection; } - return null; + + return result; } } diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ListPostMethodInvocationProcessor.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ListPostMethodInvocationProcessor.java deleted file mode 100644 index 65124b6a8e..0000000000 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ListPostMethodInvocationProcessor.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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 . - */ -package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -/** - * List Post Method Invocation Processor. This replaces the existing list with a filtered {@link ArrayList}. By doing - * this we gain the ability to replace members of a list, which is not possible using the - * {@link CollectionPostMethodInvocationProcessor}. The downside is that whatever type of list was provided gets - * replaced with an {@code ArrayList}. - * - * @author Tom Page - * @since 3.0 - */ -public class ListPostMethodInvocationProcessor extends ModifiableCollectionPostMethodInvocationProcessor -{ - @Override - protected Class getClassName() - { - return List.class; - } - - @Override - protected Collection createEmptyCollection(Collection collection) - { - return new ArrayList<>(); - } -} diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ModifiableCollectionPostMethodInvocationProcessor.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ModifiableCollectionPostMethodInvocationProcessor.java deleted file mode 100644 index 95bd18d07a..0000000000 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ModifiableCollectionPostMethodInvocationProcessor.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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 . - */ -package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor; - -import java.util.ArrayList; -import java.util.Collection; - -/** - * List Post Method Invocation Processor. This replaces the existing list with a filtered {@link ArrayList}. By doing - * this we gain the ability to replace members of a list, which is not possible using the - * {@link CollectionPostMethodInvocationProcessor}. The downside is that whatever type of list was provided gets - * replaced with an {@code ArrayList}. - * - * @author Tom Page - * @since 3.0 - */ -public abstract class ModifiableCollectionPostMethodInvocationProcessor extends CollectionPostMethodInvocationProcessor -{ - @Override - abstract protected Class getClassName(); - - /** - * Create an empty modifiable collection. - * - * @param collection The source collection to try to mimic. - * @return The new empty collection. - */ - abstract protected Collection createEmptyCollection(Collection collection); - - /** {@inheritDoc} */ - @Override - protected Collection processCollection(Collection collection, BasePostMethodInvocationProcessor processor) - { - Collection returnList = createEmptyCollection(collection); - for (T member : collection) - { - T processed = processor.process(member); - if (processed != null) - { - returnList.add(processed); - } - } - return returnList; - } -} diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/NodeRefPostMethodInvocationProcessor.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/NodeRefPostMethodInvocationProcessor.java index d358357077..c499f1c216 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/NodeRefPostMethodInvocationProcessor.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/NodeRefPostMethodInvocationProcessor.java @@ -43,7 +43,7 @@ public class NodeRefPostMethodInvocationProcessor extends BasePostMethodInvocati * @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#process(java.lang.Object) */ @Override - public T process(T object) + protected T process(T object) { T result = object; diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/PagingResultsPostMethodInvocationProcessor.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/PagingResultsPostMethodInvocationProcessor.java index 345f82e88b..e6001ab5ed 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/PagingResultsPostMethodInvocationProcessor.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/PagingResultsPostMethodInvocationProcessor.java @@ -48,7 +48,7 @@ public class PagingResultsPostMethodInvocationProcessor extends BasePostMethodIn */ @SuppressWarnings({ "rawtypes", "unchecked" }) @Override - public T process(T object) + protected T process(T object) { T result = object; diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/PermissionCheckValuePostMethodInvocationProcessor.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/PermissionCheckValuePostMethodInvocationProcessor.java index 946059818a..352fb12b29 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/PermissionCheckValuePostMethodInvocationProcessor.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/PermissionCheckValuePostMethodInvocationProcessor.java @@ -44,7 +44,7 @@ public class PermissionCheckValuePostMethodInvocationProcessor extends BasePostM * @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#process(java.lang.Object) */ @Override - public T process(T object) + protected T process(T object) { T result = object; diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/QueryEngineResultsPostMethodInvocationProcessor.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/QueryEngineResultsPostMethodInvocationProcessor.java index 397fe98922..1d8ce6a52f 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/QueryEngineResultsPostMethodInvocationProcessor.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/QueryEngineResultsPostMethodInvocationProcessor.java @@ -50,7 +50,7 @@ public class QueryEngineResultsPostMethodInvocationProcessor extends BasePostMet */ @SuppressWarnings("unchecked") @Override - public T process(T object) + protected T process(T object) { T result = object; diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ResultSetPostMethodInvocationProcessor.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ResultSetPostMethodInvocationProcessor.java index 4123b3967a..e6fa539a12 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ResultSetPostMethodInvocationProcessor.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ResultSetPostMethodInvocationProcessor.java @@ -55,7 +55,7 @@ public class ResultSetPostMethodInvocationProcessor extends BasePostMethodInvoca */ @SuppressWarnings({ "unchecked" }) @Override - public T process(T object) + protected T process(T object) { T result = object; diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/SetPostMethodInvocationProcessor.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/SetPostMethodInvocationProcessor.java deleted file mode 100644 index ab16dd9130..0000000000 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/SetPostMethodInvocationProcessor.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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 . - */ -package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor; - -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - -/** - * Set Post Method Invocation Processor. This replaces the existing set with a filtered {@link HashSet}. By doing - * this we gain the ability to replace members of a set, which is not possible using the - * {@link CollectionPostMethodInvocationProcessor}. The downside is that whatever type of set was provided gets - * replaced with an {@code HashSet}. - * - * @author Tom Page - * @since 3.0 - */ -public class SetPostMethodInvocationProcessor extends ModifiableCollectionPostMethodInvocationProcessor -{ - @Override - protected Class getClassName() - { - return Set.class; - } - - @Override - protected Collection createEmptyCollection(Collection collection) - { - return new HashSet<>(); - } -} diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/SortedSetPostMethodInvocationProcessor.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/SortedSetPostMethodInvocationProcessor.java deleted file mode 100644 index 77030ff263..0000000000 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/SortedSetPostMethodInvocationProcessor.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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 . - */ -package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor; - -import java.util.Collection; -import java.util.SortedSet; -import java.util.TreeSet; - -/** - * Sorted Set Post Method Invocation Processor. This replaces the existing set with a filtered {@link TreeSet}. - * - * @author Tom Page - * @since 3.0 - */ -public class SortedSetPostMethodInvocationProcessor extends ModifiableCollectionPostMethodInvocationProcessor -{ - @Override - protected Class getClassName() - { - return SortedSet.class; - } - - @Override - protected Collection createEmptyCollection(Collection collection) - { - SortedSet sortedSet = (SortedSet) collection; - return new TreeSet<>(sortedSet.comparator()); - } -} diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/StoreRefPostMethodInvocationProcessor.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/StoreRefPostMethodInvocationProcessor.java index f0f310c86f..5e92befb49 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/StoreRefPostMethodInvocationProcessor.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/StoreRefPostMethodInvocationProcessor.java @@ -41,10 +41,10 @@ public class StoreRefPostMethodInvocationProcessor extends BasePostMethodInvocat } /** - * @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.AbstractPostMethodInvocationProcessor#processSingleElement(java.lang.Object) + * @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#process(java.lang.Object) */ @Override - public T process(T object) + protected T process(T object) { T result = object; diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ArrayPostMethodInvocationProcessorUnitTest.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ArrayPostMethodInvocationProcessorUnitTest.java index a9c44c4601..66cf069bde 100644 --- a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ArrayPostMethodInvocationProcessorUnitTest.java +++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ArrayPostMethodInvocationProcessorUnitTest.java @@ -18,18 +18,20 @@ */ package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor; +import static org.alfresco.service.cmr.repository.StoreRef.STORE_REF_WORKSPACE_SPACESSTORE; +import static org.alfresco.util.GUID.generate; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.isA; import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; -import org.alfresco.module.org_alfresco_module_rm.classification.ContentClassificationService; -import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest; import org.alfresco.service.cmr.repository.NodeRef; import org.apache.commons.lang3.ArrayUtils; +import org.junit.Before; import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.Mockito; /** * Array Post Method Invocation Processor Unit Test @@ -37,40 +39,38 @@ import org.mockito.Mockito; * @author Tuna Aksoy * @since 3.0 */ -public class ArrayPostMethodInvocationProcessorUnitTest extends BaseUnitTest +public class ArrayPostMethodInvocationProcessorUnitTest { - @InjectMocks ArrayPostMethodInvocationProcessor arrayPostMethodInvocationProcessor; - @Mock private ContentClassificationService mockedContentClassificationService; + private static final NodeRef NODE_REF_1 = new NodeRef(STORE_REF_WORKSPACE_SPACESSTORE, generate()); + private static final NodeRef NODE_REF_2 = new NodeRef(STORE_REF_WORKSPACE_SPACESSTORE, generate()); + private static final NodeRef NODE_REF_3 = new NodeRef(STORE_REF_WORKSPACE_SPACESSTORE, generate()); + private static final NodeRef NODE_REF_4 = new NodeRef(STORE_REF_WORKSPACE_SPACESSTORE, generate()); + + @InjectMocks private ArrayPostMethodInvocationProcessor arrayPostMethodInvocationProcessor; @Mock private PostMethodInvocationProcessor mockedPostMethodInvocationProcessor; + @Mock private BasePostMethodInvocationProcessor mockedNodeRefProcessor; + + @Before + public void setUp() + { + initMocks(this); + + when(mockedPostMethodInvocationProcessor.getProcessor(isA(NodeRef.class))).thenReturn(mockedNodeRefProcessor); + + when(mockedNodeRefProcessor.process(NODE_REF_1)).thenReturn(NODE_REF_1); + when(mockedNodeRefProcessor.process(NODE_REF_2)).thenReturn(null); + when(mockedNodeRefProcessor.process(NODE_REF_3)).thenReturn(NODE_REF_3); + when(mockedNodeRefProcessor.process(NODE_REF_4)).thenReturn(null); + } @Test public void testArrayPostMethodInvocationProcessor() { - NodeRefPostMethodInvocationProcessor processor = new NodeRefPostMethodInvocationProcessor(); - processor.setNodeService(mockedNodeService); - processor.setDictionaryService(mockedDictionaryService); - processor.setContentClassificationService(mockedContentClassificationService); - - NodeRef nodeRef1 = generateNodeRef(); - NodeRef nodeRef2 = generateNodeRef(); - NodeRef nodeRef3 = generateNodeRef(); - NodeRef nodeRef4 = generateNodeRef(); - - when(mockedDictionaryService.isSubClass(mockedNodeService.getType(nodeRef1), TYPE_CONTENT)).thenReturn(true); - when(mockedDictionaryService.isSubClass(mockedNodeService.getType(nodeRef2), TYPE_CONTENT)).thenReturn(true); - when(mockedDictionaryService.isSubClass(mockedNodeService.getType(nodeRef3), TYPE_CONTENT)).thenReturn(true); - when(mockedDictionaryService.isSubClass(mockedNodeService.getType(nodeRef4), TYPE_CONTENT)).thenReturn(true); - when(mockedContentClassificationService.hasClearance(nodeRef1)).thenReturn(true); - when(mockedContentClassificationService.hasClearance(nodeRef2)).thenReturn(false); - when(mockedContentClassificationService.hasClearance(nodeRef3)).thenReturn(true); - when(mockedContentClassificationService.hasClearance(nodeRef4)).thenReturn(false); - when(mockedPostMethodInvocationProcessor.getProcessor(Mockito.any())).thenReturn(processor); - - NodeRef[] nodes = new NodeRef[] { nodeRef1, nodeRef2, nodeRef3, nodeRef4 }; + NodeRef[] nodes = new NodeRef[] { NODE_REF_1, NODE_REF_2, NODE_REF_3, NODE_REF_4 }; NodeRef[] processedNodes = arrayPostMethodInvocationProcessor.process(nodes); assertEquals(2, processedNodes.length); - assertTrue(ArrayUtils.contains(processedNodes, nodeRef1)); - assertTrue(ArrayUtils.contains(processedNodes, nodeRef3)); + assertTrue(ArrayUtils.contains(processedNodes, NODE_REF_1)); + assertTrue(ArrayUtils.contains(processedNodes, NODE_REF_3)); } } diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/CollectionPostMethodInvocationProcessorUnitTest.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/CollectionPostMethodInvocationProcessorUnitTest.java index 09a682d9d5..8d2d819b08 100644 --- a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/CollectionPostMethodInvocationProcessorUnitTest.java +++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/CollectionPostMethodInvocationProcessorUnitTest.java @@ -18,7 +18,11 @@ */ package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor; +import static com.google.common.collect.Lists.newArrayList; +import static java.util.Arrays.asList; +import static org.alfresco.util.GUID.generate; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.isA; @@ -26,9 +30,12 @@ import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; +import java.util.Comparator; +import java.util.Iterator; import java.util.List; +import java.util.SortedSet; +import java.util.TreeSet; import org.junit.Before; import org.junit.Test; @@ -43,25 +50,25 @@ import org.mockito.Mock; */ public class CollectionPostMethodInvocationProcessorUnitTest { - private static final String NON_FILTERED = "NON_FILTERED"; - private static final String FILTERED = "FILTERED"; - private static final String CHANGED_INPUT = "CHANGED_INPUT"; - private static final String CHANGED_OUTPUT = "CHANGED_OUTPUT"; + private static final String REALLY_LONG_OUTPUT_STRING = generate() + generate(); + private static final String NON_FILTERED = generate(); + private static final String FILTERED = generate(); - @InjectMocks CollectionPostMethodInvocationProcessor collectionPostMethodInvocationProcessor; - @Mock PostMethodInvocationProcessor mockPostMethodInvocationProcessor; - @Mock BasePostMethodInvocationProcessor mockStringProcessor; + @InjectMocks private CollectionPostMethodInvocationProcessor collectionPostMethodInvocationProcessor; + @Mock private PostMethodInvocationProcessor mockPostMethodInvocationProcessor; + @Mock private BasePostMethodInvocationProcessor mockStringProcessor; @Before public void setUp() { initMocks(this); + when(mockPostMethodInvocationProcessor.getProcessor(isA(List.class))).thenReturn(collectionPostMethodInvocationProcessor); when(mockPostMethodInvocationProcessor.getProcessor(isA(String.class))).thenReturn(mockStringProcessor); + when(mockStringProcessor.process(REALLY_LONG_OUTPUT_STRING)).thenReturn(REALLY_LONG_OUTPUT_STRING); when(mockStringProcessor.process(NON_FILTERED)).thenReturn(NON_FILTERED); when(mockStringProcessor.process(FILTERED)).thenReturn(null); - when(mockStringProcessor.process(CHANGED_INPUT)).thenReturn(CHANGED_OUTPUT); } @Test @@ -83,10 +90,20 @@ public class CollectionPostMethodInvocationProcessorUnitTest assertEquals("Expected collection containing null to be passed through.", collection, result); } + @Test + public void testProcess_emptyList() + { + List collection = new ArrayList<>(); + + Collection result = collectionPostMethodInvocationProcessor.process(collection); + + assertEquals(collection, result); + } + @Test public void testProcess_nonFilteredMember() { - Object collection = Arrays.asList(NON_FILTERED); + Object collection = asList(NON_FILTERED); Object result = collectionPostMethodInvocationProcessor.process(collection); @@ -96,42 +113,76 @@ public class CollectionPostMethodInvocationProcessorUnitTest @Test public void testProcess_filteredMemberInModifiableList() { - List collection = new ArrayList<>(Arrays.asList(FILTERED)); + List collection = newArrayList(FILTERED); Collection result = collectionPostMethodInvocationProcessor.process(collection); assertTrue("Expected an empty list.", result.isEmpty()); } - @Test + @Test(expected = UnsupportedOperationException.class) public void testProcess_filteredMemberInUnmodifiableList() { - List collection = Arrays.asList(FILTERED, NON_FILTERED); + List collection = asList(FILTERED, NON_FILTERED); - Collection result = collectionPostMethodInvocationProcessor.process(collection); - - assertNull("Since the collection could not be modified the whole thing should be filtered.", result); - } - - @Test - public void testProcess_modifiedMember() - { - List collection = Arrays.asList(NON_FILTERED, CHANGED_INPUT); - - Collection result = collectionPostMethodInvocationProcessor.process(collection); - - assertNull("Since the Collection interface does not support replacement, the whole collection should be filtered.", - result); + collectionPostMethodInvocationProcessor.process(collection); } @Test public void testProcess_noProcessorDefined() { - List collection = Arrays.asList(1, 4, 91); + List collection = asList(1, 4, 91); Collection result = collectionPostMethodInvocationProcessor.process(collection); - assertEquals("If no processor is defined for the members then the whole list should be returned.", collection, - result); + assertEquals("If no processor is defined for the members then the whole list should be returned.", collection, result); + } + + @SuppressWarnings("unchecked") + @Test + public void testProcess_listOfLists() + { + List innerListA = newArrayList(FILTERED, NON_FILTERED); + List innerListB = newArrayList(FILTERED, NON_FILTERED); + List> collection = newArrayList(innerListA, innerListB); + + Collection> result = collectionPostMethodInvocationProcessor.process(collection); + + List expectedInnerListA = asList(NON_FILTERED); + List expectedInnerListB = asList(NON_FILTERED); + List> expected = asList(expectedInnerListA, expectedInnerListB); + assertEquals(expected, result); + } + + /** + * Given I have a sorted set of input strings + * When I pass it to the collection processor + * Then I expect items above my clearance to be filtered + * And I expect items below my clearance to be passed through + * And I expect the output set to be sorted using the same comparator as the input. + */ + @Test + public void testProcess_sortedSet() + { + // Create a custom comparator that sorts based on the length of the strings. + Comparator comparator = new Comparator() + { + public int compare(String o1, String o2) + { + return o1.length() - o2.length(); + } + }; + + SortedSet collection = new TreeSet<>(comparator); + collection.add(REALLY_LONG_OUTPUT_STRING); + collection.add(NON_FILTERED); + collection.add(FILTERED); + + Collection result = collectionPostMethodInvocationProcessor.process(collection); + + Iterator iterator = result.iterator(); + assertEquals("Expected the first element to be the shortest", NON_FILTERED, iterator.next()); + assertEquals("Expected the second element to be the longest", REALLY_LONG_OUTPUT_STRING, iterator.next()); + assertFalse("Expected two elements in output", iterator.hasNext()); } } diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ListPostMethodInvocationProcessorUnitTest.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ListPostMethodInvocationProcessorUnitTest.java deleted file mode 100644 index e7cc4db762..0000000000 --- a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ListPostMethodInvocationProcessorUnitTest.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * 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 . - */ -package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.isA; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; - -/** - * Unit tests for {@link ListPostMethodInvocationProcessor}. - * - * @author Tom Page - * @since 3.0 - */ -public class ListPostMethodInvocationProcessorUnitTest -{ - private static final String NON_FILTERED = "NON_FILTERED"; - private static final String FILTERED = "FILTERED"; - private static final String CHANGED_INPUT = "CHANGED_INPUT"; - private static final String CHANGED_OUTPUT = "CHANGED_OUTPUT"; - - @InjectMocks ListPostMethodInvocationProcessor listPostMethodInvocationProcessor; - @Mock PostMethodInvocationProcessor mockPostMethodInvocationProcessor; - @Mock BasePostMethodInvocationProcessor mockStringProcessor; - - @Before - public void setUp() - { - initMocks(this); - - when(mockPostMethodInvocationProcessor.getProcessor(isA(List.class))).thenReturn(listPostMethodInvocationProcessor); - when(mockPostMethodInvocationProcessor.getProcessor(isA(String.class))).thenReturn(mockStringProcessor); - - when(mockStringProcessor.process(NON_FILTERED)).thenReturn(NON_FILTERED); - when(mockStringProcessor.process(FILTERED)).thenReturn(null); - when(mockStringProcessor.process(CHANGED_INPUT)).thenReturn(CHANGED_OUTPUT); - } - - @Test - public void testProcessCollection_emptyList() - { - List collection = new ArrayList<>(); - - Collection result = listPostMethodInvocationProcessor.processCollection(collection, mockStringProcessor); - - assertEquals(collection, result); - } - - @Test - public void testProcessCollection_completelyFiltered() - { - List collection = Arrays.asList(FILTERED, FILTERED); - - Collection result = listPostMethodInvocationProcessor.processCollection(collection, mockStringProcessor); - - assertTrue("Expected all members of the list to be removed.", result.isEmpty()); - } - - @Test - public void testProcessCollection_supportsReplacement() - { - List collection = Arrays.asList(NON_FILTERED, CHANGED_INPUT); - - Collection result = listPostMethodInvocationProcessor.processCollection(collection, mockStringProcessor); - - List expected = Arrays.asList(NON_FILTERED, CHANGED_OUTPUT); - assertEquals(expected, result); - } - - @Test - public void testProcess_listOfLists() - { - List innerListA = Arrays.asList(FILTERED, NON_FILTERED, CHANGED_INPUT); - List innerListB = Arrays.asList(CHANGED_INPUT, FILTERED, NON_FILTERED); - List> collection = Arrays.asList(innerListA, innerListB); - - Collection> result = listPostMethodInvocationProcessor.process(collection); - - List expectedInnerListA = Arrays.asList(NON_FILTERED, CHANGED_OUTPUT); - List expectedInnerListB = Arrays.asList(CHANGED_OUTPUT, NON_FILTERED); - List> expected = Arrays.asList(expectedInnerListA, expectedInnerListB); - assertEquals(expected, result); - } -} diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/SortedSetPostMethodInvocationProcessorUnitTest.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/SortedSetPostMethodInvocationProcessorUnitTest.java deleted file mode 100644 index 918140d06e..0000000000 --- a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/SortedSetPostMethodInvocationProcessorUnitTest.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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 . - */ -package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; - -import java.util.Collection; -import java.util.Comparator; -import java.util.Iterator; -import java.util.SortedSet; -import java.util.TreeSet; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; - -/** - * Unit tests for {@link SortedSetPostMethodInvocationProcessor}. - * - * @author Tom Page - * @since 3.0 - */ -public class SortedSetPostMethodInvocationProcessorUnitTest -{ - private static final String NON_FILTERED = "NON_FILTERED"; - private static final String FILTERED = "FILTERED"; - private static final String SHORT_INPUT = "SHORT_INPUT"; - private static final String REALLY_LONG_OUTPUT_STRING = "REALLY_LONG_OUTPUT_STRING"; - - @InjectMocks SortedSetPostMethodInvocationProcessor sortedSetPostMethodInvocationProcessor; - @Mock BasePostMethodInvocationProcessor mockStringProcessor; - - @Before - public void setUp() - { - initMocks(this); - - when(mockStringProcessor.process(NON_FILTERED)).thenReturn(NON_FILTERED); - when(mockStringProcessor.process(FILTERED)).thenReturn(null); - when(mockStringProcessor.process(SHORT_INPUT)).thenReturn(REALLY_LONG_OUTPUT_STRING); - } - - /** - * Given I have a sorted set of input strings - * When I pass it to the SortedSet processor - * Then I expect items above my clearance to be filtered - * And I expect items below my clearance to be passed through - * And I expect items that get changed by the filtering process to be changed - * And I expect the output set to be sorted using the same comparator as the input. - */ - @Test - public void testProcessCollection() - { - // Create a custom comparator that sorts based on the length of the strings. - Comparator comparator = new Comparator() - { - public int compare(String o1, String o2) - { - return o1.length() - o2.length(); - } - }; - SortedSet collection = new TreeSet<>(comparator); - collection.add(SHORT_INPUT); - collection.add(NON_FILTERED); - collection.add(FILTERED); - - Collection result = sortedSetPostMethodInvocationProcessor.processCollection(collection, mockStringProcessor); - - Iterator iterator = result.iterator(); - assertEquals("Expected the first element to be the shortest", NON_FILTERED, iterator.next()); - assertEquals("Expected the second element to be the longest", REALLY_LONG_OUTPUT_STRING, iterator.next()); - assertFalse("Expected two elements in output", iterator.hasNext()); - } -}