1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.pm.positionreportsubcat;
17
18 import junit.framework.Assert;
19
20 import org.junit.Test;
21 import org.kuali.hr.KPMEWebTestCase;
22 import org.kuali.hr.util.HtmlUnitUtil;
23 import org.kuali.kpme.core.FunctionalTest;
24 import org.kuali.kpme.pm.positionreportsubcat.PositionReportSubCategory;
25 import org.kuali.kpme.pm.service.base.PmServiceLocator;
26 import org.kuali.kpme.pm.utils.PmTestConstants;
27
28 import com.gargoylesoftware.htmlunit.html.HtmlElement;
29 import com.gargoylesoftware.htmlunit.html.HtmlForm;
30 import com.gargoylesoftware.htmlunit.html.HtmlInput;
31 import com.gargoylesoftware.htmlunit.html.HtmlPage;
32
33 @FunctionalTest
34 public class PositionReportSubCatMaintTest extends KPMEWebTestCase {
35 @Test
36 public void testRequiredFields() throws Exception {
37 String baseUrl = PmTestConstants.Urls.POSITION_REPORT_SUB_CAT_MAINT_NEW_URL;
38 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
39 Assert.assertNotNull(page);
40
41 HtmlForm form = page.getFormByName("KualiForm");
42 Assert.assertNotNull("Search form was missing from page.", form);
43
44 HtmlInput input = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
45 Assert.assertNotNull("Could not locate submit button", input);
46
47 HtmlElement element = page.getElementByName("methodToCall.route");
48 page = element.click();
49 Assert.assertTrue("page text does not contain:\n" + "Effective Date (Effective Date) is a required field.",
50 page.asText().contains("Effective Date (Effective Date) is a required field."));
51 Assert.assertTrue("page text does not contain:\n" + "Position Report Sub Category (Position Report Sub Category) is a required field.",
52 page.asText().contains("Position Report Sub Category (Position Report Sub Category) is a required field."));
53 Assert.assertTrue("page text does not contain:\n" + "Position Report Category (Position Report Category) is a required field.",
54 page.asText().contains("Position Report Category (Position Report Category) is a required field."));
55 Assert.assertTrue("page text does not contain:\n" + "Position Report Type (Position Report Type) is a required field.",
56 page.asText().contains("Position Report Type (Position Report Type) is a required field."));
57 Assert.assertTrue("page text does not contain:\n" + "Institution (Institution) is a required field.",
58 page.asText().contains("Institution (Institution) is a required field."));
59 Assert.assertTrue("page text does not contain:\n" + "Location (Location) is a required field.",
60 page.asText().contains("Location (Location) is a required field."));
61 }
62
63 @Test
64 public void testAddNew() throws Exception {
65 String prscString = "testPRSC";
66 PositionReportSubCategory prsc = PmServiceLocator.getPositionReportSubCatService().getPositionReportSubCatById("1000");
67 Assert.assertTrue("There should NOT be Position Report Sub Category with name " + prscString, prsc == null);
68
69 String baseUrl = PmTestConstants.Urls.POSITION_REPORT_SUB_CAT_MAINT_NEW_URL;
70 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
71 Assert.assertNotNull(page);
72
73 HtmlForm form = page.getFormByName("KualiForm");
74 Assert.assertNotNull("Search form was missing from page.", form);
75
76 HtmlUnitUtil.setFieldValue(page, "document.documentHeader.documentDescription", "Position Report Category - test");
77 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.effectiveDate", "04/01/2012");
78 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.positionReportSubCat", prscString);
79
80
81 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.institution", "nonExistInst");
82 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.location", "nonCam");
83
84 HtmlInput input = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
85 Assert.assertNotNull("Could not locate submit button", input);
86 HtmlElement element = page.getElementByName("methodToCall.route");
87 page = element.click();
88 HtmlUnitUtil.createTempFile(page);
89 Assert.assertTrue("page text contains:\n" + "The specified Instituion 'nonExistInst' does not exist.",
90 page.asText().contains("The specified Instituion 'nonExistInst' does not exist."));
91 Assert.assertTrue("page text contains:\n" + "The specified Location 'nonCam' does not exist.",
92 page.asText().contains("The specified Location 'nonCam' does not exist."));
93
94 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.institution", "testInst");
95 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.location", "BL");
96 element = page.getElementByName("methodToCall.route");
97 page = element.click();
98 Assert.assertFalse("page text should NOT contain:\n" + "The specified Instituion 'nonExistInst' does not exist.",
99 page.asText().contains("The specified Instituion 'nonExistInst' does not exist."));
100 Assert.assertFalse("page text should NOT contain:\n" + "The specified Location 'nonCam' does not exist.",
101 page.asText().contains("The specified Location 'nonCam' does not exist."));
102
103 }
104 }