01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: TestTaskoption.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.scheduler;
09:
10: import com.uwyn.rife.scheduler.Taskoption;
11: import com.uwyn.rife.site.ValidationError;
12: import com.uwyn.rife.tools.ExceptionUtils;
13: import java.util.Iterator;
14: import junit.framework.TestCase;
15:
16: public class TestTaskoption extends TestCase {
17: public TestTaskoption(String name) {
18: super (name);
19: }
20:
21: public void testInstantiateTaskoption() {
22: Taskoption taskoption = null;
23: assertNull(taskoption);
24: taskoption = new Taskoption();
25: assertNotNull(taskoption);
26: }
27:
28: public void testPopulateTaskoption() {
29: int taskid = 1;
30: String name = "name";
31: String value = "value";
32:
33: Taskoption taskoption = new Taskoption();
34: taskoption.setTaskId(taskid);
35: taskoption.setName(name);
36: taskoption.setValue(value);
37:
38: assertEquals(taskid, taskoption.getTaskId());
39: assertEquals(name, taskoption.getName());
40: assertEquals(value, taskoption.getValue());
41: }
42:
43: public void testCloneTaskoption() {
44: try {
45: int taskid = 1;
46: String name = "name";
47: String value = "value";
48:
49: Taskoption taskoption = new Taskoption();
50: taskoption.setTaskId(taskid);
51: taskoption.setName(name);
52: taskoption.setValue(value);
53:
54: Taskoption taskoption_clone = taskoption.clone();
55: assertTrue(taskoption != taskoption_clone);
56: assertNotNull(taskoption_clone);
57: assertTrue(taskoption.equals(taskoption_clone));
58: } catch (CloneNotSupportedException e) {
59: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
60: }
61: }
62:
63: public void testTaskoptionValidation() {
64: Taskoption taskoption = new Taskoption();
65: assertTrue(false == taskoption.validate());
66: assertTrue(3 == taskoption.countValidationErrors());
67: ValidationError error = null;
68: Iterator<ValidationError> it = taskoption.getValidationErrors()
69: .iterator();
70: error = it.next();
71: assertEquals(error.getIdentifier(), "INVALID");
72: assertEquals(error.getSubject(), "taskId");
73: error = it.next();
74: assertEquals(error.getIdentifier(), "MANDATORY");
75: assertEquals(error.getSubject(), "name");
76: error = it.next();
77: assertEquals(error.getIdentifier(), "MANDATORY");
78: assertEquals(error.getSubject(), "value");
79: }
80: }
|