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.Conflict;
8   import net.kwfgrid.gworkflowdl.analysis.Decision;
9   import net.kwfgrid.gworkflowdl.structure.*;
10  
11  /***
12   * Created by IntelliJ IDEA.
13   * User: hans
14   * Date: 10.10.2005
15   * Time: 15:15:07
16   * To change this template use File | Settings | File Templates.
17   */
18  public class ConflictTest extends AbstractTestCase {
19  
20      /***
21       * Create the test case.
22       *
23       * @param testName name of the test case
24       */
25      public ConflictTest(String testName) {
26          super(testName);
27      }
28  
29      /***
30       * @return the suite of tests being tested
31       */
32      public static Test suite() {
33          return new TestSuite(ConflictTest.class);
34      }
35  
36  
37      /***
38       * Rigourous Test :-).
39       */
40      public void testApp() {
41  
42          Place pIn = Factory.newPlace();
43          pIn.setID("p1");
44          try {
45              pIn.addToken(Factory.newToken());
46          } catch (CapacityException e) {
47          }
48          Edge e1 = Factory.newEdge();
49          e1.setPlace(pIn);
50          Edge e2 = Factory.newEdge();
51          e2.setPlace(pIn);
52          Transition t1 = Factory.newTransition();
53          Edge[] e1s = {e1};
54          t1.setInEdges(e1s);
55          Transition t2 = Factory.newTransition();
56          Edge[] e2s = {e1};
57          t2.setInEdges(e2s);
58  
59          Assert.assertTrue(Conflict.inConflict(t1, t2));
60  
61          try {
62              pIn.addToken(Factory.newToken());
63          } catch (CapacityException e) {
64          }
65  
66          Assert.assertFalse(Conflict.inConflict(t1, t2));
67  
68          Place pOut = Factory.newPlace();
69          pOut.setID("p2");
70  
71          Edge e3 = Factory.newEdge();
72          e3.setPlace(pOut);
73          Edge e4 = Factory.newEdge();
74          e4.setPlace(pOut);
75          Edge[] e3s = {e3};
76          t1.setOutEdges(e3s);
77          Edge[] e4s = {e4};
78          t2.setOutEdges(e4s);
79  
80          Assert.assertFalse(Conflict.inConflict(t1, t2));
81  
82          try {
83              pOut.setCapacity(1);
84          } catch (CapacityException e) {
85          }
86  
87          Assert.assertTrue(Conflict.inConflict(t1, t2));
88  
89          Place p = Factory.newPlace();
90          p.setID("p");
91          PlaceTest.addToken(p);
92  
93          Place q = Factory.newPlace();
94          q.setID("q");
95          PlaceTest.addToken(q);
96  
97          Transition a = Factory.newTransition();
98          a.setID("a");
99          TransitionTest.addInPlace(a, p);
100 
101         Transition b = Factory.newTransition();
102         b.setID("b");
103         TransitionTest.addInPlace(b, p);
104 
105         Transition c = Factory.newTransition();
106         c.setID("c");
107         TransitionTest.addInPlace(c, p);
108         TransitionTest.addInPlace(c, q);
109 
110         Transition d = Factory.newTransition();
111         d.setID("d");
112         TransitionTest.addInPlace(d, q);
113 
114         Workflow wf = Factory.newWorkflow();
115         wf.addPlace(p);
116         wf.addPlace(q);
117         wf.addTransition(a);
118         wf.addTransition(b);
119         wf.addTransition(c);
120         wf.addTransition(d);
121 
122         /*
123         */
124         Decision[] ds = Conflict.getDecisions(wf);
125         for (int i = 0; i < ds.length; i++) {
126             System.out.println("Hallo " + ds[i].toString());
127         }
128         /*
129         */
130 
131 
132         //Assert.assertEquals(ds.length, 2);
133         //Assert.assertEquals(ds[0].toString(), "take p\n  a\n  b\n  c");
134         //Assert.assertEquals(ds[1].toString(), "take q\n  c\n  d");
135 
136         Analyzer wfa = new Analyzer(wf);
137         Decision[] dss = wfa.getDecisions();
138         System.out.println(Decision.toString(dss));
139 
140         //Workflow wf1 = wf.deepCopy();
141 
142         Place r = Factory.newPlace();
143         r.setID("r");
144         //PlaceTest.addToken(r);
145         wf.addPlace(r);
146         try {
147             r.setCapacity(4);
148         } catch (CapacityException e) {
149         }
150         TransitionTest.addOutPlace(b, r);
151         TransitionTest.addOutPlace(c, r);
152 
153         TransitionTest.addOutPlace(a, p);
154         TransitionTest.addOutPlace(b, p);
155 
156         wfa = new Analyzer(wf);
157         dss = wfa.getDecisions();
158         System.out.println(Decision.toString(dss));
159         //wfa.kmTree1.show();
160 
161          ds = Conflict.getDecisions(wf);
162         for (int i = 0; i < ds.length; i++) {
163             System.out.println(ds[i].toString());
164         }
165 
166     }
167 }