mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
RM-2401 Pass classification schedule fields when classifying content.
Create a new data transfer object and add all the classification fields to it. Update everywhere we're classifying content with the API to use the data transfer object. Also update the new edit classification API. Break the classifyContent implementation into several smaller methods and update unit tests to target these methods. Don't actually use new fields in this commit, as there was plenty in this commit as it was! +review RM git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@108928 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -18,7 +18,6 @@
|
||||
*/
|
||||
package org.alfresco.module.org_alfresco_module_rm.classification;
|
||||
|
||||
import static com.google.common.collect.Sets.newHashSet;
|
||||
import static org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock.generateNodeRef;
|
||||
import static org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock.generateText;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -37,6 +36,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.model.QuickShareModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.InvalidNode;
|
||||
@@ -57,9 +58,6 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ContentClassificationServiceImpl}.
|
||||
*
|
||||
@@ -78,6 +76,7 @@ public class ContentClassificationServiceImplUnitTest implements ClassifiedConte
|
||||
@Mock DictionaryService mockDictionaryService;
|
||||
@Mock SecurityClearanceService mockSecurityClearanceService;
|
||||
@Mock AuthenticationUtil mockAuthenticationUtil;
|
||||
@Mock ClassificationAspectProperties mockPropertiesDTO;
|
||||
@Captor ArgumentCaptor<Map<QName, Serializable>> propertiesCaptor;
|
||||
|
||||
@Before public void setUp()
|
||||
@@ -103,10 +102,14 @@ public class ContentClassificationServiceImplUnitTest implements ClassifiedConte
|
||||
when(mockDictionaryService.isSubClass(mockNodeService.getType(content), ContentModel.TYPE_CONTENT)).thenReturn(true);
|
||||
when(mockNodeService.hasAspect(content, ClassifiedContentModel.ASPECT_CLASSIFIED)).thenReturn(false);
|
||||
when(mockSecurityClearanceService.isCurrentUserClearedForClassification("levelId1")).thenReturn(true);
|
||||
// Set up the mock DTO.
|
||||
when(mockPropertiesDTO.getClassificationLevelId()).thenReturn("levelId1");
|
||||
when(mockPropertiesDTO.getClassifiedBy()).thenReturn("classifiedBy");
|
||||
when(mockPropertiesDTO.getClassificationAgency()).thenReturn("classificationAgency");
|
||||
when(mockPropertiesDTO.getClassificationReasonIds()).thenReturn(Sets.newHashSet("reasonId1", "reasonId2"));
|
||||
|
||||
// Call the method under test
|
||||
contentClassificationServiceImpl.classifyContent("levelId1", "classifiedBy", "classificationAgency",
|
||||
Sets.newHashSet("reasonId1", "reasonId2"), content);
|
||||
contentClassificationServiceImpl.classifyContent(mockPropertiesDTO, content);
|
||||
|
||||
verify(mockNodeService).addAspect(eq(content), eq(ClassifiedContentModel.ASPECT_CLASSIFIED),
|
||||
propertiesCaptor.capture());
|
||||
@@ -128,28 +131,26 @@ public class ContentClassificationServiceImplUnitTest implements ClassifiedConte
|
||||
|
||||
/** Classify a folder using the <code>classifyContent</code> method and check that an exception is raised. */
|
||||
@Test(expected = InvalidNode.class)
|
||||
public void classifyContent_notContent()
|
||||
public void validateContent_notContent()
|
||||
{
|
||||
// Create a folder node.
|
||||
NodeRef notAPieceOfContent = new NodeRef("not://a/piece/of/content/");
|
||||
when(mockNodeService.getType(notAPieceOfContent)).thenReturn(ContentModel.TYPE_FOLDER);
|
||||
|
||||
// Call the method under test.
|
||||
contentClassificationServiceImpl.classifyContent("levelId1", "classifiedBy", "classificationAgency",
|
||||
Sets.newHashSet("reasonId1", "reasonId2"), notAPieceOfContent);
|
||||
contentClassificationServiceImpl.validateContent(notAPieceOfContent);
|
||||
}
|
||||
|
||||
/** Classify a piece of content that has already been shared */
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void classifySharedContent()
|
||||
public void validateContent_sharedContent()
|
||||
{
|
||||
NodeRef sharedContent = generateNodeRef(mockNodeService);
|
||||
when(mockDictionaryService.isSubClass(mockNodeService.getType(sharedContent), ContentModel.TYPE_CONTENT)).thenReturn(true);
|
||||
when(mockNodeService.hasAspect(sharedContent, QuickShareModel.ASPECT_QSHARE)).thenReturn(true);
|
||||
|
||||
// Call the method under test.
|
||||
contentClassificationServiceImpl.classifyContent(generateText(), generateText(), generateText(),
|
||||
newHashSet(generateText(), generateText()), sharedContent);
|
||||
contentClassificationServiceImpl.validateContent(sharedContent);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,15 +160,16 @@ public class ContentClassificationServiceImplUnitTest implements ClassifiedConte
|
||||
@Test(expected = LevelIdNotFound.class)
|
||||
public void classifyContent_notFound()
|
||||
{
|
||||
// Create a classified piece of content.
|
||||
NodeRef classifiedContent = new NodeRef("classified://content/");
|
||||
when(mockDictionaryService.isSubClass(mockNodeService.getType(classifiedContent), ContentModel.TYPE_CONTENT)).thenReturn(true);
|
||||
when(mockNodeService.hasAspect(classifiedContent, ClassifiedContentModel.ASPECT_CLASSIFIED)).thenReturn(false);
|
||||
// The user doesn't have level 1 clearance.
|
||||
when(mockSecurityClearanceService.isCurrentUserClearedForClassification("levelId1")).thenReturn(false);
|
||||
// Set up the mock DTO.
|
||||
when(mockPropertiesDTO.getClassificationLevelId()).thenReturn("levelId1");
|
||||
when(mockPropertiesDTO.getClassifiedBy()).thenReturn("classifiedBy");
|
||||
when(mockPropertiesDTO.getClassificationAgency()).thenReturn("classificationAgency");
|
||||
when(mockPropertiesDTO.getClassificationReasonIds()).thenReturn(Sets.newHashSet("reasonId1", "reasonId2"));
|
||||
|
||||
// Call the method under test.
|
||||
contentClassificationServiceImpl.classifyContent("levelId1", "classifiedBy","classificationAgency",
|
||||
Sets.newHashSet("reasonId1", "reasonId2"), classifiedContent);
|
||||
contentClassificationServiceImpl.validateProperties(mockPropertiesDTO);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -18,7 +18,6 @@
|
||||
*/
|
||||
package org.alfresco.module.org_alfresco_module_rm.script.classification;
|
||||
|
||||
import static com.google.common.collect.Sets.newHashSet;
|
||||
import static org.alfresco.module.org_alfresco_module_rm.script.classification.ClassifyContentPost.CLASSIFICATION_AGENCY;
|
||||
import static org.alfresco.module.org_alfresco_module_rm.script.classification.ClassifyContentPost.CLASSIFICATION_LEVEL_ID;
|
||||
import static org.alfresco.module.org_alfresco_module_rm.script.classification.ClassifyContentPost.CLASSIFICATION_REASONS;
|
||||
@@ -29,11 +28,14 @@ import static org.alfresco.util.WebScriptUtils.putValuetoJSONObject;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationAspectProperties;
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationLevelManager;
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationReasonManager;
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.ContentClassificationService;
|
||||
@@ -41,6 +43,8 @@ import org.alfresco.module.org_alfresco_module_rm.test.util.BaseWebScriptUnitTes
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
@@ -74,13 +78,13 @@ public class ClassifyContentPostUnitTest extends BaseWebScriptUnitTest
|
||||
|
||||
/** Mocked content classification service */
|
||||
private @Mock ContentClassificationService mockedContentClassificationService;
|
||||
|
||||
/** Mocked classification level manager */
|
||||
private @Mock ClassificationLevelManager mockedClassificationLevelManager;
|
||||
|
||||
/** Mocked classification reason manager */
|
||||
private @Mock ClassificationReasonManager mockedClassificationReasonManager;
|
||||
|
||||
/** Captor for the classification aspect properties. */
|
||||
private @Captor ArgumentCaptor<ClassificationAspectProperties> propertiesDTOCaptor;
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseWebScriptUnitTest#getWebScript()
|
||||
*/
|
||||
@@ -120,7 +124,14 @@ public class ClassifyContentPostUnitTest extends BaseWebScriptUnitTest
|
||||
assertEquals(getStringValueFromJSONObject(json, SUCCESS), Boolean.TRUE.toString());
|
||||
|
||||
// Verify that the classify content method was called
|
||||
verify(mockedContentClassificationService, times(1)).classifyContent(LEVEL_ID, BY, AGENCY, newHashSet(REASON1_ID, REASON2_ID), record);
|
||||
verify(mockedContentClassificationService, times(1)).classifyContent(propertiesDTOCaptor.capture(), eq(record));
|
||||
|
||||
// Check the values in the DTO.
|
||||
ClassificationAspectProperties propertiesDTO = propertiesDTOCaptor.getValue();
|
||||
assertEquals(LEVEL_ID, propertiesDTO.getClassificationLevelId());
|
||||
assertEquals(BY, propertiesDTO.getClassifiedBy());
|
||||
assertEquals(AGENCY, propertiesDTO.getClassificationAgency());
|
||||
assertEquals(Sets.newHashSet(REASON1_ID, REASON2_ID), propertiesDTO.getClassificationReasonIds());
|
||||
}
|
||||
|
||||
@Test public void classifyingWithBlankClassifiedByShouldReturn4xxResponse() throws Exception
|
||||
|
Reference in New Issue
Block a user