From 0d01f1c83f47a834c490abb13214c869af9c4db8 Mon Sep 17 00:00:00 2001 From: Tom Page Date: Tue, 21 Apr 2015 08:06:31 +0000 Subject: [PATCH] RM-2045 Check that content is not re-classified. Currently this is not supported, although it will be needed in the future. Also take the opportunity to change the unit tests to use: when(x.y()).thenReturn(z)); rather than: doReturn(z).when(x).y(); This is because I noticed the javadoc for "doReturn" gives a good explanation of when to use each (use the former whenever possible for readability; use the latter if there's no choice). +review RM-25 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@102231 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../ClassificationServiceImpl.java | 5 ++++ .../ClassificationServiceImplUnitTest.java | 26 ++++++++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceImpl.java index b7d40c7dce..d807ad264d 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceImpl.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceImpl.java @@ -230,6 +230,11 @@ public class ClassificationServiceImpl extends ServiceBaseImpl { throw new InvalidNode(content, "The supplied node is not a content node."); } + if (nodeService.hasAspect(content, ASPECT_CLASSIFIED)) + { + throw new UnsupportedOperationException( + "The content has already been classified. Reclassification is currently not supported."); + } Map properties = new HashMap(); checkClassificationLevelId(classificationLevelId); diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceImplUnitTest.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceImplUnitTest.java index 889550631e..7e4834c23d 100644 --- a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceImplUnitTest.java +++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceImplUnitTest.java @@ -24,7 +24,6 @@ import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -268,12 +267,13 @@ public class ClassificationServiceImplUnitTest ClassificationReason reason1 = new ClassificationReason("reasonId1", "displayLabelKey1"); ClassificationReason reason2 = new ClassificationReason("reasonId2", "displayLabelKey2"); // Set up the managers to return these objects when the ids are provided. - doReturn(level).when(mockLevelManager).findLevelById("levelId1"); - doReturn(reason1).when(mockReasonManager).findReasonById("reasonId1"); - doReturn(reason2).when(mockReasonManager).findReasonById("reasonId2"); + when(mockLevelManager.findLevelById("levelId1")).thenReturn(level); + when(mockReasonManager.findReasonById("reasonId1")).thenReturn(reason1); + when(mockReasonManager.findReasonById("reasonId2")).thenReturn(reason2); // Create a content node. NodeRef content = new NodeRef("fake://content/"); - doReturn(ContentModel.TYPE_CONTENT).when(mockNodeService).getType(content); + when(mockNodeService.getType(content)).thenReturn(ContentModel.TYPE_CONTENT); + when(mockNodeService.hasAspect(content, ClassifiedContentModel.ASPECT_CLASSIFIED)).thenReturn(false); // Call the method under test. classificationServiceImpl.classifyContent("levelId1", "classificationAuthority", @@ -301,10 +301,24 @@ public class ClassificationServiceImplUnitTest { // Create a folder node. NodeRef notAPieceOfContent = new NodeRef("not://a/piece/of/content/"); - doReturn(ContentModel.TYPE_FOLDER).when(mockNodeService).getType(notAPieceOfContent); + when(mockNodeService.getType(notAPieceOfContent)).thenReturn(ContentModel.TYPE_FOLDER); // Call the method under test. classificationServiceImpl.classifyContent("levelId1", "classificationAuthority", Sets.newHashSet("reasonId1", "reasonId2"), notAPieceOfContent); } + + /** Classify a piece of content that has already been classified. */ + @Test(expected = UnsupportedOperationException.class) + public void classifyContent_alreadyClassified() + { + // Create a classified piece of content. + NodeRef classifiedContent = new NodeRef("classified://content/"); + when(mockNodeService.getType(classifiedContent)).thenReturn(ContentModel.TYPE_CONTENT); + when(mockNodeService.hasAspect(classifiedContent, ClassifiedContentModel.ASPECT_CLASSIFIED)).thenReturn(true); + + // Call the method under test. + classificationServiceImpl.classifyContent("levelId1", "classificationAuthority", + Sets.newHashSet("reasonId1", "reasonId2"), classifiedContent); + } }