2 * CollectionSpacePerformanceTest.java
\r
4 * {Purpose of This Class}
\r
6 * {Other Notes Relating to This Class (Optional)}
\r
9 * $LastChangedRevision: $
\r
10 * $LastChangedDate: $
\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
16 * http://www.collectionspace.org
\r
17 * http://wiki.collectionspace.org
\r
19 * Copyright © 2009 {Contributing Institution}
\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
24 * You may obtain a copy of the ECL 2.0 License at
\r
25 * https://source.collectionspace.org/collection-space/LICENSE.txt
\r
27 package org.collectionspace.services.PerformanceTests.test;
\r
29 import java.util.ArrayList;
\r
30 import java.util.List;
\r
31 import java.util.Random;
\r
33 import javax.ws.rs.core.MultivaluedMap;
\r
34 import javax.ws.rs.core.Response;
\r
35 import javax.xml.bind.JAXBContext;
\r
36 import javax.xml.bind.Marshaller;
\r
38 import org.collectionspace.services.collectionobject.CollectionobjectsCommon;
\r
39 import org.collectionspace.services.collectionobject.TitleGroup;
\r
40 import org.collectionspace.services.collectionobject.TitleGroupList;
\r
41 import org.collectionspace.services.intake.IntakesCommon;
\r
42 import org.collectionspace.services.relation.RelationsCommon;
\r
43 import org.collectionspace.services.relation.RelationshipType;
\r
44 import org.jboss.resteasy.client.ClientResponse;
\r
45 import org.jboss.resteasy.plugins.providers.multipart.InputPart;
\r
46 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
\r
49 * The Class CollectionSpacePerformanceTests.
\r
51 public abstract class CollectionSpacePerformanceTest {
\r
53 protected final static String OBJECT_NUMBER = "objectNumber_";
\r
54 protected final static String OBJECT_TITLE = "objectTitle_";
\r
57 * Package scoped methods.
\r
61 * Fill collection object.
\r
64 * @param identifier the identifier
\r
66 void fillCollectionObject(CollectionobjectsCommon co, String identifier) {
\r
67 fillCollectionObject(co, OBJECT_NUMBER + identifier, OBJECT_TITLE + identifier);
\r
71 * Fill collection object.
\r
74 * @param objectNumber the object number
\r
75 * @param title the object title
\r
77 void fillCollectionObject(CollectionobjectsCommon co, String objectNumber,
\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
91 * @param theIntake the the intake
\r
92 * @param identifier the identifier
\r
94 void fillIntake(IntakesCommon theIntake, String identifier) {
\r
95 fillIntake(theIntake, "entryNumber-" + identifier, "entryDate-"
\r
102 * @param theIntake the the intake
\r
103 * @param entryNumber the entry number
\r
104 * @param entryDate the entry date
\r
106 void fillIntake(IntakesCommon theIntake, String entryNumber, String entryDate) {
\r
107 theIntake.setEntryNumber(entryNumber);
\r
108 theIntake.setEntryDate(entryDate);
\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
121 void fillRelation(RelationsCommon relation, String documentId1, String documentType1,
\r
122 String documentId2, String documentType2, RelationshipType rt)
\r
124 relation.setDocumentId1(documentId1);
\r
125 relation.setDocumentType1(documentType1);
\r
126 relation.setDocumentId2(documentId2);
\r
127 relation.setDocumentType2(documentType2);
\r
129 relation.setRelationshipType(rt.toString());
\r
133 * Creates the identifier.
\r
135 * @return the string
\r
137 String createIdentifier() {
\r
138 long identifier = System.currentTimeMillis();
\r
139 return Long.toString(identifier);
\r
145 * @param res the res
\r
147 * @return the string
\r
149 String extractId(ClientResponse<Response> res) {
\r
150 String result = null;
\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
172 * @return the object
\r
174 * @throws Exception
\r
177 static Object extractPart(MultipartInput input, String label, Class clazz) {
\r
181 for (InputPart part : input.getParts()) {
\r
182 String partLabel = part.getHeaders().getFirst("label");
\r
183 if (label.equalsIgnoreCase(partLabel)) {
\r
184 String partStr = part.getBodyAsString();
\r
185 obj = part.getBody(clazz, null);
\r
189 } catch (Exception e) {
\r
190 e.printStackTrace();
\r
199 * @param msg the msg
\r
201 void verbose(String msg) {
\r
202 // System.out.println(msg);
\r
208 * @param msg the msg
\r
210 * @param clazz the clazz
\r
212 void verbose(String msg, Object o, Class clazz) {
\r
215 JAXBContext jc = JAXBContext.newInstance(clazz);
\r
216 Marshaller m = jc.createMarshaller();
\r
217 m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
\r
218 m.marshal(o, System.out);
\r
219 } catch (Exception e) {
\r
220 e.printStackTrace();
\r
227 * @param map the map
\r
229 void verboseMap(MultivaluedMap map) {
\r
230 for (Object entry : map.entrySet()) {
\r
231 MultivaluedMap.Entry mentry = (MultivaluedMap.Entry) entry;
\r
232 verbose(" name=" + mentry.getKey() + " value=" + mentry.getValue());
\r
236 boolean isEnabled() {
\r
237 return Boolean.getBoolean("cspace.perf");
\r