1 /**
2 * Copyright 2004-2015 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.pm.positionreportcat;
17
18 import java.util.List;
19
20 import junit.framework.Assert;
21
22 import org.apache.commons.collections.CollectionUtils;
23 import org.joda.time.DateTime;
24 import org.junit.Test;
25 import org.kuali.hr.KPMEWebTestCase;
26 import org.kuali.hr.util.HtmlUnitUtil;
27 import org.kuali.kpme.core.FunctionalTest;
28 import org.kuali.kpme.core.util.TKUtils;
29 import org.kuali.kpme.pm.api.positionreportcat.PositionReportCategoryContract;
30 import org.kuali.kpme.pm.positionreportcat.PositionReportCategoryBo;
31 import org.kuali.kpme.pm.service.base.PmServiceLocator;
32 import org.kuali.kpme.pm.utils.PmTestConstants;
33
34 import com.gargoylesoftware.htmlunit.html.HtmlElement;
35 import com.gargoylesoftware.htmlunit.html.HtmlForm;
36 import com.gargoylesoftware.htmlunit.html.HtmlInput;
37 import com.gargoylesoftware.htmlunit.html.HtmlPage;
38
39 @FunctionalTest
40 public class PositionReportCatMaintTest extends KPMEWebTestCase {
41
42 @Test
43 public void testRequiredFields() throws Exception {
44 /* KPME-3088: converting to krad broke tests, need to fix when KRAD testing is figured out
45 String baseUrl = PmTestConstants.Urls.POSITION_REPORT_CAT_MAINT_NEW_URL;
46
47 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
48 Assert.assertNotNull(page);
49
50 HtmlForm form = page.getFormByName("KualiForm");
51 Assert.assertNotNull("Search form was missing from page.", form);
52
53 HtmlInput input = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
54 Assert.assertNotNull("Could not locate submit button", input);
55
56 HtmlElement element = page.getElementByName("methodToCall.route");
57 page = element.click();
58 Assert.assertTrue("page text does not contain:\n" + "Effective Date (Effective Date) is a required field.",
59 page.asText().contains("Effective Date (Effective Date) is a required field."));
60 Assert.assertTrue("page text does not contain:\n" + "Position Report Category (Position Report Category) is a required field.",
61 page.asText().contains("Position Report Category (Position Report Category) is a required field."));
62 Assert.assertTrue("page text does not contain:\n" + "Position Report Type (Position Report Type) is a required field.",
63 page.asText().contains("Position Report Type (Position Report Type) is a required field."));
64 Assert.assertTrue("page text does not contain:\n" + "Institution (Institution) is a required field.",
65 page.asText().contains("Institution (Institution) is a required field."));
66 Assert.assertTrue("page text does not contain:\n" + "Location (Location) is a required field.",
67 page.asText().contains("Location (Location) is a required field."));
68 }
69
70 @Test
71 public void testAddNew() throws Exception {
72 DateTime effectiveDate = new DateTime(2012, 4, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
73 String prcString = "testPRC";
74 String prtString = "testPRT";
75 List<? extends PositionReportCategoryContract> prcList = PmServiceLocator.getPositionReportCatService().getPositionReportCatList(prcString, prtString, "testInst", "TS", effectiveDate.toLocalDate());
76 Assert.assertTrue("There should NOT be Position Report Category with name " + prcString, CollectionUtils.isEmpty(prcList));
77
78 String baseUrl = PmTestConstants.Urls.POSITION_REPORT_CAT_MAINT_NEW_URL;
79 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
80 Assert.assertNotNull(page);
81
82 HtmlForm form = page.getFormByName("KualiForm");
83 Assert.assertNotNull("Search form was missing from page.", form);
84
85 HtmlUnitUtil.setFieldValue(page, "document.documentHeader.documentDescription", "Position Report Category - test");
86 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.effectiveDate", "04/01/2012");
87 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.positionReportCat", prcString);
88 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.positionReportType", "noType"); // non-existing positionReportType
89 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.institution", "nonExistInst"); //nonexisting institution
90 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.location", "nonCam"); //nonexisting location
91
92 HtmlInput input = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
93 Assert.assertNotNull("Could not locate submit button", input);
94 HtmlElement element = page.getElementByName("methodToCall.route");
95 page = element.click();
96 HtmlUnitUtil.createTempFile(page);
97 Assert.assertTrue("page text contains:\n" + "The specified Instituion 'nonExistInst' does not exist.",
98 page.asText().contains("The specified Instituion 'nonExistInst' does not exist."));
99 Assert.assertTrue("page text contains:\n" + "The specified Location 'nonCam' does not exist.",
100 page.asText().contains("The specified Location 'nonCam' does not exist."));
101 Assert.assertTrue("page text contains:\n" + "The specified PositionReportType 'noType' does not exist.",
102 page.asText().contains("The specified PositionReportType 'noType' does not exist."));
103
104 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.positionReportType", prtString); // postionReportType and location do not match
105 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.location", "NN"); // existing, non-matching location
106 element = page.getElementByName("methodToCall.route");
107 page = element.click();
108 Assert.assertFalse("page text contains:\n" + "The specified Location 'NN' does not exist.",
109 page.asText().contains("The specified Locaiton 'NN' does not exist."));
110 Assert.assertTrue("page text contains:\n" + "Institution 'nonExistInst' is inconsistent with institution 'testInst' of PositionReportType 'testPRT'",
111 page.asText().contains("Institution 'nonExistInst' is inconsistent with institution 'testInst' of PositionReportType 'testPRT'"));
112
113 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.institution", "II"); // existing, non-matching institution
114 element = page.getElementByName("methodToCall.route");
115 page = element.click();
116 Assert.assertTrue("page text contains:\n" + "Institution 'II' is inconsistent with institution 'testInst' of PositionReportType 'testPRT'",
117 page.asText().contains("Institution 'II' is inconsistent with institution 'testInst' of PositionReportType 'testPRT'"));
118 Assert.assertFalse("page text contains:\n" + "The specified Instituion 'II' does not exist.",
119 page.asText().contains("The specified Instituion 'II' does not exist."));
120
121 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.institution", "testInst"); // matching institution
122 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.location", "BL"); // matching location
123 element = page.getElementByName("methodToCall.route");
124 page = element.click();
125 Assert.assertFalse("page text contains error", page.asText().contains("error"));
126
127 prcList = PmServiceLocator.getPositionReportCatService().getPositionReportCatList(prcString, prtString, "testInst", "BL", effectiveDate.toLocalDate());
128 Assert.assertTrue("There should be Position Report Category with name " + prcString, CollectionUtils.isNotEmpty(prcList));
129 */
130 }
131 }