mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-1633 (Recorded Version Configuration Action)
* Added unit tests git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@83131 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
<#list recordableVersions as recordableVersion>
|
||||
{
|
||||
"policy": "${recordableVersion.policy}",
|
||||
"selected": ${recordableVersion.selected?c}
|
||||
"selected": "${recordableVersion.selected?string("true", "false")}"
|
||||
}<#if recordableVersion_has_next>,</#if>
|
||||
</#list>
|
||||
]
|
||||
|
@@ -43,7 +43,7 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
public class RecordedVersionConfigPost extends AbstractRmWebScript implements RecordableVersionModel
|
||||
{
|
||||
// Constant for recorded version parameter
|
||||
private static final String RECORDED_VERSION = "recordedVersion";
|
||||
public static final String RECORDED_VERSION = "recordedVersion";
|
||||
|
||||
/**
|
||||
* @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.Status, org.alfresco.web.scripts.Cache)
|
||||
|
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2014 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.recorded.version.config;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseWebScriptUnitTest;
|
||||
import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionModel;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* Base test class for the recorded version config tests
|
||||
*
|
||||
* @author Tuna Aksoy
|
||||
* @since 2.3
|
||||
*/
|
||||
public abstract class BaseRecordedVersionConfigTest extends BaseWebScriptUnitTest implements RecordableVersionModel
|
||||
{
|
||||
/** Recorded version config web script root folder */
|
||||
protected static final String RECORDED_VERSION_CONFIG_WEBSCRIPT_ROOT = "alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/action/";
|
||||
|
||||
/** Node ref for test document */
|
||||
protected NodeRef testdoc;
|
||||
|
||||
/** setup web script parameters */
|
||||
protected Map<String, String> buildParameters()
|
||||
{
|
||||
testdoc = generateCmContent("testdoc.txt");
|
||||
|
||||
return buildParameters
|
||||
(
|
||||
"store_type", testdoc.getStoreRef().getProtocol(),
|
||||
"store_id", testdoc.getStoreRef().getIdentifier(),
|
||||
"id", testdoc.getId()
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2014 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.recorded.version.config;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.script.slingshot.RecordedVersionConfigGet;
|
||||
import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionPolicy;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.springframework.extensions.webscripts.DeclarativeWebScript;
|
||||
|
||||
/**
|
||||
* Recorded Version Config REST API GET implementation unit test.
|
||||
*
|
||||
* @author Tuna Aksoy
|
||||
* @since 2.3
|
||||
*/
|
||||
public class RecordedVersionConfigGetTest extends BaseRecordedVersionConfigTest
|
||||
{
|
||||
/** RecordedVersionConfigGet webscript instance */
|
||||
protected @InjectMocks RecordedVersionConfigGet webScript;
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.recorded.version.config.BaseRecordedVersionConfigTest#getWebScript()
|
||||
*/
|
||||
@Override
|
||||
protected DeclarativeWebScript getWebScript()
|
||||
{
|
||||
return webScript;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.recorded.version.config.BaseRecordedVersionConfigTest#getWebScriptTemplate()
|
||||
*/
|
||||
@Override
|
||||
protected String getWebScriptTemplate()
|
||||
{
|
||||
return RECORDED_VERSION_CONFIG_WEBSCRIPT_ROOT + "recorded-version-config.get.json.ftl";
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRecordedVersionConfig() throws Exception
|
||||
{
|
||||
// Build parameters
|
||||
Map<String, String> parameters = buildParameters();
|
||||
|
||||
// Test document should not have any recordable version policy set
|
||||
doReturn(null).when(mockedNodeService).getProperty(testdoc, PROP_RECORDABLE_VERSION_POLICY);
|
||||
|
||||
// execute web script
|
||||
JSONObject json = executeJSONWebScript(parameters);
|
||||
|
||||
// Do checks
|
||||
assertNotNull(json);
|
||||
|
||||
assertTrue(json.has("data"));
|
||||
JSONObject data = json.getJSONObject("data");
|
||||
assertNotNull(data);
|
||||
|
||||
assertTrue(data.has("recordableVersions"));
|
||||
JSONArray recordableVersions = data.getJSONArray("recordableVersions");
|
||||
assertNotNull(recordableVersions);
|
||||
assertEquals(recordableVersions.length(), 3);
|
||||
|
||||
List<RecordableVersionPolicy> policies = new ArrayList<RecordableVersionPolicy>();
|
||||
boolean isSelected = false;
|
||||
int selectedOnce = 0;
|
||||
for (int i = 0; i < recordableVersions.length(); i++)
|
||||
{
|
||||
JSONObject jsonObject = recordableVersions.getJSONObject(i);
|
||||
String policy = jsonObject.getString("policy");
|
||||
policies.add(RecordableVersionPolicy.valueOf(policy));
|
||||
boolean selected = Boolean.valueOf(jsonObject.getString("selected")).booleanValue();
|
||||
if (selected)
|
||||
{
|
||||
isSelected = true;
|
||||
selectedOnce++;
|
||||
}
|
||||
}
|
||||
assertEquals(policies, Arrays.asList(RecordableVersionPolicy.values()));
|
||||
assertTrue(isSelected);
|
||||
assertEquals(selectedOnce, 1);
|
||||
|
||||
// Test document should still not have any recordable version policy set
|
||||
doReturn(null).when(mockedNodeService).getProperty(testdoc, PROP_RECORDABLE_VERSION_POLICY);
|
||||
}
|
||||
}
|
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2014 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.recorded.version.config;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.script.slingshot.RecordedVersionConfigPost;
|
||||
import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionPolicy;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.springframework.extensions.webscripts.DeclarativeWebScript;
|
||||
|
||||
/**
|
||||
* Recorded Version Config REST API POST implementation unit test.
|
||||
*
|
||||
* @author Tuna Aksoy
|
||||
* @since 2.3
|
||||
*/
|
||||
public class RecordedVersionConfigPostTest extends BaseRecordedVersionConfigTest
|
||||
{
|
||||
/** RecordedVersionConfigPost webscript instance */
|
||||
protected @InjectMocks RecordedVersionConfigPost webScript;
|
||||
|
||||
/**
|
||||
* @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 RECORDED_VERSION_CONFIG_WEBSCRIPT_ROOT + "recorded-version-config.post.json.ftl";
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setRecordedVersionConfig() throws Exception
|
||||
{
|
||||
RecordableVersionPolicy policy = RecordableVersionPolicy.ALL;
|
||||
|
||||
// Build the content
|
||||
String content = buildContent(policy);
|
||||
|
||||
// Build parameters
|
||||
Map<String, String> parameters = buildParameters();
|
||||
|
||||
// Test document should not have any recordable version policy set
|
||||
doReturn(null).when(mockedNodeService).getProperty(testdoc, PROP_RECORDABLE_VERSION_POLICY);
|
||||
|
||||
// execute web script
|
||||
JSONObject json = executeJSONWebScript(parameters, content);
|
||||
|
||||
// Do checks
|
||||
assertNotNull(json);
|
||||
assertEquals(json.length(), 0);
|
||||
|
||||
// Test document must have recordable version policy "ALL" set
|
||||
doReturn(policy).when(mockedNodeService).getProperty(testdoc, PROP_RECORDABLE_VERSION_POLICY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to build the content for the POST request
|
||||
* @param policy The recordable version policy
|
||||
*
|
||||
* @return Content for the build request
|
||||
*/
|
||||
private String buildContent(RecordableVersionPolicy policy)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("{\"");
|
||||
sb.append(RecordedVersionConfigPost.RECORDED_VERSION);
|
||||
sb.append("\":\"");
|
||||
sb.append(policy.toString());
|
||||
sb.append("\"}");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@@ -29,6 +29,8 @@ import org.alfresco.module.org_alfresco_module_rm.model.compatibility.Dictionary
|
||||
import org.alfresco.module.org_alfresco_module_rm.patch.v22.RMv22RemoveInPlaceRolesFromAllPatchUnitTest;
|
||||
import org.alfresco.module.org_alfresco_module_rm.record.RecordMetadataBootstrapUnitTest;
|
||||
import org.alfresco.module.org_alfresco_module_rm.record.RecordServiceImplUnitTest;
|
||||
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.hold.HoldPostUnitTest;
|
||||
import org.alfresco.module.org_alfresco_module_rm.script.hold.HoldPutUnitTest;
|
||||
import org.alfresco.module.org_alfresco_module_rm.script.hold.HoldsGetUnitTest;
|
||||
@@ -54,30 +56,34 @@ import org.junit.runners.Suite.SuiteClasses;
|
||||
DictionaryBootstrapPostProcessorUnitTest.class,
|
||||
BeanExtenderUnitTest.class,
|
||||
DateParameterProcessorUnitTest.class,
|
||||
|
||||
|
||||
// services
|
||||
RecordServiceImplUnitTest.class,
|
||||
HoldServiceImplUnitTest.class,
|
||||
// FilePlanPermissionServiceImplUnitTest.class, // removed because test unreliable on Bamboo
|
||||
RecordableVersionServiceImplUnitTest.class,
|
||||
|
||||
|
||||
// evaluators
|
||||
TransferEvaluatorUnitTest.class,
|
||||
FrozenEvaluatorUnitTest.class,
|
||||
|
||||
|
||||
// web scripts
|
||||
HoldsGetUnitTest.class,
|
||||
HoldPostUnitTest.class,
|
||||
HoldPutUnitTest.class,
|
||||
|
||||
|
||||
// capability conditions
|
||||
HoldCapabilityConditionUnitTest.class,
|
||||
|
||||
|
||||
// action implementations
|
||||
FileReportActionUnitTest.class,
|
||||
|
||||
|
||||
// patches
|
||||
RMv22RemoveInPlaceRolesFromAllPatchUnitTest.class
|
||||
RMv22RemoveInPlaceRolesFromAllPatchUnitTest.class,
|
||||
|
||||
// recorded version config
|
||||
RecordedVersionConfigGetTest.class,
|
||||
RecordedVersionConfigPostTest.class
|
||||
})
|
||||
public class AllUnitTestSuite
|
||||
{
|
||||
|
Reference in New Issue
Block a user