1
/*___INFO__MARK_BEGIN__*/
2
/*************************************************************************
4
* The Contents of this file are made available subject to the terms of
5
* the Sun Industry Standards Source License Version 1.2
7
* Sun Microsystems Inc., March, 2001
10
* Sun Industry Standards Source License Version 1.2
11
* =================================================
12
* The contents of this file are subject to the Sun Industry Standards
13
* Source License Version 1.2 (the "License"); You may not use this file
14
* except in compliance with the License. You may obtain a copy of the
15
* License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
17
* Software provided under this License is provided on an "AS IS" basis,
18
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
19
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
20
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
21
* See the License for the specific provisions governing your rights and
22
* obligations concerning the Software.
24
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
26
* Copyright: 2001 by Sun Microsystems, Inc.
28
* All Rights Reserved.
30
************************************************************************/
31
/*___INFO__MARK_END__*/
33
* SimpleJobTemplateTest.java
36
* Created on November 13, 2004, 5:28 PM
39
package org.ggf.drmaa;
42
import junit.framework.*;
46
* @author dan.templeton@sun.com
48
public class SimpleJobTemplateTest extends TestCase {
49
private SimpleJobTemplate jt = null;
51
public SimpleJobTemplateTest(java.lang.String testName) {
55
public static Test suite() {
56
TestSuite suite = new TestSuite(SimpleJobTemplateTest.class);
60
protected void setUp() {
61
jt = new SimpleJobTemplate();
64
protected void tearDown() {
68
/** Test of g|setRemoteCommand method, of class org.ggf.drmaa.JobTemplate. */
69
public void testRemoteCommand() throws DrmaaException {
70
System.out.println("testRemoteCommand");
72
jt.setRemoteCommand("MyRemoteCommand");
73
assertEquals("MyRemoteCommand", jt.getRemoteCommand());
76
/** Test of g|setArgs method, of class org.ggf.drmaa.JobTemplate. */
77
public void testArgs() throws DrmaaException {
78
System.out.println("testArgs");
80
List args = Arrays.asList(new String[] {"arg1", "arg2", "arg3"});
84
List retArgs = jt.getArgs();
86
assertNotSame(args, retArgs);
88
for (int count = 0; count < Math.min(args.size(), retArgs.size()); count++) {
89
assertEquals(args.get(count), retArgs.get(count));
93
/** Test of g|setJobSubmissionState method, of class org.ggf.drmaa.JobTemplate. */
94
public void testJobSubmissionState() throws DrmaaException {
95
System.out.println("testJobSubmissionState");
97
jt.setJobSubmissionState(jt.HOLD_STATE);
98
assertEquals(jt.HOLD_STATE, jt.getJobSubmissionState());
99
jt.setJobSubmissionState(jt.ACTIVE_STATE);
100
assertEquals(jt.ACTIVE_STATE, jt.getJobSubmissionState());
103
/** Test of g|setJobEnvironment method, of class org.ggf.drmaa.JobTemplate. */
104
public void testJobEnvironment() throws DrmaaException {
105
System.out.println("testJobEnvironment");
107
Map env = new HashMap();
108
env.put("PATH", "/usr/bin");
109
env.put("LD_LIBRARY_PATH", "/usr/lib");
111
jt.setJobEnvironment(env);
113
Map retEnv = jt.getJobEnvironment();
115
assertNotSame(env, retEnv);
116
assertEquals(env, retEnv);
119
/** Test of g|setWorkingDirectory method, of class org.ggf.drmaa.JobTemplate. */
120
public void testWorkingDirectory() throws DrmaaException {
121
System.out.println("testWorkingDirectory");
123
jt.setWorkingDirectory("/home/me");
124
assertEquals("/home/me", jt.getWorkingDirectory());
127
/** Test of g|setJobCategory method, of class org.ggf.drmaa.JobTemplate. */
128
public void testJobCategory() throws DrmaaException {
129
System.out.println("testJobCategory");
131
jt.setJobCategory("mycat");
132
assertEquals("mycat", jt.getJobCategory());
135
/** Test of g|setNativeSpecification method, of class org.ggf.drmaa.JobTemplate. */
136
public void testNativeSpecification() throws DrmaaException {
137
System.out.println("testNativeSpecification");
139
jt.setNativeSpecification("-shell yes");
140
assertEquals("-shell yes", jt.getNativeSpecification());
143
/** Test of g|setEmail method, of class org.ggf.drmaa.JobTemplate. */
144
public void testEmail() throws DrmaaException {
145
System.out.println("testEmail");
147
Set email = new HashSet(Arrays.asList(new String[] {"dant@germany", "admin"}));
151
Set retEmail = jt.getEmail();
153
assertNotSame(email, retEmail);
154
assertEquals(email, retEmail);
157
/** Test of g|setBlockEmail method, of class org.ggf.drmaa.JobTemplate. */
158
public void testBlockEmail() throws DrmaaException {
159
System.out.println("testBlockEmail");
161
jt.setBlockEmail(true);
162
assertTrue(jt.getBlockEmail());
163
jt.setBlockEmail(false);
164
assertFalse(jt.getBlockEmail());
167
/** Test of g|setStartTime method, of class org.ggf.drmaa.JobTemplate. */
168
public void testStartTime() throws DrmaaException {
169
System.out.println("testStartTime");
171
PartialTimestamp pt = new PartialTimestamp();
172
Calendar cal = Calendar.getInstance();
174
pt.set(pt.HOUR_OF_DAY, cal.get(cal.HOUR_OF_DAY) + 1);
175
pt.set(pt.MINUTE, 0);
179
PartialTimestamp retPt = jt.getStartTime();
181
assertNotSame(pt, retPt);
182
assertEquals(pt, retPt);
184
pt.set(pt.HOUR_OF_DAY, cal.get(cal.HOUR_OF_DAY) - 1);
188
retPt = jt.getStartTime();
190
assertNotSame(pt, retPt);
191
assertEquals(pt, retPt);
193
pt.set(pt.CENTURY, 19);
197
fail("Allowed start time in the past");
198
} catch (IllegalArgumentException e) {
203
/** Test of g|setJobName method, of class org.ggf.drmaa.JobTemplate. */
204
public void testJobName() throws DrmaaException {
205
System.out.println("testJobName");
207
jt.setJobName("MyJob");
208
assertEquals("MyJob", jt.getJobName());
211
/** Test of g|setInputPath method, of class org.ggf.drmaa.JobTemplate. */
212
public void testInputPath() throws DrmaaException {
213
System.out.println("testInputPath");
215
jt.setInputPath("/tmp");
216
assertEquals("/tmp", jt.getInputPath());
219
/** Test of g|setOutputPath method, of class org.ggf.drmaa.JobTemplate. */
220
public void testOutputPath() throws DrmaaException {
221
System.out.println("testOutputPath");
223
jt.setOutputPath("/tmp");
224
assertEquals("/tmp", jt.getOutputPath());
227
/** Test of g|setErrorPath method, of class org.ggf.drmaa.JobTemplate. */
228
public void testErrorPath() throws DrmaaException {
229
System.out.println("testErrorPath");
231
jt.setErrorPath("/tmp");
232
assertEquals("/tmp", jt.getErrorPath());
235
/** Test of g|setJoinFiles method, of class org.ggf.drmaa.JobTemplate. */
236
public void testJoinFiles() throws DrmaaException {
237
System.out.println("testJoinFiles");
239
jt.setJoinFiles(true);
240
assertTrue(jt.getJoinFiles());
241
jt.setJoinFiles(false);
242
assertFalse(jt.getJoinFiles());
245
/** Test of setTransferFiles method, of class org.ggf.drmaa.JobTemplate. */
246
public void testTransferFiles() throws DrmaaException {
247
System.out.println("testTransferFiles");
249
FileTransferMode mode = new FileTransferMode(true, false, true);
252
new SimpleJobTemplate().setTransferFiles(mode);
253
fail("Allowed setting of unsupported transferFiles property");
254
} catch (UnsupportedAttributeException e) {
259
new SimpleJobTemplate().getTransferFiles();
260
fail("Allowed getting of unsupported transferFiles property");
261
} catch (UnsupportedAttributeException e) {
266
/** Test of g|setDeadlineTime method, of class org.ggf.drmaa.JobTemplate. */
267
public void testDeadlineTime() throws DrmaaException {
268
System.out.println("testDeadlineTime");
270
PartialTimestamp pt = new PartialTimestamp();
273
new SimpleJobTemplate().setDeadlineTime(pt);
274
fail("Allowed setting of unsupported deadlineTime property");
275
} catch (UnsupportedAttributeException e) {
280
new SimpleJobTemplate().getDeadlineTime();
281
fail("Allowed getting of unsupported deadlineTime property");
282
} catch (UnsupportedAttributeException e) {
287
/** Test of g|setHardWallclockTimeLimit method, of class org.ggf.drmaa.JobTemplate. */
288
public void testHardWallclockTimeLimit() throws DrmaaException {
289
System.out.println("testHardWallclockTimeLimit");
292
new SimpleJobTemplate().setHardWallclockTimeLimit(101L);
293
fail("Allowed setting of unsupported hardWallclockTimeLimit property");
294
} catch (UnsupportedAttributeException e) {
299
new SimpleJobTemplate().getHardWallclockTimeLimit();
300
fail("Allowed getting of unsupported hardWallclockTimeLimit property");
301
} catch (UnsupportedAttributeException e) {
306
/** Test of g|setSoftWallclockTimeLimit method, of class org.ggf.drmaa.JobTemplate. */
307
public void testSoftWallclockTimeLimit() throws DrmaaException {
308
System.out.println("testSoftWallclockTimeLimit");
311
new SimpleJobTemplate().setSoftWallclockTimeLimit(101L);
312
fail("Allowed setting of unsupported softWallclockTimeLimit property");
313
} catch (UnsupportedAttributeException e) {
318
new SimpleJobTemplate().getSoftWallclockTimeLimit();
319
fail("Allowed getting of unsupported softWallclockTimeLimit property");
320
} catch (UnsupportedAttributeException e) {
325
/** Test of g|setHardRunDurationLimit method, of class org.ggf.drmaa.JobTemplate. */
326
public void testHardRunDurationLimit() throws DrmaaException {
327
System.out.println("testHardRunDurationLimit");
330
new SimpleJobTemplate().setHardRunDurationLimit(101L);
331
fail("Allowed setting of unsupported hardRunDurationLimit property");
332
} catch (UnsupportedAttributeException e) {
337
new SimpleJobTemplate().getHardRunDurationLimit();
338
fail("Allowed getting of unsupported hardRunDurationLimit property");
339
} catch (UnsupportedAttributeException e) {
344
/** Test of g|setSoftRunDurationLimit method, of class org.ggf.drmaa.JobTemplate. */
345
public void testSoftRunDurationLimit() throws DrmaaException {
346
System.out.println("testSoftRunDurationLimit");
349
new SimpleJobTemplate().setSoftRunDurationLimit(101L);
350
fail("Allowed setting of unsupported softRunDurationLimit property");
351
} catch (UnsupportedAttributeException e) {
356
new SimpleJobTemplate().getSoftRunDurationLimit();
357
fail("Allowed getting of unsupported softRunDurationLimit property");
358
} catch (UnsupportedAttributeException e) {
363
/** Test of getAttributeNames method, of class org.ggf.drmaa.JobTemplate. */
364
public void testGetAttributeNames() throws DrmaaException {
365
System.out.println("testGetAttributeNames");
367
ArrayList names = new ArrayList(21);
370
names.add("blockEmail");
372
names.add("errorPath");
373
names.add("inputPath");
374
names.add("jobCategory");
375
names.add("jobEnvironment");
376
names.add("jobName");
377
names.add("jobSubmissionState");
378
names.add("joinFiles");
379
names.add("nativeSpecification");
380
names.add("outputPath");
381
names.add("remoteCommand");
382
names.add("startTime");
383
names.add("workingDirectory");
385
List retNames = new LinkedList(jt.getAttributeNames());
387
Collections.sort(names);
388
Collections.sort(retNames);
390
assertEquals(names, retNames);
393
/** Test of getOptionalAttributeNames method, of class org.ggf.drmaa.JobTemplate. */
394
public void testGetOptionalAttributeNames() {
395
System.out.println("testGetOptionalAttributeNames");
397
Set retNames = jt.getOptionalAttributeNames();
399
assertEquals(Collections.EMPTY_SET, retNames);
402
/** Test of toString method, of class org.ggf.drmaa.JobTemplate. */
403
public void testToString() throws DrmaaException {
404
System.out.println("testToString");
406
assertEquals("{blockEmail = false} {jobSubmissionState = ACTIVE_STATE} {joinFiles = false}",
409
jt.setJobCategory("myCategory");
411
assertEquals("{blockEmail = false} {jobCategory = myCategory} {jobSubmissionState = ACTIVE_STATE} {joinFiles = false}",
414
jt.setArgs(Arrays.asList(new String[] {"arg1", "arg2"}));
416
assertEquals("{args = \"arg1\", \"arg2\"} {blockEmail = false} {jobCategory = myCategory} {jobSubmissionState = ACTIVE_STATE} {joinFiles = false}",
419
jt.setJoinFiles(true);
421
assertEquals("{args = \"arg1\", \"arg2\"} {blockEmail = false} {jobCategory = myCategory} {jobSubmissionState = ACTIVE_STATE} {joinFiles = true}",
424
jt.setJobSubmissionState(jt.HOLD_STATE);
426
assertEquals("{args = \"arg1\", \"arg2\"} {blockEmail = false} {jobCategory = myCategory} {jobSubmissionState = HOLD_STATE} {joinFiles = true}",
429
jt.setNativeSpecification("-l arch=sol-sparc64");
431
assertEquals("{args = \"arg1\", \"arg2\"} {blockEmail = false} {jobCategory = myCategory} {jobSubmissionState = HOLD_STATE} {joinFiles = true} {nativeSpecification = \"-l arch=sol-sparc64\"}",
434
Properties env = new Properties();
435
env.setProperty("PATH", "/tmp:/usr/bin");
436
env.setProperty("SHELL", "/usr/bin/csh");
437
jt.setJobEnvironment(env);
439
assertEquals("{args = \"arg1\", \"arg2\"} {blockEmail = false} {jobCategory = myCategory} {jobEnvironment = [\"SHELL\" = \"/usr/bin/csh\"], [\"PATH\" = \"/tmp:/usr/bin\"]} {jobSubmissionState = HOLD_STATE} {joinFiles = true} {nativeSpecification = \"-l arch=sol-sparc64\"}",
442
jt.setStartTime(new PartialTimestamp(19, 10, 49));
444
assertEquals("{args = \"arg1\", \"arg2\"} {blockEmail = false} {jobCategory = myCategory} {jobEnvironment = [\"SHELL\" = \"/usr/bin/csh\"], [\"PATH\" = \"/tmp:/usr/bin\"]} {jobSubmissionState = HOLD_STATE} {joinFiles = true} {nativeSpecification = \"-l arch=sol-sparc64\"} {startTime = \"19:10:49\"}",