From 8072a4d68a5c05d4cc497ae72cc3ef5a04e1c6e0 Mon Sep 17 00:00:00 2001 From: Ray Lee Date: Mon, 9 Nov 2015 17:19:19 -0800 Subject: [PATCH] CSPACE-6902: Add conservation procedure. --- services/JaxRsServiceProvider/pom.xml | 5 + .../CollectionSpaceJaxRsApplication.java | 2 + services/build.xml | 3 + .../db/postgresql/load_id_generators.sql | 36 + services/conservation/3rdparty/build.xml | 131 ++++ .../nuxeo-platform-cs-conservation/build.xml | 161 ++++ .../nuxeo-platform-cs-conservation/pom.xml | 56 ++ .../src/main/resources/OSGI-INF/README.txt | 16 + .../src/main/resources/schemas/README.txt | 16 + services/conservation/3rdparty/pom.xml | 25 + services/conservation/build.xml | 124 ++++ services/conservation/client/pom.xml | 91 +++ .../services/client/ConservationClient.java | 52 ++ .../services/client/ConservationProxy.java | 34 + .../client/test/ConservationAuthRefsTest.java | 426 +++++++++++ .../client/test/ConservationServiceTest.java | 701 ++++++++++++++++++ .../src/test/resources/log4j.properties | 23 + services/conservation/jaxb/pom.xml | 34 + .../services/ConservationJAXBSchema.java | 10 + .../ConservationListItemJAXBSchema.java | 7 + .../main/resources/conservation-common.xsd | 123 +++ services/conservation/pom.xml | 26 + services/conservation/service/pom.xml | 102 +++ .../conservation/ConservationResource.java | 63 ++ .../nuxeo/ConservationConstants.java | 35 + .../ConservationDocumentModelHandler.java | 36 + .../nuxeo/ConservationValidatorHandler.java | 18 + .../test/ConservationServiceTest.java | 13 + .../service/src/test/resources/log4j.xml | 45 ++ services/pom.xml | 1 + 30 files changed, 2415 insertions(+) create mode 100644 services/conservation/3rdparty/build.xml create mode 100644 services/conservation/3rdparty/nuxeo-platform-cs-conservation/build.xml create mode 100644 services/conservation/3rdparty/nuxeo-platform-cs-conservation/pom.xml create mode 100644 services/conservation/3rdparty/nuxeo-platform-cs-conservation/src/main/resources/OSGI-INF/README.txt create mode 100644 services/conservation/3rdparty/nuxeo-platform-cs-conservation/src/main/resources/schemas/README.txt create mode 100644 services/conservation/3rdparty/pom.xml create mode 100644 services/conservation/build.xml create mode 100644 services/conservation/client/pom.xml create mode 100644 services/conservation/client/src/main/java/org/collectionspace/services/client/ConservationClient.java create mode 100644 services/conservation/client/src/main/java/org/collectionspace/services/client/ConservationProxy.java create mode 100644 services/conservation/client/src/test/java/org/collectionspace/services/client/test/ConservationAuthRefsTest.java create mode 100644 services/conservation/client/src/test/java/org/collectionspace/services/client/test/ConservationServiceTest.java create mode 100644 services/conservation/client/src/test/resources/log4j.properties create mode 100644 services/conservation/jaxb/pom.xml create mode 100644 services/conservation/jaxb/src/main/java/org/collectionspace/services/ConservationJAXBSchema.java create mode 100644 services/conservation/jaxb/src/main/java/org/collectionspace/services/ConservationListItemJAXBSchema.java create mode 100644 services/conservation/jaxb/src/main/resources/conservation-common.xsd create mode 100644 services/conservation/pom.xml create mode 100644 services/conservation/service/pom.xml create mode 100644 services/conservation/service/src/main/java/org/collectionspace/services/conservation/ConservationResource.java create mode 100644 services/conservation/service/src/main/java/org/collectionspace/services/conservation/nuxeo/ConservationConstants.java create mode 100644 services/conservation/service/src/main/java/org/collectionspace/services/conservation/nuxeo/ConservationDocumentModelHandler.java create mode 100644 services/conservation/service/src/main/java/org/collectionspace/services/conservation/nuxeo/ConservationValidatorHandler.java create mode 100644 services/conservation/service/src/test/java/org/collectionspace/services/test/ConservationServiceTest.java create mode 100644 services/conservation/service/src/test/resources/log4j.xml diff --git a/services/JaxRsServiceProvider/pom.xml b/services/JaxRsServiceProvider/pom.xml index a47579dad..e91061e95 100644 --- a/services/JaxRsServiceProvider/pom.xml +++ b/services/JaxRsServiceProvider/pom.xml @@ -229,6 +229,11 @@ org.collectionspace.services.conditioncheck.service ${project.version} + + org.collectionspace.services + org.collectionspace.services.conservation.service + ${project.version} + org.collectionspace.services org.collectionspace.services.objectexit.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 06c5f87c2..23edf527b 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 @@ -53,6 +53,7 @@ import org.collectionspace.services.person.PersonAuthorityResource; import org.collectionspace.services.citation.CitationAuthorityResource; import org.collectionspace.services.exhibition.ExhibitionResource; import org.collectionspace.services.conditioncheck.ConditioncheckResource; +import org.collectionspace.services.conservation.ConservationResource; import javax.servlet.ServletContext; import javax.ws.rs.core.Application; @@ -120,6 +121,7 @@ public class CollectionSpaceJaxRsApplication extends Application addResourceToMapAndSingletons(new LoanoutResource()); addResourceToMapAndSingletons(new ExhibitionResource()); addResourceToMapAndSingletons(new ConditioncheckResource()); + addResourceToMapAndSingletons(new ConservationResource()); addResourceToMapAndSingletons(new ValuationcontrolResource()); addResourceToMapAndSingletons(new ObjectExitResource()); addResourceToMapAndSingletons(new BatchResource()); diff --git a/services/build.xml b/services/build.xml index a4bbaf586..04b75699e 100644 --- a/services/build.xml +++ b/services/build.xml @@ -172,6 +172,7 @@ + @@ -215,6 +216,7 @@ + @@ -271,6 +273,7 @@ + diff --git a/services/common/src/main/resources/db/postgresql/load_id_generators.sql b/services/common/src/main/resources/db/postgresql/load_id_generators.sql index 89595c1aa..933436b2f 100644 --- a/services/common/src/main/resources/db/postgresql/load_id_generators.sql +++ b/services/common/src/main/resources/db/postgresql/load_id_generators.sql @@ -830,3 +830,39 @@ INSERT INTO id_generators SELECT csid FROM id_generators ); + +-- CONSERVATION_TREATMENT_REFERENCE_NUMBER + +INSERT INTO id_generators + (csid, displayname, description, priority, last_generated_id, id_generator_state) + SELECT + 'aad54202-404d-4f19-ada9-8b1e378ad1b2', + 'Conservation Treatment Reference Number', + 'Identifies a conservation treatment.', + '9', + '', +' + + + CT + CT + + + + + + . + . + + + 6 + 1 + -1 + + +' + WHERE 'aad54202-404d-4f19-ada9-8b1e378ad1b2' NOT IN + ( + SELECT csid + FROM id_generators + ); diff --git a/services/conservation/3rdparty/build.xml b/services/conservation/3rdparty/build.xml new file mode 100644 index 000000000..f89738404 --- /dev/null +++ b/services/conservation/3rdparty/build.xml @@ -0,0 +1,131 @@ + + + + conservation service 3rdparty + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/conservation/3rdparty/nuxeo-platform-cs-conservation/build.xml b/services/conservation/3rdparty/nuxeo-platform-cs-conservation/build.xml new file mode 100644 index 000000000..333968a45 --- /dev/null +++ b/services/conservation/3rdparty/nuxeo-platform-cs-conservation/build.xml @@ -0,0 +1,161 @@ + + + + conservation nuxeo document type + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/conservation/3rdparty/nuxeo-platform-cs-conservation/pom.xml b/services/conservation/3rdparty/nuxeo-platform-cs-conservation/pom.xml new file mode 100644 index 000000000..096f15732 --- /dev/null +++ b/services/conservation/3rdparty/nuxeo-platform-cs-conservation/pom.xml @@ -0,0 +1,56 @@ + + + + + org.collectionspace.services + org.collectionspace.services.conservation.3rdparty + 4.4-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.conservation.3rdparty.nuxeo + services.conservation.3rdparty.nuxeo + jar + + Conservation Nuxeo Document Type + + + + conservation + Conservation + conservation_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/conservation/3rdparty/nuxeo-platform-cs-conservation/src/main/resources/OSGI-INF/README.txt b/services/conservation/3rdparty/nuxeo-platform-cs-conservation/src/main/resources/OSGI-INF/README.txt new file mode 100644 index 000000000..5f8c5a6d0 --- /dev/null +++ b/services/conservation/3rdparty/nuxeo-platform-cs-conservation/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/conservation/3rdparty/nuxeo-platform-cs-conservation/src/main/resources/schemas/README.txt b/services/conservation/3rdparty/nuxeo-platform-cs-conservation/src/main/resources/schemas/README.txt new file mode 100644 index 000000000..5f8c5a6d0 --- /dev/null +++ b/services/conservation/3rdparty/nuxeo-platform-cs-conservation/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/conservation/3rdparty/pom.xml b/services/conservation/3rdparty/pom.xml new file mode 100644 index 000000000..8037c7fb1 --- /dev/null +++ b/services/conservation/3rdparty/pom.xml @@ -0,0 +1,25 @@ + + + + org.collectionspace.services.conservation + org.collectionspace.services + 4.4-SNAPSHOT + + + 4.0.0 + org.collectionspace.services.conservation.3rdparty + services.conservation.3rdparty + pom + + + 3rd party build for conservation service + + + + + + diff --git a/services/conservation/build.xml b/services/conservation/build.xml new file mode 100644 index 000000000..2275607e6 --- /dev/null +++ b/services/conservation/build.xml @@ -0,0 +1,124 @@ + + + + conservation service + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/conservation/client/pom.xml b/services/conservation/client/pom.xml new file mode 100644 index 000000000..7508ea36f --- /dev/null +++ b/services/conservation/client/pom.xml @@ -0,0 +1,91 @@ + + + + org.collectionspace.services + org.collectionspace.services.conservation + 4.4-SNAPSHOT + + + 4.0.0 + org.collectionspace.services.conservation.client + services.conservation.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.conservation.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-conservation-client + + diff --git a/services/conservation/client/src/main/java/org/collectionspace/services/client/ConservationClient.java b/services/conservation/client/src/main/java/org/collectionspace/services/client/ConservationClient.java new file mode 100644 index 000000000..00b8ad1c2 --- /dev/null +++ b/services/conservation/client/src/main/java/org/collectionspace/services/client/ConservationClient.java @@ -0,0 +1,52 @@ +/** + * 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; + +/** + * ConservationClient.java + * + * $LastChangedRevision$ + * $LastChangedDate$ + * + */ +public class ConservationClient extends AbstractCommonListPoxServiceClientImpl { + + public static final String SERVICE_NAME = "conservation"; + 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; + + /* (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 ConservationProxy.class; + } + +} diff --git a/services/conservation/client/src/main/java/org/collectionspace/services/client/ConservationProxy.java b/services/conservation/client/src/main/java/org/collectionspace/services/client/ConservationProxy.java new file mode 100644 index 000000000..5f2f1e890 --- /dev/null +++ b/services/conservation/client/src/main/java/org/collectionspace/services/client/ConservationProxy.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; + +/** + * ConservationProxy.java + * + * $LastChangedRevision$ + * $LastChangedDate$ + * + */ +@Path(ConservationClient.SERVICE_PATH_PROXY) +@Produces({"application/xml"}) +@Consumes({"application/xml"}) +public interface ConservationProxy extends CollectionSpaceCommonListPoxProxy { +} diff --git a/services/conservation/client/src/test/java/org/collectionspace/services/client/test/ConservationAuthRefsTest.java b/services/conservation/client/src/test/java/org/collectionspace/services/client/test/ConservationAuthRefsTest.java new file mode 100644 index 000000000..2a8a555f3 --- /dev/null +++ b/services/conservation/client/src/test/java/org/collectionspace/services/client/test/ConservationAuthRefsTest.java @@ -0,0 +1,426 @@ +/** + * 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.ConservationClient; +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.authorityref.AuthorityRefList; +import org.collectionspace.services.jaxb.AbstractCommonList; +import org.collectionspace.services.conservation.ConservationCommon; +import org.collectionspace.services.conservation.ConservatorsList; +import org.collectionspace.services.conservation.DestAnalysisGroup; +import org.collectionspace.services.conservation.DestAnalysisGroupList; +import org.collectionspace.services.conservation.ExaminationGroup; +import org.collectionspace.services.conservation.ExaminationGroupList; +import org.collectionspace.services.conservation.OtherPartyGroup; +import org.collectionspace.services.conservation.OtherPartyGroupList; + +import org.collectionspace.services.person.PersonTermGroup; + +import org.jboss.resteasy.client.ClientResponse; + +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.Test; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * ConservationAuthRefsTest, carries out Authority References tests against a + * deployed and running Conservation Service. + * + * $LastChangedRevision$ + * $LastChangedDate$ + */ +public class ConservationAuthRefsTest extends BaseServiceTest { + + private final String CLASS_NAME = ConservationAuthRefsTest.class.getName(); + private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); + + // Instance variables specific to this test. + final String SERVICE_NAME = "conservation"; + final String SERVICE_PATH_COMPONENT = "conservation"; + final String PERSON_AUTHORITY_NAME = "TestPersonAuthForConservation"; + private String knownResourceId = null; + private List conservationIdsCreated = new ArrayList(); + private List personIdsCreated = new ArrayList(); + private String personAuthCSID = null; + private String conservatorRefName = null; + private String otherPartyRefName = null; + private String examinationStaffRefName = null; + private String approvedByRefName = null; + private String researcherRefName = null; + private String sampleByRefName = null; + private final int NUM_AUTH_REFS_EXPECTED = 6; + + /* (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 + } + + /* (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 Conservation resource. + // + // One or more fields in this resource will be PersonAuthority + // references, and will refer to Person resources by their refNames. + ConservationClient conservationClient = new ConservationClient(); + PoxPayloadOut multipart = createConservationInstance( + "conservationNumber-" + identifier, + conservatorRefName, + otherPartyRefName, + examinationStaffRefName, + approvedByRefName, + researcherRefName, + sampleByRefName); + Response response = conservationClient.create(multipart); + int statusCode = response.getStatus(); + try { + // 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); + + // Store the ID returned from the first resource created + // for additional tests below. + if (knownResourceId == null){ + knownResourceId = extractId(response); + 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. + conservationIdsCreated.add(extractId(response)); + } finally { + response.close(); + } + } + + protected void createPersonRefs(){ + 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("Connie", "Conservator", "connieConservator", authRefName); + personIdsCreated.add(csid); + conservatorRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); + + csid = createPerson("Oliver", "Otherparty", "oliverOtherparty", authRefName); + personIdsCreated.add(csid); + otherPartyRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); + + csid = createPerson("Steven", "Staff", "stevenStaff", authRefName); + personIdsCreated.add(csid); + examinationStaffRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); + + csid = createPerson("Allison", "Approver", "allisonApprover", authRefName); + personIdsCreated.add(csid); + approvedByRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); + + csid = createPerson("Rachel", "Researcher", "rachelResearcher", authRefName); + personIdsCreated.add(csid); + researcherRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); + + csid = createPerson("Sabrina", "Sampler", "sabrinaSampler", authRefName); + personIdsCreated.add(csid); + sampleByRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); + } + + protected String createPerson(String firstName, String surName, String shortId, String authRefName ) { + 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. + ConservationClient conservationClient = new ConservationClient(); + Response res = conservationClient.read(knownResourceId); + ConservationCommon conservationCommon = null; + try { + assertStatusCode(res, testName); + // Extract the common part from the response. + PoxPayloadIn input = new PoxPayloadIn(res.readEntity(String.class)); + conservationCommon = (ConservationCommon) extractPart(input, + conservationClient.getCommonPartName(), ConservationCommon.class); + Assert.assertNotNull(conservationCommon); + if(logger.isDebugEnabled()){ + logger.debug(objectAsXmlString(conservationCommon, ConservationCommon.class)); + } + } finally { + if (res != null) { + res.close(); + } + } + // + // Check a couple of fields + // + Assert.assertEquals(conservationCommon.getApprovedBy(), approvedByRefName); + Assert.assertEquals(conservationCommon.getResearcher(), researcherRefName); + + // Get the auth refs and check them + Response res2 = conservationClient.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. + */ + @AfterClass(alwaysRun=true) + public void cleanUp() { + 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 ..."); + } + PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); + // Delete Person resource(s) (before PersonAuthority resources). + + for (String resourceId : personIdsCreated) { + // Note: Any non-success responses are ignored and not reported. + personAuthClient.deleteItem(personAuthCSID, resourceId).close(); + } + + // Delete PersonAuthority resource(s). + // Note: Any non-success response is ignored and not reported. + if (personAuthCSID != null) { + personAuthClient.delete(personAuthCSID); + // Delete Conservation resource(s). + ConservationClient conservationClient = new ConservationClient(); + for (String resourceId : conservationIdsCreated) { + // Note: Any non-success responses are ignored and not reported. + conservationClient.delete(resourceId).close(); + } + } + } + + // --------------------------------------------------------------- + // Utility methods used by tests above + // --------------------------------------------------------------- + public String getServiceName() { + return SERVICE_NAME; + } + + @Override + public String getServicePathComponent() { + return SERVICE_PATH_COMPONENT; + } + + private PoxPayloadOut createConservationInstance(String conservationNumber, + String conservatorRefName, + String otherPartyRefName, + String examinationStaffRefName, + String approvedByRefName, + String researcherRefName, + String sampleByRefName) { + ConservationCommon conservationCommon = new ConservationCommon(); + conservationCommon.setConservationNumber(conservationNumber); + + ConservatorsList conservatorsList = new ConservatorsList(); + conservatorsList.getConservator().add(conservatorRefName); + + OtherPartyGroupList otherPartyGroupList = new OtherPartyGroupList(); + OtherPartyGroup otherPartyGroup = new OtherPartyGroup(); + otherPartyGroup.setOtherParty(otherPartyRefName); + otherPartyGroupList.getOtherPartyGroup().add(otherPartyGroup); + + ExaminationGroupList examinationGroupList = new ExaminationGroupList(); + ExaminationGroup examinationGroup = new ExaminationGroup(); + examinationGroup.setExaminationStaff(examinationStaffRefName); + examinationGroupList.getExaminationGroup().add(examinationGroup); + + DestAnalysisGroupList destAnalysisGroupList = new DestAnalysisGroupList(); + DestAnalysisGroup destAnalysisGroup = new DestAnalysisGroup(); + destAnalysisGroup.setSampleBy(sampleByRefName); + destAnalysisGroupList.getDestAnalysisGroup().add(destAnalysisGroup); + + conservationCommon.setConservators(conservatorsList); + conservationCommon.setOtherPartyGroupList(otherPartyGroupList); + conservationCommon.setExaminationGroupList(examinationGroupList); + conservationCommon.setApprovedBy(approvedByRefName); + conservationCommon.setResearcher(researcherRefName); + conservationCommon.setDestAnalysisGroupList(destAnalysisGroupList); + + PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent()); + PayloadOutputPart commonPart = + multipart.addPart(new ConservationClient().getCommonPartName(), conservationCommon); + + if(logger.isDebugEnabled()){ + logger.debug("to be created, conservation common"); + logger.debug(objectAsXmlString(conservationCommon, ConservationCommon.class)); + } + + return multipart; + } + + @Override + protected Class getCommonListType() { + return AbstractCommonList.class; + } +} diff --git a/services/conservation/client/src/test/java/org/collectionspace/services/client/test/ConservationServiceTest.java b/services/conservation/client/src/test/java/org/collectionspace/services/client/test/ConservationServiceTest.java new file mode 100644 index 000000000..b4b505685 --- /dev/null +++ b/services/conservation/client/src/test/java/org/collectionspace/services/client/test/ConservationServiceTest.java @@ -0,0 +1,701 @@ +/** + * 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.ConservationClient; + +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.jaxb.AbstractCommonList; +import org.collectionspace.services.conservation.ConservationCommon; +import org.collectionspace.services.conservation.ConservatorsList; +import org.collectionspace.services.conservation.ConservationStatusGroup; +import org.collectionspace.services.conservation.ConservationStatusGroupList; + +import org.jboss.resteasy.client.ClientResponse; +import org.testng.Assert; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * ConservationServiceTest, carries out tests against a + * deployed and running Conservation Service. + * + * $LastChangedRevision$ + * $LastChangedDate$ + */ +public class ConservationServiceTest extends AbstractPoxServiceTestImpl { + + /** The logger. */ + private final String CLASS_NAME = ConservationServiceTest.class.getName(); + private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); + // Instance variables specific to this test. + /** The service path component. */ + final String SERVICE_NAME = "conservation"; + final String SERVICE_PATH_COMPONENT = "conservation"; + private String CONSERVATOR_REF_NAME = + "urn:cspace:org.collectionspace.demo:personauthorities:name(TestPersonAuth):item:name(CarlaConservator)'Carla Conservator'"; + private String STATUS = "Treatment proposed"; + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() + */ + @Override + protected CollectionSpaceClient getClientInstance() { + return new ConservationClient(); + } + + /* (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. + ConservationClient client = new ConservationClient(); + String identifier = createIdentifier(); + PoxPayloadOut multipart = createConservationInstance(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. + ConservationClient client = new ConservationClient(); + 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()); + ConservationCommon conservationCommon = null; + if (payloadInputPart != null) { + conservationCommon = (ConservationCommon) payloadInputPart.getBody(); + } + Assert.assertNotNull(conservationCommon); + + // Check selected fields. + ConservatorsList conservatorsList = conservationCommon.getConservators(); + Assert.assertNotNull(conservatorsList); + List conservators = conservatorsList.getConservator(); + Assert.assertTrue(conservators.size() > 0); + Assert.assertEquals(conservators.get(0), CONSERVATOR_REF_NAME); + ConservationStatusGroupList conservationStatusGroupList = conservationCommon.getConservationStatusGroupList(); + Assert.assertNotNull(conservationStatusGroupList); + List conservationStatusGroups = conservationStatusGroupList.getConservationStatusGroup(); + Assert.assertNotNull(conservationStatusGroups); + Assert.assertTrue(conservationStatusGroups.size() > 0); + String status = conservationStatusGroups.get(0).getStatus(); + Assert.assertEquals(status, STATUS); + + if (logger.isDebugEnabled()) { + logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n" + + "UTF-8 data received=" + conservationCommon.getFabricationNote()); + } + + Assert.assertEquals(conservationCommon.getFabricationNote(), getUTF8DataFragment(), + "UTF-8 data retrieved '" + conservationCommon.getFabricationNote() + + "' does not match expected data '" + getUTF8DataFragment()); + } + + // Failure outcomes + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String) + */ + @Override +// @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, +// dependsOnMethods = {"read"}) + public void readNonExistent(String testName) throws Exception { + // Perform setup. + setupReadNonExistent(); + + // Submit the request to the service and store the response. + ConservationClient client = new ConservationClient(); + 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; + ConservationClient client = new ConservationClient(); + 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. + ConservationClient client = new ConservationClient(); + 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()); + ConservationCommon conservationCommon = null; + if (payloadInputPart != null) { + conservationCommon = (ConservationCommon) payloadInputPart.getBody(); + } + Assert.assertNotNull(conservationCommon); + + // Update the content of this resource. + conservationCommon.setConservationNumber("updated-" + conservationCommon.getConservationNumber()); + conservationCommon.setFabricationNote("updated-" + conservationCommon.getFabricationNote()); + if (logger.isDebugEnabled()) { + logger.debug("to be updated object"); + logger.debug(objectAsXmlString(conservationCommon, ConservationCommon.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(), conservationCommon); + 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()); + ConservationCommon updatedConservationCommon = null; + if (payloadInputPart != null) { + updatedConservationCommon = (ConservationCommon) payloadInputPart.getBody(); + } + Assert.assertNotNull(updatedConservationCommon); + + // Check selected fields in the updated common part. + Assert.assertEquals(updatedConservationCommon.getConservationNumber(), + conservationCommon.getConservationNumber(), + "Data in updated object did not match submitted data."); + + if (logger.isDebugEnabled()) { + logger.debug("UTF-8 data sent=" + conservationCommon.getFabricationNote() + "\n" + + "UTF-8 data received=" + updatedConservationCommon.getFabricationNote()); + } + Assert.assertTrue(updatedConservationCommon.getFabricationNote().contains(getUTF8DataFragment()), + "UTF-8 data retrieved '" + updatedConservationCommon.getFabricationNote() + + "' does not contain expected data '" + getUTF8DataFragment()); + Assert.assertEquals(updatedConservationCommon.getFabricationNote(), + conservationCommon.getFabricationNote(), + "Data in updated object did not match submitted data."); + } + + @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. + ConservationClient client = new ConservationClient(); + PoxPayloadOut multipart = createConservationInstance(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. + ConservationClient client = new ConservationClient(); + 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. + ConservationClient client = new ConservationClient(); + 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) { + return createConservationInstance(identifier); + } + + /** + * Creates the conservation instance. + * + * @param conservationNumber the conservation number + * @param returnDate the return date + * @return the multipart output + */ + private PoxPayloadOut createConservationInstance(String identifier) { + ConservationCommon conservationCommon = new ConservationCommon(); + conservationCommon.setConservationNumber("conservationNumber-" + identifier); + + ConservatorsList conservatorsList = new ConservatorsList(); + conservatorsList.getConservator().add(CONSERVATOR_REF_NAME); + + ConservationStatusGroupList conservationStatusGroupList = new ConservationStatusGroupList(); + ConservationStatusGroup conservationStatusGroup = new ConservationStatusGroup(); + conservationStatusGroup.setStatus(STATUS); + conservationStatusGroupList.getConservationStatusGroup().add(conservationStatusGroup); + + conservationCommon.setConservators(conservatorsList); + conservationCommon.setConservationStatusGroupList(conservationStatusGroupList); + conservationCommon.setFabricationNote(getUTF8DataFragment()); + + PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent()); + PayloadOutputPart commonPart = + multipart.addPart(new ConservationClient().getCommonPartName(), conservationCommon); + + if (logger.isDebugEnabled()) { + logger.debug("to be created, conservation common"); + logger.debug(objectAsXmlString(conservationCommon, ConservationCommon.class)); + } + + return multipart; + } + + @Override + public void CRUDTests(String testName) { + // TODO Auto-generated method stub + + } + + @Override + protected PoxPayloadOut createInstance(String commonPartName, + String identifier) { + PoxPayloadOut result = createConservationInstance(identifier); + return result; + } + + @Override + protected ConservationCommon updateInstance(ConservationCommon commonPartObject) { + // TODO Auto-generated method stub + return null; + } + + @Override + protected void compareUpdatedInstances(ConservationCommon original, + ConservationCommon updated) throws Exception { + // TODO Auto-generated method stub + + } +} diff --git a/services/conservation/client/src/test/resources/log4j.properties b/services/conservation/client/src/test/resources/log4j.properties new file mode 100644 index 000000000..148a3e865 --- /dev/null +++ b/services/conservation/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/conservation/jaxb/pom.xml b/services/conservation/jaxb/pom.xml new file mode 100644 index 000000000..8ff74ae9f --- /dev/null +++ b/services/conservation/jaxb/pom.xml @@ -0,0 +1,34 @@ + + + + org.collectionspace.services.conservation + org.collectionspace.services + 4.4-SNAPSHOT + + + 4.0.0 + org.collectionspace.services.conservation.jaxb + services.conservation.jaxb + + + + org.collectionspace.services + org.collectionspace.services.jaxb + ${project.version} + + + + + collectionspace-services-conservation-jaxb + install + + + org.jvnet.jaxb2.maven2 + maven-jaxb2-plugin + + + + + diff --git a/services/conservation/jaxb/src/main/java/org/collectionspace/services/ConservationJAXBSchema.java b/services/conservation/jaxb/src/main/java/org/collectionspace/services/ConservationJAXBSchema.java new file mode 100644 index 000000000..a3c821b43 --- /dev/null +++ b/services/conservation/jaxb/src/main/java/org/collectionspace/services/ConservationJAXBSchema.java @@ -0,0 +1,10 @@ +/** + * + */ +package org.collectionspace.services; + +public interface ConservationJAXBSchema { + final static String CONSERVATION_NUMBER = "conservationNumber"; +} + + diff --git a/services/conservation/jaxb/src/main/java/org/collectionspace/services/ConservationListItemJAXBSchema.java b/services/conservation/jaxb/src/main/java/org/collectionspace/services/ConservationListItemJAXBSchema.java new file mode 100644 index 000000000..3d4102466 --- /dev/null +++ b/services/conservation/jaxb/src/main/java/org/collectionspace/services/ConservationListItemJAXBSchema.java @@ -0,0 +1,7 @@ +package org.collectionspace.services; + +public interface ConservationListItemJAXBSchema { + final static String CONSERVATION_NUMBER = "conservationNumber"; + final static String CSID = "csid"; + final static String URI = "url"; +} diff --git a/services/conservation/jaxb/src/main/resources/conservation-common.xsd b/services/conservation/jaxb/src/main/resources/conservation-common.xsd new file mode 100644 index 000000000..cc9a996c6 --- /dev/null +++ b/services/conservation/jaxb/src/main/resources/conservation-common.xsd @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/conservation/pom.xml b/services/conservation/pom.xml new file mode 100644 index 000000000..078a762b2 --- /dev/null +++ b/services/conservation/pom.xml @@ -0,0 +1,26 @@ + + + + + org.collectionspace.services + org.collectionspace.services.main + 4.4-SNAPSHOT + + + 4.0.0 + org.collectionspace.services.conservation + services.conservation + pom + + + + + + jaxb + service + 3rdparty + client + + + + diff --git a/services/conservation/service/pom.xml b/services/conservation/service/pom.xml new file mode 100644 index 000000000..f996d8978 --- /dev/null +++ b/services/conservation/service/pom.xml @@ -0,0 +1,102 @@ + + + + + org.collectionspace.services + org.collectionspace.services.conservation + 4.4-SNAPSHOT + + + 4.0.0 + org.collectionspace.services.conservation.service + services.conservation.service + jar + + + + org.collectionspace.services + org.collectionspace.services.common + + + org.collectionspace.services + org.collectionspace.services.conservation.jaxb + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.conservation.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 + + + + dom4j + dom4j + 1.6.1 + 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-conservation + + + diff --git a/services/conservation/service/src/main/java/org/collectionspace/services/conservation/ConservationResource.java b/services/conservation/service/src/main/java/org/collectionspace/services/conservation/ConservationResource.java new file mode 100644 index 000000000..4d8ba1be5 --- /dev/null +++ b/services/conservation/service/src/main/java/org/collectionspace/services/conservation/ConservationResource.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.conservation; + +import org.collectionspace.services.client.ConservationClient; +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(ConservationClient.SERVICE_PATH) +@Consumes("application/xml") +@Produces("application/xml") +public class ConservationResource extends NuxeoBasedResource { + + final Logger logger = LoggerFactory.getLogger(ConservationResource.class); + + @Override + protected String getVersionString() { + final String lastChangeRevision = "$LastChangedRevision$"; + return lastChangeRevision; + } + + @Override + public String getServiceName() { + return ConservationClient.SERVICE_NAME; + } + + @Override + public Class getCommonPartClass() { + return ConservationCommon.class; + } +} + + + + + + diff --git a/services/conservation/service/src/main/java/org/collectionspace/services/conservation/nuxeo/ConservationConstants.java b/services/conservation/service/src/main/java/org/collectionspace/services/conservation/nuxeo/ConservationConstants.java new file mode 100644 index 000000000..081eecf23 --- /dev/null +++ b/services/conservation/service/src/main/java/org/collectionspace/services/conservation/nuxeo/ConservationConstants.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.conservation.nuxeo; + +/** + * ConservationConstants specifies constants for the Conservation service + * + */ +public class ConservationConstants { + + public final static String NUXEO_DOCTYPE = "Conservation"; + public final static String NUXEO_SCHEMA_NAME = "conservation"; + public final static String NUXEO_DC_TITLE = "CollectionSpace-Conservation"; +} diff --git a/services/conservation/service/src/main/java/org/collectionspace/services/conservation/nuxeo/ConservationDocumentModelHandler.java b/services/conservation/service/src/main/java/org/collectionspace/services/conservation/nuxeo/ConservationDocumentModelHandler.java new file mode 100644 index 000000000..6cf4faebc --- /dev/null +++ b/services/conservation/service/src/main/java/org/collectionspace/services/conservation/nuxeo/ConservationDocumentModelHandler.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.conservation.nuxeo; + +import org.collectionspace.services.conservation.ConservationCommon; +import org.collectionspace.services.nuxeo.client.java.NuxeoDocumentModelHandler; + +/** ConservationDocumentModelHandler + * $LastChangedRevision$ + * $LastChangedDate$ + */ +public class ConservationDocumentModelHandler + extends NuxeoDocumentModelHandler { +} + diff --git a/services/conservation/service/src/main/java/org/collectionspace/services/conservation/nuxeo/ConservationValidatorHandler.java b/services/conservation/service/src/main/java/org/collectionspace/services/conservation/nuxeo/ConservationValidatorHandler.java new file mode 100644 index 000000000..2dc7ba0bf --- /dev/null +++ b/services/conservation/service/src/main/java/org/collectionspace/services/conservation/nuxeo/ConservationValidatorHandler.java @@ -0,0 +1,18 @@ +package org.collectionspace.services.conservation.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 ConservationValidatorHandler implements ValidatorHandler { + + @Override + public void validate(Action action, ServiceContext ctx) + throws InvalidDocumentException { + // TODO Auto-generated method stub + System.out.println("ConservationValidatorHandler executed."); + + } + +} diff --git a/services/conservation/service/src/test/java/org/collectionspace/services/test/ConservationServiceTest.java b/services/conservation/service/src/test/java/org/collectionspace/services/test/ConservationServiceTest.java new file mode 100644 index 000000000..38d1a868c --- /dev/null +++ b/services/conservation/service/src/test/java/org/collectionspace/services/test/ConservationServiceTest.java @@ -0,0 +1,13 @@ +package org.collectionspace.services.test; + +//import org.collectionspace.services.conservation.Conservation; +//import org.collectionspace.services.conservation.ConservationList; + +/** + * Placeholder for server-side testing of Conservation service code. + * + * @version $Revision$ + */ +public class ConservationServiceTest { + //empty +} diff --git a/services/conservation/service/src/test/resources/log4j.xml b/services/conservation/service/src/test/resources/log4j.xml new file mode 100644 index 000000000..52121cb83 --- /dev/null +++ b/services/conservation/service/src/test/resources/log4j.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/pom.xml b/services/pom.xml index 3acd33801..6d921f513 100644 --- a/services/pom.xml +++ b/services/pom.xml @@ -64,6 +64,7 @@ loanout exhibition conditioncheck + conservation valuationcontrol objectexit batch -- 2.47.3