2 * CollectionSpaceIntegrationTest.java
\r
4 * {Purpose of This Class}
\r
6 * {Other Notes Relating to This Class (Optional)}
\r
9 * $LastChangedRevision: $
\r
10 * $LastChangedDate: $
\r
12 * This document is a part of the source code and related artifacts
\r
13 * for CollectionSpace, an open source collections management system
\r
14 * for museums and related institutions:
\r
16 * http://www.collectionspace.org
\r
17 * http://wiki.collectionspace.org
\r
19 * Copyright © 2009 {Contributing Institution}
\r
21 * Licensed under the Educational Community License (ECL), Version 2.0.
\r
22 * You may not use this file except in compliance with this License.
\r
24 * You may obtain a copy of the ECL 2.0 License at
\r
25 * https://source.collectionspace.org/collection-space/LICENSE.txt
\r
27 package org.collectionspace.services.IntegrationTests.test;
\r
29 import java.util.ArrayList;
\r
30 import java.util.List;
\r
32 import javax.ws.rs.core.MultivaluedMap;
\r
33 import javax.ws.rs.core.Response;
\r
34 import javax.xml.bind.JAXBContext;
\r
35 import javax.xml.bind.Marshaller;
\r
37 import org.collectionspace.services.client.PayloadInputPart;
\r
38 import org.collectionspace.services.client.PoxPayloadIn;
\r
39 import org.collectionspace.services.collectionobject.CollectionobjectsCommon;
\r
40 import org.collectionspace.services.collectionobject.TitleGroup;
\r
41 import org.collectionspace.services.collectionobject.TitleGroupList;
\r
42 import org.collectionspace.services.common.api.GregorianCalendarDateTimeUtils;
\r
43 import org.collectionspace.services.intake.IntakesCommon;
\r
44 import org.collectionspace.services.relation.RelationsCommon;
\r
45 import org.jboss.resteasy.client.ClientResponse;
\r
48 * The Class CollectionSpaceIntegrationTest.
\r
50 public abstract class CollectionSpaceIntegrationTest {
\r
53 * Package scoped methods.
\r
57 * Fill collection object.
\r
60 * @param identifier the identifier
\r
62 void fillCollectionObject(CollectionobjectsCommon co, String identifier) {
\r
63 fillCollectionObject(co, "objectNumber-" + identifier, "title-"
\r
68 * Fill collection object.
\r
71 * @param objectNumber the object number
\r
72 * @param title the object title
\r
74 void fillCollectionObject(CollectionobjectsCommon co, String objectNumber,
\r
76 co.setObjectNumber(objectNumber);
\r
77 TitleGroupList titleGroupList = new TitleGroupList();
\r
78 List<TitleGroup> titleGroups = titleGroupList.getTitleGroup();
\r
79 TitleGroup titleGroup = new TitleGroup();
\r
80 titleGroup.setTitle(title);
\r
81 titleGroups.add(titleGroup);
\r
82 co.setTitleGroupList(titleGroupList);
\r
88 * @param theIntake the the intake
\r
89 * @param identifier the identifier
\r
91 void fillIntake(IntakesCommon theIntake, String identifier) {
\r
92 String CURRENT_DATE_UTC = GregorianCalendarDateTimeUtils.currentDateUTC();
\r
93 fillIntake(theIntake, "entryNumber-" + identifier, CURRENT_DATE_UTC);
\r
99 * @param theIntake the the intake
\r
100 * @param entryNumber the entry number
\r
101 * @param entryDate the entry date
\r
103 void fillIntake(IntakesCommon theIntake, String entryNumber, String entryDate) {
\r
104 theIntake.setEntryNumber(entryNumber);
\r
105 theIntake.setEntryDate(entryDate);
\r
111 * @param relation the relation
\r
112 * @param subjectCsid the document id1
\r
113 * @param subjectDocumentType the document type1
\r
114 * @param objectCsid the document id2
\r
115 * @param objectDocumentType the document type2
\r
118 void fillRelation(RelationsCommon relation,
\r
119 String subjectCsid, String subjectDocumentType,
\r
120 String objectCsid, String objectDocumentType,
\r
123 relation.setSubjectCsid(subjectCsid);
\r
124 relation.setSubjectDocumentType(subjectDocumentType);
\r
125 relation.setObjectCsid(objectCsid);
\r
126 relation.setObjectDocumentType(objectDocumentType);
\r
128 relation.setRelationshipType(rt);
\r
132 * Creates the identifier.
\r
134 * @return the string
\r
136 String createIdentifier() {
\r
137 long identifier = System.currentTimeMillis();
\r
138 return Long.toString(identifier);
\r
144 * @param res the res
\r
146 * @return the string
\r
148 String extractId(ClientResponse<Response> res) {
\r
149 String result = null;
\r
151 MultivaluedMap mvm = res.getMetadata();
\r
152 String uri = (String) ((ArrayList) mvm.get("Location")).get(0);
\r
153 verbose("extractId:uri=" + uri);
\r
154 String[] segments = uri.split("/");
\r
155 result = segments[segments.length - 1];
\r
156 verbose("id=" + result);
\r
171 * @return the object
\r
173 * @throws Exception
\r
176 static Object extractPart(PoxPayloadIn input, String label, Class clazz) {
\r
179 PayloadInputPart payloadInputPart = input.getPart(label);
\r
180 if (payloadInputPart != null) {
\r
181 obj = payloadInputPart.getBody();
\r
190 * @param msg the msg
\r
192 void verbose(String msg) {
\r
193 System.out.println(msg);
\r
199 * @param msg the msg
\r
201 * @param clazz the clazz
\r
203 void verbose(String msg, Object o, Class clazz) {
\r
206 JAXBContext jc = JAXBContext.newInstance(clazz);
\r
207 Marshaller m = jc.createMarshaller();
\r
208 m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
\r
209 m.marshal(o, System.out);
\r
210 } catch (Exception e) {
\r
211 e.printStackTrace();
\r
218 * @param map the map
\r
220 void verboseMap(MultivaluedMap map) {
\r
221 for (Object entry : map.entrySet()) {
\r
222 MultivaluedMap.Entry mentry = (MultivaluedMap.Entry) entry;
\r
223 verbose(" name=" + mentry.getKey() + " value=" + mentry.getValue());
\r