mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Added missing testcase, part of RM-2343. Test ensures that whitespace-only values for 'classified by' result in a 4xx HTTP response.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@108248 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -343,4 +343,28 @@ public final class WebScriptUtils
|
|||||||
|
|
||||||
return jsonArray;
|
return jsonArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns {@code true} if the provided {@link WebScriptException}
|
||||||
|
* represents an HTTP 4xx error, else {@code false}.
|
||||||
|
*/
|
||||||
|
public static boolean is4xxError(WebScriptException e)
|
||||||
|
{
|
||||||
|
return isStatusInRange(e, 400, 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns {@code true} if the provided {@link WebScriptException}
|
||||||
|
* represents an HTTP 5xx error, else {@code false}.
|
||||||
|
*/
|
||||||
|
public static boolean is5xxError(WebScriptException e)
|
||||||
|
{
|
||||||
|
return isStatusInRange(e, 500, 600);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isStatusInRange(WebScriptException e, int lowerLimitInclusive, int upperLimitExclusive)
|
||||||
|
{
|
||||||
|
final int status = e.getStatus();
|
||||||
|
return status >= lowerLimitInclusive && status < upperLimitExclusive;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -24,6 +24,7 @@ import static org.alfresco.module.org_alfresco_module_rm.script.classification.C
|
|||||||
import static org.alfresco.module.org_alfresco_module_rm.script.classification.ClassifyContentPost.CLASSIFICATION_REASONS;
|
import static org.alfresco.module.org_alfresco_module_rm.script.classification.ClassifyContentPost.CLASSIFICATION_REASONS;
|
||||||
import static org.alfresco.module.org_alfresco_module_rm.script.classification.ClassifyContentPost.CLASSIFIED_BY;
|
import static org.alfresco.module.org_alfresco_module_rm.script.classification.ClassifyContentPost.CLASSIFIED_BY;
|
||||||
import static org.alfresco.util.WebScriptUtils.getStringValueFromJSONObject;
|
import static org.alfresco.util.WebScriptUtils.getStringValueFromJSONObject;
|
||||||
|
import static org.alfresco.util.WebScriptUtils.is4xxError;
|
||||||
import static org.alfresco.util.WebScriptUtils.putValuetoJSONObject;
|
import static org.alfresco.util.WebScriptUtils.putValuetoJSONObject;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
@@ -44,6 +45,7 @@ import org.mockito.InjectMocks;
|
|||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Spy;
|
import org.mockito.Spy;
|
||||||
import org.springframework.extensions.webscripts.DeclarativeWebScript;
|
import org.springframework.extensions.webscripts.DeclarativeWebScript;
|
||||||
|
import org.springframework.extensions.webscripts.WebScriptException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Classify content REST API POST implementation unit test.
|
* Classify content REST API POST implementation unit test.
|
||||||
@@ -103,13 +105,13 @@ public class ClassifyContentPostUnitTest extends BaseWebScriptUnitTest
|
|||||||
// Setup web script parameters
|
// Setup web script parameters
|
||||||
Map<String, String> parameters = buildParameters
|
Map<String, String> parameters = buildParameters
|
||||||
(
|
(
|
||||||
STORE_TYPE, record.getStoreRef().getProtocol(),
|
STORE_TYPE, record.getStoreRef().getProtocol(),
|
||||||
STORE_ID, record.getStoreRef().getIdentifier(),
|
STORE_ID, record.getStoreRef().getIdentifier(),
|
||||||
ID, record.getId()
|
ID, record.getId()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Build JSON to send to server
|
// Build JSON to send to server
|
||||||
String content = buildContent();
|
String content = buildContent().toString();
|
||||||
|
|
||||||
// Execute web script
|
// Execute web script
|
||||||
JSONObject json = executeJSONWebScript(parameters, content);
|
JSONObject json = executeJSONWebScript(parameters, content);
|
||||||
@@ -121,12 +123,40 @@ public class ClassifyContentPostUnitTest extends BaseWebScriptUnitTest
|
|||||||
verify(mockedContentClassificationService, times(1)).classifyContent(LEVEL_ID, BY, AGENCY, newHashSet(REASON1_ID, REASON2_ID), record);
|
verify(mockedContentClassificationService, times(1)).classifyContent(LEVEL_ID, BY, AGENCY, newHashSet(REASON1_ID, REASON2_ID), record);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Test public void classifyingWithBlankClassifiedByShouldReturn4xxResponse() throws Exception
|
||||||
* Helper method to build the request content
|
{
|
||||||
*
|
// Setup web script parameters
|
||||||
* @return The request content as {@link String}
|
Map<String, String> parameters = buildParameters
|
||||||
*/
|
(
|
||||||
private String buildContent()
|
STORE_TYPE, record.getStoreRef().getProtocol(),
|
||||||
|
STORE_ID, record.getStoreRef().getIdentifier(),
|
||||||
|
ID, record.getId()
|
||||||
|
);
|
||||||
|
|
||||||
|
final String whitespace = " \t ";
|
||||||
|
|
||||||
|
JSONObject jsonObj = buildContent();
|
||||||
|
putValuetoJSONObject(jsonObj, CLASSIFIED_BY, whitespace);
|
||||||
|
String json = jsonObj.toString();
|
||||||
|
|
||||||
|
// Execute web script
|
||||||
|
boolean exceptionThrown = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
executeJSONWebScript(parameters, json);
|
||||||
|
}
|
||||||
|
catch (WebScriptException expected)
|
||||||
|
{
|
||||||
|
exceptionThrown = true;
|
||||||
|
assertTrue("HTTP rsp should have been a 400 error. Was " + expected.getStatus(),
|
||||||
|
is4xxError(expected));
|
||||||
|
}
|
||||||
|
|
||||||
|
assertTrue("Expected exception was not thrown", exceptionThrown);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Helper method to build the request content. */
|
||||||
|
private JSONObject buildContent()
|
||||||
{
|
{
|
||||||
JSONObject content = new JSONObject();
|
JSONObject content = new JSONObject();
|
||||||
putValuetoJSONObject(content, CLASSIFICATION_LEVEL_ID, LEVEL_ID);
|
putValuetoJSONObject(content, CLASSIFICATION_LEVEL_ID, LEVEL_ID);
|
||||||
@@ -143,6 +173,6 @@ public class ClassifyContentPostUnitTest extends BaseWebScriptUnitTest
|
|||||||
classificationReasons.put(classificationReason2);
|
classificationReasons.put(classificationReason2);
|
||||||
putValuetoJSONObject(content, CLASSIFICATION_REASONS, classificationReasons);
|
putValuetoJSONObject(content, CLASSIFICATION_REASONS, classificationReasons);
|
||||||
|
|
||||||
return content.toString();
|
return content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user