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.kew.api.KewApiServiceLocator;
20  import org.kuali.rice.kew.api.WorkflowRuntimeException;
21  import org.kuali.rice.kew.api.document.attribute.WorkflowAttributeDefinition;
22  import org.kuali.rice.kew.api.document.attribute.WorkflowAttributeValidationError;
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<WorkflowAttributeValidationError> validationErrors = KewApiServiceLocator.getWorkflowDocumentActionsService().validateWorkflowAttributeDefinition(
48                  attDef);
49  		assertTrue("Validation errors should not be empty", !validationErrors.isEmpty());
50  		assertEquals("Should be 2 validation errors", 2, validationErrors.size());
51  		boolean foundKey1 = false;
52  		boolean foundKey2 = false;
53  		for (org.kuali.rice.kew.api.document.attribute.WorkflowAttributeValidationError error : validationErrors) {
54  			if (error.getKey().equals("key1")) {
55  				assertEquals("key1 key should have message of value1", "value1", error.getMessage());
56  				foundKey1 = true;
57  			} else if (error.getKey().equals("key2")) {
58  				assertEquals("key2 key should have message of value2", "value2", error.getMessage());
59  				foundKey2 = true;
60  			}
61  		}
62  		
63  		assertTrue("should have found a key1 error", foundKey1);
64  		assertTrue("should have found a key2 error", foundKey2);
65  	}
66  	
67  	@Test public void testClientApplicationValidationNoImplementsWorkflowAttributeXmlValidator() throws Exception {
68  		WorkflowAttributeDefinition attDef = WorkflowAttributeDefinition.Builder.create("TestRuleAttributeDuex").build();
69  		List<WorkflowAttributeValidationError> validationErrors = KewApiServiceLocator.getWorkflowDocumentActionsService().validateWorkflowAttributeDefinition(
70                  attDef);
71  		assertTrue("Validation errors should be empty because WorkflowAttributeXmlValidator interface is not implemented", validationErrors.isEmpty());
72  	}
73  	
74  	@Test public void testThrowWorkflowExceptionNoneExistentAttribute() throws Exception {
75          WorkflowAttributeDefinition attDef = WorkflowAttributeDefinition.Builder.create("FakeyMcAttribute").build();
76  		try {
77              KewApiServiceLocator.getWorkflowDocumentActionsService().validateWorkflowAttributeDefinition(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  }