View Javadoc

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