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.core.institution;
017    
018    import static org.junit.Assert.assertNotNull;
019    import static org.junit.Assert.assertTrue;
020    
021    import java.util.HashMap;
022    import java.util.Map;
023    import java.util.Map.Entry;
024    
025    import org.junit.Test;
026    import org.kuali.hr.KPMEWebTestCase;
027    import org.kuali.hr.util.HtmlUnitUtil;
028    import org.kuali.kpme.core.util.HrTestConstants;
029    
030    import com.gargoylesoftware.htmlunit.html.HtmlInput;
031    import com.gargoylesoftware.htmlunit.html.HtmlPage;
032    
033    public class InstitutionMaintenanceTest extends KPMEWebTestCase {
034    
035            private static String newUrl;
036            private static String lookupUrl;
037            private static Map<String,String> requiredFields;
038    
039            private void before() {
040                    
041                    newUrl = HrTestConstants.Urls.INSTITUTION_MAINT_NEW_URL;
042                    lookupUrl = HrTestConstants.Urls.INSTITUTION_MAINT_URL;
043                    
044                    requiredFields = new HashMap<String,String>();
045                    requiredFields.put("effectiveDate", "Effective Date (Effective Date) is a required field.");
046                    requiredFields.put("institutionCode", "Institution Code (Institution Code) is a required field.");
047            }
048            
049            private void after() {
050                    requiredFields.clear();
051            }
052            
053            @Override
054            public void setUp() throws Exception {
055                    before();
056                    super.setUp();
057            }
058            
059            @Override
060            public void tearDown() throws Exception {
061                    after();
062                    super.tearDown();
063            }
064            
065            @Test
066            public void testRequiredFields() throws Exception {
067                    HtmlPage maintPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), newUrl);
068                    assertNotNull("maintenance page is null", maintPage);
069                    
070                    HtmlInput docDescription = HtmlUnitUtil.getInputContainingText(maintPage, "* Document Description");
071                    assertNotNull("maintenance page does not contain document description", docDescription);
072                    
073                    docDescription.setValueAttribute("testing submission");
074                    
075                    HtmlPage resultPage = HtmlUnitUtil.clickInputContainingText(maintPage, "submit");
076                    assertNotNull("no result page returned after submit", resultPage);
077                    
078                    String resultPageAsText = resultPage.asText();
079                    for(Entry<String,String> requiredField : requiredFields.entrySet()) {
080                            assertTrue("page does not contain error message for required field: '" + requiredField.getKey() + "'",
081                                            resultPageAsText.contains(requiredField.getValue()));
082                    }
083            }
084            
085            @Test
086            public void testLookup() throws Exception {
087                    HtmlPage lookupPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), lookupUrl);
088                    assertNotNull("lookup page is null", lookupPage);
089                    
090                    lookupPage = HtmlUnitUtil.clickInputContainingText(lookupPage, "search");
091                    assertNotNull("lookup result page is null", lookupPage);
092                    
093            }
094            
095    }