View Javadoc

1   /**
2    * Copyright 2004-2013 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.junit.Assert;
20  import org.junit.Test;
21  import org.kuali.kpme.core.IntegrationTest;
22  import org.kuali.kpme.core.util.TKUtils;
23  import org.kuali.kpme.core.util.ValidationUtils;
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 institution = "*";
54  		String campus = "*";
55  		boolean results = PmValidationUtils.validatePositionReportType(prt, institution, campus, aDate.toLocalDate()); // non-existing
56  		Assert.assertFalse(results);
57  		
58  		prt = "testPRT";	
59  		results = PmValidationUtils.validatePositionReportType(prt, institution, campus, aDate.toLocalDate());	// existing, but wrong date
60  		Assert.assertFalse(results);
61  		
62  		aDate = VALID_DATE;
63  		results = PmValidationUtils.validatePositionReportType(prt, institution, campus, aDate.toLocalDate());  // existing, right date
64  		Assert.assertTrue(results);
65  	}
66  	
67  	@Test
68  	public void testValidateInstitutionWithPRT() {
69  		DateTime aDate = INVALID_DATE;
70  		String prt = "nonExist";
71  		String institution = "testInst";
72  		boolean results = PmValidationUtils.validateInstitutionWithPRT(prt, institution, aDate.toLocalDate()); // non-existing
73  		Assert.assertFalse(results);
74  		
75  		prt = "testPRT";	
76  		results = PmValidationUtils.validateInstitutionWithPRT(prt, institution, aDate.toLocalDate());	// existing, but wrong date
77  		Assert.assertFalse(results);
78  		
79  		aDate = VALID_DATE;
80  		results = PmValidationUtils.validateInstitutionWithPRT(prt, institution, aDate.toLocalDate());  // existing, right date
81  		Assert.assertTrue(results);
82  	}
83  	
84  	@Test
85  	public void testValidateCampusWithPRT() {
86  		DateTime aDate = INVALID_DATE;
87  		String prt = "nonExist";
88  		String campus = "testCamp";
89  		boolean results = PmValidationUtils.validateCampusWithPRT(prt, campus, aDate.toLocalDate());  // non-existing
90  		Assert.assertFalse(results);
91  		
92  		prt = "testPRT";	
93  		results = PmValidationUtils.validateCampusWithPRT(prt, campus, aDate.toLocalDate());	// existing, but wrong date
94  		Assert.assertFalse(results);
95  		
96  		aDate = VALID_DATE;
97  		results = PmValidationUtils.validateCampusWithPRT(prt, campus, aDate.toLocalDate()); // existing, right date, wrong campus
98  		Assert.assertFalse(results);
99  		
100 		campus = "BL";
101 		results = PmValidationUtils.validateCampusWithPRT(prt, campus, aDate.toLocalDate()); 
102 		Assert.assertTrue(results);
103 	}
104 	
105 	@Test
106 	public void testValidatePositionReportCategory() {
107 		DateTime aDate = INVALID_DATE;
108 		String prc = "nonExist";
109 		String prt = "nonExist";
110 		String institution = "*";
111 		String campus = "*";
112 		boolean results = PmValidationUtils.validatePositionReportCategory(prc, prt, institution, campus, aDate.toLocalDate()); // non-existing
113 		Assert.assertFalse(results);
114 		
115 		prc = "testPRC";	
116 		results = PmValidationUtils.validatePositionReportCategory(prc, prt, institution, campus, aDate.toLocalDate()); 	// existing, but wrong date
117 		Assert.assertFalse(results);
118 		
119 		aDate = VALID_DATE;
120 		results = PmValidationUtils.validatePositionReportCategory(prc, prt, institution, campus, aDate.toLocalDate());   // existing, right date, wrong prt
121 		Assert.assertFalse(results);
122 		
123 		prt = "testPRT";
124 		results = PmValidationUtils.validatePositionReportCategory(prc, prt, institution, campus, aDate.toLocalDate()); 
125 		Assert.assertTrue(results);
126 	}
127 	
128 	@Test
129 	public void testValidatePositionReportSubCat() {
130 		DateTime aDate = INVALID_DATE;
131 		String prsc = "nonExist";
132 		String institution = "*";
133 		String campus = "*";
134 		boolean results = PmValidationUtils.validatePositionReportSubCat(prsc, institution, campus, aDate.toLocalDate()); // non-existing
135 		Assert.assertFalse(results);
136 		
137 		prsc = "testPRSC";	
138 		results = PmValidationUtils.validatePositionReportSubCat(prsc, institution, campus, aDate.toLocalDate()); // existing, but wrong date
139 		Assert.assertFalse(results);
140 		
141 		aDate = VALID_DATE;
142 		institution = "nonExist";
143 		results = PmValidationUtils.validatePositionReportSubCat(prsc, institution, campus, aDate.toLocalDate());   // existing, right date, wrong institution
144 		Assert.assertFalse(results);
145 		
146 		institution = "testInst";
147 		campus = "nonExist";
148 		results = PmValidationUtils.validatePositionReportSubCat(prsc, institution, campus, aDate.toLocalDate());   // existing, right date, right institution, wrong campus
149 		Assert.assertFalse(results);
150 		
151 		campus = "BL";
152 		results = PmValidationUtils.validatePositionReportSubCat(prsc, institution, campus, aDate.toLocalDate());  
153 		Assert.assertTrue(results);
154 	}
155 	
156 	
157 	@Test
158 	public void testValidatePstnRptGrp() {
159 		DateTime aDate = INVALID_DATE;
160 		String prg = "nonExist";
161 		String institution = "*";
162 		String campus = "*";
163 		boolean results = PmValidationUtils.validatePstnRptGrp(prg, institution, campus, aDate.toLocalDate()); // non-existing
164 		Assert.assertFalse(results);
165 		
166 		prg = "testPRG";	
167 		results = PmValidationUtils.validatePstnRptGrp(prg, institution, campus, aDate.toLocalDate()); ; // existing, but wrong date
168 		Assert.assertFalse(results);
169 		
170 		aDate = VALID_DATE;
171 		institution = "nonExist";
172 		results = PmValidationUtils.validatePstnRptGrp(prg, institution, campus, aDate.toLocalDate());   // existing, right date, wrong institution
173 		Assert.assertFalse(results);
174 		
175 		institution = "testInst";
176 		campus = "nonExist";
177 		results = PmValidationUtils.validatePstnRptGrp(prg, institution, campus, aDate.toLocalDate());   // existing, right date, right institution, wrong campus
178 		Assert.assertFalse(results);
179 		
180 		campus = "BL";
181 		results = PmValidationUtils.validatePstnRptGrp(prg, institution, campus, aDate.toLocalDate()); 
182 		Assert.assertTrue(results);
183 	}
184 }