mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
RM-2047 (Set classification repository action)
* Unit test added +review RM-28 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@102153 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -5,7 +5,6 @@
|
|||||||
<br/>
|
<br/>
|
||||||
The body of the post should be in the form, e.g.<br/>
|
The body of the post should be in the form, e.g.<br/>
|
||||||
{<br/>
|
{<br/>
|
||||||
"nodeRef": "workspace://SpacesStore/aNodeRefId",<br/>
|
|
||||||
"classificationLevelId": "aLevelId",<br/>
|
"classificationLevelId": "aLevelId",<br/>
|
||||||
"classificationAuthority": "anAuthority",<br/>
|
"classificationAuthority": "anAuthority",<br/>
|
||||||
"classificationReasons": [<br/>
|
"classificationReasons": [<br/>
|
||||||
|
@@ -46,9 +46,9 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
|
|||||||
public class ClassifyContentPost extends AbstractRmWebScript
|
public class ClassifyContentPost extends AbstractRmWebScript
|
||||||
{
|
{
|
||||||
/** Constants */
|
/** Constants */
|
||||||
private static final String CLASSIFICATION_LEVEL_ID = "classificationLevelId";
|
public static final String CLASSIFICATION_LEVEL_ID = "classificationLevelId";
|
||||||
private static final String CLASSIFICATION_AUTHORITY = "classificationAuthority";
|
public static final String CLASSIFICATION_AUTHORITY = "classificationAuthority";
|
||||||
private static final String CLASSIFICATION_REASONS = "classificationReasons";
|
public static final String CLASSIFICATION_REASONS = "classificationReasons";
|
||||||
|
|
||||||
/** Classification service */
|
/** Classification service */
|
||||||
private ClassificationService classificationService;
|
private ClassificationService classificationService;
|
||||||
@@ -77,8 +77,6 @@ public class ClassifyContentPost extends AbstractRmWebScript
|
|||||||
@Override
|
@Override
|
||||||
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
||||||
{
|
{
|
||||||
Map<String, Object> model = new HashMap<String, Object>(1);
|
|
||||||
|
|
||||||
JSONObject jsonObject = getRequestContentAsJsonObject(req);
|
JSONObject jsonObject = getRequestContentAsJsonObject(req);
|
||||||
String classificationLevelId = getStringValueFromJSONObject(jsonObject, CLASSIFICATION_LEVEL_ID);
|
String classificationLevelId = getStringValueFromJSONObject(jsonObject, CLASSIFICATION_LEVEL_ID);
|
||||||
String classificationAuthority = getStringValueFromJSONObject(jsonObject, CLASSIFICATION_AUTHORITY);
|
String classificationAuthority = getStringValueFromJSONObject(jsonObject, CLASSIFICATION_AUTHORITY);
|
||||||
@@ -86,6 +84,8 @@ public class ClassifyContentPost extends AbstractRmWebScript
|
|||||||
NodeRef document = parseRequestForNodeRef(req);
|
NodeRef document = parseRequestForNodeRef(req);
|
||||||
|
|
||||||
getClassificationService().addClassificationToDocument(classificationLevelId, classificationAuthority, classificationReasonIds, document);
|
getClassificationService().addClassificationToDocument(classificationLevelId, classificationAuthority, classificationReasonIds, document);
|
||||||
|
|
||||||
|
Map<String, Object> model = new HashMap<String, Object>(1);
|
||||||
model.put(SUCCESS, true);
|
model.put(SUCCESS, true);
|
||||||
|
|
||||||
return model;
|
return model;
|
||||||
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
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<String, String> 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();
|
||||||
|
}
|
||||||
|
}
|
@@ -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.RecordedVersionConfigGetTest;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.recorded.version.config.RecordedVersionConfigPostTest;
|
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.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.classification.ReasonsGetTest;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.script.hold.HoldPostUnitTest;
|
import org.alfresco.module.org_alfresco_module_rm.script.hold.HoldPostUnitTest;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.script.hold.HoldPutUnitTest;
|
import org.alfresco.module.org_alfresco_module_rm.script.hold.HoldPutUnitTest;
|
||||||
@@ -85,6 +86,7 @@ import org.junit.runners.Suite.SuiteClasses;
|
|||||||
HoldPutUnitTest.class,
|
HoldPutUnitTest.class,
|
||||||
ReasonsGetTest.class,
|
ReasonsGetTest.class,
|
||||||
ClassificationLevelsGetTest.class,
|
ClassificationLevelsGetTest.class,
|
||||||
|
ClassifyContentPost.class,
|
||||||
|
|
||||||
// action implementations
|
// action implementations
|
||||||
FileReportActionUnitTest.class,
|
FileReportActionUnitTest.class,
|
||||||
|
Reference in New Issue
Block a user