1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kew.rule;
18
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertTrue;
21 import static org.junit.Assert.fail;
22
23 import org.junit.Test;
24 import org.kuali.rice.kew.api.WorkflowRuntimeException;
25 import org.kuali.rice.kew.dto.WorkflowAttributeDefinitionDTO;
26 import org.kuali.rice.kew.dto.WorkflowAttributeValidationErrorDTO;
27 import org.kuali.rice.kew.service.WorkflowInfo;
28 import org.kuali.rice.kew.test.KEWTestCase;
29
30
31
32
33
34
35
36
37
38
39 public class AttributeClientRoutingDataValidationTest extends KEWTestCase {
40
41
42 protected void loadTestData() throws Exception {
43 loadXmlFile("AttributeClientRoutingDataValidationTest.xml");
44 }
45
46 @Test public void testClientApplicationValidationImplementsWorkflowAttributeXmlValidator() throws Exception {
47 WorkflowAttributeDefinitionDTO attDef = new WorkflowAttributeDefinitionDTO(TestRuleAttributeThree.class.getName());
48 WorkflowAttributeValidationErrorDTO[] validationErrors = new WorkflowInfo().validAttributeDefinition(attDef);
49 assertTrue("Validation errors should not be empty", validationErrors.length != 0);
50 assertEquals("Should be 2 validation errors", 2, validationErrors.length);
51 boolean foundKey1 = false;
52 boolean foundKey2 = false;
53 for (int i = 0; i < validationErrors.length; i++) {
54 WorkflowAttributeValidationErrorDTO error = validationErrors[i];
55 if (error.getKey().equals("key1")) {
56 assertEquals("key1 key should have message of value1", "value1", error.getMessage());
57 foundKey1 = true;
58 } else if (error.getKey().equals("key2")) {
59 assertEquals("key2 key should have message of value2", "value2", error.getMessage());
60 foundKey2 = true;
61 }
62 }
63
64 assertTrue("should have found a key1 error", foundKey1);
65 assertTrue("should have found a key2 error", foundKey2);
66 }
67
68 @Test public void testClientApplicationValidationNoImplementsWorkflowAttributeXmlValidator() throws Exception {
69 WorkflowAttributeDefinitionDTO attDef = new WorkflowAttributeDefinitionDTO(TestRuleAttributeDuex.class.getName());
70 WorkflowAttributeValidationErrorDTO[] validationErrors = new WorkflowInfo().validAttributeDefinition(attDef);
71 assertTrue("Validation errors should be empty because WorkflowAttributeXmlValidator interface is not implemented", validationErrors.length == 0);
72 }
73
74 @Test public void testThrowWorkflowExceptionNoneExistentAttribute() throws Exception {
75 WorkflowAttributeDefinitionDTO attDef = new WorkflowAttributeDefinitionDTO("FakeyMcAttribute");
76 try {
77 new WorkflowInfo().validAttributeDefinition(attDef);
78 fail("Should have thrown WorkflowException attempting to lookup non-existent attribute");
79 } catch (WorkflowRuntimeException e) {
80 assertTrue("This is the correct exception to throw", true);
81 }
82 }
83 }