01: /*
02: * Copyright 2005-2007 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.php
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package edu.iu.uis.eden.routetemplate;
18:
19: import org.junit.Test;
20: import org.kuali.workflow.test.WorkflowTestCase;
21:
22: import edu.iu.uis.eden.clientapp.WorkflowInfo;
23: import edu.iu.uis.eden.clientapp.vo.WorkflowAttributeDefinitionVO;
24: import edu.iu.uis.eden.clientapp.vo.WorkflowAttributeValidationErrorVO;
25: import edu.iu.uis.eden.exception.WorkflowException;
26:
27: /**
28: * Tests that an attribute implementing WorkflowAttributeXmlValidator interface can be validated from the
29: * client application, including and especially edl.
30: *
31: * An attribute that doesn't implement the interface should record no errors when validated.
32: *
33: * @author rkirkend
34: *
35: */
36: public class AttributeClientRoutingDataValidationTest extends
37: WorkflowTestCase {
38:
39: protected void loadTestData() throws Exception {
40: loadXmlFile("AttributeClientRoutingDataValidationTest.xml");
41: }
42:
43: @Test
44: public void testClientApplicationValidationImplementsWorkflowAttributeXmlValidator()
45: throws Exception {
46: WorkflowAttributeDefinitionVO attDef = new WorkflowAttributeDefinitionVO(
47: TestRuleAttributeThree.class.getName());
48: WorkflowAttributeValidationErrorVO[] validationErrors = new WorkflowInfo()
49: .validAttributeDefinition(attDef);
50: assertTrue("Validation errors should not be empty",
51: validationErrors.length != 0);
52: assertEquals("Should be 2 validation errors", 2,
53: validationErrors.length);
54: boolean foundKey1 = false;
55: boolean foundKey2 = false;
56: for (int i = 0; i < validationErrors.length; i++) {
57: WorkflowAttributeValidationErrorVO error = validationErrors[i];
58: if (error.getKey().equals("key1")) {
59: assertEquals("key1 key should have message of value1",
60: "value1", error.getMessage());
61: foundKey1 = true;
62: } else if (error.getKey().equals("key2")) {
63: assertEquals("key2 key should have message of value2",
64: "value2", error.getMessage());
65: foundKey2 = true;
66: }
67: }
68:
69: assertTrue("should have found a key1 error", foundKey1);
70: assertTrue("should have found a key2 error", foundKey2);
71: }
72:
73: @Test
74: public void testClientApplicationValidationNoImplementsWorkflowAttributeXmlValidator()
75: throws Exception {
76: WorkflowAttributeDefinitionVO attDef = new WorkflowAttributeDefinitionVO(
77: TestRuleAttributeDuex.class.getName());
78: WorkflowAttributeValidationErrorVO[] validationErrors = new WorkflowInfo()
79: .validAttributeDefinition(attDef);
80: assertTrue(
81: "Validation errors should be empty because WorkflowAttributeXmlValidator interface is not implemented",
82: validationErrors.length == 0);
83: }
84:
85: @Test
86: public void testThrowWorkflowExceptionNoneExistentAttribute()
87: throws Exception {
88: WorkflowAttributeDefinitionVO attDef = new WorkflowAttributeDefinitionVO(
89: "FakeyMcAttribute");
90: try {
91: new WorkflowInfo().validAttributeDefinition(attDef);
92: fail("Should have thrown WorkflowException attempting to lookup non-existent attribute");
93: } catch (WorkflowException e) {
94: assertTrue("This is the correct exception to throw", true);
95: }
96: }
97: }
|