1
2
3
4
5
6
7
8
9
10
11 package org.astrogrid.applications.javaclass;
12
13 import org.astrogrid.applications.Application;
14 import org.astrogrid.applications.MockMonitor;
15 import org.astrogrid.applications.beans.v1.cea.castor.ResultListType;
16 import org.astrogrid.applications.beans.v1.parameters.ParameterValue;
17 import org.astrogrid.applications.manager.AppAuthorityIDResolver;
18 import org.astrogrid.applications.description.ApplicationDescription;
19 import org.astrogrid.applications.description.ApplicationDescriptionLibrary;
20 import org.astrogrid.applications.description.ApplicationInterface;
21 import org.astrogrid.applications.description.base.ApplicationDescriptionEnvironment;
22 import org.astrogrid.applications.description.base.TestAuthorityResolver;
23 import org.astrogrid.applications.javaclass.BaseJavaClassConfiguration;
24 import org.astrogrid.applications.manager.idgen.IdGen;
25 import org.astrogrid.applications.manager.idgen.InMemoryIdGen;
26 import org.astrogrid.applications.parameter.protocol.DefaultProtocolLibrary;
27 import org.astrogrid.applications.parameter.protocol.ProtocolLibrary;
28 import org.astrogrid.community.User;
29 import org.astrogrid.workflow.beans.v1.Input;
30 import org.astrogrid.workflow.beans.v1.Output;
31 import org.astrogrid.workflow.beans.v1.Tool;
32
33 import junit.framework.TestCase;
34
35 /*** Test of the JavaClass backend to CEa
36 * @author Noel Winstanley nw@jb.man.ac.uk 08-Jun-2004
37 *
38 */
39 public class JavaClassProviderTest extends TestCase {
40 /***
41 * Constructor for JavaClassCEATest.
42 * @param arg0
43 */
44 public JavaClassProviderTest(String arg0) {
45 super(arg0);
46 }
47
48
49
50 protected void setUp() throws Exception {
51 super.setUp();
52 IdGen idgen = new InMemoryIdGen();
53 ProtocolLibrary protocolLib = new DefaultProtocolLibrary();
54 monitor = new MockMonitor();
55 AppAuthorityIDResolver aresolver = new TestAuthorityResolver();
56 ApplicationDescriptionEnvironment env = new ApplicationDescriptionEnvironment(idgen,protocolLib,aresolver);
57 lib = new JavaClassApplicationDescriptionLibrary(new BaseJavaClassConfiguration(), env);
58 assertNotNull(lib);
59 }
60 protected ApplicationDescriptionLibrary lib;
61 protected MockMonitor monitor;
62
63 protected final User user = new User();
64 public void testLibrary() throws Exception {
65 String[] names = lib.getApplicationNames();
66 assertNotNull(names);
67 assertEquals(4,names.length);
68 }
69
70 public void testHelloWorld() throws Exception {
71 ApplicationDescription hw = lib.getDescription("org.astrogrid.test/helloWorld");
72 assertNotNull(hw);
73 assertEquals("org.astrogrid.test/helloWorld",hw.getName());
74 ApplicationInterface iface = hw.getInterfaces()[0];
75 assertNotNull(iface);
76 Tool tool = new Tool();
77 Output output = new Output();
78 tool.setOutput(output);
79 ParameterValue result = new ParameterValue();
80 result.setName(iface.getArrayofOutputs()[0]);
81 output.addParameter(result);
82 Application app = hw.initializeApplication("testrun",user,tool);
83 assertNotNull(app);
84 app.addObserver(monitor);
85 app.createExecutionTask().run();
86 assertTrue(monitor.sawExit);
87 ResultListType results= app.getResult();
88 assertNotNull(results);
89 assertEquals(1,results.getResultCount());
90 String o = results.getResult(0).getValue();
91 assertNotNull(o);
92 System.out.println(o);
93 }
94 public void testSum() throws Exception {
95 ApplicationDescription hw = lib.getDescription("org.astrogrid.test/sum");
96 assertNotNull(hw);
97 ApplicationInterface iface = hw.getInterfaces()[0];
98 String[] inputParameterNames = iface.getArrayofInputs();
99 assertNotNull(iface);
100 Tool tool = new Tool();
101 Input input = new Input();
102 tool.setInput(input);
103 Output output = new Output();
104 tool.setOutput(output);
105 ParameterValue a = new ParameterValue();
106 ParameterValue b = new ParameterValue();
107 a.setName(inputParameterNames[0]);
108 b.setName(inputParameterNames[1]);
109 a.setValue("1");
110 b.setValue("2");
111 input.addParameter(a);
112 input.addParameter(b);
113 ParameterValue result = new ParameterValue();
114 result.setName(iface.getArrayofOutputs()[0]);
115 output.addParameter(result);
116 Application app = hw.initializeApplication("testrun",user,tool);
117 assertNotNull(app);
118 app.addObserver(monitor);
119
120 app.createExecutionTask().run();
121 assertTrue(monitor.sawExit);
122 ResultListType results= app.getResult();
123 assertNotNull(results);
124 assertEquals(1,results.getResultCount());
125 String o = results.getResult(0).getValue();
126 assertNotNull(o);
127 System.out.println(o);
128 assertEquals("3",o);
129 }
130
131
132 public void testEchoDifferentArgs() throws Exception {
133 ApplicationDescription hw = lib.getDescription("org.astrogrid.test/echoDifferentArgs");
134 assertNotNull(hw);
135 ApplicationInterface iface = hw.getInterfaces()[0];
136 String[] inputParameterNames = iface.getArrayofInputs();
137 assertNotNull(iface);
138 Tool tool = new Tool();
139 Input input = new Input();
140 tool.setInput(input);
141 Output output = new Output();
142 tool.setOutput(output);
143 ParameterValue a = new ParameterValue();
144 ParameterValue b = new ParameterValue();
145 a.setName(inputParameterNames[0]);
146 b.setName(inputParameterNames[1]);
147 a.setValue("Hello");
148 b.setValue("2");
149 input.addParameter(a);
150 input.addParameter(b);
151 ParameterValue result = new ParameterValue();
152 result.setName(iface.getArrayofOutputs()[0]);
153 output.addParameter(result);
154 Application app = hw.initializeApplication("testrun",user,tool);
155 assertNotNull(app);
156 app.addObserver(monitor);
157
158 app.createExecutionTask().run();
159 assertTrue(monitor.sawExit);
160 ResultListType results= app.getResult();
161 assertNotNull(results);
162 assertEquals(1,results.getResultCount());
163 String o = results.getResult(0).getValue();
164 assertNotNull(o);
165 System.out.println(o);
166 assertEquals("Hello2",o);
167 }
168
169 }
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223