View Javadoc
1   /**
2    * Copyright 2005-2014 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.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   * 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<? 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  }