import org.testng.annotations.Test;
import org.collectionspace.services.client.CollectionObjectClient;
+import org.collectionspace.services.client.test.ServiceRequestType;
import org.collectionspace.services.collectionobject.CollectionObject;
import org.collectionspace.services.collectionobject.CollectionObjectList;
private final String NON_EXISTENT_ID = createNonExistentIdentifier();
private HttpClient httpClient = new HttpClient();
private TestServiceClient serviceClient = new TestServiceClient();
-
-
+
// ---------------------------------------------------------------
// Service Discovery tests
// ---------------------------------------------------------------
// Expected status code: 201 Created
final int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode();
+ // Type of service request being tested
+ final ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;
+
// Submit the request to the service and store the response.
String identifier = this.createIdentifier();
CollectionObject collectionObject = createCollectionObject(identifier);
ClientResponse<Response> res = client.createCollectionObject(collectionObject);
int statusCode = res.getStatus();
- // Experiment to determine if we can programmatically obtain the HTTP method
- // used in the request, from the response headers, so we can provide that to
- // statusCodeWithinExpectedSet(), below.
- //
- // It doesn't appear that we can; tried this also with 'curl -i {url}' without success.
- //
- // Need to look into whether this is currently returned from our Java Client Library
- // 'service access' classes, or whether we can add this functionality there.
-/*
- MultivaluedMap metadata = res.getMetadata();
- Set<String> set = metadata.keySet();
- for (String key : set) {
- // Note: values in the metadata (HTTP response headers) are of type List
- verbose(key + " : " + metadata.get(key).toString());
- }
-*/
-
// Check the status code of the response: does it match the expected response(s)?
verbose("create: status = " + statusCode);
- final String REQUEST_TYPE="CREATE"; // @TODO Consider replacing with enum.
- Assert.assertTrue(statusCodeWithinExpectedSet(REQUEST_TYPE, statusCode),
- "Status code '" + statusCode + "' in response is NOT within the expected set.");
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
// Store the ID returned from this create operation for additional tests below.
// Expected status code: 400 Bad Request
final int EXPECTED_STATUS_CODE = Response.Status.BAD_REQUEST.getStatusCode();
+ // Type of service request being tested
+ final ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;
+
// @TODO This test is currently commented out, because it returns a
// 500 Internal Server Error status code, rather than the expected status code.
// Check the status code of the response: does it match the expected response(s)?
verbose("createWithMalformedXml url=" + url + " status=" + statusCode);
- final String REQUEST_TYPE="CREATE"; // @TODO Consider replacing with enum.
- Assert.assertTrue(statusCodeWithinExpectedSet(REQUEST_TYPE, statusCode),
- "Status code '" + statusCode + "' in response is NOT within the expected set.");
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
}
*/
// Expected status code: 400 Bad Request
final int EXPECTED_STATUS_CODE = Response.Status.BAD_REQUEST.getStatusCode();
+ // Type of service request being tested
+ final ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;
+
// @TODO This test is currently commented out, because it returns a
// 500 Internal Server Error status code, rather than the expected status code.
// Check the status code of the response: does it match the expected response(s)?
verbose("createWithWrongSchema url=" + url + " status=" + statusCode);
- final String REQUEST_TYPE="CREATE"; // @TODO Consider replacing with enum.
- Assert.assertTrue(statusCodeWithinExpectedSet(REQUEST_TYPE, statusCode),
- "Status code '" + statusCode + "' in response is NOT within the expected set.");
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
}
*/
// Expected status code: 409 Conflict
final int EXPECTED_STATUS_CODE = Response.Status.CONFLICT.getStatusCode();
+
+ // Type of service request being tested
+ final ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;
// @TODO This test is currently commented out because our current
// services do not appear to permit creation of duplicate records.
// Expected status code: 200 OK
final int EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode();
+ // Type of service request being tested
+ final ServiceRequestType REQUEST_TYPE = ServiceRequestType.READ;
+
// Submit the request to the service and store the response.
ClientResponse<CollectionObject> res =
client.getCollectionObject(knownObjectId);
// Check the status code of the response: does it match the expected response(s)?
verbose("read: status = " + statusCode);
- final String REQUEST_TYPE="READ"; // @TODO Consider replacing with enum.
- Assert.assertTrue(statusCodeWithinExpectedSet(REQUEST_TYPE, statusCode),
- "Status code '" + statusCode + "' in response is NOT within the expected set.");
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
}
// Expected status code: 403 Forbidden
final int EXPECTED_STATUS_CODE = Response.Status.FORBIDDEN.getStatusCode();
+
+ // Type of service request being tested
+ final ServiceRequestType REQUEST_TYPE = ServiceRequestType.READ;
// @TODO Currently only a stub. This test can be implemented
// when the service is revised to require authorization.
// Expected status code: 404 Not Found
final int EXPECTED_STATUS_CODE = Response.Status.NOT_FOUND.getStatusCode();
+ // Type of service request being tested
+ final ServiceRequestType REQUEST_TYPE = ServiceRequestType.READ;
+
// Submit the request to the service and store the response.
ClientResponse<CollectionObject> res =
client.getCollectionObject(NON_EXISTENT_ID);
// Check the status code of the response: does it match the expected response(s)?
verbose("readNonExistent: status = " + res.getStatus());
- final String REQUEST_TYPE="READ"; // @TODO Consider replacing with enum.
- Assert.assertTrue(statusCodeWithinExpectedSet(REQUEST_TYPE, statusCode),
- "Status code '" + statusCode + "' in response is NOT within the expected set.");
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
}
// Expected status code: 200 OK
final int EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode();
+
+ // Type of service request being tested
+ final ServiceRequestType REQUEST_TYPE = ServiceRequestType.READ_MULTIPLE;
// Submit the request to the service and store the response.
ClientResponse<CollectionObjectList> res = client.getCollectionObjectList();
// Check the status code of the response: does it match the expected response(s)?
verbose("readList: status = " + res.getStatus());
- final String REQUEST_TYPE="READ_MULTIPLE"; // @TODO Consider replacing with enum.
- Assert.assertTrue(statusCodeWithinExpectedSet(REQUEST_TYPE, statusCode),
- "Status code '" + statusCode + "' in response is NOT within the expected set.");
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
// Optionally output additional data about list members for debugging.
// (NOTE: *not* 204 No Content)
final int EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode();
+ // Type of service request being tested
+ final ServiceRequestType REQUEST_TYPE = ServiceRequestType.READ_MULTIPLE;
+
// @TODO Currently only a stub. Consider how to implement this.
}
*/
// Expected status code: 400 Bad Request
final int EXPECTED_STATUS_CODE = Response.Status.BAD_REQUEST.getStatusCode();
+ // Type of service request being tested
+ final ServiceRequestType REQUEST_TYPE = ServiceRequestType.READ_MULTIPLE;
+
// @TODO This test is currently commented out, because it returns a
// 200 OK status code, rather than the expected status code.
// Check the status code of the response: does it match the expected response(s)?
verbose("readListWithBadParams: url=" + url + " status=" + statusCode);
- final String REQUEST_TYPE="READ_MULTIPLE"; // @TODO Consider replacing with enum.
- Assert.assertTrue(statusCodeWithinExpectedSet(REQUEST_TYPE, statusCode),
- "Status code '" + statusCode + "' in response is NOT within the expected set.");
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
}
*/
// Expected status code: 403 Forbidden
final int EXPECTED_STATUS_CODE = Response.Status.FORBIDDEN.getStatusCode();
+ // Type of service request being tested
+ final ServiceRequestType REQUEST_TYPE = ServiceRequestType.READ_MULTIPLE;
+
// @TODO Currently only a stub. This test can be implemented
// when the service is revised to require authorization.
}
// Expected status code: 200 OK
final int EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode();
+ // Type of service request being tested
+ final ServiceRequestType REQUEST_TYPE = ServiceRequestType.UPDATE;
+
// Retrieve an existing resource that we can update.
ClientResponse<CollectionObject> res =
client.getCollectionObject(knownObjectId);
// Check the status code of the response: does it match the expected response(s)?
verbose("update: status = " + res.getStatus());
- final String REQUEST_TYPE="UPDATE"; // @TODO Consider replacing with enum.
- Assert.assertTrue(statusCodeWithinExpectedSet(REQUEST_TYPE, statusCode),
- "Status code '" + statusCode + "' in response is NOT within the expected set.");
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
// Check the contents of the response: does it match what was submitted?
verbose("update: ", updatedCollectionObject, CollectionObject.class);
Assert.assertEquals(updatedCollectionObject.getObjectName(),
- collectionObject.getObjectName());
+ collectionObject.getObjectName(), "Data in updated object did not match submitted data.");
}
/**
// Expected status code: 400 Bad Request
final int EXPECTED_STATUS_CODE = Response.Status.BAD_REQUEST.getStatusCode();
+ // Type of service request being tested
+ final ServiceRequestType REQUEST_TYPE = ServiceRequestType.UPDATE;
+
// @TODO This test is currently commented out, because it returns a
// 500 Internal Server Error status code, rather than the expected status code.
// Check the status code of the response: does it match the expected response(s)?
verbose("updateWithMalformedXml: url=" + url + " status=" + statusCode);
- final String REQUEST_TYPE="UPDATE"; // @TODO Consider replacing with enum.
- Assert.assertTrue(statusCodeWithinExpectedSet(REQUEST_TYPE, statusCode),
- "Status code '" + statusCode + "' in response is NOT within the expected set.");
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
}
*/
// Expected status code: 400 Bad Request
final int EXPECTED_STATUS_CODE = Response.Status.BAD_REQUEST.getStatusCode();
+
+ // Type of service request being tested
+ final ServiceRequestType REQUEST_TYPE = ServiceRequestType.UPDATE;
// @TODO This test is currently commented out, because it returns a
// 500 Internal Server Error status code, rather than the expected status code.
// Check the status code of the response: does it match the expected response(s)?
verbose("updateWithWrongSchema: url=" + url + " status=" + statusCode);
- final String REQUEST_TYPE="UPDATE"; // @TODO Consider replacing with enum.
- Assert.assertTrue(statusCodeWithinExpectedSet(REQUEST_TYPE, statusCode),
- "Status code '" + statusCode + "' in response is NOT within the expected set.");
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
}
*/
// Expected status code: 404 Not Found
final int EXPECTED_STATUS_CODE = Response.Status.NOT_FOUND.getStatusCode();
+ // Type of service request being tested
+ final ServiceRequestType REQUEST_TYPE = ServiceRequestType.UPDATE;
+
// Submit the request to the service and store the response.
// Note: The ID used in this 'create' call may be arbitrary.
// The only relevant ID may be the one used in updateCollectionObject(), below.
// Check the status code of the response: does it match the expected response(s)?
verbose("updateNonExistent: status = " + res.getStatus());
- final String REQUEST_TYPE="UPDATE"; // @TODO Consider replacing with enum.
- Assert.assertTrue(statusCodeWithinExpectedSet(REQUEST_TYPE, statusCode),
- "Status code '" + statusCode + "' in response is NOT within the expected set.");
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
}
// Expected status code: 200 OK
final int EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode();
+ // Type of service request being tested
+ final ServiceRequestType REQUEST_TYPE = ServiceRequestType.DELETE;
+
// Submit the request to the service and store the response.
ClientResponse<Response> res = client.deleteCollectionObject(knownObjectId);
int statusCode = res.getStatus();
// Check the status code of the response: does it match the expected response(s)?
verbose("delete: status = " + res.getStatus());
- final String REQUEST_TYPE="DELETE"; // @TODO Consider replacing with enum.
- Assert.assertTrue(statusCodeWithinExpectedSet(REQUEST_TYPE, statusCode),
- "Status code '" + statusCode + "' in response is NOT within the expected set.");
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
}
// Expected status code: 403 Forbidden
final int EXPECTED_STATUS_CODE = Response.Status.FORBIDDEN.getStatusCode();
+ // Type of service request being tested
+ final ServiceRequestType REQUEST_TYPE = ServiceRequestType.DELETE;
+
// @TODO Currently only a stub. This test can be implemented
// when the service is revised to require authorization.
}
// Expected status code: 404 Not Found
final int EXPECTED_STATUS_CODE = Response.Status.NOT_FOUND.getStatusCode();
+ // Type of service request being tested
+ final ServiceRequestType REQUEST_TYPE = ServiceRequestType.DELETE;
+
// Submit the request to the service and store the response.
ClientResponse<Response> res =
client.deleteCollectionObject(NON_EXISTENT_ID);
// Check the status code of the response: does it match the expected response(s)?
verbose("deleteNonExistent: status = " + res.getStatus());
- final String REQUEST_TYPE="DELETE"; // @TODO Consider replacing with enum.
- Assert.assertTrue(statusCodeWithinExpectedSet(REQUEST_TYPE, statusCode),
- "Status code '" + statusCode + "' in response is NOT within the expected set.");
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
}
// Check the status code of the response: does it match the expected response(s)?
verbose("testSubmitRequest: url=" + url + " status=" + statusCode);
- final String REQUEST_TYPE="CREATE"; // @TODO Consider replacing with enum.
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE,
- "expected " + EXPECTED_STATUS_CODE);
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
}
// into a common class, perhaps at the top-level 'client' module.
// -------------------------------------------------------------
-/*
-Intent of the utility method below, per Sanjay:
-Utility that asserts various HTTP status codes received for a given type of a request.
-This should be used from any test we write for a service. For example, this utility
-could take the following two params.
-import javax.ws.rs.core.Response;
-final static public boolean checkStatus(String method, Response.Status status);
-Perhaps you could find about method used from org.jboss.resteasy.client.ClientResponse metadata.
-
-See comments in the 'create' test, above, regarding finding the method used in the request.
-*/
-
- private boolean statusCodeWithinExpectedSet(String requestType, int statusCode) {
-
- // @TODO Consider implementing this via enums for request types,
- // rather than Strings. This might also allow us to define their
- // values in the enum definition class.
-
- if (requestType.equalsIgnoreCase("CREATE")) {
- int[] validStatusCodes = {
- Response.Status.CREATED.getStatusCode(),
- Response.Status.BAD_REQUEST.getStatusCode(),
- Response.Status.FORBIDDEN.getStatusCode(),
- Response.Status.CONFLICT.getStatusCode(),
- Response.Status.INTERNAL_SERVER_ERROR.getStatusCode() };
- if (Arrays.binarySearch(validStatusCodes, statusCode) >= 0) {
- verbose("status code is IN expected set");
- return true;
- } else {
- verbose("status code is NOT in expected set");
- return false;
- }
- } else if (requestType.equalsIgnoreCase("READ")) {
- int[] validStatusCodes = {
- Response.Status.OK.getStatusCode(),
- Response.Status.FORBIDDEN.getStatusCode(),
- Response.Status.NOT_FOUND.getStatusCode(),
- Response.Status.INTERNAL_SERVER_ERROR.getStatusCode() };
- if (Arrays.binarySearch(validStatusCodes, statusCode) >= 0) {
- verbose("status code is IN expected set");
- return true;
- } else {
- verbose("status code is NOT in expected set");
- return false;
- }
- } else if (requestType.equalsIgnoreCase("READ_MULTIPLE")) {
- int[] validStatusCodes = {
- Response.Status.OK.getStatusCode(),
- Response.Status.BAD_REQUEST.getStatusCode(),
- Response.Status.FORBIDDEN.getStatusCode(),
- Response.Status.INTERNAL_SERVER_ERROR.getStatusCode() };
- if (Arrays.binarySearch(validStatusCodes, statusCode) >= 0) {
- verbose("status code is IN expected set");
- return true;
- } else {
- verbose("status code is NOT in expected set");
- return false;
- }
- } else if (requestType.equalsIgnoreCase("UPDATE")) {
- int[] validStatusCodes = {
- Response.Status.OK.getStatusCode(),
- Response.Status.BAD_REQUEST.getStatusCode(),
- Response.Status.FORBIDDEN.getStatusCode(),
- Response.Status.NOT_FOUND.getStatusCode(),
- Response.Status.INTERNAL_SERVER_ERROR.getStatusCode() };
- if (Arrays.binarySearch(validStatusCodes, statusCode) >= 0) {
- verbose("status code is IN expected set");
- return true;
- } else {
- verbose("status code is NOT in expected set");
- return false;
- }
- } else if (requestType.equalsIgnoreCase("DELETE")) {
- int[] validStatusCodes = {
- Response.Status.OK.getStatusCode(),
- Response.Status.FORBIDDEN.getStatusCode(),
- Response.Status.NOT_FOUND.getStatusCode(),
- Response.Status.INTERNAL_SERVER_ERROR.getStatusCode() };
- if (Arrays.binarySearch(validStatusCodes, statusCode) >= 0) {
- verbose("status code is IN expected set");
- return true;
- } else {
- verbose("status code is NOT in expected set");
- return false;
- }
- } else {
- logger.error("Request type '" + requestType + " must match a recognized type.");
- return false;
- }
+ protected String invalidStatusCodeMessage(ServiceRequestType requestType, int statusCode) {
+ return
+ "Status code '" + statusCode + "' in response is NOT within the expected set: " +
+ requestType.validStatusCodesAsString();
}
private String getServiceRootURL() {
--- /dev/null
+/**
+ * This document is a part of the source code and related artifacts
+ * for CollectionSpace, an open source collections management system
+ * for museums and related institutions:
+ *
+ * http://www.collectionspace.org
+ * http://wiki.collectionspace.org
+ *
+ * Copyright © 2009 Regents of the University of California
+ *
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+ *
+ * You may obtain a copy of the ECL 2.0 License at
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.collectionspace.services.client.test;
+
+import java.util.Arrays;
+import javax.ws.rs.core.Response;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * ServiceRequestType, identifies types of service requests
+ * and the valid HTTP status codes that can be returned from
+ * each type of request. Used by client tests of services.
+ *
+ * $LastChangedRevision: 566 $
+ * $LastChangedDate$
+ */
+public enum ServiceRequestType {
+
+ // Define each of the service request types and their valid HTTP status codes.
+
+ CREATE {
+ @Override
+ public int[] validStatusCodes() {
+ final int[] STATUS_CODES = {
+ Response.Status.CREATED.getStatusCode(),
+ Response.Status.BAD_REQUEST.getStatusCode(),
+ Response.Status.FORBIDDEN.getStatusCode(),
+ Response.Status.CONFLICT.getStatusCode(),
+ Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()
+ };
+ Arrays.sort(STATUS_CODES);
+ return STATUS_CODES;
+ }
+ @Override
+ public boolean isValidStatusCode(int statusCode) {
+ if (Arrays.binarySearch(CREATE.validStatusCodes(), statusCode) >= 0) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ @Override
+ public String validStatusCodesAsString() {
+ return Arrays.toString(CREATE.validStatusCodes());
+ }
+ },
+
+
+ READ {
+ @Override
+ public int[] validStatusCodes() {
+ final int[] STATUS_CODES = {
+ Response.Status.OK.getStatusCode(),
+ Response.Status.FORBIDDEN.getStatusCode(),
+ Response.Status.NOT_FOUND.getStatusCode(),
+ Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()
+ };
+ Arrays.sort(STATUS_CODES);
+ return STATUS_CODES;
+ }
+ @Override
+ public boolean isValidStatusCode(int statusCode) {
+ if (Arrays.binarySearch(READ.validStatusCodes(), statusCode) >= 0) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ @Override
+ public String validStatusCodesAsString() {
+ return Arrays.toString(READ.validStatusCodes());
+ }
+ },
+
+
+ READ_MULTIPLE {
+ @Override
+ public int[] validStatusCodes() {
+ final int[] STATUS_CODES = {
+ Response.Status.OK.getStatusCode(),
+ Response.Status.BAD_REQUEST.getStatusCode(),
+ Response.Status.FORBIDDEN.getStatusCode(),
+ Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()
+ };
+ Arrays.sort(STATUS_CODES);
+ return STATUS_CODES;
+ }
+ @Override
+ public boolean isValidStatusCode(int statusCode) {
+ if (Arrays.binarySearch(READ_MULTIPLE.validStatusCodes(), statusCode) >= 0) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ @Override
+ public String validStatusCodesAsString() {
+ return Arrays.toString(READ_MULTIPLE.validStatusCodes());
+ }
+ },
+
+
+ UPDATE {
+ @Override
+ public int[] validStatusCodes() {
+ final int[] STATUS_CODES = {
+ Response.Status.OK.getStatusCode(),
+ Response.Status.BAD_REQUEST.getStatusCode(),
+ Response.Status.FORBIDDEN.getStatusCode(),
+ Response.Status.NOT_FOUND.getStatusCode(),
+ Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()
+ };
+ Arrays.sort(STATUS_CODES);
+ return STATUS_CODES;
+ }
+ @Override
+ public boolean isValidStatusCode(int statusCode) {
+ if (Arrays.binarySearch(UPDATE.validStatusCodes(), statusCode) >= 0) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ @Override
+ public String validStatusCodesAsString() {
+ return Arrays.toString(UPDATE.validStatusCodes());
+ }
+ },
+
+
+ DELETE {
+ @Override
+ public int[] validStatusCodes() {
+ final int[] STATUS_CODES = {
+ Response.Status.OK.getStatusCode(),
+ Response.Status.FORBIDDEN.getStatusCode(),
+ Response.Status.NOT_FOUND.getStatusCode(),
+ Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()
+ };
+ Arrays.sort(STATUS_CODES);
+ return STATUS_CODES;
+ }
+ @Override
+ public boolean isValidStatusCode(int statusCode) {
+ if (Arrays.binarySearch(DELETE.validStatusCodes(), statusCode) >= 0) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ @Override
+ public String validStatusCodesAsString() {
+ return Arrays.toString(DELETE.validStatusCodes());
+ }
+ };
+
+ // Template methods to be implemented by each ServiceRequestType.
+
+ public abstract int[] validStatusCodes();
+
+ public abstract boolean isValidStatusCode(int i);
+
+ public abstract String validStatusCodesAsString();
+
+}