diff --git a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/classification/classifycontent.post.desc.xml b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/classification/classifycontent.post.desc.xml
index 24e1e2d8a9..f84189983b 100644
--- a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/classification/classifycontent.post.desc.xml
+++ b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/classification/classifycontent.post.desc.xml
@@ -5,7 +5,6 @@
The body of the post should be in the form, e.g.
{
- "nodeRef": "workspace://SpacesStore/aNodeRefId",
"classificationLevelId": "aLevelId",
"classificationAuthority": "anAuthority",
"classificationReasons": [
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/classification/ClassifyContentPost.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/classification/ClassifyContentPost.java
index d4666a405c..4041f8d54e 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/classification/ClassifyContentPost.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/classification/ClassifyContentPost.java
@@ -46,9 +46,9 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
public class ClassifyContentPost extends AbstractRmWebScript
{
/** Constants */
- private static final String CLASSIFICATION_LEVEL_ID = "classificationLevelId";
- private static final String CLASSIFICATION_AUTHORITY = "classificationAuthority";
- private static final String CLASSIFICATION_REASONS = "classificationReasons";
+ public static final String CLASSIFICATION_LEVEL_ID = "classificationLevelId";
+ public static final String CLASSIFICATION_AUTHORITY = "classificationAuthority";
+ public static final String CLASSIFICATION_REASONS = "classificationReasons";
/** Classification service */
private ClassificationService classificationService;
@@ -77,8 +77,6 @@ public class ClassifyContentPost extends AbstractRmWebScript
@Override
protected Map executeImpl(WebScriptRequest req, Status status, Cache cache)
{
- Map model = new HashMap(1);
-
JSONObject jsonObject = getRequestContentAsJsonObject(req);
String classificationLevelId = getStringValueFromJSONObject(jsonObject, CLASSIFICATION_LEVEL_ID);
String classificationAuthority = getStringValueFromJSONObject(jsonObject, CLASSIFICATION_AUTHORITY);
@@ -86,6 +84,8 @@ public class ClassifyContentPost extends AbstractRmWebScript
NodeRef document = parseRequestForNodeRef(req);
getClassificationService().addClassificationToDocument(classificationLevelId, classificationAuthority, classificationReasonIds, document);
+
+ Map model = new HashMap(1);
model.put(SUCCESS, true);
return model;
diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/script/classification/ClassifyContentPostTest.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/script/classification/ClassifyContentPostTest.java
new file mode 100644
index 0000000000..0d7cee6bce
--- /dev/null
+++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/script/classification/ClassifyContentPostTest.java
@@ -0,0 +1,145 @@
+/*
+ * 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.script.classification;
+
+import static com.google.common.collect.Sets.newHashSet;
+import static org.alfresco.module.org_alfresco_module_rm.script.classification.ClassifyContentPost.CLASSIFICATION_AUTHORITY;
+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;
+import static org.alfresco.util.WebScriptUtils.getStringValueFromJSONObject;
+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.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import java.util.Map;
+
+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.ClassificationService;
+import org.alfresco.module.org_alfresco_module_rm.test.util.BaseWebScriptUnitTest;
+import org.json.JSONArray;
+import org.json.JSONObject;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Spy;
+import org.springframework.extensions.webscripts.DeclarativeWebScript;
+
+/**
+ * Classify content REST API POST implementation unit test.
+ *
+ * @author Tuna Aksoy
+ * @since 3.0
+ */
+public class ClassifyContentPostTest extends BaseWebScriptUnitTest
+{
+ /** Classpath location of ftl template for web script */
+ private static final String WEBSCRIPT_TEMPLATE = WEBSCRIPT_ROOT_RM + "classification/classifycontent.post.json.ftl";
+
+ /** Constants */
+ private static final String STORE_TYPE = "store_type";
+ private static final String STORE_ID = "store_id";
+ private static final String ID = "id";
+ private static final String SUCCESS = "success";
+ private static final String LEVEL_ID = "aLevelId";
+ private static final String AUTHORITY = "anAuthority";
+ private static final String REASON1_ID = "reason1Id";
+ private static final String REASON2_ID = "reason2Id";
+
+ /** ClassifyContentPost webscript instance */
+ private @Spy @InjectMocks ClassifyContentPost webScript;
+
+ /** Mocked classification service */
+ private @Mock ClassificationService mockedClassificationService;
+
+ /** Mocked classification level manager */
+ private @Mock ClassificationLevelManager mockedClassificationLevelManager;
+
+ /** Mocked classification reason manager */
+ private @Mock ClassificationReasonManager mockedClassificationReasonManager;
+
+ /**
+ * @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseWebScriptUnitTest#getWebScript()
+ */
+ @Override
+ protected DeclarativeWebScript getWebScript()
+ {
+ return webScript;
+ }
+
+ /**
+ * @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseWebScriptUnitTest#getWebScriptTemplate()
+ */
+ @Override
+ protected String getWebScriptTemplate()
+ {
+ return WEBSCRIPT_TEMPLATE;
+ }
+
+ @Test
+ public void testClassifyContent() throws Exception
+ {
+ // Setup web script parameters
+ Map parameters = buildParameters
+ (
+ STORE_TYPE, record.getStoreRef().getProtocol(),
+ STORE_ID, record.getStoreRef().getIdentifier(),
+ ID, record.getId()
+ );
+
+ // Build JSON to send to server
+ String content = buildContent();
+
+ // Execute web script
+ JSONObject json = executeJSONWebScript(parameters, content);
+ assertNotNull(json);
+ assertTrue(json.has(SUCCESS));
+ assertEquals(getStringValueFromJSONObject(json, SUCCESS), Boolean.TRUE.toString());
+
+ // Verify that the classify content method was called
+ verify(mockedClassificationService, times(1)).addClassificationToDocument(LEVEL_ID, AUTHORITY, newHashSet(REASON1_ID, REASON2_ID), record);
+ }
+
+ /**
+ * Helper method to build the request content
+ *
+ * @return The request content as {@link String}
+ */
+ private String buildContent()
+ {
+ JSONObject content = new JSONObject();
+ putValuetoJSONObject(content, CLASSIFICATION_LEVEL_ID, LEVEL_ID);
+ putValuetoJSONObject(content, CLASSIFICATION_AUTHORITY, AUTHORITY);
+
+ JSONObject classificationReason1 = new JSONObject();
+ putValuetoJSONObject(classificationReason1, ID, REASON1_ID);
+ JSONObject classificationReason2 = new JSONObject();
+ putValuetoJSONObject(classificationReason2, ID, REASON2_ID);
+
+ JSONArray classificationReasons = new JSONArray();
+ classificationReasons.put(classificationReason1);
+ classificationReasons.put(classificationReason2);
+ putValuetoJSONObject(content, CLASSIFICATION_REASONS, classificationReasons);
+
+ return content.toString();
+ }
+}
diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/test/AllUnitTestSuite.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/test/AllUnitTestSuite.java
index 7cdada2dba..138ac83e10 100644
--- a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/test/AllUnitTestSuite.java
+++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/test/AllUnitTestSuite.java
@@ -39,6 +39,7 @@ import org.alfresco.module.org_alfresco_module_rm.record.RecordServiceImplUnitTe
import org.alfresco.module.org_alfresco_module_rm.recorded.version.config.RecordedVersionConfigGetTest;
import org.alfresco.module.org_alfresco_module_rm.recorded.version.config.RecordedVersionConfigPostTest;
import org.alfresco.module.org_alfresco_module_rm.script.classification.ClassificationLevelsGetTest;
+import org.alfresco.module.org_alfresco_module_rm.script.classification.ClassifyContentPost;
import org.alfresco.module.org_alfresco_module_rm.script.classification.ReasonsGetTest;
import org.alfresco.module.org_alfresco_module_rm.script.hold.HoldPostUnitTest;
import org.alfresco.module.org_alfresco_module_rm.script.hold.HoldPutUnitTest;
@@ -85,6 +86,7 @@ import org.junit.runners.Suite.SuiteClasses;
HoldPutUnitTest.class,
ReasonsGetTest.class,
ClassificationLevelsGetTest.class,
+ ClassifyContentPost.class,
// action implementations
FileReportActionUnitTest.class,