]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
03e9ef27903d61d2f4c26fced56bef0c585ccfad
[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.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
46 \r
47 /**\r
48  * The Class CollectionSpaceIntegrationTest.\r
49  */\r
50 public abstract class CollectionSpaceIntegrationTest {\r
51 \r
52         /*\r
53          * Package scoped methods.\r
54          */\r
55 \r
56         /**\r
57          * Fill collection object.\r
58          * \r
59          * @param co the co\r
60          * @param identifier the identifier\r
61          */\r
62         void fillCollectionObject(CollectionobjectsCommon co, String identifier) {\r
63                 fillCollectionObject(co, "objectNumber-" + identifier, "title-"\r
64                                 + identifier);\r
65         }\r
66 \r
67         /**\r
68          * Fill collection object.\r
69          * \r
70          * @param co the co\r
71          * @param objectNumber the object number\r
72          * @param title the object title\r
73          */\r
74         void fillCollectionObject(CollectionobjectsCommon co, String objectNumber,\r
75                         String title) {\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
83         }\r
84 \r
85         /**\r
86          * Fill intake.\r
87          * \r
88          * @param theIntake the the intake\r
89          * @param identifier the identifier\r
90          */\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
94         }\r
95 \r
96         /**\r
97          * Fill intake.\r
98          * \r
99          * @param theIntake the the intake\r
100          * @param entryNumber the entry number\r
101          * @param entryDate the entry date\r
102          */\r
103         void fillIntake(IntakesCommon theIntake, String entryNumber, String entryDate) {\r
104                 theIntake.setEntryNumber(entryNumber);\r
105                 theIntake.setEntryDate(entryDate);\r
106         }\r
107 \r
108     /**\r
109      * Fill relation.\r
110      * \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
116      * @param rt the rt\r
117      */\r
118     void fillRelation(RelationsCommon relation, \r
119             String subjectCsid, String subjectDocumentType,\r
120             String objectCsid, String objectDocumentType,\r
121             String rt)\r
122     {\r
123         relation.setSubjectCsid(subjectCsid);\r
124         relation.setSubjectDocumentType(subjectDocumentType);\r
125         relation.setObjectCsid(objectCsid);\r
126         relation.setObjectDocumentType(objectDocumentType);\r
127         \r
128         relation.setRelationshipType(rt);\r
129     }\r
130         \r
131         /**\r
132          * Creates the identifier.\r
133          * \r
134          * @return the string\r
135          */\r
136         String createIdentifier() {\r
137                 long identifier = System.currentTimeMillis();\r
138                 return Long.toString(identifier);\r
139         }\r
140 \r
141         /**\r
142          * Extract id.\r
143          * \r
144          * @param res the res\r
145          * \r
146          * @return the string\r
147          */\r
148         String extractId(ClientResponse<Response> res) {\r
149                 String result = null;\r
150                 \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
157                 \r
158                 return result;\r
159         }\r
160 \r
161         /**\r
162          * Extract part.\r
163          * \r
164          * @param input\r
165          *            the input\r
166          * @param label\r
167          *            the label\r
168          * @param clazz\r
169          *            the clazz\r
170          * \r
171          * @return the object\r
172          * \r
173          * @throws Exception\r
174          *             the exception\r
175          */\r
176         static Object extractPart(PoxPayloadIn input, String label, Class clazz) {\r
177                 Object obj = null;\r
178 \r
179                 PayloadInputPart payloadInputPart = input.getPart(label);\r
180                 if (payloadInputPart != null) {\r
181                         obj = payloadInputPart.getBody();\r
182                                 }\r
183 \r
184                 return obj;\r
185         }\r
186         \r
187         /**\r
188          * Verbose.\r
189          * \r
190          * @param msg the msg\r
191          */\r
192         void verbose(String msg) {\r
193                 System.out.println(msg);\r
194         }\r
195 \r
196         /**\r
197          * Verbose.\r
198          * \r
199          * @param msg the msg\r
200          * @param o the o\r
201          * @param clazz the clazz\r
202          */\r
203         void verbose(String msg, Object o, Class clazz) {\r
204                 try {\r
205                         verbose(msg);\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
212                 }\r
213         }\r
214 \r
215         /**\r
216          * Verbose map.\r
217          * \r
218          * @param map the map\r
219          */\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
224                 }\r
225         }\r
226 \r
227 }\r