return result;
}
+
+ String extractId(Response res) {
+ String result = null;
+
+ MultivaluedMap mvm = res.getMetadata();
+ String uri = (String) ((ArrayList) mvm.get("Location")).get(0);
+ verbose("extractId:uri=" + uri);
+ String[] segments = uri.split("/");
+ result = segments[segments.length - 1];
+ verbose("id=" + result);
+
+ return result;
+ }
/**
* Extract part.
PayloadOutputPart commonPart = multipart.addPart(collectionObjectClient.getCommonPartName(), co);
// Make the "create" call and check the response
- ClientResponse<Response> response = collectionObjectClient.create(multipart);
+ Response response = collectionObjectClient.create(multipart);
String collectionObjectCsid = null;
try {
Assert.assertEquals(response.getStatus(), Response.Status.CREATED
.getStatusCode());
collectionObjectCsid = extractId(response);
} finally {
- response.releaseConnection();
+ response.close();
}
// Create a new dimension record
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
dimensionCsid1 = extractId(response);
} finally {
- response.releaseConnection();
+ response.close();
}
// Relate the entities, by creating a new relation object
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
relationCsid1 = extractId(response);
} finally {
- response.releaseConnection();
+ response.close();
}
// Now lock the dimension record.
try {
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());
} finally {
- response.releaseConnection();
+ response.close();
}
// Also, try to soft-delete. This should also fail.
PayloadOutputPart commonPart = multipart.addPart(collectionObjectClient.getCommonPartName(), co);
// Make the create call and check the response
- ClientResponse<Response> response = collectionObjectClient.create(multipart);
+ Response response = collectionObjectClient.create(multipart);
String collectionObjectCsid = null;
try {
Assert.assertEquals(response.getStatus(), Response.Status.CREATED
.getStatusCode());
collectionObjectCsid = extractId(response);
} finally {
- response.releaseConnection();
+ response.close();
}
//Next, create the first of three Dimension records to relate the collection object record
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
dimensionCsid1 = extractId(response);
} finally {
- response.releaseConnection();
+ response.close();
}
//Next, create a the second Dimension record
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
dimensionCsid2 = extractId(response);
} finally {
- response.releaseConnection();
+ response.close();
}
//Next, create a the 3rd Dimension record
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
dimensionCsid3 = extractId(response);
} finally {
- response.releaseConnection();
+ response.close();
}
// Relate the entities, by creating a new relation object
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
relationCsid1 = extractId(response);
} finally {
- response.releaseConnection();
+ response.close();
}
// Wait 1 second and create the second relationship
try {
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
relationCsid2 = extractId(response);
} finally {
- response.releaseConnection();
+ response.close();
}
// Wait 1 second and create the 3rd relationship
try {
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
relationCsid3 = extractId(response);
} finally {
- response.releaseConnection();
+ response.close();
}
}
commonPart.setLabel(collectionObjectClient.getCommonPartName());
// Make the create call and check the response
- ClientResponse<Response> response = collectionObjectClient.create(multipart);
+ Response response = collectionObjectClient.create(multipart);
String collectionObjectCsid = null;
try {
Assert.assertEquals(response.getStatus(), Response.Status.CREATED
.getStatusCode());
collectionObjectCsid = extractId(response);
} finally {
- response.releaseConnection();
+ response.close();
}
//Next, create a Dimension record to relate the collection object to
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
dimensionCsid = extractId(response);
} finally {
- response.releaseConnection();
+ response.close();
}
@SuppressWarnings("unused")
commonPart.setLabel(relationClient.getCommonPartName());
// Make the call to crate
- ClientResponse<Response> relationresponse = relationClient.create(multipart);
- @SuppressWarnings("unused")
+ Response relationresponse = relationClient.create(multipart);
String relationCsid = null;
try {
Assert.assertEquals(relationresponse.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());
relationCsid = extractId(response);
} finally {
- relationresponse.releaseConnection();
+ relationresponse.close();
}
-
}
@Test
commonPart.setLabel(collectionObjectClient.getCommonPartName());
// Make the create call and check the response
- ClientResponse<Response> response = collectionObjectClient.create(multipart);
+ Response response = collectionObjectClient.create(multipart);
String collectionObjectCsid = null;
try {
Assert.assertEquals(response.getStatus(), Response.Status.CREATED
.getStatusCode());
collectionObjectCsid = extractId(response);
} finally {
- response.releaseConnection();
+ response.close();
}
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
intakeCsid = extractId(response);
} finally {
- response.releaseConnection();
+ response.close();
}
// Lastly, relate the two entities, by creating a new relation object
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
relationCsid = extractId(response);
} finally {
- response.releaseConnection();
+ response.close();
}
//
Assert.assertEquals(resultResponse.getStatus(), Response.Status.OK.getStatusCode());
relationList = resultResponse.getEntity();
} finally {
- resultResponse.releaseConnection();
+ resultResponse.close();
}
//
} catch (Exception e) {
e.printStackTrace();
} finally {
- multiPartResponse.releaseConnection();
+ multiPartResponse.close();
}
Assert.assertEquals(resultRelation.getSubjectCsid(), collectionObjectCsid);
commonPart.setLabel(collectionObjectClient.getCommonPartName());
// Make the create call and check the response
- ClientResponse<Response> response = collectionObjectClient.create(multipart);
+ Response response = collectionObjectClient.create(multipart);
String collectionObjectCsid = null;
try {
Assert.assertEquals(response.getStatus(), Response.Status.CREATED
collectionObjectCsid = extractId(response);
collectionObjectIDList.add(collectionObjectCsid);
} finally {
- response.releaseConnection();
+ response.close();
}
}
commonPart.setLabel(intakeClient.getCommonPartName());
// Make the call to create and check the response
- ClientResponse<Response> response = intakeClient.create(multipart);
+ Response response = intakeClient.create(multipart);
String intakeCsid = null;
try {
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
intakeCsid = extractId(response);
} finally {
- response.releaseConnection();
+ response.close();
}
// Lastly, relate the two entities, by creating a new relation object
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
relationCsid = extractId(response);
} finally {
- response.releaseConnection();
+ response.close();
}
}
Assert.assertEquals(resultResponse.getStatus(), Response.Status.OK.getStatusCode());
relationList = resultResponse.getEntity();
} finally {
- resultResponse.releaseConnection();
+ resultResponse.close();
}
//
} catch (Exception e) {
e.printStackTrace();
} finally {
- multiPartResponse.releaseConnection();
+ multiPartResponse.close();
}
Assert.assertEquals(resultRelation.getSubjectCsid(), intakeCsid);
return result;
}
+
+ String extractId(Response res) {
+ String result = null;
+
+ MultivaluedMap mvm = res.getMetadata();
+ String uri = (String) ((ArrayList) mvm.get("Location")).get(0);
+ verbose("extractId:uri=" + uri);
+ String[] segments = uri.split("/");
+ result = segments[segments.length - 1];
+ verbose("id=" + result);
+
+ return result;
+ }
/**
* Extract part.
commonPart.setLabel(collectionObjectClient.getCommonPartName());
// Make a create call with that payload and check the response.
- ClientResponse<Response> response = collectionObjectClient.create(multipart);
+ Response response = collectionObjectClient.create(multipart);
try {
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
resourceId = extractId(response);
- // Since failed Asserts can throw an Exception, ensure
- // that the underlying HTTP connection is explicitly closed
- // under all circumstances.
+ // Since failed Asserts can throw an Exception, ensure
+ // that the underlying HTTP connection is explicitly closed
+ // under all circumstances.
} finally {
- response.releaseConnection();
+ response.close();
}
// Return the ID of the newly-created CollectionObject resource.
commonPart.setLabel(collectionObjectClient.getCommonPartName());
// Make a create call with that payload and check the response.
- ClientResponse<Response> response = collectionObjectClient.create(multipart);
+ Response response = collectionObjectClient.create(multipart);
try {
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
coList[i] = extractId(response);
// that the underlying HTTP connection is explicitly closed
// under all circumstances.
} finally {
- response.releaseConnection();
+ response.close();
}
if (logger.isDebugEnabled() == true) {
CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
long identifier = 0;
int i = 0;
- ClientResponse<Response> response = null;
try {
-
for (i = 0; i <= numberOfObjects; i++) {
// Create a CollectionObject instance.
commonPart.setLabel(collectionObjectClient.getCommonPartName());
// Make a create call with that payload and check the response.
- response = collectionObjectClient.create(multipart);
-
- Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
- coList[i] = extractId(response);
-
- if (logger.isDebugEnabled() == true) {
- logger.debug("Created CollectionObject #: " + i);
+ Response response = collectionObjectClient.create(multipart);
+ try {
+ Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
+ coList[i] = extractId(response);
+ if (logger.isDebugEnabled() == true) {
+ logger.debug("Created CollectionObject #: " + i);
+ }
+ } finally {
+ response.close();
}
-
}
-
} catch (AssertionError e) {
if (logger.isDebugEnabled() == true) {
- logger.debug("FAILURE: Created " + i +
- " of " + numberOfObjects +
- " before failing.");
+ logger.debug("FAILURE: Created " + i + " of " + numberOfObjects + " before failing.");
}
Assert.assertTrue(false);
- // Since failed Asserts can throw an Exception, ensure
- // that the underlying HTTP connection is explicitly closed
- // under all circumstances.
- } finally {
- response.releaseConnection();
}
-
}
@AfterClass(alwaysRun=true)
PoxPayloadOut multipart) {
String result = null;
// Make the create call and check the response
- ClientResponse<Response> response = collectionObjectClient.create(multipart);
+ Response response = collectionObjectClient.create(multipart);
try {
int responseStatus = response.getStatus();
if (logger.isDebugEnabled() == true) {
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
result = extractId(response);
} finally {
- response.releaseConnection();
+ response.close();
}
return result;
acquisitionSourcesRefNames);
AcquisitionClient acquisitionClient = new AcquisitionClient();
- ClientResponse<Response> res = acquisitionClient.create(multipart);
+ Response res = acquisitionClient.create(multipart);
int statusCode = res.getStatus();
PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName());
- ClientResponse<Response> res = personAuthClient.create(multipart);
+ Response res = personAuthClient.create(multipart);
int statusCode = res.getStatus();
Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
AcquisitionClient client = new AcquisitionClient();
PoxPayloadOut multipart = createAcquisitionInstance(identifier);
- ClientResponse<Response> res = client.create(multipart);
+ Response res = client.create(multipart);
int statusCode = res.getStatus();
multipart = createAcquisitionInstanceFromRawXml(testName,
client.getCommonPartName(), fileName);
}
- ClientResponse<Response> res = client.create(multipart);
+ Response res = client.create(multipart);
int statusCode = res.getStatus();
if (logger.isDebugEnabled()) {
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+
import javax.ws.rs.core.PathSegment;
import javax.ws.rs.core.UriInfo;
+
import org.collectionspace.services.batch.AbstractBatchInvocable;
+import org.collectionspace.services.batch.UriInfoImpl;
import org.collectionspace.services.client.AbstractCommonListUtils;
import org.collectionspace.services.client.CollectionObjectClient;
import org.collectionspace.services.client.IQueryManager;
import org.collectionspace.services.common.invocable.InvocationResults;
import org.collectionspace.services.jaxb.AbstractCommonList;
import org.dom4j.DocumentException;
-import org.jboss.resteasy.specimpl.UriInfoImpl;
+//import org.jboss.resteasy.specimpl.UriInfoImpl;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.Namespace;
return createUriInfo("");
}
- protected UriInfo createUriInfo(String queryString) throws URISyntaxException {
+ private UriInfo createUriInfo(String queryString) throws URISyntaxException {
URI absolutePath = new URI("");
URI baseUri = new URI("");
return new UriInfoImpl(absolutePath, baseUri, "", queryString, Collections.<PathSegment>emptyList());
// references, and will refer to Person resources by their refNames.
BlobClient blobClient = new BlobClient();
PoxPayloadOut multipart = createBlobInstance(depositorRefName);
- ClientResponse<Response> res = blobClient.create(multipart);
+ Response res = blobClient.create(multipart);
try {
assertStatusCode(res, testName);
if (knownResourceId == null) {// Store the ID returned from the first resource created for additional tests below.
blobIdsCreated.add(extractId(res));// Store the IDs from every resource created; delete on cleanup
} finally {
if (res != null) {
- res.releaseConnection();
+ res.close();
}
}
}
PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
// Create a temporary PersonAuthority resource, and its corresponding refName by which it can be identified.
PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName());
- ClientResponse<Response> res = personAuthClient.create(multipart);
+ Response res = personAuthClient.create(multipart);
try {
assertStatusCode(res, "createPersonRefs (not a surefire test)");
personAuthCSID = extractId(res);
depositorRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
} finally {
if (res != null) {
- res.releaseConnection();
+ res.close();
}
}
}
implements CollectionSpacePoxClient<CLT, P> {
@Override
- public ClientResponse<Response> create(PoxPayloadOut xmlPayload) {
+ public Response create(PoxPayloadOut xmlPayload) {
return getProxy().create(xmlPayload.getBytes());
}
*/
package org.collectionspace.services.client;
+import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.util.Properties;
import javax.ws.rs.PathParam;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.ClientRequestContext;
+import javax.ws.rs.client.ClientRequestFilter;
+import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
+import javax.xml.bind.DatatypeConverter;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.jboss.resteasy.client.ClientResponse; //import org.collectionspace.services.common.context.ServiceContext;
import org.jboss.resteasy.client.ProxyFactory;
import org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor;
+import org.jboss.resteasy.client.jaxrs.ResteasyClient;
//import org.jboss.resteasy.client.core.executors.ApacheHttpClientExecutor;
import org.jboss.resteasy.plugins.providers.RegisterBuiltin;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+/**
+ * Private class for JAX-RS authentication
+ */
+class Authenticator implements ClientRequestFilter {
+
+ private final String user;
+ private final String password;
+
+ public Authenticator(String user, String password) {
+ this.user = user;
+ this.password = password;
+ }
+
+ @Override
+ public void filter(ClientRequestContext requestContext) throws IOException {
+ MultivaluedMap<String, Object> headers = requestContext.getHeaders();
+ final String basicAuthentication = getBasicAuthentication();
+ headers.add("Authorization", basicAuthentication);
+
+ }
+
+ private String getBasicAuthentication() {
+ String result = null;
+ String token = this.user + ":" + this.password;
+ try {
+ result = "Basic " + DatatypeConverter.printBase64Binary(token.getBytes("UTF-8"));
+ } catch (UnsupportedEncodingException ex) {
+ throw new IllegalStateException("Cannot encode with UTF-8", ex);
+ }
+
+ return result;
+ }
+}
+
+
/**
* BaseServiceClient is an abstract base client of all service clients FIXME:
* http://issues.collectionspace.org/browse/CSPACE-1684
*/
@Override
public void setProxy() {
+ ResteasyClient client = null;
+ String urlString = url.toString();
+ Class<P> proxyClass = this.getProxyClass();
+
+ if (useAuth()) {
+ String user = properties.getProperty(USER_PROPERTY);
+ String password = properties.getProperty(PASSWORD_PROPERTY);
+ client = (ResteasyClient)ClientBuilder.newClient().register(new Authenticator(user, password));
+ } else {
+ client = (ResteasyClient)ClientBuilder.newClient();
+ }
+
+ proxy = client.target(urlString).proxy(proxyClass);
+ }
+
+ /**
+ * allow to reset proxy as per security needs
+ */
+ @Deprecated
+ public void _setProxy() {
Class<P> proxyClass = this.getProxyClass();
if (useAuth()) {
proxy = ProxyFactory.create(proxyClass,
* Common proxied service calls
*/
- public ClientResponse<Response> create(REQUEST_TYPE payload);
+ public Response create(REQUEST_TYPE payload);
public ClientResponse<RESPONSE_TYPE> read(String csid);
* @param csid the csid
* @return the client response
*/
- public ClientResponse<Response> delete(String csid);
+ public Response delete(String csid);
}
// (C)reate
@POST
- ClientResponse<Response> create(byte[] payload);
+ Response create(byte[] payload);
// (R)ead
@GET
setupCreate();
CollectionSpaceClient client = this.getClientInstance();
REQUEST_TYPE payload = createInstance(client.getCommonPartName(), identifier);
- ClientResponse<Response> res = client.create(payload);
+ Response res = client.create(payload);
try {
int statusCode = res.getStatus();
if (logger.isDebugEnabled()) {
// so they can be deleted after tests have been run.
allResourceIdsCreated.add(result);
} finally {
- res.releaseConnection();
+ res.close();
}
return result;
public void delete(String testName) throws Exception {
setupDelete();
CollectionSpaceClient client = this.getClientInstance();
- ClientResponse<Response> res = client.delete(getKnowResourceId());
- int statusCode = res.getStatus();
-
+ Response res = client.delete(getKnowResourceId());
+ int statusCode;
+ try {
+ statusCode = res.getStatus();
+ } finally {
+ res.close();
+ }
+
// Check the status code of the response: does it match
// the expected response(s)?
if (logger.isDebugEnabled()) {
// Submit the request to the service and store the response.
CollectionSpaceClient client = this.getClientInstance();
- ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
- int statusCode = res.getStatus();
+ Response res = client.delete(NON_EXISTENT_ID);
+ int statusCode;
+ try {
+ statusCode = res.getStatus();
+ } finally {
+ res.close();
+ }
// Check the status code of the response: does it match
// the expected response(s)?
CollectionSpaceClient client = getClientInstance();
REQUEST_TYPE payload = createInstance(identifier);
- ClientResponse<Response> res = client.create(payload);
+ Response res = client.create(payload);
int statusCode = res.getStatus();
Assert.assertEquals(statusCode, STATUS_CREATED);
}
return id;
}
+
+ /**
+ * Extract id.
+ *
+ * @param res the res
+ * @return the string
+ */
+ static protected String extractId(Response res) {
+ MultivaluedMap<String, Object> mvm = res.getMetadata();
+ String uri = (String) ((List<Object>) mvm.get("Location")).get(0);
+ if (logger.isDebugEnabled()) {
+ logger.debug("extractId:uri=" + uri);
+ }
+ String[] segments = uri.split("/");
+ String id = segments[segments.length - 1];
+ if (logger.isDebugEnabled()) {
+ logger.debug("id=" + id);
+ }
+ return id;
+ }
+
/**
* Tests can override this method to customize their identifiers.
return statusCode;
}
+
+ public int assertStatusCode(Response res, String testName) {
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match the expected response(s)?
+ logger.debug(testName + ": status = " + statusCode);
+ Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(testRequestType, statusCode));
+ Assert.assertEquals(statusCode, testExpectedStatusCode);
+
+ return statusCode;
+ }
public static String getUTF8DataFragment() {
return UTF8_DATA_FRAGMENT;
//
for (String resourceId : allResourceIdsCreated) {
// Note: Any non-success responses are ignored and not reported.
- client.delete(resourceId).releaseConnection();
+ client.delete(resourceId).close();
}
}
// Submit the request to the service and store the response.
CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
testSetup(STATUS_CREATED, ServiceRequestType.CREATE);
- ClientResponse<Response> res = collectionObjectClient.create(multipart);
+ Response res = collectionObjectClient.create(multipart);
String newCsid = null;
try {
assertStatusCode(res, testName);
newCsid = extractId(res);
} finally {
if (res != null) {
- res.releaseConnection();
+ res.close();
}
}
// Store the ID returned from the first resource created
PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
displayName, shortIdentifier, personAuthClient.getCommonPartName());
- ClientResponse<Response> res = personAuthClient.create(multipart);
+ Response res = personAuthClient.create(multipart);
int statusCode = res.getStatus();
-
- Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(testRequestType, statusCode));
- Assert.assertEquals(statusCode, STATUS_CREATED);
- personAuthCSID = extractId(res);
- personAuthRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null);
+ try {
+ Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(testRequestType, statusCode));
+ Assert.assertEquals(statusCode, STATUS_CREATED);
+ personAuthCSID = extractId(res);
+ personAuthRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null);
+ } finally {
+ res.close();
+ }
}
/**
OrgAuthorityClient orgAuthClient = new OrgAuthorityClient();
PoxPayloadOut multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance(
displayName, shortIdentifier, orgAuthClient.getCommonPartName());
- ClientResponse<Response> res = orgAuthClient.create(multipart);
- int statusCode = res.getStatus();
-
- Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(testRequestType, statusCode));
- Assert.assertEquals(statusCode, STATUS_CREATED);
- orgAuthCSID = extractId(res);
- orgAuthRefName = OrgAuthorityClientUtils.getAuthorityRefName(orgAuthCSID, null);
+ Response res = orgAuthClient.create(multipart);
+ try {
+ int statusCode = res.getStatus();
+
+ Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(testRequestType, statusCode));
+ Assert.assertEquals(statusCode, STATUS_CREATED);
+ orgAuthCSID = extractId(res);
+ orgAuthRefName = OrgAuthorityClientUtils.getAuthorityRefName(orgAuthCSID, null);
+ } finally {
+ res.close();
+ }
}
/**
for (long i = 0; i < numToCreate; i++) {
PoxPayloadOut multipart = createCollectionObjectInstance(i,
keywords, keywordsInSameField);
- ClientResponse<Response> res = client.create(multipart);
+ Response res = client.create(multipart);
try {
int statusCode = res.getStatus();
Assert.assertEquals(statusCode, testExpectedStatusCode);
+ id);
}
} finally {
- res.releaseConnection();
+ res.close();
}
}
}
CollectionObjectClient client = new CollectionObjectClient();
PoxPayloadOut multipart =
createCollectionObjectInstance(client.getCommonPartName(), collectionObject, null);
- ClientResponse<Response> res = client.create(multipart);
- int statusCode = res.getStatus();
-
- // Read the response and verify that the create attempt failed.
- if (logger.isDebugEnabled()) {
- logger.debug(testName + ": status = " + statusCode);
+ Response res = client.create(multipart);
+ try {
+ int statusCode = res.getStatus();
+ // Read the response and verify that the create attempt failed.
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(testRequestType, statusCode));
+ Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
+ } finally {
+ res.close();
}
- Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(testRequestType, statusCode));
- Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
-
+
// FIXME: Consider splitting off the following into its own test method.
// Build a payload with invalid content, by setting a value to the
collectionObject.setObjectNameList(objNameList);
// Submit the request to the service and store the response.
- multipart =
- createCollectionObjectInstance(client.getCommonPartName(), collectionObject, null);
+ multipart = createCollectionObjectInstance(client.getCommonPartName(), collectionObject, null);
res = client.create(multipart);
- statusCode = res.getStatus();
-
- // Read the response and verify that the create attempt failed.
- if (logger.isDebugEnabled()) {
- logger.debug(testName + ": status = " + statusCode);
+ try {
+ int statusCode = res.getStatus();
+
+ // Read the response and verify that the create attempt failed.
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(testRequestType, statusCode));
+ Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
+ } finally {
+ res.close();
}
- Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(testRequestType, statusCode));
- Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
}
/**
// Utility methods used by tests above
// ---------------------------------------------------------------
- private ClientResponse<Response> newCollectionObject() {
- ClientResponse<Response> result = null;
+ private Response newCollectionObject() {
+ Response result = null;
CollectionObjectClient client = new CollectionObjectClient();
String identifier = createIdentifier();
private String newCollectionObject(boolean assertStatus) {
String result = null;
- ClientResponse<Response> res = newCollectionObject();
+ Response res = newCollectionObject();
try {
int statusCode = res.getStatus();
Assert.assertEquals(statusCode, STATUS_CREATED);
result = extractId(res);
} finally {
- res.releaseConnection();
+ res.close();
}
return result;
multipart = createCollectionObjectInstanceFromRawXml(testName,
client.getCommonPartName(), fileName);
}
- ClientResponse<Response> res = client.create(multipart);
- int statusCode = res.getStatus();
-
- if (logger.isDebugEnabled()) {
- logger.debug(testName + ": status = " + statusCode);
+
+ Response res = client.create(multipart);
+ String newId = null;
+ try {
+ int statusCode = res.getStatus();
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(testRequestType, statusCode));
+ Assert.assertEquals(statusCode, testExpectedStatusCode);
+ newId = extractId(res);
+ allResourceIdsCreated.add(newId);
+ } finally {
+ res.close();
}
- Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(testRequestType, statusCode));
- Assert.assertEquals(statusCode, testExpectedStatusCode);
- String newId = extractId(res);
- allResourceIdsCreated.add(newId);
+
return newId;
}
<groupId>org.nuxeo.ecm.core</groupId>
<artifactId>nuxeo-opencmis-bindings</artifactId>
<version>${nuxeo.core.version}</version>
+ <exclusions>
+ <exclusion>
+ <artifactId>jsr311-api</artifactId>
+ <groupId>javax.ws.rs</groupId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.apache.chemistry.opencmis</groupId>
*/
package org.collectionspace.services.common;
+import java.lang.reflect.Method;
import java.util.List;
import javax.ws.rs.GET;
import org.collectionspace.services.common.security.UnauthorizedException;
import org.collectionspace.services.common.storage.StorageClient;
import org.collectionspace.services.common.storage.jpa.JpaStorageClientImpl;
+import org.jboss.resteasy.core.ResourceMethodInvoker;
//import org.jboss.resteasy.core.ResourceMethod;
import org.jboss.resteasy.spi.HttpRequest;
import org.jboss.resteasy.spi.metadata.ResourceMethod;
@Override
public boolean allowAnonymousAccess(HttpRequest request,
- ResourceMethod method) {
+ Class<?> resourceClass) {
return false;
}
}
*/
// <sec:filter-chain pattern="/publicitems/*/*/content"
// filters="none"/>
- public boolean allowAnonymousAccess(HttpRequest request, Method method);
+ public boolean allowAnonymousAccess(HttpRequest request, Class<?> resourceClass);
}
@Override
public boolean allowAnonymousAccess(HttpRequest request,
- Method method) {
+ Class<?> resourceClass) {
return true;
}
private static final String ERROR_NUXEO_LOGOUT = "Attempt to logout when Nuxeo login context was null";
private static final String ERROR_UNBALANCED_LOGINS = "The number of Logins vs Logouts to the Nuxeo framework was unbalanced.";
- private boolean isAnonymousRequest(HttpRequest request, Method resourceMethod) {
+ private boolean isAnonymousRequest(HttpRequest request, ResourceMethodInvoker resourceMethodInvoker) {
boolean result = false;
- Class<?> resourceClass = resourceMethod.getClass();
+ Class<?> resourceClass = resourceMethodInvoker.getResourceClass();
try {
CollectionSpaceResource resourceInstance = (CollectionSpaceResource)resourceClass.newInstance();
- result = resourceInstance.allowAnonymousAccess(request, resourceMethod);
+ result = resourceInstance.allowAnonymousAccess(request, resourceClass);
} catch (InstantiationException e) {
logger.error("isAnonymousRequest: ", e);
} catch (IllegalAccessException e) {
return result;
}
-
+
/* (non-Javadoc)
* @see org.jboss.resteasy.spi.interception.PreProcessInterceptor#preProcess(org.jboss.resteasy.spi.HttpRequest, org.jboss.resteasy.core.ResourceMethod)
*/
Method resourceMethod = resourceMethodInvoker.getMethod();
try {
- if (isAnonymousRequest(request, resourceMethod) == true) {
+ if (isAnonymousRequest(request, resourceMethodInvoker) == true) {
// We don't need to check credentials for anonymous requests. Just login to Nuxeo and
// exit
- nuxeoPreProcess(request, resourceMethod);
+ nuxeoPreProcess(request, resourceMethodInvoker);
return result;
}
//
// Login to Nuxeo
//
- nuxeoPreProcess(request, resourceMethod);
+ nuxeoPreProcess(request, resourceMethodInvoker);
//
// We've passed all the checks. Now just log the results
//
// Nuxeo login support
//
- public ServerResponse nuxeoPreProcess(HttpRequest request, Method resourceMethod)
+ public ServerResponse nuxeoPreProcess(HttpRequest request, ResourceMethodInvoker resourceMethodInvoker)
throws Failure, CSWebApplicationException {
try {
nuxeoLogin();
PoxPayloadOut multipart = createConditioncheckInstance(
"conditionCheckRefNumber-" + identifier,
conditionCheckerRefName);
- ClientResponse<Response> response = conditioncheckClient.create(multipart);
+ Response response = conditioncheckClient.create(multipart);
int statusCode = response.getStatus();
try {
// Check the status code of the response: does it match
// so they can be deleted after tests have been run.
conditioncheckIdsCreated.add(extractId(response));
} finally {
- response.releaseConnection();
+ response.close();
}
}
protected void createPersonRefs(){
-
PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
// Create a temporary PersonAuthority resource, and its corresponding
// refName by which it can be identified.
PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName());
- ClientResponse<Response> res = personAuthClient.create(multipart);
- int statusCode = res.getStatus();
-
- Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(testRequestType, statusCode));
- Assert.assertEquals(statusCode, STATUS_CREATED);
- personAuthCSID = extractId(res);
+ Response res = personAuthClient.create(multipart);
+ try {
+ int statusCode = res.getStatus();
+ Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(testRequestType, statusCode));
+ Assert.assertEquals(statusCode, STATUS_CREATED);
+ personAuthCSID = extractId(res);
+ } finally {
+ res.close();
+ }
String authRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null);
-
// Create temporary Person resources, and their corresponding refNames
// by which they can be identified.
String csid = createPerson("Carrie", "ConditionChecker1", "carrieConditionChecker", authRefName);
String identifier = createIdentifier();
PoxPayloadOut multipart = createConditioncheckInstance(identifier);
String newID = null;
- ClientResponse<Response> res = client.create(multipart);
+ Response res = client.create(multipart);
try {
int statusCode = res.getStatus();
newID = extractId(res);
} finally {
if (res != null) {
- res.releaseConnection();
+ res.close();
}
}
String identifier = createIdentifier();
PoxPayloadOut multipart =
ContactClientUtils.createContactInstance(identifier, client.getCommonPartName());
- ClientResponse<Response> res = client.create(multipart);
-
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- //
- // Specifically:
- // Does it fall within the set of valid status codes?
- // Does it exactly match the expected status code?
- if (logger.isDebugEnabled()) {
- logger.debug(testName + ": status = " + statusCode);
+ Response res = client.create(multipart);
+ String newId = null;
+ try {
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ //
+ // Specifically:
+ // Does it fall within the set of valid status codes?
+ // Does it exactly match the expected status code?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(testRequestType, statusCode));
+ Assert.assertEquals(statusCode, testExpectedStatusCode);
+ newId = extractId(res);
+ } finally {
+ res.close();
}
- Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(testRequestType, statusCode));
- Assert.assertEquals(statusCode, testExpectedStatusCode);
// Store the ID returned from the first resource created
// for additional tests below.
if (knownResourceId == null) {
- knownResourceId = extractId(res);
+ knownResourceId = newId;
if (logger.isDebugEnabled()) {
logger.debug(testName + ": knownResourceId=" + knownResourceId);
}
// Store the IDs from every resource created by tests,
// so they can be deleted after tests have been run.
- allResourceIdsCreated.add(extractId(res));
+ allResourceIdsCreated.add(newId);
}
@Override
String identifier = createIdentifier();
PoxPayloadOut multipart = createExhibitionInstance(identifier);
String newID = null;
- ClientResponse<Response> res = client.create(multipart);
+ Response res = client.create(multipart);
try {
int statusCode = res.getStatus();
newID = extractId(res);
} finally {
if (res != null) {
- res.releaseConnection();
+ res.close();
}
}
conditionCheckerOrAssessorRefName,
insurerRefName,
valuerRefName );
- ClientResponse<Response> res = intakeClient.create(multipart);
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- //
- // Specifically:
- // Does it fall within the set of valid status codes?
- // Does it exactly match the expected status code?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
+ String newId = null;
+ Response res = intakeClient.create(multipart);
+ try {
+ int statusCode = res.getStatus();
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ //
+ // Specifically:
+ // Does it fall within the set of valid status codes?
+ // Does it exactly match the expected status code?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(testRequestType, statusCode));
+ Assert.assertEquals(statusCode, testExpectedStatusCode);
+ newId = extractId(res);
+ } finally {
+ res.close();
}
- Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(testRequestType, statusCode));
- Assert.assertEquals(statusCode, testExpectedStatusCode);
// Store the ID returned from the first resource created
// for additional tests below.
if (knownResourceId == null){
- knownResourceId = extractId(res);
+ knownResourceId = newId;
if (logger.isDebugEnabled()) {
logger.debug(testName + ": knownResourceId=" + knownResourceId);
}
// Store the IDs from every resource created by tests,
// so they can be deleted after tests have been run.
- intakeIdsCreated.add(extractId(res));
+ intakeIdsCreated.add(newId);
}
- protected void createPersonRefs(){
+ protected void createPersonRefs() {
+ //
+ // First, create a new person authority
+ //
PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName());
- ClientResponse<Response> res = personAuthClient.create(multipart);
- int statusCode = res.getStatus();
-
- Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(testRequestType, statusCode));
- Assert.assertEquals(statusCode, STATUS_CREATED);
- personAuthCSID = extractId(res);
+ Response res = personAuthClient.create(multipart);
+ try {
+ int statusCode = res.getStatus();
+ Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(testRequestType, statusCode));
+ Assert.assertEquals(statusCode, STATUS_CREATED);
+ personAuthCSID = extractId(res);
+ } finally {
+ res.close();
+ }
String authRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null);
-
String csid = createPerson("Olivier", "Owner", "olivierOwner", authRefName);
currentOwnerRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
personIdsCreated.add(csid);
insurerRefName,
valuerRefName );
- ClientResponse<Response> res = intakeClient.create(multipart);
+ Response res = intakeClient.create(multipart);
try {
int statusCode = res.getStatus();
invalidStatusCodeMessage(testRequestType, statusCode));
Assert.assertEquals(statusCode, testExpectedStatusCode);
} finally {
- res.releaseConnection();
+ res.close();
}
// Store the ID returned from the first resource created
// OrgAuthorityClientUtils.createOrgAuthRefName(ORGANIZATION_AUTHORITY_NAME, null);
PoxPayloadOut multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance(
ORGANIZATION_AUTHORITY_NAME, ORGANIZATION_AUTHORITY_NAME, orgAuthClient.getCommonPartName());
- ClientResponse<Response> res = orgAuthClient.create(multipart);
+ Response res = orgAuthClient.create(multipart);
int statusCode = res.getStatus();
Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
insurerRefName,
valuerRefName);
- ClientResponse<Response> res = intakeClient.create(multipart);
+ Response res = intakeClient.create(multipart);
try {
int statusCode = res.getStatus();
invalidStatusCodeMessage(testRequestType, statusCode));
Assert.assertEquals(statusCode, testExpectedStatusCode);
} finally {
- res.releaseConnection();
+ res.close();
}
// Store the ID returned from the first resource created
PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName());
- ClientResponse<Response> res = personAuthClient.create(multipart);
- int statusCode = res.getStatus();
-
- Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(testRequestType, statusCode));
- Assert.assertEquals(statusCode, STATUS_CREATED);
- personAuthCSID = extractId(res);
+ Response res = personAuthClient.create(multipart);
+ try {
+ int statusCode = res.getStatus();
+ Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(testRequestType, statusCode));
+ Assert.assertEquals(statusCode, STATUS_CREATED);
+ personAuthCSID = extractId(res);
+ } finally {
+ res.close();
+ }
String authRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null);
}
Assert.assertNotNull(valuerRefName);
personIdsCreated.add(csid);
-
}
protected String createPerson(String firstName, String surName, String shortId, String authRefName) {
lendersContactRefName,
borrowersContactRefName,
borrowersAuthorizerRefName);
- ClientResponse<Response> response = loaninClient.create(multipart);
- int statusCode = response.getStatus();
+ String newId = null;
+ Response response = loaninClient.create(multipart);
try {
+ int statusCode = response.getStatus();
// Check the status code of the response: does it match
// the expected response(s)?
//
Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
invalidStatusCodeMessage(testRequestType, statusCode));
Assert.assertEquals(statusCode, testExpectedStatusCode);
-
- // Store the ID returned from the first resource created
- // for additional tests below.
- if (knownResourceId == null){
- knownResourceId = extractId(response);
- if (logger.isDebugEnabled()) {
- logger.debug(testName + ": knownResourceId=" + knownResourceId);
- }
- }
-
- // Store the IDs from every resource created by tests,
- // so they can be deleted after tests have been run.
- loaninIdsCreated.add(extractId(response));
+ newId = extractId(response);
} finally {
- response.releaseConnection();
+ response.close();
}
+
+ // Store the ID returned from the first resource created
+ // for additional tests below.
+ if (knownResourceId == null){
+ knownResourceId = newId;
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": knownResourceId=" + knownResourceId);
+ }
+ }
+
+ // Store the IDs from every resource created by tests,
+ // so they can be deleted after tests have been run.
+ loaninIdsCreated.add(newId);
}
protected void createPersonRefs(){
// refName by which it can be identified.
PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName());
- ClientResponse<Response> res = personAuthClient.create(multipart);
- int statusCode = res.getStatus();
-
- Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(testRequestType, statusCode));
- Assert.assertEquals(statusCode, STATUS_CREATED);
- personAuthCSID = extractId(res);
+ Response res = personAuthClient.create(multipart);
+ try {
+ int statusCode = res.getStatus();
+
+ Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(testRequestType, statusCode));
+ Assert.assertEquals(statusCode, STATUS_CREATED);
+ personAuthCSID = extractId(res);
+ } finally {
+ res.close();
+ }
String authRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null);
String identifier = createIdentifier();
PoxPayloadOut multipart = createLoaninInstance(identifier);
String newID = null;
- ClientResponse<Response> res = client.create(multipart);
+ Response res = client.create(multipart);
try {
int statusCode = res.getStatus();
newID = extractId(res);
} finally {
if (res != null) {
- res.releaseConnection();
+ res.close();
}
}
borrowersContactRefName,
lendersAuthorizerRefName,
lendersContactRefName);
- ClientResponse<Response> res = loanoutClient.create(multipart);
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- //
- // Specifically:
- // Does it fall within the set of valid status codes?
- // Does it exactly match the expected status code?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
+ String newId = null;
+ Response res = loanoutClient.create(multipart);
+ try {
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ //
+ // Specifically:
+ // Does it fall within the set of valid status codes?
+ // Does it exactly match the expected status code?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(testRequestType, statusCode));
+ Assert.assertEquals(statusCode, testExpectedStatusCode);
+ newId = extractId(res);
+ } finally {
+ res.close();
}
- Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(testRequestType, statusCode));
- Assert.assertEquals(statusCode, testExpectedStatusCode);
// Store the ID returned from the first resource created
// for additional tests below.
if (knownResourceId == null){
- knownResourceId = extractId(res);
+ knownResourceId = newId;
if (logger.isDebugEnabled()) {
logger.debug(testName + ": knownResourceId=" + knownResourceId);
}
// Store the IDs from every resource created by tests,
// so they can be deleted after tests have been run.
- loanoutIdsCreated.add(extractId(res));
+ loanoutIdsCreated.add(newId);
}
protected void createPersonRefs(){
// refName by which it can be identified.
PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName());
- ClientResponse<Response> res = personAuthClient.create(multipart);
- int statusCode = res.getStatus();
-
- Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(testRequestType, statusCode));
- Assert.assertEquals(statusCode, STATUS_CREATED);
- personAuthCSID = extractId(res);
+ Response res = personAuthClient.create(multipart);
+ try {
+ int statusCode = res.getStatus();
+ Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(testRequestType, statusCode));
+ Assert.assertEquals(statusCode, STATUS_CREATED);
+ personAuthCSID = extractId(res);
+ } finally {
+ res.close();
+ }
String authRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null);
// Create temporary Person resources, and their corresponding refNames
// by which they can be identified.
- String csid = "";
-
- csid = createPerson("Betty", "Borrower", "bettyBorrower", authRefName);
+ String csid = createPerson("Betty", "Borrower", "bettyBorrower", authRefName);
personIdsCreated.add(csid);
borrowerRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
csid = createPerson("Larry", "Lenderscontact", "larryLenderscontact", authRefName);
personIdsCreated.add(csid);
lendersContactRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
-
}
protected String createPerson(String firstName, String surName, String shortId, String authRefName ) {
LoanoutClient client = new LoanoutClient();
String identifier = createIdentifier();
PoxPayloadOut multipart = createLoanoutInstance(identifier);
- ClientResponse<Response> res = client.create(multipart);
-
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- //
- // Specifically:
- // Does it fall within the set of valid status codes?
- // Does it exactly match the expected status code?
- if (logger.isDebugEnabled()) {
- logger.debug(testName + ": status = " + statusCode);
+ String newId = null;
+ Response res = client.create(multipart);
+ try {
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ //
+ // Specifically:
+ // Does it fall within the set of valid status codes?
+ // Does it exactly match the expected status code?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(testRequestType, statusCode));
+ Assert.assertEquals(statusCode, testExpectedStatusCode);
+ newId = extractId(res);
+ } finally {
+ res.close();
}
- Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(testRequestType, statusCode));
- Assert.assertEquals(statusCode, testExpectedStatusCode);
// Store the ID returned from the first resource created
// for additional tests below.
if (knownResourceId == null) {
- knownResourceId = extractId(res);
+ knownResourceId = newId;
if (logger.isDebugEnabled()) {
logger.debug(testName + ": knownResourceId=" + knownResourceId);
}
// Store the IDs from every resource created by tests,
// so they can be deleted after tests have been run.
- allResourceIdsCreated.add(extractId(res));
+ allResourceIdsCreated.add(newId);
}
/* (non-Javadoc)
// references, and will refer to Person resources by their refNames.
MediaClient mediaClient = new MediaClient();
PoxPayloadOut multipart = createMediaInstance(depositorRefName, "media.title-" + identifier);
- ClientResponse<Response> res = mediaClient.create(multipart);
+ Response res = mediaClient.create(multipart);
try {
assertStatusCode(res, testName);
if (knownResourceId == null) {// Store the ID returned from the first resource created for additional tests below.
mediaIdsCreated.add(extractId(res));// Store the IDs from every resource created; delete on cleanup
} finally {
if (res != null) {
- res.releaseConnection();
+ res.close();
}
}
}
// Create a temporary PersonAuthority resource, and its corresponding refName by which it can be identified.
PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName());
- ClientResponse<Response> res = personAuthClient.create(multipart);
+ Response res = personAuthClient.create(multipart);
try {
assertStatusCode(res, "createPersonRefs (not a surefire test)");
personAuthCSID = extractId(res);
} finally {
if (res != null) {
- res.releaseConnection();
+ res.close();
}
}
String authRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null);
//
MediaClient client = new MediaClient();
PoxPayloadOut multipart = createMediaInstance(createIdentifier());
- ClientResponse<Response> mediaRes = client.create(multipart);
+ Response mediaRes = client.create(multipart);
String mediaCsid = null;
try {
assertStatusCode(mediaRes, testName);
mediaCsid = extractId(mediaRes);
} finally {
if (mediaRes != null) {
- mediaRes.releaseConnection();
+ mediaRes.close();
}
}
//
"movementReferenceNumber-" + identifier,
GregorianCalendarDateTimeUtils.timestampUTC(),
movementContactRefName);
- ClientResponse<Response> res = movementClient.create(multipart);
+ String newId = null;
+ Response res = movementClient.create(multipart);
int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- //
- // Specifically:
- // Does it fall within the set of valid status codes?
- // Does it exactly match the expected status code?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
+ try {
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ //
+ // Specifically:
+ // Does it fall within the set of valid status codes?
+ // Does it exactly match the expected status code?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(testRequestType, statusCode));
+ Assert.assertEquals(statusCode, testExpectedStatusCode);
+ newId = extractId(res);
+ } finally {
+ res.close();
}
- Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(testRequestType, statusCode));
- Assert.assertEquals(statusCode, testExpectedStatusCode);
// Store the ID returned from the first resource created
// for additional tests below.
if (knownResourceId == null){
- knownResourceId = extractId(res);
+ knownResourceId = newId;
if (logger.isDebugEnabled()) {
logger.debug(testName + ": knownResourceId=" + knownResourceId);
}
// Store the IDs from every resource created by tests,
// so they can be deleted after tests have been run.
- movementIdsCreated.add(extractId(res));
+ movementIdsCreated.add(newId);
}
protected void createPersonRefs(){
-
PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
// Create a temporary PersonAuthority resource, and its corresponding
// refName by which it can be identified.
PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName());
- ClientResponse<Response> res = personAuthClient.create(multipart);
- int statusCode = res.getStatus();
-
- Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(testRequestType, statusCode));
- Assert.assertEquals(statusCode, STATUS_CREATED);
- personAuthCSID = extractId(res);
+ Response res = personAuthClient.create(multipart);
+ try {
+ int statusCode = res.getStatus();
+
+ Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(testRequestType, statusCode));
+ Assert.assertEquals(statusCode, STATUS_CREATED);
+ personAuthCSID = extractId(res);
+ } finally {
+ res.close();
+ }
String authRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null);
}
protected String createPerson(String firstName, String surName, String shortId, String authRefName ) {
+ String result = null;
+
PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
Map<String, String> personInfo = new HashMap<String,String>();
personInfo.put(PersonJAXBSchema.FORE_NAME, firstName);
PoxPayloadOut multipart =
PersonAuthorityClientUtils.createPersonInstance(personAuthCSID,
authRefName, personInfo, personTerms, personAuthClient.getItemCommonPartName());
- ClientResponse<Response> res = personAuthClient.createItem(personAuthCSID, multipart);
- int statusCode = res.getStatus();
-
- Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(testRequestType, statusCode));
- Assert.assertEquals(statusCode, STATUS_CREATED);
- return extractId(res);
+ Response res = personAuthClient.createItem(personAuthCSID, multipart);
+ try {
+ int statusCode = res.getStatus();
+ Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(testRequestType, statusCode));
+ Assert.assertEquals(statusCode, STATUS_CREATED);
+ result = extractId(res);
+ } finally {
+ res.close();
+ }
+
+ return result;
}
// Success outcomes
PoxPayloadOut multipart = createMovementInstance(createIdentifier(),
movementNote, locationDate);
MovementClient client = new MovementClient();
- ClientResponse<Response> res = client.create(multipart);
+ Response res = client.create(multipart);
try {
assertStatusCode(res, testName);
// Store the IDs from every resource created by tests,
result = extractId(res);
} finally {
if (res != null) {
- res.releaseConnection();
+ res.close();
}
}
ObjectExitClient objectexitClient = new ObjectExitClient();
PoxPayloadOut multipart = createObjectExitInstance(depositorRefName,
"exitNumber-" + identifier, CURRENT_DATE_UTC);
- ClientResponse<Response> res = objectexitClient.create(multipart);
+ Response res = objectexitClient.create(multipart);
try {
assertStatusCode(res, testName);
if (knownResourceId == null) {// Store the ID returned from the first resource created for additional tests below.
}
} finally {
if (res != null) {
- res.releaseConnection();
+ res.close();
}
}
objectexitIdsCreated.add(extractId(res));// Store the IDs from every resource created; delete on cleanup
PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
// Create a temporary PersonAuthority resource, and its corresponding refName by which it can be identified.
PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName());
- ClientResponse<Response> res = personAuthClient.create(multipart);
+ Response res = personAuthClient.create(multipart);
try {
assertStatusCode(res, "createPersonRefs (not a surefire test)");
personAuthCSID = extractId(res);
} finally {
if (res != null) {
- res.releaseConnection();
+ res.close();
}
}
String authRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null);
displayName, shortId, orgAuthClient.getCommonPartName());
// Submit the request to the service and store the response.
- ClientResponse<Response> res = orgAuthClient.create(multipart);
+ Response res = orgAuthClient.create(multipart);
try {
int statusCode = res.getStatus();
// Check the status code of the response: does it match
// so they can be deleted after tests have been run.
String newId = extractId(res);
if (knownResourceId == null){
- setKnownResource( newId, null ); //baseRefName );
+ setKnownResource(newId, null ); //baseRefName );
}
allResourceIdsCreated.add(newId);
} finally {
- res.releaseConnection();
+ res.close();
}
// Create all the person refs and entities
PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName());
- ClientResponse<Response> res = personAuthClient.create(multipart);
+ Response res = personAuthClient.create(multipart);
try {
int statusCode = res.getStatus();
Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
Assert.assertEquals(statusCode, STATUS_CREATED);
personAuthCSID = extractId(res);
} finally {
- res.releaseConnection();
+ res.close();
}
//String authRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null);
* @param res the res
* @return the string
*/
+ public static String extractId(Response res) {
+ MultivaluedMap<String, Object> mvm = res.getMetadata();
+ // FIXME: This may throw an NPE if the Location: header isn't present
+ String uri = (String) ((ArrayList<Object>) mvm.get("Location")).get(0);
+ if(logger.isDebugEnabled()){
+ logger.debug("extractId:uri=" + uri);
+ }
+ String[] segments = uri.split("/");
+ String id = segments[segments.length - 1];
+ if(logger.isDebugEnabled()){
+ logger.debug("id=" + id);
+ }
+ return id;
+ }
+
public static String extractId(ClientResponse<Response> res) {
MultivaluedMap<String, Object> mvm = res.getMetadata();
// FIXME: This may throw an NPE if the Location: header isn't present
return id;
}
+
/**
* 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
displayName, shortId, client.getCommonPartName());
String newID = null;
- ClientResponse<Response> res = client.create(multipart);
+ Response res = client.create(multipart);
try {
assertStatusCode(res, testName);
newID = PersonAuthorityClientUtils.extractId(res);
} finally {
if (res != null) {
- res.releaseConnection();
+ res.close();
}
}
// Store the refname from the first resource created
displayName, shortId, client.getCommonPartName());
String newID = null;
- ClientResponse<Response> res = client.create(multipart);
+ Response res = client.create(multipart);
try {
assertStatusCode(res, testName);
newID = PersonAuthorityClientUtils.extractId(res);
logger.info("{}: succeeded.", testName);
} finally {
if (res != null) {
- res.releaseConnection();
+ res.close();
}
}
// Store the refname from the first resource created
displayName, shortId, client.getCommonPartName());
String newID = null;
- ClientResponse<Response> res = client.create(multipart);
+ Response res = client.create(multipart);
try {
assertStatusCode(res, testName);
newID = extractId(res);
} finally {
if (res != null) {
- res.releaseConnection();
+ res.close();
}
}
// Save values for additional tests
displayName, shortId, client.getCommonPartName());
// Submit the request to the service and store the response.
- ClientResponse<Response> res = client.create(multipart);
+ Response res = client.create(multipart);
// Check the status code of the response: does it match
// the expected response(s)?
assertStatusCode(res, testName);
} finally {
if (res != null) {
- res.releaseConnection();
+ res.close();
}
}
}
String identifier = createIdentifier();
PoxPayloadOut multipart = createPublicItemInstance(identifier);
String newID = null;
- ClientResponse<Response> res = client.create(multipart);
+ Response res = client.create(multipart);
try {
int statusCode = res.getStatus();
newID = extractId(res);
} finally {
if (res != null) {
- res.releaseConnection();
+ res.close();
}
}
PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName());
- ClientResponse<Response> res = personAuthClient.create(multipart);
- int statusCode = res.getStatus();
-
- Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(testRequestType, statusCode));
- Assert.assertEquals(statusCode, STATUS_CREATED);
- personAuthCSID = extractId(res);
-
+ Response res = personAuthClient.create(multipart);
+ try {
+ int statusCode = res.getStatus();
+
+ Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(testRequestType, statusCode));
+ Assert.assertEquals(statusCode, STATUS_CREATED);
+ personAuthCSID = extractId(res);
+ } finally {
+ res.close();
+ }
+
String authRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null);
-
String csid = createPerson("Sam", "Subject", "samSubject", authRefName);
Assert.assertNotNull(csid);
samSubjectPersonCSID = csid;
// Make the subject ID equal to the object ID
relationsCommon.setSubjectCsid(relationsCommon.getObjectCsid());
PoxPayloadOut multipart = createRelationInstance(relationsCommon);
- ClientResponse<Response> res = client.create(multipart);
- int statusCode = res.getStatus();
-
+ Response res = client.create(multipart);
+ int statusCode;
+ try {
+ statusCode = res.getStatus();
+ } finally {
+ res.close();
+ }
+
// Check the status code of the response: does it match
// the expected response(s)?
//
PoxPayloadOut poxPayloadOut = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
PayloadOutputPart commonPart = poxPayloadOut.addPart(acquisitionClient.getCommonPartName(), acquisitionsCommon);
- ClientResponse<Response> res = acquisitionClient.create(poxPayloadOut);
+ Response res = acquisitionClient.create(poxPayloadOut);
try {
setupCreate();
int statusCode = res.getStatus();
// so they can be deleted after tests have been run.
allResourceIdsCreated.add(result);
} finally {
- res.releaseConnection();
+ res.close();
}
return result;
String identifier = createIdentifier();
PoxPayloadOut multipart = createCollectionObjectInstance(
collectionObjectClient.getCommonPartName(), identifier);
- ClientResponse<Response> res = collectionObjectClient.create(multipart);
- if (logger.isDebugEnabled()) {
- logger.debug("create: status = " + res.getStatus());
+ Response res = collectionObjectClient.create(multipart);
+ try {
+ if (logger.isDebugEnabled()) {
+ logger.debug("create: status = " + res.getStatus());
+ }
+ //so it does not have any permissions out-of-the-box to create a
+ //collection object
+ Assert.assertEquals(res.getStatus(),
+ Response.Status.FORBIDDEN.getStatusCode(), "expected "
+ + Response.Status.FORBIDDEN.getStatusCode());
+
+ // Store the ID returned from this create operation for additional tests
+ // below.
+ } finally {
+ res.close();
}
- //so it does not have any permissions out-of-the-box to create a
- //collection object
- Assert.assertEquals(res.getStatus(),
- Response.Status.FORBIDDEN.getStatusCode(), "expected "
- + Response.Status.FORBIDDEN.getStatusCode());
-
- // Store the ID returned from this create operation for additional tests
- // below.
- res.releaseConnection();
}
String identifier = createIdentifier();
PoxPayloadOut multipart = createCollectionObjectInstance(
collectionObjectClient.getCommonPartName(), identifier);
- ClientResponse<Response> res = collectionObjectClient.create(multipart);
- if (logger.isDebugEnabled()) {
- logger.debug("create: status = " + res.getStatus());
+ Response res = collectionObjectClient.create(multipart);
+ try {
+ if (logger.isDebugEnabled()) {
+ logger.debug("create: status = " + res.getStatus());
+ }
+ Assert.assertEquals(res.getStatus(),
+ Response.Status.UNAUTHORIZED.getStatusCode(), "expected "
+ + Response.Status.UNAUTHORIZED.getStatusCode());
+ } finally {
+ res.close();
}
- Assert.assertEquals(res.getStatus(),
- Response.Status.UNAUTHORIZED.getStatusCode(), "expected "
- + Response.Status.UNAUTHORIZED.getStatusCode());
- res.releaseConnection();
-
}
@Test(dataProvider = "testName",
PoxPayloadOut multipart = createCollectionObjectInstance(
collectionObjectClient.getCommonPartName(), identifier);
- ClientResponse<Response> res = collectionObjectClient.create(multipart);
- if (logger.isDebugEnabled()) {
- logger.debug(testName + ": status = " + res.getStatus());
+ Response res = collectionObjectClient.create(multipart);
+ try {
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + res.getStatus());
+ }
+ Assert.assertEquals(res.getStatus(),
+ Response.Status.FORBIDDEN.getStatusCode(), "expected "
+ + Response.Status.FORBIDDEN.getStatusCode());
+ } finally {
+ res.close();
}
- Assert.assertEquals(res.getStatus(),
- Response.Status.FORBIDDEN.getStatusCode(), "expected "
- + Response.Status.FORBIDDEN.getStatusCode());
- res.releaseConnection();
}
/**
String identifier = createIdentifier();
PoxPayloadOut multipart = createCollectionObjectInstance(
collectionObjectClient.getCommonPartName(), identifier);
- ClientResponse<Response> res = collectionObjectClient.create(multipart);
- if (logger.isDebugEnabled()) {
- logger.debug(testName + ": status = " + res.getStatus());
+ Response res = collectionObjectClient.create(multipart);
+ try {
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + res.getStatus());
+ }
+ Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(), "expected " + Response.Status.UNAUTHORIZED.getStatusCode());
+ } finally {
+ res.close();
}
- Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(), "expected " + Response.Status.UNAUTHORIZED.getStatusCode());
- res.releaseConnection();
}
/**
String identifier = createIdentifier();
PoxPayloadOut multipart = createCollectionObjectInstance(
collectionObjectClient.getCommonPartName(), identifier);
- ClientResponse<Response> res = collectionObjectClient.create(multipart);
- if (logger.isDebugEnabled()) {
- logger.debug(testName + ": status = " + res.getStatus());
+ Response res = collectionObjectClient.create(multipart);
+ try {
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + res.getStatus());
+ }
+ Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(), "expected " + Response.Status.UNAUTHORIZED.getStatusCode());
+ } finally {
+ res.close();
}
- Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(), "expected " + Response.Status.UNAUTHORIZED.getStatusCode());
- res.releaseConnection();
}
/**
String identifier = createIdentifier();
PoxPayloadOut multipart = createCollectionObjectInstance(
collectionObjectClient.getCommonPartName(), identifier);
- ClientResponse<Response> res = collectionObjectClient.create(multipart);
- if (logger.isDebugEnabled()) {
- logger.debug(testName + ": status = " + res.getStatus());
+ Response res = collectionObjectClient.create(multipart);
+ try {
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + res.getStatus());
+ }
+ Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(), "expected " + Response.Status.UNAUTHORIZED.getStatusCode());
+ } finally {
+ res.close();
}
- Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(), "expected " + Response.Status.UNAUTHORIZED.getStatusCode());
- res.releaseConnection();
}
/**
String identifier = createIdentifier();
PoxPayloadOut multipart = createCollectionObjectInstance(
collectionObjectClient.getCommonPartName(), identifier);
- ClientResponse<Response> res = collectionObjectClient.create(multipart);
- if (logger.isDebugEnabled()) {
- logger.debug(testName + ": status = "
- + res.getStatus());
+ Response res = collectionObjectClient.create(multipart);
+ try {
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + res.getStatus());
+ }
+ Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(), "expected " + Response.Status.UNAUTHORIZED.getStatusCode());
+ } finally {
+ res.close();
}
- Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(), "expected " + Response.Status.UNAUTHORIZED.getStatusCode());
- res.releaseConnection();
}
/**
String identifier = createIdentifier();
PoxPayloadOut multipart = createCollectionObjectInstance(
collectionObjectClient.getCommonPartName(), identifier);
- ClientResponse<Response> res = collectionObjectClient.create(multipart);
- if (logger.isDebugEnabled()) {
- logger.debug(testName + ": status = "
- + res.getStatus());
+ Response res = collectionObjectClient.create(multipart);
+ try {
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + res.getStatus());
+ }
+ Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(), "expected " + Response.Status.UNAUTHORIZED.getStatusCode());
+ } finally {
+ res.close();
}
- Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(), "expected " + Response.Status.UNAUTHORIZED.getStatusCode());
- res.releaseConnection();
}
@Test(dataProvider = "testName",
@Test(dataProvider = "testName")
public void create(String testName) throws Exception {
+ int statusCode;
setupCreate();
// Submit the request to the service and store the response.
dimension.setValueDate(new Date().toString());
PoxPayloadOut multipart = DimensionFactory.createDimensionInstance(client.getCommonPartName(),
dimension);
- ClientResponse<Response> res = client.create(multipart);
-
- int statusCode = res.getStatus();
-
- if (logger.isDebugEnabled()) {
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(testRequestType, statusCode));
- Assert.assertEquals(statusCode, Response.Status.CREATED.getStatusCode());
- knownResourceId = extractId(res);
- if (logger.isDebugEnabled()) {
- logger.debug(testName + ": knownResourceId=" + knownResourceId);
+ Response res = client.create(multipart);
+ try {
+ statusCode = res.getStatus();
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(testRequestType, statusCode));
+ Assert.assertEquals(statusCode, Response.Status.CREATED.getStatusCode());
+ knownResourceId = extractId(res);
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": knownResourceId=" + knownResourceId);
+ }
+ } finally {
+ res.close();
}
-
+
// Now verify that elmo cannot create
client = new DimensionClient();
client.setAuth(true, "elmo2010", true, "elmo2010", true);
res = client.create(multipart);
-
- statusCode = res.getStatus();
- if (logger.isDebugEnabled()) {
- logger.debug(testName + " (verify not allowed): status = " + statusCode);
+ try {
+ statusCode = res.getStatus();
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + " (verify not allowed): status = " + statusCode);
+ }
+ Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(testRequestType, statusCode));
+ Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode());
+ } finally {
+ res.close();
}
- Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(testRequestType, statusCode));
- Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode());
//Finally, verify that elmo has no access to Intakes
// Submit the request to the service and store the response.
"entryDate-" + identifier,
"depositor-" + identifier);
res = iclient.create(multipart);
- if (logger.isDebugEnabled()) {
- logger.debug(testName + " (verify create intake not allowed): status = " + statusCode);
+ try {
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + " (verify create intake not allowed): status = " + statusCode);
+ }
+ Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(testRequestType, statusCode));
+ Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode());
+ } finally {
+ res.close();
}
- Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(testRequestType, statusCode));
- Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode());
-
}
/**
intake.setDepositor(depositor);
PoxPayloadOut multipart = new PoxPayloadOut(IntakeClient.SERVICE_PAYLOAD_NAME);
- PayloadOutputPart commonPart =
- multipart.addPart(intake, MediaType.APPLICATION_XML_TYPE);
+ PayloadOutputPart commonPart = multipart.addPart(intake, MediaType.APPLICATION_XML_TYPE);
commonPart.setLabel(new IntakeClient().getCommonPartName());
if(logger.isDebugEnabled()){
@Test(dataProvider = "testName",
dependsOnMethods = {"delete"})
public void verifyCreateWithFlippedRoles(String testName) throws Exception {
+ int statusCode;
setupCreate();
// Submit the request to the service and store the response.
dimension.setValueDate(new Date().toString());
PoxPayloadOut multipart = DimensionFactory.createDimensionInstance(client.getCommonPartName(),
dimension);
- ClientResponse<Response> res = client.create(multipart);
-
- int statusCode = res.getStatus();
-
- if (logger.isDebugEnabled()) {
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(testRequestType, statusCode));
- Assert.assertEquals(statusCode, Response.Status.CREATED.getStatusCode());
- knownResourceId = extractId(res);
- if (logger.isDebugEnabled()) {
- logger.debug(testName + ": knownResourceId=" + knownResourceId);
+ Response res = client.create(multipart);
+ try {
+ statusCode = res.getStatus();
+
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(testRequestType, statusCode));
+ Assert.assertEquals(statusCode, Response.Status.CREATED.getStatusCode());
+ knownResourceId = extractId(res);
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": knownResourceId=" + knownResourceId);
+ }
+ } finally {
+ res.close();
}
//bigbird no longer allowed to create
client.setAuth(true, "bigbird2010", true, "bigbird2010", true);
res = client.create(multipart);
-
- statusCode = res.getStatus();
- if (logger.isDebugEnabled()) {
- logger.debug(testName + " (verify not allowed): status = " + statusCode);
+ try {
+ statusCode = res.getStatus();
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + " (verify not allowed): status = " + statusCode);
+ }
+ Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(testRequestType, statusCode));
+ Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode());
+ } finally {
+ res.close();
}
- Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(testRequestType, statusCode));
- Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode());
+
restoreInitialAccountRoles();
}
//
PoxPayloadOut multipart = DimensionFactory.createDimensionInstance(client.getCommonPartName(),
dimension);
- ClientResponse<Response> res = client.create(multipart);
+ Response res = client.create(multipart);
try {
assertStatusCode(res, testName);
result = extractId(res);
} finally {
if (res != null) {
- res.releaseConnection();
+ res.close();
}
}
String identifier = createIdentifier();
PoxPayloadOut multipart = createValuationcontrolInstance(identifier);
String newID = null;
- ClientResponse<Response> res = client.create(multipart);
+ Response res = client.create(multipart);
try {
int statusCode = res.getStatus();
newID = extractId(res);
} finally {
if (res != null) {
- res.releaseConnection();
+ res.close();
}
}
<groupId>org.collectionspace.services</groupId>
<artifactId>org.collectionspace.services.vocabulary.jaxb</artifactId>
<version>${project.version}</version>
+ <exclusions>
+ <exclusion>
+ <artifactId>jsr311-api</artifactId>
+ <groupId>javax.ws.rs</groupId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.collectionspace.services</groupId>
VocabularyClient client = new VocabularyClient();
PoxPayloadOut multipart = VocabularyClientUtils.createEnumerationInstance(
"Vocab with Bad Short Id", "Bad Short Id!", client.getCommonPartName());
- ClientResponse<Response> res = client.create(multipart);
+ Response res = client.create(multipart);
try {
assertStatusCode(res, testName);
} finally {
if (res != null) {
- res.releaseConnection();
+ res.close();
}
}
}