1   package net.kwfgrid.gworkflowdl;
2   
3   import junit.framework.Assert;
4   import junit.framework.Test;
5   import junit.framework.TestSuite;
6   import net.kwfgrid.gworkflowdl.analysis.Analyzer;
7   import net.kwfgrid.gworkflowdl.analysis.Decision;
8   import net.kwfgrid.gworkflowdl.analysis.Net;
9   import net.kwfgrid.gworkflowdl.analysis.WorkflowAnalyzer;
10  import net.kwfgrid.gworkflowdl.structure.Factory;
11  import net.kwfgrid.gworkflowdl.structure.Place;
12  import net.kwfgrid.gworkflowdl.structure.Transition;
13  import net.kwfgrid.gworkflowdl.structure.Workflow;
14  
15  /***
16   * Created by IntelliJ IDEA.
17   * User: hans
18   * Date: 21.10.2005
19   * Time: 13:40:10
20   * To change this template use File | Settings | File Templates.
21   */
22  public class PutTest extends AbstractTestCase {
23      /***
24       * Create the test case.
25       *
26       * @param testName name of the test case
27       */
28      public PutTest(String testName) {
29          super(testName);
30      }
31  
32      /***
33       * @return the suite of tests being tested
34       */
35      public static Test suite() {
36          return new TestSuite(PutTest.class);
37      }
38  
39  
40      /***
41       * Rigourous Test :-).
42       */
43      public void testApp() {
44          int Num = 4;
45          int tokenNum = 2;
46          Place a = Factory.newPlace();
47          a.setID("a");
48          for (int i = 0; i < tokenNum; i++) {
49              PlaceTest.addToken(a);
50          }
51  
52          Place c = Factory.newPlace();
53          c.setID("c");
54  
55          PlaceTest.setCapacity(c, 1);
56  
57          Place[] b = new Place[Num];
58          Transition[] x = new Transition[Num];
59          Transition[] y = new Transition[Num];
60          for (int i = 0; i < Num; i++) {
61              b[i] = Factory.newPlace();
62              b[i].setID("b" + (i + 1));
63          }
64          for (int i = 0; i < Num; i++) {
65              x[i] = Factory.newTransition();
66              x[i].setID("x" + (i + 1));
67              TransitionTest.addOutPlace(x[i], b[i]);
68              TransitionTest.addInPlace(x[i], a);
69  
70              y[i] = Factory.newTransition();
71              y[i].setID("y" + (i + 1));
72              TransitionTest.addOutPlace(y[i], c);
73              TransitionTest.addInPlace(y[i], b[i]);
74          }
75  
76          Workflow wf = Factory.newWorkflow();
77          wf.addPlace(a);
78          wf.addPlace(c);
79          for (int i = 0; i < Num; i++) {
80              wf.addPlace(b[i]);
81              wf.addTransition(x[i]);
82              wf.addTransition(y[i]);
83          }
84  
85          WorkflowAnalyzer wfa = new WorkflowAnalyzer(wf);
86          //wfa.kmTree1.show();
87          wfa.showAnalysis();
88  
89          Analyzer aa = new Analyzer(wf, Net.FINITE_STATE_MACHINE);
90          aa.showAnalysis();
91          /*
92          ContactFree.makeContactFree(wf);
93          System.out.println("after ContactFree.makeContactFree(workflow)");
94          System.out.println("-------------------------------------------");
95          wfa = new KarpMillerAnalyzer(wf);
96          //wfa.kmTree1.show();
97          wfa.showAnalysis();
98          */
99          Decision[] ds = aa.getDecisions();
100         for (int i = 0; i < ds.length; i++) {
101             String s = ds[i].toString();
102             Decision d = Decision.fromString(wf,s);
103             Assert.assertTrue(ds[i].equals(d));
104         }
105 
106     }
107 
108 }