//
CollectionObject co = new CollectionObject();
fillCollectionObject(co, createIdentifier());
- ClientResponse<Response> coResponse = collectionObjectClient.createCollectionObject(co);
+ ClientResponse<Response> coResponse = collectionObjectClient.create(co);
Assert.assertEquals(coResponse.getStatus(), Response.Status.CREATED.getStatusCode());
String collectionObjectCsid = extractId(coResponse);
logger.error("auth_createCollectionObject: caught " + e.getMessage());
return;
}
- ClientResponse<Response> res = collectionObjectClient.createCollectionObject(collectionObject);
+ ClientResponse<Response> res = collectionObjectClient.create(collectionObject);
verbose("auth_createCollectionObject: status = " + res.getStatus());
Assert.assertEquals(res.getStatus(), Response.Status.CREATED.getStatusCode(),
"expected " + Response.Status.CREATED.getStatusCode());
logger.error("auth_createCollectionObjectWithoutUser: caught " + e.getMessage());
return;
}
- ClientResponse<Response> res = collectionObjectClient.createCollectionObject(collectionObject);
+ ClientResponse<Response> res = collectionObjectClient.create(collectionObject);
verbose("auth_createCollectionObjectWithoutUser: status = " + res.getStatus());
Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(),
"expected " + Response.Status.UNAUTHORIZED.getStatusCode());
logger.error("auth_createCollectionObjectWithoutPassword: caught " + e.getMessage());
return;
}
- ClientResponse<Response> res = collectionObjectClient.createCollectionObject(collectionObject);
+ ClientResponse<Response> res = collectionObjectClient.create(collectionObject);
verbose("auth_createCollectionObjectWithoutPassword: status = " + res.getStatus());
Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(),
"expected " + Response.Status.UNAUTHORIZED.getStatusCode());
logger.error("auth_createCollectionObjectWithIncorrectPassword: caught " + e.getMessage());
return;
}
- ClientResponse<Response> res = collectionObjectClient.createCollectionObject(collectionObject);
+ ClientResponse<Response> res = collectionObjectClient.create(collectionObject);
verbose("auth_createCollectionObjectWithIncorrectPassword: status = " + res.getStatus());
Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(),
"expected " + Response.Status.UNAUTHORIZED.getStatusCode());
logger.error("auth_createCollectionObjectWithoutUserPassword: caught " + e.getMessage());
return;
}
- ClientResponse<Response> res = collectionObjectClient.createCollectionObject(collectionObject);
+ ClientResponse<Response> res = collectionObjectClient.create(collectionObject);
verbose("auth_createCollectionObjectWithoutUserPassword: status = " + res.getStatus());
Assert.assertEquals(res.getStatus(), Response.Status.FORBIDDEN.getStatusCode(),
"expected " + Response.Status.FORBIDDEN.getStatusCode());
logger.error("auth_createCollectionObjectWithIncorrectUserPassword: caught " + e.getMessage());
return;
}
- ClientResponse<Response> res = collectionObjectClient.createCollectionObject(collectionObject);
+ ClientResponse<Response> res = collectionObjectClient.create(collectionObject);
verbose("auth_createCollectionObjectWithIncorrectUserPassword: status = " + res.getStatus());
Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(),
"expected " + Response.Status.UNAUTHORIZED.getStatusCode());
return;
}
verbose("Calling deleteCollectionObject:" + knownCollectionObjectId);
- ClientResponse<Response> res = collectionObjectClient.deleteCollectionObject(knownCollectionObjectId);
+ ClientResponse<Response> res = collectionObjectClient.delete(knownCollectionObjectId);
verbose("auth_deleteCollectionObject: status = " + res.getStatus());
Assert.assertEquals(res.getStatus(), Response.Status.OK.getStatusCode(),
"expected " + Response.Status.OK.getStatusCode());
}
@Override
- public abstract void createMultiple();
+ public abstract void createList();
- // No setup required for createMultiple()
+ // No setup required for createList()
// Failure outcomes
clearSetup();
// Expected status code: 200 OK
EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode();
- REQUEST_TYPE = ServiceRequestType.READ_MULTIPLE;
+ REQUEST_TYPE = ServiceRequestType.READ_LIST;
}
// Failure outcomes
REQUEST_TYPE = ServiceRequestType.NON_EXISTENT;
}
- // @TODO Add Javadoc comments to all methods requiring them, below.
-
+ /**
+ * Returns an error message indicating that the status code returned by a
+ * specific call to a service does not fall within a set of valid status
+ * codes for that service.
+ *
+ * @param serviceRequestType A type of service request (e.g. CREATE, DELETE).
+ *
+ * @param statusCode The invalid status code that was returned in the response,
+ * from submitting that type of request to the service.
+ *
+ * @return An error message.
+ */
protected String invalidStatusCodeMessage(ServiceRequestType requestType, int statusCode) {
return
"Status code '" + statusCode + "' in response is NOT within the expected set: " +
requestType.validStatusCodesAsString();
}
- protected String getServiceRootURL() {
+ /**
+ * Returns the root URL for a service.
+ *
+ * This URL consists of a base URL for all services, followed by
+ * a path component (or components) for a service.
+ *
+ * @return The root URL for a service.
+ */
+ protected String getServiceRootURL() {
return serviceClient.getBaseURL() + getServicePathComponent();
}
+ /**
+ * Returns the URL of a specific resource managed by a service, and
+ * designated by an identifier (such as a universally unique ID, or UUID).
+ *
+ * @param resourceIdentifier An identifier (such as a UUID) for a resource.
+ *
+ * @return The URL of a specific resource managed by a service.
+ */
protected String getResourceURL(String resourceIdentifier) {
return getServiceRootURL() + "/" + resourceIdentifier;
}
+ // @TODO Add Javadoc comments to all methods requiring them, below.
+
protected int submitRequest(String method, String url) {
int statusCode = 0;
try {
ClientRequest request = new ClientRequest(url);
- if (method.equalsIgnoreCase("DELETE")) {
+ if (method.equals(javax.ws.rs.HttpMethod.DELETE)) {
ClientResponse res = request.delete();
statusCode = res.getStatus();
- } else if (method.equalsIgnoreCase("GET")) {
+ } else if (method.equals(javax.ws.rs.HttpMethod.GET)) {
ClientResponse res = request.get();
statusCode = res.getStatus();
} else {
}
} catch (Exception e) {
logger.error(
- "Exception during HTTP " + method + " request to " + url + " :",
+ "Exception during HTTP " + method + " request to " + url + ":",
e);
}
return statusCode;
try {
ClientRequest request = new ClientRequest(url);
request.body(MediaType.APPLICATION_XML, entityStr);
- if (method.equalsIgnoreCase("POST")) {
+ if (method.equals(javax.ws.rs.HttpMethod.POST)) {
ClientResponse res = request.post();
statusCode = res.getStatus();
- } else if (method.equalsIgnoreCase("PUT")) {
+ } else if (method.equals(javax.ws.rs.HttpMethod.PUT)) {
ClientResponse res = request.put();
statusCode = res.getStatus();
} else {
},
- READ_MULTIPLE {
+ READ_LIST {
@Override
public int[] validStatusCodes() {
final int[] STATUS_CODES = {
}
@Override
public boolean isValidStatusCode(int statusCode) {
- if (Arrays.binarySearch(READ_MULTIPLE.validStatusCodes(), statusCode) >= 0) {
+ if (Arrays.binarySearch(READ_LIST.validStatusCodes(), statusCode) >= 0) {
return true;
} else {
return false;
}
@Override
public String validStatusCodesAsString() {
- return Arrays.toString(READ_MULTIPLE.validStatusCodes());
+ return Arrays.toString(READ_LIST.validStatusCodes());
}
@Override
public String httpMethodName() {
public void create();
/**
- * Tests creation of two or more new resources by repeatedly
+ * Tests creation of a list of two or more new resources by repeatedly
* calling create(), and relies on the latter's test assertion(s).
*
- * Relied upon by 'read multiple' tests, below.
+ * Relied upon by 'read list' tests, below.
*/
- public void createMultiple();
+ public void createList();
// Failure outcomes
// Failure outcomes
// If feasible, implement a negative (failure) test
- // with unrecognized query parameters, other than
- // filtering or chunking parameters, etc., recognized
- // by the service.
+ // of handling of unrecognized query parameters
+ // (e.g. other than filtering or chunking parameters, etc.
+ // that may be supported by the service).
// ---------------------------------------------------------------
// CRUD tests : UPDATE tests
* @return
* @see org.collectionspace.hello.client.CollectionObjectProxy#getCollectionObject()
*/
- public ClientResponse<CollectionObjectList> getCollectionObjectList() {
- return collectionObjectProxy.getCollectionObjectList();
+ public ClientResponse<CollectionObjectList> readList() {
+ return collectionObjectProxy.readList();
}
/**
* @return
* @see org.collectionspace.hello.client.CollectionObjectProxy#getCollectionObject(java.lang.String)
*/
- public ClientResponse<CollectionObject> getCollectionObject(String csid) {
- return collectionObjectProxy.getCollectionObject(csid);
+ public ClientResponse<CollectionObject> read(String csid) {
+ return collectionObjectProxy.read(csid);
}
/**
* @return
* @see org.collectionspace.hello.client.CollectionObjectProxy#createCollectionObject(org.collectionspace.hello.CollectionObject)
*/
- public ClientResponse<Response> createCollectionObject(CollectionObject collectionObject) {
- return collectionObjectProxy.createCollectionObject(collectionObject);
+ public ClientResponse<Response> create(CollectionObject collectionObject) {
+ return collectionObjectProxy.create(collectionObject);
}
/**
* @return
* @see org.collectionspace.hello.client.CollectionObjectProxy#updateCollectionObject(java.lang.Long, org.collectionspace.hello.CollectionObject)
*/
- public ClientResponse<CollectionObject> updateCollectionObject(String csid, CollectionObject collectionObject) {
- return collectionObjectProxy.updateCollectionObject(csid, collectionObject);
+ public ClientResponse<CollectionObject> update(String csid, CollectionObject collectionObject) {
+ return collectionObjectProxy.update(csid, collectionObject);
}
/**
* @return
* @see org.collectionspace.hello.client.CollectionObjectProxy#deleteCollectionObject(java.lang.Long)
*/
- public ClientResponse<Response> deleteCollectionObject(String csid) {
- return collectionObjectProxy.deleteCollectionObject(csid);
+ public ClientResponse<Response> delete(String csid) {
+ return collectionObjectProxy.delete(csid);
}
}
public interface CollectionObjectProxy {
@GET
- ClientResponse<CollectionObjectList> getCollectionObjectList();
+ ClientResponse<CollectionObjectList> readList();
//(C)reate
@POST
- ClientResponse<Response> createCollectionObject(CollectionObject co);
+ ClientResponse<Response> create(CollectionObject co);
//(R)ead
@GET
@Path("/{csid}")
- ClientResponse<CollectionObject> getCollectionObject(@PathParam("csid") String csid);
+ ClientResponse<CollectionObject> read(@PathParam("csid") String csid);
//(U)pdate
@PUT
@Path("/{csid}")
- ClientResponse<CollectionObject> updateCollectionObject(@PathParam("csid") String csid, CollectionObject co);
+ ClientResponse<CollectionObject> update(@PathParam("csid") String csid, CollectionObject co);
//(D)elete
@DELETE
@Path("/{csid}")
- ClientResponse<Response> deleteCollectionObject(@PathParam("csid") String csid);
+ ClientResponse<Response> delete(@PathParam("csid") String csid);
}
\ No newline at end of file
// Submit the request to the service and store the response.
String identifier = createIdentifier();
CollectionObject collectionObject = createCollectionObject(identifier);
- ClientResponse<Response> res = client.createCollectionObject(collectionObject);
+ ClientResponse<Response> res = client.create(collectionObject);
int statusCode = res.getStatus();
// Check the status code of the response: does it match the expected response(s)?
@Override
@Test(dependsOnMethods = {"create"})
- public void createMultiple() {
+ public void createList() {
for(int i = 0; i < 3; i++){
create ();
}
@Override
@Test(dependsOnMethods = {"create"}, expectedExceptions = IllegalArgumentException.class)
public void createNull() {
- ClientResponse<Response> res = client.createCollectionObject(null);
+ ClientResponse<Response> res = client.create(null);
}
// Placeholders until the two tests below can be uncommented. See Issue CSPACE-401.
setupRead();
// Submit the request to the service and store the response.
- ClientResponse<CollectionObject> res =
- client.getCollectionObject(knownObjectId);
+ ClientResponse<CollectionObject> res = client.read(knownObjectId);
int statusCode = res.getStatus();
// Check the status code of the response: does it match the expected response(s)?
setupReadNonExistent();
// Submit the request to the service and store the response.
- ClientResponse<CollectionObject> res =
- client.getCollectionObject(NON_EXISTENT_ID);
+ ClientResponse<CollectionObject> res = client.read(NON_EXISTENT_ID);
int statusCode = res.getStatus();
// Check the status code of the response: does it match the expected response(s)?
// ---------------------------------------------------------------
- // CRUD tests : READ (list, or multiple) tests
+ // CRUD tests : READ_LIST tests
// ---------------------------------------------------------------
// Success outcomes
@Override
- @Test(dependsOnMethods = {"createMultiple"})
+ @Test(dependsOnMethods = {"createList"})
public void readList() {
// Perform setup.
setupReadList();
// Submit the request to the service and store the response.
- ClientResponse<CollectionObjectList> res = client.getCollectionObjectList();
- CollectionObjectList coList = res.getEntity();
+ ClientResponse<CollectionObjectList> res = client.readList();
+ CollectionObjectList list = res.getEntity();
int statusCode = res.getStatus();
// Check the status code of the response: does it match the expected response(s)?
// Optionally output additional data about list members for debugging.
boolean iterateThroughList = false;
if (iterateThroughList && logger.isDebugEnabled()) {
- List<CollectionObjectList.CollectionObjectListItem> coItemList =
- coList.getCollectionObjectListItem();
+ List<CollectionObjectList.CollectionObjectListItem> items =
+ list.getCollectionObjectListItem();
int i = 0;
- for(CollectionObjectList.CollectionObjectListItem pli : coItemList){
- verbose("readList: list-item[" + i + "] csid=" + pli.getCsid());
- verbose("readList: list-item[" + i + "] objectNumber=" + pli.getObjectNumber());
- verbose("readList: list-item[" + i + "] URI=" + pli.getUri());
+ for(CollectionObjectList.CollectionObjectListItem item : items){
+ verbose("readList: list-item[" + i + "] csid=" + item.getCsid());
+ verbose("readList: list-item[" + i + "] objectNumber=" + item.getObjectNumber());
+ verbose("readList: list-item[" + i + "] URI=" + item.getUri());
i++;
}
}
setupUpdate();
// Retrieve an existing resource that we can update.
- ClientResponse<CollectionObject> res =
- client.getCollectionObject(knownObjectId);
+ ClientResponse<CollectionObject> res = client.read(knownObjectId);
verbose("read: status = " + res.getStatus());
Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
CollectionObject collectionObject = res.getEntity();
collectionObject.setObjectName("updated-" + collectionObject.getObjectName());
// Submit the request to the service and store the response.
- res = client.updateCollectionObject(knownObjectId, collectionObject);
+ res = client.update(knownObjectId, collectionObject);
int statusCode = res.getStatus();
- CollectionObject updatedCollectionObject = res.getEntity();
+ CollectionObject updatedObject = res.getEntity();
// Check the status code of the response: does it match the expected response(s)?
verbose("update: status = " + res.getStatus());
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(),
+ verbose("update: ", updatedObject, CollectionObject.class);
+ Assert.assertEquals(updatedObject.getObjectName(),
collectionObject.getObjectName(),
"Data in updated object did not match submitted data.");
}
invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
}
-
*/
@Override
// 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.
+ // The only relevant ID may be the one used in update(), below.
CollectionObject collectionObject = createCollectionObject(NON_EXISTENT_ID);
ClientResponse<CollectionObject> res =
- client.updateCollectionObject(NON_EXISTENT_ID, collectionObject);
+ client.update(NON_EXISTENT_ID, collectionObject);
int statusCode = res.getStatus();
// Check the status code of the response: does it match the expected response(s)?
setupDelete();
// Submit the request to the service and store the response.
- ClientResponse<Response> res = client.deleteCollectionObject(knownObjectId);
+ ClientResponse<Response> res = client.delete(knownObjectId);
int statusCode = res.getStatus();
// Check the status code of the response: does it match the expected response(s)?
setupDeleteNonExistent();
// Submit the request to the service and store the response.
- ClientResponse<Response> res =
- client.deleteCollectionObject(NON_EXISTENT_ID);
+ ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
int statusCode = res.getStatus();
// Check the status code of the response: does it match the expected response(s)?
@Override
public String getServicePathComponent() {
// @TODO Determine if it is possible to obtain this value programmatically.
+ //
// We set this in an annotation in the CollectionObjectProxy interface, for instance.
- // We also set service-specific constants in each service module.
+ // We also set service-specific constants in each service module, which might
+ // also return this value.
return SERVICE_PATH_COMPONENT;
}
private CollectionObject createCollectionObject(String identifier) {
- CollectionObject collectionObject = createCollectionObject("objectNumber-" + identifier,
- "objectName-" + identifier);
+ CollectionObject collectionObject =
+ createCollectionObject(
+ "objectNumber-" + identifier,
+ "objectName-" + identifier);
return collectionObject;
}