View Javadoc
1   /**
2    * Copyright 2004-2014 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.kpme.pm.validation;
17  
18  import org.joda.time.DateTime;
19  import org.joda.time.LocalDate;
20  import org.junit.Assert;
21  import org.junit.Test;
22  import org.kuali.kpme.core.IntegrationTest;
23  import org.kuali.kpme.core.util.TKUtils;
24  import org.kuali.kpme.pm.PMIntegrationTestCase;
25  import org.kuali.kpme.pm.util.PmValidationUtils;
26  
27  @IntegrationTest
28  public class PmValidationUtilsTest extends PMIntegrationTestCase {
29  	
30  	private static DateTime INVALID_DATE = new DateTime(2011, 7, 7, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
31  	private static DateTime VALID_DATE = new DateTime(2012, 7, 7, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
32  	
33  	@Test
34  	public void testValidateCampus() {
35  		String campus = "*";	
36  		boolean results = PmValidationUtils.validateCampus(campus);	// wildcard should be true
37  		Assert.assertTrue(results);
38  		
39  		campus = "nonExist";	
40  		results = PmValidationUtils.validateCampus(campus);	// non-existing
41  		Assert.assertFalse(results);
42  		
43  		campus = "TS";	// existing campus
44  		results = PmValidationUtils.validateCampus(campus);
45  		Assert.assertTrue(results);
46  		
47  	}
48  	
49  	@Test
50  	public void testValidatePositionReportType() {
51  		DateTime aDate = INVALID_DATE;
52  		String prt = "nonExist";
53  //		String groupKeyCode = "testGK";
54  		boolean results = PmValidationUtils.validatePositionReportType(prt, aDate.toLocalDate()); // non-existing
55  		Assert.assertFalse(results);
56  		
57  		prt = "testPRT";	
58  		results = PmValidationUtils.validatePositionReportType(prt, aDate.toLocalDate());	// existing, but wrong date
59  		Assert.assertFalse(results);
60  		
61  		aDate = VALID_DATE;
62  		results = PmValidationUtils.validatePositionReportType(prt, aDate.toLocalDate());  // existing, right date
63  		Assert.assertTrue(results);
64  	}
65  
66      @Test
67      public void testValidatePayGradeWithSalaryGroup() {
68          DateTime aDate = INVALID_DATE;
69          String payGrade = "nonExist";
70          String salaryGroup = "*";
71          boolean results = PmValidationUtils.validatePayGradeWithSalaryGroup(salaryGroup, payGrade, aDate.toLocalDate());  //non-existing
72          Assert.assertFalse(results);
73  
74          payGrade = "T";
75          results = PmValidationUtils.validatePayGradeWithSalaryGroup(salaryGroup, payGrade, aDate.toLocalDate()); //existing, Wrong Date
76          Assert.assertFalse(results);
77  
78          aDate = VALID_DATE;
79          salaryGroup = "nonExist";
80          results = PmValidationUtils.validatePayGradeWithSalaryGroup(salaryGroup, payGrade, aDate.toLocalDate());  //existing, wrong salaryGroup
81          Assert.assertFalse(results);
82  
83          salaryGroup = "testSalGrp";
84          results = PmValidationUtils.validatePayGradeWithSalaryGroup(salaryGroup, payGrade, aDate.toLocalDate());
85          Assert.assertTrue(results);
86      }
87  
88  	@Test
89  	public void testValidatePositionReportCategory() {
90  		DateTime aDate = INVALID_DATE;
91  		String prc = "nonExist";
92  		String prt = "nonExist";
93  //		String groupKeyCode = "testGK";
94  		
95  		boolean results = PmValidationUtils.validatePositionReportCategory(prc, prt,  aDate.toLocalDate()); // non-existing
96  		Assert.assertFalse(results);
97  		
98  		prc = "testPRC";	
99  		results = PmValidationUtils.validatePositionReportCategory(prc, prt, aDate.toLocalDate()); 	// existing, but wrong date
100 		Assert.assertFalse(results);
101 		
102 		aDate = VALID_DATE;
103 		results = PmValidationUtils.validatePositionReportCategory(prc, prt, aDate.toLocalDate());   // existing, right date, wrong prt
104 		Assert.assertFalse(results);
105 		
106 		prt = "testPRT";
107 		results = PmValidationUtils.validatePositionReportCategory(prc, prt, aDate.toLocalDate()); 
108 		Assert.assertTrue(results);
109 	}
110 	
111 	@Test
112 	public void testValidatePositionReportSubCat() {
113 		DateTime aDate = INVALID_DATE;
114 		String prsc = "nonExist";
115 //		String groupKeyCode = "*-*";
116 		boolean results = PmValidationUtils.validatePositionReportSubCat(prsc,aDate.toLocalDate()); // non-existing
117 		Assert.assertFalse(results);
118 		
119 		prsc = "testPRSC";	
120 		results = PmValidationUtils.validatePositionReportSubCat(prsc, aDate.toLocalDate()); // existing, but wrong date
121 		Assert.assertFalse(results);
122 		
123 		aDate = VALID_DATE;
124 		results = PmValidationUtils.validatePositionReportSubCat(prsc, aDate.toLocalDate());  
125 		Assert.assertTrue(results);
126 	}
127 	
128 	
129 //	@Test
130 //	public void testValidatePstnRptGrp() {
131 //		DateTime aDate = INVALID_DATE;
132 //		String prg = "nonExist";
133 //		
134 //		boolean results = PmValidationUtils.validatePstnRptGrp(prg, aDate.toLocalDate()); // non-existing
135 //		Assert.assertFalse(results);
136 //		
137 //		prg = "testPRG";	
138 //		results = PmValidationUtils.validatePstnRptGrp(prg, aDate.toLocalDate()); // existing, but wrong date
139 //		Assert.assertFalse(results);
140 //		
141 //		aDate = VALID_DATE;
142 //		results = PmValidationUtils.validatePstnRptGrp(prg, aDate.toLocalDate());   // existing, right date
143 //		Assert.assertTrue(results);
144 //		
145 //		results = PmValidationUtils.validatePstnRptGrp(prg, aDate.toLocalDate()); 
146 //		Assert.assertTrue(results);
147 //	}
148 
149     @Test
150     public void testValidatePositionQualificationValue() {
151         String qValue = "nonExist";
152         boolean results = PmValidationUtils.validatePositionQualificationValue(qValue);  //non-existing
153         Assert.assertFalse(results);
154 
155         qValue = "existing";
156         results = PmValidationUtils.validatePositionQualificationValue(qValue);
157         Assert.assertTrue(results);
158     }
159 
160     @Test
161     public void testValidateAffiliation() {
162        DateTime aDate = INVALID_DATE;
163        String deptAffl = "nonExist";
164        boolean results = PmValidationUtils.validateAffiliation(deptAffl, aDate.toLocalDate()); //non-existing
165        Assert.assertFalse(results);
166 
167        deptAffl = "testType";
168        results = PmValidationUtils.validateAffiliation(deptAffl, aDate.toLocalDate()); //existing, but wrong date
169        Assert.assertFalse(results);
170 
171        results = PmValidationUtils.validateAffiliation(deptAffl, LocalDate.now());
172        Assert.assertTrue(results);
173 
174     }
175 
176     @Test
177     public void testValidatePositionType(){
178         DateTime aDate = INVALID_DATE;
179         String pType = "nonExist";
180         String institution ="*";
181         String campus = "*";
182         boolean results = PmValidationUtils.validatePositionType(pType,aDate.toLocalDate()); //non-existing
183         Assert.assertFalse(results);
184     }
185 
186     @Test
187     public void testValidatePositionAppointmentType() {
188 
189     LocalDate  asOfDate = new LocalDate(2010,1,1);
190 
191     //no wild card test
192     boolean results = PmValidationUtils.validatePositionAppointmentType("noWildCard","UGA-ATHENS",asOfDate);
193     Assert.assertTrue(results);
194 
195     }
196 }