View Javadoc

1   /*
2    * Copyright 2005-2007 The Kuali Foundation
3    * 
4    * 
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    * 
9    * http://www.opensource.org/licenses/ecl2.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 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   * Tests that an attribute implementing WorkflowAttributeXmlValidator interface can be validated from the 
32   * client application, including and especially edl.
33   * 
34   * An attribute that doesn't implement the interface should record no errors when validated.
35   * 
36   * @author Kuali Rice Team (rice.collab@kuali.org)
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  }