Revision 5139
Added by daigle over 14 years ago
WorkflowSchedulerTest.java | ||
---|---|---|
25 | 25 |
*/ |
26 | 26 |
package edu.ucsb.nceas.workflowschedulertest; |
27 | 27 |
|
28 |
import java.io.IOException; |
|
28 | 29 |
import java.io.StringReader; |
29 | 30 |
import java.util.Hashtable; |
30 | 31 |
|
... | ... | |
34 | 35 |
import org.xml.sax.InputSource; |
35 | 36 |
|
36 | 37 |
import edu.ucsb.nceas.MCTestCase; |
38 |
import edu.ucsb.nceas.metacat.client.MetacatAuthException; |
|
39 |
import edu.ucsb.nceas.metacat.client.MetacatInaccessibleException; |
|
37 | 40 |
import edu.ucsb.nceas.metacat.properties.PropertyService; |
38 | 41 |
import edu.ucsb.nceas.metacat.shared.ServiceException; |
39 | 42 |
import edu.ucsb.nceas.metacat.util.RequestUtil; |
... | ... | |
48 | 51 |
*/ |
49 | 52 |
public class WorkflowSchedulerTest extends MCTestCase { |
50 | 53 |
// Constants |
54 |
private static String docId = null; |
|
55 |
private static String dataDocId = null; |
|
56 |
private static String sessionId = null; |
|
51 | 57 |
private static String workflowJobName; |
52 | 58 |
private static String workflowSchedulerUrl; |
53 | 59 |
private static XPathFactory xPathFactory = null; |
54 | 60 |
|
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"; |
|
61 |
private static final String WORKFLOW_ID_BASE = "urn:lsid:gamma.msi.ucsb.edu/OpenAuth/:"; |
|
62 |
private static String WORKFLOW_ID = null; |
|
63 |
private static final String KAR_ID_BASE = "urn:lsid:gamma.msi.ucsb.edu/OpenAuth/:"; |
|
64 |
private static String KAR_ID = null; |
|
57 | 65 |
private static final String WORKFLOW_NAME = "tpc02-water-flow-base"; |
58 | 66 |
private static final String START_TIME = "10/10/2008 10:10:10"; |
59 | 67 |
private static final String END_TIME = "10/10/2009 10:10:10"; |
60 | 68 |
private static final String INTERVAL_VALUE = "100"; |
61 |
private static final String INTERVAL_UNIT = "s";
|
|
69 |
private static final String INTERVAL_UNIT = "min";
|
|
62 | 70 |
|
63 | 71 |
static { |
64 | 72 |
try { |
... | ... | |
85 | 93 |
xPathFactory = XPathFactory.newInstance(); |
86 | 94 |
|
87 | 95 |
} |
96 |
|
|
97 |
/** |
|
98 |
* Establish a testing framework by initializing appropriate objects |
|
99 |
*/ |
|
100 |
public void setUp() throws Exception { |
|
101 |
metacatConnectionNeeded = true; |
|
102 |
|
|
103 |
super.setUp(); |
|
104 |
//debug("session id: " + sessionId); |
|
105 |
//debug("doc id: " + docId); |
|
106 |
//debug("data doc id: " + dataDocId); |
|
107 |
|
|
108 |
try { |
|
109 |
if (sessionId == null) { |
|
110 |
String loginResult = m.login(username, password); |
|
111 |
//debug("WorkflowSchedulerTest.initialize - login result: " + loginResult); |
|
112 |
if (loginResult.contains("<sessionId>")) { |
|
113 |
int startIndex = loginResult.indexOf("<sessionId>") + 11; |
|
114 |
int endIndex = loginResult.indexOf("</sessionId>"); |
|
115 |
sessionId = loginResult.substring(startIndex, endIndex); |
|
116 |
//debug("WorkflowSchedulerTest.initialize - session id: " + sessionId); |
|
117 |
} else { |
|
118 |
fail("could not get session ID from login results"); |
|
119 |
} |
|
120 |
} |
|
88 | 121 |
|
122 |
if (docId == null) { |
|
123 |
// insert a document for us to test with |
|
124 |
docId = generateDocumentId() + ".1"; |
|
125 |
|
|
126 |
String testDoc = |
|
127 |
getTestDocFromFile(testdatadir + "tpc02-water-flow-base.xml"); |
|
128 |
// debug("test doc: " + testDoc); |
|
129 |
insertDocumentId(docId, testDoc, SUCCESS, false); |
|
130 |
|
|
131 |
WORKFLOW_ID = WORKFLOW_ID_BASE + docId.replace('.', ':'); |
|
132 |
} |
|
133 |
|
|
134 |
if (dataDocId == null) { |
|
135 |
// insert a data document (kar file) for us to test with |
|
136 |
dataDocId = generateDocumentId() + ".1"; |
|
137 |
|
|
138 |
String filePath = testdatadir + "888.42.1-tpc02-water-flow-base-10.kar"; |
|
139 |
// debug("test doc: " + testDoc); |
|
140 |
uploadDocumentId(dataDocId, filePath, SUCCESS, false); |
|
141 |
|
|
142 |
KAR_ID = KAR_ID_BASE + dataDocId.replace('.', ':'); |
|
143 |
} |
|
144 |
} catch (IOException ioe) { |
|
145 |
fail("WorkflowSchedulerTest.initialize - I/O exception: " + ioe.getMessage()); |
|
146 |
} catch (MetacatInaccessibleException mie) { |
|
147 |
fail("WorkflowSchedulerTest.initialize - Metacat Inaccessible: " + mie.getMessage()); |
|
148 |
} catch (MetacatAuthException mae) { |
|
149 |
fail("WorkflowSchedulerTest.initialize - Metacat auth issue: " + mae.getMessage()); |
|
150 |
} |
|
151 |
|
|
152 |
} |
|
153 |
|
|
89 | 154 |
/** |
90 | 155 |
* Create a suite of tests to be run together |
91 | 156 |
*/ |
... | ... | |
108 | 173 |
} |
109 | 174 |
|
110 | 175 |
public void scheduleJobTest() { |
111 |
try { |
|
112 |
|
|
176 |
try { |
|
113 | 177 |
Hashtable<String, String[]> params = new Hashtable<String, String[]>(); |
114 | 178 |
|
115 | 179 |
params.put("action", new String[] { "scheduleWorkflow" }); |
... | ... | |
122 | 186 |
params.put("endtime", new String[] { END_TIME }); |
123 | 187 |
params.put("intervalvalue", new String[] { INTERVAL_VALUE }); |
124 | 188 |
params.put("intervalunit", new String[] { INTERVAL_UNIT }); |
189 |
params.put("sessionid", new String[] { sessionId }); |
|
125 | 190 |
|
126 | 191 |
String schedulerResponse = RequestUtil.get(workflowSchedulerUrl, params); |
127 | 192 |
debug("WorkflowSchedulerTest.scheduleJobTest - response: " + schedulerResponse); |
... | ... | |
158 | 223 |
|
159 | 224 |
public void unscheduleJobTest() { |
160 | 225 |
try { |
226 |
String loginResult = m.login(username, password); |
|
227 |
String sessionId = null; |
|
228 |
if (loginResult.contains("<sessionId>")) { |
|
229 |
int startIndex = loginResult.indexOf("<sessionId>") + 11; |
|
230 |
int endIndex = loginResult.indexOf("</sessionId>"); |
|
231 |
sessionId = loginResult.substring(startIndex, endIndex); |
|
232 |
} else { |
|
233 |
fail("could not get session ID from login results"); |
|
234 |
} |
|
235 |
|
|
161 | 236 |
Hashtable<String, String[]> params = new Hashtable<String, String[]>(); |
162 | 237 |
|
163 | 238 |
params.put("action", new String[] { "unscheduleWorkflow" }); |
164 | 239 |
params.put("workflowjobname", new String[] { workflowJobName }); |
165 | 240 |
params.put("workflowid", new String[] { WORKFLOW_ID }); |
166 | 241 |
params.put("workflowname", new String[] { "tpc02-water-flow-base" }); |
242 |
params.put("sessionid", new String[] { sessionId }); |
|
167 | 243 |
|
168 | 244 |
String schedulerResponse = RequestUtil.get(workflowSchedulerUrl, params); |
169 | 245 |
debug("WorkflowSchedulerTest.unScheduleJobTest - response: " + schedulerResponse); |
... | ... | |
195 | 271 |
|
196 | 272 |
public void rescheduleJobTest() { |
197 | 273 |
try { |
274 |
String loginResult = m.login(username, password); |
|
275 |
String sessionId = null; |
|
276 |
if (loginResult.contains("<sessionId>")) { |
|
277 |
int startIndex = loginResult.indexOf("<sessionId>") + 11; |
|
278 |
int endIndex = loginResult.indexOf("</sessionId>"); |
|
279 |
sessionId = loginResult.substring(startIndex, endIndex); |
|
280 |
} else { |
|
281 |
fail("could not get session ID from login results"); |
|
282 |
} |
|
283 |
|
|
198 | 284 |
Hashtable<String, String[]> params = new Hashtable<String, String[]>(); |
199 | 285 |
|
200 | 286 |
params.put("action", new String[] { "rescheduleWorkflow" }); |
... | ... | |
202 | 288 |
params.put("workflowid", |
203 | 289 |
new String[] { WORKFLOW_ID }); |
204 | 290 |
params.put("workflowname", new String[] { "tpc02-water-flow-base" }); |
291 |
params.put("sessionid", new String[] { sessionId }); |
|
205 | 292 |
|
206 | 293 |
String schedulerResponse = RequestUtil.get(workflowSchedulerUrl, params); |
207 | 294 |
debug("WorkflowSchedulerTest.reScheduleJobTest - response: " + schedulerResponse); |
... | ... | |
233 | 320 |
|
234 | 321 |
public void deleteJobTest() { |
235 | 322 |
try { |
323 |
String loginResult = m.login(username, password); |
|
324 |
String sessionId = null; |
|
325 |
if (loginResult.contains("<sessionId>")) { |
|
326 |
int startIndex = loginResult.indexOf("<sessionId>") + 11; |
|
327 |
int endIndex = loginResult.indexOf("</sessionId>"); |
|
328 |
sessionId = loginResult.substring(startIndex, endIndex); |
|
329 |
} else { |
|
330 |
fail("could not get session ID from login results"); |
|
331 |
} |
|
332 |
|
|
236 | 333 |
Hashtable<String, String[]> params = new Hashtable<String, String[]>(); |
237 | 334 |
|
238 | 335 |
params.put("action", new String[] { "deleteScheduledWorkflow" }); |
239 | 336 |
params.put("workflowjobname", new String[] { workflowJobName }); |
337 |
params.put("sessionid", new String[] { sessionId }); |
|
240 | 338 |
|
241 | 339 |
String schedulerResponse = RequestUtil.get(workflowSchedulerUrl, params); |
242 | 340 |
debug("WorkflowSchedulerTest.deleteJobTest - response: " + schedulerResponse); |
Also available in: Unified diff
Fix errors in workflow scheduler unit test