]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
b66b1b23c5d5f5915e1720172f3415a375154db2
[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.ArrayList;\r
32 import java.util.List;\r
33 import java.util.Map;\r
34 \r
35 /**  The test cases in here also document the ways that XmlReplay was designed to be used programmatically.\r
36  *   The most automated way to use XmlReplay is demonstrated in runMaster().  You just create a master file and a control\r
37  *   file in the IntegrationTests xml replay repository, which is in services/IntegrationTests + XmlReplayTest.XMLREPLAY_REL_DIR_TO_MODULE.\r
38  *\r
39  *   If you choose to run from a module, you'll need to add a dependency to the IntegrationTests module:\r
40  *   e.g.\r
41  *    <project ...>\r
42  *    <dependencies>\r
43  *      <dependency>\r
44             <groupId>org.collectionspace.services</groupId>\r
45             <artifactId>org.collectionspace.services.IntegrationTests</artifactId>\r
46             <version>${project.version}</version>\r
47         </dependency>\r
48  *\r
49  *   User: laramie\r
50  *   $LastChangedRevision:  $\r
51  *   $LastChangedDate:  $\r
52  */\r
53 public class XmlReplaySelfTest extends XmlReplayTest {\r
54 \r
55     public static XmlReplay createXmlReplay() throws Exception {\r
56         return XmlReplayTest.createXmlReplayUsingIntegrationTestsModule("..");\r
57         //NOTE: this self-test lives in services/IntegrationTests, so relToServicesRoot is ".."\r
58         //      but if you were running from, say, services/dimension/client, then relToServicesRoot would be "../.."\r
59         //      so you would have to call XmlReplayTest.createXmlReplayUsingIntegrationTestsModule("../..")\r
60         //      which is done for you if you just call XmlReplayTest.createXmlReplay().\r
61     }\r
62 \r
63     @Test\r
64     public void runMaster() throws Exception {\r
65         XmlReplay replay = createXmlReplay();\r
66         List<List<ServiceResult>> list = replay.runMaster("xml-replay-master-self-test.xml");\r
67         logTestForGroup(list, "runMaster");\r
68     }\r
69 \r
70     @Test\r
71     public void runTestGroup() throws Exception {\r
72         XmlReplay replay = createXmlReplay();\r
73         replay.readOptionsFromMasterConfigFile("xml-replay-master-self-test.xml"); //or use: XmlReplay.DEFAULT_MASTER_CONTROL as master filename;\r
74         replay.setControlFileName("xml-replay-self-test.xml");\r
75         List<ServiceResult> list = replay.runTestGroup("selftestGroup");\r
76         logTest(list, "runTestGroup");\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     @Test\r
118     public void runTestGroup_AllOptions() throws Exception {\r
119         XmlReplay replay = createXmlReplay();  //Use the central repository.\r
120         //You can also use your own xml replay repository in your module, like so:\r
121         //   XmlReplay replay = XmlReplayTest.createXmlReplayForModule(); if you are in your module\r
122         //You can also manually specify to use the central repository:\r
123         //   XmlReplay replay = XmlReplayTest.createXmlReplayUsingIntegrationTestsModule("..");  if you are in a module such as dimension\r
124         //   XmlReplay replay = XmlReplayTest.createXmlReplayUsingIntegrationTestsModule("../.."); if you are in a module such as dimension/client\r
125 \r
126         //You may read Dump, Auths, and protoHostPort from the master file:\r
127         replay.readOptionsFromMasterConfigFile("xml-replay-master-self-test.xml"); //or use: XmlReplay.DEFAULT_MASTER_CONTROL as master filename;\r
128         //or you may set those options individually as shown next.\r
129         // Note that controlFileName is NOT set from calling readOptionsFromMasterConfigFile.\r
130         // If you run a master, it sets controlFileName, possibly in a loop.\r
131         // All of the Auths will be read from the master file, and may be referenced from your control file,\r
132         // or you may specify Auths in your control file.  There are also public methods to set the AuthsMap yourself.\r
133 \r
134         //XmlReplay wants to know about two files: a master and a control file\r
135         //  The master references one to many control files.\r
136         //  If you don't call runMaster(), you must specify the control file:\r
137         replay.setControlFileName("xml-replay-self-test.xml");\r
138 \r
139         //These option default sensibly, some of them from the master, but here's how to set them all:\r
140 \r
141         //Dump determines how much goes to log, and how verbose.\r
142         XmlReplay.Dump dump = XmlReplay.getDumpConfig(); //static factory call.\r
143         dump.payloads = false;\r
144         dump.dumpServiceResult = ServiceResult.DUMP_OPTIONS.minimal;\r
145         replay.setDump(dump);\r
146 \r
147         //use this if you must look it up from some other place.\r
148         // Default is to have it in xml-replay-master.xml\r
149         replay.setProtoHostPort("http://localhost:8180");\r
150 \r
151         //Default is true, but you can override if you want to leave objects on server, or control the order of deletion.\r
152         replay.setAutoDeletePOSTS(false);\r
153 \r
154         //You don't need this, but you can inspect what XmlReplay holds onto: a data structure of CSIDs\r
155         Map<String, ServiceResult> serviceResultsMap = replay.getServiceResultsMap();\r
156 \r
157         // ****** RUN A GROUP ***********************************************\r
158         List<ServiceResult> list = replay.runTestGroup("selftestGroup");\r
159 \r
160         // This runs a group called "organization" inside a control file named above, which happens to be called "organization.xml".\r
161         // You could also run just one test using these options by calling replay.runTest as shown above in XmlReplayTest.runOneTest()\r
162 \r
163         //Now, since we set setAutoDeletePOSTS(false) above, you can clean up manually:\r
164         replay.autoDelete("runTestGroup_AllOptions"); //deletes everything in serviceResultsMap, which it hangs onto.\r
165 \r
166         logTest(list, "runTestGroup_AllOptions");\r
167     }\r
168 \r
169 }\r