*/
package org.collectionspace.services.ItegrationTests.test;
-import java.io.IOException;
-import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.Marshaller;
import org.testng.Assert;
import org.testng.annotations.Test;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-import org.apache.commons.httpclient.Header;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpException;
-import org.apache.commons.httpclient.HttpStatus;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.methods.HeadMethod;
-import org.apache.commons.httpclient.methods.OptionsMethod;
-import org.apache.commons.httpclient.methods.TraceMethod;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
-import org.collectionspace.services.client.TestServiceClient;
-
-import org.collectionspace.services.CollectionObjectJAXBSchema;
import org.collectionspace.services.client.CollectionObjectClient;
import org.collectionspace.services.collectionobject.CollectionobjectsCommon;
-import org.collectionspace.services.collectionobject.CollectionobjectsCommonList;
-import org.collectionspace.services.IntakeJAXBSchema;
import org.collectionspace.services.client.IntakeClient;
import org.collectionspace.services.intake.IntakesCommon;
-import org.collectionspace.services.intake.IntakesCommonList;
-import org.collectionspace.services.common.relation.RelationJAXBSchema;
import org.collectionspace.services.client.RelationClient;
import org.collectionspace.services.relation.RelationsCommon;
import org.collectionspace.services.relation.RelationsCommonList;
MultipartOutput multipart = new MultipartOutput();
OutputPart commonPart = multipart.addPart(co, MediaType.APPLICATION_XML_TYPE);
commonPart.getHeaders().add("label", collectionObjectClient.getCommonPartName());
+
// Make the create call and check the response
ClientResponse<Response> response = collectionObjectClient.create(multipart);
- Assert.assertEquals(response.getStatus(), Response.Status.CREATED
- .getStatusCode());
- String collectionObjectCsid = extractId(response);
+ String collectionObjectCsid = null;
+ try {
+ Assert.assertEquals(response.getStatus(), Response.Status.CREATED
+ .getStatusCode());
+ collectionObjectCsid = extractId(response);
+ } finally {
+ response.releaseConnection();
+ }
// Next, create an Intake object
multipart = new MultipartOutput();
commonPart = multipart.addPart(intake, MediaType.APPLICATION_XML_TYPE);
commonPart.getHeaders().add("label", intakeClient.getCommonPartName());
+
// Make the call to create and check the response
response = intakeClient.create(multipart);
- Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
- String intakeCsid = extractId(response);
+ String intakeCsid = null;
+ try {
+ Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
+ intakeCsid = extractId(response);
+ } finally {
+ response.releaseConnection();
+ }
// Lastly, relate the two entities, by creating a new relation object
RelationsCommon relation = new RelationsCommon();
multipart = new MultipartOutput();
commonPart = multipart.addPart(relation, MediaType.APPLICATION_XML_TYPE);
commonPart.getHeaders().add("label", relationClient.getCommonPartName());
+
// Make the call to crate
- response = relationClient.create(multipart);
- Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
- String relationCsid = extractId(response);
+ response = relationClient.create(multipart);
+ String relationCsid = null;
+ try {
+ Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
+ relationCsid = extractId(response);
+ } finally {
+ response.releaseConnection();
+ }
//
// Now try to retrieve the Intake record of the CollectionObject.
ClientResponse<RelationsCommonList> resultResponse = relationClient.readList_SPO(collectionObjectCsid,
predicate,
intakeCsid);
- Assert.assertEquals(resultResponse.getStatus(), Response.Status.OK.getStatusCode());
+ RelationsCommonList relationList = null;
+ try {
+ Assert.assertEquals(resultResponse.getStatus(), Response.Status.OK.getStatusCode());
+ relationList = resultResponse.getEntity();
+ } finally {
+ resultResponse.releaseConnection();
+ }
//
// Each relation returned in the list needs to match what we
// requested.
//
- RelationsCommonList relationList = resultResponse.getEntity();
List<RelationsCommonList.RelationListItem> relationListItems = relationList.getRelationListItem();
Assert.assertFalse(relationListItems.isEmpty());
- ClientResponse<RelationsCommon> resultRelationResponse;
- RelationsCommon resultRelation = null;
int i = 0;
+ RelationsCommon resultRelation = null;
for(RelationsCommonList.RelationListItem listItem : relationListItems){
String foundCsid = listItem.getCsid();
+ ClientResponse<MultipartInput> multiPartResponse = null;
try {
- ClientResponse<MultipartInput> multiPartResponse = relationClient.read(foundCsid);
+ multiPartResponse = relationClient.read(foundCsid);
int responseStatus = multiPartResponse.getStatus();
Assert.assertEquals(responseStatus, Response.Status.OK.getStatusCode());
MultipartInput input = (MultipartInput) multiPartResponse.getEntity();
RelationsCommon.class);
} catch (Exception e) {
e.printStackTrace();
+ } finally {
+ multiPartResponse.releaseConnection();
}
+
Assert.assertEquals(resultRelation.getDocumentId1(), collectionObjectCsid);
Assert.assertEquals(resultRelation.getRelationshipType(), RelationshipType.COLLECTIONOBJECT_INTAKE);
Assert.assertEquals(resultRelation.getDocumentId2(), intakeCsid);
<scope>test</scope>\r
</dependency>\r
<!-- CollectionSpace dependencies -->\r
+ <dependency>\r
+ <groupId>org.collectionspace.services</groupId>\r
+ <artifactId>org.collectionspace.services.jaxb</artifactId>\r
+ <version>${project.version}</version>\r
+ </dependency>\r
<dependency>\r
<groupId>org.collectionspace.services</groupId>\r
<artifactId>org.collectionspace.services.client</artifactId>\r
*/
package org.collectionspace.services.PerformanceTests.test;
-import java.io.IOException;
-import java.util.ArrayList;
import java.util.List;
import java.util.Date;
import java.util.Random;
import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.Marshaller;
-import org.testng.Assert;
-import org.testng.annotations.Test;
import org.testng.Assert;
import org.testng.annotations.Test;
-import org.apache.commons.httpclient.Header;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpException;
-import org.apache.commons.httpclient.HttpStatus;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.methods.HeadMethod;
-import org.apache.commons.httpclient.methods.OptionsMethod;
-import org.apache.commons.httpclient.methods.TraceMethod;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.jboss.resteasy.client.ClientResponse;
-import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
-import org.collectionspace.services.client.TestServiceClient;
-
-import org.collectionspace.services.CollectionObjectJAXBSchema;
+import org.collectionspace.services.jaxb.AbstractCommonList;
import org.collectionspace.services.client.CollectionObjectClient;
import org.collectionspace.services.collectionobject.CollectionobjectsCommon;
import org.collectionspace.services.collectionobject.CollectionobjectsCommonList;
import org.collectionspace.services.collectionobject.CollectionobjectsCommonList.CollectionObjectListItem;
-import org.collectionspace.services.IntakeJAXBSchema;
-import org.collectionspace.services.client.IntakeClient;
-import org.collectionspace.services.intake.IntakesCommon;
-import org.collectionspace.services.intake.IntakesCommonList;
-
-import org.collectionspace.services.common.relation.RelationJAXBSchema;
-import org.collectionspace.services.client.RelationClient;
-import org.collectionspace.services.relation.RelationsCommon;
-import org.collectionspace.services.relation.RelationsCommonList;
-import org.collectionspace.services.relation.RelationshipType;
-
/**
* A ServiceTest.
*
*/
public class PerformanceTest extends CollectionSpacePerformanceTest {
+ /** The Constant MAX_KEYWORDS. */
private static final int MAX_KEYWORDS = 10;
+
+ /** The Constant MAX_SEARCHES. */
private static final int MAX_SEARCHES = 10;
+
+ /** The logger. */
final Logger logger = LoggerFactory
.getLogger(PerformanceTest.class);
//
// Get clients for the CollectionSpace services
//
- private static int MAX_RECORDS = 1000;
+ /** The MA x_ records. */
+ private static int MAX_RECORDS = 100;
+ /**
+ * Performance test.
+ */
@Test
public void performanceTest() {
roundTripOverhead(10);
deleteCollectionObjects();
String[] coList = this.createCollectionObjects(MAX_RECORDS);
this.searchCollectionObjects(MAX_RECORDS);
-// this.deleteCollectionObjects(coList);
+ this.deleteCollectionObjects(coList);
roundTripOverhead(10);
}
+ /**
+ * Round trip overhead.
+ *
+ * @param numOfCalls the num of calls
+ * @return the long
+ */
private long roundTripOverhead(int numOfCalls) {
long result = 0;
CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
long totalTime = 0;
for (int i = 0; i < numOfCalls; i++) {
Date startTime = new Date();
- collectionObjectClient.roundtrip();
+ collectionObjectClient.roundtrip().releaseConnection();
Date stopTime = new Date();
totalTime = totalTime + (stopTime.getTime() - startTime.getTime());
System.out.println("Overhead roundtrip time is: " + (stopTime.getTime() - startTime.getTime()));
return result;
}
+ /**
+ * Search collection objects.
+ *
+ * @param numberOfObjects the number of objects
+ */
private void searchCollectionObjects(int numberOfObjects) {
CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
Random randomGenerator = new Random(System.currentTimeMillis());
numOfKeywords++, totalTime = 0, totalSearchResults = 0, times = "") {
keywords = keywords + " " + OBJECT_NAME + randomGenerator.nextInt(numberOfObjects);
for (int i = 0; i < MAX_SEARCHES; i++) {
+ //sandwich the call with timestamps
Date startTime = new Date();
- searchResults = collectionObjectClient.keywordSearch(keywords);
+ searchResults = collectionObjectClient.keywordSearch(keywords);
Date stopTime = new Date();
+
+ //extract the result list and release the ClientResponse
+ CollectionobjectsCommonList coListItem = null;
+ try {
+ coListItem = searchResults.getEntity();
+ } finally {
+ searchResults.releaseConnection();
+ }
+
long time = stopTime.getTime() - startTime.getTime();
times = times + " " + ((float)time / 1000);
totalTime = totalTime + time;
- totalSearchResults = totalSearchResults +
- searchResults.getEntity().getCollectionObjectListItem().size();
+ totalSearchResults = totalSearchResults +
+ coListItem.getCollectionObjectListItem().size();
}
if (logger.isDebugEnabled()) {
System.out.println("------------------------------------------------------------------------------");
return;
}
+ /**
+ * Creates the collection object.
+ *
+ * @param collectionObjectClient the collection object client
+ * @param identifier the identifier
+ * @return the string
+ */
private String createCollectionObject(CollectionObjectClient collectionObjectClient,
int identifier) {
String result = null;
commonPart.getHeaders().add("label", collectionObjectClient.getCommonPartName());
// Make the create call and check the response
ClientResponse<Response> response = collectionObjectClient.create(multipart);
-
- int responseStatus = response.getStatus();
- if (logger.isDebugEnabled() == true) {
- if (responseStatus != Response.Status.CREATED.getStatusCode())
- logger.debug("Status of call to create CollectionObject was: " +
- responseStatus);
+ try {
+ int responseStatus = response.getStatus();
+ if (logger.isDebugEnabled() == true) {
+ if (responseStatus != Response.Status.CREATED.getStatusCode())
+ logger.debug("Status of call to create CollectionObject was: " +
+ responseStatus);
+ }
+
+ Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
+ result = extractId(response);
+ } finally {
+ response.releaseConnection();
}
- Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
- result = extractId(response);
-
return result;
}
+ /**
+ * Creates the collection objects.
+ *
+ * @param numberOfObjects the number of objects
+ * @return the string[]
+ */
public String[] createCollectionObjects(int numberOfObjects) {
Random randomGenerator = new Random(System.currentTimeMillis());
CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
Date startTime = new Date();
for (int i = 0; i < numberOfObjects; i++, createdObjects++) {
coList[i] = createCollectionObject(collectionObjectClient, i + 1);
+ if (logger.isDebugEnabled() == true) {
+ logger.debug("Created CollectionObject #: " + i);
+ }
}
Date stopTime = new Date();
if (logger.isDebugEnabled()) {
return coList;
}
+ /**
+ * Delete collection object.
+ *
+ * @param collectionObjectClient the collection object client
+ * @param resourceId the resource id
+ */
private void deleteCollectionObject(CollectionObjectClient collectionObjectClient,
String resourceId) {
- ClientResponse<Response> res = collectionObjectClient.delete(resourceId);
+ ClientResponse<Response> res = collectionObjectClient.delete(resourceId);
+ res.releaseConnection();
}
+ /**
+ * Delete collection objects.
+ *
+ * @param arrayOfObjects the array of objects
+ */
public void deleteCollectionObjects(String[] arrayOfObjects) {
CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
Date startTime = new Date();
for (int i = 0; i < arrayOfObjects.length; i++) {
deleteCollectionObject(collectionObjectClient, arrayOfObjects[i]);
- }
-
+ }
Date stopTime = new Date();
+
if (logger.isDebugEnabled()) {
System.out.println("Deleted " + arrayOfObjects.length + " CollectionObjects" +
" in " + (stopTime.getTime() - startTime.getTime())/1000.0 + " seconds.");
}
}
+ /**
+ * Delete collection objects.
+ * FIXME: Deletes a page at a time until there are no more CollectionObjects.
+ */
public void deleteCollectionObjects() {
CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
- ClientResponse<CollectionobjectsCommonList> commonsList;
- commonsList = collectionObjectClient.readList();
- List<CollectionObjectListItem> coListItems = commonsList.getEntity().getCollectionObjectListItem();
-
- Date startTime = new Date();
- for (CollectionObjectListItem i:coListItems) {
- deleteCollectionObject(collectionObjectClient, i.getCsid());
- }
- Date stopTime = new Date();
+ ClientResponse<AbstractCommonList> response;
- if (logger.isDebugEnabled()) {
- System.out.println("Deleted " + coListItems.size() + " CollectionObjects" +
- " in " + (stopTime.getTime() - startTime.getTime())/1000.0 + " seconds.");
- }
+ List<CollectionObjectListItem> coListItems = null;
+ do {
+ response = collectionObjectClient.readList(Integer.toString(MAX_RECORDS),
+ Integer.toString(0));
+ try {
+ CollectionobjectsCommonList commonListElement =
+ (CollectionobjectsCommonList)response.getEntity(CollectionobjectsCommonList.class);
+ coListItems = commonListElement.getCollectionObjectListItem();
+ } finally {
+ response.releaseConnection();
+ }
+
+ Date startTime = new Date();
+ for (CollectionObjectListItem i:coListItems) {
+ deleteCollectionObject(collectionObjectClient, i.getCsid());
+ }
+ Date stopTime = new Date();
+
+ if (logger.isDebugEnabled()) {
+ System.out.println("Deleted " + coListItems.size() + " CollectionObjects" +
+ " in " + (stopTime.getTime() - startTime.getTime())/1000.0 + " seconds.");
+ }
+ } while (coListItems.size() > 0);
}
}
/* (non-Javadoc)
* @see org.collectionspace.services.client.AbstractServiceClientImpl#getServicePathComponent()
*/
+ @Override
public String getServicePathComponent() {
return "accounts";
}
}
/**
- * @return
+ * @return response
* @see org.collectionspace.hello.client.AccountProxy#readList()
*/
public ClientResponse<AccountsCommonList> readList() {
/**
* @param csid
- * @return
+ * @return response
* @see org.collectionspace.hello.client.AccountProxy#getAccount(java.lang.String)
*/
public ClientResponse<AccountsCommon> read(String csid) {
}
/**
+ * @param multipart
* @param account
- * @return
+ * @return response
* @see org.collectionspace.hello.client.AccountProxy#create(org.collectionspace.services.account.AccountsCommon)
*/
public ClientResponse<Response> create(AccountsCommon multipart) {
/**
* @param csid
+ * @param multipart
* @param account
- * @return
+ * @return response
* @see org.collectionspace.hello.client.AccountProxy#updateAccount(java.lang.Long, org.collectionspace.services.account.AccountsCommon)
*/
public ClientResponse<AccountsCommon> update(String csid, AccountsCommon multipart) {
/**
* @param csid
- * @return
+ * @return response
* @see org.collectionspace.hello.client.AccountProxy#deleteAccount(java.lang.Long)
*/
- public ClientResponse<Response> delete(String csid) {
+ @Override
+ public ClientResponse<Response> delete(String csid) {
return accountProxy.delete(csid);
}
}
*/
public class AccountRoleServiceTest extends AbstractServiceTestImpl {
+ /** The Constant logger. */
static private final Logger logger =
LoggerFactory.getLogger(AccountRoleServiceTest.class);
// Instance variables specific to this test.
+ /** The known resource id. */
private String knownResourceId = null;
+
+ /** The all resource ids created. */
private List<String> allResourceIdsCreated = new ArrayList<String>();
+
+ /** The acc values. */
private Hashtable<String, AccountValue> accValues = new Hashtable<String, AccountValue>();
+
+ /** The role values. */
private Hashtable<String, RoleValue> roleValues = new Hashtable<String, RoleValue>();
/*
* This method is called only by the parent class, AbstractServiceTestImpl
*/
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
+ */
@Override
protected String getServicePathComponent() {
return new AccountRoleClient().getServicePathComponent();
}
+ /**
+ * Seed data.
+ */
@BeforeClass(alwaysRun = true)
public void seedData() {
String userId = "acc-role-user1";
*/
@Override
protected CollectionSpaceClient getClientInstance() {
- return new AccountRoleClient();
+ return new AccountRoleClient();
}
-
+
/* (non-Javadoc)
* @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
*/
@Override
- protected AbstractCommonList getAbstractCommonList(
- ClientResponse<AbstractCommonList> response) {
- //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
- throw new UnsupportedOperationException();
+ protected AbstractCommonList getAbstractCommonList(
+ ClientResponse<AbstractCommonList> response) {
+ //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
+ throw new UnsupportedOperationException();
}
-
- @Test(dataProvider = "testName")
- @Override
+
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String)
+ */
+ @Test(dataProvider = "testName")
+ @Override
public void readPaginatedList(String testName) throws Exception {
- //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
- }
-
+ //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
+ }
+
// ---------------------------------------------------------------
// CRUD tests : CREATE tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
public void create(String testName) throws Exception {
roleValues.values(), true, true);
AccountRoleClient client = new AccountRoleClient();
ClientResponse<Response> res = client.create(pv.getAccountId(), accRole);
- int statusCode = res.getStatus();
-
- if (logger.isDebugEnabled()) {
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-
- // Store the ID returned from this create operation
- // for additional tests below.
- //this is is not important in case of this relationship
- knownResourceId = extractId(res);
- if (logger.isDebugEnabled()) {
- logger.debug(testName + ": knownResourceId=" + knownResourceId);
+ try {
+ int statusCode = res.getStatus();
+
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ // Store the ID returned from this create operation
+ // for additional tests below.
+ //this is is not important in case of this relationship
+ knownResourceId = extractId(res);
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": knownResourceId=" + knownResourceId);
+ }
+ } finally {
+ res.releaseConnection();
}
- res.releaseConnection();
}
//to not cause uniqueness violation for accRole, createList is removed
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
+ */
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"create"})
@Override
public void createList(String testName) throws Exception {
- //FIXME: Should this test really be empty? If so, please comment accordingly.
+ //FIXME: Should this test really be empty? If so, please comment accordingly.
}
// Failure outcomes
// Placeholders until the three tests below can be uncommented.
// See Issue CSPACE-401.
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
+ */
@Override
public void createWithEmptyEntityBody(String testName) throws Exception {
- //FIXME: Should this test really be empty? If so, please comment accordingly.
+ //FIXME: Should this test really be empty? If so, please comment accordingly.
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
+ */
@Override
public void createWithMalformedXml(String testName) throws Exception {
- //FIXME: Should this test really be empty? If so, please comment accordingly.
+ //FIXME: Should this test really be empty? If so, please comment accordingly.
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
+ */
@Override
public void createWithWrongXmlSchema(String testName) throws Exception {
- //FIXME: Should this test really be empty? If so, please comment accordingly.
+ //FIXME: Should this test really be empty? If so, please comment accordingly.
}
// ---------------------------------------------------------------
// CRUD tests : READ tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"create"})
ClientResponse<AccountRole> res = client.read(
accValues.get("acc-role-user1").getAccountId(), "123");
int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if (logger.isDebugEnabled()) {
- logger.debug(testName + ": status = " + statusCode);
+ try {
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ AccountRole output = (AccountRole) res.getEntity();
+ Assert.assertNotNull(output);
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-
- AccountRole output = (AccountRole) res.getEntity();
- Assert.assertNotNull(output);
- res.releaseConnection();
}
// Failure outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
public void readNonExistent(String testName) throws Exception {
AccountRoleClient client = new AccountRoleClient();
ClientResponse<AccountRole> res = client.read(this.NON_EXISTENT_ID, "123");
int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if (logger.isDebugEnabled()) {
- logger.debug(testName + ": status = " + statusCode);
+ try {
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
- res.releaseConnection();
}
// ---------------------------------------------------------------
// CRUD tests : READ_LIST tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"createList", "read"})
public void readList(String testName) throws Exception {
- //FIXME: Should this test really be empty? If so, please comment accordingly.
+ //FIXME: Should this test really be empty? If so, please comment accordingly.
}
// Failure outcomes
// CRUD tests : UPDATE tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"read", "readList", "readNonExistent"})
public void update(String testName) throws Exception {
- //FIXME: Should this test really be empty? If so, please comment accordingly.
+ //FIXME: Should this test really be empty? If so, please comment accordingly.
}
// Failure outcomes
// Placeholders until the three tests below can be uncommented.
// See Issue CSPACE-401.
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
+ */
@Override
public void updateWithEmptyEntityBody(String testName) throws Exception {
- //FIXME: Should this test really be empty? If so, please comment accordingly.
+ //FIXME: Should this test really be empty? If so, please comment accordingly.
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
+ */
@Override
public void updateWithMalformedXml(String testName) throws Exception {
- //FIXME: Should this test really be empty? If so, please comment accordingly.
+ //FIXME: Should this test really be empty? If so, please comment accordingly.
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
+ */
@Override
public void updateWithWrongXmlSchema(String testName) throws Exception {
- //FIXME: Should this test really be empty? If so, please comment accordingly.
+ //FIXME: Should this test really be empty? If so, please comment accordingly.
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"readNonExistent", "testSubmitRequest"})
public void updateNonExistent(String testName) throws Exception {
- //FIXME: Should this test really be empty? If so, please comment accordingly.
+ //FIXME: Should this test really be empty? If so, please comment accordingly.
}
// ---------------------------------------------------------------
// CRUD tests : DELETE tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"read"})
public void delete(String testName) throws Exception {
-
// Perform setup.
setupDelete(testName);
ClientResponse<Response> res = client.delete(
accValues.get("acc-role-user1").getAccountId(), "123");
int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if (logger.isDebugEnabled()) {
- logger.debug(testName + ": status = " + statusCode);
+ try {
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
- res.releaseConnection();
}
// Failure outcomes
/**
* Tests the code for manually submitting data that is used by several
* of the methods above.
+ * @throws Exception
*/
@Test(dependsOnMethods = {"create"})
public void testSubmitRequest() throws Exception {
return accRole;
}
+ /**
+ * Clean up.
+ */
@AfterClass(alwaysRun = true)
+ @Override
public void cleanUp() {
setupDelete("delete");
+
String noTest = System.getProperty("noTestCleanup");
- if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
+ if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
if (logger.isDebugEnabled()) {
logger.debug("Skipping Cleanup phase ...");
}
return;
- }
+ }
if (logger.isDebugEnabled()) {
logger.debug("Cleaning up temporary resources created for testing ...");
}
+
AccountRoleClient client = new AccountRoleClient();
for (String resourceId : allResourceIdsCreated) {
-
ClientResponse<Response> res = client.delete(resourceId, "123");
- int statusCode = res.getStatus();
- if (logger.isDebugEnabled()) {
- logger.debug("clenaup: delete relationships for accission id="
- + resourceId + " status=" + statusCode);
+ try {
+ int statusCode = res.getStatus();
+ if (logger.isDebugEnabled()) {
+ logger.debug("clenaup: delete relationships for accission id="
+ + resourceId + " status=" + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
- res.releaseConnection();
}
for (AccountValue pv : accValues.values()) {
}
}
+ /**
+ * Creates the account.
+ *
+ * @param userName the user name
+ * @param email the email
+ * @return the string
+ */
private String createAccount(String userName, String email) {
setupCreate();
AccountClient accClient = new AccountClient();
return extractId(res);
}
+ /**
+ * Delete account.
+ *
+ * @param accId the acc id
+ */
private void deleteAccount(String accId) {
setupDelete();
AccountClient accClient = new AccountClient();
ClientResponse<Response> res = accClient.delete(accId);
int statusCode = res.getStatus();
- if (logger.isDebugEnabled()) {
- logger.debug("deleteAccount: delete account id="
- + accId + " status=" + statusCode);
+ try {
+ if (logger.isDebugEnabled()) {
+ logger.debug("deleteAccount: delete account id="
+ + accId + " status=" + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
- res.releaseConnection();
}
+ /**
+ * Creates the role.
+ *
+ * @param roleName the role name
+ * @return the string
+ */
private String createRole(String roleName) {
setupCreate();
RoleClient roleClient = new RoleClient();
return extractId(res);
}
+ /**
+ * Delete role.
+ *
+ * @param roleId the role id
+ */
private void deleteRole(String roleId) {
setupDelete();
RoleClient roleClient = new RoleClient();
ClientResponse<Response> res = roleClient.delete(roleId);
int statusCode = res.getStatus();
- if (logger.isDebugEnabled()) {
- logger.debug("deleteRole: delete role id=" + roleId
- + " status=" + statusCode);
+ try {
+ if (logger.isDebugEnabled()) {
+ logger.debug("deleteRole: delete role id=" + roleId
+ + " status=" + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
- res.releaseConnection();
}
}
*/
public class AccountServiceTest extends AbstractServiceTestImpl {
+ /** The Constant logger. */
static private final Logger logger =
LoggerFactory.getLogger(AccountServiceTest.class);
// Instance variables specific to this test.
+ /** The known resource id. */
private String knownResourceId = null;
- private List<String> allResourceIdsCreated = new ArrayList();
+
+ /** The add tenant. */
static boolean addTenant = true;
/*
* This method is called only by the parent class, AbstractServiceTestImpl
*/
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
+ */
@Override
protected String getServicePathComponent() {
return new AccountClient().getServicePathComponent();
// CRUD tests : CREATE tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
public void create(String testName) throws Exception {
}
}
+ /**
+ * Creates the for unique user.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"create"})
public void createForUniqueUser(String testName) throws Exception {
Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
}
+ /**
+ * Creates the with invalid tenant.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"create"})
public void createWithInvalidTenant(String testName) throws Exception {
}
+ /**
+ * Creates the without user.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"create"})
public void createWithoutUser(String testName) throws Exception {
Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
}
+ /**
+ * Creates the with invalid email.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"create"})
public void createWithInvalidEmail(String testName) throws Exception {
Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
}
+ /**
+ * Creates the without screen name.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"create"})
public void createWithoutScreenName(String testName) throws Exception {
Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
}
+ /**
+ * Creates the with invalid password.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"create"})
public void createWithInvalidPassword(String testName) throws Exception {
Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
}
+ /**
+ * Creates the with most invalid.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"create"})
public void createWithMostInvalid(String testName) throws Exception {
}
//to not cause uniqueness violation for account, createList is removed
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"create"})
// Failure outcomes
// Placeholders until the three tests below can be uncommented.
// See Issue CSPACE-401.
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
+ */
@Override
public void createWithEmptyEntityBody(String testName) throws Exception {
//FIXME: Should this test really be empty? If so, please comment accordingly.
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
+ */
@Override
public void createWithMalformedXml(String testName) throws Exception {
//FIXME: Should this test really be empty? If so, please comment accordingly.
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
+ */
@Override
public void createWithWrongXmlSchema(String testName) throws Exception {
//FIXME: Should this test really be empty? If so, please comment accordingly.
// CRUD tests : READ tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"create"})
}
// Failure outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"read"})
// CRUD tests : READ_LIST tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"createList", "read"})
}
}
+ /**
+ * Search screen name.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"createList", "read"})
public void searchScreenName(String testName) throws Exception {
}
}
+ /**
+ * Search user id.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"createList", "read"})
public void searchUserId(String testName) throws Exception {
}
}
+ /**
+ * Search email.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"createList", "read"})
public void searchEmail(String testName) throws Exception {
}
}
+ /**
+ * Search screen name email.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"createList", "read"})
public void searchScreenNameEmail(String testName) throws Exception {
// CRUD tests : UPDATE tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"read", "readList", "readNonExistent"})
"Data in updated object did not match submitted data.");
}
+ /**
+ * Update password.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"update"})
public void updatePassword(String testName) throws Exception {
// "Data in updated object did not match submitted data.");
}
+ /**
+ * Update password without user.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"update"})
public void updatePasswordWithoutUser(String testName) throws Exception {
}
+ /**
+ * Update invalid password.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"update"})
public void updateInvalidPassword(String testName) throws Exception {
}
+ /**
+ * Deactivate.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"updatePasswordWithoutUser"})
public void deactivate(String testName) throws Exception {
// Failure outcomes
// Placeholders until the three tests below can be uncommented.
// See Issue CSPACE-401.
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
+ */
@Override
public void updateWithEmptyEntityBody(String testName) throws Exception {
//FIXME: Should this test really be empty? If so, please comment accordingly.
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
+ */
@Override
public void updateWithMalformedXml(String testName) throws Exception {
//FIXME: Should this test really be empty? If so, please comment accordingly.
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
+ */
@Override
public void updateWithWrongXmlSchema(String testName) throws Exception {
//FIXME: Should this test really be empty? If so, please comment accordingly.
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"deactivate", "readNonExistent", "testSubmitRequest"})
Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
}
+ /**
+ * Update wrong user.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"deactivate", "readNonExistent", "testSubmitRequest"})
public void updateWrongUser(String testName) throws Exception {
// CRUD tests : DELETE tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"testSubmitRequest", "updateWrongUser"})
}
// Failure outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"delete"})
/**
* Tests the code for manually submitting data that is used by several
* of the methods above.
+ * @throws Exception
*/
@Test(dependsOnMethods = {"create", "read"})
public void testSubmitRequest() throws Exception {
}
- @AfterClass(alwaysRun = true)
- public void cleanUp() {
- setupDelete("delete");
- String noTest = System.getProperty("noTestCleanup");
- if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
- if (logger.isDebugEnabled()) {
- logger.debug("Skipping Cleanup phase ...");
- }
- return;
- }
- if (logger.isDebugEnabled()) {
- logger.debug("Cleaning up temporary resources created for testing ...");
- }
- AccountClient client = new AccountClient();
- for (String resourceId : allResourceIdsCreated) {
- // Note: Any non-success responses are ignored and not reported.
- ClientResponse<Response> res = client.delete(resourceId);
- int statusCode = res.getStatus();
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
- }
- }
-
+ /**
+ * Prints the list.
+ *
+ * @param testName the test name
+ * @param list the list
+ */
private void printList(String testName, AccountsCommonList list) {
List<AccountsCommonList.AccountListItem> items =
list.getAccountListItem();
import javax.persistence.Query;
import org.collectionspace.services.account.AccountTenant;
import org.collectionspace.services.account.AccountsCommon;
-import org.collectionspace.services.account.Tenant;
+//import org.collectionspace.services.account.Tenant;
import org.collectionspace.services.account.Status;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.collectionspace.services.common.authorityref.AuthorityRefList;
import org.collectionspace.services.jaxb.AbstractCommonList;
import org.collectionspace.services.acquisition.AcquisitionsCommon;
-import org.collectionspace.services.acquisition.AcquisitionsCommonList;
+//import org.collectionspace.services.acquisition.AcquisitionsCommonList;
import org.jboss.resteasy.client.ClientResponse;
final String SERVICE_PATH_COMPONENT = "acquisitions";
final String PERSON_AUTHORITY_NAME = "TestPersonAuth";
private String knownResourceId = null;
- private List<String> acquisitionIdsCreated = new ArrayList();
- private List<String> personIdsCreated = new ArrayList();
+ private List<String> acquisitionIdsCreated = new ArrayList<String>();
+ private List<String> personIdsCreated = new ArrayList<String>();
private int CREATED_STATUS = Response.Status.CREATED.getStatusCode();
private int OK_STATUS = Response.Status.OK.getStatusCode();
private String personAuthCSID = null;
for (String resourceId : acquisitionIdsCreated) {
// Note: Any non-success responses are ignored and not reported.
ClientResponse<Response> res = acquisitionClient.delete(resourceId);
+ res.releaseConnection();
}
PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
// Delete persons before PersonAuth
for (String resourceId : personIdsCreated) {
// Note: Any non-success responses are ignored and not reported.
ClientResponse<Response> res = personAuthClient.deleteItem(personAuthCSID, resourceId);
+ res.releaseConnection();
}
// Note: Any non-success response is ignored and not reported.
ClientResponse<Response> res = personAuthClient.delete(personAuthCSID);
+ res.releaseConnection();
}
// ---------------------------------------------------------------
*/
package org.collectionspace.services.client.test;
-import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
import org.testng.Assert;
-import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
import org.slf4j.Logger;
*/
public class AcquisitionServiceTest extends AbstractServiceTestImpl {
+ /** The logger. */
private final Logger logger =
LoggerFactory.getLogger(AcquisitionServiceTest.class);
// Instance variables specific to this test.
+ /** The known resource id. */
private String knownResourceId = null;
- private List<String> allResourceIdsCreated = new ArrayList();
/* (non-Javadoc)
* @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
// CRUD tests : CREATE tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
+ */
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
public void create(String testName) throws Exception {
allResourceIdsCreated.add(extractId(res));
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
+ */
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
dependsOnMethods = {"create"})
// Failure outcomes
// Placeholders until the three tests below can be uncommented.
// See Issue CSPACE-401.
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
+ */
@Override
public void createWithEmptyEntityBody(String testName) throws Exception {
+ //Should this really be empty?
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
+ */
@Override
public void createWithMalformedXml(String testName) throws Exception {
+ //Should this really be empty?
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
+ */
@Override
public void createWithWrongXmlSchema(String testName) throws Exception {
+ //Should this really be empty?
}
/*
// CRUD tests : READ tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
+ */
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
dependsOnMethods = {"create"})
}
// Failure outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
+ */
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
dependsOnMethods = {"read"})
// CRUD tests : READ_LIST tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
+ */
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
dependsOnMethods = {"createList", "read"})
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
+ */
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
dependsOnMethods = {"read"})
// Failure outcomes
// Placeholders until the three tests below can be uncommented.
// See Issue CSPACE-401.
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
+ */
@Override
public void updateWithEmptyEntityBody(String testName) throws Exception {
+ //Should this really be empty?
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
+ */
@Override
public void updateWithMalformedXml(String testName) throws Exception {
+ //Should this really be empty?
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
+ */
@Override
public void updateWithWrongXmlSchema(String testName) throws Exception {
+ //Should this really be empty?
}
/*
}
*/
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
+ */
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
dependsOnMethods = {"update", "testSubmitRequest"})
// CRUD tests : DELETE tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
+ */
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
dependsOnMethods = {"create", "read", "update"})
}
// Failure outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
+ */
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
dependsOnMethods = {"delete"})
/**
* Tests the code for manually submitting data that is used by several
* of the methods above.
+ * @throws Exception
*/
@Test(dependsOnMethods = {"create", "read"})
public void testSubmitRequest() throws Exception {
}
- // ---------------------------------------------------------------
- // Cleanup of resources created during testing
- // ---------------------------------------------------------------
-
- /**
- * Deletes all resources created by tests, after all tests have been run.
- *
- * This cleanup method will always be run, even if one or more tests fail.
- * For this reason, it attempts to remove all resources created
- * at any point during testing, even if some of those resources
- * may be expected to be deleted by certain tests.
- */
- @AfterClass(alwaysRun=true)
- public void cleanUp() {
- String noTest = System.getProperty("noTestCleanup");
- if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
- if (logger.isDebugEnabled()) {
- logger.debug("Skipping Cleanup phase ...");
- }
- return;
- }
- if (logger.isDebugEnabled()) {
- logger.debug("Cleaning up temporary resources created for testing ...");
- }
- AcquisitionClient client = new AcquisitionClient();
- for (String resourceId : allResourceIdsCreated) {
- // Note: Any non-success responses are ignored and not reported.
- ClientResponse<Response> res = client.delete(resourceId);
- }
- }
-
// ---------------------------------------------------------------
// Utility methods used by tests above
// ---------------------------------------------------------------
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
+ */
@Override
public String getServicePathComponent() {
return new AcquisitionClient().getServicePathComponent();
}
+ /**
+ * Creates the acquisition instance.
+ *
+ * @param identifier the identifier
+ * @return the multipart output
+ */
private MultipartOutput createAcquisitionInstance(String identifier) {
AcquisitionsCommon acquisition = new AcquisitionsCommon();
acquisition.setAcquisitionReferenceNumber("acquisitionReferenceNumber-" + identifier);
*/
public class PermissionRoleClient extends AbstractServiceClientImpl {
- /**
- *
- */
+ /** The permission role proxy. */
private PermissionRoleProxy permissionRoleProxy;
/* (non-Javadoc)
setProxy();
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.CollectionSpaceClient#getProxy()
+ */
@Override
public CollectionSpaceProxy getProxy() {
return this.permissionRoleProxy;
}
/**
- * allow to reset proxy as per security needs
+ * allow to reset proxy as per security needs.
*/
public void setProxy() {
if (useAuth()) {
/**
- * @param csid
+ * Read.
+ *
+ * @param csid the csid
* @param prcsid relationship does not have an id, junk is fine
- * @return
- * @see
+ * @return the client response
+ * @see
*/
public ClientResponse<PermissionRole> read(String csid, String prcsid) {
return permissionRoleProxy.read(csid, prcsid);
}
/**
- * @param permRole
- * @return
- * @see
+ * Creates the.
+ *
+ * @param csid the csid
+ * @param permRole the perm role
+ * @return the client response
+ * @see
*/
public ClientResponse<Response> create(String csid, PermissionRole permRole) {
return permissionRoleProxy.create(csid, permRole);
}
-
/**
- * @param csid
+ * Delete.
+ *
+ * @param csid the csid
* @param prcsid relationship does not have an id, junk is fine
- * @return
- * @see
+ * @return response
+ * @see
*/
public ClientResponse<Response> delete(String csid, String prcsid) {
return permissionRoleProxy.delete(csid, prcsid);
}
+
}
*/
public class PermissionRoleServiceTest extends AbstractServiceTestImpl {
+ /** The Constant logger. */
static private final Logger logger =
LoggerFactory.getLogger(PermissionRoleServiceTest.class);
// Instance variables specific to this test.
+ /** The known resource id. */
private String knownResourceId = null;
- private List<String> allResourceIdsCreated = new ArrayList();
+
+ /** The all resource ids created. */
+ private List<String> allResourceIdsCreated = new ArrayList<String>();
+
+ /** The perm values. */
private Hashtable<String, PermissionValue> permValues = new Hashtable<String, PermissionValue>();
+
+ /** The role values. */
private Hashtable<String, RoleValue> roleValues = new Hashtable<String, RoleValue>();
/*
* This method is called only by the parent class, AbstractServiceTestImpl
*/
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
+ */
@Override
protected String getServicePathComponent() {
return new PermissionRoleClient().getServicePathComponent();
}
+ /**
+ * Seed data.
+ */
@BeforeClass(alwaysRun = true)
public void seedData() {
String ra = "accounts";
*/
@Override
protected CollectionSpaceClient getClientInstance() {
- return new PermissionRoleClient();
+ return new PermissionRoleClient();
}
-
+
/* (non-Javadoc)
* @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
*/
@Override
- protected AbstractCommonList getAbstractCommonList(
- ClientResponse<AbstractCommonList> response) {
- //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
- throw new UnsupportedOperationException();
+ protected AbstractCommonList getAbstractCommonList(
+ ClientResponse<AbstractCommonList> response) {
+ //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
+ throw new UnsupportedOperationException();
}
-
- @Test(dataProvider = "testName")
- @Override
+
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String)
+ */
+ @Test(dataProvider = "testName")
+ @Override
public void readPaginatedList(String testName) throws Exception {
- //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
- }
+ //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
+ }
// ---------------------------------------------------------------
// CRUD tests : CREATE tests
// ---------------------------------------------------------------
// Success outcomes
-
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
public void create(String testName) throws Exception {
}
//to not cause uniqueness violation for permRole, createList is removed
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"create"})
public void createList(String testName) throws Exception {
+ //Should this really be empty?
}
// Failure outcomes
// Placeholders until the three tests below can be uncommented.
// See Issue CSPACE-401.
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
+ */
@Override
public void createWithEmptyEntityBody(String testName) throws Exception {
+ //Should this really be empty?
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
+ */
@Override
public void createWithMalformedXml(String testName) throws Exception {
+ //Should this really be empty?
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
+ */
@Override
public void createWithWrongXmlSchema(String testName) throws Exception {
+ //Should this really be empty?
}
// ---------------------------------------------------------------
// CRUD tests : READ tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"create"})
}
// Failure outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
public void readNonExistent(String testName) throws Exception {
// CRUD tests : READ_LIST tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"createList", "read"})
public void readList(String testName) throws Exception {
+ //Should this really be empty?
}
// Failure outcomes
// CRUD tests : UPDATE tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"read", "readList", "readNonExistent"})
public void update(String testName) throws Exception {
+ //Should this really be empty?
}
// Failure outcomes
// Placeholders until the three tests below can be uncommented.
// See Issue CSPACE-401.
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
+ */
@Override
public void updateWithEmptyEntityBody(String testName) throws Exception {
+ //Should this really be empty?
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
+ */
@Override
public void updateWithMalformedXml(String testName) throws Exception {
+ //Should this really be empty?
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
+ */
@Override
public void updateWithWrongXmlSchema(String testName) throws Exception {
+ //Should this really be empty?
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"readNonExistent", "testSubmitRequest"})
public void updateNonExistent(String testName) throws Exception {
+ //Should this really be empty?
}
// ---------------------------------------------------------------
// CRUD tests : DELETE tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"read"})
}
// Failure outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
public void deleteNonExistent(String testName) throws Exception {
/**
* Tests the code for manually submitting data that is used by several
* of the methods above.
+ * @throws Exception
*/
@Test(dependsOnMethods = {"create"})
public void testSubmitRequest() throws Exception {
// ---------------------------------------------------------------
/**
* create permRolerole instance
+ * @param pv
+ * @param rvs
+ * @param usePermId
* @param permId
* @param roleValues array of role ids
* @param userPermId
* @param useRoleId
- * @return
+ * @return PermissionRole
*/
public static PermissionRole createPermissionRoleInstance(PermissionValue pv,
Collection<RoleValue> rvs,
return permRole;
}
+ /**
+ * Clean up.
+ */
@AfterClass(alwaysRun = true)
+ @Override
public void cleanUp() {
setupDelete("cleanup");
String noTest = System.getProperty("noTestCleanup");
- if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
+ if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
if (logger.isDebugEnabled()) {
logger.debug("Skipping Cleanup phase ...");
}
return;
- }
+ }
if (logger.isDebugEnabled()) {
logger.debug("Cleaning up temporary resources created for testing ...");
}
+
+ PermissionRoleClient client = new PermissionRoleClient();
+ for (String resourceId : allResourceIdsCreated) {
+
+ ClientResponse<Response> res = client.delete(resourceId, "123");
+ int statusCode = res.getStatus();
+ try {
+ if (logger.isDebugEnabled()) {
+ logger.debug("cleanup: delete relationships for permission id="
+ + resourceId + " status=" + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ } finally {
+ res.releaseConnection();
+ }
+ }
+
for (PermissionValue pv : permValues.values()) {
deletePermission(pv.getPermissionId());
}
}
}
+ /**
+ * Creates the permission.
+ *
+ * @param resName the res name
+ * @param effect the effect
+ * @return the string
+ */
private String createPermission(String resName, EffectType effect) {
setupCreate();
PermissionClient permClient = new PermissionClient();
return extractId(res);
}
+ /**
+ * Delete permission.
+ *
+ * @param permId the perm id
+ */
private void deletePermission(String permId) {
setupDelete();
PermissionClient permClient = new PermissionClient();
ClientResponse<Response> res = permClient.delete(permId);
int statusCode = res.getStatus();
- if (logger.isDebugEnabled()) {
- logger.debug("deletePermission: delete permission id="
- + permId + " status=" + statusCode);
+ try {
+ if (logger.isDebugEnabled()) {
+ logger.debug("deletePermission: delete permission id="
+ + permId + " status=" + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
res.releaseConnection();
}
+ /**
+ * Creates the role.
+ *
+ * @param roleName the role name
+ * @return the string
+ */
private String createRole(String roleName) {
setupCreate();
RoleClient roleClient = new RoleClient();
return extractId(res);
}
+ /**
+ * Delete role.
+ *
+ * @param roleId the role id
+ */
private void deleteRole(String roleId) {
setupDelete();
RoleClient roleClient = new RoleClient();
ClientResponse<Response> res = roleClient.delete(roleId);
int statusCode = res.getStatus();
- if (logger.isDebugEnabled()) {
- logger.debug("deleteRole: delete role id=" + roleId
- + " status=" + statusCode);
+ try {
+ if (logger.isDebugEnabled()) {
+ logger.debug("deleteRole: delete role id=" + roleId
+ + " status=" + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
res.releaseConnection();
}
}
*/
package org.collectionspace.services.authorization.client.test;
-import java.util.ArrayList;
+//import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.core.Response;
//import org.collectionspace.services.authorization.ActionType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.testng.annotations.AfterClass;
/**
* PermissionServiceTest, carries out tests against a
*/
public class PermissionServiceTest extends AbstractServiceTestImpl {
+ /** The Constant logger. */
static private final Logger logger =
LoggerFactory.getLogger(PermissionServiceTest.class);
// Instance variables specific to this test.
+ /** The known resource id. */
private String knownResourceId = null;
- private List<String> allResourceIdsCreated = new ArrayList<String>();
+
+ /** The add tenant. */
boolean addTenant = true;
/*
* This method is called only by the parent class, AbstractServiceTestImpl
*/
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
+ */
@Override
protected String getServicePathComponent() {
return new PermissionClient().getServicePathComponent();
throw new UnsupportedOperationException();
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String)
+ */
@Test(dataProvider = "testName")
@Override
public void readPaginatedList(String testName) throws Exception {
// CRUD tests : CREATE tests
// ---------------------------------------------------------------
// Success outcomes
- @Override
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
+ */
+ @Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
public void create(String testName) throws Exception {
}
}
+ /**
+ * Creates the without resource name.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"create"})
public void createWithoutResourceName(String testName) throws Exception {
}
//to not cause uniqueness violation for permission, createList is removed
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"create"})
// Failure outcomes
// Placeholders until the three tests below can be uncommented.
// See Issue CSPACE-401.
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
+ */
@Override
public void createWithEmptyEntityBody(String testName) throws Exception {
//FIXME: Should this test really be empty? If so, please comment accordingly.
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
+ */
@Override
public void createWithMalformedXml(String testName) throws Exception {
//FIXME: Should this test really be empty? If so, please comment accordingly.
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
+ */
@Override
public void createWithWrongXmlSchema(String testName) throws Exception {
//FIXME: Should this test really be empty? If so, please comment accordingly.
// CRUD tests : READ tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"create"})
}
// Failure outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"read"})
// CRUD tests : READ_LIST tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"createList", "read"})
}
}
+ /**
+ * Search resource name.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"createList", "read"})
public void searchResourceName(String testName) throws Exception {
// CRUD tests : UPDATE tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"read", "readList", "readNonExistent"})
"Data in updated object did not match submitted data.");
}
+ /**
+ * Update actions.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"update"})
public void updateActions(String testName) throws Exception {
// Placeholders until the three tests below can be uncommented.
// See Issue CSPACE-401.
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
+ */
@Override
public void updateWithEmptyEntityBody(String testName) throws Exception {
//FIXME: Should this test really be empty? If so, please comment accordingly.
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
+ */
@Override
public void updateWithMalformedXml(String testName) throws Exception {
//FIXME: Should this test really be empty? If so, please comment accordingly.
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
+ */
@Override
public void updateWithWrongXmlSchema(String testName) throws Exception {
//FIXME: Should this test really be empty? If so, please comment accordingly.
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"readNonExistent", "testSubmitRequest"})
// CRUD tests : DELETE tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"updateActions"})
}
// Failure outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"delete"})
/**
* Tests the code for manually submitting data that is used by several
* of the methods above.
+ * @throws Exception
*/
@Test(dependsOnMethods = {"create", "read"})
public void testSubmitRequest() throws Exception {
* @param useResourceName
* @param useAction
* @param useEffect
- * @return
+ * @return permission
*/
public static Permission createPermissionInstance(String resourceName,
String description,
return permission;
}
- @AfterClass(alwaysRun = true)
- public void cleanUp() {
- setupDelete("delete");
- String noTest = System.getProperty("noTestCleanup");
- if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
- if (logger.isDebugEnabled()) {
- logger.debug("Skipping Cleanup phase ...");
- }
- return;
- }
- if (logger.isDebugEnabled()) {
- logger.debug("Cleaning up temporary resources created for testing ...");
- }
- PermissionClient client = new PermissionClient();
- for (String resourceId : allResourceIdsCreated) {
- ClientResponse<Response> res = client.delete(resourceId);
- int statusCode = res.getStatus();
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
- }
- }
-
+ /**
+ * Prints the list.
+ *
+ * @param testName the test name
+ * @param list the list
+ * @return the int
+ */
private int printList(String testName, PermissionsList list) {
int i = 0;
*/
package org.collectionspace.services.authorization.client.test;
-import java.util.ArrayList;
-import java.util.List;
+//import java.util.ArrayList;
+//import java.util.List;
import javax.ws.rs.core.Response;
import org.collectionspace.services.client.CollectionSpaceClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.testng.annotations.AfterClass;
/**
* RoleServiceTest, carries out tests against a
*/
public class RoleServiceTest extends AbstractServiceTestImpl {
+ /** The logger. */
private final Logger logger =
LoggerFactory.getLogger(RoleServiceTest.class);
// Instance variables specific to this test.
+ /** The known resource id. */
private String knownResourceId = null;
- private List<String> allResourceIdsCreated = new ArrayList<String>();
- boolean addTenant = true;
+// private List<String> allResourceIdsCreated = new ArrayList<String>();
+ /** The add tenant. */
+boolean addTenant = true;
/*
* This method is called only by the parent class, AbstractServiceTestImpl
*/
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
+ */
@Override
protected String getServicePathComponent() {
return new RoleClient().getServicePathComponent();
throw new UnsupportedOperationException();
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String)
+ */
@Test(dataProvider = "testName")
@Override
public void readPaginatedList(String testName) throws Exception {
// CRUD tests : CREATE tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
public void create(String testName) throws Exception {
}
}
+ /**
+ * Creates the for unique role.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"create"})
public void createForUniqueRole(String testName) throws Exception {
Assert.assertEquals(statusCode, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
+ /**
+ * Creates the without role name.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"create"})
public void createWithoutRoleName(String testName) throws Exception {
}
//to not cause uniqueness violation for role, createList is removed
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"create"})
// Failure outcomes
// Placeholders until the three tests below can be uncommented.
// See Issue CSPACE-401.
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
+ */
@Override
public void createWithEmptyEntityBody(String testName) throws Exception {
//FIXME: Should this test really be empty? If so, please comment accordingly.
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
+ */
@Override
public void createWithMalformedXml(String testName) throws Exception {
//FIXME: Should this test really be empty? If so, please comment accordingly.
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
+ */
@Override
public void createWithWrongXmlSchema(String testName) throws Exception {
//FIXME: Should this test really be empty? If so, please comment accordingly.
// CRUD tests : READ tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"create"})
}
// Failure outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"read"})
// CRUD tests : READ_LIST tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"createList", "read"})
}
}
+ /**
+ * Search role name.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"createList", "read"})
public void searchRoleName(String testName) throws Exception {
// CRUD tests : UPDATE tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"read", "readList", "readNonExistent"})
// Failure outcomes
// Placeholders until the three tests below can be uncommented.
// See Issue CSPACE-401.
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
+ */
@Override
public void updateWithEmptyEntityBody(String testName) throws Exception {
//FIXME: Should this test really be empty? If so, please comment accordingly.
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
+ */
@Override
public void updateWithMalformedXml(String testName) throws Exception {
//FIXME: Should this test really be empty? If so, please comment accordingly.
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
+ */
@Override
public void updateWithWrongXmlSchema(String testName) throws Exception {
//FIXME: Should this test really be empty? If so, please comment accordingly.
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"readNonExistent", "testSubmitRequest"})
// CRUD tests : DELETE tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"update"})
}
// Failure outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
+ */
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"delete"})
/**
* Tests the code for manually submitting data that is used by several
* of the methods above.
+ * @throws Exception
*/
@Test(dependsOnMethods = {"create", "read"})
public void testSubmitRequest() throws Exception {
* @param roleName
* @param description
* @param useRoleName
- * @return
+ * @return role
*/
public Role createRoleInstance(String roleName,
String description,
}
- @AfterClass(alwaysRun = true)
- public void cleanUp() {
- setupDelete("delete");
- String noTest = System.getProperty("noTestCleanup");
- if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
- if (logger.isDebugEnabled()) {
- logger.debug("Skipping Cleanup phase ...");
- }
- return;
- }
- if (logger.isDebugEnabled()) {
- logger.debug("Cleaning up temporary resources created for testing ...");
- }
- RoleClient client = new RoleClient();
- for (String resourceId : allResourceIdsCreated) {
- ClientResponse<Response> res = client.delete(resourceId);
- int statusCode = res.getStatus();
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
- }
- }
-
+ /**
+ * Prints the list.
+ *
+ * @param testName the test name
+ * @param list the list
+ * @return the int
+ */
private int printList(String testName, RolesList list) {
int i = 0;
import java.io.InputStream;\r
import java.net.URL;\r
import java.util.Properties;\r
+\r
+import javax.ws.rs.core.Response;\r
+\r
+//import javax.ws.rs.core.Response;\r
+\r
import org.apache.commons.httpclient.HttpClient;\r
import org.apache.commons.httpclient.UsernamePasswordCredentials;\r
-import org.apache.commons.httpclient.auth.AuthScope;\r
-//import org.collectionspace.services.collectionobject.CollectionobjectsCommonList;\r
+import org.apache.commons.httpclient.auth.AuthScope; //import org.collectionspace.services.collectionobject.CollectionobjectsCommonList;\r
import org.collectionspace.services.jaxb.AbstractCommonList;\r
-import org.jboss.resteasy.client.ClientResponse;\r
-//import org.collectionspace.services.common.context.ServiceContext;\r
+import org.jboss.resteasy.client.ClientResponse; //import org.collectionspace.services.common.context.ServiceContext;\r
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
\r
/**\r
- * BaseServiceClient is an abstract base client of all service clients\r
- * FIXME: http://issues.collectionspace.org/browse/CSPACE-1684\r
+ * BaseServiceClient is an abstract base client of all service clients FIXME:\r
+ * http://issues.collectionspace.org/browse/CSPACE-1684\r
+ * @param <CommonListType> \r
+ * @param <ListType> \r
*/\r
-public abstract class AbstractServiceClientImpl implements CollectionSpaceClient {\r
-\r
- /** The logger. */\r
- protected final Logger logger = LoggerFactory.getLogger(AbstractServiceClientImpl.class);\r
- \r
- /**\r
- * The character used to separate the words in a part label\r
- */\r
- public static final String PART_LABEL_SEPERATOR = "_";\r
- \r
- /** The Constant PART_COMMON_LABEL. */\r
- public static final String PART_COMMON_LABEL = "common";\r
- \r
- /** The properties. */\r
- private Properties properties = new Properties();\r
- \r
- /** The url. */\r
- private URL url;\r
- \r
- /** The http client. */\r
- private HttpClient httpClient;\r
+public abstract class AbstractServiceClientImpl implements\r
+ CollectionSpaceClient {\r
+\r
+ /** The logger. */\r
+ protected final Logger logger = LoggerFactory\r
+ .getLogger(AbstractServiceClientImpl.class);\r
+\r
+ /**\r
+ * The character used to separate the words in a part label\r
+ */\r
+ public static final String PART_LABEL_SEPERATOR = "_";\r
+\r
+ /** The Constant PART_COMMON_LABEL. */\r
+ public static final String PART_COMMON_LABEL = "common";\r
+\r
+ /** The properties. */\r
+ private Properties properties = new Properties();\r
+\r
+ /** The url. */\r
+ private URL url;\r
+\r
+ /** The http client. */\r
+ private HttpClient httpClient;\r
\r
/**\r
* Gets the common part name.\r
- *\r
+ * \r
* @return the common part name\r
*/\r
public String getCommonPartName() {\r
\r
/**\r
* Gets the common part name.\r
- *\r
- * @param servicePathComponent the service path component\r
+ * \r
+ * @param servicePathComponent\r
+ * the service path component\r
* @return the common part name\r
*/\r
public String getCommonPartName(String servicePathComponent) {\r
- return servicePathComponent\r
- + PART_LABEL_SEPERATOR\r
- + PART_COMMON_LABEL;\r
+ return servicePathComponent + PART_LABEL_SEPERATOR + PART_COMMON_LABEL;\r
}\r
\r
/**\r
* Gets the service path component.\r
- *\r
+ * \r
* @return the service path component\r
*/\r
abstract public String getServicePathComponent();\r
- \r
- /**\r
- * Instantiates a new abstract service client impl.\r
- */\r
- protected AbstractServiceClientImpl() {\r
- readProperties();\r
- setupHttpClient();\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see org.collectionspace.services.client.CollectionSpaceClient#getProperty(java.lang.String)\r
- */\r
- @Override\r
- public String getProperty(String propName) {\r
- return properties.getProperty(propName);\r
- }\r
\r
- /* (non-Javadoc)\r
- * @see org.collectionspace.services.client.CollectionSpaceClient#setProperty(java.lang.String, java.lang.String)\r
- */\r
- @Override\r
- public void setProperty(String propName, String value) {\r
- properties.setProperty(propName, value);\r
- }\r
+ /**\r
+ * Instantiates a new abstract service client impl.\r
+ */\r
+ protected AbstractServiceClientImpl() {\r
+ readProperties();\r
+ setupHttpClient();\r
+ }\r
\r
- /* (non-Javadoc)\r
- * @see org.collectionspace.services.client.CollectionSpaceClient#removeProperty(java.lang.String)\r
- */\r
- @Override\r
- public Object removeProperty(String propName) {\r
- return properties.remove(propName);\r
- }\r
-\r
- /**\r
- * Prints the properties.\r
- */\r
- public void printProperties() {\r
- for(Object kobj : properties.keySet()){\r
- String key = (String) kobj;\r
- logger.trace("begin property name=" + key + " value=" + properties.get(key));\r
- }\r
- }\r
- \r
- /* (non-Javadoc)\r
- * @see org.collectionspace.services.client.CollectionSpaceClient#getBaseURL()\r
- */\r
- @Override\r
- public String getBaseURL() {\r
- return properties.getProperty(URL_PROPERTY);\r
- }\r
+ /*\r
+ * (non-Javadoc)\r
+ * \r
+ * @see\r
+ * org.collectionspace.services.client.CollectionSpaceClient#getProperty\r
+ * (java.lang.String)\r
+ */\r
+ @Override\r
+ public String getProperty(String propName) {\r
+ return properties.getProperty(propName);\r
+ }\r
\r
- /* (non-Javadoc)\r
- * @see org.collectionspace.services.client.CollectionSpaceClient#getHttpClient()\r
- */\r
- @Override\r
- public HttpClient getHttpClient() {\r
- return httpClient;\r
- }\r
+ /*\r
+ * (non-Javadoc)\r
+ * \r
+ * @see\r
+ * org.collectionspace.services.client.CollectionSpaceClient#setProperty\r
+ * (java.lang.String, java.lang.String)\r
+ */\r
+ @Override\r
+ public void setProperty(String propName, String value) {\r
+ properties.setProperty(propName, value);\r
+ }\r
\r
- /* (non-Javadoc)\r
- * @see org.collectionspace.services.client.CollectionSpaceClient#useAuth()\r
- */\r
- @Override\r
- public boolean useAuth() {\r
- String auth = properties.getProperty(AUTH_PROPERTY);\r
- return Boolean.valueOf(auth);\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see org.collectionspace.services.client.CollectionSpaceClient#useSSL()\r
- */\r
- @Override\r
- public boolean useSSL() {\r
- String ssl = properties.getProperty(SSL_PROPERTY);\r
- return Boolean.valueOf(ssl);\r
- }\r
-\r
- /**\r
- * readProperties reads properties from system class path as well\r
- * as it overrides properties made available using command line\r
- * @exception RuntimeException\r
- */\r
- private void readProperties() {\r
-\r
- ClassLoader cl = Thread.currentThread().getContextClassLoader();\r
- InputStream is = null;\r
- try{\r
- is = cl.getResourceAsStream("collectionspace-client.properties");\r
- properties.load(is);\r
- if(logger.isDebugEnabled()){\r
- printProperties();\r
- }\r
- String spec = System.getProperty(URL_PROPERTY);\r
- if(spec != null && !"".equals(spec)){\r
- properties.setProperty(URL_PROPERTY, spec);\r
- }\r
-\r
- spec = properties.getProperty(URL_PROPERTY);\r
- url = new URL(spec);\r
- if(logger.isInfoEnabled()){\r
- logger.info("readProperties() using url=" + url);\r
- }\r
-\r
- String auth = System.getProperty(AUTH_PROPERTY);\r
- if(auth != null && !"".equals(auth)){\r
- properties.setProperty(AUTH_PROPERTY, auth);\r
- }\r
- String ssl = System.getProperty(SSL_PROPERTY);\r
- if(ssl != null && !"".equals(ssl)){\r
- properties.setProperty(AUTH_PROPERTY, ssl);\r
- }\r
- String user = System.getProperty(USER_PROPERTY);\r
- if(user != null && !"".equals(user)){\r
- properties.setProperty(USER_PROPERTY, user);\r
- }\r
- String password = System.getProperty(PASSWORD_PROPERTY);\r
- if(password != null && !"".equals(password)){\r
- properties.setProperty(PASSWORD_PROPERTY, password);\r
- }\r
- if(logger.isDebugEnabled()){\r
- printProperties();\r
- }\r
- }catch(Exception e){\r
- logger.debug("Caught exception while reading properties", e);\r
- throw new RuntimeException(e);\r
- }finally{\r
- if(is != null){\r
- try{\r
- is.close();\r
- }catch(Exception e){\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * setupHttpClient sets up HTTP client for the service client\r
- * the setup process relies on the following properties\r
- * URL_PROPERTY\r
- * USER_PROPERTY\r
- * PASSWORD_PROPERTY\r
- * AUTH_PROPERTY\r
- * SSL_PROPERTY\r
- */\r
- @Override\r
- public void setupHttpClient() {\r
- this.httpClient = new HttpClient();\r
- if(useAuth()){\r
- String user = properties.getProperty(USER_PROPERTY);\r
- String password = properties.getProperty(PASSWORD_PROPERTY);\r
- if(logger.isInfoEnabled()){\r
- logger.info("setupHttpClient() using url=" + url +\r
- " user=" + user + " password=" + password);\r
- }\r
-\r
- httpClient.getState().setCredentials(\r
- new AuthScope(url.getHost(), url.getPort(), AuthScope.ANY_REALM),\r
- new UsernamePasswordCredentials(user, password));\r
- //JAXRS client library requires HTTP preemptive authentication\r
- httpClient.getParams().setAuthenticationPreemptive(true);\r
- if(logger.isInfoEnabled()){\r
- logger.info("setupHttpClient: set preemptive authentication");\r
- }\r
- } else {\r
- if(logger.isInfoEnabled()){\r
- logger.info("setupHttpClient() : no auth mode!");\r
- }\r
- }\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see org.collectionspace.services.client.CollectionSpaceClient#isServerSecure()\r
- */\r
- @Override\r
- public boolean isServerSecure() {\r
- return Boolean.getBoolean("cspace.server.secure");\r
- }\r
- \r
- /* (non-Javadoc)\r
- * @see org.collectionspace.services.client.CollectionSpaceClient#readList(java.lang.String, java.lang.String)\r
- */\r
+ /*\r
+ * (non-Javadoc)\r
+ * \r
+ * @see\r
+ * org.collectionspace.services.client.CollectionSpaceClient#removeProperty\r
+ * (java.lang.String)\r
+ */\r
+ @Override\r
+ public Object removeProperty(String propName) {\r
+ return properties.remove(propName);\r
+ }\r
+\r
+ /**\r
+ * Prints the properties.\r
+ */\r
+ public void printProperties() {\r
+ for (Object kobj : properties.keySet()) {\r
+ String key = (String) kobj;\r
+ logger.trace("begin property name=" + key + " value="\r
+ + properties.get(key));\r
+ }\r
+ }\r
+\r
+ /*\r
+ * (non-Javadoc)\r
+ * \r
+ * @see\r
+ * org.collectionspace.services.client.CollectionSpaceClient#getBaseURL()\r
+ */\r
+ @Override\r
+ public String getBaseURL() {\r
+ return properties.getProperty(URL_PROPERTY);\r
+ }\r
+\r
+ /*\r
+ * (non-Javadoc)\r
+ * \r
+ * @see\r
+ * org.collectionspace.services.client.CollectionSpaceClient#getHttpClient()\r
+ */\r
+ @Override\r
+ public HttpClient getHttpClient() {\r
+ return httpClient;\r
+ }\r
+\r
+ /*\r
+ * (non-Javadoc)\r
+ * \r
+ * @see org.collectionspace.services.client.CollectionSpaceClient#useAuth()\r
+ */\r
+ @Override\r
+ public boolean useAuth() {\r
+ String auth = properties.getProperty(AUTH_PROPERTY);\r
+ return Boolean.valueOf(auth);\r
+ }\r
+\r
+ /*\r
+ * (non-Javadoc)\r
+ * \r
+ * @see org.collectionspace.services.client.CollectionSpaceClient#useSSL()\r
+ */\r
+ @Override\r
+ public boolean useSSL() {\r
+ String ssl = properties.getProperty(SSL_PROPERTY);\r
+ return Boolean.valueOf(ssl);\r
+ }\r
+\r
+ /**\r
+ * readProperties reads properties from system class path as well as it\r
+ * overrides properties made available using command line\r
+ * \r
+ * @exception RuntimeException\r
+ */\r
+ private void readProperties() {\r
+\r
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();\r
+ InputStream is = null;\r
+ try {\r
+ is = cl.getResourceAsStream("collectionspace-client.properties");\r
+ properties.load(is);\r
+ if (logger.isDebugEnabled()) {\r
+ printProperties();\r
+ }\r
+ String spec = System.getProperty(URL_PROPERTY);\r
+ if (spec != null && !"".equals(spec)) {\r
+ properties.setProperty(URL_PROPERTY, spec);\r
+ }\r
+\r
+ spec = properties.getProperty(URL_PROPERTY);\r
+ url = new URL(spec);\r
+ if (logger.isInfoEnabled()) {\r
+ logger.info("readProperties() using url=" + url);\r
+ }\r
+\r
+ String auth = System.getProperty(AUTH_PROPERTY);\r
+ if (auth != null && !"".equals(auth)) {\r
+ properties.setProperty(AUTH_PROPERTY, auth);\r
+ }\r
+ String ssl = System.getProperty(SSL_PROPERTY);\r
+ if (ssl != null && !"".equals(ssl)) {\r
+ properties.setProperty(AUTH_PROPERTY, ssl);\r
+ }\r
+ String user = System.getProperty(USER_PROPERTY);\r
+ if (user != null && !"".equals(user)) {\r
+ properties.setProperty(USER_PROPERTY, user);\r
+ }\r
+ String password = System.getProperty(PASSWORD_PROPERTY);\r
+ if (password != null && !"".equals(password)) {\r
+ properties.setProperty(PASSWORD_PROPERTY, password);\r
+ }\r
+ if (logger.isDebugEnabled()) {\r
+ printProperties();\r
+ }\r
+ } catch (Exception e) {\r
+ logger.debug("Caught exception while reading properties", e);\r
+ throw new RuntimeException(e);\r
+ } finally {\r
+ if (is != null) {\r
+ try {\r
+ is.close();\r
+ } catch (Exception e) {\r
+ if (logger.isDebugEnabled() == true) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ /**\r
+ * setupHttpClient sets up HTTP client for the service client the setup\r
+ * process relies on the following properties URL_PROPERTY USER_PROPERTY\r
+ * PASSWORD_PROPERTY AUTH_PROPERTY SSL_PROPERTY\r
+ */\r
+ @Override\r
+ public void setupHttpClient() {\r
+ this.httpClient = new HttpClient();\r
+ if (useAuth()) {\r
+ String user = properties.getProperty(USER_PROPERTY);\r
+ String password = properties.getProperty(PASSWORD_PROPERTY);\r
+ if (logger.isInfoEnabled()) {\r
+ logger.info("setupHttpClient() using url=" + url + " user="\r
+ + user + " password=" + password);\r
+ }\r
+\r
+ httpClient.getState().setCredentials(\r
+ new AuthScope(url.getHost(), url.getPort(),\r
+ AuthScope.ANY_REALM),\r
+ new UsernamePasswordCredentials(user, password));\r
+ // JAXRS client library requires HTTP preemptive authentication\r
+ httpClient.getParams().setAuthenticationPreemptive(true);\r
+ if (logger.isInfoEnabled()) {\r
+ logger.info("setupHttpClient: set preemptive authentication");\r
+ }\r
+ } else {\r
+ if (logger.isInfoEnabled()) {\r
+ logger.info("setupHttpClient() : no auth mode!");\r
+ }\r
+ }\r
+ }\r
+\r
+ /*\r
+ * (non-Javadoc)\r
+ * \r
+ * @see\r
+ * org.collectionspace.services.client.CollectionSpaceClient#isServerSecure\r
+ * ()\r
+ */\r
+ @Override\r
+ public boolean isServerSecure() {\r
+ return Boolean.getBoolean("cspace.server.secure");\r
+ }\r
+\r
+ /*\r
+ * (non-Javadoc)\r
+ * \r
+ * @see\r
+ * org.collectionspace.services.client.CollectionSpaceClient#readList(java\r
+ * .lang.String, java.lang.String)\r
+ */\r
+ @Override\r
+ public ClientResponse<AbstractCommonList> readList(String pageSize,\r
+ String pageNumber) {\r
+ return getProxy().readList(pageSize, pageNumber);\r
+ }\r
+ \r
+ /* (non-Javadoc)\r
+ * @see org.collectionspace.services.client.CollectionSpaceClient#delete(java.lang.String)\r
+ */\r
@Override\r
- public ClientResponse<AbstractCommonList> readList(String pageSize,\r
- String pageNumber) {\r
- return getProxy().readList(pageSize, pageNumber);\r
- }\r
- \r
+ public ClientResponse<Response> delete(String csid) {\r
+ // must override in children if you want behavior\r
+ throw new UnsupportedOperationException();\r
+ } \r
}\r
* limitations under the License.
*/
package org.collectionspace.services.client;
+import javax.ws.rs.core.Response;
+
import org.apache.commons.httpclient.HttpClient;
import org.collectionspace.services.jaxb.AbstractCommonList;
import org.jboss.resteasy.client.ClientResponse;
/**
* checks System property cspace.server.secure
- * @return
+ * @return boolean
*/
boolean isServerSecure();
* @return the client response
*/
public ClientResponse<AbstractCommonList> readList(String pageSize,
- String pageNumber);
+ String pageNumber);
+
+ /**
+ * Delete.
+ *
+ * @param csid the csid
+ * @return the client response
+ */
+ public ClientResponse<Response> delete(String csid);
}
package org.collectionspace.services.client;
+import javax.ws.rs.core.Response;
+
+import org.jboss.resteasy.client.ClientResponse;
+
/**
* A CollectionObjectClient.
@Override
public CollectionSpaceProxy getProxy() {
throw new UnsupportedOperationException();
- }
+ }
+
+ public ClientResponse<Response> delete(String csid) {
+ throw new UnsupportedOperationException();
+ }
}
//import java.util.List;
+import java.util.ArrayList;
+import java.util.List;
+
import javax.ws.rs.core.Response;
import org.collectionspace.services.jaxb.AbstractCommonList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
+import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
/**
/** The Constant DEFAULT_LIST_SIZE. */
static protected final int DEFAULT_LIST_SIZE = 10;
static protected final int DEFAULT_PAGINATEDLIST_SIZE = 10;
+
+ /* Use this to keep track of resources to delete */
+ protected List<String> allResourceIdsCreated = new ArrayList<String>();
// // Success outcomes
// /* (non-Javadoc)
CollectionSpaceClient client,
long pageSize, long pageNumber) throws Exception {
ClientResponse<AbstractCommonList> response =
- (ClientResponse<AbstractCommonList>)client.readList(Long.toString(pageSize),
- Long.toString(pageNumber));
- int statusCode = response.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if (getLogger().isDebugEnabled()) {
- getLogger().debug(testName + ": status = " + statusCode);
+ client.readList(Long.toString(pageSize), Long.toString(pageNumber));
+ AbstractCommonList result = null;
+ try {
+ int statusCode = response.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
+
+ result = this.getAbstractCommonList(response);
+ } finally {
+ response.releaseConnection();
}
- Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
-
- AbstractCommonList list = this.getAbstractCommonList(response);
- return list;
+
+ return result;
}
/**
// Get the current total number of items.
// If there are no items then create some
- AbstractCommonList list = this.readList(testName, client, 1 /*pgSz*/, 0 /*pgNum*/);
+ AbstractCommonList list = (AbstractCommonList) this.readList(testName, client, 1 /*pgSz*/, 0 /*pgNum*/);
if (list == null || list.getTotalItems() == 0) {
this.createPaginatedList(testName, DEFAULT_PAGINATEDLIST_SIZE);
- list = this.readList(testName, client, 1 /*pgSz*/, 0 /*pgNum*/);
+ list = (AbstractCommonList) this.readList(testName, client, 1 /*pgSz*/, 0 /*pgNum*/);
}
// Print out the current list size to be paginated
long pageSize = totalItems / 3; //create up to 3 pages to iterate over
long pagesTotal = pageSize > 0 ? (totalItems / pageSize) : 0;
for (int i = 0; i < pagesTotal; i++) {
- list = this.readList(testName, client, pageSize, i);
+ list = (AbstractCommonList) this.readList(testName, client, pageSize, i);
assertPaginationInfo(testName,
list,
i, //expected page number
// if there are any remainders be sure to paginate them as well
long mod = totalItems % pageSize;
if (mod != 0) {
- list = this.readList(testName, client, pageSize, pagesTotal);
+ list = (AbstractCommonList) this.readList(testName, client, pageSize, pagesTotal);
assertPaginationInfo(testName,
list,
pagesTotal, //expected page number
// Expected status code: 400 Bad Request
testSetup(Response.Status.BAD_REQUEST.getStatusCode(), ServiceRequestType.UPDATE, label);
}
+
+ /**
+ * Deletes all resources created by tests, after all tests have been run.
+ *
+ * This cleanup method will always be run, even if one or more tests fail.
+ * For this reason, it attempts to remove all resources created
+ * at any point during testing, even if some of those resources
+ * may be expected to be deleted by certain tests.
+ */
+ @AfterClass(alwaysRun=true)
+ public void cleanUp() {
+ String noTest = System.getProperty("noTestCleanup");
+ if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Skipping Cleanup phase ...");
+ }
+ return;
+ }
+ if (logger.isDebugEnabled()) {
+ logger.debug("Cleaning up temporary resources created for testing ...");
+ }
+ CollectionSpaceClient client = this.getClientInstance();
+ for (String resourceId : allResourceIdsCreated) {
+ // Note: Any non-success responses are ignored and not reported.
+ client.delete(resourceId).releaseConnection();
+ }
+ }
/* (non-Javadoc)
* @see org.collectionspace.services.client.test.ServiceTest#updateNonExistent(java.lang.String)
import java.io.InputStream;\r
import java.io.StringWriter;\r
import java.lang.reflect.Method;\r
-import java.util.ArrayList;\r
+//import java.util.ArrayList;\r
import java.util.List;\r
\r
import javax.ws.rs.core.MultivaluedMap;\r
import javax.xml.bind.Unmarshaller;\r
import javax.xml.parsers.DocumentBuilderFactory;\r
\r
+import org.apache.commons.httpclient.HttpMethodBase;\r
+import org.apache.commons.httpclient.methods.EntityEnclosingMethod;\r
import org.apache.commons.httpclient.methods.DeleteMethod;\r
import org.apache.commons.httpclient.methods.GetMethod;\r
import org.apache.commons.httpclient.methods.PostMethod;\r
/**\r
* FIXME: http://issues.collectionspace.org/browse/CSPACE-1685\r
* The Class BaseServiceTest.\r
+ * @param <CommonListType> \r
*/\r
public abstract class BaseServiceTest {\r
\r
*/\r
protected int submitRequest(String method, String url) {\r
int statusCode = 0;\r
+ HttpMethodBase httpMethod = null;\r
try {\r
TestServiceClient client = new TestServiceClient();\r
if (method.equals(javax.ws.rs.HttpMethod.DELETE)) {\r
- DeleteMethod deleteMethod = new DeleteMethod(url);\r
- statusCode = client.getHttpClient().executeMethod(deleteMethod);\r
+ httpMethod = new DeleteMethod(url);\r
} else if (method.equals(javax.ws.rs.HttpMethod.GET)) {\r
- GetMethod getMethod = new GetMethod(url);\r
- statusCode = client.getHttpClient().executeMethod(getMethod);\r
- } else {\r
- // Do nothing - leave status code at default value.\r
+ httpMethod = new GetMethod(url);\r
+ }\r
+ if (httpMethod != null) {\r
+ statusCode = client.getHttpClient().executeMethod(httpMethod);\r
}\r
} catch (Exception e) {\r
logger.error(\r
"Exception during HTTP " + method + " request to "\r
+ url + ":", e);\r
+ } finally {\r
+ httpMethod.releaseConnection();\r
}\r
return statusCode;\r
}\r
protected int submitRequest(String method, String url, String mediaType,\r
String entityStr) {\r
int statusCode = 0;\r
+ EntityEnclosingMethod httpMethod = null;\r
try {\r
TestServiceClient client = new TestServiceClient();\r
if (method.equals(javax.ws.rs.HttpMethod.POST)) {\r
- StringRequestEntity entityBody =\r
- new StringRequestEntity(mediaType, entityStr, NULL_CHARSET);\r
- PostMethod postMethod = new PostMethod(url);\r
- postMethod.setRequestEntity(entityBody);\r
- statusCode = client.getHttpClient().executeMethod(postMethod);\r
+ httpMethod = new PostMethod(url);\r
} else if (method.equals(javax.ws.rs.HttpMethod.PUT)) {\r
+ httpMethod = new PutMethod(url);\r
+ }\r
+ if (httpMethod != null) {\r
StringRequestEntity entityBody =\r
- new StringRequestEntity(mediaType, entityStr, NULL_CHARSET);\r
- PutMethod putMethod = new PutMethod(url);\r
- putMethod.setRequestEntity(entityBody);\r
- statusCode = client.getHttpClient().executeMethod(putMethod);\r
- } else {\r
- // Do nothing - leave status code at default value.\r
+ new StringRequestEntity(mediaType, entityStr, NULL_CHARSET);\r
+ httpMethod.setRequestEntity(entityBody);\r
+ statusCode = client.getHttpClient().executeMethod(httpMethod);\r
}\r
} catch (Exception e) {\r
logger.error(\r
"Exception during HTTP " + method + " request to "\r
+ url + ":", e);\r
+ } finally {\r
+ httpMethod.releaseConnection();\r
}\r
return statusCode;\r
}\r
* @return the string\r
*/\r
static protected String extractId(ClientResponse<Response> res) {\r
- MultivaluedMap mvm = res.getMetadata();\r
- String uri = (String) ((ArrayList) mvm.get("Location")).get(0);\r
+ MultivaluedMap<String, Object> mvm = res.getMetadata();\r
+ String uri = (String) ((List<Object>) mvm.get("Location")).get(0);\r
if (logger.isDebugEnabled()) {\r
logger.debug("extractId:uri=" + uri);\r
}\r
* @return the object\r
* @throws Exception the exception\r
*/\r
- static protected Object extractPart(MultipartInput input, String label, Class clazz)\r
+ static protected Object extractPart(MultipartInput input, String label, Class<?> clazz)\r
throws Exception {\r
Object obj = null;\r
String partLabel = "";\r
* @return the part object\r
* @throws JAXBException the jAXB exception\r
*/\r
- static protected Object getPartObject(String partStr, Class clazz)\r
+ static protected Object getPartObject(String partStr, Class<?> clazz)\r
throws JAXBException {\r
JAXBContext jc = JAXBContext.newInstance(clazz);\r
ByteArrayInputStream bais = null;\r
try {\r
bais.close();\r
} catch (Exception e) {\r
+ if (logger.isDebugEnabled() == true) {\r
+ e.printStackTrace();\r
+ }\r
}\r
}\r
}\r
* @param clazz the clazz\r
* @return the string\r
*/\r
- static protected String objectAsXmlString(Object o, Class clazz) {\r
+ static protected String objectAsXmlString(Object o, Class<?> clazz) {\r
StringWriter sw = new StringWriter();\r
try {\r
JAXBContext jc = JAXBContext.newInstance(clazz);\r
* @return\r
* @throws Exception\r
*/\r
- static protected Object getObjectFromFile(Class jaxbClass, String fileName)\r
+ static protected Object getObjectFromFile(Class<?> jaxbClass, String fileName)\r
throws Exception {\r
\r
JAXBContext context = JAXBContext.newInstance(jaxbClass);\r
* @return\r
* @throws Exception\r
*/\r
- static protected Object getObjectFromStream(Class jaxbClass, InputStream is) throws Exception {\r
+ static protected Object getObjectFromStream(Class<?> jaxbClass, InputStream is) throws Exception {\r
JAXBContext context = JAXBContext.newInstance(jaxbClass);\r
Unmarshaller unmarshaller = context.createUnmarshaller();\r
//note: setting schema to null will turn validator off\r
* @param map the map\r
* @return the string\r
*/\r
- protected String mapAsString(MultivaluedMap map) {\r
+ protected String mapAsString(MultivaluedMap<String, Object> map) {\r
StringBuffer sb = new StringBuffer();\r
for (Object entry : map.entrySet()) {\r
- MultivaluedMap.Entry mentry = (MultivaluedMap.Entry) entry;\r
+ MultivaluedMap.Entry<String, Object> mentry = (MultivaluedMap.Entry<String, Object>) entry;\r
sb.append(" name=" + mentry.getKey());\r
sb.append(" value=" + mentry.getValue() + "\n");\r
}\r
* Tests creation of a new resource.
*
* Relied upon by 'read', 'update' and 'delete' tests, below.
+ * @param testName
+ * @throws Exception
*/
public void create(String testName) throws Exception;
* calling create(), and relies on the latter's test assertion(s).
*
* Relied upon by 'read list' tests, below.
+ * @param testName
+ * @throws Exception
*/
public void createList(String testName) throws Exception;
/**
* Tests creation of a resource by submitting
* an empty entity body (aka empty payload).
+ * @param testName
+ * @throws Exception
*/
public void createWithEmptyEntityBody(String testName) throws Exception;
/**
* Tests creation of a resource by submitting
* a representation with malformed XML data.
+ * @param testName
+ * @throws Exception
*/
public void createWithMalformedXml(String testName) throws Exception;
* Tests creation of a resource by submitting
* a representation in the wrong XML schema
* (e.g. not matching the object's schema).
+ * @param testName
+ * @throws Exception
*/
public void createWithWrongXmlSchema(String testName) throws Exception;
/**
* Tests reading (i.e. retrieval) of a resource.
+ * @param testName
+ * @throws Exception
*/
public void read(String testName) throws Exception;
* Tests reading (i.e. retrieval) of a non-existent
* resource, whose resource identifier does not exist
* at the specified URL.
+ * @param testName
+ * @throws Exception
*/
public void readNonExistent(String testName) throws Exception;
/**
* Tests reading (i.e. retrieval) of a list of
* multiple resources.
+ * @param testName
+ * @throws Exception
*/
public void readList(String testName) throws Exception;
/**
* Tests updating the content of a resource.
+ * @param testName
+ * @throws Exception
*/
public void update(String testName) throws Exception;
/**
* Tests updating the content of a resource
* by submitting an empty entity body (aka empty payload).
+ * @param testName
+ * @throws Exception
*/
public void updateWithEmptyEntityBody(String testName) throws Exception;
* Tests updating the content of a resource
* by submitting a representation with malformed
* XML data.
+ * @param testName
+ * @throws Exception
*/
public void updateWithMalformedXml(String testName) throws Exception;
* Tests updating the content of a resource
* by submitting a representation in the wrong
* XML schema (e.g. not matching the object's schema).
+ * @param testName
+ * @throws Exception
*/
public void updateWithWrongXmlSchema(String testName) throws Exception;
/**
* Tests updating the content of a non-existent
* resource, whose resource identifier does not exist.
+ * @param testName
+ * @throws Exception
*/
public void updateNonExistent(String testName) throws Exception;
/**
* Tests deleting a resource.
+ * @param testName
+ * @throws Exception
*/
public void delete(String testName) throws Exception;
/**
* Tests deleting a non-existent resource, whose resource
* identifier does not exist at the specified URL.
+ * @param testName
+ * @throws Exception
*/
public void deleteNonExistent(String testName) throws Exception;
*/
package org.collectionspace.services.client;
-import javax.ws.rs.GET;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
-import org.collectionspace.services.jaxb.AbstractCommonList;
import org.collectionspace.services.collectionobject.CollectionobjectsCommonList;
import org.collectionspace.services.common.authorityref.AuthorityRefList;
//import org.collectionspace.services.common.context.ServiceContext;
}
- @Override
- public ClientResponse<AbstractCommonList> readList(String pageSize,
- String pageNumber) {
- return collectionObjectProxy.readList(pageSize, pageNumber);
-
- }
+// @Override
+// public ClientResponse<CollectionobjectsCommonList> readList(String pageSize,
+// String pageNumber) {
+// return collectionObjectProxy.readList(pageSize, pageNumber);
+// }
/**
* Roundtrip.
/**
* @param csid
- * @return
+ * @return response
* @see org.collectionspace.services.client.CollectionObjectProxy#getAuthorityRefs(java.lang.String)
*/
public ClientResponse<AuthorityRefList> getAuthorityRefs(String csid) {
* @see org.collectionspace.services.client.CollectionObjectProxy#delete()
* @return the client response< response>
*/
+ @Override
public ClientResponse<Response> delete(String csid) {
return collectionObjectProxy.delete(csid);
}
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
+//import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
+//import javax.ws.rs.core.UriInfo;
-import org.collectionspace.services.client.IClientQueryParams;
+//import org.collectionspace.services.client.IClientQueryParams;
import org.collectionspace.services.client.CollectionSpaceProxy;
import org.collectionspace.services.common.query.IQueryManager;
import org.collectionspace.services.common.authorityref.AuthorityRefList;
-import org.collectionspace.services.jaxb.AbstractCommonList;
+//import org.collectionspace.services.jaxb.AbstractCommonList;
import org.collectionspace.services.collectionobject.CollectionobjectsCommonList;
import org.jboss.resteasy.client.ClientResponse;
@GET
@Produces({"application/xml"})
ClientResponse<CollectionobjectsCommonList> readList();
+
+// /**
+// * Read list.
+// *
+// * @param pageSize the page size
+// * @param pageNumber the page number
+// * @return the client response
+// */
+// @GET
+// @Produces({"application/xml"})
+// @Override
+// ClientResponse<CollectionobjectsCommonList> readList(
+// @QueryParam(IClientQueryParams.PAGE_SIZE_PARAM) String pageSize,
+// @QueryParam(IClientQueryParams.START_PAGE_PARAM) String pageNumber);
+
/**
* Roundtrip.
*/
public class CollectionObjectAuthRefsTest extends BaseServiceTest {
+ /** The logger. */
private final Logger logger =
LoggerFactory.getLogger(CollectionObjectAuthRefsTest.class);
// Instance variables specific to this test.
+ /** The SERVIC e_ pat h_ component. */
final String SERVICE_PATH_COMPONENT = "collectionobjects";
+
+ /** The PERSO n_ authorit y_ name. */
final String PERSON_AUTHORITY_NAME = "TestPersonAuth";
+
+ /** The known resource id. */
private String knownResourceId = null;
- private List<String> collectionObjectIdsCreated = new ArrayList();
- private List<String> personIdsCreated = new ArrayList();
+
+ /** The collection object ids created. */
+ private List<String> collectionObjectIdsCreated = new ArrayList<String>();
+
+ /** The person ids created. */
+ private List<String> personIdsCreated = new ArrayList<String>();
+
+ /** The CREATE d_ status. */
private int CREATED_STATUS = Response.Status.CREATED.getStatusCode();
+
+ /** The O k_ status. */
private int OK_STATUS = Response.Status.OK.getStatusCode();
+
+ /** The person auth csid. */
private String personAuthCSID = null;
+
+ /** The content organization ref name. */
private String contentOrganizationRefName = null;
+
+ /** The content people ref name. */
private String contentPeopleRefName = null;
+
+ /** The content person ref name. */
private String contentPersonRefName = null;
+
+ /** The inscriber ref name. */
private String inscriberRefName = null;
+
+ /** The NU m_ aut h_ ref s_ expected. */
private final int NUM_AUTH_REFS_EXPECTED = 4;
/* (non-Javadoc)
// CRUD tests : CREATE tests
// ---------------------------------------------------------------
// Success outcomes
+ /**
+ * Creates the with auth refs.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
public void createWithAuthRefs(String testName) throws Exception {
collectionObjectIdsCreated.add(extractId(res));
}
+ /**
+ * Creates the person refs.
+ */
protected void createPersonRefs(){
String authRefName =
PersonAuthorityClientUtils.createPersonAuthRefName(PERSON_AUTHORITY_NAME, false);
personIdsCreated.add(createPerson("Ingrid", "Inscriber", inscriberRefName));
}
+ /**
+ * Creates the person.
+ *
+ * @param firstName the first name
+ * @param surName the sur name
+ * @param refName the ref name
+ * @return the string
+ */
protected String createPerson(String firstName, String surName, String refName ) {
Map<String, String> personInfo = new HashMap<String,String>();
personInfo.put(PersonJAXBSchema.FORE_NAME, firstName);
}
// Success outcomes
+ /**
+ * Read and check auth refs.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
dependsOnMethods = {"createWithAuthRefs"})
public void readAndCheckAuthRefs(String testName) throws Exception {
CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
for (String resourceId : collectionObjectIdsCreated) {
// Note: Any non-success responses are ignored and not reported.
- ClientResponse<Response> res = collectionObjectClient.delete(resourceId);
+ collectionObjectClient.delete(resourceId).releaseConnection();
}
// Note: Any non-success response is ignored and not reported.
PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
// Delete persons before PersonAuth
for (String resourceId : personIdsCreated) {
// Note: Any non-success responses are ignored and not reported.
- ClientResponse<Response> res = personAuthClient.deleteItem(personAuthCSID, resourceId);
+ personAuthClient.deleteItem(personAuthCSID, resourceId).releaseConnection();
}
- ClientResponse<Response> res = personAuthClient.delete(personAuthCSID);
+ personAuthClient.delete(personAuthCSID).releaseConnection();
}
// ---------------------------------------------------------------
// Utility methods used by tests above
// ---------------------------------------------------------------
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
+ */
@Override
public String getServicePathComponent() {
return SERVICE_PATH_COMPONENT;
}
+ /**
+ * Creates the collection object instance.
+ *
+ * @param title the title
+ * @param objNum the obj num
+ * @param contentOrganization the content organization
+ * @param contentPeople the content people
+ * @param contentPerson the content person
+ * @param inscriber the inscriber
+ * @return the multipart output
+ */
private MultipartOutput createCollectionObjectInstance(
String title,
String objNum,
*/
package org.collectionspace.services.client.test;
-import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
import org.testng.Assert;
-import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
import org.slf4j.Logger;
/** The known resource id. */
private String knownResourceId = null;
- /** The all resource ids created. */
- private List<String> allResourceIdsCreated = new ArrayList<String>();
-
/** The multivalue. */
private boolean multivalue; //toggle
- /**
- * Gets the logger.
- *
- * @return the logger
- */
- private Logger getLogger() {
- return this.logger;
- }
-
/* (non-Javadoc)
* @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
*/
}
- // ---------------------------------------------------------------
- // Cleanup of resources created during testing
- // ---------------------------------------------------------------
- /**
- * Deletes all resources created by tests, after all tests have been run.
- *
- * This cleanup method will always be run, even if one or more tests fail.
- * For this reason, it attempts to remove all resources created
- * at any point during testing, even if some of those resources
- * may be expected to be deleted by certain tests.
- */
- @AfterClass(alwaysRun = true)
- public void cleanUp() {
- String noTest = System.getProperty("noTestCleanup");
- if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
- if (logger.isDebugEnabled()) {
- logger.debug("Skipping Cleanup phase ...");
- }
- return;
- }
- if (logger.isDebugEnabled()) {
- logger.debug("Cleaning up temporary resources created for testing ...");
- }
- CollectionObjectClient client = new CollectionObjectClient();
- for (String resourceId : allResourceIdsCreated) {
- // Note: Any non-success responses are ignored and not reported.
- ClientResponse<Response> res = client.delete(resourceId);
- }
- }
-
// ---------------------------------------------------------------
// Utility methods used by tests above
// ---------------------------------------------------------------
// Set the page size\r
//\r
String pageSizeStr = null;\r
- List<String> list = queryParams.remove(IClientQueryParams.PAGE_SIZE_PARAM);\r
+ List<String> list = queryParams.remove(IClientQueryParams.PAGE_SIZE_PARAM); //REM: Should we really be removing this param?\r
if (list != null) {\r
pageSizeStr = list.get(0);\r
}\r
// Set the start page\r
//\r
String startPageStr = null;\r
- list = queryParams.remove(IClientQueryParams.START_PAGE_PARAM);\r
+ list = queryParams.remove(IClientQueryParams.START_PAGE_PARAM); //REM: Should we really be removing this param?\r
if (list != null) {\r
startPageStr = list.get(0);\r
}\r
// Instance variables specific to this test.
final String SERVICE_PATH_COMPONENT = "contacts";
private String knownResourceId = null;
- private List<String> allResourceIdsCreated = new ArrayList();
/* (non-Javadoc)
* @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
// See Issue CSPACE-401.
@Override
public void createWithEmptyEntityBody(String testName) throws Exception {
+ //Should this really be empty?
}
@Override
public void createWithMalformedXml(String testName) throws Exception {
+ //Should this really be empty??
}
@Override
public void createWithWrongXmlSchema(String testName) throws Exception {
+ //Should this really be empty??
}
/*
// Placeholders until the three tests below can be uncommented.
// See Issue CSPACE-401.
@Override
- public void updateWithEmptyEntityBody(String testName) throws Exception{
+ public void updateWithEmptyEntityBody(String testName) throws Exception {
+ //Should this really be empty??
}
+
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
+ */
@Override
public void updateWithMalformedXml(String testName) throws Exception {
+ //Should this really be empty??
}
+
@Override
public void updateWithWrongXmlSchema(String testName) throws Exception {
+ //Should this really be empty??
}
/*
}
- // ---------------------------------------------------------------
- // Cleanup of resources created during testing
- // ---------------------------------------------------------------
-
- /**
- * Deletes all resources created by tests, after all tests have been run.
- *
- * This cleanup method will always be run, even if one or more tests fail.
- * For this reason, it attempts to remove all resources created
- * at any point during testing, even if some of those resources
- * may be expected to be deleted by certain tests.
- */
- @AfterClass(alwaysRun=true)
- public void cleanUp() {
- if (logger.isDebugEnabled()) {
- logger.debug("Cleaning up temporary resources created for testing ...");
- }
- ContactClient client = new ContactClient();
- for (String resourceId : allResourceIdsCreated) {
- // Note: Any non-success responses are ignored and not reported.
- ClientResponse<Response> res = client.delete(resourceId);
- }
- }
-
// ---------------------------------------------------------------
// Utility methods used by tests above
// ---------------------------------------------------------------
public String getServicePathComponent() {
return SERVICE_PATH_COMPONENT;
}
-
}
setProxy();
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.CollectionSpaceClient#getProxy()
+ */
@Override
public CollectionSpaceProxy getProxy() {
return this.dimensionProxy;
/**
* @param csid
- * @return
+ * @return response
* @see org.collectionspace.services.client.DimensionProxy#deleteDimension(java.lang.Long)
*/
+ @Override
public ClientResponse<Response> delete(String csid) {
return dimensionProxy.delete(csid);
}
*/
package org.collectionspace.services.client.test;
-import java.util.ArrayList;
+//import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
import org.testng.Assert;
-import org.testng.annotations.AfterClass;
+//import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
import org.slf4j.Logger;
*/
public class DimensionServiceTest extends AbstractServiceTestImpl {
+ /** The logger. */
private final Logger logger =
LoggerFactory.getLogger(DimensionServiceTest.class);
// Instance variables specific to this test.
+ /** The SERVIC e_ pat h_ component. */
final String SERVICE_PATH_COMPONENT = "dimensions";
+
+ /** The known resource id. */
private String knownResourceId = null;
- private List<String> allResourceIdsCreated = new ArrayList<String>();
/* (non-Javadoc)
* @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
// CRUD tests : CREATE tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
+ */
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
public void create(String testName) throws Exception {
allResourceIdsCreated.add(extractId(res));
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
+ */
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
dependsOnMethods = {"create"})
// Failure outcomes
// Placeholders until the three tests below can be uncommented.
// See Issue CSPACE-401.
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
+ */
@Override
public void createWithEmptyEntityBody(String testName) throws Exception {
+ //Should this really be empty?
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
+ */
@Override
public void createWithMalformedXml(String testName) throws Exception {
+ //Should this really be empty?
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
+ */
@Override
public void createWithWrongXmlSchema(String testName) throws Exception {
+ //Should this really be empty?
}
/*
// CRUD tests : READ tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
+ */
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
dependsOnMethods = {"create"})
}
// Failure outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
+ */
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
dependsOnMethods = {"read"})
// CRUD tests : READ_LIST tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
+ */
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
dependsOnMethods = {"read"})
// CRUD tests : UPDATE tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
+ */
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
dependsOnMethods = {"read"})
// Failure outcomes
// Placeholders until the three tests below can be uncommented.
// See Issue CSPACE-401.
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
+ */
@Override
public void updateWithEmptyEntityBody(String testName) throws Exception{
+ //Should this really be empty?
}
+
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
+ */
@Override
public void updateWithMalformedXml(String testName) throws Exception {
+ //Should this really be empty?
}
+
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
+ */
@Override
public void updateWithWrongXmlSchema(String testName) throws Exception {
+ //Should this really be empty?
}
/*
}
*/
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
+ */
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
dependsOnMethods = {"update", "testSubmitRequest"})
// CRUD tests : DELETE tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
+ */
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
}
// Failure outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
+ */
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
dependsOnMethods = {"delete"})
}
- // ---------------------------------------------------------------
- // Cleanup of resources created during testing
- // ---------------------------------------------------------------
-
- /**
- * Deletes all resources created by tests, after all tests have been run.
- *
- * This cleanup method will always be run, even if one or more tests fail.
- * For this reason, it attempts to remove all resources created
- * at any point during testing, even if some of those resources
- * may be expected to be deleted by certain tests.
- */
- @AfterClass(alwaysRun=true)
- public void cleanUp() {
- String noTest = System.getProperty("noTestCleanup");
- if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
- if (logger.isDebugEnabled()) {
- logger.debug("Skipping Cleanup phase ...");
- }
- return;
- }
- if (logger.isDebugEnabled()) {
- logger.debug("Cleaning up temporary resources created for testing ...");
- }
- DimensionClient client = new DimensionClient();
- for (String resourceId : allResourceIdsCreated) {
- // Note: Any non-success responses are ignored and not reported.
- ClientResponse<Response> res = client.delete(resourceId);
- }
- }
-
// ---------------------------------------------------------------
// Utility methods used by tests above
// ---------------------------------------------------------------
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
+ */
@Override
public String getServicePathComponent() {
return SERVICE_PATH_COMPONENT;
}
+ /**
+ * Creates the dimension instance.
+ *
+ * @param identifier the identifier
+ * @return the multipart output
+ */
private MultipartOutput createDimensionInstance(String identifier) {
return createDimensionInstance(
"dimensionType-" + identifier,
"entryDate-" + identifier);
}
+ /**
+ * Creates the dimension instance.
+ *
+ * @param dimensionType the dimension type
+ * @param entryNumber the entry number
+ * @param entryDate the entry date
+ * @return the multipart output
+ */
private MultipartOutput createDimensionInstance(String dimensionType, String entryNumber, String entryDate) {
DimensionsCommon dimension = new DimensionsCommon();
dimension.setDimension(dimensionType);
final String SERVICE_PATH_COMPONENT = "intakes";
final String PERSON_AUTHORITY_NAME = "TestPersonAuth";
private String knownResourceId = null;
- private List<String> intakeIdsCreated = new ArrayList();
- private List<String> personIdsCreated = new ArrayList();
+ private List<String> intakeIdsCreated = new ArrayList<String>();
+ private List<String> personIdsCreated = new ArrayList<String>();
private int CREATED_STATUS = Response.Status.CREATED.getStatusCode();
private int OK_STATUS = Response.Status.OK.getStatusCode();
private String personAuthCSID = null;
IntakeClient intakeClient = new IntakeClient();
// Note: Any non-success responses are ignored and not reported.
for (String resourceId : intakeIdsCreated) {
- ClientResponse<Response> res = intakeClient.delete(resourceId);
+ intakeClient.delete(resourceId).releaseConnection();
}
PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
// Delete persons before PersonAuth
for (String resourceId : personIdsCreated) {
- ClientResponse<Response> res = personAuthClient.deleteItem(personAuthCSID, resourceId);
+ personAuthClient.deleteItem(personAuthCSID, resourceId).releaseConnection();
}
- ClientResponse<Response> res = personAuthClient.delete(personAuthCSID);
+ personAuthClient.delete(personAuthCSID).releaseConnection();
}
// ---------------------------------------------------------------
*/
package org.collectionspace.services.client.test;
-import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
import org.testng.Assert;
-import org.testng.annotations.AfterClass;
+//import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
import org.slf4j.Logger;
/** The known resource id. */
private String knownResourceId = null;
- /** The all resource ids created. */
- private List<String> allResourceIdsCreated = new ArrayList<String>();
-
/* (non-Javadoc)
* @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
*/
*/
@Override
public void createWithEmptyEntityBody(String testName) throws Exception {
+ //Should this really be empty?
}
/* (non-Javadoc)
*/
@Override
public void createWithMalformedXml(String testName) throws Exception {
+ //Should this really be empty?
}
/* (non-Javadoc)
*/
@Override
public void createWithWrongXmlSchema(String testName) throws Exception {
+ //Should this really be empty?
}
/*
* @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
*/
@Override
- public void updateWithEmptyEntityBody(String testName) throws Exception{
+ public void updateWithEmptyEntityBody(String testName) throws Exception {
+ //Should this really be empty?
}
/* (non-Javadoc)
*/
@Override
public void updateWithMalformedXml(String testName) throws Exception {
+ //Should this really be empty?
}
/* (non-Javadoc)
*/
@Override
public void updateWithWrongXmlSchema(String testName) throws Exception {
+ //Should this really be empty?
}
/*
}
- // ---------------------------------------------------------------
- // Cleanup of resources created during testing
- // ---------------------------------------------------------------
-
- /**
- * Deletes all resources created by tests, after all tests have been run.
- *
- * This cleanup method will always be run, even if one or more tests fail.
- * For this reason, it attempts to remove all resources created
- * at any point during testing, even if some of those resources
- * may be expected to be deleted by certain tests.
- */
- @AfterClass(alwaysRun=true)
- public void cleanUp() {
- String noTest = System.getProperty("noTestCleanup");
- if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
- if (logger.isDebugEnabled()) {
- logger.debug("Skipping Cleanup phase ...");
- }
- return;
- }
- if (logger.isDebugEnabled()) {
- logger.debug("Cleaning up temporary resources created for testing ...");
- }
- IntakeClient client = new IntakeClient();
- for (String resourceId : allResourceIdsCreated) {
- // Note: Any non-success responses are ignored and not reported.
- ClientResponse<Response> res = client.delete(resourceId);
- }
- }
-
// ---------------------------------------------------------------
// Utility methods used by tests above
// ---------------------------------------------------------------
lendersAuthorizerRefName,
lendersContactRefName,
loanInContactRefName);
- ClientResponse<Response> res = loaninClient.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);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-
- // Store the ID returned from the first resource created
- // for additional tests below.
- if (knownResourceId == null){
- knownResourceId = extractId(res);
- if (logger.isDebugEnabled()) {
- logger.debug(testName + ": knownResourceId=" + knownResourceId);
- }
+ ClientResponse<Response> response = loaninClient.create(multipart);
+ int statusCode = response.getStatus();
+ 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(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ // 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));
+ } finally {
+ response.releaseConnection();
}
-
- // Store the IDs from every resource created by tests,
- // so they can be deleted after tests have been run.
- loaninIdsCreated.add(extractId(res));
}
protected void createPersonRefs(){
for (String resourceId : personIdsCreated) {
// Note: Any non-success responses are ignored and not reported.
- personAuthClient.deleteItem(personAuthCSID, resourceId);
+ ClientResponse<Response> response =
+ personAuthClient.deleteItem(personAuthCSID, resourceId); // alternative to personAuthClient.deleteItem().releaseConnection();
+ response.releaseConnection();
}
// Delete PersonAuthority resource(s).
if (personAuthCSID != null) {
personAuthClient.delete(personAuthCSID);
// Delete Loans In resource(s).
- LoaninClient loaninClient = new LoaninClient();
+ LoaninClient loaninClient = new LoaninClient();
+ ClientResponse<Response> response = null;
for (String resourceId : loaninIdsCreated) {
// Note: Any non-success responses are ignored and not reported.
- loaninClient.delete(resourceId);
+ response = loaninClient.delete(resourceId); // alternative to loaninClient.delete(resourceId).releaseConnection();
+ response.releaseConnection();
}
}
}
*/
package org.collectionspace.services.client.test;
-import java.util.ArrayList;
+//import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
import org.testng.Assert;
-import org.testng.annotations.AfterClass;
+//import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
import org.slf4j.Logger;
*/
public class LoaninServiceTest extends AbstractServiceTestImpl {
+ /** The logger. */
private final Logger logger =
LoggerFactory.getLogger(LoaninServiceTest.class);
// Instance variables specific to this test.
+ /** The SERVIC e_ pat h_ component. */
final String SERVICE_PATH_COMPONENT = "loansin";
+
+ /** The known resource id. */
private String knownResourceId = null;
- private List<String> allResourceIdsCreated = new ArrayList<String>();
/* (non-Javadoc)
* @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
// CRUD tests : CREATE tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
+ */
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
public void create(String testName) throws Exception {
LoaninClient client = new LoaninClient();
String identifier = createIdentifier();
MultipartOutput multipart = createLoaninInstance(identifier);
+ String newID = null;
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);
+ 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(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ newID = extractId(res);
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
// 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)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
+ */
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
dependsOnMethods = {"create"})
// Failure outcomes
// Placeholders until the three tests below can be uncommented.
// See Issue CSPACE-401.
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
+ */
@Override
public void createWithEmptyEntityBody(String testName) throws Exception {
+ //Should this really be empty?
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
+ */
@Override
public void createWithMalformedXml(String testName) throws Exception {
+ //Should this really be empty?
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
+ */
@Override
public void createWithWrongXmlSchema(String testName) throws Exception {
+ //Should this really be empty?
}
/*
// CRUD tests : READ tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
+ */
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
dependsOnMethods = {"create"})
public void read(String testName) throws Exception {
-
// Perform setup.
setupRead(testName);
// Submit the request to the service and store the response.
+ MultipartInput input = null;
LoaninClient client = new LoaninClient();
ClientResponse<MultipartInput> res = client.read(knownResourceId);
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
+ try {
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ input = res.getEntity();
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-
- MultipartInput input = (MultipartInput) res.getEntity();
+
LoansinCommon loanin = (LoansinCommon) extractPart(input,
client.getCommonPartName(), LoansinCommon.class);
Assert.assertNotNull(loanin);
}
// Failure outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
+ */
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
dependsOnMethods = {"read"})
// Submit the request to the service and store the response.
LoaninClient client = new LoaninClient();
ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
+ try {
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
}
// ---------------------------------------------------------------
// CRUD tests : READ_LIST tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
+ */
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
dependsOnMethods = {"createList", "read"})
public void readList(String testName) throws Exception {
-
// Perform setup.
setupReadList(testName);
// Submit the request to the service and store the response.
+ LoansinCommonList list = null;
LoaninClient client = new LoaninClient();
ClientResponse<LoansinCommonList> res = client.readList();
- LoansinCommonList list = res.getEntity();
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
+ try {
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ list = res.getEntity();
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
// Optionally output additional data about list members for debugging.
boolean iterateThroughList = false;
- if(iterateThroughList && logger.isDebugEnabled()){
+ if (iterateThroughList && logger.isDebugEnabled()){
List<LoansinCommonList.LoaninListItem> items =
list.getLoaninListItem();
int i = 0;
i++;
}
}
-
}
// Failure outcomes
// CRUD tests : UPDATE tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
+ */
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
dependsOnMethods = {"read"})
setupUpdate(testName);
// Retrieve the contents of a resource to update.
+ MultipartInput input = null;
LoaninClient client = new LoaninClient();
ClientResponse<MultipartInput> res =
- client.read(knownResourceId);
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": read status = " + res.getStatus());
- }
- Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
-
- if(logger.isDebugEnabled()){
- logger.debug("got object to update with ID: " + knownResourceId);
+ client.read(knownResourceId);
+ try {
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": read status = " + res.getStatus());
+ }
+ Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
+
+ if(logger.isDebugEnabled()){
+ logger.debug("got object to update with ID: " + knownResourceId);
+ }
+ input = res.getEntity();
+ } finally {
+ res.releaseConnection();
}
- MultipartInput input = (MultipartInput) res.getEntity();
+
LoansinCommon loanin = (LoansinCommon) extractPart(input,
client.getCommonPartName(), LoansinCommon.class);
Assert.assertNotNull(loanin);
commonPart.getHeaders().add("label", client.getCommonPartName());
res = client.update(knownResourceId, output);
- int statusCode = res.getStatus();
- // Check the status code of the response: does it match the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
+ try {
+ int statusCode = res.getStatus();
+ // Check the status code of the response: does it match the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+
+ input = (MultipartInput) res.getEntity();
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-
-
- input = (MultipartInput) res.getEntity();
+
LoansinCommon updatedLoanin =
(LoansinCommon) extractPart(input,
client.getCommonPartName(), LoansinCommon.class);
Assert.assertEquals(updatedLoanin.getLoanReturnDate(),
loanin.getLoanReturnDate(),
"Data in updated object did not match submitted data.");
-
}
// Failure outcomes
// Placeholders until the three tests below can be uncommented.
// See Issue CSPACE-401.
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
+ */
@Override
- public void updateWithEmptyEntityBody(String testName) throws Exception{
+ public void updateWithEmptyEntityBody(String testName) throws Exception {
+ //Should this really be empty?
}
+
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
+ */
@Override
public void updateWithMalformedXml(String testName) throws Exception {
+ //Should this really be empty?
}
+
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
+ */
@Override
public void updateWithWrongXmlSchema(String testName) throws Exception {
+ //Should this really be empty?
}
/*
}
*/
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
+ */
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
dependsOnMethods = {"update", "testSubmitRequest"})
MultipartOutput multipart = createLoaninInstance(NON_EXISTENT_ID);
ClientResponse<MultipartInput> res =
client.update(NON_EXISTENT_ID, multipart);
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
+ try {
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
}
// ---------------------------------------------------------------
// CRUD tests : DELETE tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
+ */
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
// Submit the request to the service and store the response.
LoaninClient client = new LoaninClient();
ClientResponse<Response> res = client.delete(knownResourceId);
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
+ try {
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
}
// Failure outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
+ */
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
dependsOnMethods = {"delete"})
public void deleteNonExistent(String testName) throws Exception {
-
// Perform setup.
setupDeleteNonExistent(testName);
// Submit the request to the service and store the response.
LoaninClient client = new LoaninClient();
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)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
+ try {
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
}
// ---------------------------------------------------------------
}
- // ---------------------------------------------------------------
- // Cleanup of resources created during testing
- // ---------------------------------------------------------------
-
- /**
- * Deletes all resources created by tests, after all tests have been run.
- *
- * This cleanup method will always be run, even if one or more tests fail.
- * For this reason, it attempts to remove all resources created
- * at any point during testing, even if some of those resources
- * may be expected to be deleted by certain tests.
- */
- @AfterClass(alwaysRun=true)
- public void cleanUp() {
- if (logger.isDebugEnabled()) {
- logger.debug("Cleaning up temporary resources created for testing ...");
- }
- LoaninClient client = new LoaninClient();
- for (String resourceId : allResourceIdsCreated) {
- // Note: Any non-success responses are ignored and not reported.
- ClientResponse<Response> res = client.delete(resourceId);
- }
- }
-
// ---------------------------------------------------------------
// Utility methods used by tests above
// ---------------------------------------------------------------
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
+ */
@Override
public String getServicePathComponent() {
return SERVICE_PATH_COMPONENT;
}
+ /**
+ * Creates the loanin instance.
+ *
+ * @param identifier the identifier
+ * @return the multipart output
+ */
private MultipartOutput createLoaninInstance(String identifier) {
return createLoaninInstance(
"loaninNumber-" + identifier,
"returnDate-" + identifier);
}
+ /**
+ * Creates the loanin instance.
+ *
+ * @param loaninNumber the loanin number
+ * @param returnDate the return date
+ * @return the multipart output
+ */
private MultipartOutput createLoaninInstance(String loaninNumber,
String returnDate) {
LoansinCommon loanin = new LoansinCommon();
*/
package org.collectionspace.services.client.test;
-import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
import org.testng.Assert;
-import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
import org.slf4j.Logger;
/** The known resource id. */
private String knownResourceId = null;
- /** The all resource ids created. */
- private List<String> allResourceIdsCreated = new ArrayList<String>();
-
/* (non-Javadoc)
* @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
*/
*/
@Override
public void createWithEmptyEntityBody(String testName) throws Exception {
+ //Should this really be empty?
}
/* (non-Javadoc)
*/
@Override
public void createWithMalformedXml(String testName) throws Exception {
+ //Should this really be empty?
}
/* (non-Javadoc)
*/
@Override
public void createWithWrongXmlSchema(String testName) throws Exception {
+ //Should this really be empty?
}
/*
*/
@Override
public void updateWithEmptyEntityBody(String testName) throws Exception{
+ //Should this really be empty?
}
/* (non-Javadoc)
*/
@Override
public void updateWithMalformedXml(String testName) throws Exception {
+ //Should this really be empty?
}
/* (non-Javadoc)
*/
@Override
public void updateWithWrongXmlSchema(String testName) throws Exception {
+ //Should this really be empty?
}
/*
}
- // ---------------------------------------------------------------
- // Cleanup of resources created during testing
- // ---------------------------------------------------------------
-
- /**
- * Deletes all resources created by tests, after all tests have been run.
- *
- * This cleanup method will always be run, even if one or more tests fail.
- * For this reason, it attempts to remove all resources created
- * at any point during testing, even if some of those resources
- * may be expected to be deleted by certain tests.
- */
- @AfterClass(alwaysRun=true)
- public void cleanUp() {
- String noTest = System.getProperty("noTestCleanup");
- if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
- if (logger.isDebugEnabled()) {
- logger.debug("Skipping Cleanup phase ...");
- }
- return;
- }
- if (logger.isDebugEnabled()) {
- logger.debug("Cleaning up temporary resources created for testing ...");
- }
- LoanoutClient client = new LoanoutClient();
- for (String resourceId : allResourceIdsCreated) {
- // Note: Any non-success responses are ignored and not reported.
- ClientResponse<Response> res = client.delete(resourceId);
- }
- }
-
// ---------------------------------------------------------------
// Utility methods used by tests above
// ---------------------------------------------------------------
+/** \r
+ * OrgAuthorityClientUtils.java\r
+ *\r
+ * {Purpose of This Class}\r
+ *\r
+ * {Other Notes Relating to This Class (Optional)}\r
+ *\r
+ * $LastChangedBy: $\r
+ * $LastChangedRevision: $\r
+ * $LastChangedDate: $\r
+ *\r
+ * This document is a part of the source code and related artifacts\r
+ * for CollectionSpace, an open source collections management system\r
+ * for museums and related institutions:\r
+ *\r
+ * http://www.collectionspace.org\r
+ * http://wiki.collectionspace.org\r
+ *\r
+ * Copyright © 2009 {Contributing Institution}\r
+ *\r
+ * Licensed under the Educational Community License (ECL), Version 2.0.\r
+ * You may not use this file except in compliance with this License.\r
+ *\r
+ * You may obtain a copy of the ECL 2.0 License at\r
+ * https://source.collectionspace.org/collection-space/LICENSE.txt\r
+ */\r
package org.collectionspace.services.client;\r
\r
import java.util.ArrayList;\r
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
\r
+/**\r
+ * The Class OrgAuthorityClientUtils.\r
+ */\r
public class OrgAuthorityClientUtils {\r
+ \r
+ /** The Constant logger. */\r
private static final Logger logger =\r
LoggerFactory.getLogger(OrgAuthorityClientUtils.class);\r
\r
+ /**\r
+ * Creates the org authority instance.\r
+ *\r
+ * @param displayName the display name\r
+ * @param refName the ref name\r
+ * @param headerLabel the header label\r
+ * @return the multipart output\r
+ */\r
public static MultipartOutput createOrgAuthorityInstance(\r
String displayName, String refName, String headerLabel ) {\r
OrgauthoritiesCommon orgAuthority = new OrgauthoritiesCommon();\r
return multipart;\r
}\r
\r
+ /**\r
+ * Creates the item in authority.\r
+ *\r
+ * @param vcsid the vcsid\r
+ * @param orgAuthorityRefName the org authority ref name\r
+ * @param orgInfo the org info\r
+ * @param client the client\r
+ * @return the string\r
+ */\r
public static String createItemInAuthority(String vcsid, \r
String orgAuthorityRefName, Map<String, String> orgInfo,\r
OrgAuthorityClient client) {\r
orgInfo.get(OrganizationJAXBSchema.SHORT_NAME ), \r
orgInfo.get(OrganizationJAXBSchema.FOUNDING_PLACE ));\r
}\r
- String refName = createOrganizationRefName( orgAuthorityRefName, displayName, true);\r
+ String refName = createOrganizationRefName(orgAuthorityRefName, displayName, true);\r
\r
if(logger.isDebugEnabled()){\r
logger.debug("Import: Create Item: \""+displayName\r
+"\" in orgAuthority: \"" + orgAuthorityRefName +"\"");\r
}\r
MultipartOutput multipart =\r
- createOrganizationInstance( vcsid, refName, orgInfo, client.getItemCommonPartName() );\r
+ createOrganizationInstance(vcsid, refName, orgInfo, client.getItemCommonPartName());\r
ClientResponse<Response> res = client.createItem(vcsid, multipart);\r
-\r
- int statusCode = res.getStatus();\r
-\r
- if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
- throw new RuntimeException("Could not create Item: \""+displayName\r
- +"\" in orgAuthority: \"" + orgAuthorityRefName\r
- +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
+ String result;\r
+ try { \r
+ int statusCode = res.getStatus();\r
+ \r
+ if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
+ throw new RuntimeException("Could not create Item: \""+displayName\r
+ +"\" in orgAuthority: \"" + orgAuthorityRefName\r
+ +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
+ }\r
+ if(statusCode != EXPECTED_STATUS_CODE) {\r
+ throw new RuntimeException("Unexpected Status when creating Item: \""+ displayName\r
+ +"\" in orgAuthority: \"" + orgAuthorityRefName +"\", Status:"+ statusCode);\r
+ }\r
+ \r
+ result = extractId(res);\r
+ } finally {\r
+ res.releaseConnection();\r
}\r
- if(statusCode != EXPECTED_STATUS_CODE) {\r
- throw new RuntimeException("Unexpected Status when creating Item: \""+displayName\r
- +"\" in orgAuthority: \"" + orgAuthorityRefName +"\", Status:"+ statusCode);\r
- }\r
-\r
- return extractId(res);\r
+ \r
+ return result;\r
}\r
\r
+ /**\r
+ * Creates the organization instance.\r
+ *\r
+ * @param inAuthority the in authority\r
+ * @param orgRefName the org ref name\r
+ * @param orgInfo the org info\r
+ * @param headerLabel the header label\r
+ * @return the multipart output\r
+ */\r
public static MultipartOutput createOrganizationInstance(String inAuthority, \r
String orgRefName, Map<String, String> orgInfo, String headerLabel){\r
OrganizationsCommon organization = new OrganizationsCommon();\r
requestType.validStatusCodesAsString();\r
}\r
\r
+ /**\r
+ * Extract id.\r
+ *\r
+ * @param res the res\r
+ * @return the string\r
+ */\r
public static String extractId(ClientResponse<Response> res) {\r
MultivaluedMap<String, Object> mvm = res.getMetadata();\r
String uri = (String) ((ArrayList<Object>) mvm.get("Location")).get(0);\r
return id;\r
}\r
\r
+ /**\r
+ * Creates the org auth ref name.\r
+ *\r
+ * @param orgAuthorityName the org authority name\r
+ * @param withDisplaySuffix the with display suffix\r
+ * @return the string\r
+ */\r
public static String createOrgAuthRefName(String orgAuthorityName, boolean withDisplaySuffix) {\r
String refName = "urn:cspace:org.collectionspace.demo:orgauthority:name("\r
+orgAuthorityName+")";\r
return refName;\r
}\r
\r
+ /**\r
+ * Creates the organization ref name.\r
+ *\r
+ * @param orgAuthRefName the org auth ref name\r
+ * @param orgName the org name\r
+ * @param withDisplaySuffix the with display suffix\r
+ * @return the string\r
+ */\r
public static String createOrganizationRefName(\r
String orgAuthRefName, String orgName, boolean withDisplaySuffix) {\r
String refName = orgAuthRefName+":organization:name("+orgName+")";\r
*/
public class OrgAuthorityAuthRefsTest extends BaseServiceTest {
+ /** The logger. */
private final Logger logger =
LoggerFactory.getLogger(OrgAuthorityAuthRefsTest.class);
// Instance variables specific to this test.
+ /** The SERVIC e_ pat h_ component. */
final String SERVICE_PATH_COMPONENT = "orgauthorities";
+
+ /** The PERSO n_ authorit y_ name. */
final String PERSON_AUTHORITY_NAME = "TestPersonAuth";
+
+ /** The known resource ref name. */
private String knownResourceRefName = null;
+
+ /** The known auth resource id. */
private String knownAuthResourceId = null;
+
+ /** The known item id. */
private String knownItemId = null;
+
+ /** The all resource ids created. */
private List<String> allResourceIdsCreated = new ArrayList<String>();
+
+ /** The all item resource ids created. */
private Map<String, String> allItemResourceIdsCreated =
new HashMap<String, String>();
- private List<String> personIdsCreated = new ArrayList();
+
+ /** The person ids created. */
+ private List<String> personIdsCreated = new ArrayList<String>();
+
+ /** The CREATE d_ status. */
private int CREATED_STATUS = Response.Status.CREATED.getStatusCode();
+
+ /** The O k_ status. */
private int OK_STATUS = Response.Status.OK.getStatusCode();
+
+ /** The person auth csid. */
private String personAuthCSID = null;
+
+ /** The organization contact person ref name. */
private String organizationContactPersonRefName = null;
+
+ /** The NU m_ aut h_ ref s_ expected. */
private final int NUM_AUTH_REFS_EXPECTED = 1;
/* (non-Javadoc)
// CRUD tests : CREATE tests
// ---------------------------------------------------------------
// Success outcomes
+ /**
+ * Creates the with auth refs.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
public void createWithAuthRefs(String testName) throws Exception {
OrgAuthorityClientUtils.createOrgAuthRefName(displayName, createWithDisplayName);
MultipartOutput multipart =
OrgAuthorityClientUtils.createOrgAuthorityInstance(
- displayName, knownResourceRefName, new OrgAuthorityClient().getCommonPartName());
+ displayName, knownResourceRefName, orgAuthClient.getCommonPartName());
// Submit the request to the service and store the response.
ClientResponse<Response> res = orgAuthClient.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);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-
- // Store the IDs from every resource created by tests,
- // so they can be deleted after tests have been run.
- knownAuthResourceId = extractId(res);
+ 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(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ // Store the IDs from every resource created by tests,
+ // so they can be deleted after tests have been run.
+ knownAuthResourceId = extractId(res);
+ } finally {
+ res.releaseConnection();
+ }
allResourceIdsCreated.add(knownAuthResourceId);
// Create all the person refs and entities
knownItemId = OrgAuthorityClientUtils.createItemInAuthority(
knownAuthResourceId, knownResourceRefName, testOrgMap, orgAuthClient);
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-
// Store the IDs from every item created by tests,
// so they can be deleted after tests have been run.
allItemResourceIdsCreated.put(knownItemId, knownAuthResourceId);
-
}
- protected void createPersonRefs(){
-
+ /**
+ * Creates the person refs.
+ */
+ protected void createPersonRefs() {
PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
// Create a temporary PersonAuthority resource, and its corresponding
// refName by which it can be identified.
PersonAuthorityClientUtils.createPersonAuthRefName(PERSON_AUTHORITY_NAME, false);
MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
PERSON_AUTHORITY_NAME, authRefName, personAuthClient.getCommonPartName());
- ClientResponse<Response> res = personAuthClient.create(multipart);
- int statusCode = res.getStatus();
-
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, CREATED_STATUS);
- personAuthCSID = extractId(res);
+
+ ClientResponse<Response> res = personAuthClient.create(multipart);
+ try {
+ int statusCode = res.getStatus();
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, CREATED_STATUS);
+ personAuthCSID = extractId(res);
+ } finally {
+ res.releaseConnection();
+ }
// Create a temporary Person resource, and its corresponding refName
// by which it can be identified.
}
+ /**
+ * Creates the person.
+ *
+ * @param firstName the first name
+ * @param surName the sur name
+ * @param refName the ref name
+ * @return the string
+ */
protected String createPerson(String firstName, String surName, String refName ) {
PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
Map<String, String> personInfo = new HashMap<String,String>();
MultipartOutput multipart =
PersonAuthorityClientUtils.createPersonInstance(personAuthCSID,
refName, personInfo, personAuthClient.getItemCommonPartName());
- ClientResponse<Response> res = personAuthClient.createItem(personAuthCSID, multipart);
- int statusCode = res.getStatus();
-
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, CREATED_STATUS);
- return extractId(res);
+
+ String result = null;
+ ClientResponse<Response> res = personAuthClient.createItem(personAuthCSID, multipart);
+ try {
+ int statusCode = res.getStatus();
+
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, CREATED_STATUS);
+ result = extractId(res);
+ } finally {
+ res.releaseConnection();
+ }
+
+ return result;
}
// Success outcomes
+ /**
+ * Read and check auth refs.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
dependsOnMethods = {"createWithAuthRefs"})
public void readAndCheckAuthRefs(String testName) throws Exception {
}
PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
// Delete Person resource(s) (before PersonAuthority resources).
- ClientResponse<Response> res;
for (String resourceId : personIdsCreated) {
// Note: Any non-success responses are ignored and not reported.
- res = personAuthClient.deleteItem(personAuthCSID, resourceId);
+ personAuthClient.deleteItem(personAuthCSID, resourceId).releaseConnection();
}
// Delete PersonAuthority resource(s).
// Note: Any non-success response is ignored and not reported.
- res = personAuthClient.delete(personAuthCSID);
+ personAuthClient.delete(personAuthCSID).releaseConnection();
+
String parentResourceId;
String itemResourceId;
OrgAuthorityClient client = new OrgAuthorityClient();
parentResourceId = entry.getValue();
// Note: Any non-success responses from the delete operation
// below are ignored and not reported.
- res = client.deleteItem(parentResourceId, itemResourceId);
+ client.deleteItem(parentResourceId, itemResourceId).releaseConnection();
}
+
// Clean up parent resources.
for (String resourceId : allResourceIdsCreated) {
// Note: Any non-success responses from the delete operation
// below are ignored and not reported.
- res = client.delete(resourceId);
+ client.delete(resourceId).releaseConnection();
}
}
// ---------------------------------------------------------------
// Utility methods used by tests above
// ---------------------------------------------------------------
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
+ */
@Override
public String getServicePathComponent() {
return SERVICE_PATH_COMPONENT;
}
+ /**
+ * Creates the org authority instance.
+ *
+ * @param identifier the identifier
+ * @return the multipart output
+ */
private MultipartOutput createOrgAuthorityInstance(String identifier) {
String displayName = "displayName-" + identifier;
String refName = OrgAuthorityClientUtils.createOrgAuthRefName(displayName, true);
*/
package org.collectionspace.services.client.test;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
*/
public class OrgAuthorityServiceTest extends AbstractServiceTestImpl {
+ /** The logger. */
private final Logger logger =
LoggerFactory.getLogger(OrgAuthorityServiceTest.class);
// Instance variables specific to this test.
+ /** The SERVIC e_ pat h_ component. */
final String SERVICE_PATH_COMPONENT = "orgauthorities";
+
+ /** The ITE m_ servic e_ pat h_ component. */
final String ITEM_SERVICE_PATH_COMPONENT = "items";
+
+ /** The CONTAC t_ servic e_ pat h_ component. */
final String CONTACT_SERVICE_PATH_COMPONENT = "contacts";
+
+ /** The TES t_ or g_ shortname. */
private final String TEST_ORG_SHORTNAME = "Test Org";
+
+ /** The TES t_ or g_ foundin g_ place. */
private final String TEST_ORG_FOUNDING_PLACE = "Anytown, USA";
+
+ /** The known resource id. */
private String knownResourceId = null;
+
+ /** The known resource display name. */
private String knownResourceDisplayName = null;
+
+ /** The known resource ref name. */
private String knownResourceRefName = null;
+
+ /** The known item resource id. */
private String knownItemResourceId = null;
+
+ /** The known contact resource id. */
private String knownContactResourceId = null;
+
+ /** The n items to create in list. */
private int nItemsToCreateInList = 3;
- private List<String> allResourceIdsCreated = new ArrayList<String>();
+
+ /** The all item resource ids created. */
private Map<String, String> allItemResourceIdsCreated =
new HashMap<String, String>();
+
+ /** The all contact resource ids created. */
private Map<String, String> allContactResourceIdsCreated =
new HashMap<String, String>();
// CRUD tests : CREATE tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
+ */
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
groups = {"create"})
MultipartOutput multipart =
OrgAuthorityClientUtils.createOrgAuthorityInstance(
displayName, refName, 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);
+
+ String newID = null;
+ ClientResponse<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(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ // Store the refname from the first resource created
+ // for additional tests below.
+ knownResourceRefName = refName;
+
+ newID = OrgAuthorityClientUtils.extractId(res);
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-
- // Store the refname from the first resource created
- // for additional tests below.
- knownResourceRefName = refName;
-
- String newID = OrgAuthorityClientUtils.extractId(res);
+
// Store the ID returned from the first resource created
// for additional tests below.
if (knownResourceId == null){
allResourceIdsCreated.add(newID);
}
+ /**
+ * Creates the item.
+ *
+ * @param testName the test name
+ */
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
groups = {"create"}, dependsOnMethods = {"create"})
public void createItem(String testName) {
String newID = createItemInAuthority(knownResourceId, knownResourceRefName);
}
+ /**
+ * Creates the item in authority.
+ *
+ * @param vcsid the vcsid
+ * @param authRefName the auth ref name
+ * @return the string
+ */
private String createItemInAuthority(String vcsid, String authRefName) {
final String testName = "createItemInAuthority";
return newID;
}
+ /**
+ * Creates the contact.
+ *
+ * @param testName the test name
+ */
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
groups = {"create"}, dependsOnMethods = {"createItem"})
public void createContact(String testName) {
String newID = createContactInItem(knownResourceId, knownItemResourceId);
}
+ /**
+ * Creates the contact in item.
+ *
+ * @param parentcsid the parentcsid
+ * @param itemcsid the itemcsid
+ * @return the string
+ */
private String createContactInItem(String parentcsid, String itemcsid) {
final String testName = "createContactInItem";
MultipartOutput multipart =
ContactClientUtils.createContactInstance(parentcsid,
itemcsid, identifier, new ContactClient().getCommonPartName());
+
+ String newID = null;
ClientResponse<Response> res =
client.createContact(parentcsid, itemcsid, multipart);
- int statusCode = res.getStatus();
- String newID = OrgAuthorityClientUtils.extractId(res);
+ try {
+ int statusCode = res.getStatus();
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
+ newID = OrgAuthorityClientUtils.extractId(res);
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
// Store the ID returned from the first contact resource created
// for additional tests below.
// Placeholders until the three tests below can be uncommented.
// See Issue CSPACE-401.
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
+ */
@Override
public void createWithEmptyEntityBody(String testName) throws Exception {
+ //Should this really be empty?
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
+ */
@Override
public void createWithMalformedXml(String testName) throws Exception {
+ //Should this really be empty?
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
+ */
@Override
public void createWithWrongXmlSchema(String testName) throws Exception {
+ //Should this really be empty?
}
/*
// CRUD tests : CREATE LIST tests
// ---------------------------------------------------------------
// Success outcomes
- @Override
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
+ */
+@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
groups = {"createList"}, dependsOnGroups = {"create"})
public void createList(String testName) throws Exception {
}
}
+ /**
+ * Creates the item list.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
groups = {"createList"}, dependsOnMethods = {"createList"})
public void createItemList(String testName) throws Exception {
}
}
+ /**
+ * Creates the contact list.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
groups = {"createList"}, dependsOnMethods = {"createItemList"})
public void createContactList(String testName) throws Exception {
// CRUD tests : READ tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
+ */
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
groups = {"read"}, dependsOnGroups = {"create"})
// Submit the request to the service and store the response.
OrgAuthorityClient client = new OrgAuthorityClient();
ClientResponse<MultipartInput> res = client.read(knownResourceId);
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
- //FIXME: remove the following try catch once Aron fixes signatures
try {
- MultipartInput input = (MultipartInput) res.getEntity();
- OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
- client.getCommonPartName(), OrgauthoritiesCommon.class);
- Assert.assertNotNull(orgAuthority);
- } catch (Exception e) {
- throw new RuntimeException(e);
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ //FIXME: remove the following try catch once Aron fixes signatures
+ try {
+ MultipartInput input = (MultipartInput) res.getEntity();
+ OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
+ client.getCommonPartName(), OrgauthoritiesCommon.class);
+ Assert.assertNotNull(orgAuthority);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ } finally {
+ res.releaseConnection();
}
}
+ /**
+ * Read by name.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
groups = {"read"}, dependsOnGroups = {"create"})
public void readByName(String testName) throws Exception {
// Submit the request to the service and store the response.
OrgAuthorityClient client = new OrgAuthorityClient();
ClientResponse<MultipartInput> res = client.readByName(knownResourceDisplayName);
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
- //FIXME: remove the following try catch once Aron fixes signatures
try {
- MultipartInput input = (MultipartInput) res.getEntity();
- OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
- new OrgAuthorityClient().getCommonPartName(), OrgauthoritiesCommon.class);
- Assert.assertNotNull(orgAuthority);
- } catch (Exception e) {
- throw new RuntimeException(e);
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ //FIXME: remove the following try catch once Aron fixes signatures
+ try {
+ MultipartInput input = (MultipartInput) res.getEntity();
+ OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
+ new OrgAuthorityClient().getCommonPartName(), OrgauthoritiesCommon.class);
+ Assert.assertNotNull(orgAuthority);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ } finally {
+ res.releaseConnection();
}
}
}
*/
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
+ /**
+ * Read item.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
+@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
groups = {"read"}, dependsOnMethods = {"read"})
public void readItem(String testName) throws Exception {
// Submit the request to the service and store the response.
OrgAuthorityClient client = new OrgAuthorityClient();
ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-
- // Check whether we've received a organization.
- MultipartInput input = (MultipartInput) res.getEntity();
- OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
- client.getItemCommonPartName(), OrganizationsCommon.class);
- Assert.assertNotNull(organization);
- boolean showFull = true;
- if(showFull && logger.isDebugEnabled()){
- logger.debug(testName + ": returned payload:");
- logger.debug(objectAsXmlString(organization,
- OrganizationsCommon.class));
+ try {
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ // Check whether we've received a organization.
+ MultipartInput input = (MultipartInput) res.getEntity();
+ OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
+ client.getItemCommonPartName(), OrganizationsCommon.class);
+ Assert.assertNotNull(organization);
+ boolean showFull = true;
+ if(showFull && logger.isDebugEnabled()){
+ logger.debug(testName + ": returned payload:");
+ logger.debug(objectAsXmlString(organization,
+ OrganizationsCommon.class));
+ }
+ Assert.assertEquals(organization.getInAuthority(), knownResourceId);
+ } finally {
+ res.releaseConnection();
}
- Assert.assertEquals(organization.getInAuthority(), knownResourceId);
}
+ /**
+ * Verify item display name.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
dependsOnMethods = {"readItem", "updateItem"})
public void verifyItemDisplayName(String testName) throws Exception {
// Submit the request to the service and store the response.
OrgAuthorityClient client = new OrgAuthorityClient();
+ MultipartInput input = null;
ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
+ try {
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ // Check whether organization has expected displayName.
+ input = res.getEntity();
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-
- // Check whether organization has expected displayName.
- MultipartInput input = (MultipartInput) res.getEntity();
+
OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
client.getItemCommonPartName(), OrganizationsCommon.class);
Assert.assertNotNull(organization);
OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
commonPart.getHeaders().add("label", client.getItemCommonPartName());
res = client.updateItem(knownResourceId, knownItemResourceId, output);
- statusCode = res.getStatus();
-
- // Check the status code of the response: does it match the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug("updateItem: status = " + statusCode);
+ try {
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug("updateItem: status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ // Retrieve the updated resource and verify that its contents exist.
+ input = (MultipartInput) res.getEntity();
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-
- // Retrieve the updated resource and verify that its contents exist.
- input = (MultipartInput) res.getEntity();
+
OrganizationsCommon updatedOrganization =
(OrganizationsCommon) extractPart(input,
client.getItemCommonPartName(), OrganizationsCommon.class);
commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
commonPart.getHeaders().add("label", client.getItemCommonPartName());
res = client.updateItem(knownResourceId, knownItemResourceId, output);
- statusCode = res.getStatus();
-
- // Check the status code of the response: does it match the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug("updateItem: status = " + statusCode);
+ try {
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug("updateItem: status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ // Retrieve the updated resource and verify that its contents exist.
+ input = (MultipartInput) res.getEntity();
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-
- // Retrieve the updated resource and verify that its contents exist.
- input = (MultipartInput) res.getEntity();
+
updatedOrganization =
(OrganizationsCommon) extractPart(input,
client.getItemCommonPartName(), OrganizationsCommon.class);
"Updated DisplayName (not computed) in Organization not stored.");
}
+ /**
+ * Verify illegal item display name.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
dependsOnMethods = {"verifyItemDisplayName"})
public void verifyIllegalItemDisplayName(String testName) throws Exception {
Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
}
+ /**
+ * Read contact.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
groups = {"read"}, dependsOnMethods = {"readItem"})
public void readContact(String testName) throws Exception {
}
// Failure outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
+ */
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
groups = {"read"}, dependsOnMethods = {"read"})
Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
}
+ /**
+ * Read item non existent.
+ *
+ * @param testName the test name
+ */
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
groups = {"read"}, dependsOnMethods = {"readItem"})
public void readItemNonExistent(String testName) {
Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
}
+ /**
+ * Read contact non existent.
+ *
+ * @param testName the test name
+ */
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
groups = {"read"}, dependsOnMethods = {"readContact"})
public void readContactNonExistent(String testName) {
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
+ */
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
groups = {"readList"}, dependsOnGroups = {"createList", "read"})
}
}
+ /**
+ * Read item list.
+ */
@Test(groups = {"readList"}, dependsOnMethods = {"readList"})
public void readItemList() {
readItemList(knownResourceId, null);
}
+ /**
+ * Read item list by authority name.
+ */
@Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
public void readItemListByAuthorityName() {
readItemList(null, knownResourceDisplayName);
}
+ /**
+ * Read item list.
+ *
+ * @param vcsid the vcsid
+ * @param name the name
+ */
private void readItemList(String vcsid, String name) {
final String testName = "readItemList";
}
}
+ /**
+ * Read contact list.
+ */
@Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
public void readContactList() {
readContactList(knownResourceId, knownItemResourceId);
}
+ /**
+ * Read contact list.
+ *
+ * @param parentcsid the parentcsid
+ * @param itemcsid the itemcsid
+ */
private void readContactList(String parentcsid, String itemcsid) {
final String testName = "readContactList";
// CRUD tests : UPDATE tests
// ---------------------------------------------------------------
// Success outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
+ */
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
groups = {"update"}, dependsOnGroups = {"read", "readList"})
"Data in updated object did not match submitted data.");
}
+ /**
+ * Update item.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
groups = {"update"}, dependsOnMethods = {"update"})
public void updateItem(String testName) throws Exception {
"Data in updated Organization did not match submitted data.");
}
+ /**
+ * Update contact.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
groups = {"update"}, dependsOnMethods = {"updateItem"})
public void updateContact(String testName) throws Exception {
// Failure outcomes
// Placeholders until the three tests below can be uncommented.
// See Issue CSPACE-401.
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
+ */
@Override
public void updateWithEmptyEntityBody(String testName) throws Exception {
+ //Should this really be empty?
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
+ */
@Override
public void updateWithMalformedXml(String testName) throws Exception {
+ //Should this really be empty?
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
+ */
@Override
public void updateWithWrongXmlSchema(String testName) throws Exception {
+ //Should this really be empty?
}
/*
}
*/
- @Override
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
+ */
+@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
public void updateNonExistent(String testName) throws Exception {
Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
}
+ /**
+ * Update non existent item.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
public void updateNonExistentItem(String testName) throws Exception {
Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
}
+ /**
+ * Update non existent contact.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
public void updateNonExistentContact(String testName) throws Exception {
// Note: delete sub-resources in ascending hierarchical order,
// before deleting their parents.
+ /**
+ * Delete contact.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
public void deleteContact(String testName) throws Exception {
Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
}
+ /**
+ * Delete item.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
groups = {"delete"}, dependsOnMethods = {"deleteContact"})
public void deleteItem(String testName) throws Exception {
Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
}
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
+ */
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
groups = {"delete"}, dependsOnMethods = {"deleteItem"})
}
// Failure outcomes
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
+ */
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
groups = {"delete"}, dependsOnMethods = {"delete"})
Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
}
+ /**
+ * Delete non existent item.
+ *
+ * @param testName the test name
+ */
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
groups = {"delete"}, dependsOnMethods = {"deleteItem"})
public void deleteNonExistentItem(String testName) {
Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
}
+ /**
+ * Delete non existent contact.
+ *
+ * @param testName the test name
+ */
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
groups = {"delete"}, dependsOnMethods = {"deleteContact"})
public void deleteNonExistentContact(String testName) {
}
+ /**
+ * Test item submit request.
+ */
@Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
public void testItemSubmitRequest() {
}
+ /**
+ * Test contact submit request.
+ */
@Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
public void testContactSubmitRequest() {
*/
@AfterClass(alwaysRun=true)
+ @Override
public void cleanUp() {
String noTest = System.getProperty("noTestCleanup");
if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
if (logger.isDebugEnabled()) {
logger.debug("Cleaning up temporary resources created for testing ...");
}
+
String parentResourceId;
String itemResourceId;
String contactResourceId;
// below are ignored and not reported.
ClientResponse<Response> res =
client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
+ res.releaseConnection();
}
// Clean up item resources.
for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
// below are ignored and not reported.
ClientResponse<Response> res =
client.deleteItem(parentResourceId, itemResourceId);
+ res.releaseConnection();
}
// Clean up parent resources.
- for (String resourceId : allResourceIdsCreated) {
- // Note: Any non-success responses from the delete operation
- // below are ignored and not reported.
- ClientResponse<Response> res = client.delete(resourceId);
- }
+ super.cleanUp();
+
}
// ---------------------------------------------------------------
// Utility methods used by tests above
// ---------------------------------------------------------------
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
+ */
@Override
public String getServicePathComponent() {
return SERVICE_PATH_COMPONENT;
}
+ /**
+ * Gets the item service path component.
+ *
+ * @return the item service path component
+ */
public String getItemServicePathComponent() {
return ITEM_SERVICE_PATH_COMPONENT;
}
+ /**
+ * Gets the contact service path component.
+ *
+ * @return the contact service path component
+ */
public String getContactServicePathComponent() {
return CONTACT_SERVICE_PATH_COMPONENT;
}
itemResourceIdentifier) + "/" + contactResourceIdentifier;
}
+ /**
+ * Creates the org authority instance.
+ *
+ * @param identifier the identifier
+ * @return the multipart output
+ */
private MultipartOutput createOrgAuthorityInstance(String identifier) {
String displayName = "displayName-" + identifier;
String refName = OrgAuthorityClientUtils.createOrgAuthRefName(displayName, true);
<artifactId>testng</artifactId>\r
<version>5.6</version>\r
</dependency>\r
+ <!-- RESTEasy -->\r
<dependency>\r
<groupId>org.jboss.resteasy</groupId>\r
<artifactId>resteasy-jaxrs</artifactId>\r
<groupId>org.jboss.resteasy</groupId>\r
<artifactId>resteasy-multipart-provider</artifactId>\r
</dependency>\r
+ \r
<dependency>\r
<groupId>commons-httpclient</groupId>\r
<artifactId>commons-httpclient</artifactId>\r
+/** \r
+ * PersonAuthorityClientUtils.java\r
+ *\r
+ * {Purpose of This Class}\r
+ *\r
+ * {Other Notes Relating to This Class (Optional)}\r
+ *\r
+ * $LastChangedBy: $\r
+ * $LastChangedRevision: $\r
+ * $LastChangedDate: $\r
+ *\r
+ * This document is a part of the source code and related artifacts\r
+ * for CollectionSpace, an open source collections management system\r
+ * for museums and related institutions:\r
+ *\r
+ * http://www.collectionspace.org\r
+ * http://wiki.collectionspace.org\r
+ *\r
+ * Copyright © 2009 {Contributing Institution}\r
+ *\r
+ * Licensed under the Educational Community License (ECL), Version 2.0.\r
+ * You may not use this file except in compliance with this License.\r
+ *\r
+ * You may obtain a copy of the ECL 2.0 License at\r
+ * https://source.collectionspace.org/collection-space/LICENSE.txt\r
+ */\r
package org.collectionspace.services.client;\r
\r
import java.util.ArrayList;\r
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
\r
+/**\r
+ * The Class PersonAuthorityClientUtils.\r
+ */\r
public class PersonAuthorityClientUtils {\r
+ \r
+ /** The Constant logger. */\r
private static final Logger logger =\r
LoggerFactory.getLogger(PersonAuthorityClientUtils.class);\r
\r
+ /**\r
+ * Creates the person authority instance.\r
+ *\r
+ * @param displayName the display name\r
+ * @param refName the ref name\r
+ * @param headerLabel the header label\r
+ * @return the multipart output\r
+ */\r
public static MultipartOutput createPersonAuthorityInstance(\r
String displayName, String refName, String headerLabel ) {\r
PersonauthoritiesCommon personAuthority = new PersonauthoritiesCommon();\r
return multipart;\r
}\r
\r
+ /**\r
+ * Creates the person instance.\r
+ *\r
+ * @param inAuthority the in authority\r
+ * @param personRefName the person ref name\r
+ * @param personInfo the person info\r
+ * @param headerLabel the header label\r
+ * @return the multipart output\r
+ */\r
public static MultipartOutput createPersonInstance(String inAuthority, \r
String personRefName, Map<String, String> personInfo, String headerLabel){\r
PersonsCommon person = new PersonsCommon();\r
return multipart;\r
}\r
\r
+ /**\r
+ * Creates the item in authority.\r
+ *\r
+ * @param vcsid the vcsid\r
+ * @param personAuthorityRefName the person authority ref name\r
+ * @param personMap the person map\r
+ * @param client the client\r
+ * @return the string\r
+ */\r
public static String createItemInAuthority(String vcsid, \r
String personAuthorityRefName, Map<String,String> personMap,\r
PersonAuthorityClient client ) {\r
MultipartOutput multipart = \r
createPersonInstance( vcsid, refName,\r
personMap, client.getItemCommonPartName() );\r
+ \r
+ String result = null;\r
ClientResponse<Response> res = client.createItem(vcsid, multipart);\r
-\r
- int statusCode = res.getStatus();\r
-\r
- if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
- throw new RuntimeException("Could not create Item: \""+refName\r
- +"\" in personAuthority: \"" + personAuthorityRefName\r
- +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
+ try {\r
+ int statusCode = res.getStatus();\r
+ \r
+ if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
+ throw new RuntimeException("Could not create Item: \""+refName\r
+ +"\" in personAuthority: \"" + personAuthorityRefName\r
+ +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
+ }\r
+ if(statusCode != EXPECTED_STATUS_CODE) {\r
+ throw new RuntimeException("Unexpected Status when creating Item: \""+refName\r
+ +"\" in personAuthority: \"" + personAuthorityRefName +"\", Status:"+ statusCode);\r
+ }\r
+ \r
+ result = extractId(res);\r
+ } finally {\r
+ res.releaseConnection();\r
}\r
- if(statusCode != EXPECTED_STATUS_CODE) {\r
- throw new RuntimeException("Unexpected Status when creating Item: \""+refName\r
- +"\" in personAuthority: \"" + personAuthorityRefName +"\", Status:"+ statusCode);\r
- }\r
-\r
- return extractId(res);\r
+ \r
+ return result;\r
}\r
\r
+ /**\r
+ * Creates the person auth ref name.\r
+ *\r
+ * @param personAuthorityName the person authority name\r
+ * @param withDisplaySuffix the with display suffix\r
+ * @return the string\r
+ */\r
public static String createPersonAuthRefName(String personAuthorityName, boolean withDisplaySuffix) {\r
String refName = "urn:cspace:org.collectionspace.demo:personauthority:name("\r
+personAuthorityName+")";\r
return refName;\r
}\r
\r
+ /**\r
+ * Creates the person ref name.\r
+ *\r
+ * @param personAuthRefName the person auth ref name\r
+ * @param personName the person name\r
+ * @param withDisplaySuffix the with display suffix\r
+ * @return the string\r
+ */\r
public static String createPersonRefName(\r
String personAuthRefName, String personName, boolean withDisplaySuffix) {\r
String refName = personAuthRefName+":person:name("+personName+")";\r
return refName;\r
}\r
\r
+ /**\r
+ * Extract id.\r
+ *\r
+ * @param res the res\r
+ * @return the string\r
+ */\r
public static String extractId(ClientResponse<Response> res) {\r
MultivaluedMap<String, Object> mvm = res.getMetadata();\r
String uri = (String) ((ArrayList<Object>) mvm.get("Location")).get(0);\r
* @param surName\r
* @param birthDate\r
* @param deathDate\r
- * @return\r
+ * @return display name\r
*/\r
public static String prepareDefaultDisplayName(\r
String foreName, String middleName, String surName,\r
*/
package org.collectionspace.services.client.test;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** The n items to create in list. */
private int nItemsToCreateInList = 3;
- /** The all resource ids created. */
- private List<String> allResourceIdsCreated = new ArrayList<String>();
-
/** The all item resource ids created. */
private Map<String, String> allItemResourceIdsCreated =
new HashMap<String, String>();
MultipartOutput multipart =
PersonAuthorityClientUtils.createPersonAuthorityInstance(
displayName, fullRefName, 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);
- }
- Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
-
+
+ String newID = null;
+ ClientResponse<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(this.REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
+
+ newID = PersonAuthorityClientUtils.extractId(res);
+ } finally {
+ res.releaseConnection();
+ }
// Store the refname from the first resource created
// for additional tests below.
knownResourceRefName = baseRefName;
-
- String newID = PersonAuthorityClientUtils.extractId(res);
// Store the ID returned from the first resource created
// for additional tests below.
if (knownResourceId == null){
MultipartOutput multipart =
PersonAuthorityClientUtils.createPersonInstance(vcsid, refName, johnWayneMap,
client.getItemCommonPartName() );
+
+ String newID = null;
ClientResponse<Response> res = client.createItem(vcsid, multipart);
- int statusCode = res.getStatus();
- String newID = PersonAuthorityClientUtils.extractId(res);
+ try {
+ int statusCode = res.getStatus();
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
+ newID = PersonAuthorityClientUtils.extractId(res);
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
// Store the ID returned from the first item resource created
// for additional tests below.
MultipartOutput multipart =
ContactClientUtils.createContactInstance(parentcsid,
itemcsid, identifier, new ContactClient().getCommonPartName());
+
+ String newID = null;
ClientResponse<Response> res =
client.createContact(parentcsid, itemcsid, multipart);
- int statusCode = res.getStatus();
- String newID = PersonAuthorityClientUtils.extractId(res);
+ try {
+ int statusCode = res.getStatus();
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
+ newID = PersonAuthorityClientUtils.extractId(res);
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
// Store the ID returned from the first contact resource created
// for additional tests below.
*/
@Override
public void createWithEmptyEntityBody(String testName) throws Exception {
+ //Should this really be empty?
}
/* (non-Javadoc)
*/
@Override
public void createWithMalformedXml(String testName) throws Exception {
+ //Should this really be empty?
}
/* (non-Javadoc)
*/
@Override
public void createWithWrongXmlSchema(String testName) throws Exception {
+ //Should this really be empty?
}
/*
/* (non-Javadoc)
* @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
*/
-@Override
+ @Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
groups = {"createList"}, dependsOnGroups = {"create"})
public void createList(String testName) throws Exception {
// Submit the request to the service and store the response.
PersonAuthorityClient client = new PersonAuthorityClient();
ClientResponse<MultipartInput> res = client.read(knownResourceId);
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
- //FIXME: remove the following try catch once Aron fixes signatures
try {
- MultipartInput input = (MultipartInput) res.getEntity();
- PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
- client.getCommonPartName(), PersonauthoritiesCommon.class);
- Assert.assertNotNull(personAuthority);
- } catch (Exception e) {
- throw new RuntimeException(e);
+ int statusCode = res.getStatus();
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ //FIXME: remove the following try catch once Aron fixes signatures
+ try {
+ MultipartInput input = (MultipartInput) res.getEntity();
+ PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
+ client.getCommonPartName(), PersonauthoritiesCommon.class);
+ Assert.assertNotNull(personAuthority);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ } finally {
+ res.releaseConnection();
}
}
groups = {"read"}, dependsOnGroups = {"create"})
public void readByName(String testName) throws Exception {
- // Perform setup.
+ // Perform setup.
setupRead();
// Submit the request to the service and store the response.
PersonAuthorityClient client = new PersonAuthorityClient();
ClientResponse<MultipartInput> res = client.readByName(knownResourceDisplayName);
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
- //FIXME: remove the following try catch once Aron fixes signatures
try {
- MultipartInput input = (MultipartInput) res.getEntity();
- PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
- client.getCommonPartName(), PersonauthoritiesCommon.class);
- Assert.assertNotNull(personAuthority);
- } catch (Exception e) {
- throw new RuntimeException(e);
+ int statusCode = res.getStatus();
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ //FIXME: remove the following try catch once Aron fixes signatures
+ try {
+ MultipartInput input = (MultipartInput) res.getEntity();
+ PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
+ client.getCommonPartName(), PersonauthoritiesCommon.class);
+ Assert.assertNotNull(personAuthority);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ } finally {
+ res.releaseConnection();
}
}
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
groups = {"read"}, dependsOnMethods = {"read"})
public void readItem(String testName) throws Exception {
-
// Perform setup.
setupRead(testName);
// Submit the request to the service and store the response.
PersonAuthorityClient client = new PersonAuthorityClient();
ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-
- // Check whether we've received a person.
- MultipartInput input = (MultipartInput) res.getEntity();
- PersonsCommon person = (PersonsCommon) extractPart(input,
- client.getItemCommonPartName(), PersonsCommon.class);
- Assert.assertNotNull(person);
- boolean showFull = true;
- if(showFull && logger.isDebugEnabled()){
- logger.debug(testName + ": returned payload:");
- logger.debug(objectAsXmlString(person, PersonsCommon.class));
+ try {
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ // Check whether we've received a person.
+ MultipartInput input = (MultipartInput) res.getEntity();
+ PersonsCommon person = (PersonsCommon) extractPart(input,
+ client.getItemCommonPartName(), PersonsCommon.class);
+ Assert.assertNotNull(person);
+ boolean showFull = true;
+ if(showFull && logger.isDebugEnabled()){
+ logger.debug(testName + ": returned payload:");
+ logger.debug(objectAsXmlString(person, PersonsCommon.class));
+ }
+ Assert.assertEquals(person.getInAuthority(), knownResourceId);
+ } finally {
+ res.releaseConnection();
}
- Assert.assertEquals(person.getInAuthority(), knownResourceId);
-
}
/**
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
dependsOnMethods = {"readItem", "updateItem"})
public void verifyItemDisplayName(String testName) throws Exception {
-
// Perform setup.
setupUpdate(testName);
// Submit the request to the service and store the response.
PersonAuthorityClient client = new PersonAuthorityClient();
+ MultipartInput input =null;
ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-
- // Check whether person has expected displayName.
- MultipartInput input = (MultipartInput) res.getEntity();
+ try {
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ // Check whether person has expected displayName.
+ input = (MultipartInput) res.getEntity();
+ } finally {
+ res.releaseConnection();
+ }
+
PersonsCommon person = (PersonsCommon) extractPart(input,
client.getItemCommonPartName(), PersonsCommon.class);
Assert.assertNotNull(person);
TEST_FORE_NAME, null, TEST_SUR_NAME,
TEST_BIRTH_DATE, TEST_DEATH_DATE);
Assert.assertNotNull(displayName, expectedDisplayName);
-
+
// Update the shortName and verify the computed name is updated.
person.setCsid(null);
person.setDisplayNameComputed(true);
OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
commonPart.getHeaders().add("label", client.getItemCommonPartName());
res = client.updateItem(knownResourceId, knownItemResourceId, output);
- statusCode = res.getStatus();
-
- // Check the status code of the response: does it match the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug("updateItem: status = " + statusCode);
+ try {
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug("updateItem: status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ // Retrieve the updated resource and verify that its contents exist.
+ input = (MultipartInput) res.getEntity();
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-
- // Retrieve the updated resource and verify that its contents exist.
- input = (MultipartInput) res.getEntity();
+
PersonsCommon updatedPerson =
(PersonsCommon) extractPart(input,
client.getItemCommonPartName(), PersonsCommon.class);
commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
commonPart.getHeaders().add("label", client.getItemCommonPartName());
res = client.updateItem(knownResourceId, knownItemResourceId, output);
- statusCode = res.getStatus();
-
- // Check the status code of the response: does it match the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug("updateItem: status = " + statusCode);
+ try {
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug("updateItem: status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ // Retrieve the updated resource and verify that its contents exist.
+ input = (MultipartInput) res.getEntity();
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-
- // Retrieve the updated resource and verify that its contents exist.
- input = (MultipartInput) res.getEntity();
+
updatedPerson =
(PersonsCommon) extractPart(input,
client.getItemCommonPartName(), PersonsCommon.class);
// Submit the request to the service and store the response.
PersonAuthorityClient client = new PersonAuthorityClient();
+ MultipartInput input = null;
ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
+ try {
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
+
+ // Check whether Person has expected displayName.
+ input = (MultipartInput) res.getEntity();
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
-
- // Check whether Person has expected displayName.
- MultipartInput input = (MultipartInput) res.getEntity();
+
PersonsCommon person = (PersonsCommon) extractPart(input,
client.getItemCommonPartName(), PersonsCommon.class);
Assert.assertNotNull(person);
OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
commonPart.getHeaders().add("label", client.getItemCommonPartName());
res = client.updateItem(knownResourceId, knownItemResourceId, output);
- statusCode = res.getStatus();
-
- // Check the status code of the response: does it match the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug("updateItem: status = " + statusCode);
+ try {
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug("updateItem: status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
}
/**
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
groups = {"read"}, dependsOnMethods = {"readItem"})
public void readContact(String testName) throws Exception {
-
// Perform setup.
setupRead(testName);
// Submit the request to the service and store the response.
PersonAuthorityClient client = new PersonAuthorityClient();
+ MultipartInput input = null;
ClientResponse<MultipartInput> res =
client.readContact(knownResourceId, knownItemResourceId,
knownContactResourceId);
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
+ try {
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ // Check whether we've received a contact.
+ input = (MultipartInput) res.getEntity();
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-
- // Check whether we've received a contact.
- MultipartInput input = (MultipartInput) res.getEntity();
+
ContactsCommon contact = (ContactsCommon) extractPart(input,
new ContactClient().getCommonPartName(), ContactsCommon.class);
Assert.assertNotNull(contact);
// Submit the request to the service and store the response.
PersonAuthorityClient client = new PersonAuthorityClient();
ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
+ try {
+ int statusCode = res.getStatus();
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
}
/**
// Submit the request to the service and store the response.
PersonAuthorityClient client = new PersonAuthorityClient();
ClientResponse<MultipartInput> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
+ try {
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
}
/**
PersonAuthorityClient client = new PersonAuthorityClient();
ClientResponse<MultipartInput> res =
client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
+ try {
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
}
// ---------------------------------------------------------------
// Submit the request to the service and store the response.
PersonAuthorityClient client = new PersonAuthorityClient();
+ PersonauthoritiesCommonList list = null;
ClientResponse<PersonauthoritiesCommonList> res = client.readList();
- PersonauthoritiesCommonList list = res.getEntity();
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
+ try {
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ list = res.getEntity();
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
// Optionally output additional data about list members for debugging.
boolean iterateThroughList = false;
// Submit the request to the service and store the response.
PersonAuthorityClient client = new PersonAuthorityClient();
ClientResponse<PersonsCommonList> res = null;
- if(vcsid!= null) {
+ if (vcsid!= null) {
res = client.readItemList(vcsid);
- } else if(name!= null) {
+ } else if (name!= null) {
res = client.readItemListForNamedAuthority(name);
} else {
Assert.fail("readItemList passed null csid and name!");
}
- PersonsCommonList list = res.getEntity();
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
+ PersonsCommonList list = null;
+ try {
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ list = res.getEntity();
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
List<PersonsCommonList.PersonListItem> items =
list.getPersonListItem();
// Submit the request to the service and store the response.
PersonAuthorityClient client = new PersonAuthorityClient();
+ ContactsCommonList list = null;
ClientResponse<ContactsCommonList> res =
client.readContactList(parentcsid, itemcsid);
- ContactsCommonList list = res.getEntity();
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
+ try {
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ list = res.getEntity();
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-
+
List<ContactsCommonList.ContactListItem> listitems =
list.getContactListItem();
int nItemsReturned = listitems.size();
// Retrieve the contents of a resource to update.
PersonAuthorityClient client = new PersonAuthorityClient();
- ClientResponse<MultipartInput> res =
- client.read(knownResourceId);
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": read status = " + res.getStatus());
- }
- Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
-
- if(logger.isDebugEnabled()){
- logger.debug("got PersonAuthority to update with ID: " + knownResourceId);
+ MultipartInput input = null;
+ ClientResponse<MultipartInput> res = client.read(knownResourceId);
+ try {
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": read status = " + res.getStatus());
+ }
+ Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
+
+ if(logger.isDebugEnabled()){
+ logger.debug("got PersonAuthority to update with ID: " + knownResourceId);
+ }
+ input = res.getEntity();
+ } finally {
+ res.releaseConnection();
}
- MultipartInput input = (MultipartInput) res.getEntity();
+
PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
client.getCommonPartName(), PersonauthoritiesCommon.class);
Assert.assertNotNull(personAuthority);
OutputPart commonPart = output.addPart(personAuthority, MediaType.APPLICATION_XML_TYPE);
commonPart.getHeaders().add("label", client.getCommonPartName());
res = client.update(knownResourceId, output);
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
+ try {
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ // Retrieve the updated resource and verify that its contents exist.
+ input = (MultipartInput) res.getEntity();
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-
- // Retrieve the updated resource and verify that its contents exist.
- input = (MultipartInput) res.getEntity();
+
PersonauthoritiesCommon updatedPersonAuthority =
(PersonauthoritiesCommon) extractPart(input,
client.getCommonPartName(), PersonauthoritiesCommon.class);
// Retrieve the contents of a resource to update.
PersonAuthorityClient client = new PersonAuthorityClient();
+ MultipartInput input = null;
ClientResponse<MultipartInput> res =
client.readItem(knownResourceId, knownItemResourceId);
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": read status = " + res.getStatus());
- }
- Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
-
- if(logger.isDebugEnabled()){
- logger.debug("got Person to update with ID: " +
- knownItemResourceId +
- " in PersonAuthority: " + knownResourceId );
+ try {
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": read status = " + res.getStatus());
+ }
+ Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
+
+ if(logger.isDebugEnabled()){
+ logger.debug("got Person to update with ID: " +
+ knownItemResourceId +
+ " in PersonAuthority: " + knownResourceId );
+ }
+ input = res.getEntity();
+ } finally {
+ res.releaseConnection();
}
- MultipartInput input = (MultipartInput) res.getEntity();
+
PersonsCommon person = (PersonsCommon) extractPart(input,
client.getItemCommonPartName(), PersonsCommon.class);
Assert.assertNotNull(person);
OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
commonPart.getHeaders().add("label", client.getItemCommonPartName());
res = client.updateItem(knownResourceId, knownItemResourceId, output);
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
+ try {
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ // Retrieve the updated resource and verify that its contents exist.
+ input = (MultipartInput) res.getEntity();
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-
- // Retrieve the updated resource and verify that its contents exist.
- input = (MultipartInput) res.getEntity();
+
PersonsCommon updatedPerson =
(PersonsCommon) extractPart(input,
client.getItemCommonPartName(), PersonsCommon.class);
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
groups = {"update"}, dependsOnMethods = {"updateItem"})
public void updateContact(String testName) throws Exception {
-
// Perform setup.
setupUpdate(testName);
// Retrieve the contents of a resource to update.
PersonAuthorityClient client = new PersonAuthorityClient();
+ MultipartInput input = null;
ClientResponse<MultipartInput> res =
client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": read status = " + res.getStatus());
- }
- Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
-
- if(logger.isDebugEnabled()){
- logger.debug("got Contact to update with ID: " +
- knownContactResourceId +
- " in item: " + knownItemResourceId +
- " in parent: " + knownResourceId );
+ try {
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": read status = " + res.getStatus());
+ }
+ Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
+
+ if(logger.isDebugEnabled()){
+ logger.debug("got Contact to update with ID: " +
+ knownContactResourceId +
+ " in item: " + knownItemResourceId +
+ " in parent: " + knownResourceId );
+ }
+ input = res.getEntity();
+ } finally {
+ res.releaseConnection();
}
- MultipartInput input = (MultipartInput) res.getEntity();
+
ContactsCommon contact = (ContactsCommon) extractPart(input,
new ContactClient().getCommonPartName(), ContactsCommon.class);
Assert.assertNotNull(contact);
OutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE);
commonPart.getHeaders().add("label", new ContactClient().getCommonPartName());
res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
+ try {
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ // Retrieve the updated resource and verify that its contents exist.
+ input = (MultipartInput) res.getEntity();
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-
- // Retrieve the updated resource and verify that its contents exist.
- input = (MultipartInput) res.getEntity();
ContactsCommon updatedContact =
(ContactsCommon) extractPart(input,
new ContactClient().getCommonPartName(), ContactsCommon.class);
*/
@Override
public void updateWithEmptyEntityBody(String testName) throws Exception {
+ //Should this really be empty?
}
/* (non-Javadoc)
*/
@Override
public void updateWithMalformedXml(String testName) throws Exception {
+ //Should this really be empty?
}
/* (non-Javadoc)
*/
@Override
public void updateWithWrongXmlSchema(String testName) throws Exception {
+ //Should this really be empty?
}
/*
displayName, fullRefName, client.getCommonPartName());
ClientResponse<MultipartInput> res =
client.update(NON_EXISTENT_ID, multipart);
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
+ try {
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
}
/**
client.getItemCommonPartName() );
ClientResponse<MultipartInput> res =
client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
+ try {
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ } finally {
+ res.releaseConnection();
}
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
}
/**
ClientResponse<Response> res =
client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
int statusCode = res.getStatus();
+ res.releaseConnection();
// Check the status code of the response: does it match
// the expected response(s)?
PersonAuthorityClient client = new PersonAuthorityClient();
ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
int statusCode = res.getStatus();
+ res.releaseConnection();
// Check the status code of the response: does it match
// the expected response(s)?
PersonAuthorityClient client = new PersonAuthorityClient();
ClientResponse<Response> res = client.delete(knownResourceId);
int statusCode = res.getStatus();
+ res.releaseConnection();
// Check the status code of the response: does it match
// the expected response(s)?
PersonAuthorityClient client = new PersonAuthorityClient();
ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
int statusCode = res.getStatus();
+ res.releaseConnection();
// Check the status code of the response: does it match
// the expected response(s)?
PersonAuthorityClient client = new PersonAuthorityClient();
ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
int statusCode = res.getStatus();
+ res.releaseConnection();
// Check the status code of the response: does it match
// the expected response(s)?
ClientResponse<Response> res =
client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
int statusCode = res.getStatus();
+ res.releaseConnection();
// Check the status code of the response: does it match
// the expected response(s)?
*/
@AfterClass(alwaysRun=true)
+ @Override
public void cleanUp() {
String noTest = System.getProperty("noTestCleanup");
if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
// below are ignored and not reported.
ClientResponse<Response> res =
client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
+ res.releaseConnection();
}
// Clean up item resources.
for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
// below are ignored and not reported.
ClientResponse<Response> res =
client.deleteItem(parentResourceId, itemResourceId);
+ res.releaseConnection();
}
// Clean up parent resources.
- for (String resourceId : allResourceIdsCreated) {
- // Note: Any non-success responses from the delete operation
- // below are ignored and not reported.
- ClientResponse<Response> res = client.delete(resourceId);
- }
+ super.cleanUp();
}
// ---------------------------------------------------------------
<dependency>\r
<groupId>org.slf4j</groupId>\r
<artifactId>slf4j-api</artifactId>\r
- <version>1.5.2</version>\r
</dependency>\r
- <!-- <dependency>\r
+ <dependency>\r
<groupId>org.slf4j</groupId>\r
<artifactId>slf4j-log4j12</artifactId>\r
- <version>1.5.2</version>\r
- </dependency> -->\r
- <!-- CollectionSpace Dependencies -->\r
+ </dependency>\r
<dependency>\r
<groupId>org.collectionspace.services</groupId>\r
<artifactId>org.collectionspace.services.person.jaxb</artifactId>\r
import org.collectionspace.services.common.ClientType;
import org.collectionspace.services.common.ServiceMain;
import org.collectionspace.services.common.authorityref.AuthorityRefDocList;
-import org.collectionspace.services.common.authorityref.AuthorityRefList;
-import org.collectionspace.services.common.context.MultipartServiceContext;
+//import org.collectionspace.services.common.authorityref.AuthorityRefList;
+//import org.collectionspace.services.common.context.MultipartServiceContext;
import org.collectionspace.services.common.context.MultipartServiceContextFactory;
-import org.collectionspace.services.common.context.MultipartServiceContextImpl;
+//import org.collectionspace.services.common.context.MultipartServiceContextImpl;
import org.collectionspace.services.common.context.ServiceBindingUtils;
import org.collectionspace.services.common.context.ServiceContext;
import org.collectionspace.services.common.document.BadRequestException;
-import org.collectionspace.services.common.document.DocumentException;
+//import org.collectionspace.services.common.document.DocumentException;
import org.collectionspace.services.common.document.DocumentFilter;
import org.collectionspace.services.common.document.DocumentHandler;
import org.collectionspace.services.common.document.DocumentNotFoundException;
import org.collectionspace.services.common.repository.RepositoryClient;
import org.collectionspace.services.common.security.UnauthorizedException;
import org.collectionspace.services.common.vocabulary.RefNameServiceUtils;
-import org.collectionspace.services.common.vocabulary.RefNameUtils;
+//import org.collectionspace.services.common.vocabulary.RefNameUtils;
import org.collectionspace.services.common.query.IQueryManager;
import org.collectionspace.services.contact.ContactResource;
import org.collectionspace.services.contact.ContactsCommon;
import org.collectionspace.services.contact.ContactsCommonList;
import org.collectionspace.services.contact.ContactJAXBSchema;
import org.collectionspace.services.contact.nuxeo.ContactDocumentModelHandler;
-import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
+//import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
import org.collectionspace.services.person.nuxeo.PersonDocumentModelHandler;
import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
@GET
@Path("urn:cspace:name({specifier})")
public MultipartOutput getPersonAuthorityByName(@PathParam("specifier") String specifier) {
- String idValue = null;
+//REM: String idValue = null;
if (specifier == null) {
logger.error("getPersonAuthority: missing name!");
Response response = Response.status(Response.Status.BAD_REQUEST).entity(
* can be passed as a query param "type", and must match a configured type
* for the service bindings. If not set, the type defaults to
* ServiceBindingUtils.SERVICE_TYPE_PROCEDURE.
+ * @param parentcsid
*
* @param csid the parent csid
* @param itemcsid the person csid
*/
@GET
@Path("{csid}/items/{itemcsid}/refObjs")
- @Produces("application/xml")
+ @Produces("application/xml") //FIXME: REM do this for CSPACE-1079 in Org authority.
public AuthorityRefDocList getReferencingObjects(
@PathParam("csid") String parentcsid,
@PathParam("itemcsid") String itemcsid,
}
try {
// Note that we have to create the service context for the Items, not the main service
- ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(getItemServiceName());
+ ServiceContext<MultipartInput, MultipartOutput> ctx = MultipartServiceContextFactory.get().createServiceContext(getItemServiceName());
DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
RepositoryClient repoClient = getRepositoryClient(ctx);
DocumentFilter myFilter = handler.createDocumentFilter();
public PersonauthoritiesCommonList getPersonAuthorityList(@Context UriInfo ui) {
PersonauthoritiesCommonList personAuthorityObjectList = new PersonauthoritiesCommonList();
try {
- ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
+ ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);
DocumentHandler handler = createDocumentHandler(ctx);
- DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter();
- myFilter.setPagination(queryParams); //FIXME
+//REM: DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter();
+//REM: myFilter.setPagination(queryParams); //FIXME
String nameQ = queryParams.getFirst("refName");
if (nameQ != null) {
- myFilter.setWhereClause("personauthorities_common:refName='" + nameQ + "'");
+ handler.getDocumentFilter().setWhereClause("personauthorities_common:refName='" + nameQ + "'");
}
- handler.setDocumentFilter(myFilter);
+//REM: handler.setDocumentFilter(myFilter);
getRepositoryClient(ctx).getFiltered(ctx, handler);
personAuthorityObjectList = (PersonauthoritiesCommonList) handler.getCommonPartList();
} catch (UnauthorizedException ue) {
}
- /*************************************************************************
+ /**
+ * ***********************************************************************
* Person parts - this is a sub-resource of PersonAuthority
- *************************************************************************/
+ * ***********************************************************************.
+ *
+ * @param parentcsid the parentcsid
+ * @param input the input
+ * @return the response
+ */
@POST
@Path("{csid}/items")
public Response createPerson(@PathParam("csid") String parentcsid, MultipartInput input) {
ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName(),
queryParams);
DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
- DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter();
- myFilter.setPagination(queryParams); //FIXME (this is unnecessary since it is already set by "createContactDocumentHandler" method
+//REM: DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter();
+//REM: myFilter.setPagination(queryParams); //FIXME (this is unnecessary since it is already set by "createContactDocumentHandler" method
// Add the where clause "persons_common:inAuthority='" + parentcsid + "'"
- myFilter.setWhereClause(PersonJAXBSchema.PERSONS_COMMON + ":" +
+ handler.getDocumentFilter().setWhereClause(PersonJAXBSchema.PERSONS_COMMON + ":" +
PersonJAXBSchema.IN_AUTHORITY + "='" + parentcsid + "'");
// AND persons_common:displayName LIKE '%partialTerm%'
PersonJAXBSchema.DISPLAY_NAME +
" LIKE " +
"'%" + partialTerm + "%'";
- myFilter.appendWhereClause(ptClause);
- }
-
- handler.setDocumentFilter(myFilter);
+ handler.getDocumentFilter().appendWhereClause(ptClause);
+ }
+//REM: handler.setDocumentFilter(myFilter);
getRepositoryClient(ctx).getFiltered(ctx, handler);
personObjectList = (PersonsCommonList) handler.getCommonPartList();
} catch (UnauthorizedException ue) {
ctx = createServiceContext(getItemServiceName(), queryParams);
DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
- DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter();
- myFilter.setPagination(queryParams); //FIXME
+//REM: DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter();
+//REM: myFilter.setPagination(queryParams); //FIXME
// Add the where clause "persons_common:inAuthority='" + parentcsid + "'"
- myFilter.setWhereClause(PersonJAXBSchema.PERSONS_COMMON + ":" +
+ handler.createDocumentFilter().setWhereClause(PersonJAXBSchema.PERSONS_COMMON + ":" +
PersonJAXBSchema.IN_AUTHORITY + "='" + parentcsid + "'");
// AND persons_common:displayName LIKE '%partialTerm%'
PersonJAXBSchema.DISPLAY_NAME +
" LIKE " +
"'%" + partialTerm + "%'";
- myFilter.appendWhereClause(ptClause);
+ handler.createDocumentFilter().appendWhereClause(ptClause);
}
- handler.setDocumentFilter(myFilter);
+//REM: handler.setDocumentFilter(myFilter);
getRepositoryClient(ctx).getFiltered(ctx, handler);
personObjectList = (PersonsCommonList) handler.getCommonPartList();
} catch (UnauthorizedException ue) {
}
- /*************************************************************************
+ /**
+ * ***********************************************************************
* Contact parts - this is a sub-resource of Person (or "item")
- *************************************************************************/
+ * ***********************************************************************.
+ *
+ * @param parentcsid the parentcsid
+ * @param itemcsid the itemcsid
+ * @param input the input
+ * @return the response
+ */
@POST
@Path("{parentcsid}/items/{itemcsid}/contacts")
public Response createContact(
ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getContactServiceName(),
queryParams);
DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid);
- DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter();
- myFilter.setPagination(queryParams); //FIXME (this is unnecessary since it is already set by "createContactDocumentHandler" method
- myFilter.setWhereClause(ContactJAXBSchema.CONTACTS_COMMON + ":" +
+//REM: DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter();
+//REM: myFilter.setPagination(queryParams); //FIXME (this is unnecessary since it is already set by "createContactDocumentHandler" method
+ handler.createDocumentFilter().setWhereClause(ContactJAXBSchema.CONTACTS_COMMON + ":" +
ContactJAXBSchema.IN_AUTHORITY +
"='" + parentcsid + "'" +
" AND " +
ContactJAXBSchema.IN_ITEM +
"='" + itemcsid + "'" +
" AND ecm:isProxy = 0");
- handler.setDocumentFilter(myFilter);
+//REM: handler.setDocumentFilter(myFilter);
getRepositoryClient(ctx).getFiltered(ctx, handler);
contactObjectList = (ContactsCommonList) handler.getCommonPartList();
} catch (UnauthorizedException ue) {
<parent>\r
<artifactId>org.collectionspace.services.main</artifactId>\r
<groupId>org.collectionspace.services</groupId>\r
- <version>1.0</version>\r
+ <version>0.7-SNAPSHOT</version>\r
</parent>\r
+ \r
<modelVersion>4.0.0</modelVersion>\r
<groupId>org.collectionspace.services</groupId>\r
- <version>1.0</version>\r
<artifactId>org.collectionspace.services.query</artifactId>\r
- <packaging>pom</packaging>\r
<name>services.query</name>\r
+ <packaging>pom</packaging>\r
\r
<modules>\r
<module>service</module>\r
<?xml version="1.0" encoding="UTF-8"?>\r
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">\r
-\r
+<project xmlns="http://maven.apache.org/POM/4.0.0"\r
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">\r
<parent>\r
- <artifactId>org.collectionspace.services.query</artifactId>\r
<groupId>org.collectionspace.services</groupId>\r
- <version>1.0</version>\r
+ <artifactId>org.collectionspace.services.query</artifactId>\r
+ <version>0.7-SNAPSHOT</version>\r
</parent>\r
\r
<modelVersion>4.0.0</modelVersion>\r
<groupId>org.collectionspace.services</groupId>\r
<artifactId>org.collectionspace.services.query.service</artifactId>\r
- <packaging>jar</packaging>\r
- <version>1.0</version>\r
<name>services.query.service</name>\r
\r
<dependencies>\r
- <dependency>\r
- <groupId>org.collectionspace.services</groupId>\r
- <artifactId>org.collectionspace.services.common</artifactId>\r
- <version>1.0</version>\r
- </dependency>\r
<dependency>\r
<groupId>org.slf4j</groupId>\r
<artifactId>slf4j-api</artifactId>\r
<artifactId>slf4j-log4j12</artifactId>\r
</dependency>\r
<dependency>\r
- <groupId>junit</groupId>\r
- <artifactId>junit</artifactId>\r
- <version>4.1</version>\r
- <scope>test</scope>\r
+ <groupId>org.collectionspace.services</groupId>\r
+ <artifactId>org.collectionspace.services.common</artifactId>\r
+ <version>1.0</version>\r
</dependency>\r
<dependency>\r
<groupId>org.testng</groupId>\r
<artifactId>commons-logging</artifactId>\r
<version>1.1</version>\r
</dependency>\r
- <!-- javax -->\r
\r
+ <!-- javax -->\r
\r
- <dependency>\r
+<!-- <dependency>\r
<groupId>javax.security</groupId>\r
<artifactId>jaas</artifactId>\r
- <version>1.0.01</version>\r
<scope>provided</scope>\r
</dependency>\r
-\r
<dependency>\r
<groupId>dom4j</groupId>\r
<artifactId>dom4j</artifactId>\r
- <version>1.6.1</version>\r
<scope>provided</scope>\r
- </dependency>\r
+ </dependency> -->\r
\r
<!-- jboss -->\r
\r
+ <dependency>\r
+ <groupId>org.jboss.resteasy</groupId>\r
+ <artifactId>jaxrs-api</artifactId>\r
+ </dependency>\r
<dependency>\r
<groupId>org.jboss.resteasy</groupId>\r
<artifactId>resteasy-jaxrs</artifactId>\r
<groupId>org.jboss.resteasy</groupId>\r
<artifactId>resteasy-multipart-provider</artifactId>\r
</dependency>\r
- \r
- <!-- nuxeo -->\r
-\r
- <dependency>\r
- <groupId>org.nuxeo.ecm.core</groupId>\r
- <artifactId>nuxeo-core-api</artifactId>\r
- <version>${nuxeo.version.1.5}</version>\r
- <exclusions>\r
- <exclusion>\r
- <artifactId>jboss-remoting</artifactId>\r
- <groupId>jboss</groupId>\r
- </exclusion>\r
- </exclusions>\r
- </dependency>\r
-\r
- <dependency>\r
- <groupId>org.restlet</groupId>\r
- <artifactId>org.restlet</artifactId>\r
- <version>1.0.7</version>\r
- </dependency>\r
- <dependency>\r
- <groupId>com.noelios.restlet</groupId>\r
- <artifactId>com.noelios.restlet.ext.httpclient</artifactId>\r
- <version>1.0.7</version>\r
- </dependency>\r
- <dependency>\r
- <groupId>com.noelios.restlet</groupId>\r
- <artifactId>com.noelios.restlet</artifactId>\r
- <version>1.0.7</version>\r
- </dependency>\r
-\r
</dependencies>\r
\r
<build>\r
import javax.ws.rs.core.Response;\r
import javax.ws.rs.core.UriBuilder;\r
import javax.ws.rs.core.UriInfo;\r
-import javax.xml.bind.JAXBContext;\r
-import javax.xml.bind.Marshaller;\r
+//import javax.xml.bind.JAXBContext;\r
+//import javax.xml.bind.Marshaller;\r
\r
import org.collectionspace.services.common.query.QueryManager;\r
//import org.collectionspace.services.common.NuxeoClientType;\r