1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.pm.positionreportgroup;
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.positionreportgroup.PositionReportGroup;
30 import org.kuali.kpme.pm.service.base.PmServiceLocator;
31 import org.kuali.kpme.pm.utils.PmTestConstants;
32
33 import com.gargoylesoftware.htmlunit.html.HtmlElement;
34 import com.gargoylesoftware.htmlunit.html.HtmlForm;
35 import com.gargoylesoftware.htmlunit.html.HtmlInput;
36 import com.gargoylesoftware.htmlunit.html.HtmlPage;
37
38 @FunctionalTest
39 public class PositionReportGroupMaintTest extends KPMEWebTestCase {
40
41 @Test
42 public void testRequiredFields() throws Exception {
43 String baseUrl = PmTestConstants.Urls.POSITION_REPORT_GROUP_MAINT_NEW_URL;
44 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
45 Assert.assertNotNull(page);
46
47 HtmlForm form = page.getFormByName("KualiForm");
48 Assert.assertNotNull("Search form was missing from page.", form);
49
50 HtmlInput input = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
51 Assert.assertNotNull("Could not locate submit button", input);
52
53 HtmlElement element = page.getElementByName("methodToCall.route");
54 page = element.click();
55 Assert.assertTrue("page text does not contain:\n" + "Effective Date (Effective Date) is a required field.",
56 page.asText().contains("Effective Date (Effective Date) is a required field."));
57 Assert.assertTrue("page text does not contain:\n" + "Position Report Group (Position Report Group) is a required field.",
58 page.asText().contains("Position Report Group (Position Report Group) is a required field."));
59 Assert.assertTrue("page text does not contain:\n" + "Institution (Institution) is a required field.",
60 page.asText().contains("Institution (Institution) is a required field."));
61 Assert.assertTrue("page text does not contain:\n" + "Location (Location) is a required field.",
62 page.asText().contains("Location (Location) is a required field."));
63 }
64
65 @Test
66 public void testAddNew() throws Exception {
67 DateTime effectiveDate = new DateTime(2012, 4, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
68 String prgString = "testPRG";
69 List<PositionReportGroup> prgList = PmServiceLocator.getPositionReportGroupService().getPositionReportGroupList(prgString, "testInst", "TS", effectiveDate.toLocalDate());
70 Assert.assertTrue("There should NOT be Position Report Group with name " + prgString, CollectionUtils.isEmpty(prgList));
71
72 String baseUrl = PmTestConstants.Urls.POSITION_REPORT_GROUP_MAINT_NEW_URL;
73 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
74 Assert.assertNotNull(page);
75
76 HtmlForm form = page.getFormByName("KualiForm");
77 Assert.assertNotNull("Search form was missing from page.", form);
78
79 HtmlUnitUtil.setFieldValue(page, "document.documentHeader.documentDescription", "Position Report Group - test");
80 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.effectiveDate", "04/01/2012");
81 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.positionReportGroup", prgString);
82 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.institution", "nonExistInst");
83 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.location", "nonCam");
84
85 HtmlInput input = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
86 Assert.assertNotNull("Could not locate submit button", input);
87 HtmlElement element = page.getElementByName("methodToCall.route");
88 page = element.click();
89 HtmlUnitUtil.createTempFile(page);
90 Assert.assertTrue("page text contains:\n" + "The specified Instituion 'nonExistInst' does not exist.",
91 page.asText().contains("The specified Instituion 'nonExistInst' does not exist."));
92 Assert.assertTrue("page text contains:\n" + "The specified Location 'nonCam' does not exist.",
93 page.asText().contains("The specified Location 'nonCam' does not exist."));
94
95 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.institution", "testInst");
96 element = page.getElementByName("methodToCall.route");
97 page = element.click();
98 Assert.assertFalse("page text contains:\n" + "The specified Instituion 'testInst' does not exist.",
99 page.asText().contains("The specified Instituion 'testInst' does not exist."));
100
101 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.location", "BL");
102 element = page.getElementByName("methodToCall.route");
103 page = element.click();
104 Assert.assertFalse("page text contains error", page.asText().contains("error"));
105
106 prgList = PmServiceLocator.getPositionReportGroupService().getPositionReportGroupList(prgString, "testInst", "BL", effectiveDate.toLocalDate());
107 Assert.assertTrue("There should be Position Report Group with name " + prgString, CollectionUtils.isNotEmpty(prgList));
108
109 }
110 }