]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
b3fc2ca00b2de5e4792b80bd15609779f61d067d
[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 documentId1 the document id1\r
116      * @param documentType1 the document type1\r
117      * @param documentId2 the document id2\r
118      * @param documentType2 the document type2\r
119      * @param rt the rt\r
120      */\r
121     void fillRelation(RelationsCommon relation, String documentId1, String documentType1,\r
122                 String documentId2, String documentType2, String rt)\r
123     {\r
124         relation.setDocumentId1(documentId1);\r
125         relation.setDocumentType1(documentType1);\r
126         relation.setDocumentId2(documentId2);\r
127         relation.setDocumentType2(documentType2);\r
128         \r
129         relation.setRelationshipType(rt);\r
130     }\r
131         \r
132         /**\r
133          * Creates the identifier.\r
134          * \r
135          * @return the string\r
136          */\r
137         String createIdentifier() {\r
138                 long identifier = System.currentTimeMillis();\r
139                 return Long.toString(identifier);\r
140         }\r
141 \r
142         /**\r
143          * Extract id.\r
144          * \r
145          * @param res the res\r
146          * \r
147          * @return the string\r
148          */\r
149         String extractId(ClientResponse<Response> res) {\r
150                 String result = null;\r
151                 \r
152                 MultivaluedMap mvm = res.getMetadata();\r
153                 String uri = (String) ((ArrayList) mvm.get("Location")).get(0);\r
154                 verbose("extractId:uri=" + uri);\r
155                 String[] segments = uri.split("/");\r
156                 result = segments[segments.length - 1];\r
157                 verbose("id=" + result);\r
158                 \r
159                 return result;\r
160         }\r
161 \r
162         /**\r
163          * Extract part.\r
164          * \r
165          * @param input\r
166          *            the input\r
167          * @param label\r
168          *            the label\r
169          * @param clazz\r
170          *            the clazz\r
171          * \r
172          * @return the object\r
173          * \r
174          * @throws Exception\r
175          *             the exception\r
176          */\r
177         static Object extractPart(PoxPayloadIn input, String label, Class clazz) {\r
178                 Object obj = null;\r
179 \r
180                 PayloadInputPart payloadInputPart = input.getPart(label);\r
181                 if (payloadInputPart != null) {\r
182                         obj = payloadInputPart.getBody();\r
183                                 }\r
184 \r
185                 return obj;\r
186         }\r
187         \r
188         /**\r
189          * Verbose.\r
190          * \r
191          * @param msg the msg\r
192          */\r
193         void verbose(String msg) {\r
194                 System.out.println(msg);\r
195         }\r
196 \r
197         /**\r
198          * Verbose.\r
199          * \r
200          * @param msg the msg\r
201          * @param o the o\r
202          * @param clazz the clazz\r
203          */\r
204         void verbose(String msg, Object o, Class clazz) {\r
205                 try {\r
206                         verbose(msg);\r
207                         JAXBContext jc = JAXBContext.newInstance(clazz);\r
208                         Marshaller m = jc.createMarshaller();\r
209                         m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);\r
210                         m.marshal(o, System.out);\r
211                 } catch (Exception e) {\r
212                         e.printStackTrace();\r
213                 }\r
214         }\r
215 \r
216         /**\r
217          * Verbose map.\r
218          * \r
219          * @param map the map\r
220          */\r
221         void verboseMap(MultivaluedMap map) {\r
222                 for (Object entry : map.entrySet()) {\r
223                         MultivaluedMap.Entry mentry = (MultivaluedMap.Entry) entry;\r
224                         verbose("  name=" + mentry.getKey() + " value=" + mentry.getValue());\r
225                 }\r
226         }\r
227 \r
228 }\r