2 * CollectionSpacePerformanceTest.java
4 * {Purpose of This Class}
6 * {Other Notes Relating to This Class (Optional)}
9 * $LastChangedRevision: $
12 * This document is a part of the source code and related artifacts
13 * for CollectionSpace, an open source collections management system
14 * for museums and related institutions:
16 * http://www.collectionspace.org
17 * http://wiki.collectionspace.org
19 * Copyright © 2009 {Contributing Institution}
21 * Licensed under the Educational Community License (ECL), Version 2.0.
22 * You may not use this file except in compliance with this License.
24 * You may obtain a copy of the ECL 2.0 License at
25 * https://source.collectionspace.org/collection-space/LICENSE.txt
27 package org.collectionspace.services.PerformanceTests.test;
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.Random;
33 import javax.ws.rs.core.MultivaluedMap;
34 import javax.ws.rs.core.Response;
35 import javax.xml.bind.JAXBContext;
36 import javax.xml.bind.Marshaller;
38 import org.collectionspace.services.collectionobject.CollectionobjectsCommon;
39 import org.collectionspace.services.collectionobject.TitleGroup;
40 import org.collectionspace.services.collectionobject.TitleGroupList;
41 import org.collectionspace.services.intake.IntakesCommon;
42 import org.collectionspace.services.relation.RelationsCommon;
43 import org.collectionspace.services.relation.RelationshipType;
44 import org.jboss.resteasy.client.ClientResponse;
45 import org.jboss.resteasy.plugins.providers.multipart.InputPart;
46 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
49 * The Class CollectionSpacePerformanceTests.
51 public abstract class CollectionSpacePerformanceTest {
53 protected final static String OBJECT_NUMBER = "objectNumber_";
54 protected final static String OBJECT_TITLE = "objectTitle_";
57 * Package scoped methods.
61 * Fill collection object.
64 * @param identifier the identifier
66 void fillCollectionObject(CollectionobjectsCommon co, String identifier) {
67 fillCollectionObject(co, OBJECT_NUMBER + identifier, OBJECT_TITLE + identifier);
71 * Fill collection object.
74 * @param objectNumber the object number
75 * @param title the object title
77 void fillCollectionObject(CollectionobjectsCommon co, String objectNumber,
79 co.setObjectNumber(objectNumber);
80 TitleGroupList titleGroupList = new TitleGroupList();
81 List<TitleGroup> titleGroups = titleGroupList.getTitleGroup();
82 TitleGroup titleGroup = new TitleGroup();
83 titleGroup.setTitle(title);
84 titleGroups.add(titleGroup);
85 co.setTitleGroupList(titleGroupList);
91 * @param theIntake the the intake
92 * @param identifier the identifier
94 void fillIntake(IntakesCommon theIntake, String identifier) {
95 fillIntake(theIntake, "entryNumber-" + identifier, "entryDate-"
102 * @param theIntake the the intake
103 * @param entryNumber the entry number
104 * @param entryDate the entry date
106 void fillIntake(IntakesCommon theIntake, String entryNumber, String entryDate) {
107 theIntake.setEntryNumber(entryNumber);
108 theIntake.setEntryDate(entryDate);
114 * @param relation the relation
115 * @param subjectCsid the document id1
116 * @param subjectDocumentType the document type1
117 * @param objectCsid the document id2
118 * @param objectDocumentType the document type2
121 void fillRelation(RelationsCommon relation, String subjectCsid, String subjectDocumentType,
122 String objectCsid, String objectDocumentType, RelationshipType rt)
124 relation.setSubjectCsid(subjectCsid);
125 relation.setSubjectDocumentType(subjectDocumentType);
126 relation.setSubjectCsid(objectCsid);
127 relation.setObjectDocumentType(objectDocumentType);
129 relation.setRelationshipType(rt.toString());
133 * Creates the identifier.
137 String createIdentifier() {
138 long identifier = System.currentTimeMillis();
139 return Long.toString(identifier);
149 String extractId(ClientResponse<Response> res) {
150 String result = null;
152 MultivaluedMap mvm = res.getMetadata();
153 String uri = (String) ((ArrayList) mvm.get("Location")).get(0);
154 verbose("extractId:uri=" + uri);
155 String[] segments = uri.split("/");
156 result = segments[segments.length - 1];
157 verbose("id=" + result);
162 String extractId(Response res) {
163 String result = null;
165 MultivaluedMap mvm = res.getMetadata();
166 String uri = (String) ((ArrayList) mvm.get("Location")).get(0);
167 verbose("extractId:uri=" + uri);
168 String[] segments = uri.split("/");
169 result = segments[segments.length - 1];
170 verbose("id=" + result);
190 static Object extractPart(MultipartInput input, String label, Class clazz) {
194 for (InputPart part : input.getParts()) {
195 String partLabel = part.getHeaders().getFirst("label");
196 if (label.equalsIgnoreCase(partLabel)) {
197 String partStr = part.getBodyAsString();
198 obj = part.getBody(clazz, null);
202 } catch (Exception e) {
214 void verbose(String msg) {
215 // System.out.println(msg);
223 * @param clazz the clazz
225 void verbose(String msg, Object o, Class clazz) {
228 JAXBContext jc = JAXBContext.newInstance(clazz);
229 Marshaller m = jc.createMarshaller();
230 m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
231 m.marshal(o, System.out);
232 } catch (Exception e) {
242 void verboseMap(MultivaluedMap map) {
243 for (Object entry : map.entrySet()) {
244 MultivaluedMap.Entry mentry = (MultivaluedMap.Entry) entry;
245 verbose(" name=" + mentry.getKey() + " value=" + mentry.getValue());
249 boolean isEnabled() {
250 return Boolean.getBoolean("cspace.perf");