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