From aaecf7ad809097a5fe2abb5f638f409cb4f4157c Mon Sep 17 00:00:00 2001 From: Tuna Aksoy Date: Mon, 8 Jun 2015 13:53:44 +0000 Subject: [PATCH] RM-2280 (Move the code for checking if the content is classified to the service layer) * Added integration tests +review RM-87 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@105748 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../jscript/app/JSONConversionComponent.java | 2 +- .../jscript/JSONConversionComponentTest.java | 247 +++++++++++++++++- 2 files changed, 247 insertions(+), 2 deletions(-) diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/jscript/app/JSONConversionComponent.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/jscript/app/JSONConversionComponent.java index ed13840379..75c24aceba 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/jscript/app/JSONConversionComponent.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/jscript/app/JSONConversionComponent.java @@ -69,7 +69,7 @@ public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JS private static final String IS_RM_SITE_CREATED = "isRmSiteCreated"; private static final String IS_RECORD_CONTRIBUTOR_GROUP_ENABLED = "isRecordContributorGroupEnabled"; private static final String RECORD_CONTRIBUTOR_GROUP_NAME = "recordContributorGroupName"; - private static final String IS_CLASSIFIED = "isClassified"; + public static final String IS_CLASSIFIED = "isClassified"; /** true if record contributor group is enabled, false otherwise */ private boolean isRecordContributorsGroupEnabled = false; diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/jscript/JSONConversionComponentTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/jscript/JSONConversionComponentTest.java index 1af499ba9f..e9cd9edf69 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/jscript/JSONConversionComponentTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/jscript/JSONConversionComponentTest.java @@ -18,8 +18,14 @@ */ package org.alfresco.module.org_alfresco_module_rm.test.legacy.jscript; +import static com.google.common.collect.Sets.newHashSet; +import static org.alfresco.module.org_alfresco_module_rm.classification.ClassificationLevelManager.UNCLASSIFIED_ID; +import static org.alfresco.module.org_alfresco_module_rm.jscript.app.JSONConversionComponent.IS_CLASSIFIED; +import static org.alfresco.util.GUID.generate; + import java.io.Serializable; +import org.alfresco.module.org_alfresco_module_rm.classification.ContentClassificationService; import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; import org.alfresco.repo.jscript.app.JSONConversionComponent; import org.alfresco.service.cmr.repository.NodeRef; @@ -32,7 +38,11 @@ import org.json.JSONObject; */ public class JSONConversionComponentTest extends BaseRMTestCase { + private static final String LEVEL1 = "level1"; + private static final String REASON1 = "Test Reason 1"; + private JSONConversionComponent converter; + private ContentClassificationService contentClassificationService; private NodeRef record; @@ -40,7 +50,8 @@ public class JSONConversionComponentTest extends BaseRMTestCase protected void initServices() { super.initServices(); - converter = (JSONConversionComponent)applicationContext.getBean("jsonConversionComponent"); + converter = (JSONConversionComponent) applicationContext.getBean("jsonConversionComponent"); + contentClassificationService = (ContentClassificationService) applicationContext.getBean("ContentClassificationService"); } @Override @@ -52,6 +63,240 @@ public class JSONConversionComponentTest extends BaseRMTestCase record = utils.createRecord(rmFolder, "testRecord.txt"); } + @Override + protected boolean isCollaborationSiteTest() + { + return true; + } + + /** + * Given a record exists in the RM site + * When I classify the record with a level not equal to "Unclassified" and convert it + * Then the result should include an attribute "isClassified" with the value "true" + */ + public void testClassifyRecord_classified() + { + doBehaviourDrivenTest(new BehaviourDrivenTest() + { + private NodeRef record; + private String jsonString; + + @Override + public void given() throws Exception + { + NodeRef category = filePlanService.createRecordCategory(filePlan, generate()); + NodeRef folder = recordFolderService.createRecordFolder(category, generate()); + record = utils.createRecord(folder, generate()); + } + + @Override + public void when() throws Exception + { + contentClassificationService.classifyContent(LEVEL1, generate(), newHashSet(REASON1), record); + jsonString = converter.toJSON(record, true); + } + + @Override + public void then() throws Exception + { + assertNotNull(jsonString); + JSONObject jsonObject = new JSONObject(jsonString); + Object isClassifiedObject = jsonObject.get(IS_CLASSIFIED); + assertNotNull(isClassifiedObject); + assertTrue(((Boolean) isClassifiedObject).booleanValue()); + } + }); + } + + /** + * Given a record exists in the RM site + * When I classify the record with the level "Unclassified" and convert it + * Then the result should include an attribute "isClassified" with the value "false" + */ + public void testClassifyRecord_unclassified() + { + doBehaviourDrivenTest(new BehaviourDrivenTest() + { + private NodeRef record; + private String jsonString; + + @Override + public void given() throws Exception + { + NodeRef category = filePlanService.createRecordCategory(filePlan, generate()); + NodeRef folder = recordFolderService.createRecordFolder(category, generate()); + record = utils.createRecord(folder, generate()); + } + + @Override + public void when() throws Exception + { + contentClassificationService.classifyContent(UNCLASSIFIED_ID, generate(), newHashSet(REASON1), record); + jsonString = converter.toJSON(record, true); + } + + @Override + public void then() throws Exception + { + assertNotNull(jsonString); + JSONObject jsonObject = new JSONObject(jsonString); + Object isClassifiedObject = jsonObject.get(IS_CLASSIFIED); + assertNotNull(isClassifiedObject); + assertFalse(((Boolean) isClassifiedObject).booleanValue()); + } + }); + } + + /** + * Given a record exists in the RM site + * When I classify the record with the level "Unclassified" and convert it + * Then the result should include an attribute "isClassified" with the value "false" + */ + public void testClassifyRecord_notclassified() + { + doBehaviourDrivenTest(new BehaviourDrivenTest() + { + private NodeRef record; + private String jsonString; + + @Override + public void given() throws Exception + { + NodeRef category = filePlanService.createRecordCategory(filePlan, generate()); + NodeRef folder = recordFolderService.createRecordFolder(category, generate()); + record = utils.createRecord(folder, generate()); + } + + @Override + public void when() throws Exception + { + jsonString = converter.toJSON(record, true); + } + + @Override + public void then() throws Exception + { + assertNotNull(jsonString); + JSONObject jsonObject = new JSONObject(jsonString); + Object isClassifiedObject = jsonObject.get(IS_CLASSIFIED); + assertNotNull(isClassifiedObject); + assertFalse(((Boolean) isClassifiedObject).booleanValue()); + } + }); + } + + /** + * Given a file exists in a collaboration site + * When I classify the file with a level not equal to "Unclassified" and convert it + * Then the result should include an attribute "isClassified" with the value "true" + */ + public void testClassifyFile_classified() + { + doBehaviourDrivenTest(new BehaviourDrivenTest() + { + private NodeRef file; + private String jsonString; + + @Override + public void given() throws Exception + { + file = fileFolderService.create(documentLibrary, generate(), TYPE_CONTENT).getNodeRef(); + } + + @Override + public void when() throws Exception + { + contentClassificationService.classifyContent(LEVEL1, generate(), newHashSet(REASON1), file); + jsonString = converter.toJSON(file, true); + } + + @Override + public void then() throws Exception + { + assertNotNull(jsonString); + JSONObject jsonObject = new JSONObject(jsonString); + Object isClassifiedObject = jsonObject.get(IS_CLASSIFIED); + assertNotNull(isClassifiedObject); + assertTrue(((Boolean) isClassifiedObject).booleanValue()); + } + }); + } + + /** + * Given a file exists in a collaboration site + * When I classify the file with the level "Unclassified" and convert it + * Then the result should include an attribute "isClassified" with the value "false" + */ + public void testClassifyFile_unclassified() + { + doBehaviourDrivenTest(new BehaviourDrivenTest() + { + private NodeRef file; + private String jsonString; + + @Override + public void given() throws Exception + { + file = fileFolderService.create(documentLibrary, generate(), TYPE_CONTENT).getNodeRef(); + } + + @Override + public void when() throws Exception + { + contentClassificationService.classifyContent(UNCLASSIFIED_ID, generate(), newHashSet(REASON1), file); + jsonString = converter.toJSON(file, true); + } + + @Override + public void then() throws Exception + { + assertNotNull(jsonString); + JSONObject jsonObject = new JSONObject(jsonString); + Object isClassifiedObject = jsonObject.get(IS_CLASSIFIED); + assertNotNull(isClassifiedObject); + assertFalse(((Boolean) isClassifiedObject).booleanValue()); + } + }); + } + + /** + * Given a file exists in a collaboration site + * When I classify the file with the level "Unclassified" and convert it + * Then the result should include an attribute "isClassified" with the value "false" + */ + public void testClassifyFile_notclassified() + { + doBehaviourDrivenTest(new BehaviourDrivenTest() + { + private NodeRef file; + private String jsonString; + + @Override + public void given() throws Exception + { + NodeRef category = filePlanService.createRecordCategory(filePlan, generate()); + NodeRef folder = recordFolderService.createRecordFolder(category, generate()); + file = utils.createRecord(folder, generate()); + } + + @Override + public void when() throws Exception + { + jsonString = converter.toJSON(file, true); + } + + @Override + public void then() throws Exception + { + assertNotNull(jsonString); + JSONObject jsonObject = new JSONObject(jsonString); + Object isClassifiedObject = jsonObject.get(IS_CLASSIFIED); + assertNotNull(isClassifiedObject); + assertFalse(((Boolean) isClassifiedObject).booleanValue()); + } + }); + } + public void testJSON() throws Exception { doTestInTransaction(new JSONTest