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.actions;
18  
19  import org.junit.Test;
20  import org.kuali.rice.kew.dto.NetworkIdDTO;
21  import org.kuali.rice.kew.exception.WorkflowException;
22  import org.kuali.rice.kew.service.KEWServiceLocator;
23  import org.kuali.rice.kew.service.WorkflowDocument;
24  import org.kuali.rice.kew.test.KEWTestCase;
25  
26  
27  public class CreateDocumentTest extends KEWTestCase {
28      
29      @Override
30      protected void loadTestData() throws Exception {
31          loadXmlFile("ActionsConfig.xml");
32      }
33  
34      /**
35  	 * Tests the attempt to create a document from a non-existent document type.
36  	 */
37  	@Test public void testCreateNonExistentDocumentType() throws Exception {
38  		WorkflowDocument document = new WorkflowDocument(getPrincipalIdForName("ewestfal"), "flim-flam-flooey");
39  		try {
40  			document.getRouteHeaderId();
41  			fail("A workflow exception should have been thrown.");
42  		} catch (WorkflowException e) {
43  			e.printStackTrace();
44  		}
45  	}
46  	
47  	/**
48  	 * Tests the attempt to create a document from a document type with no routing path.
49  	 */
50  	@Test public void testCreateNonRoutableDocumentType() throws Exception {
51  		// the BlanketApproveTest is a parent document type that has no routing path defined.  Attempts to
52  		// create documents of this type should return an error
53  		WorkflowDocument document = new WorkflowDocument(getPrincipalIdForName("ewestfal"), "BlanketApproveTest");
54  		try {
55  			document.getRouteHeaderId();
56  			fail("A workflow exception should have been thrown.");
57  		} catch (IllegalArgumentException e) {
58  			e.printStackTrace();
59  		}
60  	}
61      
62      /**
63       * Tests the attempt to create a document from a document type with no routing path.
64       */
65      @Test public void testCreateInactiveDocumentType() throws Exception {
66          // the CreatedDocumentInactive document type is inactive and should not be able to 
67          // be initiated for a new document
68          WorkflowDocument document = new WorkflowDocument(getPrincipalIdForName("ewestfal"), "CreatedDocumentInactive");
69          try {
70              document.getRouteHeaderId();
71              fail("A workflow exception should have been thrown.");
72          } catch (WorkflowException e) {
73              e.printStackTrace();
74          }
75      }
76      
77      protected String getPrincipalIdForName(String principalName) {
78          return KEWServiceLocator.getIdentityHelperService()
79                  .getIdForPrincipalName(principalName);
80      }
81  }