1 package net.kwfgrid.gworkflowdl;
2
3 import net.kwfgrid.gworkflowdl.analysis.SmartCopy;
4 import net.kwfgrid.gworkflowdl.analysis.ComplexityReducer;
5 import net.kwfgrid.gworkflowdl.structure.*;
6 import junit.framework.Test;
7 import junit.framework.TestSuite;
8
9 import java.util.ArrayList;
10
11 public final class Hong_Linh_Test extends AbstractTestCase {
12 /***
13 * Create the test case.
14 *
15 * @param testName name of the test case
16 */
17 public Hong_Linh_Test(String testName) {
18 super(testName);
19 }
20
21 /***
22 * @return the suite of tests being tested
23 */
24 public static Test suite() {
25 return new TestSuite(Hong_Linh_Test.class);
26 }
27
28
29 /***
30 * Rigourous Test :-).
31 */
32 public void testApp() {
33 Place a0 = PlaceTest.exampleWithDataTokens("a0", 1);
34 Place b0 = PlaceTest.exampleWithDataTokens("b0", 1);
35 Place p1 = PlaceTest.exampleWithDataTokens("p1", 0);
36 Place p2 = PlaceTest.exampleWithDataTokens("p2", 0);
37 Place p3 = PlaceTest.exampleWithDataTokens("p3", 0);
38 Place p4 = PlaceTest.exampleWithDataTokens("p4", 0);
39 Place a5 = PlaceTest.exampleWithDataTokens("a5", 0);
40 Place b5 = PlaceTest.exampleWithDataTokens("b5", 0);
41 Place r0 = PlaceTest.exampleWithDataTokens("r0", 0);
42 Place w0 = PlaceTest.exampleWithDataTokens("w0", 0);
43
44 Place[] in0 = {a0, b0};
45 Place[] out0 = {p1};
46 Place[] read0 = {r0};
47 Place[] write0 = {w0};
48 Transition t0 = TransitionTest.example("", "t0", read0, in0, write0, out0);
49
50 Place[] in1 = {p1};
51 Place[] out1 = {p2};
52 Transition t1 = TransitionTest.example("", "t1", read0, in1, write0, out1);
53
54 Place[] in2 = {p2};
55 Place[] out2 = {p3};
56 Transition t2 = TransitionTest.example("", "t2", read0, in2, write0, out2);
57
58 Place[] in3 = {p3};
59 Place[] out3 = {p4};
60 Transition t3 = TransitionTest.example("", "t3", read0, in3, write0, out3);
61
62 Place[] in4 = {p4};
63 Place[] out4 = {a5, b5};
64 Transition t4 = TransitionTest.example("", "t4", read0, in4, write0, out4);
65
66
67 Workflow wf = Factory.newWorkflow();
68
69 wf.addPlace(a0);
70 wf.addPlace(b0);
71 wf.addPlace(p1);
72 wf.addPlace(p2);
73 wf.addPlace(p3);
74 wf.addPlace(p4);
75 wf.addPlace(a5);
76 wf.addPlace(b5);
77 wf.addPlace(r0);
78 wf.addPlace(w0);
79
80 wf.addTransition(t0);
81 wf.addTransition(t1);
82 wf.addTransition(t2);
83 wf.addTransition(t3);
84 wf.addTransition(t4);
85
86 Workflow swf = SmartCopy.copy(wf);
87
88 String wfs = "";
89 try {
90 wfs = JdomString.workflow2string(swf);
91 } catch (Exception e) {
92 System.out.println(e);
93 }
94 System.out.println("before reduce");
95 System.out.println(wfs);
96
97 ComplexityReducer reducer = new ComplexityReducer(swf);
98 reducer.reduce();
99
100
101 try {
102 wfs = JdomString.workflow2string(swf);
103 } catch (Exception e) {
104 System.out.println(e);
105 }
106
107 System.out.println("after reduce");
108 System.out.println(wfs);
109
110
111 ArrayList queue = new ArrayList();
112 queue.add("p2");
113 String s = "p2";
114 while (s != null) {
115 s = (String) reducer.rememberPlaces.get(s);
116 if (s != null) {
117 queue.add(s);
118 }
119 }
120 s = "p2";
121 while (s != null) {
122 s = (String) reducer.rememberPlacesBack.get(s);
123 if (s != null) {
124 queue.add(0,s);
125 }
126 }
127
128 System.out.println("place queue of p2");
129
130 for (int i = 0; i < queue.size(); i++) {
131 System.out.println(queue.get(i));
132 }
133 }
134 }