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.krad.service;
17  
18  import org.junit.Test;
19  import org.kuali.rice.kew.api.WorkflowDocument;
20  import org.kuali.rice.krad.UserSession;
21  import org.kuali.rice.krad.test.document.AccountRequestDocument;
22  import org.kuali.rice.krad.util.GlobalVariables;
23  import org.kuali.rice.krad.util.MessageMap;
24  import org.kuali.rice.krad.test.KRADTestCase;
25  
26  import static org.junit.Assert.assertEquals;
27  
28  /**
29   * This class tests the DocumentService (currently only getNewDocument is tested).
30   *
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   *
33   */
34  public class DocumentServiceTest extends KRADTestCase {
35  
36      public DocumentServiceTest() {
37      }
38  
39      @Override
40      public void setUp() throws Exception {
41          super.setUp();
42          GlobalVariables.setMessageMap(new MessageMap());
43          GlobalVariables.setUserSession(new UserSession("quickstart"));
44      }
45  
46      @Override
47      public void tearDown() throws Exception {
48          GlobalVariables.setMessageMap(new MessageMap());
49          GlobalVariables.setUserSession(null);
50          super.tearDown();
51      }
52  
53      /**
54       * This method tests getNewDocument
55       *
56       * @throws Exception
57       */
58      @Test public void testGetNewDocument() throws Exception {
59          AccountRequestDocument travelDocument = (AccountRequestDocument) KRADServiceLocatorWeb.getDocumentService().getNewDocument("AccountRequest");
60          WorkflowDocument wd =  travelDocument.getDocumentHeader().getWorkflowDocument();
61  
62          assertEquals("Initiator should be the current user", wd.getInitiatorPrincipalId(), GlobalVariables.getUserSession().getPerson().getPrincipalId());
63      }
64  
65      /**
66       * This method tests getNewDocument but the initiator is not the current user
67       *
68       * @throws Exception
69       */
70      @Test public void testGetNewDocumentDifferentInitiatorThanCurrentUser() throws Exception {
71          AccountRequestDocument travelDocument = (AccountRequestDocument) KRADServiceLocatorWeb.getDocumentService().getNewDocument("AccountRequest", "testuser1");
72          WorkflowDocument wd =  travelDocument.getDocumentHeader().getWorkflowDocument();
73  
74          assertEquals("Initiator should be testuser1", wd.getInitiatorPrincipalId(), "testuser1");
75      }
76  
77      /**
78       * This method tests getNewDocument but the initiator is invalid
79       *
80       * @throws Exception
81       */
82      @Test public void testGetNewDocumentInvalidInitiator() throws Exception {
83          AccountRequestDocument travelDocument = (AccountRequestDocument) KRADServiceLocatorWeb.getDocumentService().getNewDocument("AccountRequest", "notValidUserAtAll");
84          WorkflowDocument wd =  travelDocument.getDocumentHeader().getWorkflowDocument();
85  
86          assertEquals("Initiator should be the current user", wd.getInitiatorPrincipalId(), GlobalVariables.getUserSession().getPerson().getPrincipalId());
87      }
88  }