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:
Tuna Aksoy
2015-04-19 19:49:22 +00:00
parent 69dda6b842
commit f78917ea24
4 changed files with 152 additions and 6 deletions

View File

@@ -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();
}
}

View File

@@ -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,