Revision 5046
Added by daigle about 15 years ago
test/edu/ucsb/nceas/workflowschedulertest/WorkflowSchedulerTest.java | ||
---|---|---|
1 |
/** |
|
2 |
* '$RCSfile$' |
|
3 |
* Purpose: A Class that implements a metadata catalog as a java Servlet |
|
4 |
* Copyright: 2006 Regents of the University of California and the |
|
5 |
* National Center for Ecological Analysis and Synthesis |
|
6 |
* Authors: Matt Jones, Dan Higgins, Jivka Bojilova, Chad Berkley, Matthew Perry |
|
7 |
* |
|
8 |
* '$Author: daigle $' |
|
9 |
* '$Date: 2008-09-24 11:28:29 -0700 (Wed, 24 Sep 2008) $' |
|
10 |
* '$Revision: 4384 $' |
|
11 |
* |
|
12 |
* This program is free software; you can redistribute it and/or modify |
|
13 |
* it under the terms of the GNU General Public License as published by |
|
14 |
* the Free Software Foundation; either version 2 of the License, or |
|
15 |
* (at your option) any later version. |
|
16 |
* |
|
17 |
* This program is distributed in the hope that it will be useful, |
|
18 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20 |
* GNU General Public License for more details. |
|
21 |
* |
|
22 |
* You should have received a copy of the GNU General Public License |
|
23 |
* along with this program; if not, write to the Free Software |
|
24 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
25 |
*/ |
|
26 |
package edu.ucsb.nceas.workflowschedulertest; |
|
27 |
|
|
28 |
import java.io.StringReader; |
|
29 |
import java.util.Hashtable; |
|
30 |
|
|
31 |
import javax.xml.xpath.XPath; |
|
32 |
import javax.xml.xpath.XPathExpression; |
|
33 |
import javax.xml.xpath.XPathFactory; |
|
34 |
import org.xml.sax.InputSource; |
|
35 |
|
|
36 |
import edu.ucsb.nceas.MCTestCase; |
|
37 |
import edu.ucsb.nceas.metacat.properties.PropertyService; |
|
38 |
import edu.ucsb.nceas.metacat.shared.ServiceException; |
|
39 |
import edu.ucsb.nceas.metacat.util.RequestUtil; |
|
40 |
import edu.ucsb.nceas.utilities.PropertyNotFoundException; |
|
41 |
|
|
42 |
import junit.framework.Test; |
|
43 |
import junit.framework.TestSuite; |
|
44 |
|
|
45 |
|
|
46 |
/* |
|
47 |
* A junit test class to test public methods in AuthLdap class. |
|
48 |
*/ |
|
49 |
public class WorkflowSchedulerTest extends MCTestCase { |
|
50 |
// Constants |
|
51 |
private static String workflowJobName; |
|
52 |
private static String workflowSchedulerUrl; |
|
53 |
private static XPathFactory xPathFactory = null; |
|
54 |
|
|
55 |
private static final String WORKFLOW_ID = "urn:lsid:gamma.msi.ucsb.edu/OpenAuth/:423:379:29"; |
|
56 |
private static final String KAR_ID = "urn:lsid:gamma.msi.ucsb.edu/OpenAuth/:423:715:1"; |
|
57 |
private static final String WORKFLOW_NAME = "tpc02-water-flow-base"; |
|
58 |
private static final String START_TIME = "10/10/2008 10:10:10"; |
|
59 |
private static final String END_TIME = "10/10/2009 10:10:10"; |
|
60 |
private static final String INTERVAL_VALUE = "100"; |
|
61 |
private static final String INTERVAL_UNIT = "s"; |
|
62 |
|
|
63 |
static { |
|
64 |
try { |
|
65 |
PropertyService.getInstance(); |
|
66 |
workflowSchedulerUrl = PropertyService |
|
67 |
.getProperty("test.workflowSchedulerUrl"); |
|
68 |
} catch (PropertyNotFoundException pnfe) { |
|
69 |
System.err.println("Could not get property in static block: " |
|
70 |
+ pnfe.getMessage()); |
|
71 |
} catch (ServiceException se) { |
|
72 |
System.err.println("Service problem in static block: " + se.getMessage()); |
|
73 |
} |
|
74 |
} |
|
75 |
|
|
76 |
/** |
|
77 |
* Constructor to build the test |
|
78 |
* |
|
79 |
* @param name |
|
80 |
* the name of the test method |
|
81 |
*/ |
|
82 |
public WorkflowSchedulerTest(String name) { |
|
83 |
super(name); |
|
84 |
|
|
85 |
xPathFactory = XPathFactory.newInstance(); |
|
86 |
|
|
87 |
} |
|
88 |
|
|
89 |
/** |
|
90 |
* Create a suite of tests to be run together |
|
91 |
*/ |
|
92 |
public static Test suite() { |
|
93 |
TestSuite suite = new TestSuite(); |
|
94 |
suite.addTest(new WorkflowSchedulerTest("initialize")); |
|
95 |
suite.addTest(new WorkflowSchedulerTest("scheduleJobTest")); |
|
96 |
suite.addTest(new WorkflowSchedulerTest("unscheduleJobTest")); |
|
97 |
suite.addTest(new WorkflowSchedulerTest("rescheduleJobTest")); |
|
98 |
suite.addTest(new WorkflowSchedulerTest("deleteJobTest")); |
|
99 |
return suite; |
|
100 |
} |
|
101 |
|
|
102 |
/** |
|
103 |
* Run an initial test that always passes to check that the test harness is |
|
104 |
* working. |
|
105 |
*/ |
|
106 |
public void initialize() { |
|
107 |
assertTrue(1 == 1); |
|
108 |
} |
|
109 |
|
|
110 |
public void scheduleJobTest() { |
|
111 |
try { |
|
112 |
|
|
113 |
Hashtable<String, String[]> params = new Hashtable<String, String[]>(); |
|
114 |
|
|
115 |
params.put("action", new String[] { "scheduleWorkflow" }); |
|
116 |
params.put("workflowid", |
|
117 |
new String[] { WORKFLOW_ID }); |
|
118 |
params.put("karid", |
|
119 |
new String[] { KAR_ID }); |
|
120 |
params.put("workflowname", new String[] { WORKFLOW_NAME }); |
|
121 |
params.put("starttime", new String[] { START_TIME }); |
|
122 |
params.put("endtime", new String[] { END_TIME }); |
|
123 |
params.put("intervalvalue", new String[] { INTERVAL_VALUE }); |
|
124 |
params.put("intervalunit", new String[] { INTERVAL_UNIT }); |
|
125 |
|
|
126 |
String schedulerResponse = RequestUtil.get(workflowSchedulerUrl, params); |
|
127 |
debug("WorkflowSchedulerTest.scheduleJobTest - response: " + schedulerResponse); |
|
128 |
|
|
129 |
XPath xPath=xPathFactory.newXPath(); |
|
130 |
XPathExpression xPathExpression = xPath.compile("/success"); |
|
131 |
String successMessage = xPathExpression.evaluate(new InputSource(new StringReader(schedulerResponse))); |
|
132 |
|
|
133 |
assertTrue("success message did not start with 'Scheduled'", |
|
134 |
successMessage != null && successMessage.startsWith("Scheduled:")); |
|
135 |
|
|
136 |
String[] successMessageArray = successMessage.split(" "); |
|
137 |
|
|
138 |
workflowJobName = successMessageArray[1]; |
|
139 |
debug("WorkflowSchedulerTest.scheduleJobTest - workflow job name: " + workflowJobName); |
|
140 |
|
|
141 |
Hashtable<String, String[]> getWorkflowParams = new Hashtable<String, String[]>(); |
|
142 |
getWorkflowParams.put("action", new String[] { "getScheduledWorkflow" }); |
|
143 |
getWorkflowParams.put("workflowid", new String[] { WORKFLOW_ID }); |
|
144 |
|
|
145 |
String getWorkflowsResponse = RequestUtil.get(workflowSchedulerUrl, getWorkflowParams); |
|
146 |
//debug("WorkflowSchedulerTest.scheduleJobTest - get runs for workflow id " + WORKFLOW_ID + " returns: " + getWorkflowsResponse); |
|
147 |
|
|
148 |
XPath getWorkflowsXPath=xPathFactory.newXPath(); |
|
149 |
XPathExpression getStatusXPathExpression = getWorkflowsXPath.compile("/scheduledWorkflowResultset/scheduledJob[name=\"" + workflowJobName + "\"]/status"); |
|
150 |
String status = getStatusXPathExpression.evaluate(new InputSource(new StringReader(getWorkflowsResponse))); |
|
151 |
|
|
152 |
assertTrue(status != null && status.equals("scheduled")); |
|
153 |
|
|
154 |
} catch (Exception e) { |
|
155 |
fail("WorkflowSchedulerTest.scheduleJobTest - General exception:\n" + e.getMessage()); |
|
156 |
} |
|
157 |
} |
|
158 |
|
|
159 |
public void unscheduleJobTest() { |
|
160 |
try { |
|
161 |
Hashtable<String, String[]> params = new Hashtable<String, String[]>(); |
|
162 |
|
|
163 |
params.put("action", new String[] { "unscheduleWorkflow" }); |
|
164 |
params.put("workflowjobname", new String[] { workflowJobName }); |
|
165 |
params.put("workflowid", new String[] { WORKFLOW_ID }); |
|
166 |
params.put("workflowname", new String[] { "tpc02-water-flow-base" }); |
|
167 |
|
|
168 |
String schedulerResponse = RequestUtil.get(workflowSchedulerUrl, params); |
|
169 |
debug("WorkflowSchedulerTest.unScheduleJobTest - response: " + schedulerResponse); |
|
170 |
|
|
171 |
XPath xPath=xPathFactory.newXPath(); |
|
172 |
XPathExpression xPathExpression = xPath.compile("/success"); |
|
173 |
String successMessage = xPathExpression.evaluate(new InputSource(new StringReader(schedulerResponse))); |
|
174 |
|
|
175 |
assertTrue("success message did not start with 'Unscheduled'", |
|
176 |
successMessage != null && successMessage.startsWith("Unscheduled:")); |
|
177 |
|
|
178 |
Hashtable<String, String[]> getWorkflowParams = new Hashtable<String, String[]>(); |
|
179 |
getWorkflowParams.put("action", new String[] { "getScheduledWorkflow" }); |
|
180 |
getWorkflowParams.put("workflowid", new String[] { WORKFLOW_ID }); |
|
181 |
|
|
182 |
String getWorkflowsResponse = RequestUtil.get(workflowSchedulerUrl, getWorkflowParams); |
|
183 |
//debug("WorkflowSchedulerTest.unScheduleJobTest - get runs for workflow id " + WORKFLOW_ID + " returns: " + getWorkflowsResponse); |
|
184 |
|
|
185 |
XPath getWorkflowsXPath=xPathFactory.newXPath(); |
|
186 |
XPathExpression getStatusXPathExpression = getWorkflowsXPath.compile("/scheduledWorkflowResultset/scheduledJob[name=\"" + workflowJobName + "\"]/status"); |
|
187 |
String status = getStatusXPathExpression.evaluate(new InputSource(new StringReader(getWorkflowsResponse))); |
|
188 |
|
|
189 |
assertTrue(status != null && status.equals("unscheduled")); |
|
190 |
|
|
191 |
} catch (Exception e) { |
|
192 |
fail("WorkflowSchedulerTest.unScheduleJobTest - General exception:\n" + e.getMessage()); |
|
193 |
} |
|
194 |
} |
|
195 |
|
|
196 |
public void rescheduleJobTest() { |
|
197 |
try { |
|
198 |
Hashtable<String, String[]> params = new Hashtable<String, String[]>(); |
|
199 |
|
|
200 |
params.put("action", new String[] { "rescheduleWorkflow" }); |
|
201 |
params.put("workflowjobname", new String[] { workflowJobName }); |
|
202 |
params.put("workflowid", |
|
203 |
new String[] { WORKFLOW_ID }); |
|
204 |
params.put("workflowname", new String[] { "tpc02-water-flow-base" }); |
|
205 |
|
|
206 |
String schedulerResponse = RequestUtil.get(workflowSchedulerUrl, params); |
|
207 |
debug("WorkflowSchedulerTest.reScheduleJobTest - response: " + schedulerResponse); |
|
208 |
|
|
209 |
XPath xPath=xPathFactory.newXPath(); |
|
210 |
XPathExpression xPathExpression = xPath.compile("/success"); |
|
211 |
String successMessage = xPathExpression.evaluate(new InputSource(new StringReader(schedulerResponse))); |
|
212 |
|
|
213 |
assertTrue("success message did not start with 'Rescheduled'", |
|
214 |
successMessage != null && successMessage.startsWith("Rescheduled:")); |
|
215 |
|
|
216 |
Hashtable<String, String[]> getWorkflowParams = new Hashtable<String, String[]>(); |
|
217 |
getWorkflowParams.put("action", new String[] { "getScheduledWorkflow" }); |
|
218 |
getWorkflowParams.put("workflowid", new String[] { WORKFLOW_ID }); |
|
219 |
|
|
220 |
String getWorkflowsResponse = RequestUtil.get(workflowSchedulerUrl, getWorkflowParams); |
|
221 |
//debug("WorkflowSchedulerTest.reScheduleJobTest - get runs for workflow id " + WORKFLOW_ID + " returns: " + getWorkflowsResponse); |
|
222 |
|
|
223 |
XPath getWorkflowsXPath=xPathFactory.newXPath(); |
|
224 |
XPathExpression getStatusXPathExpression = getWorkflowsXPath.compile("/scheduledWorkflowResultset/scheduledJob[name=\"" + workflowJobName + "\"]/status"); |
|
225 |
String status = getStatusXPathExpression.evaluate(new InputSource(new StringReader(getWorkflowsResponse))); |
|
226 |
|
|
227 |
assertTrue(status != null && status.equals("scheduled")); |
|
228 |
|
|
229 |
} catch (Exception e) { |
|
230 |
fail("WorkflowSchedulerTest.reScheduleJobTest - General exception:\n" + e.getMessage()); |
|
231 |
} |
|
232 |
} |
|
233 |
|
|
234 |
public void deleteJobTest() { |
|
235 |
try { |
|
236 |
Hashtable<String, String[]> params = new Hashtable<String, String[]>(); |
|
237 |
|
|
238 |
params.put("action", new String[] { "deleteScheduledWorkflow" }); |
|
239 |
params.put("workflowjobname", new String[] { workflowJobName }); |
|
240 |
|
|
241 |
String schedulerResponse = RequestUtil.get(workflowSchedulerUrl, params); |
|
242 |
debug("WorkflowSchedulerTest.deleteJobTest - response: " + schedulerResponse); |
|
243 |
|
|
244 |
XPath xPath=xPathFactory.newXPath(); |
|
245 |
XPathExpression xPathExpression = xPath.compile("/success"); |
|
246 |
String successMessage = xPathExpression.evaluate(new InputSource(new StringReader(schedulerResponse))); |
|
247 |
|
|
248 |
assertTrue("success message did not start with 'Deleted'", |
|
249 |
successMessage != null && successMessage.startsWith("Deleted:")); |
|
250 |
|
|
251 |
Hashtable<String, String[]> getWorkflowParams = new Hashtable<String, String[]>(); |
|
252 |
getWorkflowParams.put("action", new String[] { "getScheduledWorkflow" }); |
|
253 |
getWorkflowParams.put("workflowid", new String[] { WORKFLOW_ID }); |
|
254 |
|
|
255 |
String getWorkflowsResponse = RequestUtil.get(workflowSchedulerUrl, getWorkflowParams); |
|
256 |
//debug("WorkflowSchedulerTest.deleteJobTest - get runs for workflow id " + WORKFLOW_ID + " returns: " + getWorkflowsResponse); |
|
257 |
|
|
258 |
XPath getWorkflowsXPath=xPathFactory.newXPath(); |
|
259 |
XPathExpression getStatusXPathExpression = getWorkflowsXPath.compile("/scheduledWorkflowResultset/scheduledJob[name=\"" + workflowJobName + "\"]/status"); |
|
260 |
String status = getStatusXPathExpression.evaluate(new InputSource(new StringReader(getWorkflowsResponse))); |
|
261 |
|
|
262 |
assertTrue(status == null || status.equals("")); |
|
263 |
|
|
264 |
} catch (Exception e) { |
|
265 |
fail("WorkflowSchedulerTest.deleteJobTest - General exception:\n" + e.getMessage()); |
|
266 |
} |
|
267 |
} |
|
268 |
|
|
269 |
} |
|
0 | 270 |
Also available in: Unified diff
Create workflow scheduler test.