View Javadoc

1   /**
2    * Copyright 2004-2012 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.time.earncode.service;
17  
18  import java.sql.Date;
19  import java.util.List;
20  import java.util.Map;
21  
22  import org.apache.log4j.Logger;
23  import org.junit.Assert;
24  import org.junit.Before;
25  import org.junit.Test;
26  import org.kuali.hr.test.KPMETestCase;
27  import org.kuali.hr.time.assignment.Assignment;
28  import org.kuali.hr.time.earncode.EarnCode;
29  import org.kuali.hr.time.service.base.TkServiceLocator;
30  import org.kuali.hr.time.test.HtmlUnitUtil;
31  import org.kuali.hr.time.test.TkTestConstants;
32  import org.kuali.hr.time.util.TKUtils;
33  
34  import com.gargoylesoftware.htmlunit.html.HtmlInput;
35  import com.gargoylesoftware.htmlunit.html.HtmlPage;
36  import com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput;
37  import com.gargoylesoftware.htmlunit.html.HtmlSelect;
38  import org.kuali.rice.kim.api.identity.principal.Principal;
39  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
40  
41  public class EarnCodeServiceImplTest extends KPMETestCase {
42  
43  
44  	public static final String TEST_USER = "admin";
45  	public static final Long TEST_ASSIGNMENT_JOB_NUMBER = 1L;
46  	public static final Long TEST_ASSIGNMENT_JOB_NUMBER_2 = 2L;
47  	public static final Long TEST_ASSIGNMENT_JOB_NUMBER_3 = 3L;
48  	public static final Long TEST_ASSIGNMENT_JOB_NUMBER_4 = 4L;
49  
50  	@SuppressWarnings("unused")
51  	private static final Logger LOG = Logger.getLogger(EarnCodeServiceImplTest.class);
52  
53  	EarnCodeService earnCodeService = null;
54  
55  
56  	@Before
57  	public void setUp() throws Exception {
58  		super.setUp();
59  		earnCodeService=TkServiceLocator.getEarnCodeService();
60  	}
61  
62  	@Test
63  	public void getEarnCodes() throws Exception {
64          Date asOfDate = TKUtils.getTimelessDate(null);
65  		List<Assignment> assignments = TkServiceLocator.getAssignmentService().getAssignments(TEST_USER, asOfDate);
66  		Assert.assertNotNull(assignments);
67  		Assert.assertTrue("Emtpy assignment list", !assignments.isEmpty());
68  
69  		Assignment assignment1 = null;
70  		Assignment assignment2 = null;
71  		Assignment assignment3 = null;
72  		Assignment assignment4 = null;
73  		for (Assignment a : assignments) {
74  			if (a.getJobNumber().equals(TEST_ASSIGNMENT_JOB_NUMBER)) {
75  				assignment1 = a;
76  			} else if (a.getJobNumber().equals(TEST_ASSIGNMENT_JOB_NUMBER_2)) {
77  				assignment2 = a;
78  			} else if (a.getJobNumber().equals(TEST_ASSIGNMENT_JOB_NUMBER_3)) {
79  				assignment3 = a;
80  			} else if (a.getJobNumber().equals(TEST_ASSIGNMENT_JOB_NUMBER_4)) {
81  				assignment4 = a;
82  			}
83  		}
84  
85  		// one for each test scenario involving wildcards at least...
86  		Assert.assertNotNull("Test assignment not found.", assignment1);
87  		Assert.assertNotNull("Test assignment not found.", assignment2);
88  		Assert.assertNotNull("Test assignment not found.", assignment3);
89  		Assert.assertNotNull("Test assignment not found.", assignment4);
90  
91          // Testing standard lookup.
92  		List<EarnCode> earnCodes = earnCodeService.getEarnCodes(assignment1, asOfDate);
93  		Assert.assertEquals("Wrong number of earn codes returned.", 8, earnCodes.size());
94  
95  		// Wildcard on SalGroup
96  		earnCodes = earnCodeService.getEarnCodes(assignment2, asOfDate);
97  		Assert.assertEquals("Wrong number of earn codes returned.", 3, earnCodes.size());
98  
99  		// Dual Wildcards
100 		earnCodes = earnCodeService.getEarnCodes(assignment3, asOfDate);
101 		Assert.assertEquals("Wrong number of earn codes returned.",2, earnCodes.size());
102 	}
103 
104 	@Test
105 	public void testEarnCodeMaintenancePage() throws Exception{
106 
107 		HtmlPage earnCodeLookUp = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.Urls.EARN_CODE_MAINT_URL);
108 		earnCodeLookUp = HtmlUnitUtil.clickInputContainingText(earnCodeLookUp, "search");
109 		Assert.assertTrue("Page contains SDR entry", earnCodeLookUp.asText().contains("SDR"));
110 		HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(earnCodeLookUp, "edit","1");
111 
112 		//Sai - confirm that the error is throw by not selecting a record type
113 		HtmlSelect inputText= maintPage.getHtmlElementById("document.newMaintainableObject.recordMethod");
114 		inputText.setDefaultValue("H");
115 
116 		HtmlInput inputForDescription = HtmlUnitUtil.getInputContainingText(
117 				maintPage, "* Document Description");
118 		inputForDescription.setValueAttribute("Description");
119 //		setFieldValue(maintPage, "document.newMaintainableObject.fractionalTimeAllowed", "99");
120 //		setFieldValue(maintPage, "document.newMaintainableObject.roundingOption", "T");
121 
122 		HtmlPage resultantPageAfterEdit = HtmlUnitUtil
123 				.clickInputContainingText(maintPage, "submit");
124 		System.out.println(resultantPageAfterEdit.asText());
125 
126 //		assertTrue("Error message for not selecting any record type",
127 //				resultantPageAfterEdit.asText().contains("For this earn code you must specify Record Hours or Record Time or Record Amount"));
128 
129 		//Sai - confirm that the error is thrown if more than one record type is selected
130 //		checkBox  = maintPage.getHtmlElementById("document.newMaintainableObject.recordTime");
131 //		checkBox.setChecked(true);
132 //		checkBox  = maintPage.getHtmlElementById("document.newMaintainableObject.recordHours");
133 //		checkBox.setChecked(true);
134 
135 		inputForDescription = HtmlUnitUtil.getInputContainingText(
136 				maintPage, "* Document Description");
137 		inputForDescription.setValueAttribute("Description");
138 		resultantPageAfterEdit = HtmlUnitUtil
139 				.clickInputContainingText(maintPage, "submit");
140 //		assertTrue("Error message for selecting more than one record type",
141 //				resultantPageAfterEdit.asText().contains("For this earn code you can only specify one of the Record types"));
142 	}
143 
144 }