From b3e0a5ba6058d87f05f597b5b00aa923abe3d0ab Mon Sep 17 00:00:00 2001 From: Laramie Crocker Date: Wed, 11 May 2011 03:57:31 +0000 Subject: [PATCH] CSPACE-3899 --- .../client/test/BatchAuthRefsTest.java | 239 ------------------ .../client/test/BatchServiceTest.java | 17 -- .../services/BatchJAXBSchema.java | 11 +- .../services/BatchListItemJAXBSchema.java | 3 - 4 files changed, 2 insertions(+), 268 deletions(-) delete mode 100644 services/batch/client/src/test/java/org/collectionspace/services/client/test/BatchAuthRefsTest.java diff --git a/services/batch/client/src/test/java/org/collectionspace/services/client/test/BatchAuthRefsTest.java b/services/batch/client/src/test/java/org/collectionspace/services/client/test/BatchAuthRefsTest.java deleted file mode 100644 index 50c3dbe72..000000000 --- a/services/batch/client/src/test/java/org/collectionspace/services/client/test/BatchAuthRefsTest.java +++ /dev/null @@ -1,239 +0,0 @@ -/** - * 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.MediaType; -import javax.ws.rs.core.Response; - -import org.collectionspace.services.PersonJAXBSchema; -import org.collectionspace.services.client.CollectionSpaceClient; -import org.collectionspace.services.client.ContactClient; -import org.collectionspace.services.client.BatchClient; -import org.collectionspace.services.client.PayloadOutputPart; -import org.collectionspace.services.client.PersonAuthorityClient; -import org.collectionspace.services.client.PersonAuthorityClientUtils; -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.batch.BatchCommon; - -import org.jboss.resteasy.client.ClientResponse; - -import org.jboss.resteasy.plugins.providers.multipart.OutputPart; -import org.testng.Assert; -import org.testng.annotations.AfterClass; -import org.testng.annotations.Test; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * BatchAuthRefsTest, carries out Authority References tests against a deployed and running Batch (aka Loans Out) Service. - * $LastChangedRevision: $ - * $LastChangedDate: $ - */ -public class BatchAuthRefsTest extends BaseServiceTest { - - private final String CLASS_NAME = BatchAuthRefsTest.class.getName(); - private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); - final String PERSON_AUTHORITY_NAME = "BatchPersonAuth"; - private String knownResourceId = null; - private List batchIdsCreated = new ArrayList(); - private List personIdsCreated = new ArrayList(); - private String personAuthCSID = null; - private String depositorRefName = null; - - private String name = null; - private String className = null; - private String forDocType = null; - private String notes = null; - - @Override - public String getServicePathComponent() { - return BatchClient.SERVICE_PATH_COMPONENT; - } - - @Override - protected String getServiceName() { - return BatchClient.SERVICE_NAME; - } - - @Override - protected CollectionSpaceClient getClientInstance() { - throw new UnsupportedOperationException(); //method not supported (or needed) in this test class - } - - @Override - protected AbstractCommonList getAbstractCommonList(ClientResponse response) { - throw new UnsupportedOperationException(); //method not supported (or needed) in this test class - } - - private PoxPayloadOut createBatchInstance(String className, String forDocType, String notes) { - this.className = className; - this.forDocType = forDocType; - this.notes = notes; - - BatchCommon batch = new BatchCommon(); - batch.setClassName(className); - batch.setForDocType(forDocType); - batch.setNotes(notes); - - PoxPayloadOut multipart = new PoxPayloadOut(BatchClient.SERVICE_PAYLOAD_NAME); - PayloadOutputPart commonPart = multipart.addPart(batch, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(new BatchClient().getCommonPartName()); - logger.debug("to be created, batch common: " + objectAsXmlString(batch, BatchCommon.class)); - return multipart; - } - - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) - public void createWithAuthRefs(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - testSetup(STATUS_CREATED, ServiceRequestType.CREATE); - String identifier = createIdentifier(); // Submit the request to the service and store the response. - createPersonRefs();// Create all the person refs and entities - // Create a new Loans In resource. One or more fields in this resource will be PersonAuthority - // references, and will refer to Person resources by their refNames. - BatchClient batchClient = new BatchClient(); - //private PoxPayloadOut createBatchInstance(String className, String forDocType, String notes) { - PoxPayloadOut multipart = createBatchInstance("className", "docType-"+identifier, "Notes-" + identifier); - ClientResponse res = batchClient.create(multipart); - assertStatusCode(res, testName); - if (knownResourceId == null) {// Store the ID returned from the first resource created for additional tests below. - knownResourceId = extractId(res); - } - batchIdsCreated.add(extractId(res));// Store the IDs from every resource created; delete on cleanup - } - - 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()); - ClientResponse res = personAuthClient.create(multipart); - assertStatusCode(res, "createPersonRefs (not a surefire test)"); - personAuthCSID = extractId(res); - String authRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null); - // Create temporary Person resources, and their corresponding refNames by which they can be identified. - String csid = ""; - - csid = createPerson("Owen the Cur", "Owner", "owenCurOwner", authRefName); - personIdsCreated.add(csid); - depositorRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); - - csid = createPerson("Davenport", "Depositor", "davenportDepositor", authRefName); - personIdsCreated.add(csid); - depositorRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); - } - - protected String createPerson(String firstName, String surName, String shortId, String authRefName) { - 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); - PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonInstance(personAuthCSID, authRefName, personInfo, personAuthClient.getItemCommonPartName()); - ClientResponse res = personAuthClient.createItem(personAuthCSID, multipart); - assertStatusCode(res, "createPerson (not a surefire test)"); - return extractId(res); - } - - @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"createWithAuthRefs"}) - public void readAndCheckAuthRefs(String testName) throws Exception { - logger.debug(testBanner(testName, CLASS_NAME)); - testSetup(STATUS_OK, ServiceRequestType.READ); - BatchClient batchClient = new BatchClient(); - ClientResponse res = batchClient.read(knownResourceId); - assertStatusCode(res, testName); - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - BatchCommon batch = (BatchCommon) extractPart(input, batchClient.getCommonPartName(), BatchCommon.class); - Assert.assertNotNull(batch); - logger.debug(objectAsXmlString(batch, BatchCommon.class)); - - // Check a couple of fields - Assert.assertEquals(batch.getClassName(), className); - Assert.assertEquals(batch.getForDocType(), forDocType); - Assert.assertEquals(batch.getName(), name); - Assert.assertEquals(batch.getNotes(), notes); - - // Get the auth refs and check them - ClientResponse res2 = batchClient.getAuthorityRefs(knownResourceId); - assertStatusCode(res2, testName); - AuthorityRefList list = res2.getEntity(); - List items = list.getAuthorityRefItem(); - int numAuthRefsFound = items.size(); - logger.debug("Authority references, found " + numAuthRefsFound); - //Assert.assertEquals(numAuthRefsFound, NUM_AUTH_REFS_EXPECTED, - // "Did not find all expected authority references! " + - // "Expected " + NUM_AUTH_REFS_EXPECTED + ", found " + numAuthRefsFound); - if (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++; - } - } - } - - /** - * 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)) { - logger.debug("Skipping Cleanup phase ..."); - return; - } - 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); - } - // Delete PersonAuthority resource(s). - // Note: Any non-success response is ignored and not reported. - if (personAuthCSID != null) { - personAuthClient.delete(personAuthCSID); - // Delete Loans In resource(s). - BatchClient batchClient = new BatchClient(); - for (String resourceId : batchIdsCreated) { - // Note: Any non-success responses are ignored and not reported. - batchClient.delete(resourceId); - } - } - } - -} diff --git a/services/batch/client/src/test/java/org/collectionspace/services/client/test/BatchServiceTest.java b/services/batch/client/src/test/java/org/collectionspace/services/client/test/BatchServiceTest.java index efc5051ac..14467be10 100644 --- a/services/batch/client/src/test/java/org/collectionspace/services/client/test/BatchServiceTest.java +++ b/services/batch/client/src/test/java/org/collectionspace/services/client/test/BatchServiceTest.java @@ -140,23 +140,6 @@ public class BatchServiceTest extends AbstractServiceTestImpl { i++; } } - - /* - List items = list.getListItem(); - int i = 0; - for(AbstractCommonList.ListItem item : items){ - List elList = item.getAny(); - StringBuilder elementStrings = new StringBuilder(); - for(Element el : elList) { - Node textEl = el.getFirstChild(); - if (textEl != null){ - elementStrings.append("["+el.getNodeName()+":"+textEl.getNodeValue()+"] "); - } - } - System.out.println("\r\n\r\n\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~"+testName + ": list-item[" + i + "]: "+elementStrings.toString()); - i++; - } - */ } @Override diff --git a/services/batch/jaxb/src/main/java/org/collectionspace/services/BatchJAXBSchema.java b/services/batch/jaxb/src/main/java/org/collectionspace/services/BatchJAXBSchema.java index 8613c0868..99e817618 100644 --- a/services/batch/jaxb/src/main/java/org/collectionspace/services/BatchJAXBSchema.java +++ b/services/batch/jaxb/src/main/java/org/collectionspace/services/BatchJAXBSchema.java @@ -4,13 +4,6 @@ package org.collectionspace.services; public interface BatchJAXBSchema { - final static String OBJECT_EXIT_CURRENT_OWNER = "currentOwner"; - final static String OBJECT_EXIT_DEPOSITOR = "depositor"; - final static String OBJECT_EXIT_DATE = "exitDate"; - final static String OBJECT_EXIT_METHODS = "exitMethods"; - final static String OBJECT_EXIT_METHOD = "exitMethod"; - final static String OBJECT_EXIT_NOTE = "exitNote"; - final static String OBJECT_EXIT_NUMBER = "exitNumber"; - final static String OBJECT_EXIT_REASON = "exitReason"; - final static String OBJECT_EXIT_PACKING_NOTE = "packingNote"; + final static String BATCH_NAME = "name"; + final static String BATCH_FORDOCTYPE = "forDocType"; } diff --git a/services/batch/jaxb/src/main/java/org/collectionspace/services/BatchListItemJAXBSchema.java b/services/batch/jaxb/src/main/java/org/collectionspace/services/BatchListItemJAXBSchema.java index ab7f83029..4c8df2315 100644 --- a/services/batch/jaxb/src/main/java/org/collectionspace/services/BatchListItemJAXBSchema.java +++ b/services/batch/jaxb/src/main/java/org/collectionspace/services/BatchListItemJAXBSchema.java @@ -1,9 +1,6 @@ package org.collectionspace.services; public interface BatchListItemJAXBSchema { - final static String OBJECT_EXIT_CURRENT_OWNER = "currentOwner"; - final static String OBJECT_EXIT_NUMBER = "exitNumber"; - final static String CSID = "csid"; final static String URI = "url"; } -- 2.47.3