MNT-18806 Remove some raw Exceptions from REST test framework.

This commit is contained in:
Tom Page
2018-08-20 08:36:41 +01:00
parent 1e87f6a25b
commit 2239b23e40
4 changed files with 33 additions and 24 deletions

View File

@@ -135,7 +135,7 @@ public class FilePlanAPI extends RMModelRequest
/** /**
* see {@link #createRootRecordCategory(RecordCategory, String, String)} * see {@link #createRootRecordCategory(RecordCategory, String, String)}
*/ */
public RecordCategory createRootRecordCategory(RecordCategory recordCategoryModel, String filePlanId) throws Exception public RecordCategory createRootRecordCategory(RecordCategory recordCategoryModel, String filePlanId)
{ {
mandatoryObject("recordCategoryModel", recordCategoryModel); mandatoryObject("recordCategoryModel", recordCategoryModel);
mandatoryString("filePlanId", filePlanId); mandatoryString("filePlanId", filePlanId);
@@ -150,7 +150,7 @@ public class FilePlanAPI extends RMModelRequest
* @param filePlanId The identifier of a file plan * @param filePlanId The identifier of a file plan
* @param parameters The URL parameters to add * @param parameters The URL parameters to add
* @return The created {@link RecordCategory} * @return The created {@link RecordCategory}
* @throws Exception for the following cases: * @throws RuntimeException for the following cases:
* <ul> * <ul>
* <li>{@code filePlanId} is not a valid format or {@code filePlanId} is invalid</li> * <li>{@code filePlanId} is not a valid format or {@code filePlanId} is invalid</li>
* <li>authentication fails</li> * <li>authentication fails</li>
@@ -160,7 +160,7 @@ public class FilePlanAPI extends RMModelRequest
* <li>model integrity exception, including node name with invalid characters</li> * <li>model integrity exception, including node name with invalid characters</li>
* </ul> * </ul>
*/ */
public RecordCategory createRootRecordCategory(RecordCategory recordCategoryModel, String filePlanId, String parameters) throws Exception public RecordCategory createRootRecordCategory(RecordCategory recordCategoryModel, String filePlanId, String parameters)
{ {
mandatoryObject("recordCategoryModel", recordCategoryModel); mandatoryObject("recordCategoryModel", recordCategoryModel);
mandatoryString("filePlanId", filePlanId); mandatoryString("filePlanId", filePlanId);

View File

@@ -201,7 +201,7 @@ public class RecordCategoryAPI extends RMModelRequest
/** /**
* see {@link #createRecordCategoryChild(RecordCategoryChild, String, String)} * see {@link #createRecordCategoryChild(RecordCategoryChild, String, String)}
*/ */
public RecordCategoryChild createRecordCategoryChild(RecordCategoryChild recordCategoryChildModel, String recordCategoryId) throws Exception public RecordCategoryChild createRecordCategoryChild(RecordCategoryChild recordCategoryChildModel, String recordCategoryId)
{ {
mandatoryObject("recordCategoryChildModel", recordCategoryChildModel); mandatoryObject("recordCategoryChildModel", recordCategoryChildModel);
mandatoryString("recordCategoryId", recordCategoryId); mandatoryString("recordCategoryId", recordCategoryId);
@@ -216,7 +216,7 @@ public class RecordCategoryAPI extends RMModelRequest
* @param recordCategoryId The identifier of a record category * @param recordCategoryId The identifier of a record category
* @param parameters The URL parameters to add * @param parameters The URL parameters to add
* @return The created {@link RecordCategoryChild} * @return The created {@link RecordCategoryChild}
* @throws Exception for the following cases: * @throws RuntimeException for the following cases:
* <ul> * <ul>
* <li>{@code recordCategoryId} is not a valid format or {@code recordCategoryChildModel} is invalid</li> * <li>{@code recordCategoryId} is not a valid format or {@code recordCategoryChildModel} is invalid</li>
* <li>authentication fails</li> * <li>authentication fails</li>
@@ -226,7 +226,7 @@ public class RecordCategoryAPI extends RMModelRequest
* <li>model integrity exception, including node name with invalid characters</li> * <li>model integrity exception, including node name with invalid characters</li>
* </ul> * </ul>
*/ */
public RecordCategoryChild createRecordCategoryChild(RecordCategoryChild recordCategoryChildModel, String recordCategoryId, String parameters) throws Exception public RecordCategoryChild createRecordCategoryChild(RecordCategoryChild recordCategoryChildModel, String recordCategoryId, String parameters)
{ {
mandatoryObject("filePlanComponentProperties", recordCategoryChildModel); mandatoryObject("filePlanComponentProperties", recordCategoryChildModel);
mandatoryString("recordCategoryId", recordCategoryId); mandatoryString("recordCategoryId", recordCategoryId);

View File

@@ -40,6 +40,7 @@ import static org.springframework.http.HttpMethod.PUT;
import static org.testng.Assert.fail; import static org.testng.Assert.fail;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.Iterator; import java.util.Iterator;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
@@ -212,7 +213,7 @@ public class RecordFolderAPI extends RMModelRequest
/** /**
* see {@link #createRecord(Record, String, String)} * see {@link #createRecord(Record, String, String)}
*/ */
public Record createRecord(Record recordModel, String recordFolderId) throws Exception public Record createRecord(Record recordModel, String recordFolderId)
{ {
mandatoryObject("recordModel", recordModel); mandatoryObject("recordModel", recordModel);
mandatoryString("recordFolderId", recordFolderId); mandatoryString("recordFolderId", recordFolderId);
@@ -227,9 +228,9 @@ public class RecordFolderAPI extends RMModelRequest
* @param recordContent {@link File} pointing to the content of the electronic record to be created * @param recordContent {@link File} pointing to the content of the electronic record to be created
* @param recordFolderId The identifier of a record folder * @param recordFolderId The identifier of a record folder
* @return newly created {@link Record} * @return newly created {@link Record}
* @throws Exception for invalid recordModel JSON strings * @throws RuntimeException for invalid recordModel JSON strings
*/ */
public Record createRecord(Record recordModel, String recordFolderId, File recordContent) throws Exception public Record createRecord(Record recordModel, String recordFolderId, File recordContent) throws RuntimeException
{ {
mandatoryString("recordFolderId", recordFolderId); mandatoryString("recordFolderId", recordFolderId);
mandatoryObject("recordContent", recordContent); mandatoryObject("recordContent", recordContent);
@@ -245,7 +246,15 @@ public class RecordFolderAPI extends RMModelRequest
* to the request. * to the request.
*/ */
RequestSpecBuilder builder = getRmRestWrapper().configureRequestSpec(); RequestSpecBuilder builder = getRmRestWrapper().configureRequestSpec();
JsonNode root = new ObjectMapper().readTree(toJson(recordModel, Record.class, FilePlanComponentMixIn.class)); JsonNode root;
try
{
root = new ObjectMapper().readTree(toJson(recordModel, Record.class, FilePlanComponentMixIn.class));
}
catch (IOException e)
{
throw new RuntimeException("Failed to convert model to JSON.", e);
}
// add request fields // add request fields
Iterator<String> fieldNames = root.fieldNames(); Iterator<String> fieldNames = root.fieldNames();
while (fieldNames.hasNext()) while (fieldNames.hasNext())
@@ -266,7 +275,7 @@ public class RecordFolderAPI extends RMModelRequest
* @param recordFolderId The identifier of a record folder * @param recordFolderId The identifier of a record folder
* @param parameters The URL parameters to add * @param parameters The URL parameters to add
* @return The created {@link Record} * @return The created {@link Record}
* @throws Exception for the following cases: * @throws RuntimeException for the following cases:
* <ul> * <ul>
* <li>{@code recordFolderId is not a valid format or {@code recordModel} is invalid</li> * <li>{@code recordFolderId is not a valid format or {@code recordModel} is invalid</li>
* <li>authentication fails</li> * <li>authentication fails</li>
@@ -275,7 +284,7 @@ public class RecordFolderAPI extends RMModelRequest
* <li>model integrity exception, including node name with invalid characters</li> * <li>model integrity exception, including node name with invalid characters</li>
* </ul> * </ul>
*/ */
public Record createRecord(Record recordModel, String recordFolderId, String parameters) throws Exception public Record createRecord(Record recordModel, String recordFolderId, String parameters)
{ {
mandatoryObject("recordModel", recordModel); mandatoryObject("recordModel", recordModel);
mandatoryString("recordFolderId", recordFolderId); mandatoryString("recordFolderId", recordFolderId);

View File

@@ -196,9 +196,9 @@ public class BaseRMRestTest extends RestTest
* @param userModel The user under whose privileges this structure is going to be created * @param userModel The user under whose privileges this structure is going to be created
* @param categoryName The name of the category * @param categoryName The name of the category
* @return The created category * @return The created category
* @throws Exception on unsuccessful component creation * @throws RuntimeException on unsuccessful component creation
*/ */
public RecordCategory createRootCategory(UserModel userModel, String categoryName) throws Exception public RecordCategory createRootCategory(UserModel userModel, String categoryName)
{ {
return createRootCategory(userModel, categoryName, RECORD_CATEGORY_TITLE); return createRootCategory(userModel, categoryName, RECORD_CATEGORY_TITLE);
} }
@@ -223,9 +223,9 @@ public class BaseRMRestTest extends RestTest
* @param categoryName The name of the category * @param categoryName The name of the category
* @param categoryTitle The title of the category * @param categoryTitle The title of the category
* @return The created category * @return The created category
* @throws Exception on unsuccessful component creation * @throws RuntimeException on unsuccessful component creation
*/ */
public RecordCategory createRootCategory(UserModel userModel, String categoryName, String categoryTitle) throws Exception public RecordCategory createRootCategory(UserModel userModel, String categoryName, String categoryTitle)
{ {
RecordCategory recordCategoryModel = createRecordCategoryModel(categoryName, categoryTitle); RecordCategory recordCategoryModel = createRecordCategoryModel(categoryName, categoryTitle);
return getRestAPIFactory().getFilePlansAPI(userModel).createRootRecordCategory(recordCategoryModel, FILE_PLAN_ALIAS); return getRestAPIFactory().getFilePlansAPI(userModel).createRootRecordCategory(recordCategoryModel, FILE_PLAN_ALIAS);
@@ -294,9 +294,9 @@ public class BaseRMRestTest extends RestTest
* @param recordCategoryId The id of the record category * @param recordCategoryId The id of the record category
* @param name The name of the folder * @param name The name of the folder
* @return The created folder * @return The created folder
* @throws Exception on unsuccessful component creation * @throws RuntimeException on unsuccessful component creation
*/ */
public RecordCategoryChild createFolder(UserModel user, String recordCategoryId, String name) throws Exception public RecordCategoryChild createFolder(UserModel user, String recordCategoryId, String name)
{ {
RecordCategoryChild recordFolderModel = createRecordCategoryChildModel(name, RECORD_FOLDER_TYPE); RecordCategoryChild recordFolderModel = createRecordCategoryChildModel(name, RECORD_FOLDER_TYPE);
return getRestAPIFactory().getRecordCategoryAPI(user).createRecordCategoryChild(recordFolderModel, recordCategoryId); return getRestAPIFactory().getRecordCategoryAPI(user).createRecordCategoryChild(recordFolderModel, recordCategoryId);
@@ -434,13 +434,13 @@ public class BaseRMRestTest extends RestTest
} }
/** /**
* Helper method to create a randomly-named <category>/<folder> structure in file plan * Helper method to create a randomly-named [category]/[folder] structure in file plan
* *
* @param user The user under whose privileges this structure is going to be created * @param user The user under whose privileges this structure is going to be created
* @return {@link RecordCategoryChild} which represents the record folder * @return {@link RecordCategoryChild} which represents the record folder
* @throws Exception on failed creation * @throws RuntimeException on failed creation
*/ */
public RecordCategoryChild createCategoryFolderInFilePlan(UserModel user) throws Exception public RecordCategoryChild createCategoryFolderInFilePlan(UserModel user)
{ {
// create root category // create root category
RecordCategory recordCategory = createRootCategory(user, "Category " + getRandomAlphanumeric()); RecordCategory recordCategory = createRootCategory(user, "Category " + getRandomAlphanumeric());
@@ -450,12 +450,12 @@ public class BaseRMRestTest extends RestTest
} }
/** /**
* Helper method to create a randomly-named <category>/<folder> structure in file plan as the admin user * Helper method to create a randomly-named [category]/[folder] structure in file plan as the admin user
* *
* @return {@link RecordCategoryChild} which represents the record folder * @return {@link RecordCategoryChild} which represents the record folder
* @throws Exception on failed creation * @throws RuntimeException on failed creation
*/ */
public RecordCategoryChild createCategoryFolderInFilePlan() throws Exception public RecordCategoryChild createCategoryFolderInFilePlan()
{ {
return createCategoryFolderInFilePlan(getAdminUser()); return createCategoryFolderInFilePlan(getAdminUser());
} }