*/
public class ReportServiceTest extends AbstractServiceTestImpl {
- /** The logger. */
+ /** The logger. */
private final String CLASS_NAME = ReportServiceTest.class.getName();
private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
-
final String SERVICE_NAME = "reports";
final String SERVICE_PATH_COMPONENT = "reports";
-
// Instance variables specific to this test.
-
-
/** The known resource id. */
private String knownResourceId = null;
-
+
/* (non-Javadoc)
* @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
*/
@Override
protected CollectionSpaceClient getClientInstance() {
- return new ReportClient();
+ return new ReportClient();
}
-
+
/* (non-Javadoc)
* @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
*/
@Override
- protected AbstractCommonList getAbstractCommonList(
- ClientResponse<AbstractCommonList> response) {
- return response.getEntity(ReportsCommonList.class);
+ protected AbstractCommonList getAbstractCommonList(
+ ClientResponse<AbstractCommonList> response) {
+ return response.getEntity(ReportsCommonList.class);
}
-
+
// ---------------------------------------------------------------
// CRUD tests : CREATE tests
// ---------------------------------------------------------------
* @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
*/
@Override
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
public void create(String testName) throws Exception {
if (logger.isDebugEnabled()) {
// Does it fall within the set of valid status codes?
// Does it exactly match the expected status code?
int statusCode = res.getStatus();
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug(testName + ": status = " + statusCode);
}
Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
// Store the ID returned from the first resource created
// for additional tests below.
- if (knownResourceId == null){
+ if (knownResourceId == null) {
knownResourceId = extractId(res);
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));
* @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
*/
@Override
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- dependsOnMethods = {"create"})
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ dependsOnMethods = {"create"})
public void createList(String testName) throws Exception {
- for(int i = 0; i < 3; i++){
+ for (int i = 0; i < 3; i++) {
create(testName);
}
}
*/
@Override
public void createWithEmptyEntityBody(String testName) throws Exception {
- //Should this really be empty?
+ //Should this really be empty?
}
/* (non-Javadoc)
*/
@Override
public void createWithMalformedXml(String testName) throws Exception {
- //Should this really be empty?
+ //Should this really be empty?
}
/* (non-Javadoc)
*/
@Override
public void createWithWrongXmlSchema(String testName) throws Exception {
- //Should this really be empty?
+ //Should this really be empty?
}
// ---------------------------------------------------------------
* @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
*/
@Override
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- dependsOnMethods = {"create"})
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ dependsOnMethods = {"create"})
public void read(String testName) throws Exception {
if (logger.isDebugEnabled()) {
// Check the status code of the response: does it match
// the expected response(s)?
int statusCode = res.getStatus();
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug(testName + ": status = " + statusCode);
}
Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
ReportsCommon reportCommon = null;
if (payloadInputPart != null) {
- reportCommon = (ReportsCommon) payloadInputPart.getBody();
- }
+ reportCommon = (ReportsCommon) payloadInputPart.getBody();
+ }
Assert.assertNotNull(reportCommon);
+
+ // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
+ if (logger.isDebugEnabled()) {
+ logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n"
+ + "UTF-8 data received=" + reportCommon.getNotes());
+ }
+ Assert.assertEquals(reportCommon.getNotes(), getUTF8DataFragment(),
+ "UTF-8 data retrieved '" + reportCommon.getNotes()
+ + "' does not match expected data '" + getUTF8DataFragment());
}
// Failure outcomes
* @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
*/
@Override
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- dependsOnMethods = {"read"})
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ dependsOnMethods = {"read"})
public void readNonExistent(String testName) throws Exception {
if (logger.isDebugEnabled()) {
// Check the status code of the response: does it match
// the expected response(s)?
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug(testName + ": status = " + statusCode);
}
Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
* @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
*/
@Override
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- dependsOnMethods = {"createList", "read"})
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ dependsOnMethods = {"createList", "read"})
public void readList(String testName) throws Exception {
if (logger.isDebugEnabled()) {
// Check the status code of the response: does it match
// the expected response(s)?
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug(testName + ": status = " + statusCode);
}
Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
// Optionally output additional data about list members for debugging.
boolean iterateThroughList = false;
- if(iterateThroughList && logger.isDebugEnabled()){
+ if (iterateThroughList && logger.isDebugEnabled()) {
List<ReportsCommonList.ReportListItem> items =
list.getReportListItem();
int i = 0;
- for(ReportsCommonList.ReportListItem item : items){
- logger.debug(testName + ": list-item[" + i + "] csid=" +
- item.getCsid());
- logger.debug(testName + ": list-item[" + i + "] name=" +
- item.getName());
- logger.debug(testName + ": list-item[" + i + "] outputMIME=" +
- item.getOutputMIME());
- logger.debug(testName + ": list-item[" + i + "] URI=" +
- item.getUri());
+ for (ReportsCommonList.ReportListItem item : items) {
+ logger.debug(testName + ": list-item[" + i + "] csid="
+ + item.getCsid());
+ logger.debug(testName + ": list-item[" + i + "] name="
+ + item.getName());
+ logger.debug(testName + ": list-item[" + i + "] outputMIME="
+ + item.getOutputMIME());
+ logger.debug(testName + ": list-item[" + i + "] URI="
+ + item.getUri());
i++;
}
}
* @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
*/
@Override
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- dependsOnMethods = {"read"})
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ dependsOnMethods = {"read"})
public void update(String testName) throws Exception {
if (logger.isDebugEnabled()) {
// Retrieve the contents of a resource to update.
ReportClient client = new ReportClient();
ClientResponse<String> res = client.read(knownResourceId);
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug(testName + ": read status = " + res.getStatus());
}
Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug("got object to update with ID: " + knownResourceId);
}
PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
ReportsCommon reportCommon = null;
if (payloadInputPart != null) {
- reportCommon = (ReportsCommon) payloadInputPart.getBody();
+ reportCommon = (ReportsCommon) payloadInputPart.getBody();
}
Assert.assertNotNull(reportCommon);
// Update its content.
reportCommon.setName("updated-" + reportCommon.getName());
reportCommon.setOutputMIME("updated-" + reportCommon.getOutputMIME());
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug("to be updated object");
logger.debug(objectAsXmlString(reportCommon, ReportsCommon.class));
}
-
+ reportCommon.setNotes("updated-" + reportCommon.getNotes());
+
// Submit the updated common part in an update request to the service
// and store the response.
PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
// Check the status code of the response: does it match the expected response(s)?
int statusCode = res.getStatus();
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug(testName + ": status = " + statusCode);
}
Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
payloadInputPart = input.getPart(client.getCommonPartName());
ReportsCommon updatedReportCommon = null;
if (payloadInputPart != null) {
- updatedReportCommon = (ReportsCommon) payloadInputPart.getBody();
+ updatedReportCommon = (ReportsCommon) payloadInputPart.getBody();
}
Assert.assertNotNull(updatedReportCommon);
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug("updated object");
logger.debug(objectAsXmlString(updatedReportCommon, ReportsCommon.class));
}
reportCommon.getName(),
"Data in updated object did not match submitted data.");
+ // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
+ if (logger.isDebugEnabled()) {
+ logger.debug("UTF-8 data sent=" + reportCommon.getNotes() + "\n"
+ + "UTF-8 data received=" + updatedReportCommon.getNotes());
+ }
+ Assert.assertTrue(updatedReportCommon.getNotes().contains(getUTF8DataFragment()),
+ "UTF-8 data retrieved '" + updatedReportCommon.getNotes()
+ + "' does not contain expected data '" + getUTF8DataFragment());
+ Assert.assertEquals(updatedReportCommon.getNotes(),
+ reportCommon.getNotes(),
+ "Data in updated object did not match submitted data.");
}
// Failure outcomes
*/
@Override
public void updateWithEmptyEntityBody(String testName) throws Exception {
- //Should this really be empty?
+ //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?
+ //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?
+ //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"})
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ dependsOnMethods = {"update", "testSubmitRequest"})
public void updateNonExistent(String testName) throws Exception {
if (logger.isDebugEnabled()) {
// Check the status code of the response: does it match
// the expected response(s)?
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug(testName + ": status = " + statusCode);
}
Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
* @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
*/
@Override
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
public void delete(String testName) throws Exception {
if (logger.isDebugEnabled()) {
// Check the status code of the response: does it match
// the expected response(s)?
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug(testName + ": status = " + statusCode);
}
Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
* @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
*/
@Override
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- dependsOnMethods = {"delete"})
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ dependsOnMethods = {"delete"})
public void deleteNonExistent(String testName) throws Exception {
if (logger.isDebugEnabled()) {
// Check the status code of the response: does it match
// the expected response(s)?
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug(testName + ": status = " + statusCode);
}
Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
// ---------------------------------------------------------------
// Utility tests : tests of code used in tests above
// ---------------------------------------------------------------
-
/**
* Tests the code for manually submitting data that is used by several
* of the methods above.
// Check the status code of the response: does it match
// the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug("testSubmitRequest: url=" + url +
- " status=" + statusCode);
+ if (logger.isDebugEnabled()) {
+ logger.debug("testSubmitRequest: url=" + url
+ + " status=" + statusCode);
}
Assert.assertEquals(statusCode, EXPECTED_STATUS);
// ---------------------------------------------------------------
// Utility methods used by tests above
// ---------------------------------------------------------------
-
-
@Override
protected String getServiceName() {
return SERVICE_NAME;
return createReportInstance(
"name-" + identifier,
"persAuthTermCountsTest.jasper",
- "application/pdf" );
+ "application/pdf");
}
/**
* @return the multipart output
*/
private PoxPayloadOut createReportInstance(String name,
- String filename,
- String outputMIME) {
+ String filename,
+ String outputMIME) {
ReportsCommon reportCommon = new ReportsCommon();
reportCommon.setName(name);
reportCommon.setFilename(filename);
reportCommon.setOutputMIME(outputMIME);
+ reportCommon.setNotes(getUTF8DataFragment()); // For UTF-8 tests
PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent());
PayloadOutputPart commonPart =
- multipart.addPart(reportCommon, MediaType.APPLICATION_XML_TYPE);
+ multipart.addPart(reportCommon, MediaType.APPLICATION_XML_TYPE);
commonPart.setLabel(new ReportClient().getCommonPartName());
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug("to be created, report common");
logger.debug(objectAsXmlString(reportCommon, ReportsCommon.class));
logger.debug(multipart.toXML());