1
2
3
4
5
6
7
8
9 package net.kwfgrid.gwes;
10
11 import junit.framework.Assert;
12 import junit.framework.Test;
13 import junit.framework.TestSuite;
14 import net.kwfgrid.gwes.exception.*;
15 import net.kwfgrid.gworkflowdl.structure.WorkflowFormatException;
16 import org.apache.log4j.Logger;
17 import org.jaxen.JaxenException;
18 import org.jdom.JDOMException;
19
20 import java.io.IOException;
21
22
23
24
25
26
27
28
29
30
31
32
33 public final class GWES_StoreRestoreRestartTest extends LocalGWESAbstractTestCase {
34
35
36
37
38 static Logger logger = Logger.getLogger(GWES_StoreRestoreRestartTest.class);
39
40 public final String userID;
41
42 GWES gwes;
43
44 String workflowID;
45
46
47
48
49
50
51 public GWES_StoreRestoreRestartTest(String testName) throws LoggingException {
52 super(testName);
53 userID = System.getProperty("user.name");
54 }
55
56
57
58
59 public static Test suite() {
60 return new TestSuite(GWES_StoreRestoreRestartTest.class);
61 }
62
63 public void testStoreRestore() throws IOException, StateTransitionException, WorkflowFormatException, WorkflowSecurityException, NoSuchWorkflowException, InterruptedException, DatabaseException, JaxenException, JDOMException, LoggingException, GWESException {
64 gwes = new GWESEngine();
65 String fn = "examples/controlflow/gworkflowdl_breakpoint.xml";
66 workflowID = gwes.initiate(readfile(fn), userID);
67 logger.info("workflowID: " + workflowID);
68 gwes.start(workflowID, userID);
69 waitWorkflowStatus(gwes, workflowID);
70
71
72 logger.info("Status: " + WorkflowStatus.getStatusAsString(gwes.getStatus(workflowID, userID)));
73
74
75 String path = gwes.store(workflowID, userID);
76 logger.info("Workflow stored at "+path);
77 gwes.abort(workflowID, userID);
78
79
80 String restoredWorkfow = gwes.restore(path, userID);
81 logger.info("Status of restored workflow: " + WorkflowStatus.getStatusAsString(gwes.getStatus(restoredWorkfow, userID)));
82 gwes.start(restoredWorkfow, userID);
83 waitWorkflowStatus(gwes, restoredWorkfow);
84
85
86 logger.info("Status of restored workflow: " + WorkflowStatus.getStatusAsString(gwes.getStatus(restoredWorkfow, userID)));
87
88
89 Assert.assertEquals("Status of aborted workflow", WorkflowStatus.STATUS_TERMINATED, gwes.getStatus(workflowID, userID));
90 Assert.assertEquals("Status of restored workflow", WorkflowStatus.STATUS_COMPLETED, gwes.getStatus(restoredWorkfow, userID));
91
92 String[] end = gwes.getData(restoredWorkfow, "end", userID);
93 logger.info("Token on end place\n" + end[0].trim());
94 Assert.assertEquals("Token on end place", "<control xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xsi:type=\"xsd:boolean\">true</control>", end[0].trim());
95 }
96
97 public void testAbortRestart() throws IOException, StateTransitionException, WorkflowFormatException, WorkflowSecurityException, NoSuchWorkflowException, InterruptedException, DatabaseException, JaxenException, JDOMException, LoggingException, GWESException {
98 gwes = new GWESEngine();
99 String fn = "examples/controlflow/gworkflowdl_breakpoint.xml";
100 workflowID = gwes.initiate(readfile(fn), userID);
101 logger.info("workflowID: " + workflowID);
102 gwes.start(workflowID, userID);
103 waitWorkflowStatus(gwes, workflowID);
104
105
106 logger.info("Status: " + WorkflowStatus.getStatusAsString(gwes.getStatus(workflowID, userID)));
107
108
109 gwes.abort(workflowID, userID);
110 logger.info("Status: " + WorkflowStatus.getStatusAsString(gwes.getStatus(workflowID, userID)));
111 Assert.assertEquals("Status of aborted workflow", WorkflowStatus.STATUS_TERMINATED, gwes.getStatus(workflowID, userID));
112
113
114 String restartedWorkfow = gwes.restart(workflowID, userID);
115 gwes.start(restartedWorkfow, userID);
116 logger.info("Status of restarted workflow: " + WorkflowStatus.getStatusAsString(gwes.getStatus(restartedWorkfow, userID)));
117 waitWorkflowStatus(gwes, restartedWorkfow);
118
119
120 logger.info("Status of restarted workflow: " + WorkflowStatus.getStatusAsString(gwes.getStatus(restartedWorkfow, userID)));
121 Assert.assertEquals("Status of restarted workflow", WorkflowStatus.STATUS_SUSPENDED, gwes.getStatus(restartedWorkfow, userID));
122 gwes.resume(restartedWorkfow, userID);
123 waitWorkflowStatus(gwes, restartedWorkfow);
124
125
126 Assert.assertEquals("Status of restarted workflow", WorkflowStatus.STATUS_COMPLETED, gwes.getStatus(restartedWorkfow, userID));
127
128 String[] end = gwes.getData(restartedWorkfow, "end", userID);
129 logger.info("Token on end place\n" + end[0].trim());
130 Assert.assertEquals("Token on end place", "<control xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xsi:type=\"xsd:boolean\">true</control>", end[0].trim());
131 }
132
133 }