]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
8fe6645c7cde57ed0adb63960142ea2b3aa65882
[tmp/jakarta-migration.git] /
1 /**     
2  * CollectionSpaceIntegrationTest.java
3  *
4  * {Purpose of This Class}
5  *
6  * {Other Notes Relating to This Class (Optional)}
7  *
8  * $LastChangedBy: $
9  * $LastChangedRevision: $
10  * $LastChangedDate: $
11  *
12  * This document is a part of the source code and related artifacts
13  * for CollectionSpace, an open source collections management system
14  * for museums and related institutions:
15  *
16  * http://www.collectionspace.org
17  * http://wiki.collectionspace.org
18  *
19  * Copyright © 2009 {Contributing Institution}
20  *
21  * Licensed under the Educational Community License (ECL), Version 2.0.
22  * You may not use this file except in compliance with this License.
23  *
24  * You may obtain a copy of the ECL 2.0 License at
25  * https://source.collectionspace.org/collection-space/LICENSE.txt
26  */
27 package org.collectionspace.services.IntegrationTests.test;
28
29 import java.util.ArrayList;
30 import java.util.List;
31
32 import javax.ws.rs.core.MultivaluedMap;
33 import javax.ws.rs.core.Response;
34 import javax.xml.bind.JAXBContext;
35 import javax.xml.bind.Marshaller;
36
37 import org.collectionspace.services.client.PayloadInputPart;
38 import org.collectionspace.services.client.PoxPayloadIn;
39 import org.collectionspace.services.collectionobject.CollectionobjectsCommon;
40 import org.collectionspace.services.collectionobject.TitleGroup;
41 import org.collectionspace.services.collectionobject.TitleGroupList;
42 import org.collectionspace.services.common.api.GregorianCalendarDateTimeUtils;
43 import org.collectionspace.services.intake.IntakesCommon;
44 import org.collectionspace.services.relation.RelationsCommon;
45
46 /**
47  * The Class CollectionSpaceIntegrationTest.
48  */
49 public abstract class CollectionSpaceIntegrationTest {
50
51         /*
52          * Package scoped methods.
53          */
54
55         /**
56          * Fill collection object.
57          * 
58          * @param co the co
59          * @param identifier the identifier
60          */
61         void fillCollectionObject(CollectionobjectsCommon co, String identifier) {
62                 fillCollectionObject(co, "objectNumber-" + identifier, "title-"
63                                 + identifier);
64         }
65
66         /**
67          * Fill collection object.
68          * 
69          * @param co the co
70          * @param objectNumber the object number
71          * @param title the object title
72          */
73         void fillCollectionObject(CollectionobjectsCommon co, String objectNumber,
74                         String title) {
75                 co.setObjectNumber(objectNumber);
76                 TitleGroupList titleGroupList = new TitleGroupList();
77                 List<TitleGroup> titleGroups = titleGroupList.getTitleGroup();
78                 TitleGroup titleGroup = new TitleGroup();
79                 titleGroup.setTitle(title);
80                 titleGroups.add(titleGroup);
81                 co.setTitleGroupList(titleGroupList);
82         }
83
84         /**
85          * Fill intake.
86          * 
87          * @param theIntake the the intake
88          * @param identifier the identifier
89          */
90         void fillIntake(IntakesCommon theIntake, String identifier) {
91                 String CURRENT_DATE_UTC = GregorianCalendarDateTimeUtils.currentDateUTC();
92                 fillIntake(theIntake, "entryNumber-" + identifier, CURRENT_DATE_UTC);
93         }
94
95         /**
96          * Fill intake.
97          * 
98          * @param theIntake the the intake
99          * @param entryNumber the entry number
100          * @param entryDate the entry date
101          */
102         void fillIntake(IntakesCommon theIntake, String entryNumber, String entryDate) {
103                 theIntake.setEntryNumber(entryNumber);
104                 theIntake.setEntryDate(entryDate);
105         }
106
107     /**
108      * Fill relation.
109      * 
110      * @param relation the relation
111      * @param subjectCsid the document id1
112      * @param subjectDocumentType the document type1
113      * @param objectCsid the document id2
114      * @param objectDocumentType the document type2
115      * @param rt the rt
116      */
117     void fillRelation(RelationsCommon relation, 
118             String subjectCsid, String subjectDocumentType,
119             String objectCsid, String objectDocumentType,
120             String rt)
121     {
122         relation.setSubjectCsid(subjectCsid);
123         relation.setSubjectDocumentType(subjectDocumentType);
124         relation.setObjectCsid(objectCsid);
125         relation.setObjectDocumentType(objectDocumentType);
126         
127         relation.setRelationshipType(rt);
128     }
129         
130         /**
131          * Creates the identifier.
132          * 
133          * @return the string
134          */
135         String createIdentifier() {
136                 long identifier = System.currentTimeMillis();
137                 return Long.toString(identifier);
138         }
139
140         String extractId(Response res) {
141                 String result = null;
142                 
143                 MultivaluedMap mvm = res.getMetadata();
144                 String uri = (String) ((ArrayList) mvm.get("Location")).get(0);
145                 verbose("extractId:uri=" + uri);
146                 String[] segments = uri.split("/");
147                 result = segments[segments.length - 1];
148                 verbose("id=" + result);
149                 
150                 return result;
151         }       
152
153         /**
154          * Extract part.
155          * 
156          * @param input
157          *            the input
158          * @param label
159          *            the label
160          * @param clazz
161          *            the clazz
162          * 
163          * @return the object
164          * 
165          * @throws Exception
166          *             the exception
167          */
168         static Object extractPart(PoxPayloadIn input, String label, Class clazz) {
169                 Object obj = null;
170
171                 PayloadInputPart payloadInputPart = input.getPart(label);
172                 if (payloadInputPart != null) {
173                         obj = payloadInputPart.getBody();
174                                 }
175
176                 return obj;
177         }
178         
179         /**
180          * Verbose.
181          * 
182          * @param msg the msg
183          */
184         void verbose(String msg) {
185                 System.out.println(msg);
186         }
187
188         /**
189          * Verbose.
190          * 
191          * @param msg the msg
192          * @param o the o
193          * @param clazz the clazz
194          */
195         void verbose(String msg, Object o, Class clazz) {
196                 try {
197                         verbose(msg);
198                         JAXBContext jc = JAXBContext.newInstance(clazz);
199                         Marshaller m = jc.createMarshaller();
200                         m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
201                         m.marshal(o, System.out);
202                 } catch (Exception e) {
203                         e.printStackTrace();
204                 }
205         }
206
207         /**
208          * Verbose map.
209          * 
210          * @param map the map
211          */
212         void verboseMap(MultivaluedMap map) {
213                 for (Object entry : map.entrySet()) {
214                         MultivaluedMap.Entry mentry = (MultivaluedMap.Entry) entry;
215                         verbose("  name=" + mentry.getKey() + " value=" + mentry.getValue());
216                 }
217         }
218
219 }