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.position;
017    
018    import org.junit.Assert;
019    import org.junit.Test;
020    import org.kuali.hr.test.KPMETestCase;
021    import org.kuali.hr.time.test.HtmlUnitUtil;
022    import org.kuali.hr.time.test.TkTestConstants;
023    
024    import com.gargoylesoftware.htmlunit.html.HtmlInput;
025    import com.gargoylesoftware.htmlunit.html.HtmlPage;
026    
027    public class PositionTest extends KPMETestCase {
028    
029            public static final String TEST_USER = "admin";
030            
031            
032            @Test
033            public void testPositionMaintWorkAreaSave() throws Exception {
034    
035                    HtmlPage positionLookup = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.POSITION_MAINT_URL);
036                    HtmlPage resultPage = HtmlUnitUtil.clickInputContainingText(positionLookup, "search");
037                    
038                    //look up a work area
039                    HtmlPage positionMaintPage = HtmlUnitUtil.clickAnchorContainingText(resultPage, "edit", "2085");
040                    HtmlUnitUtil.createTempFile(positionMaintPage);
041                    Assert.assertTrue("Maintenance page contains:\n" + "Work area for Position 2085 is 1003", positionMaintPage.asText().contains("1003"));
042                    
043                    //submit a changed work area
044                    setFieldValue(positionMaintPage, "document.documentHeader.documentDescription", "Position workArea - test");
045                    HtmlInput workAreaText = HtmlUnitUtil.getInputContainingText(positionMaintPage, "id=\"document.newMaintainableObject.workArea\"");
046                    workAreaText.setValueAttribute("30");
047                    HtmlPage outputPage = HtmlUnitUtil.clickInputContainingText(positionMaintPage, "submit");
048                    HtmlUnitUtil.createTempFile(outputPage);
049                    Assert.assertTrue("Maintenance page text contains:\n" + "Document was successfully submitted", outputPage.asText().contains("Document was successfully submitted"));
050                    Assert.assertTrue("Maintenance page contains:\n" + "Work area changed to 30", outputPage.asText().contains("30"));
051                    
052                    //look up the changed work area
053                    HtmlPage fetchedPositionMaintPage = HtmlUnitUtil.clickAnchorContainingText(resultPage, "edit", "2085");
054                    HtmlUnitUtil.createTempFile(fetchedPositionMaintPage);
055                    Assert.assertTrue("Fetched maintenance page now contains:\n" + "Work area for Position 2085 is 30", fetchedPositionMaintPage.asText().contains("30"));
056            }
057            
058            @Test
059            public void testPositionMaintWorkAreaInquiry() throws Exception {
060                    
061                    HtmlPage positionLookup = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.POSITION_MAINT_URL);
062                    HtmlPage resultPage = HtmlUnitUtil.clickInputContainingText(positionLookup, "search");
063    
064                    //test the work area inquiry from the position page note that this returns the first work area in tk_work_area_t in all cases for now -- see KPME-1219
065                    HtmlPage workAreaInquiryPage = HtmlUnitUtil.clickAnchorContainingText(resultPage, "workarea", "1000");
066                    HtmlUnitUtil.createTempFile(workAreaInquiryPage);
067                    Assert.assertTrue("Inquiry page text contains:\n" + "Work Area Inquiry", workAreaInquiryPage.asText().contains("Work Area Inquiry"));
068                    //first work area in tk-test -- see comment above for this test
069                    Assert.assertTrue("Inquiry page text contains:\n" + "First work area in tk-test", workAreaInquiryPage.asText().contains("1000"));
070                    
071            }
072            
073    }