mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
Changed REST API tests for DataSets
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@44430 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -22,8 +22,7 @@ import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.webscript.BootstraptestDataRestApiTest;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.webscript.DataSetPostTest;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.webscript.DataSetsGetTest;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.webscript.DataSetRestApiTest;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.webscript.DispositionRestApiTest;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.webscript.EventRestApiTest;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.webscript.RMCaveatConfigScriptTest;
|
||||
@@ -54,8 +53,7 @@ public class WebScriptTestSuite extends TestSuite
|
||||
suite.addTestSuite(RMConstraintScriptTest.class);
|
||||
suite.addTestSuite(RmRestApiTest.class);
|
||||
suite.addTestSuite(RoleRestApiTest.class);
|
||||
suite.addTestSuite(DataSetsGetTest.class);
|
||||
suite.addTestSuite(DataSetPostTest.class);
|
||||
suite.addTestSuite(DataSetRestApiTest.class);
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
|
@@ -1,83 +0,0 @@
|
||||
package org.alfresco.module.org_alfresco_module_rm.test.webscript;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMWebScriptTestCase;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
|
||||
|
||||
public class DataSetPostTest extends BaseRMWebScriptTestCase
|
||||
{
|
||||
/** URL for the REST APIs */
|
||||
private static final String GET_DATASETS_URL = "/api/rma/datasets?site=%s";
|
||||
private static final String POST_DATASET_URL = "/api/rma/datasets/%s?site=%s";
|
||||
|
||||
/** Constant for the content type */
|
||||
private static final String APPLICATION_JSON = "application/json";
|
||||
|
||||
/**
|
||||
* Test the REST API to import a RM data set into a file plan
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws JSONException
|
||||
*/
|
||||
public void testPostDataSetAction() throws IOException, JSONException
|
||||
{
|
||||
String dataSetId = getDataSetId();
|
||||
if (StringUtils.isNotBlank(dataSetId))
|
||||
{
|
||||
// Format url and send request
|
||||
String url = String.format(POST_DATASET_URL, dataSetId, SITE_ID);
|
||||
Response response = sendRequest(new PostRequest(url, new JSONObject().toString(), APPLICATION_JSON), Status.STATUS_OK);
|
||||
|
||||
// Check the content from the response
|
||||
String contentAsString = response.getContentAsString();
|
||||
assertNotNull(contentAsString);
|
||||
|
||||
// Convert the response to json and check the result
|
||||
JSONObject contentAsJson = new JSONObject(contentAsString);
|
||||
String success = contentAsJson.getString("success");
|
||||
assertNotNull(success);
|
||||
assertTrue(success.equals("true"));
|
||||
|
||||
// It is not possible to import the same data set into the same file plan
|
||||
response = sendRequest(new PostRequest(url, new JSONObject().toString(), APPLICATION_JSON), Status.STATUS_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method for getting a data set id
|
||||
*
|
||||
* @return A data set id from the list of available data sets or null if there is no data set
|
||||
* @throws IOException
|
||||
* @throws JSONException
|
||||
*/
|
||||
private String getDataSetId() throws IOException, JSONException
|
||||
{
|
||||
// Format url and send request
|
||||
String url = String.format(GET_DATASETS_URL, SITE_ID);
|
||||
Response response = sendRequest(new GetRequest(url), Status.STATUS_OK);
|
||||
|
||||
// Get the response as string, convert to json and retrieve the data sets
|
||||
String contentAsString = response.getContentAsString();
|
||||
JSONObject contentAsJson = new JSONObject(contentAsString);
|
||||
JSONObject data = contentAsJson.getJSONObject("data");
|
||||
JSONArray dataSets = data.getJSONArray("datasets");
|
||||
|
||||
// Check if there are some test data sets
|
||||
String dataSetId = null;
|
||||
if (dataSets.length() > 0)
|
||||
{
|
||||
JSONObject dataSet = (JSONObject) dataSets.get(0);
|
||||
dataSetId = (String) dataSet.get("id");
|
||||
}
|
||||
|
||||
return dataSetId;
|
||||
}
|
||||
}
|
@@ -0,0 +1,95 @@
|
||||
package org.alfresco.module.org_alfresco_module_rm.test.webscript;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMWebScriptTestCase;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
|
||||
|
||||
public class DataSetRestApiTest extends BaseRMWebScriptTestCase
|
||||
{
|
||||
/** URL for the REST APIs */
|
||||
private static final String GET_DATASETS_URL = "/api/rma/datasets?site=%s";
|
||||
private static final String POST_DATASET_URL = "/api/rma/datasets/%s?site=%s";
|
||||
|
||||
/** Constant for the content type */
|
||||
private static final String APPLICATION_JSON = "application/json";
|
||||
|
||||
/**
|
||||
* Test the REST API to retrieve details of available RM data sets
|
||||
* and to import an RM data set into a file plan
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws JSONException
|
||||
*/
|
||||
public void testGetPostDataSetAction() throws IOException, JSONException
|
||||
{
|
||||
/** Test GET */
|
||||
|
||||
// Format url and send request
|
||||
String getUrl = String.format(GET_DATASETS_URL, SITE_ID);
|
||||
Response getResponse = sendRequest(new GetRequest(getUrl), Status.STATUS_OK);
|
||||
|
||||
// Check the content from the response
|
||||
String getContentAsString = getResponse.getContentAsString();
|
||||
assertNotNull(getContentAsString);
|
||||
|
||||
// Convert the response to json and check the data
|
||||
JSONObject getContentAsJson = new JSONObject(getContentAsString);
|
||||
JSONObject getData = getContentAsJson.getJSONObject("data");
|
||||
assertNotNull(getData);
|
||||
|
||||
// Get the data sets and check them
|
||||
JSONArray getDataSets = getData.getJSONArray("datasets");
|
||||
assertNotNull(getDataSets);
|
||||
|
||||
// Check the label and the id of the data sets
|
||||
for (int i = 0; i < getDataSets.length(); i++)
|
||||
{
|
||||
JSONObject dataSet = (JSONObject) getDataSets.get(i);
|
||||
assertTrue(dataSet.length() == 3);
|
||||
assertNotNull(dataSet.get("label"));
|
||||
assertNotNull(dataSet.get("id"));
|
||||
assertNotNull(dataSet.get("isLoaded"));
|
||||
}
|
||||
|
||||
/** Test POST */
|
||||
String dataSetId = getDataSets.getJSONObject(0).getString("id");
|
||||
if (StringUtils.isNotBlank(dataSetId))
|
||||
{
|
||||
// Format url and send request
|
||||
String url = String.format(POST_DATASET_URL, dataSetId, SITE_ID);
|
||||
Response response = sendRequest(new PostRequest(url, new JSONObject().toString(), APPLICATION_JSON), Status.STATUS_OK);
|
||||
|
||||
// Check the content from the response
|
||||
String contentAsString = response.getContentAsString();
|
||||
assertNotNull(contentAsString);
|
||||
|
||||
// Convert the response to json and check the result
|
||||
JSONObject contentAsJson = new JSONObject(contentAsString);
|
||||
String success = contentAsJson.getString("success");
|
||||
assertNotNull(success);
|
||||
assertTrue(success.equals("true"));
|
||||
|
||||
// It is not possible to import the same data set into the same file plan
|
||||
response = sendRequest(new PostRequest(url, new JSONObject().toString(), APPLICATION_JSON), Status.STATUS_OK);
|
||||
|
||||
// Check the content from the response
|
||||
contentAsString = response.getContentAsString();
|
||||
assertNotNull(contentAsString);
|
||||
|
||||
// Convert the response to json and check the result
|
||||
contentAsJson = new JSONObject(contentAsString);
|
||||
success = contentAsJson.getString("success");
|
||||
assertNotNull(success);
|
||||
assertTrue(success.equals("false"));
|
||||
assertNotNull(contentAsJson.getString("message"));
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,53 +0,0 @@
|
||||
package org.alfresco.module.org_alfresco_module_rm.test.webscript;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMWebScriptTestCase;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
|
||||
|
||||
public class DataSetsGetTest extends BaseRMWebScriptTestCase
|
||||
{
|
||||
/** URL for the REST API */
|
||||
private static final String GET_DATASETS_URL = "/api/rma/datasets?site=%s";
|
||||
|
||||
/**
|
||||
* Test the REST API to retrieve details of available RM data sets
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws JSONException
|
||||
*/
|
||||
public void testGetDataSetsAction() throws IOException, JSONException
|
||||
{
|
||||
// Format url and send request
|
||||
String url = String.format(GET_DATASETS_URL, SITE_ID);
|
||||
Response response = sendRequest(new GetRequest(url), Status.STATUS_OK);
|
||||
|
||||
// Check the content from the response
|
||||
String contentAsString = response.getContentAsString();
|
||||
assertNotNull(contentAsString);
|
||||
|
||||
// Convert the response to json and check the data
|
||||
JSONObject contentAsJson = new JSONObject(contentAsString);
|
||||
JSONObject data = contentAsJson.getJSONObject("data");
|
||||
assertNotNull(data);
|
||||
|
||||
// Get the data sets and check them
|
||||
JSONArray dataSets = data.getJSONArray("datasets");
|
||||
assertNotNull(dataSets);
|
||||
|
||||
// Check the label and the id of the data sets
|
||||
for (int i = 0; i < dataSets.length(); i++)
|
||||
{
|
||||
JSONObject dataSet = (JSONObject) dataSets.get(i);
|
||||
assertTrue(dataSet.length() == 3);
|
||||
assertNotNull(dataSet.get("label"));
|
||||
assertNotNull(dataSet.get("id"));
|
||||
assertNotNull(dataSet.get("isLoaded"));
|
||||
}
|
||||
}
|
||||
}
|
@@ -47,7 +47,7 @@ public class EmailMapScriptTest extends BaseRMWebScriptTestCase
|
||||
*/
|
||||
public void testEmailMap() throws IOException, JSONException
|
||||
{
|
||||
// Test Get
|
||||
/** Test GET */
|
||||
Response getResponse = sendRequest(new GetRequest(URL_RM_EMAILMAP), Status.STATUS_OK);
|
||||
|
||||
JSONObject getResponseContent = new JSONObject(getResponse.getContentAsString());
|
||||
@@ -55,7 +55,7 @@ public class EmailMapScriptTest extends BaseRMWebScriptTestCase
|
||||
JSONArray getMappings = getData.getJSONArray("mappings");
|
||||
assertTrue(getMappings.length() == 20);
|
||||
|
||||
// Test Post
|
||||
/** Test POST */
|
||||
JSONObject newMapping = new JSONObject();
|
||||
newMapping.put("from", "whatever");
|
||||
newMapping.put("to", "rmc:Wibble");
|
||||
@@ -76,7 +76,7 @@ public class EmailMapScriptTest extends BaseRMWebScriptTestCase
|
||||
assertFalse(Boolean.parseBoolean(postResponseContent.getString("success")));
|
||||
assertFalse(postResponseContent.getString("message").isEmpty());
|
||||
|
||||
// Test Delete
|
||||
/** Test DELETE */
|
||||
Response deleteResponse = sendRequest(new DeleteRequest(String.format(URL_RM_EMAILMAP_DELETE, "whatever", "rmc:Wibble")), Status.STATUS_OK);
|
||||
JSONObject deleteResponseContent = new JSONObject(deleteResponse.getContentAsString());
|
||||
JSONObject deleteData = deleteResponseContent.getJSONObject("data");
|
||||
|
Reference in New Issue
Block a user