View Javadoc

1   /**
2    * Copyright 2005-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * Tests that an attribute implementing WorkflowAttributeXmlValidator interface can be validated from the 
31   * client application, including and especially edl.
32   * 
33   * An attribute that doesn't implement the interface should record no errors when validated.
34   * 
35   * @author Kuali Rice Team (rice.collab@kuali.org)
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  }