From 8b370959155df3032d93786cdf63cf51ddefde9a Mon Sep 17 00:00:00 2001 From: Aron Roberts Date: Thu, 21 Jul 2011 04:15:05 +0000 Subject: [PATCH] CSPACE-4172,CSPACE-3332: Revised Loanin service to return CommonList format for list results. --- .../services/client/LoaninClient.java | 25 +- .../services/client/LoaninProxy.java | 46 +- .../client/test/LoaninServiceTest.java | 652 +++++++++--------- 3 files changed, 357 insertions(+), 366 deletions(-) diff --git a/services/loanin/client/src/main/java/org/collectionspace/services/client/LoaninClient.java b/services/loanin/client/src/main/java/org/collectionspace/services/client/LoaninClient.java index 68cff472d..75a3b8e16 100644 --- a/services/loanin/client/src/main/java/org/collectionspace/services/client/LoaninClient.java +++ b/services/loanin/client/src/main/java/org/collectionspace/services/client/LoaninClient.java @@ -16,9 +16,6 @@ */ package org.collectionspace.services.client; -import org.jboss.resteasy.client.ClientResponse; -import org.collectionspace.services.jaxb.AbstractCommonList; - /** * LoaninClient.java * @@ -26,7 +23,8 @@ import org.collectionspace.services.jaxb.AbstractCommonList; * $LastChangedDate$ * */ -public class LoaninClient extends AbstractPoxServiceClientImpl { +public class LoaninClient extends AbstractCommonListPoxServiceClientImpl { + public static final String SERVICE_NAME = "loansin"; public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME; public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT; @@ -44,20 +42,9 @@ public class LoaninClient extends AbstractPoxServiceClientImpl getProxyClass() { - return LoaninProxy.class; - } - - /* - * Proxied service calls - */ - - /** - * @return - * @see org.collectionspace.services.client.LoaninProxy#getLoanin() - */ - public ClientResponse readList() { - return getProxy().readList(); + @Override + public Class getProxyClass() { + return LoaninProxy.class; } + } diff --git a/services/loanin/client/src/main/java/org/collectionspace/services/client/LoaninProxy.java b/services/loanin/client/src/main/java/org/collectionspace/services/client/LoaninProxy.java index 8009531c7..7dc0e9abf 100644 --- a/services/loanin/client/src/main/java/org/collectionspace/services/client/LoaninProxy.java +++ b/services/loanin/client/src/main/java/org/collectionspace/services/client/LoaninProxy.java @@ -1,36 +1,34 @@ +/** + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + * + * http://www.collectionspace.org + * http://wiki.collectionspace.org + * + * Copyright (c) 2009 Regents of the University of California + * + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + * + * You may obtain a copy of the ECL 2.0 License at + * https://source.collectionspace.org/collection-space/LICENSE.txt + */ package org.collectionspace.services.client; -import org.jboss.resteasy.client.ClientResponse; import javax.ws.rs.Consumes; -import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; - -import org.collectionspace.services.client.workflow.WorkflowClient; -import org.collectionspace.services.jaxb.AbstractCommonList; /** - * @version $Revision$ + * LoaninProxy.java + * + * $LastChangedRevision$ + * $LastChangedDate$ + * */ @Path("/loansin/") @Produces({"application/xml;charset=UTF-8"}) @Consumes({"application/xml"}) -public interface LoaninProxy extends CollectionSpacePoxProxy { - // List - @GET - ClientResponse readList(); - - @Override - @GET - @Produces({"application/xml"}) - ClientResponse readIncludeDeleted( - @QueryParam(WorkflowClient.WORKFLOW_QUERY_NONDELETED) String includeDeleted); - - @Override - @GET - @Produces({"application/xml"}) - ClientResponse keywordSearchIncludeDeleted( - @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords, - @QueryParam(WorkflowClient.WORKFLOW_QUERY_NONDELETED) String includeDeleted); +public interface LoaninProxy extends CollectionSpaceCommonListPoxProxy { } diff --git a/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninServiceTest.java b/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninServiceTest.java index b8595a3a1..af9b62c68 100644 --- a/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninServiceTest.java +++ b/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninServiceTest.java @@ -54,18 +54,15 @@ import org.slf4j.LoggerFactory; */ public class LoaninServiceTest extends AbstractServiceTestImpl { - /** The logger. */ + /** The logger. */ private final String CLASS_NAME = LoaninServiceTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); - // Instance variables specific to this test. /** The service path component. */ final String SERVICE_NAME = "loansin"; final String SERVICE_PATH_COMPONENT = "loansin"; - /** The known resource id. */ private String knownResourceId = null; - private String LENDER_REF_NAME = "urn:cspace:org.collectionspace.demo:personauthority:name(TestPersonAuth):person:name(Harry Lender)'Harry Lender'"; @@ -74,27 +71,29 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { */ @Override protected CollectionSpaceClient getClientInstance() { - return new LoaninClient(); + return new LoaninClient(); } - + /* (non-Javadoc) * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) */ @Override - protected AbstractCommonList getAbstractCommonList( - ClientResponse response) { + protected AbstractCommonList getAbstractCommonList( + ClientResponse response) { return response.getEntity(AbstractCommonList.class); } - + // --------------------------------------------------------------- // 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) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void create(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -112,35 +111,35 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { String newID = null; ClientResponse 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); - - newID = extractId(res); + 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(); + res.releaseConnection(); } // Store the ID returned from the first resource created // for additional tests below. - if (knownResourceId == null){ + if (knownResourceId == null) { knownResourceId = newID; if (logger.isDebugEnabled()) { logger.debug(testName + ": knownResourceId=" + knownResourceId); } } - + // Store the IDs from every resource created by tests, // so they can be deleted after tests have been run. allResourceIdsCreated.add(newID); @@ -150,10 +149,10 @@ public class LoaninServiceTest 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); } } @@ -161,12 +160,13 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { // 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? + //Should this really be empty? } /* (non-Javadoc) @@ -174,7 +174,7 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { */ @Override public void createWithMalformedXml(String testName) throws Exception { - //Should this really be empty? + //Should this really be empty? } /* (non-Javadoc) @@ -182,110 +182,112 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { */ @Override public void createWithWrongXmlSchema(String testName) throws Exception { - //Should this really be empty? + //Should this really be empty? } /* @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - dependsOnMethods = {"create", "testSubmitRequest"}) + dependsOnMethods = {"create", "testSubmitRequest"}) public void createWithEmptyEntityBody(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupCreateWithEmptyEntityBody(); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getServiceRootURL(); - String mediaType = MediaType.APPLICATION_XML; - final String entity = ""; - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug("createWithEmptyEntityBody url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + if (logger.isDebugEnabled()) { + logger.debug(testBanner(testName, CLASS_NAME)); } - + // Perform setup. + setupCreateWithEmptyEntityBody(); + + // Submit the request to the service and store the response. + String method = REQUEST_TYPE.httpMethodName(); + String url = getServiceRootURL(); + String mediaType = MediaType.APPLICATION_XML; + final String entity = ""; + int statusCode = submitRequest(method, url, mediaType, entity); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug("createWithEmptyEntityBody url=" + url + + " status=" + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - dependsOnMethods = {"create", "testSubmitRequest"}) + dependsOnMethods = {"create", "testSubmitRequest"}) public void createWithMalformedXml(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupCreateWithMalformedXml(testName, logger); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getServiceRootURL(); - String mediaType = MediaType.APPLICATION_XML; - final String entity = MALFORMED_XML_DATA; // Constant from base class. - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + if (logger.isDebugEnabled()) { + logger.debug(testBanner(testName, CLASS_NAME)); } - + // Perform setup. + setupCreateWithMalformedXml(testName, logger); + + // Submit the request to the service and store the response. + String method = REQUEST_TYPE.httpMethodName(); + String url = getServiceRootURL(); + String mediaType = MediaType.APPLICATION_XML; + final String entity = MALFORMED_XML_DATA; // Constant from base class. + int statusCode = submitRequest(method, url, mediaType, entity); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": url=" + url + + " status=" + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - dependsOnMethods = {"create", "testSubmitRequest"}) + dependsOnMethods = {"create", "testSubmitRequest"}) public void createWithWrongXmlSchema(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupCreateWithWrongXmlSchema(testName, logger); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getServiceRootURL(); - String mediaType = MediaType.APPLICATION_XML; - final String entity = WRONG_XML_SCHEMA_DATA; - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + if (logger.isDebugEnabled()) { + logger.debug(testBanner(testName, CLASS_NAME)); + } + // Perform setup. + setupCreateWithWrongXmlSchema(testName, logger); + + // Submit the request to the service and store the response. + String method = REQUEST_TYPE.httpMethodName(); + String url = getServiceRootURL(); + String mediaType = MediaType.APPLICATION_XML; + final String entity = WRONG_XML_SCHEMA_DATA; + int statusCode = submitRequest(method, url, mediaType, entity); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": url=" + url + + " status=" + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); } */ - + // --------------------------------------------------------------- // 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"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + dependsOnMethods = {"create"}) public void read(String testName) throws Exception { - + if (logger.isDebugEnabled()) { logger.debug(testBanner(testName, CLASS_NAME)); } @@ -297,26 +299,26 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { ClientResponse res = client.read(knownResourceId); PoxPayloadIn input = 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); - input = new PoxPayloadIn(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); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + input = new PoxPayloadIn(res.getEntity()); } finally { - res.releaseConnection(); + res.releaseConnection(); } // Get the common part of the response and verify that it is not null. PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName()); LoansinCommon loaninCommon = null; if (payloadInputPart != null) { - loaninCommon = (LoansinCommon) payloadInputPart.getBody(); + loaninCommon = (LoansinCommon) payloadInputPart.getBody(); } Assert.assertNotNull(loaninCommon); @@ -329,24 +331,24 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { String lender = lenderGroups.get(0).getLender(); Assert.assertEquals(lender, LENDER_REF_NAME); - if(logger.isDebugEnabled()){ + if (logger.isDebugEnabled()) { logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n" + "UTF-8 data received=" + loaninCommon.getLoanInNote()); - } + } Assert.assertEquals(loaninCommon.getLoanInNote(), getUTF8DataFragment(), "UTF-8 data retrieved '" + loaninCommon.getLoanInNote() + "' does not match expected data '" + getUTF8DataFragment()); - } // Failure outcomes + /* (non-Javadoc) * @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()) { @@ -359,33 +361,35 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { LoaninClient client = new LoaninClient(); ClientResponse res = client.read(NON_EXISTENT_ID); 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); + 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(); + 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"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + dependsOnMethods = {"createList", "read"}) public void readList(String testName) throws Exception { - + if (logger.isDebugEnabled()) { logger.debug(testBanner(testName, CLASS_NAME)); } @@ -397,48 +401,45 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { LoaninClient client = new LoaninClient(); ClientResponse res = client.readList(); 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(); + 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(); + res.releaseConnection(); } // Optionally output additional data about list members for debugging. - boolean iterateThroughList = false; - if (iterateThroughList && logger.isDebugEnabled()){ - List items = - list.getListItem(); - int i = 0; - for(AbstractCommonList.ListItem item : items){ - logger.debug(testName + ": list-item[" + i + "] " + - item.toString()); - i++; - } + boolean iterateThroughList = true; + if(iterateThroughList && logger.isDebugEnabled()){ + ListItemsInAbstractCommonList(list, logger, testName); } + } // Failure outcomes // None at present. + // --------------------------------------------------------------- // 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"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + dependsOnMethods = {"read"}) public void update(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -452,24 +453,24 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { ClientResponse res = client.read(knownResourceId); PoxPayloadIn input = null; 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 = new PoxPayloadIn(res.getEntity()); + 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 = new PoxPayloadIn(res.getEntity()); } finally { - res.releaseConnection(); + res.releaseConnection(); } // Extract the common part from the response. PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName()); LoansinCommon loaninCommon = null; if (payloadInputPart != null) { - loaninCommon = (LoansinCommon) payloadInputPart.getBody(); + loaninCommon = (LoansinCommon) payloadInputPart.getBody(); } Assert.assertNotNull(loaninCommon); @@ -477,7 +478,7 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { loaninCommon.setLoanInNumber("updated-" + loaninCommon.getLoanInNumber()); loaninCommon.setLoanReturnDate("updated-" + loaninCommon.getLoanReturnDate()); loaninCommon.setLoanInNote("updated-" + loaninCommon.getLoanInNote()); - if(logger.isDebugEnabled()){ + if (logger.isDebugEnabled()) { logger.debug("to be updated object"); logger.debug(objectAsXmlString(loaninCommon, LoansinCommon.class)); } @@ -489,24 +490,24 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { commonPart.setLabel(client.getCommonPartName()); res = client.update(knownResourceId, output); 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 = new PoxPayloadIn(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); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + input = new PoxPayloadIn(res.getEntity()); } finally { - res.releaseConnection(); + res.releaseConnection(); } // Extract the updated common part from the response. payloadInputPart = input.getPart(client.getCommonPartName()); LoansinCommon updatedLoaninCommon = null; if (payloadInputPart != null) { - updatedLoaninCommon = (LoansinCommon) payloadInputPart.getBody(); + updatedLoaninCommon = (LoansinCommon) payloadInputPart.getBody(); } Assert.assertNotNull(updatedLoaninCommon); @@ -515,10 +516,10 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { loaninCommon.getLoanReturnDate(), "Data in updated object did not match submitted data."); - if(logger.isDebugEnabled()){ + if (logger.isDebugEnabled()) { logger.debug("UTF-8 data sent=" + loaninCommon.getLoanInNote() + "\n" + "UTF-8 data received=" + updatedLoaninCommon.getLoanInNote()); - } + } Assert.assertTrue(updatedLoaninCommon.getLoanInNote().contains(getUTF8DataFragment()), "UTF-8 data retrieved '" + updatedLoaninCommon.getLoanInNote() + "' does not contain expected data '" + getUTF8DataFragment()); @@ -530,116 +531,117 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { // 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? + //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? } /* @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - dependsOnMethods = {"create", "update", "testSubmitRequest"}) + dependsOnMethods = {"create", "update", "testSubmitRequest"}) public void updateWithEmptyEntityBody(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdateWithEmptyEntityBody(); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getResourceURL(knownResourceId); - String mediaType = MediaType.APPLICATION_XML; - final String entity = ""; - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + if (logger.isDebugEnabled()) { + logger.debug(testBanner(testName, CLASS_NAME)); } - + // Perform setup. + setupUpdateWithEmptyEntityBody(); + + // Submit the request to the service and store the response. + String method = REQUEST_TYPE.httpMethodName(); + String url = getResourceURL(knownResourceId); + String mediaType = MediaType.APPLICATION_XML; + final String entity = ""; + int statusCode = submitRequest(method, url, mediaType, entity); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": url=" + url + + " status=" + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - dependsOnMethods = {"create", "update", "testSubmitRequest"}) + dependsOnMethods = {"create", "update", "testSubmitRequest"}) public void updateWithMalformedXml(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdateWithMalformedXml(); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getResourceURL(knownResourceId); - String mediaType = MediaType.APPLICATION_XML; - final String entity = MALFORMED_XML_DATA; - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + if (logger.isDebugEnabled()) { + logger.debug(testBanner(testName, CLASS_NAME)); } - + // Perform setup. + setupUpdateWithMalformedXml(); + + // Submit the request to the service and store the response. + String method = REQUEST_TYPE.httpMethodName(); + String url = getResourceURL(knownResourceId); + String mediaType = MediaType.APPLICATION_XML; + final String entity = MALFORMED_XML_DATA; + int statusCode = submitRequest(method, url, mediaType, entity); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": url=" + url + + " status=" + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - dependsOnMethods = {"create", "update", "testSubmitRequest"}) + dependsOnMethods = {"create", "update", "testSubmitRequest"}) public void updateWithWrongXmlSchema(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdateWithWrongXmlSchema(); - - // Submit the request to the service and store the response. - String method = REQUEST_TYPE.httpMethodName(); - String url = getResourceURL(knownResourceId); - String mediaType = MediaType.APPLICATION_XML; - final String entity = WRONG_XML_SCHEMA_DATA; - int statusCode = submitRequest(method, url, mediaType, entity); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": url=" + url + - " status=" + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + if (logger.isDebugEnabled()) { + logger.debug(testBanner(testName, CLASS_NAME)); + } + // Perform setup. + setupUpdateWithWrongXmlSchema(); + + // Submit the request to the service and store the response. + String method = REQUEST_TYPE.httpMethodName(); + String url = getResourceURL(knownResourceId); + String mediaType = MediaType.APPLICATION_XML; + final String entity = WRONG_XML_SCHEMA_DATA; + int statusCode = submitRequest(method, url, mediaType, entity); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": url=" + url + + " status=" + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); } */ @@ -647,8 +649,8 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { * @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()) { @@ -664,31 +666,33 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { PoxPayloadOut multipart = createLoaninInstance(NON_EXISTENT_ID); ClientResponse res = client.update(NON_EXISTENT_ID, multipart); 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); + 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(); + res.releaseConnection(); } } // --------------------------------------------------------------- // 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"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"}) public void delete(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -701,30 +705,31 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { LoaninClient client = new LoaninClient(); ClientResponse res = client.delete(knownResourceId); 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); + 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(); + res.releaseConnection(); } } // Failure outcomes + /* (non-Javadoc) * @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()) { logger.debug(testBanner(testName, CLASS_NAME)); } @@ -735,24 +740,25 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { LoaninClient client = new LoaninClient(); ClientResponse res = client.delete(NON_EXISTENT_ID); 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); + 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(); + res.releaseConnection(); } } // --------------------------------------------------------------- // 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. @@ -770,9 +776,9 @@ public class LoaninServiceTest 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); @@ -781,7 +787,7 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { // --------------------------------------------------------------- // Utility methods used by tests above // --------------------------------------------------------------- - + @Override public String getServiceName() { return SERVICE_NAME; @@ -797,9 +803,9 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { @Override protected PoxPayloadOut createInstance(String identifier) { - return createLoaninInstance(identifier); + return createLoaninInstance(identifier); } - + /** * Creates the loanin instance. * @@ -820,7 +826,7 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { * @return the multipart output */ private PoxPayloadOut createLoaninInstance(String loaninNumber, - String returnDate) { + String returnDate) { LoansinCommon loaninCommon = new LoansinCommon(); loaninCommon.setLoanInNumber(loaninNumber); @@ -835,10 +841,10 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent()); PayloadOutputPart commonPart = - multipart.addPart(loaninCommon, MediaType.APPLICATION_XML_TYPE); + multipart.addPart(loaninCommon, MediaType.APPLICATION_XML_TYPE); commonPart.setLabel(new LoaninClient().getCommonPartName()); - if(logger.isDebugEnabled()){ + if (logger.isDebugEnabled()) { logger.debug("to be created, loanin common"); logger.debug(objectAsXmlString(loaninCommon, LoansinCommon.class)); } -- 2.47.3