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.plugins.providers.multipart.InputPart;
45 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
48 * The Class CollectionSpacePerformanceTests.
50 public abstract class CollectionSpacePerformanceTest {
52 protected final static String OBJECT_NUMBER = "objectNumber_";
53 protected final static String OBJECT_TITLE = "objectTitle_";
56 * Package scoped methods.
60 * Fill collection object.
63 * @param identifier the identifier
65 void fillCollectionObject(CollectionobjectsCommon co, String identifier) {
66 fillCollectionObject(co, OBJECT_NUMBER + identifier, OBJECT_TITLE + identifier);
70 * Fill collection object.
73 * @param objectNumber the object number
74 * @param title the object title
76 void fillCollectionObject(CollectionobjectsCommon co, String objectNumber,
78 co.setObjectNumber(objectNumber);
79 TitleGroupList titleGroupList = new TitleGroupList();
80 List<TitleGroup> titleGroups = titleGroupList.getTitleGroup();
81 TitleGroup titleGroup = new TitleGroup();
82 titleGroup.setTitle(title);
83 titleGroups.add(titleGroup);
84 co.setTitleGroupList(titleGroupList);
90 * @param theIntake the the intake
91 * @param identifier the identifier
93 void fillIntake(IntakesCommon theIntake, String identifier) {
94 fillIntake(theIntake, "entryNumber-" + identifier, "entryDate-"
101 * @param theIntake the the intake
102 * @param entryNumber the entry number
103 * @param entryDate the entry date
105 void fillIntake(IntakesCommon theIntake, String entryNumber, String entryDate) {
106 theIntake.setEntryNumber(entryNumber);
107 theIntake.setEntryDate(entryDate);
113 * @param relation the relation
114 * @param subjectCsid the document id1
115 * @param subjectDocumentType the document type1
116 * @param objectCsid the document id2
117 * @param objectDocumentType the document type2
120 void fillRelation(RelationsCommon relation, String subjectCsid, String subjectDocumentType,
121 String objectCsid, String objectDocumentType, RelationshipType rt)
123 relation.setSubjectCsid(subjectCsid);
124 relation.setSubjectDocumentType(subjectDocumentType);
125 relation.setSubjectCsid(objectCsid);
126 relation.setObjectDocumentType(objectDocumentType);
128 relation.setRelationshipType(rt.toString());
132 * Creates the identifier.
136 String createIdentifier() {
137 long identifier = System.currentTimeMillis();
138 return Long.toString(identifier);
141 String extractId(Response res) {
142 String result = null;
144 MultivaluedMap mvm = res.getMetadata();
145 String uri = (String) ((ArrayList) mvm.get("Location")).get(0);
146 verbose("extractId:uri=" + uri);
147 String[] segments = uri.split("/");
148 result = segments[segments.length - 1];
149 verbose("id=" + result);
169 static Object extractPart(MultipartInput input, String label, Class clazz) {
173 for (InputPart part : input.getParts()) {
174 String partLabel = part.getHeaders().getFirst("label");
175 if (label.equalsIgnoreCase(partLabel)) {
176 String partStr = part.getBodyAsString();
177 obj = part.getBody(clazz, null);
181 } catch (Exception e) {
193 void verbose(String msg) {
194 // System.out.println(msg);
202 * @param clazz the clazz
204 void verbose(String msg, Object o, Class clazz) {
207 JAXBContext jc = JAXBContext.newInstance(clazz);
208 Marshaller m = jc.createMarshaller();
209 m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
210 m.marshal(o, System.out);
211 } catch (Exception e) {
221 void verboseMap(MultivaluedMap map) {
222 for (Object entry : map.entrySet()) {
223 MultivaluedMap.Entry mentry = (MultivaluedMap.Entry) entry;
224 verbose(" name=" + mentry.getKey() + " value=" + mentry.getValue());
228 boolean isEnabled() {
229 return Boolean.getBoolean("cspace.perf");