]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
a4200fe7e00fc83bac924d4bd66d9605434ef215
[tmp/jakarta-migration.git] /
1 /**\r
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
5  *\r
6  * http://www.collectionspace.org\r
7  * http://wiki.collectionspace.org\r
8  *\r
9  * Copyright (c) 2009 Regents of the University of California\r
10  *\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
13  *\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
16  *\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
22  */\r
23 \r
24 package org.collectionspace.services.IntegrationTests.test;\r
25 \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
30 \r
31 import java.util.List;\r
32 import java.util.Map;\r
33 \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
37  *\r
38  *   If you choose to run from a module, you'll need to add a dependency to the IntegrationTests module:\r
39  *   e.g.\r
40  *    <project ...>\r
41  *    <dependencies>\r
42  *      <dependency>\r
43             <groupId>org.collectionspace.services</groupId>\r
44             <artifactId>org.collectionspace.services.IntegrationTests</artifactId>\r
45             <version>${project.version}</version>\r
46         </dependency>\r
47  *\r
48  *   User: laramie\r
49  *   $LastChangedRevision:  $\r
50  *   $LastChangedDate:  $\r
51  */\r
52 public class XmlReplaySelfTest extends XmlReplayTest {\r
53 \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
60     }\r
61 \r
62     @Test\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
67     }\r
68 \r
69     @Test\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
76     }\r
77 \r
78 /*\r
79     @Test\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
84 \r
85         ServiceResult res = replay.runTest("selftestGroup", "OrgAuth1");\r
86         logTest(res, "runOneTest");\r
87     }\r
88 \r
89 \r
90     @Test\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
96 \r
97         List<ServiceResult> testResultsList = new ArrayList<ServiceResult>();\r
98 \r
99         ServiceResult res1 = replay.runTest("selftestGroup", "OrgAuth1");\r
100         testResultsList.add(res1);\r
101 \r
102         ServiceResult res2 = replay.runTest("selftestGroup", "Org1");\r
103         testResultsList.add(res2);\r
104 \r
105         ServiceResult res3 = replay.runTest("selftestGroup", "getOrg1");\r
106         testResultsList.add(res3);\r
107 \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
110 \r
111         logTest(testResultsList, "runTwoTestsManualCleanup.tests");\r
112         logTest(deleteList, "runTwoTestsManualCleanup.cleanups");\r
113 \r
114     }\r
115 */\r
116 \r
117 \r
118     @Test\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
126 \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
134 \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
139 \r
140         //These option default sensibly, some of them from the master, but here's how to set them all:\r
141 \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
147 \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
151 \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
154 \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
157 \r
158         // ****** RUN A GROUP ***********************************************\r
159         List<ServiceResult> list = replay.runTestGroup("selftestGroup");\r
160 \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
163 \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
166 \r
167         logTest(list, "runTestGroup_AllOptions");\r
168     }\r
169 \r
170 }\r