001 /**
002 * Copyright 2004-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.hr.lm.leaveCalendar;
017
018 import org.apache.log4j.Logger;
019 import org.joda.time.DateTime;
020 import org.junit.Assert;
021 import org.kuali.hr.KPMEWebTestCase;
022 import org.kuali.hr.TestAutoLoginFilter;
023 import org.kuali.hr.util.HtmlUnitUtil;
024 import org.kuali.kpme.core.util.TKUtils;
025 import org.kuali.kpme.tklm.utils.TkTestConstants;
026 import org.kuali.rice.kim.api.identity.Person;
027 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
028
029 import com.gargoylesoftware.htmlunit.html.HtmlPage;
030
031 public abstract class LeaveCalendarWebTestBase extends KPMEWebTestCase {
032 private static final Logger LOG = Logger.getLogger(LeaveCalendarWebTestBase.class);
033 public static final DateTime JAN_AS_OF_DATE = new DateTime(2010, 1, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
034 public static final String USER_PRINCIPAL_ID = "admin";
035
036 private String baseDetailURL = ""; // moved to setUp() method -- initialization order for TkTestConstants problem.
037
038 @Override
039 public void setUp() throws Exception {
040 super.setUp();
041 setBaseDetailURL(TkTestConstants.Urls.LEAVE_CALENDAR_URL + "?documentId=");
042 }
043
044 @Override
045 public void tearDown() throws Exception {
046 super.tearDown();
047 //KPMELoginFilter.TEST_ID = "admin";
048 TestAutoLoginFilter.OVERRIDE_ID = "";
049 }
050
051 public String getLeaveCalendarUrl(String tdocId) {
052 return getBaseDetailURL() + tdocId;
053 }
054
055 /**
056 * Uses an ID hack to manipulate the current Test user Login.
057 *
058 */
059 public synchronized HtmlPage loginAndGetLeaveCalendarHtmlPage(String principalId, String tdocId, boolean assertValid) throws Exception {
060
061 Person person = KimApiServiceLocator.getPersonService().getPerson(principalId);
062 Assert.assertNotNull(person);
063 Assert.assertEquals(person.getPrincipalId(), principalId);
064 TestAutoLoginFilter.OVERRIDE_ID = principalId;
065 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), getLeaveCalendarUrl(tdocId));
066 TestAutoLoginFilter.OVERRIDE_ID = "";
067 Assert.assertNotNull(page);
068 HtmlUnitUtil.createTempFile(page, "Login-"+principalId);
069 LOG.debug(page.asText());
070 String pageAsText = page.asText();
071 if (assertValid) {
072 Assert.assertTrue("Login info not present.", pageAsText.contains("Employee Id:"));
073 Assert.assertTrue("Login info not present for " + person.getName() , pageAsText.contains(person.getName()));
074 Assert.assertTrue("Wrong Document Loaded.", pageAsText.contains(tdocId));
075 }
076
077 return page;
078 }
079
080 /**
081 * Uses an ID hack to manipulate the current Test user Login.
082 *
083 */
084 public synchronized HtmlPage login(String principalId, String tdocId, boolean assertValid) throws Exception {
085
086 Person person = KimApiServiceLocator.getPersonService().getPerson(principalId);
087 Assert.assertNotNull(person);
088 Assert.assertEquals(person.getPrincipalId(), principalId);
089 TestAutoLoginFilter.OVERRIDE_ID = principalId;
090 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), getLeaveCalendarUrl(tdocId));
091 TestAutoLoginFilter.OVERRIDE_ID = "";
092 Assert.assertNotNull(page);
093
094 return page;
095 }
096
097 public String getBaseDetailURL() {
098 return baseDetailURL;
099 }
100
101 public void setBaseDetailURL(String baseDetailURL) {
102 this.baseDetailURL = baseDetailURL;
103 }
104 }