From: Aron Roberts Date: Tue, 20 Sep 2011 23:31:39 +0000 (+0000) Subject: CSPACE-3270,CSPACE-4172,CSPACE-3332,CSPACE-1018: Updated Contact schema to reflect... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=e9ae71dc4c101cdbde78ec67dae5b8373ccdbc79;p=tmp%2Fjakarta-migration.git CSPACE-3270,CSPACE-4172,CSPACE-3332,CSPACE-1018: Updated Contact schema to reflect current wiki schema. Updated Contact service to use AbstractCommonList and DocHandlerBase. Includes stub code to generate a displayname from constituent fields. --- diff --git a/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml b/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml index 8cf60d6ee..dc32e07b1 100644 --- a/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml +++ b/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml @@ -1831,6 +1831,16 @@ --> default-domain org.collectionspace.services.contact.nuxeo.ContactDocumentModelHandler + + + + + displayName + displayName + + + + diff --git a/services/contact/3rdparty/nuxeo-platform-cs-contact/src/main/resources/schemas/contacts_common.xsd b/services/contact/3rdparty/nuxeo-platform-cs-contact/src/main/resources/schemas/contacts_common.xsd index 54cf1ca3b..008f37ebe 100644 --- a/services/contact/3rdparty/nuxeo-platform-cs-contact/src/main/resources/schemas/contacts_common.xsd +++ b/services/contact/3rdparty/nuxeo-platform-cs-contact/src/main/resources/schemas/contacts_common.xsd @@ -21,16 +21,82 @@ + + + + + + + + + + + + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + + + + + + + + diff --git a/services/contact/client/pom.xml b/services/contact/client/pom.xml index b5548ecab..f76eda645 100644 --- a/services/contact/client/pom.xml +++ b/services/contact/client/pom.xml @@ -34,6 +34,11 @@ org.collectionspace.services.client ${project.version} + + org.collectionspace.services + org.collectionspace.services.common + ${project.version} + dom4j diff --git a/services/contact/client/src/main/java/org/collectionspace/services/client/AuthorityWithContactsClient.java b/services/contact/client/src/main/java/org/collectionspace/services/client/AuthorityWithContactsClient.java index 5564f0723..ee7955802 100644 --- a/services/contact/client/src/main/java/org/collectionspace/services/client/AuthorityWithContactsClient.java +++ b/services/contact/client/src/main/java/org/collectionspace/services/client/AuthorityWithContactsClient.java @@ -2,7 +2,6 @@ package org.collectionspace.services.client; import javax.ws.rs.core.Response; -import org.collectionspace.services.contact.ContactsCommonList; import org.collectionspace.services.jaxb.AbstractCommonList; import org.jboss.resteasy.client.ClientResponse; @@ -121,7 +120,7 @@ public interface AuthorityWithContactsClient

* @param itemcsid the itemcsid * @return the client response */ - public ClientResponse readContactList(String parentcsid, + public ClientResponse readContactList(String parentcsid, String itemcsid); /** @@ -131,7 +130,7 @@ public interface AuthorityWithContactsClient

* @param itemspecifier (shortIdentifier) * @return the client response */ - public ClientResponse readContactListForNamedItem( + public ClientResponse readContactListForNamedItem( String parentcsid, String itemspecifier); @@ -142,7 +141,7 @@ public interface AuthorityWithContactsClient

* @param itemcsid * @return the client response */ - public ClientResponse readContactListForItemInNamedAuthority( + public ClientResponse readContactListForItemInNamedAuthority( String parentspecifier, String itemcsid); @@ -153,7 +152,7 @@ public interface AuthorityWithContactsClient

* @param itemspecifier (shortIdentifier) * @return the client response */ - public ClientResponse readContactListForNamedItemInNamedAuthority( + public ClientResponse readContactListForNamedItemInNamedAuthority( String parentspecifier, String itemspecifier); diff --git a/services/contact/client/src/main/java/org/collectionspace/services/client/AuthorityWithContactsClientImpl.java b/services/contact/client/src/main/java/org/collectionspace/services/client/AuthorityWithContactsClientImpl.java index 092ffb1d4..9dd97a070 100644 --- a/services/contact/client/src/main/java/org/collectionspace/services/client/AuthorityWithContactsClientImpl.java +++ b/services/contact/client/src/main/java/org/collectionspace/services/client/AuthorityWithContactsClientImpl.java @@ -3,7 +3,6 @@ package org.collectionspace.services.client; import javax.ws.rs.core.Response; import org.jboss.resteasy.client.ClientResponse; -import org.collectionspace.services.contact.ContactsCommonList; import org.collectionspace.services.jaxb.AbstractCommonList; /* @@ -140,7 +139,7 @@ public abstract class AuthorityWithContactsClientImpl

readContactList(String parentcsid, + public ClientResponse readContactList(String parentcsid, String itemcsid) { return getProxy().readContactList(parentcsid, itemcsid); } @@ -153,7 +152,7 @@ public abstract class AuthorityWithContactsClientImpl

readContactListForNamedItem( + public ClientResponse readContactListForNamedItem( String parentcsid, String itemspecifier){ return getProxy().readContactList(parentcsid, itemspecifier); @@ -167,7 +166,7 @@ public abstract class AuthorityWithContactsClientImpl

readContactListForItemInNamedAuthority( + public ClientResponse readContactListForItemInNamedAuthority( String parentspecifier, String itemcsid){ return getProxy().readContactList(parentspecifier, itemcsid); @@ -181,7 +180,7 @@ public abstract class AuthorityWithContactsClientImpl

readContactListForNamedItemInNamedAuthority( + public ClientResponse readContactListForNamedItemInNamedAuthority( String parentspecifier, String itemspecifier){ return getProxy().readContactList(parentspecifier, itemspecifier); diff --git a/services/contact/client/src/main/java/org/collectionspace/services/client/AuthorityWithContactsProxy.java b/services/contact/client/src/main/java/org/collectionspace/services/client/AuthorityWithContactsProxy.java index 8b57e3ae9..c31f4bb18 100644 --- a/services/contact/client/src/main/java/org/collectionspace/services/client/AuthorityWithContactsProxy.java +++ b/services/contact/client/src/main/java/org/collectionspace/services/client/AuthorityWithContactsProxy.java @@ -9,7 +9,7 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.Response; -import org.collectionspace.services.contact.ContactsCommonList; +import org.collectionspace.services.jaxb.AbstractCommonList; import org.jboss.resteasy.client.ClientResponse; /* @@ -20,27 +20,27 @@ public interface AuthorityWithContactsProxy extends AuthorityProxy { @GET @Produces({"application/xml"}) @Path("/{parentcsid}/items/{itemcsid}/contacts/") - public ClientResponse readContactList( + public ClientResponse readContactList( @PathParam("parentcsid") String parentcsid, @PathParam("itemcsid") String itemcsid); @GET @Produces({"application/xml"}) @Path("/{parentcsid}/items/urn:cspace:name({itemspecifier})/contacts/") - ClientResponse readContactListForNamedItem( + ClientResponse readContactListForNamedItem( @PathParam("parentcsid") String parentcsid, @PathParam("itemspecifier") String itemspecifier); @GET @Produces({"application/xml"}) @Path("/urn:cspace:name({parentspecifier})/items/{itemcsid}/contacts/") - ClientResponse readContactListForItemInNamedAuthority( + ClientResponse readContactListForItemInNamedAuthority( @PathParam("parentspecifier") String parentspecifier, @PathParam("itemcsid") String itemcsid); @GET @Produces({"application/xml"}) @Path("/urn:cspace:name({parentspecifier})/items/urn:cspace:name({itemspecifier})/contacts/") - ClientResponse readContactListForNamedItemInNamedAuthority( + ClientResponse readContactListForNamedItemInNamedAuthority( @PathParam("parentspecifier") String parentspecifier, @PathParam("itemspecifier") String itemspecifier); diff --git a/services/contact/client/src/main/java/org/collectionspace/services/client/ContactClient.java b/services/contact/client/src/main/java/org/collectionspace/services/client/ContactClient.java index fd4804688..2471a8e8e 100644 --- a/services/contact/client/src/main/java/org/collectionspace/services/client/ContactClient.java +++ b/services/contact/client/src/main/java/org/collectionspace/services/client/ContactClient.java @@ -16,47 +16,32 @@ */ package org.collectionspace.services.client; -import org.jboss.resteasy.client.ClientResponse; -import org.collectionspace.services.contact.ContactsCommonList; - /** * ContactClient.java * * $LastChangedRevision: $ * $LastChangedDate: $ */ - -public class ContactClient extends AbstractPoxServiceClientImpl { - public static final String SERVICE_NAME = "contacts"; - public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME; - public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT; - public static final String SERVICE_PATH_PROXY = SERVICE_PATH + "/"; - public static final String SERVICE_PAYLOAD_NAME = SERVICE_NAME; +public class ContactClient extends AbstractCommonListPoxServiceClientImpl { - @Override - public String getServiceName() { - return SERVICE_NAME; - } - - @Override - public String getServicePathComponent() { - return SERVICE_PATH_COMPONENT; - } + public static final String SERVICE_NAME = "contacts"; + public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME; + public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT; + public static final String SERVICE_PATH_PROXY = SERVICE_PATH + "/"; + public static final String SERVICE_PAYLOAD_NAME = SERVICE_NAME; + + @Override + public String getServiceName() { + return SERVICE_NAME; + } - @Override - public Class getProxyClass() { - return ContactProxy.class; - } + @Override + public String getServicePathComponent() { + return SERVICE_PATH_COMPONENT; + } - /* - * Service calls - */ - - /** - * @return - * @see org.collectionspace.services.client.Contact#getContact() - */ - public ClientResponse readList() { - return getProxy().readList(); + @Override + public Class getProxyClass() { + return ContactProxy.class; } } diff --git a/services/contact/client/src/main/java/org/collectionspace/services/client/ContactClientUtils.java b/services/contact/client/src/main/java/org/collectionspace/services/client/ContactClientUtils.java index 39d173de4..4ad1c158e 100644 --- a/services/contact/client/src/main/java/org/collectionspace/services/client/ContactClientUtils.java +++ b/services/contact/client/src/main/java/org/collectionspace/services/client/ContactClientUtils.java @@ -1,10 +1,14 @@ package org.collectionspace.services.client; +import java.util.List; import javax.ws.rs.core.MediaType; import org.collectionspace.services.client.ContactClient; +import org.collectionspace.services.contact.AddressGroup; +import org.collectionspace.services.contact.AddressGroupList; import org.collectionspace.services.contact.ContactsCommon; -//import org.jboss.resteasy.plugins.providers.multipart.OutputPart; +import org.collectionspace.services.contact.EmailGroup; +import org.collectionspace.services.contact.EmailGroupList; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -20,9 +24,9 @@ public class ContactClientUtils { return createContactInstance( inAuthority, inItem, + "email-" + identifier, "addressType-" + identifier, "addressPlace-" + identifier, - "emakl-" + identifier, headerLabel); } @@ -31,21 +35,35 @@ public class ContactClientUtils { return createContactInstance( inAuthority, inItem, + "email-" + identifier, "addressType-" + identifier, "addressPlace-" + identifier, - "emakl-" + identifier, headerLabel); } public static PoxPayloadOut createContactInstance( - String inAuthority, String inItem, String addressType, - String addressPlace, String email, String headerLabel) { + String inAuthority, String inItem, String email, + String addressType, String addressPlace, String headerLabel) { ContactsCommon contact = new ContactsCommon(); + contact.setInAuthority(inAuthority); contact.setInItem(inItem); - contact.setAddressType(addressType); - contact.setAddressPlace(addressPlace); - contact.setEmail(email); + + EmailGroupList emailGroupList = new EmailGroupList(); + List emailGroups = emailGroupList.getEmailGroup(); + EmailGroup emailGroup = new EmailGroup(); + emailGroup.setEmail(email); + emailGroups.add(emailGroup); + contact.setEmailGroupList(emailGroupList); + + AddressGroupList addressGroupList = new AddressGroupList(); + List addressGroups = addressGroupList.getAddressGroup(); + AddressGroup addressGroup = new AddressGroup(); + addressGroup.setAddressType(addressType); + addressGroup.setAddressPlace1(addressPlace); + addressGroups.add(addressGroup); + contact.setAddressGroupList(addressGroupList); + PoxPayloadOut multipart = new PoxPayloadOut(ContactClient.SERVICE_PAYLOAD_NAME); @SuppressWarnings("deprecation") PayloadOutputPart commonPart = @@ -53,13 +71,7 @@ public class ContactClientUtils { // ContactClient client = new ContactClient(); commonPart.setLabel(headerLabel); - if(logger.isDebugEnabled()){ - logger.debug("to be created, contact common"); - // logger.debug(objectAsXmlString(contact, ContactsCommon.class)); - } - return multipart; } - } diff --git a/services/contact/client/src/main/java/org/collectionspace/services/client/ContactProxy.java b/services/contact/client/src/main/java/org/collectionspace/services/client/ContactProxy.java index 274719c24..8fe639449 100644 --- a/services/contact/client/src/main/java/org/collectionspace/services/client/ContactProxy.java +++ b/services/contact/client/src/main/java/org/collectionspace/services/client/ContactProxy.java @@ -1,35 +1,33 @@ +/** + * 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.contact.ContactsCommonList; /** - * @version $Revision:$ + * ContactProxy.java + * + * $LastChangedRevision: $ + * $LastChangedDate: $ */ @Path(ContactClient.SERVICE_PATH_PROXY) @Produces({"application/xml"}) @Consumes({"application/xml"}) -public interface ContactProxy extends CollectionSpacePoxProxy { - @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 ContactProxy extends CollectionSpaceCommonListPoxProxy { } diff --git a/services/contact/client/src/test/java/org/collectionspace/services/client/test/ContactServiceTest.java b/services/contact/client/src/test/java/org/collectionspace/services/client/test/ContactServiceTest.java index 3999e93e2..9b9b0445c 100644 --- a/services/contact/client/src/test/java/org/collectionspace/services/client/test/ContactServiceTest.java +++ b/services/contact/client/src/test/java/org/collectionspace/services/client/test/ContactServiceTest.java @@ -32,15 +32,17 @@ import org.collectionspace.services.client.ContactClientUtils; import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; +import org.collectionspace.services.common.AbstractCommonListUtils; +import org.collectionspace.services.contact.AddressGroup; +import org.collectionspace.services.contact.AddressGroupList; import org.collectionspace.services.contact.ContactsCommon; -import org.collectionspace.services.contact.ContactsCommonList; +import org.collectionspace.services.contact.EmailGroup; +import org.collectionspace.services.contact.EmailGroupList; import org.collectionspace.services.jaxb.AbstractCommonList; import org.jboss.resteasy.client.ClientResponse; -//import org.jboss.resteasy.plugins.providers.multipart.OutputPart; import org.testng.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.Test; import org.slf4j.Logger; @@ -54,39 +56,38 @@ import org.slf4j.LoggerFactory; * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $ */ public class ContactServiceTest extends AbstractServiceTestImpl { + private final String CLASS_NAME = ContactServiceTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(ContactServiceTest.class); - // Instance variables specific to this test. // final String SERVICE_PATH_COMPONENT = "contacts"; - private String knownResourceId = null; - @Override - public String getServicePathComponent() { - return ContactClient.SERVICE_PATH_COMPONENT; - } + @Override + public String getServicePathComponent() { + return ContactClient.SERVICE_PATH_COMPONENT; + } + + @Override + protected String getServiceName() { + return ContactClient.SERVICE_NAME; + } - @Override - protected String getServiceName() { - return ContactClient.SERVICE_NAME; - } - /* (non-Javadoc) * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() */ @Override protected CollectionSpaceClient getClientInstance() { - return new ContactClient(); + return new ContactClient(); } - + /* (non-Javadoc) * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) */ @Override - protected AbstractCommonList getAbstractCommonList( - ClientResponse response) { - return response.getEntity(ContactsCommonList.class); + protected AbstractCommonList getAbstractCommonList( + ClientResponse response) { + return response.getEntity(AbstractCommonList.class); } // @Override @@ -96,13 +97,12 @@ public class ContactServiceTest extends AbstractServiceTestImpl { // ContactClientUtils.createContactInstance(identifier, client.getCommonPartName()); // return multipart; // } - // --------------------------------------------------------------- // CRUD tests : CREATE tests // --------------------------------------------------------------- // Success outcomes @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void create(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -117,7 +117,7 @@ public class ContactServiceTest extends AbstractServiceTestImpl { ContactClient client = new ContactClient(); String identifier = createIdentifier(); PoxPayloadOut multipart = - ContactClientUtils.createContactInstance(identifier, client.getCommonPartName()); + ContactClientUtils.createContactInstance(identifier, client.getCommonPartName()); ClientResponse res = client.create(multipart); int statusCode = res.getStatus(); @@ -128,7 +128,7 @@ public class ContactServiceTest extends AbstractServiceTestImpl { // Specifically: // Does it fall within the set of valid status codes? // Does it exactly match the expected status code? - if(logger.isDebugEnabled()){ + if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), @@ -137,7 +137,7 @@ public class ContactServiceTest 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); @@ -150,10 +150,10 @@ public class ContactServiceTest extends AbstractServiceTestImpl { } @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); } } @@ -163,115 +163,114 @@ public class ContactServiceTest extends AbstractServiceTestImpl { // See Issue CSPACE-401. @Override public void createWithEmptyEntityBody(String testName) throws Exception { - //Should this really be empty? + //Should this really be empty? } @Override public void createWithMalformedXml(String testName) throws Exception { - //Should this really be empty?? + //Should this really be empty?? } @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(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 = ""; - 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(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 = ""; + 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(); - - // 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(); + + // 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 @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()) { @@ -287,7 +286,7 @@ public class ContactServiceTest 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), @@ -302,8 +301,8 @@ public class ContactServiceTest extends AbstractServiceTestImpl { // Failure outcomes @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()) { @@ -319,7 +318,7 @@ public class ContactServiceTest 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), @@ -332,8 +331,8 @@ public class ContactServiceTest extends AbstractServiceTestImpl { // --------------------------------------------------------------- // Success outcomes @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"read"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + dependsOnMethods = {"read"}) public void readList(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -344,13 +343,13 @@ public class ContactServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. ContactClient client = new ContactClient(); - ClientResponse res = client.readList(); - ContactsCommonList list = res.getEntity(); + ClientResponse res = client.readList(); + AbstractCommonList list = res.getEntity(); int statusCode = res.getStatus(); // 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), @@ -359,19 +358,8 @@ public class ContactServiceTest extends AbstractServiceTestImpl { // Optionally output additional data about list members for debugging. boolean iterateThroughList = false; - if(iterateThroughList && logger.isDebugEnabled()){ - List items = - list.getContactListItem(); - int i = 0; - for(ContactsCommonList.ContactListItem item : items){ - logger.debug(testName + ": list-item[" + i + "] csid=" + - item.getCsid()); - logger.debug(testName + ": list-item[" + i + "] objectNumber=" + - item.getAddressPlace()); - logger.debug(testName + ": list-item[" + i + "] URI=" + - item.getUri()); - i++; - } + if (iterateThroughList && logger.isDebugEnabled()) { + AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); } } @@ -383,8 +371,8 @@ public class ContactServiceTest extends AbstractServiceTestImpl { // --------------------------------------------------------------- // Success outcomes @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()) { @@ -396,27 +384,56 @@ public class ContactServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. ContactClient client = new ContactClient(); 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); } PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); ContactsCommon contact = (ContactsCommon) extractPart(input, client.getCommonPartName(), ContactsCommon.class); Assert.assertNotNull(contact); - - // Update the content of this resource. - contact.setAddressType("updated-" + contact.getAddressType()); - contact.setAddressPlace("updated-" + contact.getAddressPlace()); - contact.setEmail("updated-" + contact.getEmail()); + if(logger.isDebugEnabled()){ + logger.debug("contact common before updating"); + logger.debug(BaseServiceTest.objectAsXmlString(contact, ContactsCommon.class)); + } + + // Verify the contents of this resource + EmailGroupList emailGroupList = contact.getEmailGroupList(); + Assert.assertNotNull(emailGroupList); + List emailGroups = emailGroupList.getEmailGroup(); + Assert.assertNotNull(emailGroups); + Assert.assertTrue(emailGroups.size() > 0); + String email = emailGroups.get(0).getEmail(); + Assert.assertNotNull(email); + + AddressGroupList addressGroupList = contact.getAddressGroupList(); + Assert.assertNotNull(addressGroupList); + List addressGroups = addressGroupList.getAddressGroup(); + Assert.assertNotNull(addressGroups); + Assert.assertTrue(addressGroups.size() > 0); + String addressType = addressGroups.get(0).getAddressType(); + String addressPlace1 = addressGroups.get(0).getAddressPlace1(); + Assert.assertNotNull(addressType); + Assert.assertNotNull(addressPlace1); + + // Update the contents of this resource. + emailGroups.get(0).setEmail("updated-" + email); + contact.setEmailGroupList(emailGroupList); + + addressGroups.get(0).setAddressType("updated-" + addressType); + addressGroups.get(0).setAddressPlace1("updated-" + addressPlace1); + contact.setAddressGroupList(addressGroupList); + + if (logger.isDebugEnabled()) { logger.debug("to be updated object"); - logger.debug(objectAsXmlString(contact, ContactsCommon.class)); + logger.debug(BaseServiceTest.objectAsXmlString(contact, ContactsCommon.class)); } + // Submit the request to the service and store the response. PoxPayloadOut output = new PoxPayloadOut(ContactClient.SERVICE_PAYLOAD_NAME); PayloadOutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE); @@ -425,22 +442,27 @@ public class ContactServiceTest extends AbstractServiceTestImpl { res = client.update(knownResourceId, output); int statusCode = res.getStatus(); // Check the status code of the response: does it match the expected response(s)? - if(logger.isDebugEnabled()){ + 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()); ContactsCommon updatedContact = (ContactsCommon) extractPart(input, - client.getCommonPartName(), ContactsCommon.class); + client.getCommonPartName(), ContactsCommon.class); Assert.assertNotNull(updatedContact); - - Assert.assertEquals(updatedContact.getEmail(), - contact.getEmail(), + + if (logger.isDebugEnabled()) { + logger.debug("object after update"); + logger.debug(objectAsXmlString(updatedContact, ContactsCommon.class)); + } + + Assert.assertNotNull(updatedContact.getEmailGroupList().getEmailGroup().get(0)); + Assert.assertEquals(updatedContact.getEmailGroupList().getEmailGroup().get(0).getEmail(), + contact.getEmailGroupList().getEmailGroup().get(0).getEmail(), "Data in updated object did not match submitted data."); } @@ -450,114 +472,113 @@ public class ContactServiceTest extends AbstractServiceTestImpl { // See Issue CSPACE-401. @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?? } @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(testName, logger); - - // 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(testName, logger); + + // 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); } */ - @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()) { @@ -578,7 +599,7 @@ public class ContactServiceTest 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), @@ -591,8 +612,8 @@ public class ContactServiceTest extends AbstractServiceTestImpl { // --------------------------------------------------------------- // Success outcomes @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()) { @@ -608,7 +629,7 @@ public class ContactServiceTest 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), @@ -618,8 +639,8 @@ public class ContactServiceTest extends AbstractServiceTestImpl { // Failure outcomes @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()) { @@ -635,7 +656,7 @@ public class ContactServiceTest 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), @@ -663,9 +684,9 @@ public class ContactServiceTest 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); diff --git a/services/contact/jaxb/src/main/java/org/collectionspace/services/contact/ContactJAXBSchema.java b/services/contact/jaxb/src/main/java/org/collectionspace/services/contact/ContactJAXBSchema.java index 22834c93d..8cd3d7aa5 100644 --- a/services/contact/jaxb/src/main/java/org/collectionspace/services/contact/ContactJAXBSchema.java +++ b/services/contact/jaxb/src/main/java/org/collectionspace/services/contact/ContactJAXBSchema.java @@ -7,16 +7,20 @@ package org.collectionspace.services.contact; * */ public interface ContactJAXBSchema { + final static String CONTACTS_COMMON = "contacts_common"; final static String CSID = "csid"; - final static String IN_AUTHORITY = "inAuthority"; - final static String IN_ITEM ="inItem"; + final static String IN_AUTHORITY = "inAuthority"; + final static String IN_ITEM = "inItem"; + final static String DISPLAY_NAME = "displayName"; + + final static String EMAIL_GROUP_LIST = "emailGroupList"; + final static String EMAIL = "email"; + final static String TELEPHONE_NUMBER_GROUP_LIST = "telephoneNumberGroupList"; + final static String TELEPHONE_NUMBER = "telephoneNumber"; + final static String FAX_NUMBER = "faxNumber"; + final static String WEB = "web"; + final static String ADDRESS_GROUP_LIST = "addressGroupList"; final static String ADDRESS_TYPE = "addressType"; - final static String ADDRESS_PLACE = "addressPlace"; - final static String WEB = "web"; - final static String EMAIL = "email"; - final static String TELEPHONE_NUMBER = "telephoneNumber"; - final static String FAX_NUMBER = "faxNumber"; + final static String ADDRESS_PLACE_1 = "addressPlace1"; } - - diff --git a/services/contact/jaxb/src/main/resources/contacts-common.xsd b/services/contact/jaxb/src/main/resources/contacts-common.xsd index 37cc196ef..81ca55008 100644 --- a/services/contact/jaxb/src/main/resources/contacts-common.xsd +++ b/services/contact/jaxb/src/main/resources/contacts-common.xsd @@ -33,49 +33,86 @@ - - - - - - + + + + + + - - - - - - - + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/contact/service/src/main/java/org/collectionspace/services/contact/AuthorityResourceWithContacts.java b/services/contact/service/src/main/java/org/collectionspace/services/contact/AuthorityResourceWithContacts.java index 949299df5..529a07b14 100644 --- a/services/contact/service/src/main/java/org/collectionspace/services/contact/AuthorityResourceWithContacts.java +++ b/services/contact/service/src/main/java/org/collectionspace/services/contact/AuthorityResourceWithContacts.java @@ -47,9 +47,9 @@ import org.collectionspace.services.common.document.DocumentFilter; import org.collectionspace.services.common.document.DocumentHandler; import org.collectionspace.services.contact.ContactResource; import org.collectionspace.services.contact.ContactsCommon; -import org.collectionspace.services.contact.ContactsCommonList; import org.collectionspace.services.contact.ContactJAXBSchema; import org.collectionspace.services.contact.nuxeo.ContactDocumentModelHandler; +import org.collectionspace.services.jaxb.AbstractCommonList; import org.jboss.resteasy.util.HttpResponseCodes; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -60,32 +60,31 @@ import org.slf4j.LoggerFactory; @Consumes("application/xml") @Produces("application/xml") public abstract class AuthorityResourceWithContacts extends //FIXME: REM - Why is this resource in this package instead of somewhere in 'common'? - AuthorityResource { + AuthorityResource { private ContactResource contactResource = new ContactResource(); // Warning: ContactResource is a singleton. - final Logger logger = LoggerFactory.getLogger(AuthorityResourceWithContacts.class); - public AuthorityResourceWithContacts( - Class authCommonClass, Class resourceClass, - String authorityCommonSchemaName, String authorityItemCommonSchemaName) { - super(authCommonClass, resourceClass, - authorityCommonSchemaName, authorityItemCommonSchemaName); - } + public AuthorityResourceWithContacts( + Class authCommonClass, Class resourceClass, + String authorityCommonSchemaName, String authorityItemCommonSchemaName) { + super(authCommonClass, resourceClass, + authorityCommonSchemaName, authorityItemCommonSchemaName); + } - public abstract String getItemServiceName(); + public abstract String getItemServiceName(); public String getContactServiceName() { return contactResource.getServiceName(); } private DocumentHandler createContactDocumentHandler( - ServiceContext ctx, String inAuthority, + ServiceContext ctx, String inAuthority, String inItem) throws Exception { - ContactDocumentModelHandler docHandler = (ContactDocumentModelHandler)createDocumentHandler( - ctx, - ctx.getCommonPartLabel(getContactServiceName()), - ContactsCommon.class); + ContactDocumentModelHandler docHandler = (ContactDocumentModelHandler) createDocumentHandler( + ctx, + ctx.getCommonPartLabel(getContactServiceName()), + ContactsCommon.class); docHandler.setInAuthority(inAuthority); docHandler.setInItem(inItem); return docHandler; @@ -93,8 +92,8 @@ public abstract class AuthorityResourceWithContacts /************************************************************************* * Contact parts - this is a sub-resource of the AuthorityItem - * @param parentspecifier either a CSID or one of the urn forms - * @param itemspecifier either a CSID or one of the urn forms + * @param parentspecifier either a CSID or one of the urn forms + * @param itemspecifier either a CSID or one of the urn forms * @return contact *************************************************************************/ @POST @@ -104,7 +103,7 @@ public abstract class AuthorityResourceWithContacts @PathParam("itemcsid") String itemspecifier, String xmlPayload) { try { - PoxPayloadIn input = new PoxPayloadIn(xmlPayload); + PoxPayloadIn input = new PoxPayloadIn(xmlPayload); String parentcsid = lookupParentCSID(parentspecifier, "createContact(authority)", "CREATE_ITEM_CONTACT", null); ServiceContext itemCtx = createServiceContext(getItemServiceName()); @@ -112,7 +111,7 @@ public abstract class AuthorityResourceWithContacts // Note that we have to create the service context and document // handler for the Contact service, not the main service. - ServiceContext ctx = createServiceContext(getContactServiceName(), input); + ServiceContext ctx = createServiceContext(getContactServiceName(), input); DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid); String csid = getRepositoryClient(ctx).create(ctx, handler); UriBuilder path = UriBuilder.fromResource(resourceClass); @@ -121,17 +120,17 @@ public abstract class AuthorityResourceWithContacts return response; } catch (Exception e) { throw bigReThrow(e, - "Create Contact failed; one of the requested specifiers for authority:" - +parentspecifier+": and item:"+itemspecifier+": was not found.", - itemspecifier); + "Create Contact failed; one of the requested specifiers for authority:" + + parentspecifier + ": and item:" + itemspecifier + ": was not found.", + itemspecifier); } } /** * Gets the contact list. * - * @param parentspecifier either a CSID or one of the urn forms - * @param itemspecifier either a CSID or one of the urn forms + * @param parentspecifier either a CSID or one of the urn forms + * @param itemspecifier either a CSID or one of the urn forms * @param ui the ui * * @return the contact list @@ -139,11 +138,11 @@ public abstract class AuthorityResourceWithContacts @GET @Produces({"application/xml"}) @Path("{parentcsid}/items/{itemcsid}/contacts/") - public ContactsCommonList getContactList( + public AbstractCommonList getContactList( @PathParam("parentcsid") String parentspecifier, @PathParam("itemcsid") String itemspecifier, @Context UriInfo ui) { - ContactsCommonList contactObjectList = new ContactsCommonList(); + AbstractCommonList contactObjectList = new AbstractCommonList(); try { String parentcsid = lookupParentCSID(parentspecifier, "getContactList(parent)", "GET_CONTACT_LIST", null); @@ -151,24 +150,24 @@ public abstract class AuthorityResourceWithContacts String itemcsid = lookupItemCSID(itemspecifier, parentcsid, "getContactList(item)", "GET_CONTACT_LIST", itemCtx); MultivaluedMap queryParams = ui.getQueryParameters(); - ServiceContext ctx = createServiceContext(getContactServiceName(), queryParams); + ServiceContext ctx = createServiceContext(getContactServiceName(), queryParams); DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid); DocumentFilter myFilter = handler.getDocumentFilter(); //new DocumentFilter(); - myFilter.appendWhereClause(ContactJAXBSchema.CONTACTS_COMMON + ":" + - ContactJAXBSchema.IN_AUTHORITY + - "='" + parentcsid + "'" + - IQueryManager.SEARCH_QUALIFIER_AND + - ContactJAXBSchema.CONTACTS_COMMON + ":" + - ContactJAXBSchema.IN_ITEM + - "='" + itemcsid + "'", - IQueryManager.SEARCH_QUALIFIER_AND); // "AND" this clause to any existing + myFilter.appendWhereClause(ContactJAXBSchema.CONTACTS_COMMON + ":" + + ContactJAXBSchema.IN_AUTHORITY + + "='" + parentcsid + "'" + + IQueryManager.SEARCH_QUALIFIER_AND + + ContactJAXBSchema.CONTACTS_COMMON + ":" + + ContactJAXBSchema.IN_ITEM + + "='" + itemcsid + "'", + IQueryManager.SEARCH_QUALIFIER_AND); // "AND" this clause to any existing getRepositoryClient(ctx).getFiltered(ctx, handler); - contactObjectList = (ContactsCommonList) handler.getCommonPartList(); + contactObjectList = (AbstractCommonList) handler.getCommonPartList(); } catch (Exception e) { throw bigReThrow(e, - "Get ContactList failed; one of the requested specifiers for authority:" - +parentspecifier+": and item:"+itemspecifier+": was not found.", - itemspecifier); + "Get ContactList failed; one of the requested specifiers for authority:" + + parentspecifier + ": and item:" + itemspecifier + ": was not found.", + itemspecifier); } return contactObjectList; } @@ -176,8 +175,8 @@ public abstract class AuthorityResourceWithContacts /** * Gets the contact. * - * @param parentspecifier either a CSID or one of the urn forms - * @param itemspecifier either a CSID or one of the urn forms + * @param parentspecifier either a CSID or one of the urn forms + * @param itemspecifier either a CSID or one of the urn forms * @param csid the csid * * @return the contact @@ -188,7 +187,7 @@ public abstract class AuthorityResourceWithContacts @PathParam("parentcsid") String parentspecifier, @PathParam("itemcsid") String itemspecifier, @PathParam("csid") String csid) { - PoxPayloadOut result = null; + PoxPayloadOut result = null; try { String parentcsid = lookupParentCSID(parentspecifier, "getContact(parent)", "GET_ITEM_CONTACT", null); @@ -196,20 +195,18 @@ public abstract class AuthorityResourceWithContacts String itemcsid = lookupItemCSID(itemspecifier, parentcsid, "getContact(item)", "GET_ITEM_CONTACT", itemCtx); // Note that we have to create the service context and document handler for the Contact service, not the main service. - ServiceContext ctx = createServiceContext(getContactServiceName()); + ServiceContext ctx = createServiceContext(getContactServiceName()); DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid); getRepositoryClient(ctx).get(ctx, csid, handler); result = ctx.getOutput(); } catch (Exception e) { - throw bigReThrow(e, "Get failed, the requested Contact CSID:" + csid + - ": or one of the specifiers for authority:"+parentspecifier+ - ": and item:"+itemspecifier+": was not found.", - csid); + throw bigReThrow(e, "Get failed, the requested Contact CSID:" + csid + + ": or one of the specifiers for authority:" + parentspecifier + + ": and item:" + itemspecifier + ": was not found.", + csid); } if (result == null) { - Response response = Response.status(Response.Status.NOT_FOUND) - .entity("Get failed, the requested Contact CSID:" + csid + ": was not found.") - .type("text/plain").build(); + Response response = Response.status(Response.Status.NOT_FOUND).entity("Get failed, the requested Contact CSID:" + csid + ": was not found.").type("text/plain").build(); throw new WebApplicationException(response); } return result.toXML(); @@ -218,8 +215,8 @@ public abstract class AuthorityResourceWithContacts /** * Update contact. * - * @param parentspecifier either a CSID or one of the urn forms - * @param itemspecifier either a CSID or one of the urn forms + * @param parentspecifier either a CSID or one of the urn forms + * @param itemspecifier either a CSID or one of the urn forms * @param csid the csid * * @return the multipart output @@ -231,25 +228,25 @@ public abstract class AuthorityResourceWithContacts @PathParam("itemcsid") String itemspecifier, @PathParam("csid") String csid, String xmlPayload) { - PoxPayloadOut result = null; + PoxPayloadOut result = null; try { - PoxPayloadIn theUpdate = new PoxPayloadIn(xmlPayload); - String parentcsid = lookupParentCSID(parentspecifier, "updateContact(authority)", "UPDATE_CONTACT", null); + PoxPayloadIn theUpdate = new PoxPayloadIn(xmlPayload); + String parentcsid = lookupParentCSID(parentspecifier, "updateContact(authority)", "UPDATE_CONTACT", null); ServiceContext itemCtx = createServiceContext(getItemServiceName()); String itemcsid = lookupItemCSID(itemspecifier, parentcsid, "updateContact(item)", "UPDATE_CONTACT", itemCtx); ServiceContext ctx = null; // Note that we have to create the service context and document handler for the Contact service, not the main service. - ctx = createServiceContext(getContactServiceName(), theUpdate); + ctx = createServiceContext(getContactServiceName(), theUpdate); DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid); getRepositoryClient(ctx).update(ctx, csid, handler); result = ctx.getOutput(); } catch (Exception e) { - throw bigReThrow(e, "Update failed, the requested Contact CSID:" + csid + - ": or one of the specifiers for authority:"+parentspecifier+ - ": and item:"+itemspecifier+": was not found.", - csid); + throw bigReThrow(e, "Update failed, the requested Contact CSID:" + csid + + ": or one of the specifiers for authority:" + parentspecifier + + ": and item:" + itemspecifier + ": was not found.", + csid); } return result.toXML(); } @@ -257,8 +254,8 @@ public abstract class AuthorityResourceWithContacts /** * Delete contact. * - * @param parentspecifier either a CSID or one of the urn forms - * @param itemspecifier either a CSID or one of the urn forms + * @param parentspecifier either a CSID or one of the urn forms + * @param itemspecifier either a CSID or one of the urn forms * @param csid the csid * * @return the response @@ -270,7 +267,7 @@ public abstract class AuthorityResourceWithContacts @PathParam("itemcsid") String itemspecifier, @PathParam("csid") String csid) { try { - String parentcsid = lookupParentCSID(parentspecifier, "deleteContact(authority)", "DELETE_CONTACT", null); + String parentcsid = lookupParentCSID(parentspecifier, "deleteContact(authority)", "DELETE_CONTACT", null); ServiceContext itemCtx = createServiceContext(getItemServiceName()); String itemcsid = lookupItemCSID(itemspecifier, parentcsid, "deleteContact(item)", "DELETE_CONTACT", itemCtx); @@ -278,14 +275,13 @@ public abstract class AuthorityResourceWithContacts ServiceContext ctx = null; // Note that we have to create the service context for the Contact service, not the main service. - ctx = createServiceContext(getContactServiceName()); + ctx = createServiceContext(getContactServiceName()); getRepositoryClient(ctx).delete(ctx, csid); return Response.status(HttpResponseCodes.SC_OK).build(); - } catch (Exception e) { - throw bigReThrow(e, "DELETE failed, the requested Contact CSID:" + csid + - ": or one of the specifiers for authority:"+parentspecifier+ - ": and item:"+itemspecifier+": was not found.", csid); + } catch (Exception e) { + throw bigReThrow(e, "DELETE failed, the requested Contact CSID:" + csid + + ": or one of the specifiers for authority:" + parentspecifier + + ": and item:" + itemspecifier + ": was not found.", csid); } } - } diff --git a/services/contact/service/src/main/java/org/collectionspace/services/contact/nuxeo/ContactDocumentModelHandler.java b/services/contact/service/src/main/java/org/collectionspace/services/contact/nuxeo/ContactDocumentModelHandler.java index c4c5dc406..b1d4cc9ec 100644 --- a/services/contact/service/src/main/java/org/collectionspace/services/contact/nuxeo/ContactDocumentModelHandler.java +++ b/services/contact/service/src/main/java/org/collectionspace/services/contact/nuxeo/ContactDocumentModelHandler.java @@ -23,24 +23,15 @@ */ package org.collectionspace.services.contact.nuxeo; -import java.util.Iterator; -import java.util.List; import java.util.Map; import org.collectionspace.services.contact.ContactJAXBSchema; -import org.collectionspace.services.common.document.DocumentHandler.Action; import org.collectionspace.services.common.document.DocumentWrapper; +import org.collectionspace.services.nuxeo.client.java.DocHandlerBase; import org.collectionspace.services.common.service.ObjectPartType; -import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema; import org.collectionspace.services.contact.ContactsCommon; -import org.collectionspace.services.contact.ContactsCommonList; -import org.collectionspace.services.contact.ContactsCommonList.ContactListItem; -import org.collectionspace.services.jaxb.AbstractCommonList; -import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl; -import org.collectionspace.services.nuxeo.util.NuxeoUtils; import org.nuxeo.ecm.core.api.DocumentModel; -import org.nuxeo.ecm.core.api.DocumentModelList; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -48,21 +39,14 @@ import org.slf4j.LoggerFactory; * The Class ContactDocumentModelHandler. */ public class ContactDocumentModelHandler - extends RemoteDocumentModelHandlerImpl { + extends DocHandlerBase { - /** The logger. */ private final Logger logger = LoggerFactory.getLogger(ContactDocumentModelHandler.class); - - /** The contact. */ - private ContactsCommon contact; - - /** The contact list. */ - private ContactsCommonList contactList; - - /** The in authority. */ + private static final String COMMON_PART_LABEL = "contacts_common"; private String inAuthority; - - /** + private String inItem; + + /** * Gets the in authority. * * @return the in authority @@ -74,15 +58,12 @@ public class ContactDocumentModelHandler /** * Sets the in authority. * - * @param inAuthority the new in authority + * @param inAuthority the new in item */ public void setInAuthority(String inAuthority) { this.inAuthority = inAuthority; } - /** The in item. */ - private String inItem; - /** * Gets the in item. * @@ -106,11 +87,12 @@ public class ContactDocumentModelHandler */ @Override public void handleCreate(DocumentWrapper wrapDoc) throws Exception { - // first fill all the parts of the document - super.handleCreate(wrapDoc); - handleInAuthority(wrapDoc.getWrappedObject()); + // first fill all the parts of the document + super.handleCreate(wrapDoc); + handleInAuthority(wrapDoc.getWrappedObject()); + // handleDisplayNames(wrapDoc.getWrappedObject()); } - + /** * Check the logic around the parent pointer. Note that we only need do this on * create, since we have logic to make this read-only on update. @@ -120,110 +102,89 @@ public class ContactDocumentModelHandler * @throws Exception the exception */ private void handleInAuthority(DocumentModel docModel) throws Exception { - String commonPartLabel = getServiceContext().getCommonPartLabel("contacts"); - docModel.setProperty(commonPartLabel, - ContactJAXBSchema.IN_AUTHORITY, inAuthority); - docModel.setProperty(commonPartLabel, - ContactJAXBSchema.IN_ITEM, inItem); + String commonPartLabel = getServiceContext().getCommonPartLabel("contacts"); + docModel.setProperty(commonPartLabel, + ContactJAXBSchema.IN_AUTHORITY, inAuthority); + docModel.setProperty(commonPartLabel, + ContactJAXBSchema.IN_ITEM, inItem); } - /* (non-Javadoc) - * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#getCommonPart() - */ - @Override - public ContactsCommon getCommonPart() { - return contact; + private void handleDisplayNames(DocumentModel docModel) throws Exception { + String commonPartLabel = getServiceContext().getCommonPartLabel("contacts"); + String email = getStringValueInPrimaryRepeatingComplexProperty( + docModel, commonPartLabel, ContactJAXBSchema.EMAIL_GROUP_LIST, + ContactJAXBSchema.EMAIL); + String telephoneNumber = getStringValueInPrimaryRepeatingComplexProperty( + docModel, commonPartLabel, ContactJAXBSchema.TELEPHONE_NUMBER_GROUP_LIST, + ContactJAXBSchema.TELEPHONE_NUMBER); + String addressPlace1 = getStringValueInPrimaryRepeatingComplexProperty( + docModel, commonPartLabel, ContactJAXBSchema.ADDRESS_GROUP_LIST, + ContactJAXBSchema.ADDRESS_PLACE_1); + String displayName = prepareDefaultDisplayName(email, telephoneNumber, addressPlace1); + docModel.setProperty(commonPartLabel, ContactJAXBSchema.DISPLAY_NAME, + displayName); } - /* (non-Javadoc) - * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPart(java.lang.Object) - */ - @Override - public void setCommonPart(ContactsCommon contact) { - this.contact = contact; - } - - /* (non-Javadoc) - * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#getCommonPartList() - */ - @Override - public ContactsCommonList getCommonPartList() { - return contactList; - } - - /* (non-Javadoc) - * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPartList(java.lang.Object) - */ - @Override - public void setCommonPartList(ContactsCommonList contactList) { - this.contactList = contactList; - } - - /* (non-Javadoc) - * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPart(org.collectionspace.services.common.document.DocumentWrapper) - */ - @Override - public ContactsCommon extractCommonPart(DocumentWrapper wrapDoc) - throws Exception { - throw new UnsupportedOperationException(); - } - - /* (non-Javadoc) - * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#fillCommonPart(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper) - */ - @Override - public void fillCommonPart(ContactsCommon contactObject, DocumentWrapper wrapDoc) throws Exception { - throw new UnsupportedOperationException(); - } - - /* (non-Javadoc) - * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPartList(org.collectionspace.services.common.document.DocumentWrapper) + /** + * Produces a default displayName from the basic name and foundingPlace fields. + * @see OrgAuthorityClientUtils.prepareDefaultDisplayName() which + * duplicates this logic, until we define a service-general utils package + * that is neither client nor service specific. + * @param shortName + * @param foundingPlace + * @return + * @throws Exception */ - @Override - public ContactsCommonList extractCommonPartList(DocumentWrapper wrapDoc) throws Exception { - ContactsCommonList coList = extractPagingInfo(new ContactsCommonList(), wrapDoc); - AbstractCommonList commonList = (AbstractCommonList) coList; - commonList.setFieldsReturned("addressPlace|uri|csid"); - List list = coList.getContactListItem(); - Iterator iter = wrapDoc.getWrappedObject().iterator(); - while(iter.hasNext()){ - DocumentModel docModel = iter.next(); - ContactListItem clistItem = new ContactListItem(); - // TODO Revisit which information unit(s) should be returned - // in each entry, in a list of contact information. - // See CSPACE-1018 - clistItem.setAddressPlace((String) docModel.getProperty(getServiceContext().getCommonPartLabel(), - ContactJAXBSchema.ADDRESS_PLACE)); - String id = getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString()); - clistItem.setUri(getServiceContextPath() + id); - clistItem.setCsid(id); - list.add(clistItem); + private static String prepareDefaultDisplayName(String email, + String telephoneNumber, String addressPlace1) throws Exception { + + final int MAX_DISPLAY_NAME_LENGTH = 30; + + StringBuilder newStr = new StringBuilder(""); + final String sep = " "; + boolean firstAdded = false; + + if (! email.isEmpty()) { + newStr.append(email); + firstAdded = true; + } + + if (! telephoneNumber.isEmpty() && newStr.length() <= MAX_DISPLAY_NAME_LENGTH) { + if (firstAdded) { + newStr.append(sep); + } else { + firstAdded = true; + } + newStr.append(telephoneNumber); + } + + if (! addressPlace1.isEmpty() && newStr.length() <= MAX_DISPLAY_NAME_LENGTH) { + if (firstAdded) { + newStr.append(sep); + } + newStr.append(addressPlace1); + } + + if (newStr.length() > MAX_DISPLAY_NAME_LENGTH) { + return newStr.toString().substring(0, MAX_DISPLAY_NAME_LENGTH) + "..."; + } else { + return newStr.toString(); } - - return coList; } - /* (non-Javadoc) - * @see org.collectionspace.services.common.document.AbstractMultipartDocumentHandlerImpl#getQProperty(java.lang.String) - */ - @Override - public String getQProperty(String prop) { - return ContactConstants.NUXEO_SCHEMA_NAME + ":" + prop; - } - /** * Filters out ContactJAXBSchema.IN_AUTHORITY, and IN_ITEM, to ensure that * the parent links remains untouched. + * Also remove the display name, as this is always computed. * @param objectProps the properties parsed from the update payload * @param partMeta metadata for the object to fill */ @Override public void filterReadOnlyPropertiesForPart( - Map objectProps, ObjectPartType partMeta) { - super.filterReadOnlyPropertiesForPart(objectProps, partMeta); - objectProps.remove(ContactJAXBSchema.IN_AUTHORITY); - objectProps.remove(ContactJAXBSchema.IN_ITEM); + Map objectProps, ObjectPartType partMeta) { + super.filterReadOnlyPropertiesForPart(objectProps, partMeta); + objectProps.remove(ContactJAXBSchema.IN_AUTHORITY); + objectProps.remove(ContactJAXBSchema.IN_ITEM); + objectProps.remove(ContactJAXBSchema.DISPLAY_NAME); } - } - diff --git a/services/location/client/src/test/java/org/collectionspace/services/client/test/LocationAuthorityServiceTest.java b/services/location/client/src/test/java/org/collectionspace/services/client/test/LocationAuthorityServiceTest.java index 5083f02eb..c2e8b68b2 100644 --- a/services/location/client/src/test/java/org/collectionspace/services/client/test/LocationAuthorityServiceTest.java +++ b/services/location/client/src/test/java/org/collectionspace/services/client/test/LocationAuthorityServiceTest.java @@ -30,14 +30,10 @@ import java.util.Map; import org.collectionspace.services.LocationJAXBSchema; import org.collectionspace.services.client.AuthorityClient; import org.collectionspace.services.client.CollectionSpaceClient; -import org.collectionspace.services.client.ContactClient; -import org.collectionspace.services.client.ContactClientUtils; import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.common.AbstractCommonListUtils; -import org.collectionspace.services.contact.ContactsCommon; -import org.collectionspace.services.contact.ContactsCommonList; import org.collectionspace.services.client.LocationAuthorityClient; import org.collectionspace.services.client.LocationAuthorityClientUtils; import org.collectionspace.services.jaxb.AbstractCommonList; diff --git a/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityServiceTest.java b/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityServiceTest.java index dcb5a1336..8529b975f 100644 --- a/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityServiceTest.java +++ b/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityServiceTest.java @@ -38,8 +38,9 @@ import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.common.AbstractCommonListUtils; +import org.collectionspace.services.contact.AddressGroup; +import org.collectionspace.services.contact.AddressGroupList; import org.collectionspace.services.contact.ContactsCommon; -import org.collectionspace.services.contact.ContactsCommonList; import org.collectionspace.services.client.OrgAuthorityClient; import org.collectionspace.services.client.OrgAuthorityClientUtils; import org.collectionspace.services.jaxb.AbstractCommonList; @@ -71,53 +72,46 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: private final String REFNAME = "refName"; private final String DISPLAYNAME = "displayName"; - @Override - public String getServicePathComponent() { - return OrgAuthorityClient.SERVICE_PATH_COMPONENT; - } + @Override + public String getServicePathComponent() { + return OrgAuthorityClient.SERVICE_PATH_COMPONENT; + } - @Override - protected String getServiceName() { - return OrgAuthorityClient.SERVICE_NAME; - } - + @Override + protected String getServiceName() { + return OrgAuthorityClient.SERVICE_NAME; + } /** The test organization shortname. */ private final String TEST_ORG_SHORTNAME = "Test Org"; - /** The test organization founding place. */ private final String TEST_ORG_FOUNDING_PLACE = "Anytown, USA"; - // Hold some values for a recently created item to verify upon read. private String knownResourceId = null; private String knownResourceShortIdentifer = null; private String knownResourceRefName = null; private String knownItemResourceId = null; private String knownItemResourceShortIdentifer = null; - /** The known contact resource id. */ private String knownContactResourceId = null; - /** The n items to create in list. */ private int nItemsToCreateInList = 3; - /** The all item resource ids created. */ private Map allItemResourceIdsCreated = - new HashMap(); - + new HashMap(); /** The all contact resource ids created. */ private Map allContactResourceIdsCreated = - new HashMap(); - - protected void setKnownResource( String id, String shortIdentifer, - String refName ) { - knownResourceId = id; - knownResourceShortIdentifer = shortIdentifer; - knownResourceRefName = refName; + new HashMap(); + + protected void setKnownResource(String id, String shortIdentifer, + String refName) { + knownResourceId = id; + knownResourceShortIdentifer = shortIdentifer; + knownResourceRefName = refName; } - protected void setKnownItemResource( String id, String shortIdentifer ) { - knownItemResourceId = id; - knownItemResourceShortIdentifer = shortIdentifer; + protected void setKnownItemResource(String id, String shortIdentifer) { + knownItemResourceId = id; + knownItemResourceShortIdentifer = shortIdentifer; } /* (non-Javadoc) @@ -125,9 +119,9 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: */ @Override protected CollectionSpaceClient getClientInstance() { - return new OrgAuthorityClient(); + return new OrgAuthorityClient(); } - + // --------------------------------------------------------------- // CRUD tests : CREATE tests // --------------------------------------------------------------- @@ -136,8 +130,8 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String) */ @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"create"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"create"}) public void create(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -152,37 +146,37 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: OrgAuthorityClient client = new OrgAuthorityClient(); String shortId = createIdentifier(); String displayName = "displayName-" + shortId; - String baseRefName = OrgAuthorityClientUtils.createOrgAuthRefName(shortId, null); - PoxPayloadOut multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance( - displayName, shortId, client.getCommonPartName()); - - String newID = null; - ClientResponse res = client.create(multipart); + String baseRefName = OrgAuthorityClientUtils.createOrgAuthRefName(shortId, null); + PoxPayloadOut multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance( + displayName, shortId, client.getCommonPartName()); + + 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 = OrgAuthorityClientUtils.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 = OrgAuthorityClientUtils.extractId(res); } finally { - res.releaseConnection(); + res.releaseConnection(); } - + // Store the ID returned from the first resource created // for additional tests below. - if (knownResourceId == null){ - setKnownResource( newID, shortId, baseRefName ); + if (knownResourceId == null) { + setKnownResource(newID, shortId, baseRefName); if (logger.isDebugEnabled()) { logger.debug(testName + ": knownResourceId=" + knownResourceId); } @@ -194,34 +188,34 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: @Override protected PoxPayloadOut createInstance(String identifier) { - OrgAuthorityClient client = new OrgAuthorityClient(); + OrgAuthorityClient client = new OrgAuthorityClient(); String displayName = "displayName-" + identifier; PoxPayloadOut multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance( displayName, identifier, client.getCommonPartName()); return multipart; } - + @Override - protected PoxPayloadOut createItemInstance(String parentCsid, String identifier) { - String headerLabel = new OrgAuthorityClient().getItemCommonPartName(); + protected PoxPayloadOut createItemInstance(String parentCsid, String identifier) { + String headerLabel = new OrgAuthorityClient().getItemCommonPartName(); String shortId = "testOrg"; - Map testOrgMap = new HashMap(); + Map testOrgMap = new HashMap(); testOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, shortId); testOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, TEST_ORG_SHORTNAME); testOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "The real official test organization"); testOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "May 26, 1907"); testOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, TEST_ORG_FOUNDING_PLACE); - return OrgAuthorityClientUtils.createOrganizationInstance(identifier, testOrgMap, headerLabel); + return OrgAuthorityClientUtils.createOrganizationInstance(identifier, testOrgMap, headerLabel); } - + /** * Creates the item. * * @param testName the test name */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"create"}, dependsOnMethods = {"create"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"create"}, dependsOnMethods = {"create"}) public void createItem(String testName) { setupCreate(); String newID = createItemInAuthority(knownResourceId, knownResourceRefName); @@ -237,26 +231,26 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: private String createItemInAuthority(String vcsid, String authRefName) { final String testName = "createItemInAuthority"; - if(logger.isDebugEnabled()){ + if (logger.isDebugEnabled()) { logger.debug(testName + ":..."); } // Submit the request to the service and store the response. OrgAuthorityClient client = new OrgAuthorityClient(); String shortId = "testOrg"; - Map testOrgMap = new HashMap(); + Map testOrgMap = new HashMap(); testOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, shortId); testOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, TEST_ORG_SHORTNAME); testOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "The real official test organization"); testOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "May 26, 1907"); testOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, TEST_ORG_FOUNDING_PLACE); - - Map> testOrgRepeatablesMap = new HashMap>(); + + Map> testOrgRepeatablesMap = new HashMap>(); List testOrgContactNames = new ArrayList(); testOrgContactNames.add("joe@example.org"); testOrgContactNames.add("sally@example.org"); testOrgRepeatablesMap.put(OrganizationJAXBSchema.CONTACT_NAMES, testOrgContactNames); - + MainBodyGroupList mainBodyList = new MainBodyGroupList(); List mainBodyGroups = mainBodyList.getMainBodyGroup(); MainBodyGroup mainBodyGroup = new MainBodyGroup(); @@ -265,12 +259,12 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: mainBodyGroups.add(mainBodyGroup); String newID = OrgAuthorityClientUtils.createItemInAuthority( - vcsid, authRefName, testOrgMap, testOrgRepeatablesMap, mainBodyList, client); - + vcsid, authRefName, testOrgMap, testOrgRepeatablesMap, mainBodyList, client); + // Store the ID returned from the first item resource created // for additional tests below. - if (knownItemResourceId == null){ - setKnownItemResource(newID, shortId); + if (knownItemResourceId == null) { + setKnownItemResource(newID, shortId); if (logger.isDebugEnabled()) { logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId); } @@ -289,21 +283,21 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * * @param testName the test name */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"create"}, dependsOnMethods = {"createItem"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"create"}, dependsOnMethods = {"createItem"}) public void createContact(String testName) { setupCreate(); String newID = createContactInItem(knownResourceId, knownItemResourceId); } - /** - * Creates the contact in item. - * - * @param parentcsid the parentcsid - * @param itemcsid the itemcsid - * @return the string - */ - private String createContactInItem(String parentcsid, String itemcsid) { + /** + * Creates the contact in item. + * + * @param parentcsid the parentcsid + * @param itemcsid the itemcsid + * @return the string + */ + private String createContactInItem(String parentcsid, String itemcsid) { final String testName = "createContactInItem"; if (logger.isDebugEnabled()) { @@ -315,31 +309,31 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: OrgAuthorityClient client = new OrgAuthorityClient(); String identifier = createIdentifier(); PoxPayloadOut multipart = - ContactClientUtils.createContactInstance(parentcsid, - itemcsid, identifier, new ContactClient().getCommonPartName()); - + ContactClientUtils.createContactInstance(parentcsid, + itemcsid, identifier, new ContactClient().getCommonPartName()); + String newID = null; ClientResponse res = - client.createContact(parentcsid, itemcsid, multipart); + client.createContact(parentcsid, itemcsid, 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); - - newID = OrgAuthorityClientUtils.extractId(res); + 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); + + newID = OrgAuthorityClientUtils.extractId(res); } finally { - res.releaseConnection(); + res.releaseConnection(); } // Store the ID returned from the first contact resource created // for additional tests below. - if (knownContactResourceId == null){ + if (knownContactResourceId == null) { knownContactResourceId = newID; if (logger.isDebugEnabled()) { logger.debug(testName + ": knownContactResourceId=" + knownContactResourceId); @@ -355,7 +349,6 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: } // Failure outcomes - // Placeholders until the three tests below can be uncommented. // See Issue CSPACE-401. /* (non-Javadoc) @@ -363,7 +356,7 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: */ @Override public void createWithEmptyEntityBody(String testName) throws Exception { - //Should this really be empty? + //Should this really be empty? } /* (non-Javadoc) @@ -371,7 +364,7 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: */ @Override public void createWithMalformedXml(String testName) throws Exception { - //Should this really be empty? + //Should this really be empty? } /* (non-Javadoc) @@ -379,108 +372,107 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: */ @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, - groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"}) + groups = {"create"}, 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(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. + 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(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, - groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"}) + groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"}) public void createWithMalformedXml(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupCreateWithMalformedXml(); - - // 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(); + + // 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, - groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"}) + groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"}) public void createWithWrongXmlSchema(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupCreateWithWrongXmlSchema(); - - // 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(); + + // 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 : CREATE LIST tests // --------------------------------------------------------------- // Success outcomes /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String) - */ -@Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"createList"}, dependsOnGroups = {"create"}) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String) + */ + @Override + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"createList"}, dependsOnGroups = {"create"}) public void createList(String testName) throws Exception { for (int i = 0; i < nItemsToCreateInList; i++) { create(testName); @@ -493,8 +485,8 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"createList"}, dependsOnMethods = {"createList"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"createList"}, dependsOnMethods = {"createList"}) public void createItemList(String testName) throws Exception { // Add items to the initially-created, known parent record. for (int j = 0; j < nItemsToCreateInList; j++) { @@ -508,8 +500,8 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"createList"}, dependsOnMethods = {"createItemList"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"createList"}, dependsOnMethods = {"createItemList"}) public void createContactList(String testName) throws Exception { // Add contacts to the initially-created, known item record. for (int j = 0; j < nItemsToCreateInList; j++) { @@ -525,10 +517,10 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String) */ @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"read"}, dependsOnGroups = {"create"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"read"}, dependsOnGroups = {"create"}) public void read(String testName) throws Exception { - readInternal(testName, knownResourceId, null); + readInternal(testName, knownResourceId, null); } /** @@ -537,12 +529,12 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"read"}, dependsOnGroups = {"create"}) - public void readByName(String testName) throws Exception { - readInternal(testName, null, knownResourceShortIdentifer); + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"read"}, dependsOnGroups = {"create"}) + public void readByName(String testName) throws Exception { + readInternal(testName, null, knownResourceShortIdentifer); } - + protected void readInternal(String testName, String CSID, String shortId) { if (logger.isDebugEnabled()) { @@ -554,35 +546,38 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: // Submit the request to the service and store the response. OrgAuthorityClient client = new OrgAuthorityClient(); ClientResponse res = null; - if(CSID!=null) { + if (CSID != null) { res = client.read(CSID); - } else if(shortId!=null) { - res = client.readByName(shortId); + } else if (shortId != null) { + res = client.readByName(shortId); } else { - Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null"); + Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-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); - //FIXME: remove the following try catch once Aron fixes signatures - try { - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input, - new OrgAuthorityClient().getCommonPartName(), OrgauthoritiesCommon.class); - Assert.assertNotNull(orgAuthority); - } catch (Exception e) { - throw new RuntimeException(e); - } + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if (logger.isDebugEnabled()) { + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + //FIXME: remove the following try catch once Aron fixes signatures + try { + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input, + new OrgAuthorityClient().getCommonPartName(), OrgauthoritiesCommon.class); + if (logger.isDebugEnabled()) { + logger.debug(objectAsXmlString(orgAuthority, OrgauthoritiesCommon.class)); + } + Assert.assertNotNull(orgAuthority); + } catch (Exception e) { + throw new RuntimeException(e); + } } finally { - res.releaseConnection(); + res.releaseConnection(); } } @@ -592,8 +587,8 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"readItem"}, dependsOnGroups = {"read"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"readItem"}, dependsOnGroups = {"read"}) public void readItem(String testName) throws Exception { readItemInternal(testName, knownResourceId, null, knownItemResourceId, null); } @@ -607,20 +602,19 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * @param testName the test name * @throws Exception the exception @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"readItem"}, dependsOnGroups = {"read"}) + groups = {"readItem"}, dependsOnGroups = {"read"}) public void readItemInNamedAuth(String testName) throws Exception { - readItemInternal(testName, null, knownResourceShortIdentifer, knownItemResourceId, null); + readItemInternal(testName, null, knownResourceShortIdentifer, knownItemResourceId, null); } */ - /** * Read named item. * * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"readItem"}, dependsOnGroups = {"read"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"readItem"}, dependsOnGroups = {"read"}) public void readNamedItem(String testName) throws Exception { readItemInternal(testName, knownResourceId, null, null, knownItemResourceShortIdentifer); } @@ -631,15 +625,15 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"readItem"}, dependsOnGroups = {"read"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"readItem"}, dependsOnGroups = {"read"}) public void readNamedItemInNamedAuth(String testName) throws Exception { readItemInternal(testName, null, knownResourceShortIdentifer, null, knownItemResourceShortIdentifer); } - protected void readItemInternal(String testName, - String authCSID, String authShortId, String itemCSID, String itemShortId) - throws Exception { + protected void readItemInternal(String testName, + String authCSID, String authShortId, String itemCSID, String itemShortId) + throws Exception { if (logger.isDebugEnabled()) { logger.debug(testBanner(testName, CLASS_NAME)); @@ -650,59 +644,59 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: // Submit the request to the service and store the response. OrgAuthorityClient client = new OrgAuthorityClient(); ClientResponse res = null; - if(authCSID!=null) { - if(itemCSID!=null) { + if (authCSID != null) { + if (itemCSID != null) { res = client.readItem(authCSID, itemCSID); - } else if(itemShortId!=null) { - res = client.readNamedItem(authCSID, itemShortId); + } else if (itemShortId != null) { + res = client.readNamedItem(authCSID, itemShortId); } else { - Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null"); + Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null"); } - } else if(authShortId!=null) { - if(itemCSID!=null) { + } else if (authShortId != null) { + if (itemCSID != null) { res = client.readItemInNamedAuthority(authShortId, itemCSID); - } else if(itemShortId!=null) { - res = client.readNamedItemInNamedAuthority(authShortId, itemShortId); + } else if (itemShortId != null) { + res = client.readNamedItemInNamedAuthority(authShortId, itemShortId); } else { - Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null"); + Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null"); } } else { - Assert.fail("readInternal: Internal error. One of authCSID or authShortId must be non-null"); + Assert.fail("readInternal: Internal error. One of authCSID or authShortId must be non-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); - - // Check whether we've received a organization. - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - OrganizationsCommon organization = (OrganizationsCommon) extractPart(input, - client.getItemCommonPartName(), OrganizationsCommon.class); - Assert.assertNotNull(organization); - boolean showFull = true; - if(showFull && logger.isDebugEnabled()){ - logger.debug(testName + ": returned payload:"); - logger.debug(objectAsXmlString(organization, OrganizationsCommon.class)); - } - - // Check that the organization item is within the expected OrgAuthority. - Assert.assertEquals(organization.getInAuthority(), knownResourceId); - - // Verify the number and contents of values in a repeatable field, - // as created in the instance record used for testing. - List contactNames = organization.getContactNames().getContactName(); - Assert.assertTrue(contactNames.size() > 0); - Assert.assertNotNull(contactNames.get(0)); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if (logger.isDebugEnabled()) { + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Check whether we've received a organization. + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + OrganizationsCommon organization = (OrganizationsCommon) extractPart(input, + client.getItemCommonPartName(), OrganizationsCommon.class); + Assert.assertNotNull(organization); + boolean showFull = true; + if (showFull && logger.isDebugEnabled()) { + logger.debug(testName + ": returned payload:"); + logger.debug(objectAsXmlString(organization, OrganizationsCommon.class)); + } + + // Check that the organization item is within the expected OrgAuthority. + Assert.assertEquals(organization.getInAuthority(), knownResourceId); + + // Verify the number and contents of values in a repeatable field, + // as created in the instance record used for testing. + List contactNames = organization.getContactNames().getContactName(); + Assert.assertTrue(contactNames.size() > 0); + Assert.assertNotNull(contactNames.get(0)); } finally { - res.releaseConnection(); + res.releaseConnection(); } } @@ -712,8 +706,8 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"readItem", "updateItem"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + dependsOnMethods = {"readItem", "updateItem"}) public void verifyItemDisplayName(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -727,33 +721,33 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: PoxPayloadIn input = null; ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); try { - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Check whether organization has expected displayName. - input = 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); + + // Check whether organization has expected displayName. + input = new PoxPayloadIn(res.getEntity()); } finally { - res.releaseConnection(); + res.releaseConnection(); } - + OrganizationsCommon organization = (OrganizationsCommon) extractPart(input, client.getItemCommonPartName(), OrganizationsCommon.class); Assert.assertNotNull(organization); String displayName = organization.getDisplayName(); // Make sure displayName matches computed form - String expectedDisplayName = - OrgAuthorityClientUtils.prepareDefaultDisplayName( + String expectedDisplayName = + OrgAuthorityClientUtils.prepareDefaultDisplayName( TEST_ORG_SHORTNAME, TEST_ORG_FOUNDING_PLACE); Assert.assertNotNull(displayName, expectedDisplayName); - + // Update the shortName and verify the computed name is updated. organization.setCsid(null); organization.setDisplayNameComputed(true); @@ -766,9 +760,9 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: mainBodyGroups.add(mainBodyGroup); organization.setMainBodyGroupList(mainBodyList); - expectedDisplayName = - OrgAuthorityClientUtils.prepareDefaultDisplayName( - updatedShortName, TEST_ORG_FOUNDING_PLACE); + expectedDisplayName = + OrgAuthorityClientUtils.prepareDefaultDisplayName( + updatedShortName, TEST_ORG_FOUNDING_PLACE); // Submit the updated resource to the service and store the response. PoxPayloadOut output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); @@ -776,25 +770,25 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: commonPart.setLabel(client.getItemCommonPartName()); res = client.updateItem(knownResourceId, knownItemResourceId, 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("updateItem: status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Retrieve the updated resource and verify that its contents exist. - input = 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("updateItem: status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Retrieve the updated resource and verify that its contents exist. + input = new PoxPayloadIn(res.getEntity()); } finally { - res.releaseConnection(); + res.releaseConnection(); } - + OrganizationsCommon updatedOrganization = (OrganizationsCommon) extractPart(input, - client.getItemCommonPartName(), OrganizationsCommon.class); + client.getItemCommonPartName(), OrganizationsCommon.class); Assert.assertNotNull(updatedOrganization); // Verify that the updated resource received the correct data. @@ -806,7 +800,7 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: // Verify that the updated resource computes the right displayName. Assert.assertEquals(updatedOrganization.getDisplayName(), expectedDisplayName, - "Updated ShortName in Organization not reflected in computed DisplayName."); + "Updated ShortName in Organization not reflected in computed DisplayName."); // Now Update the displayName, not computed and verify the computed name is overriden. organization.setDisplayNameComputed(false); @@ -819,25 +813,25 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: commonPart.setLabel(client.getItemCommonPartName()); res = client.updateItem(knownResourceId, knownItemResourceId, 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("updateItem: status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Retrieve the updated resource and verify that its contents exist. - input = 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("updateItem: status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Retrieve the updated resource and verify that its contents exist. + input = new PoxPayloadIn(res.getEntity()); } finally { - res.releaseConnection(); + res.releaseConnection(); } - + updatedOrganization = (OrganizationsCommon) extractPart(input, - client.getItemCommonPartName(), OrganizationsCommon.class); + client.getItemCommonPartName(), OrganizationsCommon.class); Assert.assertNotNull(updatedOrganization); // Verify that the updated resource received the correct data. @@ -845,7 +839,7 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: "Updated displayNameComputed in Organization did not match submitted data."); // Verify that the updated resource computes the right displayName. Assert.assertEquals(updatedOrganization.getDisplayName(), - expectedDisplayName, + expectedDisplayName, "Updated DisplayName (not computed) in Organization not stored."); } @@ -855,8 +849,8 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"verifyItemDisplayName"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + dependsOnMethods = {"verifyItemDisplayName"}) public void verifyIllegalItemDisplayName(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -864,50 +858,50 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: } // Perform setup. testSetup(STATUS_BAD_REQUEST, ServiceRequestType.UPDATE); - // setupUpdateWithWrongXmlSchema(testName, logger); + // setupUpdateWithWrongXmlSchema(testName, logger); // Submit the request to the service and store the response. OrgAuthorityClient client = new OrgAuthorityClient(); ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); try { - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode()); - - // Check whether organization has expected displayName. - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - OrganizationsCommon organization = (OrganizationsCommon) extractPart(input, - client.getItemCommonPartName(), OrganizationsCommon.class); - Assert.assertNotNull(organization); - // Try to Update with computed false and no displayName - organization.setDisplayNameComputed(false); - organization.setDisplayName(null); - - // Submit the updated resource to the service and store the response. - PoxPayloadOut output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); - PayloadOutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getItemCommonPartName()); - res.releaseConnection(); - res = client.updateItem(knownResourceId, knownItemResourceId, output); - statusCode = res.getStatus(); - - // Check the status code of the response: does it match the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug("updateItem: status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } finally { - res.releaseConnection(); - } + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if (logger.isDebugEnabled()) { + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode()); + + // Check whether organization has expected displayName. + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + OrganizationsCommon organization = (OrganizationsCommon) extractPart(input, + client.getItemCommonPartName(), OrganizationsCommon.class); + Assert.assertNotNull(organization); + // Try to Update with computed false and no displayName + organization.setDisplayNameComputed(false); + organization.setDisplayName(null); + + // Submit the updated resource to the service and store the response. + PoxPayloadOut output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); + PayloadOutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE); + commonPart.setLabel(client.getItemCommonPartName()); + res.releaseConnection(); + res = client.updateItem(knownResourceId, knownItemResourceId, output); + statusCode = res.getStatus(); + + // Check the status code of the response: does it match the expected response(s)? + if (logger.isDebugEnabled()) { + logger.debug("updateItem: status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } } /** @@ -916,8 +910,8 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"readItem"}, dependsOnMethods = {"readItem"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"readItem"}, dependsOnMethods = {"readItem"}) public void readContact(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -929,35 +923,35 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: // Submit the request to the service and store the response. OrgAuthorityClient client = new OrgAuthorityClient(); ClientResponse res = - client.readContact(knownResourceId, knownItemResourceId, - knownContactResourceId); + client.readContact(knownResourceId, knownItemResourceId, + knownContactResourceId); try { - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Check whether we've received a contact. - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - ContactsCommon contact = (ContactsCommon) extractPart(input, - new ContactClient().getCommonPartName(), ContactsCommon.class); - Assert.assertNotNull(contact); - boolean showFull = true; - if(showFull && logger.isDebugEnabled()){ - logger.debug(testName + ": returned payload:"); - logger.debug(objectAsXmlString(contact, ContactsCommon.class)); - } - Assert.assertEquals(contact.getInAuthority(), knownResourceId); - Assert.assertEquals(contact.getInItem(), knownItemResourceId); - } finally { - res.releaseConnection(); - } + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if (logger.isDebugEnabled()) { + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Check whether we've received a contact. + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + ContactsCommon contact = (ContactsCommon) extractPart(input, + new ContactClient().getCommonPartName(), ContactsCommon.class); + Assert.assertNotNull(contact); + boolean showFull = true; + if (showFull && logger.isDebugEnabled()) { + logger.debug(testName + ": returned payload:"); + logger.debug(objectAsXmlString(contact, ContactsCommon.class)); + } + Assert.assertEquals(contact.getInAuthority(), knownResourceId); + Assert.assertEquals(contact.getInItem(), knownItemResourceId); + } finally { + res.releaseConnection(); + } } // Failure outcomes @@ -965,8 +959,8 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String) */ @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"read"}, dependsOnMethods = {"read"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"read"}, dependsOnMethods = {"read"}) public void readNonExistent(String testName) { if (logger.isDebugEnabled()) { @@ -979,19 +973,19 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: OrgAuthorityClient client = new OrgAuthorityClient(); 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); - } finally { - res.releaseConnection(); - } + 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(); + } } /** @@ -999,8 +993,8 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * * @param testName the test name */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"readItem"}, dependsOnMethods = {"readItem"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"readItem"}, dependsOnMethods = {"readItem"}) public void readItemNonExistent(String testName) { if (logger.isDebugEnabled()) { @@ -1013,19 +1007,19 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: OrgAuthorityClient client = new OrgAuthorityClient(); ClientResponse res = client.readItem(knownResourceId, 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); - } finally { - res.releaseConnection(); - } + 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(); + } } /** @@ -1033,8 +1027,8 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * * @param testName the test name */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"readItem"}, dependsOnMethods = {"readContact"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"readItem"}, dependsOnMethods = {"readContact"}) public void readContactNonExistent(String testName) { if (logger.isDebugEnabled()) { @@ -1046,21 +1040,21 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: // Submit the request to the service and store the response. OrgAuthorityClient client = new OrgAuthorityClient(); ClientResponse res = - client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID); + client.readContact(knownResourceId, knownItemResourceId, 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); - } finally { - res.releaseConnection(); - } + 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(); + } } // --------------------------------------------------------------- @@ -1072,8 +1066,8 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String) */ @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"readList"}, dependsOnGroups = {"createList", "read"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"readList"}, dependsOnGroups = {"createList", "read"}) public void readList(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -1086,25 +1080,25 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: OrgAuthorityClient client = new OrgAuthorityClient(); ClientResponse res = client.readList(); try { - AbstractCommonList 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); - - // Optionally output additional data about list members for debugging. - if(logger.isTraceEnabled()){ - AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); - } - } finally { - res.releaseConnection(); - } + AbstractCommonList 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); + + // Optionally output additional data about list members for debugging. + if (logger.isTraceEnabled()) { + AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); + } + } finally { + res.releaseConnection(); + } } /** @@ -1142,56 +1136,56 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: // Submit the request to the service and store the response. OrgAuthorityClient client = new OrgAuthorityClient(); ClientResponse res = null; - if(vcsid!= null) { - res = client.readItemList(vcsid, null, null); - } else if(name!= null) { - res = client.readItemListForNamedAuthority(name, null, null); + if (vcsid != null) { + res = client.readItemList(vcsid, null, null); + } else if (name != null) { + res = client.readItemListForNamedAuthority(name, null, null); } else { - Assert.fail("readItemList passed null csid and name!"); + Assert.fail("readItemList passed null csid and name!"); } try { - AbstractCommonList 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 items = - list.getListItem(); - int nItemsReturned = items.size(); - // There will be one item created, associated with a - // known parent resource, by the createItem test. - // - // In addition, there will be 'nItemsToCreateInList' - // additional items created by the createItemList test, - // all associated with the same parent resource. - int nExpectedItems = nItemsToCreateInList + 1; - if(logger.isDebugEnabled()){ - logger.debug(testName + ": Expected " - + nExpectedItems +" items; got: "+nItemsReturned); - } - Assert.assertEquals(nItemsReturned, nExpectedItems); - + AbstractCommonList 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 items = + list.getListItem(); + int nItemsReturned = items.size(); + // There will be one item created, associated with a + // known parent resource, by the createItem test. + // + // In addition, there will be 'nItemsToCreateInList' + // additional items created by the createItemList test, + // all associated with the same parent resource. + int nExpectedItems = nItemsToCreateInList + 1; + if (logger.isDebugEnabled()) { + logger.debug(testName + ": Expected " + + nExpectedItems + " items; got: " + nItemsReturned); + } + Assert.assertEquals(nItemsReturned, nExpectedItems); + for (AbstractCommonList.ListItem item : items) { - String value = - AbstractCommonListUtils.ListItemGetElementValue(item, REFNAME); + String value = + AbstractCommonListUtils.ListItemGetElementValue(item, REFNAME); Assert.assertTrue((null != value), "Item refName is null!"); - value = - AbstractCommonListUtils.ListItemGetElementValue(item, DISPLAYNAME); + value = + AbstractCommonListUtils.ListItemGetElementValue(item, DISPLAYNAME); Assert.assertTrue((null != value), "Item displayName is null!"); } - if(logger.isTraceEnabled()){ - AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); + if (logger.isTraceEnabled()) { + AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); } - } finally { - res.releaseConnection(); - } + } finally { + res.releaseConnection(); + } } /** @@ -1219,60 +1213,50 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: // Submit the request to the service and store the response. OrgAuthorityClient client = new OrgAuthorityClient(); - ContactsCommonList list = null; - ClientResponse res = + AbstractCommonList list = null; + ClientResponse res = client.readContactList(parentcsid, itemcsid); try { - 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 listitems = - list.getContactListItem(); - int nItemsReturned = listitems.size(); - // There will be one item created, associated with a - // known parent resource, by the createItem test. - // - // In addition, there will be 'nItemsToCreateInList' - // additional items created by the createItemList test, - // all associated with the same parent resource. - int nExpectedItems = nItemsToCreateInList + 1; - if(logger.isDebugEnabled()){ - logger.debug(testName + ": Expected " - + nExpectedItems +" items; got: "+nItemsReturned); - } - Assert.assertEquals(nItemsReturned, nExpectedItems); - - int i = 0; - for (ContactsCommonList.ContactListItem listitem : listitems) { - // Optionally output additional data about list members for debugging. - boolean showDetails = false; - if (showDetails && logger.isDebugEnabled()) { - logger.debug(" " + testName + ": list-item[" + i + "] csid=" + - listitem.getCsid()); - logger.debug(" " + testName + ": list-item[" + i + "] addressPlace=" + - listitem.getAddressPlace()); - logger.debug(" " + testName + ": list-item[" + i + "] URI=" + - listitem.getUri()); - } - i++; - } - } finally { - res.releaseConnection(); - } + 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 listitems = + list.getListItem(); + int nItemsReturned = listitems.size(); + // There will be one item created, associated with a + // known parent resource, by the createItem test. + // + // In addition, there will be 'nItemsToCreateInList' + // additional items created by the createItemList test, + // all associated with the same parent resource. + int nExpectedItems = nItemsToCreateInList + 1; + if (logger.isDebugEnabled()) { + logger.debug(testName + ": Expected " + + nExpectedItems + " items; got: " + nItemsReturned); + } + Assert.assertEquals(nItemsReturned, nExpectedItems); + + // Optionally output additional data about list members for debugging. + boolean iterateThroughList = false; + if (iterateThroughList && logger.isDebugEnabled()) { + AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); + } + } finally { + res.releaseConnection(); + } } // Failure outcomes // None at present. - // --------------------------------------------------------------- // CRUD tests : UPDATE tests // --------------------------------------------------------------- @@ -1281,8 +1265,8 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String) */ @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"update"}, dependsOnGroups = {"read", "readList"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"update"}, dependsOnGroups = {"read", "readList"}) public void update(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -1296,57 +1280,57 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: ClientResponse res = client.read(knownResourceId); try { - if(logger.isDebugEnabled()){ - logger.debug(testName + ": read status = " + res.getStatus()); - } - Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); - - if(logger.isDebugEnabled()){ - logger.debug("got OrgAuthority to update with ID: " + knownResourceId); - } - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input, - client.getCommonPartName(), OrgauthoritiesCommon.class); - Assert.assertNotNull(orgAuthority); - - // Update the contents of this resource. - orgAuthority.setDisplayName("updated-" + orgAuthority.getDisplayName()); - orgAuthority.setVocabType("updated-" + orgAuthority.getVocabType()); - if(logger.isDebugEnabled()){ - logger.debug("to be updated OrgAuthority"); - logger.debug(objectAsXmlString(orgAuthority, OrgauthoritiesCommon.class)); - } - - // Submit the updated resource to the service and store the response. - PoxPayloadOut output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_PAYLOAD_NAME); - PayloadOutputPart commonPart = output.addPart(orgAuthority, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getCommonPartName()); - res.releaseConnection(); - res = client.update(knownResourceId, output); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Retrieve the updated resource and verify that its contents exist. - input = new PoxPayloadIn(res.getEntity()); - OrgauthoritiesCommon updatedOrgAuthority = - (OrgauthoritiesCommon) extractPart(input, - client.getCommonPartName(), OrgauthoritiesCommon.class); - Assert.assertNotNull(updatedOrgAuthority); - - // Verify that the updated resource received the correct data. - Assert.assertEquals(updatedOrgAuthority.getDisplayName(), - orgAuthority.getDisplayName(), - "Data in updated object did not match submitted data."); - } finally { - res.releaseConnection(); - } + if (logger.isDebugEnabled()) { + logger.debug(testName + ": read status = " + res.getStatus()); + } + Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); + + if (logger.isDebugEnabled()) { + logger.debug("got OrgAuthority to update with ID: " + knownResourceId); + } + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input, + client.getCommonPartName(), OrgauthoritiesCommon.class); + Assert.assertNotNull(orgAuthority); + + // Update the contents of this resource. + orgAuthority.setDisplayName("updated-" + orgAuthority.getDisplayName()); + orgAuthority.setVocabType("updated-" + orgAuthority.getVocabType()); + if (logger.isDebugEnabled()) { + logger.debug("to be updated OrgAuthority"); + logger.debug(objectAsXmlString(orgAuthority, OrgauthoritiesCommon.class)); + } + + // Submit the updated resource to the service and store the response. + PoxPayloadOut output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_PAYLOAD_NAME); + PayloadOutputPart commonPart = output.addPart(orgAuthority, MediaType.APPLICATION_XML_TYPE); + commonPart.setLabel(client.getCommonPartName()); + res.releaseConnection(); + res = client.update(knownResourceId, output); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match the expected response(s)? + if (logger.isDebugEnabled()) { + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Retrieve the updated resource and verify that its contents exist. + input = new PoxPayloadIn(res.getEntity()); + OrgauthoritiesCommon updatedOrgAuthority = + (OrgauthoritiesCommon) extractPart(input, + client.getCommonPartName(), OrgauthoritiesCommon.class); + Assert.assertNotNull(updatedOrgAuthority); + + // Verify that the updated resource received the correct data. + Assert.assertEquals(updatedOrgAuthority.getDisplayName(), + orgAuthority.getDisplayName(), + "Data in updated object did not match submitted data."); + } finally { + res.releaseConnection(); + } } /** @@ -1355,8 +1339,8 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"update"}, dependsOnMethods = {"update"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"update"}, dependsOnMethods = {"update"}) public void updateItem(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -1370,69 +1354,69 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); try { - if(logger.isDebugEnabled()){ - logger.debug(testName + ": read status = " + res.getStatus()); - } - Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); - - if(logger.isDebugEnabled()){ - logger.debug("got Organization to update with ID: " + - knownItemResourceId + - " in OrgAuthority: " + knownResourceId ); - } - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - OrganizationsCommon organization = (OrganizationsCommon) extractPart(input, - client.getItemCommonPartName(), OrganizationsCommon.class); - Assert.assertNotNull(organization); - - // Update the contents of this resource. - organization.setCsid(null); - - MainBodyGroupList mainBodyList = organization.getMainBodyGroupList(); - Assert.assertNotNull(mainBodyList); - List mainBodyGroups = mainBodyList.getMainBodyGroup(); - Assert.assertTrue(mainBodyList.getMainBodyGroup().size() > 0); - String updatedShortName = "updated-" + mainBodyGroups.get(0).getShortName(); - mainBodyGroups.get(0).setShortName(updatedShortName); - - if(logger.isDebugEnabled()){ - logger.debug("to be updated Organization"); - logger.debug(objectAsXmlString(organization, - OrganizationsCommon.class)); - } - - // Submit the updated resource to the service and store the response. - PoxPayloadOut output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); - PayloadOutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(client.getItemCommonPartName()); - res.releaseConnection(); - res = client.updateItem(knownResourceId, knownItemResourceId, output); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Retrieve the updated resource and verify that its contents exist. - input = new PoxPayloadIn(res.getEntity()); - OrganizationsCommon updatedOrganization = - (OrganizationsCommon) extractPart(input, - client.getItemCommonPartName(), OrganizationsCommon.class); - Assert.assertNotNull(updatedOrganization); - - // Verify that the updated resource received the correct data. - mainBodyList = organization.getMainBodyGroupList(); - Assert.assertNotNull(mainBodyList); - Assert.assertTrue(mainBodyList.getMainBodyGroup().size() > 0); - Assert.assertEquals(updatedOrganization.getMainBodyGroupList().getMainBodyGroup().get(0).getShortName(), - updatedShortName, "Data in updated Organization did not match submitted data."); - } finally { - res.releaseConnection(); - } + if (logger.isDebugEnabled()) { + logger.debug(testName + ": read status = " + res.getStatus()); + } + Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); + + if (logger.isDebugEnabled()) { + logger.debug("got Organization to update with ID: " + + knownItemResourceId + + " in OrgAuthority: " + knownResourceId); + } + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + OrganizationsCommon organization = (OrganizationsCommon) extractPart(input, + client.getItemCommonPartName(), OrganizationsCommon.class); + Assert.assertNotNull(organization); + + // Update the contents of this resource. + organization.setCsid(null); + + MainBodyGroupList mainBodyList = organization.getMainBodyGroupList(); + Assert.assertNotNull(mainBodyList); + List mainBodyGroups = mainBodyList.getMainBodyGroup(); + Assert.assertTrue(mainBodyList.getMainBodyGroup().size() > 0); + String updatedShortName = "updated-" + mainBodyGroups.get(0).getShortName(); + mainBodyGroups.get(0).setShortName(updatedShortName); + + if (logger.isDebugEnabled()) { + logger.debug("to be updated Organization"); + logger.debug(objectAsXmlString(organization, + OrganizationsCommon.class)); + } + + // Submit the updated resource to the service and store the response. + PoxPayloadOut output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); + PayloadOutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE); + commonPart.setLabel(client.getItemCommonPartName()); + res.releaseConnection(); + res = client.updateItem(knownResourceId, knownItemResourceId, output); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match the expected response(s)? + if (logger.isDebugEnabled()) { + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Retrieve the updated resource and verify that its contents exist. + input = new PoxPayloadIn(res.getEntity()); + OrganizationsCommon updatedOrganization = + (OrganizationsCommon) extractPart(input, + client.getItemCommonPartName(), OrganizationsCommon.class); + Assert.assertNotNull(updatedOrganization); + + // Verify that the updated resource received the correct data. + mainBodyList = organization.getMainBodyGroupList(); + Assert.assertNotNull(mainBodyList); + Assert.assertTrue(mainBodyList.getMainBodyGroup().size() > 0); + Assert.assertEquals(updatedOrganization.getMainBodyGroupList().getMainBodyGroup().get(0).getShortName(), + updatedShortName, "Data in updated Organization did not match submitted data."); + } finally { + res.releaseConnection(); + } } /** @@ -1441,8 +1425,8 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"update"}, dependsOnMethods = {"updateItem"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"update"}, dependsOnMethods = {"updateItem"}) public void updateContact(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -1456,60 +1440,71 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: ClientResponse res = client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId); try { - if(logger.isDebugEnabled()){ - logger.debug(testName + ": read status = " + res.getStatus()); - } - Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); - - if(logger.isDebugEnabled()){ - logger.debug("got Contact to update with ID: " + - knownContactResourceId + - " in item: " + knownItemResourceId + - " in parent: " + knownResourceId ); - } - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - ContactsCommon contact = (ContactsCommon) extractPart(input, - new ContactClient().getCommonPartName(), ContactsCommon.class); - Assert.assertNotNull(contact); - - // Update the contents of this resource. - contact.setAddressPlace("updated-" + contact.getAddressPlace()); - if(logger.isDebugEnabled()){ - logger.debug("to be updated Contact"); - logger.debug(objectAsXmlString(contact, - ContactsCommon.class)); - } - - // Submit the updated resource to the service and store the response. - PoxPayloadOut output = new PoxPayloadOut(ContactClient.SERVICE_PAYLOAD_NAME); - PayloadOutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(new ContactClient().getCommonPartName()); - res.releaseConnection(); - res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Retrieve the updated resource and verify that its contents exist. - input = new PoxPayloadIn(res.getEntity()); - ContactsCommon updatedContact = - (ContactsCommon) extractPart(input, - new ContactClient().getCommonPartName(), ContactsCommon.class); - Assert.assertNotNull(updatedContact); - - // Verify that the updated resource received the correct data. - Assert.assertEquals(updatedContact.getAddressPlace(), - contact.getAddressPlace(), - "Data in updated Contact did not match submitted data."); - } finally { - res.releaseConnection(); - } + if (logger.isDebugEnabled()) { + logger.debug(testName + ": read status = " + res.getStatus()); + } + Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); + + if (logger.isDebugEnabled()) { + logger.debug("got Contact to update with ID: " + + knownContactResourceId + + " in item: " + knownItemResourceId + + " in parent: " + knownResourceId); + } + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + ContactsCommon contact = (ContactsCommon) extractPart(input, + new ContactClient().getCommonPartName(), ContactsCommon.class); + Assert.assertNotNull(contact); + + // Verify the contents of this resource + AddressGroupList addressGroupList = contact.getAddressGroupList(); + Assert.assertNotNull(addressGroupList); + List addressGroups = addressGroupList.getAddressGroup(); + Assert.assertNotNull(addressGroups); + Assert.assertTrue(addressGroups.size() > 0); + String addressPlace1 = addressGroups.get(0).getAddressPlace1(); + Assert.assertNotNull(addressPlace1); + + // Update the contents of this resource. + addressGroups.get(0).setAddressPlace1("updated-" + addressPlace1); + contact.setAddressGroupList(addressGroupList); + if (logger.isDebugEnabled()) { + logger.debug("to be updated Contact"); + logger.debug(objectAsXmlString(contact, + ContactsCommon.class)); + } + + // Submit the updated resource to the service and store the response. + PoxPayloadOut output = new PoxPayloadOut(ContactClient.SERVICE_PAYLOAD_NAME); + PayloadOutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE); + commonPart.setLabel(new ContactClient().getCommonPartName()); + res.releaseConnection(); + res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match the expected response(s)? + if (logger.isDebugEnabled()) { + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Retrieve the updated resource and verify that its contents exist. + input = new PoxPayloadIn(res.getEntity()); + ContactsCommon updatedContact = + (ContactsCommon) extractPart(input, + new ContactClient().getCommonPartName(), ContactsCommon.class); + Assert.assertNotNull(updatedContact); + + // Verify that the updated resource received the correct data. + Assert.assertEquals(updatedContact.getAddressGroupList().getAddressGroup().get(0).getAddressPlace1(), + contact.getAddressGroupList().getAddressGroup().get(0).getAddressPlace1(), + "Data in updated object did not match submitted data."); + + } finally { + res.releaseConnection(); + } } // Failure outcomes @@ -1520,7 +1515,7 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: */ @Override public void updateWithEmptyEntityBody(String testName) throws Exception { - //Should this really be empty? + //Should this really be empty? } /* (non-Javadoc) @@ -1528,7 +1523,7 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: */ @Override public void updateWithMalformedXml(String testName) throws Exception { - //Should this really be empty? + //Should this really be empty? } /* (non-Javadoc) @@ -1536,101 +1531,101 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: */ @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, - groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"}) + groups = {"update"}, dependsOnMethods = {"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, - groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"}) + groups = {"update"}, dependsOnMethods = {"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); - } - - @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"}) - public void updateWithWrongXmlSchema(String testName) throws Exception { - - // Perform setup. - setupUpdateWithWrongXmlSchema(testName, logger); - - // 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("updateWithWrongXmlSchema: 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, + groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"}) + public void updateWithWrongXmlSchema(String testName) throws Exception { + + // Perform setup. + setupUpdateWithWrongXmlSchema(testName, logger); + + // 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("updateWithWrongXmlSchema: url=" + url + + " status=" + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); } -*/ + */ /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String) - */ -@Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"}) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String) + */ + @Override + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"}) public void updateNonExistent(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -1643,25 +1638,25 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: // Note: The ID used in this 'create' call may be arbitrary. // The only relevant ID may be the one used in update(), below. OrgAuthorityClient client = new OrgAuthorityClient(); - PoxPayloadOut multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance( - NON_EXISTENT_ID, NON_EXISTENT_ID, - new OrgAuthorityClient().getCommonPartName()); + PoxPayloadOut multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance( + NON_EXISTENT_ID, NON_EXISTENT_ID, + new OrgAuthorityClient().getCommonPartName()); 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); - } finally { - res.releaseConnection(); - } + 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(); + } } /** @@ -1670,8 +1665,8 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"}) public void updateNonExistentItem(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -1684,29 +1679,29 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: // Note: The ID(s) used when creating the request payload may be arbitrary. // The only relevant ID may be the one used in update(), below. OrgAuthorityClient client = new OrgAuthorityClient(); - Map nonexOrgMap = new HashMap(); + Map nonexOrgMap = new HashMap(); nonexOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, "nonExistent"); nonexOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "Non-existent"); - PoxPayloadOut multipart = - OrgAuthorityClientUtils.createOrganizationInstance( - knownResourceRefName, - nonexOrgMap, client.getItemCommonPartName() ); + PoxPayloadOut multipart = + OrgAuthorityClientUtils.createOrganizationInstance( + knownResourceRefName, + nonexOrgMap, client.getItemCommonPartName()); ClientResponse res = client.updateItem(knownResourceId, 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); - } finally { - res.releaseConnection(); - } + 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(); + } } /** @@ -1715,8 +1710,8 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"}) public void updateNonExistentContact(String testName) throws Exception { // Currently a no-op test } @@ -1725,18 +1720,16 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: // CRUD tests : DELETE tests // --------------------------------------------------------------- // Success outcomes - // Note: delete sub-resources in ascending hierarchical order, // before deleting their parents. - /** * Delete contact. * * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"}) public void deleteContact(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -1745,40 +1738,40 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: // Perform setup. setupDelete(); - if(logger.isDebugEnabled()){ - logger.debug("parentcsid =" + knownResourceId + - " itemcsid = " + knownItemResourceId + - " csid = " + knownContactResourceId); + if (logger.isDebugEnabled()) { + logger.debug("parentcsid =" + knownResourceId + + " itemcsid = " + knownItemResourceId + + " csid = " + knownContactResourceId); } // Submit the request to the service and store the response. OrgAuthorityClient client = new OrgAuthorityClient(); ClientResponse res = - client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId); + client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId); try { - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } finally { - res.releaseConnection(); - } - } - - /** - * Delete item. - * - * @param testName the test name - * @throws Exception the exception - */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"delete"}, dependsOnMethods = {"deleteContact"}) + 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(); + } + } + + /** + * Delete item. + * + * @param testName the test name + * @throws Exception the exception + */ + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"delete"}, dependsOnMethods = {"deleteContact"}) public void deleteItem(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -1787,36 +1780,36 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: // Perform setup. setupDelete(); - if(logger.isDebugEnabled()){ - logger.debug("parentcsid =" + knownResourceId + - " itemcsid = " + knownItemResourceId); + if (logger.isDebugEnabled()) { + logger.debug("parentcsid =" + knownResourceId + + " itemcsid = " + knownItemResourceId); } // Submit the request to the service and store the response. OrgAuthorityClient client = new OrgAuthorityClient(); ClientResponse res = client.deleteItem(knownResourceId, knownItemResourceId); try { - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } finally { - res.releaseConnection(); - } + 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(); + } } /* (non-Javadoc) * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String) */ @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"delete"}, dependsOnMethods = {"deleteItem"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"delete"}, dependsOnMethods = {"deleteItem"}) public void delete(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -1825,7 +1818,7 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: // Perform setup. setupDelete(); - if(logger.isDebugEnabled()){ + if (logger.isDebugEnabled()) { logger.debug("parentcsid =" + knownResourceId); } @@ -1833,19 +1826,19 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: OrgAuthorityClient client = new OrgAuthorityClient(); 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); - } finally { - res.releaseConnection(); - } + 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(); + } } // Failure outcomes @@ -1853,8 +1846,8 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String) */ @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"delete"}, dependsOnMethods = {"delete"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"delete"}, dependsOnMethods = {"delete"}) public void deleteNonExistent(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -1867,19 +1860,19 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: OrgAuthorityClient client = new OrgAuthorityClient(); 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); - } finally { - res.releaseConnection(); - } + 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(); + } } /** @@ -1887,8 +1880,8 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * * @param testName the test name */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"delete"}, dependsOnMethods = {"deleteItem"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"delete"}, dependsOnMethods = {"deleteItem"}) public void deleteNonExistentItem(String testName) { if (logger.isDebugEnabled()) { @@ -1901,19 +1894,19 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: OrgAuthorityClient client = new OrgAuthorityClient(); ClientResponse res = client.deleteItem(knownResourceId, 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); - } finally { - res.releaseConnection(); - } + 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(); + } } /** @@ -1921,8 +1914,8 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * * @param testName the test name */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"delete"}, dependsOnMethods = {"deleteContact"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"delete"}, dependsOnMethods = {"deleteContact"}) public void deleteNonExistentContact(String testName) { if (logger.isDebugEnabled()) { @@ -1934,21 +1927,21 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: // Submit the request to the service and store the response. OrgAuthorityClient client = new OrgAuthorityClient(); ClientResponse res = - client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID); + client.deleteContact(knownResourceId, knownItemResourceId, 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); - } finally { - res.releaseConnection(); - } + 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(); + } } // --------------------------------------------------------------- @@ -1971,9 +1964,9 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: // 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); @@ -1995,9 +1988,9 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: // Check the status code of the response: does it match // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug("testItemSubmitRequest: url=" + url + - " status=" + statusCode); + if (logger.isDebugEnabled()) { + logger.debug("testItemSubmitRequest: url=" + url + + " status=" + statusCode); } Assert.assertEquals(statusCode, EXPECTED_STATUS); @@ -2015,24 +2008,22 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: // Submit the request to the service and store the response. String method = ServiceRequestType.READ.httpMethodName(); String url = getContactResourceURL(knownResourceId, - knownItemResourceId, knownContactResourceId); + knownItemResourceId, knownContactResourceId); int statusCode = submitRequest(method, url); // Check the status code of the response: does it match // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug("testItemSubmitRequest: url=" + url + - " status=" + statusCode); + if (logger.isDebugEnabled()) { + logger.debug("testItemSubmitRequest: url=" + url + + " status=" + statusCode); } Assert.assertEquals(statusCode, EXPECTED_STATUS); } - // --------------------------------------------------------------- // Cleanup of resources created during testing // --------------------------------------------------------------- - /** * Deletes all resources created by tests, after all tests have been run. * @@ -2041,21 +2032,20 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * at any point during testing, even if some of those resources * may be expected to be deleted by certain tests. */ - - @AfterClass(alwaysRun=true) + @AfterClass(alwaysRun = true) @Override public void cleanUp() { String noTest = System.getProperty("noTestCleanup"); - if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { + if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { if (logger.isDebugEnabled()) { logger.debug("Skipping Cleanup phase ..."); } return; - } + } if (logger.isDebugEnabled()) { logger.debug("Cleaning up temporary resources created for testing ..."); } - + String parentResourceId; String itemResourceId; String contactResourceId; @@ -2068,7 +2058,7 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: // Note: Any non-success responses from the delete operation // below are ignored and not reported. ClientResponse res = - client.deleteContact(parentResourceId, itemResourceId, contactResourceId); + client.deleteContact(parentResourceId, itemResourceId, contactResourceId); res.releaseConnection(); } // Clean up item resources. @@ -2078,12 +2068,12 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: // Note: Any non-success responses from the delete operation // below are ignored and not reported. ClientResponse res = - client.deleteItem(parentResourceId, itemResourceId); + client.deleteItem(parentResourceId, itemResourceId); res.releaseConnection(); } // Clean up parent resources. super.cleanUp(); - + } // --------------------------------------------------------------- @@ -2142,7 +2132,6 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier; } - /** * Returns the root URL for the contact service. * @@ -2160,9 +2149,9 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * @return The root URL for the contact service. */ protected String getContactServiceRootURL(String parentResourceIdentifier, - String itemResourceIdentifier) { - return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/" + - getContactServicePathComponent(); + String itemResourceIdentifier) { + return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/" + + getContactServicePathComponent(); } /** @@ -2178,8 +2167,8 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: * @return The URL of a specific resource managed by a service. */ protected String getContactResourceURL(String parentResourceIdentifier, - String itemResourceIdentifier, String contactResourceIdentifier) { + String itemResourceIdentifier, String contactResourceIdentifier) { return getContactServiceRootURL(parentResourceIdentifier, - itemResourceIdentifier) + "/" + contactResourceIdentifier; + itemResourceIdentifier) + "/" + contactResourceIdentifier; } } diff --git a/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java b/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java index fd653102a..a3ea09e71 100644 --- a/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java +++ b/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java @@ -34,16 +34,17 @@ import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; -import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.client.ContactClient; import org.collectionspace.services.client.ContactClientUtils; import org.collectionspace.services.common.AbstractCommonListUtils; +import org.collectionspace.services.contact.AddressGroup; +import org.collectionspace.services.contact.AddressGroupList; import org.collectionspace.services.contact.ContactsCommon; -import org.collectionspace.services.contact.ContactsCommonList; import org.collectionspace.services.client.PersonAuthorityClient; import org.collectionspace.services.client.PersonAuthorityClientUtils; +import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.PersonJAXBSchema; import org.collectionspace.services.person.PersonauthoritiesCommon; import org.collectionspace.services.person.PersonsCommon; @@ -70,81 +71,69 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); private final String REFNAME = "refName"; private final String DISPLAYNAME = "displayName"; - - @Override - public String getServicePathComponent() { - return PersonAuthorityClient.SERVICE_PATH_COMPONENT; - } - - @Override - protected String getServiceName() { - return PersonAuthorityClient.SERVICE_NAME; - } - + + @Override + public String getServicePathComponent() { + return PersonAuthorityClient.SERVICE_PATH_COMPONENT; + } + + @Override + protected String getServiceName() { + return PersonAuthorityClient.SERVICE_NAME; + } + public String getItemServicePathComponent() { return AuthorityClient.ITEMS; - } - + } /** The test forename. */ final String TEST_FORE_NAME = "John"; - /** The test middle name. */ final String TEST_MIDDLE_NAME = null; - /** The test surname. */ final String TEST_SUR_NAME = "Wayne"; - /** The test birthdate. */ final String TEST_BIRTH_DATE = "May 26, 1907"; - /** The test death date. */ final String TEST_DEATH_DATE = "June 11, 1979"; - // Hold some values for a recently created item to verify upon read. private String knownResourceId = null; private String knownResourceShortIdentifer = null; private String knownResourceRefName = null; private String knownItemResourceId = null; private String knownItemResourceShortIdentifer = null; - // The resource ID of an item resource used for partial term matching tests. private String knownItemPartialTermResourceId = null; - /** The known contact resource id. */ private String knownContactResourceId = null; - /** The n items to create in list. */ private int nItemsToCreateInList = 3; - /** The all item resource ids created. */ private Map allItemResourceIdsCreated = - new HashMap(); - + new HashMap(); /** The all contact resource ids created. */ private Map allContactResourceIdsCreated = - new HashMap(); + new HashMap(); - protected void setKnownResource( String id, String shortIdentifer, - String refName ) { - knownResourceId = id; - knownResourceShortIdentifer = shortIdentifer; - knownResourceRefName = refName; + protected void setKnownResource(String id, String shortIdentifer, + String refName) { + knownResourceId = id; + knownResourceShortIdentifer = shortIdentifer; + knownResourceRefName = refName; } - protected void setKnownItemResource( String id, String shortIdentifer ) { - knownItemResourceId = id; - knownItemResourceShortIdentifer = shortIdentifer; + protected void setKnownItemResource(String id, String shortIdentifer) { + knownItemResourceId = id; + knownItemResourceShortIdentifer = shortIdentifer; } - /* (non-Javadoc) * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() */ @Override protected CollectionSpaceClient getClientInstance() { - return new PersonAuthorityClient(); + return new PersonAuthorityClient(); } - + // --------------------------------------------------------------- // CRUD tests : CREATE tests // --------------------------------------------------------------- @@ -153,10 +142,10 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String) */ @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"create"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"create"}) public void create(String testName) throws Exception { - + if (logger.isDebugEnabled()) { logger.debug(testBanner(testName, CLASS_NAME)); } @@ -168,38 +157,38 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); String shortId = createIdentifier(); - String displayName = "displayName-" + shortId; - String baseRefName = PersonAuthorityClientUtils.createPersonAuthRefName(shortId, null); - PoxPayloadOut multipart = - PersonAuthorityClientUtils.createPersonAuthorityInstance( - displayName, shortId, client.getCommonPartName()); - - 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(this.REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE); - - newID = PersonAuthorityClientUtils.extractId(res); - } finally { - res.releaseConnection(); - } + String displayName = "displayName-" + shortId; + String baseRefName = PersonAuthorityClientUtils.createPersonAuthRefName(shortId, null); + PoxPayloadOut multipart = + PersonAuthorityClientUtils.createPersonAuthorityInstance( + displayName, shortId, client.getCommonPartName()); + + 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(this.REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE); + + newID = PersonAuthorityClientUtils.extractId(res); + } finally { + res.releaseConnection(); + } // Save values for additional tests - if (knownResourceId == null){ - setKnownResource( newID, shortId, baseRefName ); - if (logger.isDebugEnabled()) { + if (knownResourceId == null) { + setKnownResource(newID, shortId, baseRefName); + if (logger.isDebugEnabled()) { logger.debug(testName + ": knownResourceId=" + knownResourceId); } } @@ -210,16 +199,16 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM @Override protected PoxPayloadOut createInstance(String identifier) { - PersonAuthorityClient client = new PersonAuthorityClient(); + PersonAuthorityClient client = new PersonAuthorityClient(); String displayName = "displayName-" + identifier; PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance( displayName, identifier, client.getCommonPartName()); return multipart; } - + @Override protected PoxPayloadOut createItemInstance(String parentCsid, String identifier) { - String headerLabel = new PersonAuthorityClient().getItemCommonPartName(); + String headerLabel = new PersonAuthorityClient().getItemCommonPartName(); HashMap personInfo = new HashMap(); String shortId = "johnWayneTempActor"; personInfo.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false"); @@ -228,16 +217,16 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM personInfo.put(PersonJAXBSchema.SHORT_DISPLAY_NAME, "JohnWayneTemp"); personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId); - return PersonAuthorityClientUtils.createPersonInstance(parentCsid, identifier, personInfo, headerLabel); + return PersonAuthorityClientUtils.createPersonInstance(parentCsid, identifier, personInfo, headerLabel); } - + /** * Creates the item. * * @param testName the test name */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"create"}, dependsOnMethods = {"create"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"create"}, dependsOnMethods = {"create"}) public void createItem(String testName) { if (logger.isDebugEnabled()) { logger.debug(testBanner(testName, CLASS_NAME)); @@ -251,30 +240,29 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * * @param testName the test name */ - /* + /* @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"create"}, dependsOnMethods = {"create"}) + groups = {"create"}, dependsOnMethods = {"create"}) public void createItemWithEmptyShortId(String testName) { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - setupCreate(); - - // Fill the property map - String shortId = ""; - Map fieldProperties = new HashMap(); - fieldProperties.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false"); - fieldProperties.put(PersonJAXBSchema.DISPLAY_NAME, "Rod Beck"); - fieldProperties.put(PersonJAXBSchema.SHORT_DISPLAY_NAME_COMPUTED, "false"); - fieldProperties.put(PersonJAXBSchema.SHORT_DISPLAY_NAME, "RodBeck"); - - final Map NULL_REPEATABLE_FIELD_PROPERTIES = null; - String newID = createItemInAuthority(knownResourceId, knownResourceRefName, - shortId, fieldProperties, NULL_REPEATABLE_FIELD_PROPERTIES); - allResourceIdsCreated.add(newID); + if (logger.isDebugEnabled()) { + logger.debug(testBanner(testName, CLASS_NAME)); } -*/ - + setupCreate(); + + // Fill the property map + String shortId = ""; + Map fieldProperties = new HashMap(); + fieldProperties.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false"); + fieldProperties.put(PersonJAXBSchema.DISPLAY_NAME, "Rod Beck"); + fieldProperties.put(PersonJAXBSchema.SHORT_DISPLAY_NAME_COMPUTED, "false"); + fieldProperties.put(PersonJAXBSchema.SHORT_DISPLAY_NAME, "RodBeck"); + + final Map NULL_REPEATABLE_FIELD_PROPERTIES = null; + String newID = createItemInAuthority(knownResourceId, knownResourceRefName, + shortId, fieldProperties, NULL_REPEATABLE_FIELD_PROPERTIES); + allResourceIdsCreated.add(newID); + } + */ /** * Creates an item in an authority, using test data. * @@ -285,11 +273,11 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM private String createItemInAuthority(String vcsid, String authRefName) { final String testName = "createItemInAuthority"; - if(logger.isDebugEnabled()){ - logger.debug(testName + ":"+vcsid+"..."); + if (logger.isDebugEnabled()) { + logger.debug(testName + ":" + vcsid + "..."); } - Map johnWayneMap = new HashMap(); + Map johnWayneMap = new HashMap(); // // Fill the property map // @@ -306,14 +294,14 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM johnWayneMap.put(PersonJAXBSchema.BIRTH_DATE, TEST_BIRTH_DATE); johnWayneMap.put(PersonJAXBSchema.BIRTH_PLACE, "Winterset, Iowa"); johnWayneMap.put(PersonJAXBSchema.DEATH_DATE, TEST_DEATH_DATE); - johnWayneMap.put(PersonJAXBSchema.BIO_NOTE, "born Marion Robert Morrison and better" + - "known by his stage name John Wayne, was an American film actor, director " + - "and producer. He epitomized rugged masculinity and has become an enduring " + - "American icon. He is famous for his distinctive voice, walk and height. " + - "He was also known for his conservative political views and his support in " + - "the 1950s for anti-communist positions."); - - Map> johnWayneRepeatablesMap = new HashMap>(); + johnWayneMap.put(PersonJAXBSchema.BIO_NOTE, "born Marion Robert Morrison and better" + + "known by his stage name John Wayne, was an American film actor, director " + + "and producer. He epitomized rugged masculinity and has become an enduring " + + "American icon. He is famous for his distinctive voice, walk and height. " + + "He was also known for his conservative political views and his support in " + + "the 1950s for anti-communist positions."); + + Map> johnWayneRepeatablesMap = new HashMap>(); List johnWayneGroups = new ArrayList(); johnWayneGroups.add("Irish"); johnWayneGroups.add("Scottish"); @@ -336,45 +324,45 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM Map itemFieldProperties, Map itemRepeatableFieldProperties) { final String testName = "createItemInAuthority"; - if(logger.isDebugEnabled()){ - logger.debug(testName + ":"+vcsid+"..."); + if (logger.isDebugEnabled()) { + logger.debug(testName + ":" + vcsid + "..."); } // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); - - PoxPayloadOut multipart = - PersonAuthorityClientUtils.createPersonInstance(vcsid, authRefName, itemFieldProperties, - itemRepeatableFieldProperties, client.getItemCommonPartName() ); + + PoxPayloadOut multipart = + PersonAuthorityClientUtils.createPersonInstance(vcsid, authRefName, itemFieldProperties, + itemRepeatableFieldProperties, client.getItemCommonPartName()); String newID = null; ClientResponse res = client.createItem(vcsid, 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); - - newID = PersonAuthorityClientUtils.extractId(res); + 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); + + newID = PersonAuthorityClientUtils.extractId(res); } finally { - res.releaseConnection(); + res.releaseConnection(); } // Store the ID returned from the first item resource created // for additional tests below. - if (knownItemResourceId == null){ - setKnownItemResource(newID, shortId); + if (knownItemResourceId == null) { + setKnownItemResource(newID, shortId); if (logger.isDebugEnabled()) { - logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId); + logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId); } } - if(logger.isDebugEnabled()){ - logger.debug(testName + " (created):"+vcsid+"/("+newID+","+shortId+")"); + if (logger.isDebugEnabled()) { + logger.debug(testName + " (created):" + vcsid + "/(" + newID + "," + shortId + ")"); } // Store the IDs from any item resources created @@ -390,8 +378,8 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * * @param testName the test name */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"create"}, dependsOnMethods = {"createItem"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"create"}, dependsOnMethods = {"createItem"}) public void createContact(String testName) { if (logger.isDebugEnabled()) { logger.debug(testBanner(testName, CLASS_NAME)); @@ -400,50 +388,50 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM String newID = createContactInItem(knownResourceId, knownItemResourceId); } - /** - * Creates the contact in item. - * - * @param parentcsid the parentcsid - * @param itemcsid the itemcsid - * @return the string - */ - private String createContactInItem(String parentcsid, String itemcsid) { + /** + * Creates the contact in item. + * + * @param parentcsid the parentcsid + * @param itemcsid the itemcsid + * @return the string + */ + private String createContactInItem(String parentcsid, String itemcsid) { final String testName = "createContactInItem"; - if(logger.isDebugEnabled()){ + if (logger.isDebugEnabled()) { logger.debug(testName + ":..."); } - + setupCreate(); // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); String identifier = createIdentifier(); PoxPayloadOut multipart = ContactClientUtils.createContactInstance(parentcsid, - itemcsid, identifier, new ContactClient().getCommonPartName()); - + itemcsid, identifier, new ContactClient().getCommonPartName()); + String newID = null; ClientResponse res = - client.createContact(parentcsid, itemcsid, multipart); + client.createContact(parentcsid, itemcsid, 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); - - newID = PersonAuthorityClientUtils.extractId(res); + 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); + + newID = PersonAuthorityClientUtils.extractId(res); } finally { - res.releaseConnection(); + res.releaseConnection(); } // Store the ID returned from the first contact resource created // for additional tests below. - if (knownContactResourceId == null){ + if (knownContactResourceId == null) { knownContactResourceId = newID; if (logger.isDebugEnabled()) { logger.debug(testName + ": knownContactResourceId=" + knownContactResourceId); @@ -459,7 +447,6 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM } // Failure outcomes - // Placeholders until the three tests below can be uncommented. // See Issue CSPACE-401. /* (non-Javadoc) @@ -467,7 +454,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM */ @Override public void createWithEmptyEntityBody(String testName) throws Exception { - //Should this really be empty? + //Should this really be empty? } /* (non-Javadoc) @@ -475,7 +462,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM */ @Override public void createWithMalformedXml(String testName) throws Exception { - //Should this really be empty? + //Should this really be empty? } /* (non-Javadoc) @@ -483,106 +470,105 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM */ @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, - groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"}) + groups = {"create"}, 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(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. + 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(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, - groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"}) + groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"}) public void createWithMalformedXml(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupCreateWithMalformedXml(); - - // 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(); + + // 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, - groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"}) + groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"}) public void createWithWrongXmlSchema(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupCreateWithWrongXmlSchema(); - - // 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(); + + // 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); + } + */ /** * Attempts to create an authority with an short identifier that contains * non-word characters. * * @param testName the test name */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"create", "nonWordCharsInShortId"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"create", "nonWordCharsInShortId"}) public void createWithShortIdNonWordChars(String testName) throws Exception { if (logger.isDebugEnabled()) { logger.debug(testBanner(testName, CLASS_NAME)); @@ -594,27 +580,27 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM // Create the payload to be included in the body of the request PersonAuthorityClient client = new PersonAuthorityClient(); String shortId = createIdentifier() + "*" + createIdentifier(); - String displayName = "displayName-" + shortId; + String displayName = "displayName-" + shortId; PoxPayloadOut multipart = - PersonAuthorityClientUtils.createPersonAuthorityInstance( - displayName, shortId, client.getCommonPartName()); + PersonAuthorityClientUtils.createPersonAuthorityInstance( + displayName, shortId, client.getCommonPartName()); // Submit the request to the service and store the response. - ClientResponse res = client.create(multipart); + ClientResponse res = client.create(multipart); - // Check the status code of the response: does it match - // the expected response(s)? + // Check the status code of the response: does it match + // the expected response(s)? try { int statusCode = res.getStatus(); - if(logger.isDebugEnabled()){ + if (logger.isDebugEnabled()) { logger.debug(testName + ": status = " + statusCode); } Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE); - } finally { - res.releaseConnection(); - } + } finally { + res.releaseConnection(); + } } @@ -624,8 +610,8 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * * @param testName the test name */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"create", "nonWordCharsInShortId"}, dependsOnMethods = {"create"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"create", "nonWordCharsInShortId"}, dependsOnMethods = {"create"}) public void createItemWithShortIdNonWordChars(String testName) { if (logger.isDebugEnabled()) { logger.debug(testBanner(testName, CLASS_NAME)); @@ -634,11 +620,11 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM REQUEST_TYPE = ServiceRequestType.CREATE; testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE); - PersonAuthorityClient client = new PersonAuthorityClient(); + PersonAuthorityClient client = new PersonAuthorityClient(); // Create the payload to be included in the body of the request String shortId = "7-Eleven"; - Map fieldProperties = new HashMap(); + Map fieldProperties = new HashMap(); fieldProperties.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false"); fieldProperties.put(PersonJAXBSchema.DISPLAY_NAME, shortId); fieldProperties.put(PersonJAXBSchema.SHORT_DISPLAY_NAME_COMPUTED, "false"); @@ -646,27 +632,27 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM fieldProperties.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId); final Map NULL_REPEATABLE_FIELD_PROPERTIES = null; PoxPayloadOut multipart = - PersonAuthorityClientUtils.createPersonInstance(knownResourceId, + PersonAuthorityClientUtils.createPersonInstance(knownResourceId, knownResourceRefName, fieldProperties, NULL_REPEATABLE_FIELD_PROPERTIES, client.getItemCommonPartName()); - + // Send the request and receive a response ClientResponse res = client.createItem(knownResourceId, multipart); // Check the status code of the response: does it match - // the expected response(s)? + // the expected response(s)? try { int statusCode = res.getStatus(); // 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), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); } finally { - res.releaseConnection(); + res.releaseConnection(); } } @@ -676,13 +662,13 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM // --------------------------------------------------------------- // Success outcomes /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String) - */ + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String) + */ @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"createList"}, dependsOnGroups = {"create"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"createList"}, dependsOnGroups = {"create"}) public void createList(String testName) throws Exception { - if (logger.isDebugEnabled()) { + if (logger.isDebugEnabled()) { logger.debug(testBanner(testName, CLASS_NAME)); } for (int i = 0; i < nItemsToCreateInList; i++) { @@ -696,8 +682,8 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"createList"}, dependsOnMethods = {"createList"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"createList"}, dependsOnMethods = {"createList"}) public void createItemList(String testName) throws Exception { if (logger.isDebugEnabled()) { logger.debug(testBanner(testName, CLASS_NAME)); @@ -714,8 +700,8 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"createList"}, dependsOnMethods = {"createItemList"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"createList"}, dependsOnMethods = {"createItemList"}) public void createContactList(String testName) throws Exception { // Add contacts to the initially-created, known item record. for (int j = 0; j < nItemsToCreateInList; j++) { @@ -731,10 +717,10 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String) */ @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"read"}, dependsOnGroups = {"create"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"read"}, dependsOnGroups = {"create"}) public void read(String testName) throws Exception { - readInternal(testName, knownResourceId, null); + readInternal(testName, knownResourceId, null); } /** @@ -743,12 +729,12 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"read"}, dependsOnMethods = {"read"}) - public void readByName(String testName) throws Exception { - readInternal(testName, null, knownResourceShortIdentifer); + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"read"}, dependsOnMethods = {"read"}) + public void readByName(String testName) throws Exception { + readInternal(testName, null, knownResourceShortIdentifer); } - + protected void readInternal(String testName, String CSID, String shortId) { if (logger.isDebugEnabled()) { logger.debug(testBanner(testName, CLASS_NAME)); @@ -759,34 +745,34 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); ClientResponse res = null; - if(CSID!=null) { + if (CSID != null) { res = client.read(CSID); - } else if(shortId!=null) { - res = client.readByName(shortId); + } else if (shortId != null) { + res = client.readByName(shortId); } else { - Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null"); + Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-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); - //FIXME: remove the following try catch once Aron fixes signatures - try { - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input, - client.getCommonPartName(), PersonauthoritiesCommon.class); - Assert.assertNotNull(personAuthority); - } catch (Exception e) { - throw new RuntimeException(e); - } + int statusCode = res.getStatus(); + // Check the status code of the response: does it match + // the expected response(s)? + if (logger.isDebugEnabled()) { + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + //FIXME: remove the following try catch once Aron fixes signatures + try { + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input, + client.getCommonPartName(), PersonauthoritiesCommon.class); + Assert.assertNotNull(personAuthority); + } catch (Exception e) { + throw new RuntimeException(e); + } } finally { - res.releaseConnection(); + res.releaseConnection(); } } @@ -796,8 +782,8 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"readItem"}, dependsOnGroups = {"read"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"readItem"}, dependsOnGroups = {"read"}) public void readItem(String testName) throws Exception { readItemInternal(testName, knownResourceId, null, knownItemResourceId, null); } @@ -808,8 +794,8 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"readItem"}, dependsOnMethods = {"readItem"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"readItem"}, dependsOnMethods = {"readItem"}) public void readItemInNamedAuth(String testName) throws Exception { readItemInternal(testName, null, knownResourceShortIdentifer, knownItemResourceId, null); } @@ -820,8 +806,8 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"readItem"}, dependsOnMethods = {"readItem"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"readItem"}, dependsOnMethods = {"readItem"}) public void readNamedItem(String testName) throws Exception { readItemInternal(testName, knownResourceId, null, null, knownItemResourceShortIdentifer); } @@ -832,20 +818,20 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"readItem"}, dependsOnMethods = {"readItem"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"readItem"}, dependsOnMethods = {"readItem"}) public void readNamedItemInNamedAuth(String testName) throws Exception { readItemInternal(testName, null, knownResourceShortIdentifer, null, knownItemResourceShortIdentifer); } - protected void readItemInternal(String testName, - String authCSID, String authShortId, String itemCSID, String itemShortId) - throws Exception { + protected void readItemInternal(String testName, + String authCSID, String authShortId, String itemCSID, String itemShortId) + throws Exception { if (logger.isDebugEnabled()) { logger.debug(testBanner(testName, CLASS_NAME)); - logger.debug("Reading:"+((authCSID!=null)?authCSID:authShortId)+"/"+ - ((itemCSID!=null)?authCSID:itemShortId)); + logger.debug("Reading:" + ((authCSID != null) ? authCSID : authShortId) + "/" + + ((itemCSID != null) ? authCSID : itemShortId)); } // Perform setup. setupRead(); @@ -853,59 +839,59 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); ClientResponse res = null; - if(authCSID!=null) { - if(itemCSID!=null) { + if (authCSID != null) { + if (itemCSID != null) { res = client.readItem(authCSID, itemCSID); - } else if(itemShortId!=null) { - res = client.readNamedItem(authCSID, itemShortId); + } else if (itemShortId != null) { + res = client.readNamedItem(authCSID, itemShortId); } else { - Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null"); + Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null"); } - } else if(authShortId!=null) { - if(itemCSID!=null) { + } else if (authShortId != null) { + if (itemCSID != null) { res = client.readItemInNamedAuthority(authShortId, itemCSID); - } else if(itemShortId!=null) { - res = client.readNamedItemInNamedAuthority(authShortId, itemShortId); + } else if (itemShortId != null) { + res = client.readNamedItemInNamedAuthority(authShortId, itemShortId); } else { - Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null"); + Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null"); } } else { - Assert.fail("readInternal: Internal error. One of authCSID or authShortId must be non-null"); + Assert.fail("readInternal: Internal error. One of authCSID or authShortId must be non-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); - - // Check whether we've received a person. - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - PersonsCommon person = (PersonsCommon) extractPart(input, - client.getItemCommonPartName(), PersonsCommon.class); - Assert.assertNotNull(person); - boolean showFull = true; - if(showFull && logger.isDebugEnabled()){ - logger.debug(testName + ": returned payload:"); - logger.debug(objectAsXmlString(person, PersonsCommon.class)); - } - - // Check that the person item is within the expected Person Authority. - Assert.assertEquals(person.getInAuthority(), knownResourceId); - - // Verify the number and contents of values in a repeatable field, - // as created in the instance record used for testing. - List groups = person.getGroups().getGroup(); - Assert.assertTrue(groups.size() > 0); - Assert.assertNotNull(groups.get(0)); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if (logger.isDebugEnabled()) { + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Check whether we've received a person. + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + PersonsCommon person = (PersonsCommon) extractPart(input, + client.getItemCommonPartName(), PersonsCommon.class); + Assert.assertNotNull(person); + boolean showFull = true; + if (showFull && logger.isDebugEnabled()) { + logger.debug(testName + ": returned payload:"); + logger.debug(objectAsXmlString(person, PersonsCommon.class)); + } + + // Check that the person item is within the expected Person Authority. + Assert.assertEquals(person.getInAuthority(), knownResourceId); + + // Verify the number and contents of values in a repeatable field, + // as created in the instance record used for testing. + List groups = person.getGroups().getGroup(); + Assert.assertTrue(groups.size() > 0); + Assert.assertNotNull(groups.get(0)); } finally { - res.releaseConnection(); + res.releaseConnection(); } } @@ -915,11 +901,11 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"update"}, dependsOnMethods = {"updateItem"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"update"}, dependsOnMethods = {"updateItem"}) public void verifyItemDisplayNames(String testName) throws Exception { - - if (logger.isDebugEnabled()) { + + if (logger.isDebugEnabled()) { logger.debug(testBanner(testName, CLASS_NAME)); } // Perform setup. @@ -927,56 +913,56 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); - PoxPayloadIn input =null; + PoxPayloadIn input = null; ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); try { - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Check whether person has expected displayName. - input = 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); + + // Check whether person has expected displayName. + input = new PoxPayloadIn(res.getEntity()); } finally { - res.releaseConnection(); + res.releaseConnection(); } - + PersonsCommon person = (PersonsCommon) extractPart(input, client.getItemCommonPartName(), PersonsCommon.class); Assert.assertNotNull(person); String displayName = person.getDisplayName(); // Make sure displayName matches computed form - String expectedDisplayName = - PersonAuthorityClientUtils.prepareDefaultDisplayName( - TEST_FORE_NAME, null, TEST_SUR_NAME, - TEST_BIRTH_DATE, TEST_DEATH_DATE); + String expectedDisplayName = + PersonAuthorityClientUtils.prepareDefaultDisplayName( + TEST_FORE_NAME, null, TEST_SUR_NAME, + TEST_BIRTH_DATE, TEST_DEATH_DATE); Assert.assertFalse(displayName.equals(expectedDisplayName)); - + String shortDisplayName = person.getShortDisplayName(); // Make sure displayName matches computed form - String expectedShortDisplayName = - PersonAuthorityClientUtils.prepareDefaultDisplayName( - TEST_FORE_NAME, null, TEST_SUR_NAME,null, null); + String expectedShortDisplayName = + PersonAuthorityClientUtils.prepareDefaultDisplayName( + TEST_FORE_NAME, null, TEST_SUR_NAME, null, null); Assert.assertFalse(expectedShortDisplayName.equals(shortDisplayName)); - + // Update the forename and verify the computed name is updated. person.setCsid(null); person.setDisplayNameComputed(true); person.setShortDisplayNameComputed(true); person.setForeName("updated-" + TEST_FORE_NAME); - expectedDisplayName = - PersonAuthorityClientUtils.prepareDefaultDisplayName( - "updated-" + TEST_FORE_NAME, null, TEST_SUR_NAME, - TEST_BIRTH_DATE, TEST_DEATH_DATE); - expectedShortDisplayName = - PersonAuthorityClientUtils.prepareDefaultDisplayName( - "updated-" + TEST_FORE_NAME, null, TEST_SUR_NAME,null, null); + expectedDisplayName = + PersonAuthorityClientUtils.prepareDefaultDisplayName( + "updated-" + TEST_FORE_NAME, null, TEST_SUR_NAME, + TEST_BIRTH_DATE, TEST_DEATH_DATE); + expectedShortDisplayName = + PersonAuthorityClientUtils.prepareDefaultDisplayName( + "updated-" + TEST_FORE_NAME, null, TEST_SUR_NAME, null, null); // Submit the updated resource to the service and store the response. PoxPayloadOut output = new PoxPayloadOut(PersonAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); @@ -984,36 +970,36 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM commonPart.setLabel(client.getItemCommonPartName()); res = client.updateItem(knownResourceId, knownItemResourceId, 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("updateItem: status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Retrieve the updated resource and verify that its contents exist. - input = 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("updateItem: status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Retrieve the updated resource and verify that its contents exist. + input = new PoxPayloadIn(res.getEntity()); } finally { - res.releaseConnection(); + res.releaseConnection(); } - + PersonsCommon updatedPerson = (PersonsCommon) extractPart(input, - client.getItemCommonPartName(), PersonsCommon.class); + client.getItemCommonPartName(), PersonsCommon.class); Assert.assertNotNull(updatedPerson); // Verify that the updated resource received the correct data. Assert.assertEquals(updatedPerson.getForeName(), person.getForeName(), - "Updated ForeName in Person did not match submitted data."); + "Updated ForeName in Person did not match submitted data."); // Verify that the updated resource computes the right displayName. Assert.assertEquals(updatedPerson.getDisplayName(), expectedDisplayName, - "Updated ForeName in Person not reflected in computed DisplayName."); + "Updated ForeName in Person not reflected in computed DisplayName."); // Verify that the updated resource computes the right displayName. Assert.assertEquals(updatedPerson.getShortDisplayName(), expectedShortDisplayName, - "Updated ForeName in Person not reflected in computed ShortDisplayName."); + "Updated ForeName in Person not reflected in computed ShortDisplayName."); // Now Update the displayName, not computed and verify the computed name is overriden. person.setDisplayNameComputed(false); @@ -1028,25 +1014,25 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM commonPart.setLabel(client.getItemCommonPartName()); res = client.updateItem(knownResourceId, knownItemResourceId, 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("updateItem: status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Retrieve the updated resource and verify that its contents exist. - input = new PoxPayloadIn(res.getEntity()); - } finally { - res.releaseConnection(); - } - - updatedPerson = + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match the expected response(s)? + if (logger.isDebugEnabled()) { + logger.debug("updateItem: status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Retrieve the updated resource and verify that its contents exist. + input = new PoxPayloadIn(res.getEntity()); + } finally { + res.releaseConnection(); + } + + updatedPerson = (PersonsCommon) extractPart(input, - client.getItemCommonPartName(), PersonsCommon.class); + client.getItemCommonPartName(), PersonsCommon.class); Assert.assertNotNull(updatedPerson); // Verify that the updated resource received the correct data. @@ -1054,14 +1040,14 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM "Updated displayNameComputed in Person did not match submitted data."); // Verify that the updated resource computes the right displayName. Assert.assertEquals(updatedPerson.getDisplayName(), - expectedDisplayName, + expectedDisplayName, "Updated DisplayName (not computed) in Person not stored."); // Verify that the updated resource received the correct data. Assert.assertEquals(updatedPerson.isShortDisplayNameComputed(), false, "Updated shortDisplayNameComputed in Person did not match submitted data."); // Verify that the updated resource computes the right displayName. Assert.assertEquals(updatedPerson.getShortDisplayName(), - expectedDisplayName, + expectedDisplayName, "Updated ShortDisplayName (not computed) in Person not stored."); } @@ -1071,8 +1057,8 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"update"}, dependsOnMethods = {"verifyItemDisplayNames"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"update"}, dependsOnMethods = {"verifyItemDisplayNames"}) public void verifyIllegalItemDisplayName(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -1080,30 +1066,30 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM } // Perform setup. testSetup(STATUS_BAD_REQUEST, ServiceRequestType.UPDATE); - // setupUpdateWithWrongXmlSchema(testName); + // setupUpdateWithWrongXmlSchema(testName); // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); PoxPayloadIn input = null; ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); try { - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode()); - - // Check whether Person has expected displayName. - input = 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, Response.Status.OK.getStatusCode()); + + // Check whether Person has expected displayName. + input = new PoxPayloadIn(res.getEntity()); } finally { - res.releaseConnection(); + res.releaseConnection(); } - + PersonsCommon person = (PersonsCommon) extractPart(input, client.getItemCommonPartName(), PersonsCommon.class); Assert.assertNotNull(person); @@ -1117,30 +1103,30 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM commonPart.setLabel(client.getItemCommonPartName()); res = client.updateItem(knownResourceId, knownItemResourceId, 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("updateItem: 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("updateItem: status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); } finally { - res.releaseConnection(); + res.releaseConnection(); } } - + /** * Read contact. * * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"readItem"}, dependsOnMethods = {"readItem"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"readItem"}, dependsOnMethods = {"readItem"}) public void readContact(String testName) throws Exception { - + if (logger.isDebugEnabled()) { logger.debug(testBanner(testName, CLASS_NAME)); } @@ -1151,31 +1137,31 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM PersonAuthorityClient client = new PersonAuthorityClient(); PoxPayloadIn input = null; ClientResponse res = - client.readContact(knownResourceId, knownItemResourceId, - knownContactResourceId); + client.readContact(knownResourceId, knownItemResourceId, + knownContactResourceId); try { - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Check whether we've received a contact. - input = 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); + + // Check whether we've received a contact. + input = new PoxPayloadIn(res.getEntity()); } finally { - res.releaseConnection(); + res.releaseConnection(); } - + ContactsCommon contact = (ContactsCommon) extractPart(input, new ContactClient().getCommonPartName(), ContactsCommon.class); Assert.assertNotNull(contact); boolean showFull = true; - if(showFull && logger.isDebugEnabled()){ + if (showFull && logger.isDebugEnabled()) { logger.debug(testName + ": returned payload:"); logger.debug(objectAsXmlString(contact, ContactsCommon.class)); } @@ -1189,8 +1175,8 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String) */ @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"read"}, dependsOnMethods = {"read"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"read"}, dependsOnMethods = {"read"}) public void readNonExistent(String testName) { if (logger.isDebugEnabled()) { @@ -1203,17 +1189,17 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM PersonAuthorityClient client = new PersonAuthorityClient(); 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(); } } @@ -1222,8 +1208,8 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * * @param testName the test name */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"readItem"}, dependsOnMethods = {"readItem"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"readItem"}, dependsOnMethods = {"readItem"}) public void readItemNonExistent(String testName) { if (logger.isDebugEnabled()) { @@ -1236,18 +1222,18 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM PersonAuthorityClient client = new PersonAuthorityClient(); ClientResponse res = client.readItem(knownResourceId, 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(); } } @@ -1256,8 +1242,8 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * * @param testName the test name */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"readItem"}, dependsOnMethods = {"readContact"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"readItem"}, dependsOnMethods = {"readContact"}) public void readContactNonExistent(String testName) { if (logger.isDebugEnabled()) { @@ -1269,20 +1255,20 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); ClientResponse res = - client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID); + client.readContact(knownResourceId, knownItemResourceId, 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(); } } @@ -1295,8 +1281,8 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String) */ @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"readList"}, dependsOnGroups = {"createList", "read"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"readList"}, dependsOnGroups = {"createList", "read"}) public void readList(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -1310,34 +1296,34 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM AbstractCommonList list = null; 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. // Optionally output additional data about list members for debugging. - if(logger.isTraceEnabled()){ - AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); + if (logger.isTraceEnabled()) { + AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); } } /** * Read item list. */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"readList"}, dependsOnMethods = {"readList"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"readList"}, dependsOnMethods = {"readList"}) public void readItemList(String testName) { readItemList(knownResourceId, null, testName); } @@ -1345,12 +1331,12 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM /** * Read item list by authority name. */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"readList"}, dependsOnMethods = {"readItemList"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"readList"}, dependsOnMethods = {"readItemList"}) public void readItemListByAuthorityName(String testName) { readItemList(null, knownResourceShortIdentifer, testName); } - + /** * Read item list. * @@ -1361,37 +1347,37 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM // Perform setup. setupReadList(); - - // Submit the request to the service and store the response. + + // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); ClientResponse res = null; - if (vcsid!= null) { - res = client.readItemList(vcsid, null, null); - } else if (name!= null) { - res = client.readItemListForNamedAuthority(name, null, null); + if (vcsid != null) { + res = client.readItemList(vcsid, null, null); + } else if (name != null) { + res = client.readItemListForNamedAuthority(name, null, null); } else { - Assert.fail("readItemList passed null csid and name!"); + Assert.fail("readItemList passed null csid and name!"); } AbstractCommonList list = null; try { - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - list = res.getEntity(); + 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(); } List items = - list.getListItem(); + list.getListItem(); int nItemsReturned = items.size(); // There will be one item created, associated with a // known parent resource, by the createItem test. @@ -1400,22 +1386,22 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM // additional items created by the createItemList test, // all associated with the same parent resource. int nExpectedItems = nItemsToCreateInList + 1; - if(logger.isDebugEnabled()){ + if (logger.isDebugEnabled()) { logger.debug(testName + ": Expected " - + nExpectedItems +" items; got: "+nItemsReturned); + + nExpectedItems + " items; got: " + nItemsReturned); } Assert.assertEquals(nItemsReturned, nExpectedItems); for (AbstractCommonList.ListItem item : items) { - String value = - AbstractCommonListUtils.ListItemGetElementValue(item, REFNAME); + String value = + AbstractCommonListUtils.ListItemGetElementValue(item, REFNAME); Assert.assertTrue((null != value), "Item refName is null!"); - value = - AbstractCommonListUtils.ListItemGetElementValue(item, DISPLAYNAME); + value = + AbstractCommonListUtils.ListItemGetElementValue(item, DISPLAYNAME); Assert.assertTrue((null != value), "Item displayName is null!"); } - if(logger.isTraceEnabled()){ - AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); + if (logger.isTraceEnabled()) { + AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); } } @@ -1441,28 +1427,28 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); - ContactsCommonList list = null; - ClientResponse res = + AbstractCommonList list = null; + ClientResponse res = client.readContactList(parentcsid, itemcsid); 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(); } - - List listitems = - list.getContactListItem(); + + List listitems = + list.getListItem(); int nItemsReturned = listitems.size(); // There will be one item created, associated with a // known parent resource, by the createItem test. @@ -1471,32 +1457,21 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM // additional items created by the createItemList test, // all associated with the same parent resource. int nExpectedItems = nItemsToCreateInList + 1; - if(logger.isDebugEnabled()){ + if (logger.isDebugEnabled()) { logger.debug(testName + ": Expected " - + nExpectedItems +" items; got: "+nItemsReturned); + + nExpectedItems + " items; got: " + nItemsReturned); } Assert.assertEquals(nItemsReturned, nExpectedItems); - - int i = 0; - for (ContactsCommonList.ContactListItem listitem : listitems) { - // Optionally output additional data about list members for debugging. - boolean showDetails = false; - if (showDetails && logger.isDebugEnabled()) { - logger.debug(" " + testName + ": list-item[" + i + "] csid=" + - listitem.getCsid()); - logger.debug(" " + testName + ": list-item[" + i + "] addressPlace=" + - listitem.getAddressPlace()); - logger.debug(" " + testName + ": list-item[" + i + "] URI=" + - listitem.getUri()); - } - i++; + + // Optionally output additional data about list members for debugging. + boolean iterateThroughList = false; + if (iterateThroughList && logger.isDebugEnabled()) { + AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); } } // Failure outcomes - // There are no failure outcome tests at present. - // --------------------------------------------------------------- // CRUD tests : UPDATE tests // --------------------------------------------------------------- @@ -1505,8 +1480,8 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String) */ @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"update"}, dependsOnGroups = {"readItem", "readList"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"update"}, dependsOnGroups = {"readItem", "readList"}) public void update(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -1520,19 +1495,19 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM PoxPayloadIn input = null; ClientResponse res = client.read(knownResourceId); try { - if(logger.isDebugEnabled()){ - logger.debug(testName + ": read status = " + res.getStatus()); - } - Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); - - if(logger.isDebugEnabled()){ - logger.debug("got PersonAuthority to update with ID: " + knownResourceId); - } - input = 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 PersonAuthority to update with ID: " + knownResourceId); + } + input = new PoxPayloadIn(res.getEntity()); } finally { - res.releaseConnection(); + res.releaseConnection(); } - + PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input, client.getCommonPartName(), PersonauthoritiesCommon.class); Assert.assertNotNull(personAuthority); @@ -1540,7 +1515,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM // Update the contents of this resource. personAuthority.setDisplayName("updated-" + personAuthority.getDisplayName()); personAuthority.setVocabType("updated-" + personAuthority.getVocabType()); - if(logger.isDebugEnabled()){ + if (logger.isDebugEnabled()) { logger.debug("to be updated PersonAuthority"); logger.debug(objectAsXmlString(personAuthority, PersonauthoritiesCommon.class)); } @@ -1551,25 +1526,25 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM 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); - - // Retrieve the updated resource and verify that its contents exist. - 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); + + // Retrieve the updated resource and verify that its contents exist. + input = new PoxPayloadIn(res.getEntity()); } finally { - res.releaseConnection(); + res.releaseConnection(); } - + PersonauthoritiesCommon updatedPersonAuthority = (PersonauthoritiesCommon) extractPart(input, - client.getCommonPartName(), PersonauthoritiesCommon.class); + client.getCommonPartName(), PersonauthoritiesCommon.class); Assert.assertNotNull(updatedPersonAuthority); // Verify that the updated resource received the correct data. @@ -1584,8 +1559,8 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"update"}, dependsOnMethods = {"update"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"update"}, dependsOnMethods = {"update"}) public void updateItem(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -1600,70 +1575,70 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); try { - if(logger.isDebugEnabled()){ - logger.debug(testName + ": read status = " + res.getStatus()); - } - Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); - - if(logger.isDebugEnabled()){ - logger.debug("got Person to update with ID: " + - knownItemResourceId + - " in PersonAuthority: " + knownResourceId ); - } - input = 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 Person to update with ID: " + + knownItemResourceId + + " in PersonAuthority: " + knownResourceId); + } + input = new PoxPayloadIn(res.getEntity()); } finally { - res.releaseConnection(); + res.releaseConnection(); } - + PersonsCommon person = (PersonsCommon) extractPart(input, client.getItemCommonPartName(), PersonsCommon.class); Assert.assertNotNull(person); - + if (logger.isDebugEnabled() == true) { - logger.debug("About to update the following person..."); - logger.debug(objectAsXmlString(person, PersonsCommon.class)); + logger.debug("About to update the following person..."); + logger.debug(objectAsXmlString(person, PersonsCommon.class)); } // Update the contents of this resource. person.setCsid(null); person.setForeName("updated-" + person.getForeName()); - if(logger.isDebugEnabled()){ + if (logger.isDebugEnabled()) { logger.debug("to be updated Person"); logger.debug(objectAsXmlString(person, - PersonsCommon.class)); - } - + PersonsCommon.class)); + } + // Submit the updated resource to the service and store the response. PoxPayloadOut output = new PoxPayloadOut(PersonAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); PayloadOutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE); commonPart.setLabel(client.getItemCommonPartName()); res = client.updateItem(knownResourceId, knownItemResourceId, 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); - - // Retrieve the updated resource and verify that its contents exist. - 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); + + // Retrieve the updated resource and verify that its contents exist. + input = new PoxPayloadIn(res.getEntity()); } finally { - res.releaseConnection(); + res.releaseConnection(); } - + PersonsCommon updatedPerson = (PersonsCommon) extractPart(input, - client.getItemCommonPartName(), PersonsCommon.class); + client.getItemCommonPartName(), PersonsCommon.class); Assert.assertNotNull(updatedPerson); - + if (logger.isDebugEnabled() == true) { - logger.debug("Updated to following person to:"); - logger.debug(objectAsXmlString(updatedPerson, PersonsCommon.class)); - } + logger.debug("Updated to following person to:"); + logger.debug(objectAsXmlString(updatedPerson, PersonsCommon.class)); + } // Verify that the updated resource received the correct data. Assert.assertEquals(updatedPerson.getForeName(), @@ -1677,10 +1652,10 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"update"}, dependsOnMethods = {"updateItem"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"update"}, dependsOnMethods = {"updateItem"}) public void updateContact(String testName) throws Exception { - + if (logger.isDebugEnabled()) { logger.debug(testBanner(testName, CLASS_NAME)); } @@ -1693,32 +1668,42 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM ClientResponse res = client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId); try { - if(logger.isDebugEnabled()){ - logger.debug(testName + ": read status = " + res.getStatus()); - } - Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); - - if(logger.isDebugEnabled()){ - logger.debug("got Contact to update with ID: " + - knownContactResourceId + - " in item: " + knownItemResourceId + - " in parent: " + knownResourceId ); - } - input = 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 Contact to update with ID: " + + knownContactResourceId + + " in item: " + knownItemResourceId + + " in parent: " + knownResourceId); + } + input = new PoxPayloadIn(res.getEntity()); } finally { - res.releaseConnection(); + res.releaseConnection(); } - + ContactsCommon contact = (ContactsCommon) extractPart(input, new ContactClient().getCommonPartName(), ContactsCommon.class); Assert.assertNotNull(contact); + // Verify the contents of this resource + AddressGroupList addressGroupList = contact.getAddressGroupList(); + Assert.assertNotNull(addressGroupList); + List addressGroups = addressGroupList.getAddressGroup(); + Assert.assertNotNull(addressGroups); + Assert.assertTrue(addressGroups.size() > 0); + String addressPlace1 = addressGroups.get(0).getAddressPlace1(); + Assert.assertNotNull(addressPlace1); + // Update the contents of this resource. - contact.setAddressPlace("updated-" + contact.getAddressPlace()); - if(logger.isDebugEnabled()){ + addressGroups.get(0).setAddressPlace1("updated-" + addressPlace1); + contact.setAddressGroupList(addressGroupList); + if (logger.isDebugEnabled()) { logger.debug("to be updated Contact"); logger.debug(objectAsXmlString(contact, - ContactsCommon.class)); + ContactsCommon.class)); } // Submit the updated resource to the service and store the response. @@ -1727,30 +1712,30 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM commonPart.setLabel(client.getCommonPartName()); res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, 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); - - // Retrieve the updated resource and verify that its contents exist. - 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); + + // Retrieve the updated resource and verify that its contents exist. + input = new PoxPayloadIn(res.getEntity());; } finally { - res.releaseConnection(); + res.releaseConnection(); } ContactsCommon updatedContact = (ContactsCommon) extractPart(input, - new ContactClient().getCommonPartName(), ContactsCommon.class); + new ContactClient().getCommonPartName(), ContactsCommon.class); Assert.assertNotNull(updatedContact); // Verify that the updated resource received the correct data. - Assert.assertEquals(updatedContact.getAddressPlace(), - contact.getAddressPlace(), - "Data in updated Contact did not match submitted data."); + Assert.assertEquals(updatedContact.getAddressGroupList().getAddressGroup().get(0).getAddressPlace1(), + contact.getAddressGroupList().getAddressGroup().get(0).getAddressPlace1(), + "Data in updated object did not match submitted data."); } // Failure outcomes @@ -1761,7 +1746,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM */ @Override public void updateWithEmptyEntityBody(String testName) throws Exception { - //Should this really be empty? + //Should this really be empty? } /* (non-Javadoc) @@ -1769,7 +1754,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM */ @Override public void updateWithMalformedXml(String testName) throws Exception { - //Should this really be empty? + //Should this really be empty? } /* (non-Javadoc) @@ -1777,104 +1762,104 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM */ @Override public void updateWithWrongXmlSchema(String testName) throws Exception { - //Should this really be empty? + //Should this really be empty? } -/* //FIXME: REM - Can we kill all this dead code please? + /* //FIXME: REM - Can we kill all this dead code please? @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"}) + groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"}) public void updateWithEmptyEntityBody(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupUpdateWithEmptyEntityBody(testName, logger); - - // 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(testName, logger); + + // 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, - groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"}) + groups = {"update"}, dependsOnMethods = {"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, - groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"}) + groups = {"update"}, dependsOnMethods = {"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("updateWithWrongXmlSchema: 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("updateWithWrongXmlSchema: url=" + url + + " status=" + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + */ /* (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String) - */ -@Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"}) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String) + */ + @Override + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"}) public void updateNonExistent(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -1888,23 +1873,23 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM // The only relevant ID may be the one used in update(), below. PersonAuthorityClient client = new PersonAuthorityClient(); String displayName = "displayName-NON_EXISTENT_ID"; - PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance( - displayName, "NON_EXISTENT_SHORT_ID", client.getCommonPartName()); + PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance( + displayName, "NON_EXISTENT_SHORT_ID", client.getCommonPartName()); 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(); } } @@ -1914,8 +1899,8 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"}) public void updateNonExistentItem(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -1928,31 +1913,31 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM // Note: The ID used in this 'create' call may be arbitrary. // The only relevant ID may be the one used in update(), below. PersonAuthorityClient client = new PersonAuthorityClient(); - Map nonexMap = new HashMap(); + Map nonexMap = new HashMap(); nonexMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, "nonEX"); nonexMap.put(PersonJAXBSchema.FORE_NAME, "John"); nonexMap.put(PersonJAXBSchema.SUR_NAME, "Wayne"); nonexMap.put(PersonJAXBSchema.GENDER, "male"); Map> nonexRepeatablesMap = new HashMap>(); - PoxPayloadOut multipart = - PersonAuthorityClientUtils.createPersonInstance(NON_EXISTENT_ID, - PersonAuthorityClientUtils.createPersonAuthRefName(NON_EXISTENT_ID, null), - nonexMap, nonexRepeatablesMap, client.getItemCommonPartName() ); + PoxPayloadOut multipart = + PersonAuthorityClientUtils.createPersonInstance(NON_EXISTENT_ID, + PersonAuthorityClientUtils.createPersonAuthRefName(NON_EXISTENT_ID, null), + nonexMap, nonexRepeatablesMap, client.getItemCommonPartName()); ClientResponse res = client.updateItem(knownResourceId, 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(); } } @@ -1962,8 +1947,8 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"}) public void updateNonExistentContact(String testName) throws Exception { // Currently a no-op test } @@ -1972,18 +1957,16 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM // CRUD tests : DELETE tests // --------------------------------------------------------------- // Success outcomes - // Note: delete sub-resources in ascending hierarchical order, // before deleting their parents. - /** * Delete contact. * * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"delete"}, dependsOnGroups = {"update"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"delete"}, dependsOnGroups = {"update"}) public void deleteContact(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -1992,40 +1975,40 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM // Perform setup. setupDelete(); - if(logger.isDebugEnabled()){ - logger.debug("parentcsid =" + knownResourceId + - " itemcsid = " + knownItemResourceId + - " csid = " + knownContactResourceId); + if (logger.isDebugEnabled()) { + logger.debug("parentcsid =" + knownResourceId + + " itemcsid = " + knownItemResourceId + + " csid = " + knownContactResourceId); } // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); ClientResponse res = - client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId); + client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId); try { - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } finally { - res.releaseConnection(); - } - } - - /** - * Delete item. - * - * @param testName the test name - * @throws Exception the exception - */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"delete"}, dependsOnMethods = {"deleteContact"}) + 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(); + } + } + + /** + * Delete item. + * + * @param testName the test name + * @throws Exception the exception + */ + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"delete"}, dependsOnMethods = {"deleteContact"}) public void deleteItem(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -2034,36 +2017,36 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM // Perform setup. setupDelete(); - if(logger.isDebugEnabled()){ - logger.debug("parentcsid =" + knownResourceId + - " itemcsid = " + knownItemResourceId); + if (logger.isDebugEnabled()) { + logger.debug("parentcsid =" + knownResourceId + + " itemcsid = " + knownItemResourceId); } // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); ClientResponse res = client.deleteItem(knownResourceId, knownItemResourceId); try { - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } finally { - res.releaseConnection(); - } + 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(); + } } /* (non-Javadoc) * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String) */ @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"delete"}, dependsOnMethods = {"deleteItem"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"delete"}, dependsOnMethods = {"deleteItem"}) public void delete(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -2072,7 +2055,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM // Perform setup. setupDelete(); - if(logger.isDebugEnabled()){ + if (logger.isDebugEnabled()) { logger.debug("parentcsid =" + knownResourceId); } @@ -2080,19 +2063,19 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM PersonAuthorityClient client = new PersonAuthorityClient(); 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); - } finally { - res.releaseConnection(); - } + 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(); + } } // Failure outcomes @@ -2100,8 +2083,8 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String) */ @Override - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"delete"}, dependsOnMethods = {"delete"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"delete"}, dependsOnMethods = {"delete"}) public void deleteNonExistent(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -2114,19 +2097,19 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM PersonAuthorityClient client = new PersonAuthorityClient(); 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); - } finally { - res.releaseConnection(); - } + 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(); + } } /** @@ -2134,8 +2117,8 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * * @param testName the test name */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"delete"}, dependsOnMethods = {"deleteItem"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"delete"}, dependsOnMethods = {"deleteItem"}) public void deleteNonExistentItem(String testName) { if (logger.isDebugEnabled()) { @@ -2148,19 +2131,19 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM PersonAuthorityClient client = new PersonAuthorityClient(); ClientResponse res = client.deleteItem(knownResourceId, 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); - } finally { - res.releaseConnection(); - } + 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(); + } } /** @@ -2168,8 +2151,8 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * * @param testName the test name */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"delete"}, dependsOnMethods = {"deleteContact"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"delete"}, dependsOnMethods = {"deleteContact"}) public void deleteNonExistentContact(String testName) { if (logger.isDebugEnabled()) { @@ -2181,21 +2164,21 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); ClientResponse res = - client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID); + client.deleteContact(knownResourceId, knownItemResourceId, 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); - } finally { - res.releaseConnection(); - } + 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(); + } } // --------------------------------------------------------------- @@ -2218,9 +2201,9 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM // 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); @@ -2242,9 +2225,9 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM // Check the status code of the response: does it match // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug("testItemSubmitRequest: url=" + url + - " status=" + statusCode); + if (logger.isDebugEnabled()) { + logger.debug("testItemSubmitRequest: url=" + url + + " status=" + statusCode); } Assert.assertEquals(statusCode, EXPECTED_STATUS); @@ -2262,24 +2245,22 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM // Submit the request to the service and store the response. String method = ServiceRequestType.READ.httpMethodName(); String url = getContactResourceURL(knownResourceId, - knownItemResourceId, knownContactResourceId); + knownItemResourceId, knownContactResourceId); int statusCode = submitRequest(method, url); // Check the status code of the response: does it match // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug("testItemSubmitRequest: url=" + url + - " status=" + statusCode); + if (logger.isDebugEnabled()) { + logger.debug("testItemSubmitRequest: url=" + url + + " status=" + statusCode); } Assert.assertEquals(statusCode, EXPECTED_STATUS); } - // --------------------------------------------------------------- // Cleanup of resources created during testing // --------------------------------------------------------------- - /** * Deletes all resources created by tests, after all tests have been run. * @@ -2288,17 +2269,16 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * at any point during testing, even if some of those resources * may be expected to be deleted by certain tests. */ - - @AfterClass(alwaysRun=true) + @AfterClass(alwaysRun = true) @Override public void cleanUp() { String noTest = System.getProperty("noTestCleanup"); - if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { + if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { if (logger.isDebugEnabled()) { logger.debug("Skipping Cleanup phase ..."); } return; - } + } if (logger.isDebugEnabled()) { logger.debug("Cleaning up temporary resources created for testing ..."); } @@ -2314,7 +2294,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM // Note: Any non-success responses from the delete operation // below are ignored and not reported. ClientResponse res = - client.deleteContact(parentResourceId, itemResourceId, contactResourceId); + client.deleteContact(parentResourceId, itemResourceId, contactResourceId); res.releaseConnection(); } // Clean up item resources. @@ -2324,7 +2304,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM // Note: Any non-success responses from the delete operation // below are ignored and not reported. ClientResponse res = - client.deleteItem(parentResourceId, itemResourceId); + client.deleteItem(parentResourceId, itemResourceId); res.releaseConnection(); } // Clean up parent resources. @@ -2342,7 +2322,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM public String getContactServicePathComponent() { return ContactClient.SERVICE_PATH_COMPONENT; } - + /** * Returns the root URL for the item service. * @@ -2375,7 +2355,6 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier; } - /** * Returns the root URL for the contact service. * @@ -2393,9 +2372,9 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * @return The root URL for the contact service. */ protected String getContactServiceRootURL(String parentResourceIdentifier, - String itemResourceIdentifier) { - return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/" + - getContactServicePathComponent(); + String itemResourceIdentifier) { + return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/" + + getContactServicePathComponent(); } /** @@ -2411,8 +2390,8 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXM * @return The URL of a specific resource managed by a service. */ protected String getContactResourceURL(String parentResourceIdentifier, - String itemResourceIdentifier, String contactResourceIdentifier) { + String itemResourceIdentifier, String contactResourceIdentifier) { return getContactServiceRootURL(parentResourceIdentifier, - itemResourceIdentifier) + "/" + contactResourceIdentifier; + itemResourceIdentifier) + "/" + contactResourceIdentifier; } }