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