]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
7b3cf371560b075d08a9ac52d07b7d42cb3ec70e
[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.intake.IntakesCommon;\r
43 import org.collectionspace.services.relation.RelationsCommon;\r
44 import org.collectionspace.services.relation.RelationshipType;\r
45 import org.jboss.resteasy.client.ClientResponse;\r
46 import org.jboss.resteasy.plugins.providers.multipart.InputPart;\r
47 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;\r
48 \r
49 /**\r
50  * The Class CollectionSpaceIntegrationTest.\r
51  */\r
52 public abstract class CollectionSpaceIntegrationTest {\r
53 \r
54         /*\r
55          * Package scoped methods.\r
56          */\r
57 \r
58         /**\r
59          * Fill collection object.\r
60          * \r
61          * @param co the co\r
62          * @param identifier the identifier\r
63          */\r
64         void fillCollectionObject(CollectionobjectsCommon co, String identifier) {\r
65                 fillCollectionObject(co, "objectNumber-" + identifier, "title-"\r
66                                 + identifier);\r
67         }\r
68 \r
69         /**\r
70          * Fill collection object.\r
71          * \r
72          * @param co the co\r
73          * @param objectNumber the object number\r
74          * @param title the object title\r
75          */\r
76         void fillCollectionObject(CollectionobjectsCommon co, String objectNumber,\r
77                         String title) {\r
78                 co.setObjectNumber(objectNumber);\r
79                 TitleGroupList titleGroupList = new TitleGroupList();\r
80                 List<TitleGroup> titleGroups = titleGroupList.getTitleGroup();\r
81                 TitleGroup titleGroup = new TitleGroup();\r
82                 titleGroup.setTitle(title);\r
83                 titleGroups.add(titleGroup);\r
84                 co.setTitleGroupList(titleGroupList);\r
85         }\r
86 \r
87         /**\r
88          * Fill intake.\r
89          * \r
90          * @param theIntake the the intake\r
91          * @param identifier the identifier\r
92          */\r
93         void fillIntake(IntakesCommon theIntake, String identifier) {\r
94                 fillIntake(theIntake, "entryNumber-" + identifier, "entryDate-"\r
95                                 + identifier);\r
96         }\r
97 \r
98         /**\r
99          * Fill intake.\r
100          * \r
101          * @param theIntake the the intake\r
102          * @param entryNumber the entry number\r
103          * @param entryDate the entry date\r
104          */\r
105         void fillIntake(IntakesCommon theIntake, String entryNumber, String entryDate) {\r
106                 theIntake.setEntryNumber(entryNumber);\r
107                 theIntake.setEntryDate(entryDate);\r
108         }\r
109 \r
110     /**\r
111      * Fill relation.\r
112      * \r
113      * @param relation the relation\r
114      * @param documentId1 the document id1\r
115      * @param documentType1 the document type1\r
116      * @param documentId2 the document id2\r
117      * @param documentType2 the document type2\r
118      * @param rt the rt\r
119      */\r
120     void fillRelation(RelationsCommon relation, String documentId1, String documentType1,\r
121                 String documentId2, String documentType2, String rt)\r
122     {\r
123         relation.setDocumentId1(documentId1);\r
124         relation.setDocumentType1(documentType1);\r
125         relation.setDocumentId2(documentId2);\r
126         relation.setDocumentType2(documentType2);\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