import org.collectionspace.services.jaxb.AbstractCommonList;
import org.collectionspace.services.client.CollectionSpaceClient;
-//import org.collectionspace.services.client.AbstractServiceClientImpl;
import org.jboss.resteasy.client.ClientResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
*/
public abstract class AbstractServiceTestImpl extends BaseServiceTest implements ServiceTest {
- /** The logger. */
- protected final Logger logger = LoggerFactory.getLogger(AbstractServiceTestImpl.class);
-
- /** 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)
-// * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
-// */
-// @Override
-// public void create(String testName) throws Exception {
-// //empty?
-// }
+ /** The logger. */
+ protected final Logger logger = LoggerFactory.getLogger(AbstractServiceTestImpl.class);
+
+ /** 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>();
/**
* Gets the logger.
return this.logger;
}
+ // ---------------------------------------------------------------
+ // CRUD tests : CREATE tests
+ //
+ // (See below for utility methods in support of create list tests.)
+ // ---------------------------------------------------------------
+
+ // Success outcomes
+
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
+ */
+ @Override
+ public abstract void create(String testName) throws Exception;
+
/**
- * Setup create.
+ * Sets up create tests.
*/
protected void setupCreate() {
setupCreate("Create");
}
/**
- * Sets the up create.
+ * Sets up create tests.
*
- * @param label the new up create
+ * @param label A label to be displayed prior to running this test.
*/
protected void setupCreate(String label) {
- testSetup(Response.Status.CREATED.getStatusCode(), ServiceRequestType.CREATE, label);
+ EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode();
+ REQUEST_TYPE = ServiceRequestType.CREATE;
+ testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, label);
}
/* (non-Javadoc)
@Override
public abstract void createList(String testName) throws Exception;
- // No setup required for createList()
+ // Note: No setup is required for createList(), as it currently
+ // just invokes create() multiple times.
+
// Failure outcomes
+
/* (non-Javadoc)
* @see org.collectionspace.services.client.test.ServiceTest#createWithEmptyEntityBody(java.lang.String)
*/
throws Exception;
/**
- * Setup create with empty entity body.
+ * Sets up create tests with empty entity body.
*/
protected void setupCreateWithEmptyEntityBody() {
setupCreateWithEmptyEntityBody("CreateWithEmptyEntityBody");
}
/**
- * Sets the up create with empty entity body.
+ * Sets up create tests with empty entity body.
*
- * @param label the new up create with empty entity body
+ * @param label A label to be displayed prior to running this test.
*/
protected void setupCreateWithEmptyEntityBody(String label) {
- clearSetup();
EXPECTED_STATUS_CODE = Response.Status.BAD_REQUEST.getStatusCode();
REQUEST_TYPE = ServiceRequestType.CREATE;
- if (logger.isDebugEnabled()) {
- banner(label);
- }
+ testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, label);
}
/* (non-Javadoc)
public abstract void createWithMalformedXml(String testName) throws Exception;
/**
- * Setup create with malformed xml.
+ * Sets up create tests with malformed xml.
*/
protected void setupCreateWithMalformedXml() {
setupCreateWithMalformedXml("CreateWithMalformedXml");
}
/**
- * Sets the up create with malformed xml.
+ * Sets up create tests with malformed xml.
*
- * @param label the new up create with malformed xml
+ * @param label A label to be displayed prior to running this test.
*/
protected void setupCreateWithMalformedXml(String label) {
- clearSetup();
- // Expected status code: 400 Bad Request
EXPECTED_STATUS_CODE = Response.Status.BAD_REQUEST.getStatusCode();
REQUEST_TYPE = ServiceRequestType.CREATE;
- if (logger.isDebugEnabled()) {
- banner(label);
- }
+ testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, label);
}
/* (non-Javadoc)
public abstract void createWithWrongXmlSchema(String testName) throws Exception;
/**
- * Setup create with wrong xml schema.
+ * Sets up create tests with wrong xml schema.
*/
protected void setupCreateWithWrongXmlSchema() {
setupCreateWithWrongXmlSchema("CreateWithWrongXmlSchema");
}
/**
- * Sets the up create with wrong xml schema.
+ * Sets up create tests with wrong xml schema.
*
* @param label the new up create with wrong xml schema
*/
protected void setupCreateWithWrongXmlSchema(String label) {
- clearSetup();
- // Expected status code: 400 Bad Request
EXPECTED_STATUS_CODE = Response.Status.BAD_REQUEST.getStatusCode();
REQUEST_TYPE = ServiceRequestType.CREATE;
- if (logger.isDebugEnabled()) {
- banner(label);
- }
+ testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, label);
}
// ---------------------------------------------------------------
// CRUD tests : READ tests
// ---------------------------------------------------------------
+
// Success outcomes
+
/* (non-Javadoc)
* @see org.collectionspace.services.client.test.ServiceTest#read(java.lang.String)
*/
public abstract void read(String testName) throws Exception;
/**
- * Setup read.
+ * Sets up read tests.
*/
protected void setupRead() {
setupRead("Read");
}
/**
- * Sets the up read.
+ * Sets up read tests.
*
- * @param label the new up read
+ * @param label A label to be displayed prior to running this test.
*/
protected void setupRead(String label) {
- testSetup(Response.Status.OK.getStatusCode(), ServiceRequestType.READ, label);
+ EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode();
+ REQUEST_TYPE = ServiceRequestType.READ;
+ testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, label);
}
// Failure outcomes
+
/* (non-Javadoc)
* @see org.collectionspace.services.client.test.ServiceTest#readNonExistent(java.lang.String)
*/
public abstract void readNonExistent(String testName) throws Exception;
/**
- * Setup read non existent.
+ * Sets up read non existent tests.
*/
protected void setupReadNonExistent() {
setupReadNonExistent("ReadNonExistent");
}
/**
- * Sets the up read non existent.
+ * Sets up read non existent tests.
*
- * @param label the new up read non existent
+ * @param label A label to be displayed prior to running this test.
*/
protected void setupReadNonExistent(String label) {
- // Expected status code: 404 Not Found
- testSetup(Response.Status.NOT_FOUND.getStatusCode(), ServiceRequestType.READ, label);
- }
-
- /**
- * Read list.
- *
- * @param testName the test name
- * @param client the client
- * @param pageSize the page size
- * @param pageNumber the page number
- * @return the abstract common list
- * @throws Exception the exception
- */
- private AbstractCommonList readList(String testName,
- CollectionSpaceClient client,
- long pageSize, long pageNumber) throws Exception {
- ClientResponse<AbstractCommonList> response =
- 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();
- }
-
- return result;
- }
-
- /**
- * Creates the list.
- *
- * @param testName the test name
- * @param listSize the list size
- * @throws Exception the exception
- */
- protected void createPaginatedList(String testName, int listSize) throws Exception {
- for (int i = 0; i < listSize; i++) {
- create(testName);
- }
- }
-
- /*@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
- public void leafCeate(String testName) throws Exception {
- this.create(testName);
- }*/
-
- private void assertPaginationInfo(String testName,
- AbstractCommonList list,
- long expectedPageNum,
- long expectedPageSize,
- long expectedListSize,
- long expectedTotalItems) {
- Assert.assertNotNull(list);
-
- long pageNum = list.getPageNum();
- Assert.assertEquals(pageNum, expectedPageNum);
- if (getLogger().isDebugEnabled() == true) {
- getLogger().debug(testName + ":" + "page number is " + pageNum);
- }
-
- long pageSizeReturned = list.getPageSize();
- Assert.assertEquals(pageSizeReturned, expectedPageSize);
- if (getLogger().isDebugEnabled() == true) {
- getLogger().debug(testName + ":" + "page size is " + list.getPageSize());
- }
-
- long itemsInPage = list.getItemsInPage();
- Assert.assertEquals(itemsInPage, expectedListSize);
- if (getLogger().isDebugEnabled() == true) {
- getLogger().debug(testName + ":" + "actual items in page was/were " + itemsInPage);
- }
-
- long totalItemsReturned = list.getTotalItems();
- Assert.assertEquals(totalItemsReturned, expectedTotalItems);
- if (getLogger().isDebugEnabled() == true) {
- getLogger().debug(testName + ":" + "total number of items is " + list.getTotalItems());
- }
- }
-
- /**
- * Read paginated list.
- *
- * @param testName the test name
- * @throws Exception the exception
- */
- @Test(dataProvider = "testName") /*, dataProviderClass = AbstractServiceTestImpl.class,
- dependsOnMethods = {"leafCeate"}) */
- public void readPaginatedList(String testName) throws Exception {
- // Perform setup.
- setupReadList(testName);
- CollectionSpaceClient client = this.getClientInstance();
-
- // Get the current total number of items.
- // If there are no items then create some
- AbstractCommonList list = (AbstractCommonList) this.readList(testName, client, 1 /*pgSz*/, 0 /*pgNum*/);
- if (list == null || list.getTotalItems() == 0) {
- this.createPaginatedList(testName, DEFAULT_PAGINATEDLIST_SIZE);
- list = (AbstractCommonList) this.readList(testName, client, 1 /*pgSz*/, 0 /*pgNum*/);
- }
-
- // Print out the current list size to be paginated
- Assert.assertNotNull(list);
- long totalItems = list.getTotalItems();
- Assert.assertFalse(totalItems == 0);
- if (getLogger().isDebugEnabled() == true) {
- getLogger().debug(testName + ":" + "created list of " +
- totalItems + " 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 = (AbstractCommonList) this.readList(testName, client, pageSize, i);
- assertPaginationInfo(testName,
- list,
- i, //expected page number
- pageSize, //expected page size
- pageSize, //expected num of items in page
- totalItems);//expected total num of items
- }
-
- // if there are any remainders be sure to paginate them as well
- long mod = pageSize != 0 ? totalItems % pageSize : totalItems;
- if (mod != 0) {
- list = (AbstractCommonList) this.readList(testName, client, pageSize, pagesTotal);
- assertPaginationInfo(testName,
- list,
- pagesTotal, //expected page number
- pageSize, //expected page size
- mod, //expected num of items in page
- totalItems);//expected total num of items
- }
+ EXPECTED_STATUS_CODE = Response.Status.NOT_FOUND.getStatusCode();
+ REQUEST_TYPE = ServiceRequestType.READ;
+ testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, label);
}
- // ---------------------------------------------------------------
+ // ---------------------------------------------------------------
// CRUD tests : READ (list, or multiple) tests
+ //
+ // (See below for utility methods in support of list tests.)
// ---------------------------------------------------------------
+
// Success outcomes
+
/* (non-Javadoc)
* @see org.collectionspace.services.client.test.ServiceTest#readList(java.lang.String)
*/
- @Override
+ @Override
public abstract void readList(String testName) throws Exception;
/**
- * Setup read list.
+ * Sets up read list tests.
*/
protected void setupReadList() {
setupReadList("ReadList");
}
/**
- * Sets the up read list.
+ * Sets up read list tests.
*
- * @param label the new up read list
+ * @param label A label to be displayed prior to running this test.
*/
protected void setupReadList(String label) {
- testSetup(Response.Status.OK.getStatusCode(), ServiceRequestType.READ_LIST, label);
+ EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode();
+ REQUEST_TYPE = ServiceRequestType.READ_LIST;
+ testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, label);
}
// Failure outcomes
+
// None tested at present.
+
// ---------------------------------------------------------------
// CRUD tests : UPDATE tests
// ---------------------------------------------------------------
+
// Success outcomes
+
/* (non-Javadoc)
* @see org.collectionspace.services.client.test.ServiceTest#update(java.lang.String)
*/
public abstract void update(String testName) throws Exception;
/**
- * Setup update.
+ * Sets up update tests.
*/
protected void setupUpdate() {
setupUpdate("Update");
}
/**
- * Sets the up update.
+ * Sets up update tests.
*
- * @param label the new up update
+ * @param label A label to be displayed prior to running this test.
*/
protected void setupUpdate(String label) {
- // Expected status code: 200 OK
- testSetup(Response.Status.OK.getStatusCode(), ServiceRequestType.UPDATE, label);
+ EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode();
+ REQUEST_TYPE = ServiceRequestType.UPDATE;
+ testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, label);
}
// Failure outcomes
+
/* (non-Javadoc)
* @see org.collectionspace.services.client.test.ServiceTest#updateWithEmptyEntityBody(java.lang.String)
*/
public abstract void updateWithEmptyEntityBody(String testName) throws Exception;
/**
- * Setup update with empty entity body.
+ * Sets up update tests with an empty entity body.
*/
protected void setupUpdateWithEmptyEntityBody() {
setupUpdateWithEmptyEntityBody("UpdateWithEmptyEntityBody");
}
/**
- * Sets the up update with empty entity body.
+ * Sets up update tests with an empty entity body.
*
- * @param label the new up update with empty entity body
+ * @param label A label to be displayed prior to running this test.
*/
protected void setupUpdateWithEmptyEntityBody(String label) {
- // Expected status code: 400 Bad Request
- testSetup(Response.Status.BAD_REQUEST.getStatusCode(), ServiceRequestType.UPDATE, label);
+ EXPECTED_STATUS_CODE = Response.Status.BAD_REQUEST.getStatusCode();
+ REQUEST_TYPE = ServiceRequestType.UPDATE;
+ testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, label);
}
/* (non-Javadoc)
public abstract void updateWithMalformedXml(String testName) throws Exception;
/**
- * Setup update with malformed xml.
+ * Sets up update tests with malformed xml.
*/
protected void setupUpdateWithMalformedXml() {
setupUpdateWithMalformedXml("UpdateWithMalformedXml");
}
/**
- * Sets the up update with malformed xml.
+ * Sets up update tests with malformed xml.
*
- * @param label the new up update with malformed xml
+ * @param label A label to be displayed prior to running this test.
*/
protected void setupUpdateWithMalformedXml(String label) {
- // Expected status code: 400 Bad Request
- testSetup(Response.Status.BAD_REQUEST.getStatusCode(), ServiceRequestType.UPDATE, label);
+ EXPECTED_STATUS_CODE = Response.Status.BAD_REQUEST.getStatusCode();
+ REQUEST_TYPE = ServiceRequestType.UPDATE;
+ testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, label);
}
/* (non-Javadoc)
public abstract void updateWithWrongXmlSchema(String testName) throws Exception;
/**
- * Setup update with wrong xml schema.
+ * Sets up update tests with wrong xml schema.
*/
protected void setupUpdateWithWrongXmlSchema() {
setupUpdateWithWrongXmlSchema("UpdateWithWrongXmlSchema");
}
/**
- * Sets the up update with wrong xml schema.
+ * Sets up update tests with wrong xml schema.
*
- * @param label the new up update with wrong xml schema
+ * @param label A label to be displayed prior to running this test.
*/
protected void setupUpdateWithWrongXmlSchema(String label) {
- // Expected status code: 400 Bad Request
- testSetup(Response.Status.BAD_REQUEST.getStatusCode(), ServiceRequestType.UPDATE, label);
+ EXPECTED_STATUS_CODE = Response.Status.BAD_REQUEST.getStatusCode();
+ REQUEST_TYPE = ServiceRequestType.UPDATE;
+ testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, 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)
*/
public abstract void updateNonExistent(String testName) throws Exception;
/**
- * Setup update non existent.
+ * Sets up update non existent tests.
*/
protected void setupUpdateNonExistent() {
setupUpdateNonExistent("UpdateNonExistent");
}
/**
- * Sets the up update non existent.
+ * Sets up update non existent tests
*
- * @param label the new up update non existent
+ * @param label A label to be displayed prior to running this test.
*/
protected void setupUpdateNonExistent(String label) {
- // Expected status code: 404 Not Found
- testSetup(Response.Status.NOT_FOUND.getStatusCode(), ServiceRequestType.UPDATE, label);
+ EXPECTED_STATUS_CODE = Response.Status.NOT_FOUND.getStatusCode();
+ REQUEST_TYPE = ServiceRequestType.UPDATE;
+ testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, label);
}
// ---------------------------------------------------------------
// CRUD tests : DELETE tests
// ---------------------------------------------------------------
+
// Success outcomes
+
/* (non-Javadoc)
* @see org.collectionspace.services.client.test.ServiceTest#delete(java.lang.String)
*/
public abstract void delete(String testName) throws Exception;
/**
- * Setup delete.
+ * Sets up delete tests.
*/
protected void setupDelete() {
setupDelete("Delete");
}
/**
- * Sets the up delete.
+ * Sets up delete tests.
*
- * @param label the new up delete
+ * @param label A label to be displayed prior to running this test.
*/
protected void setupDelete(String label) {
- testSetup(Response.Status.OK.getStatusCode(), ServiceRequestType.DELETE, label);
+ EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode();
+ REQUEST_TYPE = ServiceRequestType.DELETE;
+ testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, label);
}
// Failure outcomes
+
/* (non-Javadoc)
* @see org.collectionspace.services.client.test.ServiceTest#deleteNonExistent(java.lang.String)
*/
public abstract void deleteNonExistent(String testName) throws Exception;
/**
- * Setup delete non existent.
+ * Sets up delete non existent tests.
*/
protected void setupDeleteNonExistent() {
setupDeleteNonExistent("DeleteNonExistent");
}
/**
- * Sets the up delete non existent.
+ * Sets up delete non existent tests.
*
- * @param label the new up delete non existent
+ * @param label A label to be displayed prior to running this test.
*/
protected void setupDeleteNonExistent(String label) {
- clearSetup();
- // Expected status code: 404 Not Found
EXPECTED_STATUS_CODE = Response.Status.NOT_FOUND.getStatusCode();
REQUEST_TYPE = ServiceRequestType.DELETE;
+ testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE, label);
+ }
+
+ // ---------------------------------------------------------------
+ // Utility methods to clean up resources created during tests.
+ // ---------------------------------------------------------------
+
+ /**
+ * 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()) {
- banner(label);
+ 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();
}
}
+
+ // ---------------------------------------------------------------
+ // Utility methods in support of list tests.
+ // ---------------------------------------------------------------
+
+ /**
+ * Read list.
+ *
+ * @param testName the test name
+ * @param client the client
+ * @param pageSize the page size
+ * @param pageNumber the page number
+ * @return the abstract common list
+ * @throws Exception the exception
+ */
+ private AbstractCommonList readList(String testName,
+ CollectionSpaceClient client,
+ long pageSize, long pageNumber) throws Exception {
+ ClientResponse<AbstractCommonList> response =
+ 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();
+ }
+
+ return result;
+ }
+
+ /**
+ * Creates the list.
+ *
+ * @param testName the test name
+ * @param listSize the list size
+ * @throws Exception the exception
+ */
+ protected void createPaginatedList(String testName, int listSize) throws Exception {
+ for (int i = 0; i < listSize; i++) {
+ create(testName);
+ }
+ }
+
+ /*@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
+ public void leafCreate(String testName) throws Exception {
+ this.create(testName);
+ }*/
+
+ private void assertPaginationInfo(String testName,
+ AbstractCommonList list,
+ long expectedPageNum,
+ long expectedPageSize,
+ long expectedListSize,
+ long expectedTotalItems) {
+ Assert.assertNotNull(list);
+
+ long pageNum = list.getPageNum();
+ Assert.assertEquals(pageNum, expectedPageNum);
+ if (getLogger().isDebugEnabled() == true) {
+ getLogger().debug(testName + ":" + "page number is " + pageNum);
+ }
+
+ long pageSizeReturned = list.getPageSize();
+ Assert.assertEquals(pageSizeReturned, expectedPageSize);
+ if (getLogger().isDebugEnabled() == true) {
+ getLogger().debug(testName + ":" + "page size is " + list.getPageSize());
+ }
+
+ long itemsInPage = list.getItemsInPage();
+ Assert.assertEquals(itemsInPage, expectedListSize);
+ if (getLogger().isDebugEnabled() == true) {
+ getLogger().debug(testName + ":" + "actual items in page was/were " + itemsInPage);
+ }
+
+ long totalItemsReturned = list.getTotalItems();
+ Assert.assertEquals(totalItemsReturned, expectedTotalItems);
+ if (getLogger().isDebugEnabled() == true) {
+ getLogger().debug(testName + ":" + "total number of items is " + list.getTotalItems());
+ }
+ }
+
+ /**
+ * Read paginated list.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
+ @Test(dataProvider = "testName") /*, dataProviderClass = AbstractServiceTestImpl.class,
+ dependsOnMethods = {"leafCreate"}) */
+ public void readPaginatedList(String testName) throws Exception {
+ // Perform setup.
+ setupReadList(testName);
+ CollectionSpaceClient client = this.getClientInstance();
+
+ // Get the current total number of items.
+ // If there are no items then create some
+ AbstractCommonList list = (AbstractCommonList) this.readList(testName, client, 1 /*pgSz*/, 0 /*pgNum*/);
+ if (list == null || list.getTotalItems() == 0) {
+ this.createPaginatedList(testName, DEFAULT_PAGINATEDLIST_SIZE);
+ list = (AbstractCommonList) this.readList(testName, client, 1 /*pgSz*/, 0 /*pgNum*/);
+ }
+
+ // Print out the current list size to be paginated
+ Assert.assertNotNull(list);
+ long totalItems = list.getTotalItems();
+ Assert.assertFalse(totalItems == 0);
+ if (getLogger().isDebugEnabled() == true) {
+ getLogger().debug(testName + ":" + "created list of " +
+ totalItems + " 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 = (AbstractCommonList) this.readList(testName, client, pageSize, i);
+ assertPaginationInfo(testName,
+ list,
+ i, //expected page number
+ pageSize, //expected page size
+ pageSize, //expected num of items in page
+ totalItems);//expected total num of items
+ }
+
+ // if there are any remainders be sure to paginate them as well
+ long mod = pageSize != 0 ? totalItems % pageSize : totalItems;
+ if (mod != 0) {
+ list = (AbstractCommonList) this.readList(testName, client, pageSize, pagesTotal);
+ assertPaginationInfo(testName,
+ list,
+ pagesTotal, //expected page number
+ pageSize, //expected page size
+ mod, //expected num of items in page
+ totalItems);//expected total num of items
+ }
+ }
+
}