From bf41e3161f6b2c0653bf1881c484e9ddb29fe66a Mon Sep 17 00:00:00 2001 From: Aron Roberts Date: Mon, 21 Mar 2011 23:23:53 +0000 Subject: [PATCH] CSPACE-3582: Completed UTF-8 support changs for the Report service, following the migration of that service to POX payloads. --- .../services/client/ReportClient.java | 7 +- .../services/client/ReportProxy.java | 4 +- .../client/test/ReportServiceTest.java | 171 ++++++++++-------- .../services/report/ReportResource.java | 8 +- 4 files changed, 101 insertions(+), 89 deletions(-) diff --git a/services/report/client/src/main/java/org/collectionspace/services/client/ReportClient.java b/services/report/client/src/main/java/org/collectionspace/services/client/ReportClient.java index 31e9fb3b6..ba606c77a 100644 --- a/services/report/client/src/main/java/org/collectionspace/services/client/ReportClient.java +++ b/services/report/client/src/main/java/org/collectionspace/services/client/ReportClient.java @@ -125,8 +125,7 @@ public class ReportClient extends AbstractServiceClientImpl { * @see org.collectionspace.services.client.ReportProxy#createReport(org.collectionspace.hello.Report) */ public ClientResponse create(PoxPayloadOut multipart) { - String payload = multipart.toXML(); - return reportProxy.create(payload); + return reportProxy.create(multipart.getBytes()); } /** @@ -136,9 +135,7 @@ public class ReportClient extends AbstractServiceClientImpl { * @see org.collectionspace.services.client.ReportProxy#updateReport(java.lang.Long, org.collectionspace.hello.Report) */ public ClientResponse update(String csid, PoxPayloadOut multipart) { - String payload = multipart.toXML(); - return reportProxy.update(csid, payload); - + return reportProxy.update(csid, multipart.getBytes()); } /** diff --git a/services/report/client/src/main/java/org/collectionspace/services/client/ReportProxy.java b/services/report/client/src/main/java/org/collectionspace/services/client/ReportProxy.java index 2225743f4..32b836ee7 100644 --- a/services/report/client/src/main/java/org/collectionspace/services/client/ReportProxy.java +++ b/services/report/client/src/main/java/org/collectionspace/services/client/ReportProxy.java @@ -67,7 +67,7 @@ public interface ReportProxy extends CollectionSpaceProxy { * @return the client response */ @POST - ClientResponse create(String payload); + ClientResponse create(byte[] payload); //(R)ead /** @@ -90,7 +90,7 @@ public interface ReportProxy extends CollectionSpaceProxy { */ @PUT @Path("/{csid}") - ClientResponse update(@PathParam("csid") String csid, String payload); + ClientResponse update(@PathParam("csid") String csid, byte[] payload); //(D)elete /** diff --git a/services/report/client/src/test/java/org/collectionspace/services/client/test/ReportServiceTest.java b/services/report/client/src/test/java/org/collectionspace/services/client/test/ReportServiceTest.java index 04fe3212c..3b5fbc9dd 100644 --- a/services/report/client/src/test/java/org/collectionspace/services/client/test/ReportServiceTest.java +++ b/services/report/client/src/test/java/org/collectionspace/services/client/test/ReportServiceTest.java @@ -54,36 +54,32 @@ import org.slf4j.LoggerFactory; */ 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 response) { - return response.getEntity(ReportsCommonList.class); + protected AbstractCommonList getAbstractCommonList( + ClientResponse response) { + return response.getEntity(ReportsCommonList.class); } - + // --------------------------------------------------------------- // CRUD tests : CREATE tests // --------------------------------------------------------------- @@ -92,7 +88,7 @@ public class ReportServiceTest extends AbstractServiceTestImpl { * @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()) { @@ -116,7 +112,7 @@ public class ReportServiceTest extends AbstractServiceTestImpl { // 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), @@ -125,13 +121,13 @@ public class ReportServiceTest extends AbstractServiceTestImpl { // 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)); @@ -141,10 +137,10 @@ public class ReportServiceTest extends AbstractServiceTestImpl { * @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); } } @@ -157,7 +153,7 @@ public class ReportServiceTest extends AbstractServiceTestImpl { */ @Override public void createWithEmptyEntityBody(String testName) throws Exception { - //Should this really be empty? + //Should this really be empty? } /* (non-Javadoc) @@ -165,7 +161,7 @@ public class ReportServiceTest extends AbstractServiceTestImpl { */ @Override public void createWithMalformedXml(String testName) throws Exception { - //Should this really be empty? + //Should this really be empty? } /* (non-Javadoc) @@ -173,7 +169,7 @@ public class ReportServiceTest extends AbstractServiceTestImpl { */ @Override public void createWithWrongXmlSchema(String testName) throws Exception { - //Should this really be empty? + //Should this really be empty? } // --------------------------------------------------------------- @@ -184,8 +180,8 @@ public class ReportServiceTest extends AbstractServiceTestImpl { * @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()) { @@ -201,7 +197,7 @@ public class ReportServiceTest extends AbstractServiceTestImpl { // 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), @@ -213,9 +209,18 @@ public class ReportServiceTest extends AbstractServiceTestImpl { 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 @@ -223,8 +228,8 @@ public class ReportServiceTest extends AbstractServiceTestImpl { * @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()) { @@ -240,7 +245,7 @@ public class ReportServiceTest extends AbstractServiceTestImpl { // 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), @@ -256,8 +261,8 @@ public class ReportServiceTest extends AbstractServiceTestImpl { * @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()) { @@ -274,7 +279,7 @@ public class ReportServiceTest extends AbstractServiceTestImpl { // 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), @@ -283,19 +288,19 @@ public class ReportServiceTest extends AbstractServiceTestImpl { // Optionally output additional data about list members for debugging. boolean iterateThroughList = false; - if(iterateThroughList && logger.isDebugEnabled()){ + if (iterateThroughList && logger.isDebugEnabled()) { List 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++; } } @@ -310,8 +315,8 @@ public class ReportServiceTest extends AbstractServiceTestImpl { * @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()) { @@ -323,11 +328,11 @@ public class ReportServiceTest extends AbstractServiceTestImpl { // Retrieve the contents of a resource to update. ReportClient client = new ReportClient(); ClientResponse 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); } @@ -336,18 +341,19 @@ public class ReportServiceTest extends AbstractServiceTestImpl { 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()); @@ -357,7 +363,7 @@ public class ReportServiceTest extends AbstractServiceTestImpl { // 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), @@ -369,10 +375,10 @@ public class ReportServiceTest extends AbstractServiceTestImpl { 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)); } @@ -382,6 +388,17 @@ public class ReportServiceTest extends AbstractServiceTestImpl { 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 @@ -392,31 +409,31 @@ public class ReportServiceTest extends AbstractServiceTestImpl { */ @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()) { @@ -435,7 +452,7 @@ public class ReportServiceTest extends AbstractServiceTestImpl { // 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), @@ -451,8 +468,8 @@ public class ReportServiceTest extends AbstractServiceTestImpl { * @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()) { @@ -468,7 +485,7 @@ public class ReportServiceTest extends AbstractServiceTestImpl { // 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), @@ -481,8 +498,8 @@ public class ReportServiceTest extends AbstractServiceTestImpl { * @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()) { @@ -498,7 +515,7 @@ public class ReportServiceTest extends AbstractServiceTestImpl { // 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), @@ -509,7 +526,6 @@ public class ReportServiceTest extends AbstractServiceTestImpl { // --------------------------------------------------------------- // 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. @@ -527,9 +543,9 @@ public class ReportServiceTest extends AbstractServiceTestImpl { // 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); @@ -538,8 +554,6 @@ public class ReportServiceTest extends AbstractServiceTestImpl { // --------------------------------------------------------------- // Utility methods used by tests above // --------------------------------------------------------------- - - @Override protected String getServiceName() { return SERVICE_NAME; @@ -563,7 +577,7 @@ public class ReportServiceTest extends AbstractServiceTestImpl { return createReportInstance( "name-" + identifier, "persAuthTermCountsTest.jasper", - "application/pdf" ); + "application/pdf"); } /** @@ -575,19 +589,20 @@ public class ReportServiceTest extends AbstractServiceTestImpl { * @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()); diff --git a/services/report/service/src/main/java/org/collectionspace/services/report/ReportResource.java b/services/report/service/src/main/java/org/collectionspace/services/report/ReportResource.java index 9a0b43ce6..c0e83ea39 100644 --- a/services/report/service/src/main/java/org/collectionspace/services/report/ReportResource.java +++ b/services/report/service/src/main/java/org/collectionspace/services/report/ReportResource.java @@ -185,7 +185,7 @@ public class ReportResource extends */ @GET @Path("{csid}") - public String getReport( + public byte[] getReport( @PathParam("csid") String csid) { if (logger.isDebugEnabled()) { logger.debug("getReport with csid=" + csid); @@ -229,7 +229,7 @@ public class ReportResource extends "text/plain").build(); throw new WebApplicationException(response); } - return result.toXML(); + return result.getBytes(); } /** @@ -444,7 +444,7 @@ public class ReportResource extends */ @PUT @Path("{csid}") - public String updateReport( + public byte[] updateReport( @PathParam("csid") String csid, String xmlText) { if (logger.isDebugEnabled()) { @@ -481,7 +481,7 @@ public class ReportResource extends Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build(); throw new WebApplicationException(response); } - return result.toXML(); + return result.getBytes(); } /** -- 2.47.3