* Added new methods to the data set service

* Added/changed the tests
* Added new aspect
* Changed the REST API for getting the list of data sets

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@41625 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tuna Aksoy
2012-09-14 21:25:49 +00:00
parent c6af92d1a5
commit 26737c520f
12 changed files with 303 additions and 26 deletions

View File

@@ -1,5 +1,6 @@
package org.alfresco.module.org_alfresco_module_rm.test.service;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -69,6 +70,7 @@ public class DataSetServiceImplTest extends BaseRMTestCase
// Test the data sets
Map<String, DataSet> dataSets = dataSetService.getDataSets();
assertNotNull(dataSets);
assertTrue(dataSets.size() > 0);
for (Map.Entry<String, DataSet> entry : dataSets.entrySet())
{
@@ -99,6 +101,38 @@ public class DataSetServiceImplTest extends BaseRMTestCase
});
}
/**
* @see DataSetService#getDataSets(NodeRef, boolean)
*/
public void testGetDataSetsForNodeRef() throws Exception
{
doTestInTransaction(new Test<Void>()
{
@Override
public Void run() throws Exception
{
// This will be tested in testFilePlanBeforeImportingDOD5015DataSet() and testFilePlanAfterImportingDOD5015DataSet()
return null;
}
});
}
/**
* @see DataSetService#getLoadedDataSets(NodeRef)
*/
public void testGetLoadedDataSets() throws Exception
{
doTestInTransaction(new Test<Void>()
{
@Override
public Void run() throws Exception
{
// This will be tested in testFilePlanBeforeImportingDOD5015DataSet() and testFilePlanAfterImportingDOD5015DataSet()
return null;
}
});
}
/**
* @see DataSetService#loadDataSet(String, org.alfresco.service.cmr.repository.NodeRef)
*/
@@ -121,7 +155,7 @@ public class DataSetServiceImplTest extends BaseRMTestCase
testFilePlan(filePlan, dataSetId, Condition.BEFORE);
// Load the data set into the specified file plan
dataSetService.loadDataSet(dataSetId, filePlan);
dataSetService.loadDataSet(filePlan, dataSetId);
// Test the file plan after importing the data sets
testFilePlan(filePlan, dataSetId, Condition.AFTER);
@@ -166,6 +200,15 @@ public class DataSetServiceImplTest extends BaseRMTestCase
assertNull(getRecordCategory(filePlan, "Military Files"));
assertNull(getRecordCategory(filePlan, "Miscellaneous Files"));
assertNull(getRecordCategory(filePlan, "Reports"));
// The aspect should exist before loading a data set
assertNull(nodeService.getProperty(filePlan, PROP_LOADED_DATA_SET_IDS));
// At the beginning the file plan is empty. So there should not be any data sets
assertTrue(dataSetService.getLoadedDataSets(filePlan).size() == 0);
assertFalse(dataSetService.isLoadedDataSet(filePlan, DATA_SET_ID_DOD5015));
assertTrue(dataSetService.getDataSets(filePlan, true).size() == 1);
assertTrue(dataSetService.getDataSets(filePlan, false).size() == 1);
}
/**
@@ -259,6 +302,22 @@ public class DataSetServiceImplTest extends BaseRMTestCase
NodeRef rep4 = getRecordCategory(rep, "Unit Manning Documents");
assertNotNull(rep4);
assertNotNull(getRecordFolder(rep4, "1st Quarter Unit Manning Documents"));
// After loading the data set into the file plan the custom aspect should contain the id of the loaded data set
Serializable nodeProperty = nodeService.getProperty(filePlan, PROP_LOADED_DATA_SET_IDS);
assertNotNull(nodeProperty);
@SuppressWarnings("unchecked")
ArrayList<String> loadedDataSetIds = (ArrayList<String>)nodeProperty;
assertTrue(loadedDataSetIds.size() == 1);
assertTrue(loadedDataSetIds.contains(DATA_SET_ID_DOD5015));
// The data set has been loaded into the file plan, so the file plan should contain the data set id
Map<String, DataSet> loadedDataSets = dataSetService.getLoadedDataSets(filePlan);
assertTrue(loadedDataSets.size() == 1);
assertTrue(loadedDataSets.containsKey(DATA_SET_ID_DOD5015));
assertTrue(dataSetService.isLoadedDataSet(filePlan, DATA_SET_ID_DOD5015));
assertTrue(dataSetService.getDataSets(filePlan, true).size() == 0);
assertTrue(dataSetService.getDataSets(filePlan, false).size() == 1);
}
/**
@@ -308,4 +367,20 @@ public class DataSetServiceImplTest extends BaseRMTestCase
});
}
/**
* @see DataSetService#isLoadedDataSet(NodeRef, String)
*/
public void testIsLoadedDataSet() throws Exception
{
doTestInTransaction(new Test<Void>()
{
@Override
public Void run() throws Exception
{
// This will be tested in testFilePlanBeforeImportingDOD5015DataSet() and testFilePlanAfterImportingDOD5015DataSet()
return null;
}
});
}
}

View File

@@ -15,7 +15,7 @@ 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";
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 */
@@ -60,8 +60,9 @@ public class DataSetPostTest extends BaseRMWebScriptTestCase
*/
private String getDataSetId() throws IOException, JSONException
{
// Send request
Response response = sendRequest(new GetRequest(GET_DATASETS_URL), Status.STATUS_OK);
// 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();

View File

@@ -13,7 +13,7 @@ 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";
private static final String GET_DATASETS_URL = "/api/rma/datasets?site=%s";
/**
* Test the REST API to retrieve details of available RM data sets
@@ -23,8 +23,9 @@ public class DataSetsGetTest extends BaseRMWebScriptTestCase
*/
public void testGetDataSetsAction() throws IOException, JSONException
{
// Send request
Response response = sendRequest(new GetRequest(GET_DATASETS_URL), Status.STATUS_OK);
// 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();
@@ -43,9 +44,10 @@ public class DataSetsGetTest extends BaseRMWebScriptTestCase
for (int i = 0; i < dataSets.length(); i++)
{
JSONObject dataSet = (JSONObject) dataSets.get(i);
assertTrue(dataSet.length() == 2);
assertTrue(dataSet.length() == 3);
assertNotNull(dataSet.get("label"));
assertNotNull(dataSet.get("id"));
assertNotNull(dataSet.get("isLoaded"));
}
}
}