1 package net.kwfgrid.gwes;
2
3 import java.io.*;
4 import java.rmi.RemoteException;
5
6 import junit.framework.Assert;
7 import net.kwfgrid.gwes.exception.*;
8 import net.kwfgrid.gworkflowdl.structure.*;
9 import org.apache.log4j.Logger;
10
11
12
13
14 public abstract class LocalGWESAbstractTestCase
15 extends AbstractTestCase {
16
17 protected GWES gwes;
18
19 String workflowID;
20
21 static Logger logger = Logger.getLogger(LocalGWESAbstractTestCase.class);
22
23
24
25
26 public LocalGWESAbstractTestCase(String testName) throws LoggingException {
27 super(testName);
28 gwes = new GWESEngine();
29 }
30
31 public GWES getGwes() {
32 return gwes;
33 }
34
35 public String testGWES(String gworkflowdlPath, int expectedStatus) throws StateTransitionException, WorkflowFormatException, WorkflowSecurityException, NoSuchWorkflowException, InterruptedException, DatabaseException, LoggingException {
36 String retGWorkflowDL = null;
37 try {
38 if (gwes == null) {
39 gwes = getGwes();
40 }
41 workflowID = gwes.initiate(readfile(gworkflowdlPath), userID);
42 logger.debug("workflowID: " + workflowID);
43 gwes.start(workflowID, userID);
44
45 int status = waitWorkflowStatus(gwes, workflowID);
46
47 retGWorkflowDL = gwes.getWorkflowDescription(workflowID, userID);
48 logger.debug(retGWorkflowDL);
49
50 Assert.assertEquals("Exit status of workflow "+workflowID, expectedStatus, status);
51 } catch (GWESException e) {
52 logger.error("GWES exception: "+e,e);
53 Assert.fail("Got unpredicted GWES exception");
54 } catch (RemoteException e) {
55 logger.error("GWES Remote exception: "+e,e);
56 Assert.fail("GWES Remote exception");
57 } catch (IOException e) {
58 logger.error("GWES IO exception: "+e,e);
59 Assert.fail("GWES IO exception");
60 }
61
62 return retGWorkflowDL;
63 }
64
65
66
67
68
69
70 public int waitWorkflowStatus(GWES gwes, String workflowID) throws NoSuchWorkflowException, InterruptedException, RemoteException, DatabaseException, LoggingException, GWESException, WorkflowSecurityException {
71 Logger logger = Logger.getLogger(gwes.getClass());
72 int status = gwes.getStatus(workflowID, userID);
73 logger.debug("Status: "+ WorkflowStatus.getStatusAsString(status));
74 while (status != WorkflowStatus.STATUS_COMPLETED
75 && status != WorkflowStatus.STATUS_TERMINATED
76 && status != WorkflowStatus.STATUS_SUSPENDED) {
77 int oldStatus = status;
78 status = gwes.waitForStatusChangeFrom(workflowID, oldStatus, userID);
79 logger.debug("Status: "+ WorkflowStatus.getStatusAsString(status));
80 }
81 return status;
82 }
83
84 }
85
86
87