1
2
3
4
5
6
7
8
9 package net.kwfgrid.gwes;
10
11 import junit.framework.Assert;
12 import junit.framework.Test;
13 import junit.framework.TestSuite;
14 import net.kwfgrid.gwes.exception.LoggingException;
15 import net.kwfgrid.gwes.exception.OperationMapperException;
16 import net.kwfgrid.gwes.prorater.AbstractProrater;
17 import net.kwfgrid.gwes.prorater.SimpleProrater;
18 import net.kwfgrid.gwes.prorater.RecurrentProrater;
19 import net.kwfgrid.gworkflowdl.structure.*;
20 import org.apache.log4j.Logger;
21
22 import java.util.ArrayList;
23
24
25
26
27
28
29
30 public class ProraterTest extends LocalGWESAbstractTestCase {
31
32
33
34
35 static Logger logger = Logger.getLogger(ResourceMatcherClientTest.class);
36
37
38
39
40
41
42 public ProraterTest(String testName) throws LoggingException {
43 super(testName);
44 }
45
46
47
48
49 public static Test suite() {
50 return new TestSuite(ProraterTest.class);
51 }
52
53 public void testProrater() {
54 AbstractProrater p = new SimpleProrater();
55
56 ArrayList<Transition> tlist = new ArrayList<Transition>();
57 for (int i = 0; i < 5; ++i) {
58 Transition t = net.kwfgrid.gworkflowdl.structure.Factory.newTransition();
59 t.setID("t" + i);
60 Operation op = Factory.newOperation();
61 OperationClass opc = Factory.newOperationClass();
62 OperationCandidate[] ocs = new OperationCandidate[4];
63 for (int j = 0; j < ocs.length; ++j) {
64 ocs[j] = Factory.newOperationCandidate();
65 ocs[j].setResourceName("testpc" + j);
66 }
67 opc.setOperationCandidates(ocs);
68 op.set(opc);
69 t.setOperation(op);
70 tlist.add(t);
71 }
72
73 try {
74 p.processTransitions(null, tlist);
75 } catch (OperationMapperException e) {
76 logger.error("exception:\n" + e, e);
77 Assert.fail("exception: " + e);
78 }
79
80 System.out.println("\nResult:");
81 for (Transition transition : tlist) {
82 System.out.println(transition.getID());
83 OperationCandidate[] cands = ((OperationClass) transition.getOperation().get()).getOperationCandidates();
84 for (OperationCandidate oc : cands) {
85 if (oc.isSelected()) System.out.println(" " + oc.getResourceName());
86 }
87 }
88 }
89
90 public void testRecurrentProrater() {
91 RecurrentProrater p = new RecurrentProrater();
92
93 ArrayList<Transition> tlist = new ArrayList<Transition>();
94 for (int i = 0; i < 5; ++i) {
95 Transition t = net.kwfgrid.gworkflowdl.structure.Factory.newTransition();
96 t.setID("t" + i);
97 Operation op = Factory.newOperation();
98 OperationClass opc = Factory.newOperationClass();
99 OperationCandidate[] ocs = new OperationCandidate[4];
100 for (int j = 0; j < ocs.length; ++j) {
101 ocs[j] = Factory.newOperationCandidate();
102 ocs[j].setResourceName("testpc" + j);
103 }
104 opc.setOperationCandidates(ocs);
105 op.set(opc);
106 t.setOperation(op);
107 tlist.add(t);
108 }
109
110 try {
111 p.processTransitions(null, tlist);
112 } catch (OperationMapperException e) {
113 logger.error("exception:\n" + e, e);
114 Assert.fail("exception: " + e);
115 }
116
117 System.out.println("\nResult:");
118 for (Transition transition : tlist) {
119 System.out.println(transition.getID());
120 OperationCandidate[] cands = ((OperationClass) transition.getOperation().get()).getOperationCandidates();
121 for (OperationCandidate oc : cands) {
122 if (oc.isSelected()) System.out.println(" " + oc.getResourceName());
123 }
124 }
125 }
126
127
128 }