From 11d7eb0d2095e7ae284a90e898fea87a0327bd44 Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Wed, 9 May 2018 23:00:18 -0700 Subject: [PATCH] DRYD-328: First draft of Use of Collections procedure. --- services/JaxRsServiceProvider/pom.xml | 5 + .../CollectionSpaceJaxRsApplication.java | 2 + services/pom.xml | 1 + services/uoc/3rdparty/build.xml | 130 ++++ .../nuxeo-platform-cs-loanin/build.xml | 161 +++++ .../3rdparty/nuxeo-platform-cs-loanin/pom.xml | 55 ++ .../src/main/resources/OSGI-INF/README.txt | 16 + .../src/main/resources/schemas/README.txt | 16 + services/uoc/3rdparty/pom.xml | 24 + services/uoc/build.xml | 124 ++++ services/uoc/client/pom.xml | 91 +++ .../services/client/UocClient.java | 62 ++ .../services/client/UocProxy.java | 34 + .../services/client/test/UocAuthRefsTest.java | 430 +++++++++++ .../services/client/test/UocServiceTest.java | 679 ++++++++++++++++++ .../src/test/resources/log4j.properties | 23 + services/uoc/jaxb/pom.xml | 34 + .../services/UocJAXBSchema.java | 9 + .../services/UocListItemJAXBSchema.java | 6 + .../jaxb/src/main/resources/uoc-common.xsd | 47 ++ services/uoc/pom.xml | 26 + services/uoc/service/pom.xml | 96 +++ .../services/uoc/UocResource.java | 63 ++ .../services/uoc/nuxeo/UocConstants.java | 35 + .../uoc/nuxeo/UocDocumentModelHandler.java | 36 + .../uoc/nuxeo/UocValidatorHandler.java | 18 + .../services/test/UocServiceTest.java | 10 + .../uoc/service/src/test/resources/log4j.xml | 45 ++ 28 files changed, 2278 insertions(+) create mode 100644 services/uoc/3rdparty/build.xml create mode 100644 services/uoc/3rdparty/nuxeo-platform-cs-loanin/build.xml create mode 100644 services/uoc/3rdparty/nuxeo-platform-cs-loanin/pom.xml create mode 100644 services/uoc/3rdparty/nuxeo-platform-cs-loanin/src/main/resources/OSGI-INF/README.txt create mode 100644 services/uoc/3rdparty/nuxeo-platform-cs-loanin/src/main/resources/schemas/README.txt create mode 100644 services/uoc/3rdparty/pom.xml create mode 100644 services/uoc/build.xml create mode 100644 services/uoc/client/pom.xml create mode 100644 services/uoc/client/src/main/java/org/collectionspace/services/client/UocClient.java create mode 100644 services/uoc/client/src/main/java/org/collectionspace/services/client/UocProxy.java create mode 100644 services/uoc/client/src/test/java/org/collectionspace/services/client/test/UocAuthRefsTest.java create mode 100644 services/uoc/client/src/test/java/org/collectionspace/services/client/test/UocServiceTest.java create mode 100644 services/uoc/client/src/test/resources/log4j.properties create mode 100644 services/uoc/jaxb/pom.xml create mode 100644 services/uoc/jaxb/src/main/java/org/collectionspace/services/UocJAXBSchema.java create mode 100644 services/uoc/jaxb/src/main/java/org/collectionspace/services/UocListItemJAXBSchema.java create mode 100644 services/uoc/jaxb/src/main/resources/uoc-common.xsd create mode 100644 services/uoc/pom.xml create mode 100644 services/uoc/service/pom.xml create mode 100644 services/uoc/service/src/main/java/org/collectionspace/services/uoc/UocResource.java create mode 100644 services/uoc/service/src/main/java/org/collectionspace/services/uoc/nuxeo/UocConstants.java create mode 100644 services/uoc/service/src/main/java/org/collectionspace/services/uoc/nuxeo/UocDocumentModelHandler.java create mode 100644 services/uoc/service/src/main/java/org/collectionspace/services/uoc/nuxeo/UocValidatorHandler.java create mode 100644 services/uoc/service/src/test/java/org/collectionspace/services/test/UocServiceTest.java create mode 100644 services/uoc/service/src/test/resources/log4j.xml diff --git a/services/JaxRsServiceProvider/pom.xml b/services/JaxRsServiceProvider/pom.xml index d423776ec..aab135965 100644 --- a/services/JaxRsServiceProvider/pom.xml +++ b/services/JaxRsServiceProvider/pom.xml @@ -254,6 +254,11 @@ org.collectionspace.services.loanout.service ${project.version} + + org.collectionspace.services + org.collectionspace.services.uoc.service + ${project.version} + org.collectionspace.services org.collectionspace.services.claim.service diff --git a/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java b/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java index 8409726be..5d17455f2 100644 --- a/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java +++ b/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java @@ -32,6 +32,7 @@ import org.collectionspace.services.group.GroupResource; import org.collectionspace.services.intake.IntakeResource; import org.collectionspace.services.loanin.LoaninResource; import org.collectionspace.services.loanout.LoanoutResource; +import org.collectionspace.services.uoc.UocResource; import org.collectionspace.services.valuationcontrol.ValuationcontrolResource; import org.collectionspace.services.objectexit.ObjectExitResource; import org.collectionspace.services.batch.BatchResource; @@ -133,6 +134,7 @@ public class CollectionSpaceJaxRsApplication extends Application addResourceToMapAndSingletons(new ExhibitionResource()); addResourceToMapAndSingletons(new ConditioncheckResource()); addResourceToMapAndSingletons(new ConservationResource()); + addResourceToMapAndSingletons(new UocResource()); addResourceToMapAndSingletons(new ValuationcontrolResource()); addResourceToMapAndSingletons(new ObjectExitResource()); addResourceToMapAndSingletons(new BatchResource()); diff --git a/services/pom.xml b/services/pom.xml index 53cd8fab2..8c1775988 100644 --- a/services/pom.xml +++ b/services/pom.xml @@ -87,6 +87,7 @@ workflow index media + uoc publicitem IntegrationTests PerformanceTests diff --git a/services/uoc/3rdparty/build.xml b/services/uoc/3rdparty/build.xml new file mode 100644 index 000000000..658bd884a --- /dev/null +++ b/services/uoc/3rdparty/build.xml @@ -0,0 +1,130 @@ + + + uoc service 3rdparty + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/uoc/3rdparty/nuxeo-platform-cs-loanin/build.xml b/services/uoc/3rdparty/nuxeo-platform-cs-loanin/build.xml new file mode 100644 index 000000000..c271e01d1 --- /dev/null +++ b/services/uoc/3rdparty/nuxeo-platform-cs-loanin/build.xml @@ -0,0 +1,161 @@ + + + + uoc nuxeo document type + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/uoc/3rdparty/nuxeo-platform-cs-loanin/pom.xml b/services/uoc/3rdparty/nuxeo-platform-cs-loanin/pom.xml new file mode 100644 index 000000000..a037fc740 --- /dev/null +++ b/services/uoc/3rdparty/nuxeo-platform-cs-loanin/pom.xml @@ -0,0 +1,55 @@ + + + + org.collectionspace.services + org.collectionspace.services.uoc.3rdparty + 5.1-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.uoc.3rdparty.nuxeo + services.uoc.3rdparty.nuxeo + jar + + Use of Collections Nuxeo Document Type + + + + uoc + Uoc + uoc_common + cs_default + + + + + + src/main/resources + true + + + ../../../../3rdparty/nuxeo/nuxeo-doctype/src/main/resources + true + + + + + org.apache.maven.plugins + maven-jar-plugin + + + target/classes/META-INF/MANIFEST.MF + + ${eclipseVersion} + 2 + + + + + + + + diff --git a/services/uoc/3rdparty/nuxeo-platform-cs-loanin/src/main/resources/OSGI-INF/README.txt b/services/uoc/3rdparty/nuxeo-platform-cs-loanin/src/main/resources/OSGI-INF/README.txt new file mode 100644 index 000000000..5f8c5a6d0 --- /dev/null +++ b/services/uoc/3rdparty/nuxeo-platform-cs-loanin/src/main/resources/OSGI-INF/README.txt @@ -0,0 +1,16 @@ +Files formerly located in this directory are no longer needed +------------------------------------------------------------- + +In CollectionSpace versions 4.0 and higher, changes were introduced +which streamline and simplify the process through which you configure +fields in CollectionSpace's main record types. + +In most cases now, you will typically change the behavior of existing fields, +or create extension schemas to add new fields specific to your museum and/or +community of practice, merely by editing simpler XML-based configuration +files within CollectionSpace's Application layer. + +Services layer files that were formerly located in this directory and +other, similar directories - which you previously needed to manually +create or edit - are now generated automatically from your configuration +in the Application layer. \ No newline at end of file diff --git a/services/uoc/3rdparty/nuxeo-platform-cs-loanin/src/main/resources/schemas/README.txt b/services/uoc/3rdparty/nuxeo-platform-cs-loanin/src/main/resources/schemas/README.txt new file mode 100644 index 000000000..5f8c5a6d0 --- /dev/null +++ b/services/uoc/3rdparty/nuxeo-platform-cs-loanin/src/main/resources/schemas/README.txt @@ -0,0 +1,16 @@ +Files formerly located in this directory are no longer needed +------------------------------------------------------------- + +In CollectionSpace versions 4.0 and higher, changes were introduced +which streamline and simplify the process through which you configure +fields in CollectionSpace's main record types. + +In most cases now, you will typically change the behavior of existing fields, +or create extension schemas to add new fields specific to your museum and/or +community of practice, merely by editing simpler XML-based configuration +files within CollectionSpace's Application layer. + +Services layer files that were formerly located in this directory and +other, similar directories - which you previously needed to manually +create or edit - are now generated automatically from your configuration +in the Application layer. \ No newline at end of file diff --git a/services/uoc/3rdparty/pom.xml b/services/uoc/3rdparty/pom.xml new file mode 100644 index 000000000..846f8ab75 --- /dev/null +++ b/services/uoc/3rdparty/pom.xml @@ -0,0 +1,24 @@ + + + org.collectionspace.services.uoc + org.collectionspace.services + 5.1-SNAPSHOT + + + 4.0.0 + org.collectionspace.services.uoc.3rdparty + services.uoc.3rdparty + pom + + + 3rd party build for uoc service + + + + + + diff --git a/services/uoc/build.xml b/services/uoc/build.xml new file mode 100644 index 000000000..1975d1f31 --- /dev/null +++ b/services/uoc/build.xml @@ -0,0 +1,124 @@ + + + + uoc service + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/uoc/client/pom.xml b/services/uoc/client/pom.xml new file mode 100644 index 000000000..06e60ac1d --- /dev/null +++ b/services/uoc/client/pom.xml @@ -0,0 +1,91 @@ + + + + org.collectionspace.services + org.collectionspace.services.uoc + 5.1-SNAPSHOT + + + 4.0.0 + org.collectionspace.services.uoc.client + services.uoc.client + + + + + org.slf4j + slf4j-api + test + + + org.slf4j + slf4j-log4j12 + test + + + + org.collectionspace.services + org.collectionspace.services.jaxb + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.common + true + + + org.collectionspace.services + org.collectionspace.services.client + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.uoc.jaxb + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.person.client + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.authority.jaxb + ${project.version} + + + + org.testng + testng + + + org.jboss.resteasy + resteasy-jaxrs + + + + tjws + webserver + + + + + org.jboss.resteasy + resteasy-jaxb-provider + + + org.jboss.resteasy + resteasy-multipart-provider + + + commons-httpclient + commons-httpclient + + + + + collectionspace-services-uoc-client + + diff --git a/services/uoc/client/src/main/java/org/collectionspace/services/client/UocClient.java b/services/uoc/client/src/main/java/org/collectionspace/services/client/UocClient.java new file mode 100644 index 000000000..cc649638c --- /dev/null +++ b/services/uoc/client/src/main/java/org/collectionspace/services/client/UocClient.java @@ -0,0 +1,62 @@ +/** + * 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.collectionspace.services.uoc.UocCommon; + +/** + * UocClient.java + * + * $LastChangedRevision$ + * $LastChangedDate$ + * + */ +public class UocClient extends AbstractCommonListPoxServiceClientImpl { + + public static final String SERVICE_NAME = "uoc"; + 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 UocClient() throws Exception { + super(); + } + + public UocClient(String clientPropertiesFilename) throws Exception { + super(clientPropertiesFilename); + } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.AbstractServiceClientImpl#getServicePathComponent() + */ + @Override + public String getServicePathComponent() { + return SERVICE_PATH_COMPONENT; + } + + @Override + public String getServiceName() { + return SERVICE_NAME; + } + + @Override + public Class getProxyClass() { + return UocProxy.class; + } + +} diff --git a/services/uoc/client/src/main/java/org/collectionspace/services/client/UocProxy.java b/services/uoc/client/src/main/java/org/collectionspace/services/client/UocProxy.java new file mode 100644 index 000000000..6873b9c7f --- /dev/null +++ b/services/uoc/client/src/main/java/org/collectionspace/services/client/UocProxy.java @@ -0,0 +1,34 @@ +/** + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + * + * http://www.collectionspace.org + * http://wiki.collectionspace.org + * + * Copyright (c) 2009 Regents of the University of California + * + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + * + * You may obtain a copy of the ECL 2.0 License at + * https://source.collectionspace.org/collection-space/LICENSE.txt + */ +package org.collectionspace.services.client; + +import javax.ws.rs.Consumes; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +/** + * UocProxy.java + * + * $LastChangedRevision$ + * $LastChangedDate$ + * + */ +@Path(UocClient.SERVICE_PATH_PROXY) +@Produces({"application/xml"}) +@Consumes({"application/xml"}) +public interface UocProxy extends CollectionSpaceCommonListPoxProxy { +} diff --git a/services/uoc/client/src/test/java/org/collectionspace/services/client/test/UocAuthRefsTest.java b/services/uoc/client/src/test/java/org/collectionspace/services/client/test/UocAuthRefsTest.java new file mode 100644 index 000000000..5eda18c2c --- /dev/null +++ b/services/uoc/client/src/test/java/org/collectionspace/services/client/test/UocAuthRefsTest.java @@ -0,0 +1,430 @@ +/** + * 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 © 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.collectionspace.services.client.test; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.ws.rs.core.Response; + +import org.collectionspace.services.PersonJAXBSchema; +import org.collectionspace.services.client.CollectionSpaceClient; +import org.collectionspace.services.client.UocClient; +import org.collectionspace.services.client.PersonAuthorityClient; +import org.collectionspace.services.client.PersonAuthorityClientUtils; +import org.collectionspace.services.client.PayloadOutputPart; +import org.collectionspace.services.client.PoxPayloadIn; +import org.collectionspace.services.client.PoxPayloadOut; +import org.collectionspace.services.common.api.GregorianCalendarDateTimeUtils; +import org.collectionspace.services.common.authorityref.AuthorityRefList; +import org.collectionspace.services.jaxb.AbstractCommonList; +import org.collectionspace.services.person.PersonTermGroup; +import org.collectionspace.services.uoc.UocCommon; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * UocAuthRefsTest, carries out Authority References tests against a deployed + * and running uoc (aka Use of Collections) Service. + * + * $LastChangedRevision$ $LastChangedDate$ + */ +public class UocAuthRefsTest extends BaseServiceTest { + + private final String CLASS_NAME = UocAuthRefsTest.class.getName(); + private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); + + // Instance variables specific to this test. + final String SERVICE_NAME = "uoc"; + final String SERVICE_PATH_COMPONENT = "uoc"; + final String PERSON_AUTHORITY_NAME = "TestPersonAuth"; + private String knownResourceId = null; + private List uocIdsCreated = new ArrayList(); + private List personIdsCreated = new ArrayList(); + private String personAuthCSID = null; + private final int NUM_AUTH_REFS_EXPECTED = 0; + private final static String CURRENT_DATE_UTC = GregorianCalendarDateTimeUtils.currentDateUTC(); + + /* + * (non-Javadoc) + * + * @see + * org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() + */ + @Override + protected CollectionSpaceClient getClientInstance() { + throw new UnsupportedOperationException(); // method not supported (or needed) in this test class + } + + @Override + protected CollectionSpaceClient getClientInstance(String clientPropertiesFilename) { + throw new UnsupportedOperationException(); // method not supported (or needed) in this test class + } + + /* + * (non-Javadoc) + * + * @see org.collectionspace.services.client.test.BaseServiceTest# + * getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) + */ + @Override + protected AbstractCommonList getCommonList(Response response) { + throw new UnsupportedOperationException(); // method not supported (or needed) in this test class + } + + // --------------------------------------------------------------- + // CRUD tests : CREATE tests + // --------------------------------------------------------------- + // Success outcomes + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) + public void createWithAuthRefs(String testName) throws Exception { + testSetup(STATUS_CREATED, ServiceRequestType.CREATE); + + // Submit the request to the service and store the response. + String identifier = createIdentifier(); + + // Create all the person refs and entities + createPersonRefs(); + + // Create a new Use of Collections resource. + // + // One or more fields in this resource will be PersonAuthority + // references, and will refer to Person resources by their refNames. + UocClient uocClient = new UocClient(); + PoxPayloadOut multipart = createUocInstance("referenceNumber-" + identifier, "title-" + identifier); + String newId = null; + Response response = uocClient.create(multipart); + try { + int statusCode = response.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(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + newId = extractId(response); + } finally { + response.close(); + } + + // Store the ID returned from the first resource created + // for additional tests below. + if (knownResourceId == null) { + knownResourceId = newId; + if (logger.isDebugEnabled()) { + logger.debug(testName + ": knownResourceId=" + knownResourceId); + } + } + + // Store the IDs from every resource created by tests, + // so they can be deleted after tests have been run. + uocIdsCreated.add(newId); + } + + protected void createPersonRefs() throws Exception { + + PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); + // Create a temporary PersonAuthority resource, and its corresponding + // refName by which it can be identified. + PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(PERSON_AUTHORITY_NAME, + PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName()); + Response res = personAuthClient.create(multipart); + try { + int statusCode = res.getStatus(); + + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, STATUS_CREATED); + personAuthCSID = extractId(res); + } finally { + res.close(); + } + + String authRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null); + + // Create temporary Person resources, and their corresponding refNames + // by which they can be identified. + String csid = createPerson("Linus", "Lender", "linusLender", authRefName); + personIdsCreated.add(csid); + // lenderRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, + // csid, null); + // + // csid = createPerson("Art", "Lendersauthorizor", "artLendersauthorizor", + // authRefName); + // personIdsCreated.add(csid); + // lendersAuthorizerRefName = + // PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); + // + // csid = createPerson("Larry", "Lenderscontact", "larryLenderscontact", + // authRefName); + // personIdsCreated.add(csid); + // lendersContactRefName = + // PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); + // + // csid = createPerson("Carrie", "Borrowerscontact", "carrieBorrowerscontact", + // authRefName); + // personIdsCreated.add(csid); + // uocReferenceNumber = + // PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); + // + // csid = createPerson("Bonnie", "Borrowersauthorizer", + // "bonnieBorrowersauthorizer", authRefName); + // personIdsCreated.add(csid); + // borrowersAuthorizerRefName = + // PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); + + // FIXME: Add instance(s) of 'lenders' field when we can work with + // repeatable / multivalued authority reference fields. Be sure to + } + + protected String createPerson(String firstName, String surName, String shortId, String authRefName) + throws Exception { + String result = null; + + PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); + Map personInfo = new HashMap(); + personInfo.put(PersonJAXBSchema.FORE_NAME, firstName); + personInfo.put(PersonJAXBSchema.SUR_NAME, surName); + personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId); + List personTerms = new ArrayList(); + PersonTermGroup term = new PersonTermGroup(); + String termName = firstName + " " + surName; + term.setTermDisplayName(termName); + term.setTermName(termName); + personTerms.add(term); + PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonInstance(personAuthCSID, authRefName, + personInfo, personTerms, personAuthClient.getItemCommonPartName()); + Response res = personAuthClient.createItem(personAuthCSID, multipart); + try { + int statusCode = res.getStatus(); + + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, STATUS_CREATED); + result = extractId(res); + } finally { + res.close(); + } + + return result; + } + + // Success outcomes + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = { + "createWithAuthRefs" }) + public void readAndCheckAuthRefs(String testName) throws Exception { + // Perform setup. + testSetup(STATUS_OK, ServiceRequestType.READ); + + // Submit the request to the service and store the response. + UocClient uocClient = new UocClient(); + Response res = uocClient.read(knownResourceId); + UocCommon uocCommon = null; + try { + assertStatusCode(res, testName); + // Extract the common part from the response. + PoxPayloadIn input = new PoxPayloadIn(res.readEntity(String.class)); + uocCommon = (UocCommon) extractPart(input, uocClient.getCommonPartName(), UocCommon.class); + Assert.assertNotNull(uocCommon); + if (logger.isDebugEnabled()) { + logger.debug(objectAsXmlString(uocCommon, UocCommon.class)); + } + } finally { + if (res != null) { + res.close(); + } + } + // + // Check a couple of fields + // Assert.assertEquals(uocCommon.xyz(), lenderRefName); + // Assert.assertEquals(uocCommon.pdq(), lendersAuthorizerRefName); + // Assert.assertEquals(uocCommon.rem(), lendersContactRefName); + // + + // Get the auth refs and check them + Response res2 = uocClient.getAuthorityRefs(knownResourceId); + AuthorityRefList list = null; + try { + assertStatusCode(res2, testName); + list = res2.readEntity(AuthorityRefList.class); + // Assert.assertNotNull(list); + } finally { + if (res2 != null) { + res2.close(); + } + } + + List items = list.getAuthorityRefItem(); + int numAuthRefsFound = items.size(); + if (logger.isDebugEnabled()) { + logger.debug("Expected " + NUM_AUTH_REFS_EXPECTED + " authority references, found " + numAuthRefsFound); + } + + // Optionally output additional data about list members for debugging. + boolean iterateThroughList = true; + if (iterateThroughList && logger.isDebugEnabled()) { + int i = 0; + for (AuthorityRefList.AuthorityRefItem item : items) { + logger.debug(testName + ": list-item[" + i + "] Field:" + item.getSourceField() + "= " + + item.getAuthDisplayName() + item.getItemDisplayName()); + logger.debug(testName + ": list-item[" + i + "] refName=" + item.getRefName()); + logger.debug(testName + ": list-item[" + i + "] URI=" + item.getUri()); + i++; + } + } + + Assert.assertEquals(numAuthRefsFound, NUM_AUTH_REFS_EXPECTED, "Did not find all expected authority references! " + + "Expected " + NUM_AUTH_REFS_EXPECTED + ", found " + numAuthRefsFound); + + } + + // --------------------------------------------------------------- + // Cleanup of resources created during testing + // --------------------------------------------------------------- + + /** + * Deletes all resources created by tests, after all tests have been run. + * + * This cleanup method will always be run, even if one or more tests fail. For + * this reason, it attempts to remove all resources created at any point during + * testing, even if some of those resources may be expected to be deleted by + * certain tests. + * + * @throws Exception + */ + @Override + @AfterClass(alwaysRun = true) + public void cleanUp() throws Exception { + String noTest = System.getProperty("noTestCleanup"); + if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { + if (logger.isDebugEnabled()) { + logger.debug("Skipping Cleanup phase ..."); + } + return; + } + if (logger.isDebugEnabled()) { + logger.debug("Cleaning up temporary resources created for testing ..."); + } + // + // Delete the uoc records before the person items/terms + // + UocClient uocClient = new UocClient(); + for (String csid : uocIdsCreated) { + Response res = null; + try { + res = uocClient.delete(csid); + if (res.getStatus() != Response.Status.OK.getStatusCode()) { + throw new Exception(String.format("Could not delete uoc record with CSID=%s", csid)); + } + } catch (Throwable t) { + if (res != null) + res.close(); + throw t; + } + } + // + // Delete Person resource(s) (before PersonAuthority resources). + // + PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); + for (String csid : personIdsCreated) { + Response res = null; + try { + res = personAuthClient.deleteItem(personAuthCSID, csid); + if (res.getStatus() != Response.Status.OK.getStatusCode()) { + throw new Exception(String.format( + "Could not delete person item/term record with CSID=%s inside person authority with CSID=%s", + csid, personAuthCSID)); + } + } catch (Throwable t) { + if (res != null) + res.close(); + throw t; + } + } + // + // Delete the PersonAuthority resource. + // + if (personAuthCSID != null) { + Response res = null; + try { + res = personAuthClient.delete(personAuthCSID); + } catch (Throwable t) { + if (res != null) + res.close(); + throw t; + } + } + } + + // --------------------------------------------------------------- + // Utility methods used by tests above + // --------------------------------------------------------------- + @Override + public String getServiceName() { + return SERVICE_NAME; + } + + @Override + public String getServicePathComponent() { + return SERVICE_PATH_COMPONENT; + } + + private PoxPayloadOut createUocInstance(String referenceNumber, String title) throws Exception { + UocCommon uocCommon = new UocCommon(); + uocCommon.setTitle(title); + uocCommon.setReferenceNumber(referenceNumber); + // LenderGroupList lenderGroupList = new LenderGroupList(); + // LenderGroup lenderGroup = new LenderGroup(); + // lenderGroup.setLender(lender); + // lenderGroup.setLendersAuthorizer(lendersAuthorizer); + // lenderGroup.setLendersContact(lendersContact); + // lenderGroupList.getLenderGroup().add(lenderGroup); + // uocCommon.setLenderGroupList(lenderGroupList); + + PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent()); + PayloadOutputPart commonPart = multipart.addPart(new UocClient().getCommonPartName(), uocCommon); + + if (logger.isDebugEnabled()) { + logger.debug("to be created, uoc common"); + logger.debug(objectAsXmlString(uocCommon, UocCommon.class)); + } + + return multipart; + } + + @Override + protected Class getCommonListType() { + return AbstractCommonList.class; + } +} diff --git a/services/uoc/client/src/test/java/org/collectionspace/services/client/test/UocServiceTest.java b/services/uoc/client/src/test/java/org/collectionspace/services/client/test/UocServiceTest.java new file mode 100644 index 000000000..28d3f8c5a --- /dev/null +++ b/services/uoc/client/src/test/java/org/collectionspace/services/client/test/UocServiceTest.java @@ -0,0 +1,679 @@ +/** + * 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 © 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.collectionspace.services.client.test; + +//import java.util.ArrayList; +//import java.util.List; + +import javax.ws.rs.core.Response; + +import org.collectionspace.services.client.AbstractCommonListUtils; +import org.collectionspace.services.client.CollectionSpaceClient; +import org.collectionspace.services.client.UocClient; +import org.collectionspace.services.client.PayloadInputPart; +import org.collectionspace.services.client.PayloadOutputPart; +import org.collectionspace.services.client.PoxPayloadIn; +import org.collectionspace.services.client.PoxPayloadOut; +import org.collectionspace.services.common.api.GregorianCalendarDateTimeUtils; +import org.collectionspace.services.jaxb.AbstractCommonList; +import org.collectionspace.services.uoc.UocCommon; +import org.testng.Assert; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * UocServiceTest, carries out tests against a + * deployed and running uoc (aka Use of Collections) Service. + * + * $LastChangedRevision$ + * $LastChangedDate$ + */ +public class UocServiceTest extends AbstractPoxServiceTestImpl { + + /** The logger. */ + private final String CLASS_NAME = UocServiceTest.class.getName(); + private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); + // Instance variables specific to this test. + /** The service path component. */ + final String SERVICE_NAME = "uoc"; + final String SERVICE_PATH_COMPONENT = "uoc"; + private String LENDER_REF_NAME = + "urn:cspace:org.collectionspace.demo:personauthorities:name(TestPersonAuth):item:name(HarryLender)'Harry Lender'"; + private final static String CURRENT_DATE_UTC = + GregorianCalendarDateTimeUtils.currentDateUTC(); + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() + */ + @Override + protected CollectionSpaceClient getClientInstance() throws Exception { + return new UocClient(); + } + + @Override + protected CollectionSpaceClient getClientInstance(String clientPropertiesFilename) throws Exception { + return new UocClient(clientPropertiesFilename); + } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) + */ + @Override + protected AbstractCommonList getCommonList(Response response) { + return response.readEntity(AbstractCommonList.class); + } + + // --------------------------------------------------------------- + // CRUD tests : CREATE tests + // --------------------------------------------------------------- + + // Success outcomes + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String) + */ + @Override +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) + public void create(String testName) throws Exception { + // Perform setup, such as initializing the type of service request + // (e.g. CREATE, DELETE), its valid and expected status codes, and + // its associated HTTP method name (e.g. POST, DELETE). + setupCreate(); + + // Submit the request to the service and store the response. + UocClient client = new UocClient(); + String identifier = createIdentifier(); + PoxPayloadOut multipart = createUocInstance(identifier); + String newID = null; + Response 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(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + + newID = extractId(res); + } finally { + if (res != null) { + res.close(); + } + } + + // Store the ID returned from the first resource created + // for additional tests below. + if (knownResourceId == null) { + knownResourceId = newID; + if (logger.isDebugEnabled()) { + logger.debug(testName + ": knownResourceId=" + knownResourceId); + } + } + + // Store the IDs from every resource created by tests, + // so they can be deleted after tests have been run. + allResourceIdsCreated.add(newID); + } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String) + */ + @Override +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"create"}) + public void createList(String testName) throws Exception { + for (int i = 0; i < 3; i++) { + create(testName); + } + } + + + /* + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"create", "testSubmitRequest"}) + public void createWithEmptyEntityBody(String testName) throws Exception { + + if (logger.isDebugEnabled()) { + logger.debug(testBanner(testName, CLASS_NAME)); + } + // Perform setup. + setupCreateWithEmptyEntityBody(); + + // Submit the request to the service and store the response. + String method = REQUEST_TYPE.httpMethodName(); + String url = getServiceRootURL(); + String mediaType = MediaType.APPLICATION_XML; + final String entity = ""; + int statusCode = submitRequest(method, url, mediaType, entity); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug("createWithEmptyEntityBody url=" + url + + " status=" + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"create", "testSubmitRequest"}) + public void createWithMalformedXml(String testName) throws Exception { + + if (logger.isDebugEnabled()) { + logger.debug(testBanner(testName, CLASS_NAME)); + } + // Perform setup. + setupCreateWithMalformedXml(testName, logger); + + // Submit the request to the service and store the response. + String method = REQUEST_TYPE.httpMethodName(); + String url = getServiceRootURL(); + String mediaType = MediaType.APPLICATION_XML; + final String entity = MALFORMED_XML_DATA; // Constant from base class. + int statusCode = submitRequest(method, url, mediaType, entity); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": url=" + url + + " status=" + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + 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); + } + */ + + // --------------------------------------------------------------- + // CRUD tests : READ tests + // --------------------------------------------------------------- + + // Success outcomes + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String) + */ + @Override +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"create"}) + public void read(String testName) throws Exception { + // Perform setup. + setupRead(); + + // Submit the request to the service and store the response. + UocClient client = new UocClient(); + Response res = client.read(knownResourceId); + PoxPayloadIn input = null; + try { + assertStatusCode(res, testName); + input = new PoxPayloadIn(res.readEntity(String.class)); + } finally { + if (res != null) { + res.close(); + } + } + + // Get the common part of the response and verify that it is not null. + PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName()); + UocCommon uocCommon = null; + if (payloadInputPart != null) { + uocCommon = (UocCommon) payloadInputPart.getBody(); + } + Assert.assertNotNull(uocCommon); + + } + + // Failure outcomes + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String) + */ + @Override +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"read"}) + public void readNonExistent(String testName) throws Exception { + // Perform setup. + setupReadNonExistent(); + + // Submit the request to the service and store the response. + UocClient client = new UocClient(); + Response 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(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + } finally { + if (res != null) { + res.close(); + } + } + } + + // --------------------------------------------------------------- + // CRUD tests : READ_LIST tests + // --------------------------------------------------------------- + + // Success outcomes + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String) + */ + @Override +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"createList", "read"}) + public void readList(String testName) throws Exception { + // Perform setup. + setupReadList(); + + // Submit the request to the service and store the response. + AbstractCommonList list = null; + UocClient client = new UocClient(); + Response res = client.readList(); + assertStatusCode(res, testName); + 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(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + + list = res.readEntity(getCommonListType()); + } finally { + if (res != null) { + res.close(); + } + } + + // Optionally output additional data about list members for debugging. + boolean iterateThroughList = true; + if(iterateThroughList && logger.isDebugEnabled()){ + AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); + } + + } + + // Failure outcomes + // None at present. + + // --------------------------------------------------------------- + // CRUD tests : UPDATE tests + // --------------------------------------------------------------- + + // Success outcomes + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String) + */ + @Override +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"read"}) + public void update(String testName) throws Exception { + // Perform setup. + setupRead(); + + // Retrieve the contents of a resource to update. + UocClient client = new UocClient(); + Response res = client.read(knownResourceId); + PoxPayloadIn input = null; + try { + assertStatusCode(res, testName); + input = new PoxPayloadIn(res.readEntity(String.class)); + if (logger.isDebugEnabled()) { + logger.debug("got object to update with ID: " + knownResourceId); + } + } finally { + if (res != null) { + res.close(); + } + } + + // Extract the common part from the response. + PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName()); + UocCommon uocCommon = null; + if (payloadInputPart != null) { + uocCommon = (UocCommon) payloadInputPart.getBody(); + } + Assert.assertNotNull(uocCommon); + + // Update the content of this resource. + uocCommon.setReferenceNumber("updated-" + uocCommon.getReferenceNumber()); + uocCommon.setTitle("updated-" + uocCommon.getTitle()); + if (logger.isDebugEnabled()) { + logger.debug("to be updated object"); + logger.debug(objectAsXmlString(uocCommon, UocCommon.class)); + } + + setupUpdate(); + + // Submit the updated common part in an update request to the service + // and store the response. + PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent()); + PayloadOutputPart commonPart = output.addPart(client.getCommonPartName(), uocCommon); + res = client.update(knownResourceId, output); + try { + assertStatusCode(res, testName); + 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(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + input = new PoxPayloadIn(res.readEntity(String.class)); + } finally { + if (res != null) { + res.close(); + } + } + + // Extract the updated common part from the response. + payloadInputPart = input.getPart(client.getCommonPartName()); + UocCommon updatedUocCommon = null; + if (payloadInputPart != null) { + updatedUocCommon = (UocCommon) payloadInputPart.getBody(); + } + Assert.assertNotNull(updatedUocCommon); + + // Check selected fields in the updated common part. + Assert.assertEquals(updatedUocCommon.getReferenceNumber(), + uocCommon.getReferenceNumber(), + "Data in updated object did not match submitted data."); + + if (logger.isDebugEnabled()) { + logger.debug("UTF-8 data sent=" + uocCommon.getTitle() + "\n" + + "UTF-8 data received=" + updatedUocCommon.getTitle()); + } + } + + @Override +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"update", "testSubmitRequest"}) + public void updateNonExistent(String testName) throws Exception { + // Perform setup. + setupUpdateNonExistent(); + + // Submit the request to the service and store the response. + // Note: The ID used in this 'create' call may be arbitrary. + // The only relevant ID may be the one used in update(), below. + UocClient client = new UocClient(); + PoxPayloadOut multipart = createUocInstance(NON_EXISTENT_ID); + Response 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(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + } finally { + if (res != null) { + res.close(); + } + } + } + + // --------------------------------------------------------------- + // CRUD tests : DELETE tests + // --------------------------------------------------------------- + + // Success outcomes + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String) + */ + @Override +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"}) + public void delete(String testName) throws Exception { + // Perform setup. + setupDelete(); + + // Submit the request to the service and store the response. + UocClient client = new UocClient(); + Response 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(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + } finally { + if (res != null) { + res.close(); + } + } + } + + // Failure outcomes + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String) + */ + @Override +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"delete"}) + public void deleteNonExistent(String testName) throws Exception { + // Perform setup. + setupDeleteNonExistent(); + + // Submit the request to the service and store the response. + UocClient client = new UocClient(); + Response 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(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + } finally { + if (res != null) { + res.close(); + } + } + } + + // --------------------------------------------------------------- + // Utility tests : tests of code used in tests above + // --------------------------------------------------------------- + + /** + * Tests the code for manually submitting data that is used by several + * of the methods above. + */ +// @Test(dependsOnMethods = {"create", "read"}) + public void testSubmitRequest() { + + // Expected status code: 200 OK + final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); + + // Submit the request to the service and store the response. + String method = ServiceRequestType.READ.httpMethodName(); + String url = getResourceURL(knownResourceId); + int statusCode = submitRequest(method, url); + + // Check the status code of the response: does it match + // the expected response(s)? + if (logger.isDebugEnabled()) { + logger.debug("testSubmitRequest: url=" + url + + " status=" + statusCode); + } + Assert.assertEquals(statusCode, EXPECTED_STATUS); + + } + + // --------------------------------------------------------------- + // Utility methods used by tests above + // --------------------------------------------------------------- + + @Override + public String getServiceName() { + return SERVICE_NAME; + } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent() + */ + @Override + public String getServicePathComponent() { + return SERVICE_PATH_COMPONENT; + } + + @Override + protected PoxPayloadOut createInstance(String identifier) throws Exception { + return createUocInstance(identifier); + } + + /** + * Creates the uoc instance. + * + * @param identifier the identifier + * @return the multipart output + * @throws Exception + */ + private PoxPayloadOut createUocInstance(String identifier) throws Exception { + return createUocInstance( + "referenceNumber-" + identifier, + "title-" + identifier); + } + + /** + * Creates the uoc instance. + * + * @param referenceNumber the Use of Collections ref number + * @param title the title + * @return the multipart output + * @throws Exception + */ + private PoxPayloadOut createUocInstance(String referenceNumber, + String title) throws Exception { + + UocCommon uocCommon = new UocCommon(); + uocCommon.setReferenceNumber(referenceNumber); + uocCommon.setTitle(title); + + PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent()); + PayloadOutputPart commonPart = + multipart.addPart(new UocClient().getCommonPartName(), uocCommon); + + if (logger.isDebugEnabled()) { + logger.debug("to be created, uoc common"); + logger.debug(objectAsXmlString(uocCommon, UocCommon.class)); + } + + return multipart; + } + + @Override + public void CRUDTests(String testName) { + // TODO Auto-generated method stub + + } + + @Override + protected PoxPayloadOut createInstance(String commonPartName, + String identifier) throws Exception { + PoxPayloadOut result = createUocInstance(identifier); + return result; + } + + @Override + protected UocCommon updateInstance(UocCommon commonPartObject) { + // TODO Auto-generated method stub + return null; + } + + @Override + protected void compareUpdatedInstances(UocCommon original, + UocCommon updated) throws Exception { + // TODO Auto-generated method stub + + } +} diff --git a/services/uoc/client/src/test/resources/log4j.properties b/services/uoc/client/src/test/resources/log4j.properties new file mode 100644 index 000000000..148a3e865 --- /dev/null +++ b/services/uoc/client/src/test/resources/log4j.properties @@ -0,0 +1,23 @@ +log4j.rootLogger=debug, stdout, R + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout + +# Pattern to output the caller's file name and line number. +log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n + +log4j.appender.R=org.apache.log4j.RollingFileAppender +log4j.appender.R.File=target/test-client.log + +log4j.appender.R.MaxFileSize=100KB +# Keep one backup file +log4j.appender.R.MaxBackupIndex=1 + +log4j.appender.R.layout=org.apache.log4j.PatternLayout +log4j.appender.R.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n + +#packages +log4j.logger.org.collectionspace=DEBUG +log4j.logger.org.apache=INFO +log4j.logger.httpclient=INFO +log4j.logger.org.jboss.resteasy=INFO diff --git a/services/uoc/jaxb/pom.xml b/services/uoc/jaxb/pom.xml new file mode 100644 index 000000000..18ebbddaa --- /dev/null +++ b/services/uoc/jaxb/pom.xml @@ -0,0 +1,34 @@ + + + + org.collectionspace.services.uoc + org.collectionspace.services + 5.1-SNAPSHOT + + + 4.0.0 + org.collectionspace.services.uoc.jaxb + services.uoc.jaxb + + + + org.collectionspace.services + org.collectionspace.services.jaxb + ${project.version} + + + + + collectionspace-services-uoc-jaxb + install + + + org.jvnet.jaxb2.maven2 + maven-jaxb2-plugin + + + + + diff --git a/services/uoc/jaxb/src/main/java/org/collectionspace/services/UocJAXBSchema.java b/services/uoc/jaxb/src/main/java/org/collectionspace/services/UocJAXBSchema.java new file mode 100644 index 000000000..68f84d6b7 --- /dev/null +++ b/services/uoc/jaxb/src/main/java/org/collectionspace/services/UocJAXBSchema.java @@ -0,0 +1,9 @@ +/** + * + */ +package org.collectionspace.services; + +public interface UocJAXBSchema { + final static String UOC_REFERENCE_NUMBER = "referenceNumber"; + final static String UOC_TITLE = "title"; +} \ No newline at end of file diff --git a/services/uoc/jaxb/src/main/java/org/collectionspace/services/UocListItemJAXBSchema.java b/services/uoc/jaxb/src/main/java/org/collectionspace/services/UocListItemJAXBSchema.java new file mode 100644 index 000000000..315436c3b --- /dev/null +++ b/services/uoc/jaxb/src/main/java/org/collectionspace/services/UocListItemJAXBSchema.java @@ -0,0 +1,6 @@ +package org.collectionspace.services; + +public interface UocListItemJAXBSchema { + final static String UOC_REFERENCE_NUMBER = "referenceNumber"; + final static String UOC_TITLE = "title"; +} diff --git a/services/uoc/jaxb/src/main/resources/uoc-common.xsd b/services/uoc/jaxb/src/main/resources/uoc-common.xsd new file mode 100644 index 000000000..e82423553 --- /dev/null +++ b/services/uoc/jaxb/src/main/resources/uoc-common.xsd @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/uoc/pom.xml b/services/uoc/pom.xml new file mode 100644 index 000000000..2bcacda8b --- /dev/null +++ b/services/uoc/pom.xml @@ -0,0 +1,26 @@ + + + + + org.collectionspace.services + org.collectionspace.services.main + 5.1-SNAPSHOT + + + 4.0.0 + org.collectionspace.services.uoc + services.uoc + pom + + + + + + jaxb + service + 3rdparty + client + + + + diff --git a/services/uoc/service/pom.xml b/services/uoc/service/pom.xml new file mode 100644 index 000000000..ca1486574 --- /dev/null +++ b/services/uoc/service/pom.xml @@ -0,0 +1,96 @@ + + + + + org.collectionspace.services + org.collectionspace.services.uoc + 5.1-SNAPSHOT + + + 4.0.0 + org.collectionspace.services.uoc.service + services.uoc.service + jar + + + + org.collectionspace.services + org.collectionspace.services.common + + + org.collectionspace.services + org.collectionspace.services.uoc.jaxb + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.uoc.client + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.collectionobject.jaxb + ${project.version} + + + + + junit + junit + test + + + org.testng + testng + + + + + + javax.security + jaas + 1.0.01 + provided + + + + + + org.jboss.resteasy + resteasy-jaxrs + + + tjws + webserver + + + + + org.jboss.resteasy + resteasy-jaxb-provider + + + org.jboss.resteasy + resteasy-multipart-provider + + + + + + org.nuxeo.ecm.core + nuxeo-core-api + + + jboss-remoting + jboss + + + + + + + + collectionspace-services-uoc + + + diff --git a/services/uoc/service/src/main/java/org/collectionspace/services/uoc/UocResource.java b/services/uoc/service/src/main/java/org/collectionspace/services/uoc/UocResource.java new file mode 100644 index 000000000..053b831ae --- /dev/null +++ b/services/uoc/service/src/main/java/org/collectionspace/services/uoc/UocResource.java @@ -0,0 +1,63 @@ +/** + * 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 2009 University of California at Berkeley + + * 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 + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.collectionspace.services.uoc; + +import org.collectionspace.services.client.UocClient; +import org.collectionspace.services.common.NuxeoBasedResource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.ws.rs.Consumes; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +@Path(UocClient.SERVICE_PATH) +@Consumes("application/xml") +@Produces("application/xml") +public class UocResource extends NuxeoBasedResource { + + final Logger logger = LoggerFactory.getLogger(UocResource.class); + + @Override + protected String getVersionString() { + final String lastChangeRevision = "$LastChangedRevision$"; + return lastChangeRevision; + } + + @Override + public String getServiceName() { + return UocClient.SERVICE_NAME; + } + + @Override + public Class getCommonPartClass() { + return UocCommon.class; + } +} + + + + + + diff --git a/services/uoc/service/src/main/java/org/collectionspace/services/uoc/nuxeo/UocConstants.java b/services/uoc/service/src/main/java/org/collectionspace/services/uoc/nuxeo/UocConstants.java new file mode 100644 index 000000000..9891259af --- /dev/null +++ b/services/uoc/service/src/main/java/org/collectionspace/services/uoc/nuxeo/UocConstants.java @@ -0,0 +1,35 @@ +/** + * 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 2009 University of California at Berkeley + + * 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 + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.collectionspace.services.uoc.nuxeo; + +/** + * UocConstants specifies constants for the Use of Collections service + * + */ +public class UocConstants { + + public final static String NUXEO_DOCTYPE = "Uoc"; + public final static String NUXEO_SCHEMA_NAME = "uoc"; + public final static String NUXEO_DC_TITLE = "CollectionSpace-Uoc"; +} diff --git a/services/uoc/service/src/main/java/org/collectionspace/services/uoc/nuxeo/UocDocumentModelHandler.java b/services/uoc/service/src/main/java/org/collectionspace/services/uoc/nuxeo/UocDocumentModelHandler.java new file mode 100644 index 000000000..d316caec5 --- /dev/null +++ b/services/uoc/service/src/main/java/org/collectionspace/services/uoc/nuxeo/UocDocumentModelHandler.java @@ -0,0 +1,36 @@ +/** + * 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 2009 University of California at Berkeley + + * 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 + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.collectionspace.services.uoc.nuxeo; + +import org.collectionspace.services.uoc.UocCommon; +import org.collectionspace.services.nuxeo.client.java.NuxeoDocumentModelHandler; + +/** UocDocumentModelHandler + * $LastChangedRevision$ + * $LastChangedDate$ + */ +public class UocDocumentModelHandler + extends NuxeoDocumentModelHandler { +} + diff --git a/services/uoc/service/src/main/java/org/collectionspace/services/uoc/nuxeo/UocValidatorHandler.java b/services/uoc/service/src/main/java/org/collectionspace/services/uoc/nuxeo/UocValidatorHandler.java new file mode 100644 index 000000000..a28719017 --- /dev/null +++ b/services/uoc/service/src/main/java/org/collectionspace/services/uoc/nuxeo/UocValidatorHandler.java @@ -0,0 +1,18 @@ +package org.collectionspace.services.uoc.nuxeo; + +import org.collectionspace.services.common.context.ServiceContext; +import org.collectionspace.services.common.document.InvalidDocumentException; +import org.collectionspace.services.common.document.ValidatorHandler; +import org.collectionspace.services.common.document.DocumentHandler.Action; + +public class UocValidatorHandler implements ValidatorHandler { + + @Override + public void validate(Action action, ServiceContext ctx) + throws InvalidDocumentException { + // TODO Auto-generated method stub + System.out.println("UocValidatorHandler executed."); + + } + +} diff --git a/services/uoc/service/src/test/java/org/collectionspace/services/test/UocServiceTest.java b/services/uoc/service/src/test/java/org/collectionspace/services/test/UocServiceTest.java new file mode 100644 index 000000000..4d9f87923 --- /dev/null +++ b/services/uoc/service/src/test/java/org/collectionspace/services/test/UocServiceTest.java @@ -0,0 +1,10 @@ +package org.collectionspace.services.test; + +/** + * Placeholder for server-side testing of Use of Collections service code. + * + * @version $Revision$ + */ +public class UocServiceTest { + //empty +} diff --git a/services/uoc/service/src/test/resources/log4j.xml b/services/uoc/service/src/test/resources/log4j.xml new file mode 100644 index 000000000..52121cb83 --- /dev/null +++ b/services/uoc/service/src/test/resources/log4j.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- 2.47.3