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.time.earngroup.service;
017    
018    import java.sql.Date;
019    
020    import org.apache.commons.lang.StringUtils;
021    import org.junit.Assert;
022    import org.junit.Test;
023    import org.kuali.hr.test.KPMETestCase;
024    import org.kuali.hr.time.earncodegroup.EarnCodeGroup;
025    import org.kuali.hr.time.service.base.TkServiceLocator;
026    import org.kuali.hr.time.test.HtmlUnitUtil;
027    import org.kuali.hr.time.test.TkTestConstants;
028    
029    import com.gargoylesoftware.htmlunit.html.HtmlPage;
030    
031    public class EarnCodeGroupServiceTest extends KPMETestCase{
032            @Test
033            public void testEarnGroupFetch() throws Exception{
034                    EarnCodeGroup earnGroup = TkServiceLocator.getEarnCodeGroupService().getEarnCodeGroup("REG", new Date(System.currentTimeMillis()));
035                    Assert.assertTrue("Test Earn Group fetch failed", earnGroup!=null && StringUtils.equals("REG", earnGroup.getEarnCodeGroup()));
036                    Assert.assertTrue("Test earn group def fetch failed", earnGroup.getEarnCodeGroups()!=null && earnGroup.getEarnCodeGroups().get(0).getHrEarnCodeGroupId().equals("100"));
037            }
038            
039            @Test
040            public void testEarnGroupMaintenancePage() throws Exception{                            
041                    HtmlPage earnCodeLookUp = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.Urls.EARN_CODE_GROUP_MAINT_URL);
042                    earnCodeLookUp = HtmlUnitUtil.clickInputContainingText(earnCodeLookUp, "search");
043                    HtmlUnitUtil.createTempFile(earnCodeLookUp);
044                    Assert.assertTrue("Page contains REG entry", earnCodeLookUp.asText().contains("REG"));  
045                    
046                    EarnCodeGroup earnGroup = TkServiceLocator.getEarnCodeGroupService().getEarnCodeGroup("REG", new Date(System.currentTimeMillis()));
047                    String earnGroupId = earnGroup.getHrEarnCodeGroupId().toString();
048                    HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(earnCodeLookUp, "edit", earnGroupId);               
049                    HtmlUnitUtil.createTempFile(maintPage);
050                    Assert.assertTrue("Maintenance Page contains REG entry",maintPage.asText().contains("REG"));            
051            }       
052    }