View Javadoc
1   /**
2    * Copyright 2004-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.hr.lm.leaveCalendar;
17  
18  import org.apache.log4j.Logger;
19  import org.joda.time.DateTime;
20  import org.junit.Assert;
21  import org.kuali.hr.KPMEWebTestCase;
22  import org.kuali.hr.TestAutoLoginFilter;
23  import org.kuali.hr.util.HtmlUnitUtil;
24  import org.kuali.kpme.core.util.TKUtils;
25  import org.kuali.kpme.tklm.utils.TkTestConstants;
26  import org.kuali.rice.kim.api.identity.Person;
27  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
28  
29  import com.gargoylesoftware.htmlunit.html.HtmlPage;
30  
31  public abstract class LeaveCalendarWebTestBase extends KPMEWebTestCase {
32      private static final Logger LOG = Logger.getLogger(LeaveCalendarWebTestBase.class);
33      public static final DateTime JAN_AS_OF_DATE = new DateTime(2010, 1, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
34      public static final String USER_PRINCIPAL_ID = "admin";
35  
36      private String baseDetailURL = ""; // moved to setUp() method -- initialization order for TkTestConstants problem.
37  
38      @Override
39      public void setUp() throws Exception {
40          super.setUp();
41          setBaseDetailURL(TkTestConstants.Urls.LEAVE_CALENDAR_URL + "?documentId=");
42      }
43  
44      @Override
45      public void tearDown() throws Exception {
46          super.tearDown();
47          //KPMELoginFilter.TEST_ID = "admin";
48          TestAutoLoginFilter.OVERRIDE_ID = "";
49      }
50  
51      public String getLeaveCalendarUrl(String tdocId) {
52          return getBaseDetailURL() + tdocId;
53      }
54  
55      /**
56       * Uses an ID hack to manipulate the current Test user Login.
57       *
58       */
59      public synchronized HtmlPage loginAndGetLeaveCalendarHtmlPage(String principalId, String tdocId, boolean assertValid) throws Exception {
60  
61          Person person = KimApiServiceLocator.getPersonService().getPerson(principalId);
62          Assert.assertNotNull(person);
63          Assert.assertEquals(person.getPrincipalId(), principalId);
64          TestAutoLoginFilter.OVERRIDE_ID = principalId;
65          HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), getLeaveCalendarUrl(tdocId));
66          TestAutoLoginFilter.OVERRIDE_ID = "";
67          Assert.assertNotNull(page);
68          HtmlUnitUtil.createTempFile(page, "Login-"+principalId);
69          LOG.debug(page.asText());
70          String pageAsText = page.asText();
71          if (assertValid) {
72              Assert.assertTrue("Login info not present.", pageAsText.contains("Employee Id:"));
73              Assert.assertTrue("Login info not present for " + person.getName() , pageAsText.contains(person.getName()));
74              Assert.assertTrue("Wrong Document Loaded.", pageAsText.contains(tdocId));
75          }
76  
77          return page;
78      }
79  
80      /**
81       * Uses an ID hack to manipulate the current Test user Login.
82       *
83       */
84      public synchronized HtmlPage login(String principalId, String tdocId, boolean assertValid) throws Exception {
85  
86          Person person = KimApiServiceLocator.getPersonService().getPerson(principalId);
87          Assert.assertNotNull(person);
88          Assert.assertEquals(person.getPrincipalId(), principalId);
89          TestAutoLoginFilter.OVERRIDE_ID = principalId;
90          HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), getLeaveCalendarUrl(tdocId));
91          TestAutoLoginFilter.OVERRIDE_ID = "";
92          Assert.assertNotNull(page);
93  
94          return page;
95      }
96      
97      public String getBaseDetailURL() {
98          return baseDetailURL;
99      }
100 
101     public void setBaseDetailURL(String baseDetailURL) {
102         this.baseDetailURL = baseDetailURL;
103     }
104 }