1   package net.kwfgrid.gworkflowdl;
2   
3   
4   import junit.framework.Assert;
5   import junit.framework.Test;
6   import junit.framework.TestSuite;
7   import net.kwfgrid.gworkflowdl.analysis.Analyzer;
8   import net.kwfgrid.gworkflowdl.analysis.Net;
9   import net.kwfgrid.gworkflowdl.structure.*;
10  
11  /***
12   * Created by IntelliJ IDEA.
13   * User: hans
14   * Date: 11.10.2005
15   * Time: 15:15:24
16   * To change this template use File | Settings | File Templates.
17   */
18  public class AnalyseTest extends AbstractTestCase {
19  
20      public AnalyseTest(String testName) {
21          super(testName);
22      }
23  
24      /***
25       * @return the suite of tests being tested
26       */
27      public static Test suite() {
28          return new TestSuite(AnalyseTest.class);
29      }
30  
31  
32      /***
33       * Rigourous Test :-).
34       */
35      public void testApp() {
36         
37          Place begin = Factory.newPlace();
38          begin.setID("begin");
39          try {
40              begin.addToken(Factory.newToken());
41          } catch (CapacityException e) {
42          }
43          Place p1 = Factory.newPlace();
44          p1.setID("p1");
45  
46          Place p2 = Factory.newPlace();
47          p2.setID("p2");
48  
49          Place end = Factory.newPlace();
50          end.setID("end");
51  
52          Transition t1 = Factory.newTransition();
53          t1.setID("t1");
54          Edge in1 = Factory.newEdge();
55          in1.setPlace(begin);
56          t1.addInEdge(in1);
57          Edge out1 = Factory.newEdge();
58          out1.setPlace(p1);
59          t1.addOutEdge(out1);
60  
61          Transition t2 = Factory.newTransition();
62          t2.setID("t2");
63          Edge in2 = Factory.newEdge();
64          in2.setPlace(begin);
65          t2.addInEdge(in2);
66          Edge out2 = Factory.newEdge();
67          out2.setPlace(p2);
68          t2.addOutEdge(out2);
69  
70          Transition t = Factory.newTransition();
71          t.setID("first");
72          Edge inn1 = Factory.newEdge();
73          inn1.setPlace(p1);
74          t.addInEdge(inn1);
75          Edge inn2 = Factory.newEdge();
76          inn2.setPlace(p2);
77          t.addInEdge(inn2);
78          Edge out = Factory.newEdge();
79          out.setPlace(end);
80          t.addOutEdge(out);
81  
82          Workflow wf = Factory.newWorkflow();
83          wf.addPlace(begin);
84          wf.addPlace(p1);
85          wf.addPlace(p2);
86          wf.addPlace(end);
87  
88          wf.addTransition(t1);
89          wf.addTransition(t2);
90          wf.addTransition(t);
91  
92          try {
93              String s = JdomString.workflow2string(wf);
94              System.out.println(s);
95          } catch (Exception e) {
96              System.out.println(e);
97          }
98  
99          Analyzer wkm = new Analyzer(wf);
100         Assert.assertTrue(wkm.isQuasiLive(t1));
101         Assert.assertTrue(wkm.isQuasiLive(t2));
102         Assert.assertFalse(wkm.isQuasiLive(t));
103 
104         Assert.assertTrue(wkm.isQuasiLive(begin));
105         Assert.assertTrue(wkm.isQuasiLive(p1));
106         Assert.assertTrue(wkm.isQuasiLive(p2));
107         Assert.assertFalse(wkm.isQuasiLive(end));
108 
109         Assert.assertFalse(wkm.isFinallyMarked(end));
110 
111         try {
112             p1.addToken(Factory.newToken());
113         } catch (CapacityException e) {
114         }
115 
116         wkm = new Analyzer(wf);
117         Assert.assertTrue(wkm.isQuasiLive(t1));
118         Assert.assertTrue(wkm.isQuasiLive(t2));
119         Assert.assertTrue(wkm.isQuasiLive(t));
120 
121         Assert.assertTrue(wkm.isQuasiLive(begin));
122         Assert.assertTrue(wkm.isQuasiLive(p1));
123         Assert.assertTrue(wkm.isQuasiLive(p2));
124         Assert.assertTrue(wkm.isQuasiLive(end));
125 
126         //wkm.net.show();
127         Assert.assertFalse(wkm.isFinallyMarked(end));
128 
129 
130         try {
131             p2.addToken(Factory.newToken());
132         } catch (CapacityException e) {
133         }
134         wkm = new Analyzer(wf);
135         /*
136         wkm.kmTree1.show();
137         Assert.assertTrue(wkm.isFinallyMarked(end));
138         */
139         Analyzer a = new Analyzer(wf, Net.FINITE_STATE_MACHINE);
140         a.showAnalysis();
141 
142 
143 
144 
145     }
146 }