XML_DECLARATION +
"<wrong_schema>wrong schema contents</wrong_schema>";
-
// ---------------------------------------------------------------
// CRUD tests : CREATE tests
// ---------------------------------------------------------------
// Failure outcomes
- @Override
- public void createNull() {
- }
-
- // No setup required for createNull()
-
@Override
public abstract void createWithMalformedXml();
return getServiceRootURL() + "/" + resourceIdentifier;
}
- // @TODO Add Javadoc comments to all methods requiring them, below.
-
+ /**
+ * Submits an HTTP request to a specified URL, and returns the
+ * status code of the response. Currently accepts GET and DELETE
+ * requests.
+ *
+ * @param method An HTTP method.
+ *
+ * @param url A String representation of a URL.
+ *
+ * @return The status code received in the HTTP response.
+ */
protected int submitRequest(String method, String url) {
int statusCode = 0;
try {
return statusCode;
}
- protected int submitRequest(String method, String url, String entityStr) {
+ /**
+ * Submits an HTTP request to a specified URL, with the submitted
+ * entity body, and returns the status code of the response.
+ * Currently accepts POST and PUT requests.
+ *
+ * @param method An HTTP method.
+ *
+ * @param url A String representation of a URL.
+ *
+ * @param mediaType The media type of the entity body to be submitted.
+ *
+ * @param entity The contents of the entity body to be submitted.
+ *
+ * @return The status code received in the HTTP response.
+ */
+ protected int submitRequest(String method, String url,
+ String mediaType, String entityStr) {
int statusCode = 0;
try {
ClientRequest request = new ClientRequest(url);
- request.body(MediaType.APPLICATION_XML, entityStr);
+ request.body(mediaType, entityStr);
if (method.equals(javax.ws.rs.HttpMethod.POST)) {
- ClientResponse res = request.post();
+ ClientResponse res = request.post(java.lang.String.class);
statusCode = res.getStatus();
} else if (method.equals(javax.ws.rs.HttpMethod.PUT)) {
- ClientResponse res = request.put();
+ ClientResponse res = request.put(java.lang.String.class);
statusCode = res.getStatus();
} else {
// Do nothing - leave status code at default value.
}
} catch (Exception e) {
logger.error(
- "Exception during HTTP " + method + " request to " + url + " :",
+ "Exception during HTTP " + method + " request to " + url + ":",
e);
}
return statusCode;
}
+ // @TODO Add Javadoc comments to all methods requiring them, below.
+
+
protected String extractId(ClientResponse<Response> res) {
MultivaluedMap mvm = res.getMetadata();
String uri = (String) ((ArrayList) mvm.get("Location")).get(0);
// Failure outcomes
- /**
- * Tests creation of a null resource via the
- * Java Client Library.
- */
- public void createNull();
-
/**
* Tests creation of a resource by submitting
* a representation with malformed XML data.
package org.collectionspace.services.client.test;
import java.util.List;
+import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
// Failure outcomes
- @Override
- @Test(dependsOnMethods = {"create"},
- expectedExceptions = IllegalArgumentException.class)
- public void createNull() {
- ClientResponse<Response> res = client.create(null);
- }
-
// Placeholders until the two tests below can be uncommented.
// See Issue CSPACE-401.
public void createWithMalformedXml() {}
// Submit the request to the service and store the response.
String method = REQUEST_TYPE.httpMethodName();
String url = getServiceRootURL();
+ String mediaType = MediaType.APPLICATION_XML;
final String entity = MALFORMED_XML_DATA; // Constant from base class.
- int statusCode = submitRequest(method, url, entity);
+ int statusCode = submitRequest(method, url, mediaType, entity);
// Check the status code of the response: does it match
// the expected response(s)?
// Submit the request to the service and store the response.
String method = REQUEST_TYPE.httpMethodName();
String url = getServiceRootURL();
+ String mediaType = MediaType.APPLICATION_XML;
final String entity = WRONG_XML_SCHEMA_DATA;
- int statusCode = submitRequest(method, url, entity);
+ int statusCode = submitRequest(method, url, mediaType, entity);
// Check the status code of the response: does it match
// the expected response(s)?
String method = REQUEST_TYPE.httpMethodName();
String url = getResourceURL(knownResourceId);
final String entity = MALFORMED_XML_DATA;
- int statusCode = submitRequest(method, url, entity);
+ String mediaType = MediaType.APPLICATION_XML;
+ int statusCode = submitRequest(method, url, mediaType, entity);
// Check the status code of the response: does it match
// the expected response(s)?
// Submit the request to the service and store the response.
String method = REQUEST_TYPE.httpMethodName();
String url = getResourceURL(knownResourceId);
+ String mediaType = MediaType.APPLICATION_XML;
final String entity = WRONG_XML_SCHEMA_DATA;
- int statusCode = submitRequest(method, url, entity);
+ int statusCode = submitRequest(method, url, mediaType, entity);
// Check the status code of the response: does it match
// the expected response(s)?
package org.collectionspace.services.client.test;
import java.util.List;
+import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
// Failure outcomes
- @Override
- @Test(dependsOnMethods = {"create"},
- expectedExceptions = IllegalArgumentException.class)
- public void createNull() {
- ClientResponse<Response> res = client.create(null);
- }
-
// Placeholders until the two tests below can be uncommented.
// See Issue CSPACE-401.
public void createWithMalformedXml() {}
// Submit the request to the service and store the response.
String method = REQUEST_TYPE.httpMethodName();
String url = getServiceRootURL();
+ String mediaType = MediaType.APPLICATION_XML;
final String entity = MALFORMED_XML_DATA; // Constant from base class.
- int statusCode = submitRequest(method, url, entity);
+ int statusCode = submitRequest(method, url, mediaType, entity);
// Check the status code of the response: does it match
// the expected response(s)?
// Submit the request to the service and store the response.
String method = REQUEST_TYPE.httpMethodName();
String url = getServiceRootURL();
+ String mediaType = MediaType.APPLICATION_XML;
final String entity = WRONG_XML_SCHEMA_DATA;
- int statusCode = submitRequest(method, url, entity);
+ int statusCode = submitRequest(method, url, mediaType, entity);
// Check the status code of the response: does it match
// the expected response(s)?
// Submit the request to the service and store the response.
String method = REQUEST_TYPE.httpMethodName();
String url = getResourceURL(knownResourceId);
+ String mediaType = MediaType.APPLICATION_XML;
final String entity = MALFORMED_XML_DATA;
- int statusCode = submitRequest(method, url, entity);
+ int statusCode = submitRequest(method, url, mediaType, entity);
// Check the status code of the response: does it match
// the expected response(s)?
// Submit the request to the service and store the response.
String method = REQUEST_TYPE.httpMethodName();
String url = getResourceURL(knownResourceId);
+ String mediaType = MediaType.APPLICATION_XML;
final String entity = WRONG_XML_SCHEMA_DATA;
- int statusCode = submitRequest(method, url, entity);
+ int statusCode = submitRequest(method, url, mediaType, entity);
// Check the status code of the response: does it match
// the expected response(s)?
package org.collectionspace.services.client.test;
import java.util.List;
+import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
// Failure outcomes
- @Override
- @Test(dependsOnMethods = {"create"},
- expectedExceptions = IllegalArgumentException.class)
- public void createNull() {
- ClientResponse<Response> res = client.create(null);
- }
-
// Placeholders until the two tests below can be uncommented.
// See Issue CSPACE-401.
public void createWithMalformedXml() {}
// Submit the request to the service and store the response.
String method = REQUEST_TYPE.httpMethodName();
String url = getServiceRootURL();
+ String mediaType = MediaType.APPLICATION_XML;
final String entity = MALFORMED_XML_DATA; // Constant from base class.
- int statusCode = submitRequest(method, url, entity);
+ int statusCode = submitRequest(method, url, mediaType, entity);
// Check the status code of the response: does it match
// the expected response(s)?
// Submit the request to the service and store the response.
String method = REQUEST_TYPE.httpMethodName();
String url = getServiceRootURL();
+ String mediaType = MediaType.APPLICATION_XML;
final String entity = WRONG_XML_SCHEMA_DATA;
- int statusCode = submitRequest(method, url, entity);
+ int statusCode = submitRequest(method, url, mediaType, entity);
// Check the status code of the response: does it match
// the expected response(s)?
// Submit the request to the service and store the response.
String method = REQUEST_TYPE.httpMethodName();
String url = getResourceURL(knownResourceId);
+ String mediaType = MediaType.APPLICATION_XML;
final String entity = MALFORMED_XML_DATA; // Constant from abstract base class.
- int statusCode = submitRequest(method, url, entity);
+ int statusCode = submitRequest(method, url, mediaType, entity);
// Check the status code of the response: does it match
// the expected response(s)?
// Submit the request to the service and store the response.
String method = REQUEST_TYPE.httpMethodName();
String url = getResourceURL(knownResourceId);
+ String mediaType = MediaType.APPLICATION_XML;
final String entity = WRONG_XML_SCHEMA_DATA; // Constant from abstract base class.
- int statusCode = submitRequest(method, url, entity);
+ int statusCode = submitRequest(method, url, mediaType, entity);
// Check the status code of the response: does it match
// the expected response(s)?