From: Richard Millet Date: Wed, 14 Oct 2009 22:57:58 +0000 (+0000) Subject: CSPACE-527: Updated IntegrationTests module to use the new schema extension changes... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=ac6e21334d61c6e0ef41b251175f788e282bd769;p=tmp%2Fjakarta-migration.git CSPACE-527: Updated IntegrationTests module to use the new schema extension changes in the Java Client API --- diff --git a/services/IntegrationTests/.classpath b/services/IntegrationTests/.classpath index c641afdb9..425cd1620 100644 --- a/services/IntegrationTests/.classpath +++ b/services/IntegrationTests/.classpath @@ -4,7 +4,7 @@ - + diff --git a/services/IntegrationTests/src/test/java/org/collectionspace/services/ItegrationTests/test/CollectionSpaceIntegrationTest.java b/services/IntegrationTests/src/test/java/org/collectionspace/services/ItegrationTests/test/CollectionSpaceIntegrationTest.java index 475f881f9..1f3bf427b 100644 --- a/services/IntegrationTests/src/test/java/org/collectionspace/services/ItegrationTests/test/CollectionSpaceIntegrationTest.java +++ b/services/IntegrationTests/src/test/java/org/collectionspace/services/ItegrationTests/test/CollectionSpaceIntegrationTest.java @@ -1,3 +1,29 @@ +/** + * CollectionSpaceIntegrationTest.java + * + * {Purpose of This Class} + * + * {Other Notes Relating to This Class (Optional)} + * + * $LastChangedBy: $ + * $LastChangedRevision: $ + * $LastChangedDate: $ + * + * 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 {Contributing Institution} + * + * 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.ItegrationTests.test; import java.util.ArrayList; @@ -7,40 +33,81 @@ import javax.ws.rs.core.Response; import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; -import org.collectionspace.services.collectionobject.CollectionObject; -import org.collectionspace.services.intake.Intake; -import org.collectionspace.services.relation.Relation; +import org.collectionspace.services.collectionobject.CollectionobjectsCommon; +import org.collectionspace.services.intake.IntakesCommon; +import org.collectionspace.services.relation.RelationsCommon; import org.collectionspace.services.relation.RelationshipType; import org.jboss.resteasy.client.ClientResponse; +import org.jboss.resteasy.plugins.providers.multipart.InputPart; +import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; +/** + * The Class CollectionSpaceIntegrationTest. + */ public abstract class CollectionSpaceIntegrationTest { /* * Package scoped methods. */ - void fillCollectionObject(CollectionObject co, String identifier) { + /** + * Fill collection object. + * + * @param co the co + * @param identifier the identifier + */ + void fillCollectionObject(CollectionobjectsCommon co, String identifier) { fillCollectionObject(co, "objectNumber-" + identifier, "objectName-" + identifier); } - void fillCollectionObject(CollectionObject co, String objectNumber, + /** + * Fill collection object. + * + * @param co the co + * @param objectNumber the object number + * @param objectName the object name + */ + void fillCollectionObject(CollectionobjectsCommon co, String objectNumber, String objectName) { co.setObjectNumber(objectNumber); co.setObjectName(objectName); } - void fillIntake(Intake theIntake, String identifier) { + /** + * Fill intake. + * + * @param theIntake the the intake + * @param identifier the identifier + */ + void fillIntake(IntakesCommon theIntake, String identifier) { fillIntake(theIntake, "entryNumber-" + identifier, "entryDate-" + identifier); } - void fillIntake(Intake theIntake, String entryNumber, String entryDate) { + /** + * Fill intake. + * + * @param theIntake the the intake + * @param entryNumber the entry number + * @param entryDate the entry date + */ + void fillIntake(IntakesCommon theIntake, String entryNumber, String entryDate) { theIntake.setEntryNumber(entryNumber); theIntake.setEntryDate(entryDate); } - void fillRelation(Relation relation, String documentId1, String documentType1, + /** + * Fill relation. + * + * @param relation the relation + * @param documentId1 the document id1 + * @param documentType1 the document type1 + * @param documentId2 the document id2 + * @param documentType2 the document type2 + * @param rt the rt + */ + void fillRelation(RelationsCommon relation, String documentId1, String documentType1, String documentId2, String documentType2, RelationshipType rt) { relation.setDocumentId1(documentId1); @@ -51,11 +118,23 @@ public abstract class CollectionSpaceIntegrationTest { relation.setRelationshipType(rt); } + /** + * Creates the identifier. + * + * @return the string + */ String createIdentifier() { long identifier = System.currentTimeMillis(); return Long.toString(identifier); } + /** + * Extract id. + * + * @param res the res + * + * @return the string + */ String extractId(ClientResponse res) { String result = null; @@ -69,10 +148,56 @@ public abstract class CollectionSpaceIntegrationTest { return result; } + /** + * Extract part. + * + * @param input + * the input + * @param label + * the label + * @param clazz + * the clazz + * + * @return the object + * + * @throws Exception + * the exception + */ + static Object extractPart(MultipartInput input, String label, Class clazz) { + Object obj = null; + + try { + for (InputPart part : input.getParts()) { + String partLabel = part.getHeaders().getFirst("label"); + if (label.equalsIgnoreCase(partLabel)) { + String partStr = part.getBodyAsString(); + obj = part.getBody(clazz, null); + break; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + + return obj; + } + + /** + * Verbose. + * + * @param msg the msg + */ void verbose(String msg) { System.out.println(msg); } + /** + * Verbose. + * + * @param msg the msg + * @param o the o + * @param clazz the clazz + */ void verbose(String msg, Object o, Class clazz) { try { verbose(msg); @@ -85,6 +210,11 @@ public abstract class CollectionSpaceIntegrationTest { } } + /** + * Verbose map. + * + * @param map the map + */ void verboseMap(MultivaluedMap map) { for (Object entry : map.entrySet()) { MultivaluedMap.Entry mentry = (MultivaluedMap.Entry) entry; diff --git a/services/IntegrationTests/src/test/java/org/collectionspace/services/ItegrationTests/test/RelationIntegrationTest.java b/services/IntegrationTests/src/test/java/org/collectionspace/services/ItegrationTests/test/RelationIntegrationTest.java index 853141a76..57d0e277b 100644 --- a/services/IntegrationTests/src/test/java/org/collectionspace/services/ItegrationTests/test/RelationIntegrationTest.java +++ b/services/IntegrationTests/src/test/java/org/collectionspace/services/ItegrationTests/test/RelationIntegrationTest.java @@ -25,6 +25,8 @@ package org.collectionspace.services.ItegrationTests.test; import java.io.IOException; import java.util.ArrayList; import java.util.List; + +import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.Response; import javax.xml.bind.JAXBContext; @@ -50,23 +52,26 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.jboss.resteasy.client.ClientResponse; +import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; +import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; +import org.jboss.resteasy.plugins.providers.multipart.OutputPart; import org.collectionspace.services.client.TestServiceClient; import org.collectionspace.services.CollectionObjectJAXBSchema; import org.collectionspace.services.client.CollectionObjectClient; -import org.collectionspace.services.collectionobject.CollectionObject; -import org.collectionspace.services.collectionobject.CollectionObjectList; +import org.collectionspace.services.collectionobject.CollectionobjectsCommon; +import org.collectionspace.services.collectionobject.CollectionobjectsCommonList; import org.collectionspace.services.IntakeJAXBSchema; import org.collectionspace.services.client.IntakeClient; -import org.collectionspace.services.intake.Intake; -import org.collectionspace.services.intake.IntakeList; +import org.collectionspace.services.intake.IntakesCommon; +import org.collectionspace.services.intake.IntakesCommonList; import org.collectionspace.services.common.relation.RelationJAXBSchema; import org.collectionspace.services.client.RelationClient; -import org.collectionspace.services.relation.Relation; -import org.collectionspace.services.relation.RelationList; +import org.collectionspace.services.relation.RelationsCommon; +import org.collectionspace.services.relation.RelationsCommonList; import org.collectionspace.services.relation.RelationshipType; /** @@ -91,51 +96,77 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { // // First create a CollectionObject // - CollectionObject co = new CollectionObject(); + CollectionobjectsCommon co = new CollectionobjectsCommon(); fillCollectionObject(co, createIdentifier()); - ClientResponse coResponse = collectionObjectClient.create(co); - Assert.assertEquals(coResponse.getStatus(), Response.Status.CREATED.getStatusCode()); - String collectionObjectCsid = extractId(coResponse); + + // Next, create a part object + MultipartOutput multipart = new MultipartOutput(); + OutputPart commonPart = multipart.addPart(co, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", collectionObjectClient.getCommonPartName()); + // Make the create call and check the response + ClientResponse response = collectionObjectClient.create(multipart); + Assert.assertEquals(response.getStatus(), Response.Status.CREATED + .getStatusCode()); + String collectionObjectCsid = extractId(response); + - // Next, create an Intake record - Intake intake = new Intake(); + // Next, create an Intake object + IntakesCommon intake = new IntakesCommon(); fillIntake(intake, createIdentifier()); - ClientResponse intakeResponse = intakeClient.create(intake); - Assert.assertEquals(intakeResponse.getStatus(), Response.Status.CREATED.getStatusCode()); - String intakeCsid = extractId(intakeResponse); + // Create the a part object + multipart = new MultipartOutput(); + commonPart = multipart.addPart(intake, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", intakeClient.getCommonPartName()); + // Make the call to create and check the response + response = intakeClient.create(multipart); + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + String intakeCsid = extractId(response); - // Lastly, relate the two entities - Relation relation = new Relation(); - fillRelation(relation, collectionObjectCsid, CollectionObject.class.getSimpleName(), - intakeCsid, Intake.class.getSimpleName(), + // Lastly, relate the two entities, by creating a new relation object + RelationsCommon relation = new RelationsCommon(); + fillRelation(relation, collectionObjectCsid, CollectionobjectsCommon.class.getSimpleName(), + intakeCsid, IntakesCommon.class.getSimpleName(), RelationshipType.COLLECTIONOBJECT_INTAKE); - ClientResponse relationResponse = relationClient.create(relation); - Assert.assertEquals(relationResponse.getStatus(), Response.Status.CREATED.getStatusCode()); - String relationCsid = extractId(relationResponse); + // Create the part and fill it with the relation object + multipart = new MultipartOutput(); + commonPart = multipart.addPart(relation, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", relationClient.getCommonPartName()); + // Make the call to crate + response = relationClient.create(multipart); + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + String relationCsid = extractId(response); // // Now try to retrieve the Intake record of the CollectionObject. // String predicate = RelationshipType.COLLECTIONOBJECT_INTAKE.value(); - ClientResponse resultResponse = relationClient.readList_SPO(collectionObjectCsid, + ClientResponse resultResponse = relationClient.readList_SPO(collectionObjectCsid, predicate, intakeCsid); + Assert.assertEquals(resultResponse.getStatus(), Response.Status.OK.getStatusCode()); // // Each relation returned in the list needs to match what we // requested. // - RelationList relationList = resultResponse.getEntity(); - List relationListItems = relationList.getRelationListItem(); - ClientResponse resultRelationResponse; - Relation resultRelation = null; + RelationsCommonList relationList = resultResponse.getEntity(); + List relationListItems = relationList.getRelationListItem(); + Assert.assertFalse(relationListItems.isEmpty()); + + ClientResponse resultRelationResponse; + RelationsCommon resultRelation = null; int i = 0; - for(RelationList.RelationListItem listItem : relationListItems){ + for(RelationsCommonList.RelationListItem listItem : relationListItems){ String foundCsid = listItem.getCsid(); try { - resultRelationResponse = relationClient.read(foundCsid); - resultRelation = resultRelationResponse.getEntity(); + ClientResponse multiPartResponse = relationClient.read(foundCsid); + int responseStatus = multiPartResponse.getStatus(); + Assert.assertEquals(responseStatus, Response.Status.OK.getStatusCode()); + MultipartInput input = (MultipartInput) multiPartResponse.getEntity(); + resultRelation = (RelationsCommon) extractPart(input, + relationClient.getCommonPartName(), + RelationsCommon.class); } catch (Exception e) { e.printStackTrace(); } diff --git a/services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationConstants.java b/services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationConstants.java index 69455525e..762a32f15 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationConstants.java +++ b/services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationConstants.java @@ -30,7 +30,7 @@ package org.collectionspace.services.common.relation.nuxeo; public class RelationConstants { public final static String NUXEO_DOCTYPE = "Relation"; - public final static String NUXEO_SCHEMA_NAME = "relation"; + public final static String NUXEO_SCHEMA_NAME = "relations_common"; public final static String NUXEO_DC_TITLE = "CollectionSpace-Relation"; /** The Constant REL_NUXEO_SCHEMA_ROOT_ELEMENT. */ final public static String NUXEO_SCHEMA_ROOT_ELEMENT = "relationtype"; diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandler.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandler.java index aa3c14370..0ecb3f9ef 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandler.java @@ -118,6 +118,12 @@ public abstract class RemoteDocumentModelHandler for(InputPart part : inputParts){ String partLabel = part.getHeaders().getFirst("label"); + if (partLabel == null) { + String msg = "Part label is missing or empty!"; + logger.error(msg + "Ctx=" + getServiceContext().toString()); + throw new BadRequestException(msg); + } + //skip if the part is not in metadata if(!partsMetaMap.containsKey(partLabel)){ continue; diff --git a/services/pom.xml b/services/pom.xml index bc7d464b9..82aa9806d 100644 --- a/services/pom.xml +++ b/services/pom.xml @@ -21,16 +21,14 @@ relation acquisition - vocabulary - id collectionobject intake JaxRsServiceProvider client sdk - + IntegrationTests