]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
1fa2515c7756b75e422f70dd30486e305be9e98a
[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     protected List<String> allRelationResourceIdsCreated = new ArrayList<String>();
51     protected List<String> allResourceIdsCreated = new ArrayList<String>();
52
53         /*
54          * Package scoped methods.
55          */
56
57         /**
58          * Fill collection object.
59          * 
60          * @param co the co
61          * @param identifier the identifier
62          */
63         void fillCollectionObject(CollectionobjectsCommon co, String identifier) {
64                 fillCollectionObject(co, "objectNumber-" + identifier, "title-"
65                                 + identifier);
66         }
67
68         /**
69          * Fill collection object.
70          * 
71          * @param co the co
72          * @param objectNumber the object number
73          * @param title the object title
74          */
75         void fillCollectionObject(CollectionobjectsCommon co, String objectNumber,
76                         String title) {
77                 co.setObjectNumber(objectNumber);
78                 TitleGroupList titleGroupList = new TitleGroupList();
79                 List<TitleGroup> titleGroups = titleGroupList.getTitleGroup();
80                 TitleGroup titleGroup = new TitleGroup();
81                 titleGroup.setTitle(title);
82                 titleGroups.add(titleGroup);
83                 co.setTitleGroupList(titleGroupList);
84         }
85
86         /**
87          * Fill intake.
88          * 
89          * @param theIntake the the intake
90          * @param identifier the identifier
91          */
92         void fillIntake(IntakesCommon theIntake, String identifier) {
93                 String CURRENT_DATE_UTC = GregorianCalendarDateTimeUtils.currentDateUTC();
94                 fillIntake(theIntake, "entryNumber-" + identifier, CURRENT_DATE_UTC);
95         }
96
97         /**
98          * Fill intake.
99          * 
100          * @param theIntake the the intake
101          * @param entryNumber the entry number
102          * @param entryDate the entry date
103          */
104         void fillIntake(IntakesCommon theIntake, String entryNumber, String entryDate) {
105                 theIntake.setEntryNumber(entryNumber);
106                 theIntake.setEntryDate(entryDate);
107         }
108
109     /**
110      * Fill relation.
111      * 
112      * @param relation the relation
113      * @param subjectCsid the document id1
114      * @param subjectDocumentType the document type1
115      * @param objectCsid the document id2
116      * @param objectDocumentType the document type2
117      * @param rt the rt
118      */
119     void fillRelation(RelationsCommon relation, 
120             String subjectCsid, String subjectDocumentType,
121             String objectCsid, String objectDocumentType,
122             String rt)
123     {
124         relation.setSubjectCsid(subjectCsid);
125         relation.setSubjectDocumentType(subjectDocumentType);
126         relation.setObjectCsid(objectCsid);
127         relation.setObjectDocumentType(objectDocumentType);
128         
129         relation.setRelationshipType(rt);
130     }
131         
132         /**
133          * Creates the identifier.
134          * 
135          * @return the string
136          */
137         String createIdentifier() {
138                 long identifier = System.currentTimeMillis();
139                 return Long.toString(identifier);
140         }
141
142         String extractId(Response res) {
143                 String result = null;
144                 
145                 MultivaluedMap<String, Object> mvm = res.getMetadata();
146                 String uri = (String) ((ArrayList<Object>) mvm.get("Location")).get(0);
147                 verbose("extractId:uri=" + uri);
148                 String[] segments = uri.split("/");
149                 result = segments[segments.length - 1];
150                 verbose("id=" + result);
151                 
152                 return result;
153         }       
154
155         /**
156          * Extract part.
157          * 
158          * @param input
159          *            the input
160          * @param label
161          *            the label
162          * @param clazz
163          *            the clazz
164          * 
165          * @return the object
166          * 
167          * @throws Exception
168          *             the exception
169          */
170         static Object extractPart(PoxPayloadIn input, String label) {
171                 Object obj = null;
172
173                 PayloadInputPart payloadInputPart = input.getPart(label);
174                 if (payloadInputPart != null) {
175                         obj = payloadInputPart.getBody();
176                 }
177
178                 return obj;
179         }
180         
181         /**
182          * Verbose.
183          * 
184          * @param msg the msg
185          */
186         void verbose(String msg) {
187                 System.out.println(msg);
188         }
189
190         /**
191          * Verbose.
192          * 
193          * @param msg the msg
194          * @param o the o
195          * @param clazz the clazz
196          */
197         void verbose(String msg, Object o, Class clazz) {
198                 try {
199                         verbose(msg);
200                         JAXBContext jc = JAXBContext.newInstance(clazz);
201                         Marshaller m = jc.createMarshaller();
202                         m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
203                         m.marshal(o, System.out);
204                 } catch (Exception e) {
205                         e.printStackTrace();
206                 }
207         }
208
209         /**
210          * Verbose map.
211          * 
212          * @param map the map
213          */
214         void verboseMap(MultivaluedMap map) {
215                 for (Object entry : map.entrySet()) {
216                         MultivaluedMap.Entry mentry = (MultivaluedMap.Entry) entry;
217                         verbose("  name=" + mentry.getKey() + " value=" + mentry.getValue());
218                 }
219         }
220
221 }