2 * This document is a part of the source code and related artifacts
\r
3 * for CollectionSpace, an open source collections management system
\r
4 * for museums and related institutions:
\r
6 * http://www.collectionspace.org
\r
7 * http://wiki.collectionspace.org
\r
9 * Copyright (c) 2009 Regents of the University of California
\r
11 * Licensed under the Educational Community License (ECL), Version 2.0.
\r
12 * You may not use this file except in compliance with this License.
\r
14 * You may obtain a copy of the ECL 2.0 License at
\r
15 * https://source.collectionspace.org/collection-space/LICENSE.txt
\r
17 * Unless required by applicable law or agreed to in writing, software
\r
18 * distributed under the License is distributed on an "AS IS" BASIS,
\r
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
20 * See the License for the specific language governing permissions and
\r
21 * limitations under the License.
\r
24 package org.collectionspace.services.IntegrationTests.test;
\r
26 import org.collectionspace.services.IntegrationTests.xmlreplay.ServiceResult;
\r
27 import org.collectionspace.services.IntegrationTests.xmlreplay.XmlReplay;
\r
28 import org.collectionspace.services.IntegrationTests.xmlreplay.XmlReplayTest;
\r
29 import org.testng.annotations.Test;
\r
31 import java.util.List;
\r
32 import java.util.Map;
\r
34 /** The test cases in here also document the ways that XmlReplay was designed to be used programmatically.
\r
35 * The most automated way to use XmlReplay is demonstrated in runMaster(). You just create a master file and a control
\r
36 * file in the IntegrationTests xml replay repository, which is in services/IntegrationTests + XmlReplayTest.XMLREPLAY_REL_DIR_TO_MODULE.
\r
38 * If you choose to run from a module, you'll need to add a dependency to the IntegrationTests module:
\r
43 <groupId>org.collectionspace.services</groupId>
\r
44 <artifactId>org.collectionspace.services.IntegrationTests</artifactId>
\r
45 <version>${project.version}</version>
\r
49 * $LastChangedRevision: $
\r
50 * $LastChangedDate: $
\r
52 public class XmlReplaySelfTest extends XmlReplayTest {
\r
54 public static XmlReplay createXmlReplay() throws Exception {
\r
55 return XmlReplayTest.createXmlReplayUsingIntegrationTestsModule("..");
\r
56 //NOTE: this self-test lives in services/IntegrationTests, so relToServicesRoot is ".."
\r
57 // but if you were running from, say, services/dimension/client, then relToServicesRoot would be "../.."
\r
58 // so you would have to call XmlReplayTest.createXmlReplayUsingIntegrationTestsModule("../..")
\r
59 // which is done for you if you just call XmlReplayTest.createXmlReplay().
\r
63 public void runMaster() throws Exception {
\r
64 XmlReplay replay = createXmlReplay();
\r
65 List<List<ServiceResult>> list = replay.runMaster("xml-replay-master-self-test.xml");
\r
66 logTestForGroup(list, "runMaster");
\r
70 public void runTestGroup() throws Exception {
\r
71 XmlReplay replay = createXmlReplay();
\r
72 replay.readOptionsFromMasterConfigFile("xml-replay-master-self-test.xml"); //or use: XmlReplay.DEFAULT_MASTER_CONTROL as master filename;
\r
73 replay.setControlFileName("xml-replay-self-test.xml");
\r
74 List<ServiceResult> list = replay.runTestGroup("selftestGroup");
\r
75 logTest(list, "runTestGroup");
\r
80 public void runOneTest() throws Exception {
\r
81 XmlReplay replay = createXmlReplay();
\r
82 replay.readOptionsFromMasterConfigFile("xml-replay-master-self-test.xml");
\r
83 replay.setControlFileName("xml-replay-self-test.xml");
\r
85 ServiceResult res = replay.runTest("selftestGroup", "OrgAuth1");
\r
86 logTest(res, "runOneTest");
\r
91 public void runMultipleTestsManualCleanup() throws Exception {
\r
92 XmlReplay replay = createXmlReplay();
\r
93 replay.readOptionsFromMasterConfigFile("xml-replay-master-self-test.xml");
\r
94 replay.setControlFileName("xml-replay-self-test.xml");
\r
95 replay.setAutoDeletePOSTS(false); //defaults to true, so turn it off to to it ourselves.
\r
97 List<ServiceResult> testResultsList = new ArrayList<ServiceResult>();
\r
99 ServiceResult res1 = replay.runTest("selftestGroup", "OrgAuth1");
\r
100 testResultsList.add(res1);
\r
102 ServiceResult res2 = replay.runTest("selftestGroup", "Org1");
\r
103 testResultsList.add(res2);
\r
105 ServiceResult res3 = replay.runTest("selftestGroup", "getOrg1");
\r
106 testResultsList.add(res3);
\r
108 //Now, clean up. You may skip this if your tests do all the DELETEs.
\r
109 List<ServiceResult> deleteList = replay.autoDelete("runMultipleTestsManualCleanup");
\r
111 logTest(testResultsList, "runTwoTestsManualCleanup.tests");
\r
112 logTest(deleteList, "runTwoTestsManualCleanup.cleanups");
\r
119 public void runTestGroup_AllOptions() throws Exception {
\r
120 XmlReplay replay = createXmlReplay(); //Use the central repository.
\r
121 //You can also use your own xml replay repository in your module, like so:
\r
122 // XmlReplay replay = XmlReplayTest.createXmlReplayForModule(); if you are in your module
\r
123 //You can also manually specify to use the central repository:
\r
124 // XmlReplay replay = XmlReplayTest.createXmlReplayUsingIntegrationTestsModule(".."); if you are in a module such as dimension
\r
125 // XmlReplay replay = XmlReplayTest.createXmlReplayUsingIntegrationTestsModule("../.."); if you are in a module such as dimension/client
\r
127 //You may read Dump, Auths, and protoHostPort from the master file:
\r
128 replay.readOptionsFromMasterConfigFile("xml-replay-master-self-test.xml"); //or use: XmlReplay.DEFAULT_MASTER_CONTROL as master filename;
\r
129 //or you may set those options individually as shown next.
\r
130 // Note that controlFileName is NOT set from calling readOptionsFromMasterConfigFile.
\r
131 // If you run a master, it sets controlFileName, possibly in a loop.
\r
132 // All of the Auths will be read from the master file, and may be referenced from your control file,
\r
133 // or you may specify Auths in your control file. There are also public methods to set the AuthsMap yourself.
\r
135 //XmlReplay wants to know about two files: a master and a control file
\r
136 // The master references one to many control files.
\r
137 // If you don't call runMaster(), you must specify the control file:
\r
138 replay.setControlFileName("xml-replay-self-test.xml");
\r
140 //These option default sensibly, some of them from the master, but here's how to set them all:
\r
142 //Dump determines how much goes to log, and how verbose.
\r
143 XmlReplay.Dump dump = XmlReplay.getDumpConfig(); //static factory call.
\r
144 dump.payloads = false;
\r
145 dump.dumpServiceResult = ServiceResult.DUMP_OPTIONS.minimal;
\r
146 replay.setDump(dump);
\r
148 //use this if you must look it up from some other place.
\r
149 // Default is to have it in xml-replay-master.xml
\r
150 replay.setProtoHostPort("http://localhost:8180");
\r
152 //Default is true, but you can override if you want to leave objects on server, or control the order of deletion.
\r
153 replay.setAutoDeletePOSTS(false);
\r
155 //You don't need this, but you can inspect what XmlReplay holds onto: a data structure of CSIDs
\r
156 Map<String, ServiceResult> serviceResultsMap = replay.getServiceResultsMap();
\r
158 // ****** RUN A GROUP ***********************************************
\r
159 List<ServiceResult> list = replay.runTestGroup("selftestGroup");
\r
161 // This runs a group called "organization" inside a control file named above, which happens to be called "organization.xml".
\r
162 // You could also run just one test using these options by calling replay.runTest as shown above in XmlReplayTest.runOneTest()
\r
164 //Now, since we set setAutoDeletePOSTS(false) above, you can clean up manually:
\r
165 replay.autoDelete("runTestGroup_AllOptions"); //deletes everything in serviceResultsMap, which it hangs onto.
\r
167 logTest(list, "runTestGroup_AllOptions");
\r