1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.ap.service;
17
18
19 import org.apache.commons.lang.mutable.MutableLong;
20 import org.junit.Test;
21 import org.junit.runner.RunWith;
22 import org.kuali.student.ap.academicplan.constants.AcademicPlanServiceConstants;
23 import org.kuali.student.ap.academicplan.dto.LearningPlanInfo;
24 import org.kuali.student.ap.academicplan.dto.PlanItemInfo;
25 import org.kuali.student.ap.academicplan.infc.LearningPlan;
26 import org.kuali.student.ap.framework.config.KsapFrameworkServiceLocator;
27 import org.kuali.student.common.test.util.AttributeTester;
28 import org.kuali.student.common.test.util.IdEntityTester;
29 import org.kuali.student.common.test.util.MetaTester;
30 import org.kuali.student.common.test.util.RichTextTester;
31 import org.kuali.student.r2.common.dto.MetaInfo;
32 import org.kuali.student.r2.common.exceptions.AlreadyExistsException;
33 import org.kuali.student.r2.common.exceptions.DoesNotExistException;
34 import org.kuali.student.r2.common.exceptions.InvalidParameterException;
35 import org.kuali.student.r2.common.exceptions.MissingParameterException;
36 import org.kuali.student.r2.common.exceptions.OperationFailedException;
37 import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
38 import org.kuali.student.r2.common.util.RichTextHelper;
39 import org.kuali.student.r2.lum.util.constants.CluServiceConstants;
40 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
41 import org.springframework.test.context.transaction.TransactionConfiguration;
42 import org.springframework.transaction.annotation.Transactional;
43
44 import java.math.BigDecimal;
45 import java.util.ArrayList;
46 import java.util.Collections;
47 import java.util.HashMap;
48 import java.util.List;
49 import java.util.Map;
50
51 import static org.junit.Assert.assertEquals;
52 import static org.junit.Assert.assertNotNull;
53 import static org.junit.Assert.assertTrue;
54
55
56 @RunWith(SpringJUnit4ClassRunner.class)
57 @TransactionConfiguration(transactionManager = "JtaTxManager", defaultRollback = true)
58 @Transactional
59 public abstract class TestAcademicPlanServiceImplConformanceExtendedCrud extends TestAcademicPlanServiceImplConformanceBaseCrud
60 {
61
62
63
64
65
66
67
68
69
70
71
72
73 public void testCrudLearningPlan_setDTOFieldsForTestCreate(LearningPlanInfo expected)
74 {
75 expected.setStudentId("student1");
76 expected.setTypeKey(AcademicPlanServiceConstants.LEARNING_PLAN_TYPE_PLAN);
77 expected.setStateKey(AcademicPlanServiceConstants.LEARNING_PLAN_ACTIVE_STATE_KEY);
78 expected.setDescr(RichTextHelper.buildRichTextInfo("My Plan", "<span>My Plan</span>"));
79 expected.setName("Test Plan Name");
80 expected.setMeta(new MetaInfo());
81 expected.setShared(false);
82 }
83
84
85
86
87
88
89
90 public void testCrudLearningPlan_testDTOFieldsForTestCreateUpdate(LearningPlanInfo expected, LearningPlanInfo actual)
91 {
92 assertEquals (expected.getStudentId(), actual.getStudentId());
93 assertEquals (expected.getTypeKey(), actual.getTypeKey());
94 assertEquals (expected.getStateKey(), actual.getStateKey());
95 assertEquals (expected.getShared(), actual.getShared());
96 assertEquals (expected.getName(), actual.getName());
97 new RichTextTester().check(expected.getDescr(), actual.getDescr());
98 }
99
100
101
102
103 public void testCrudLearningPlan_setDTOFieldsForTestUpdate(LearningPlanInfo expected)
104 {
105 expected.setShared(false);
106 expected.setDescr(RichTextHelper.buildRichTextInfo("My Plan updated", "<span>My Plan updated</span>"));
107 expected.setName("Test Plan Name updated");
108 }
109
110
111
112
113
114 public void testCrudLearningPlan_testDTOFieldsForTestReadAfterUpdate(LearningPlanInfo expected, LearningPlanInfo actual)
115 {
116 assertEquals (expected.getStudentId(), actual.getStudentId());
117 assertEquals (expected.getId(), actual.getId());
118 assertEquals (expected.getTypeKey(), actual.getTypeKey());
119 assertEquals (expected.getStateKey(), actual.getStateKey());
120 assertEquals (expected.getShared(), actual.getShared());
121 assertEquals (expected.getName(), actual.getName());
122 new RichTextTester().check(expected.getDescr(), actual.getDescr());
123 }
124
125
126
127
128
129 public void testCrudLearningPlan_setDTOFieldsForTestReadAfterUpdate(LearningPlanInfo expected)
130 {
131 expected.setShared(true);
132 expected.setDescr(RichTextHelper.buildRichTextInfo("My Plan updated again", "<span>My Plan updated again</span>"));
133 expected.setName("Test Plan Name updated again");
134 }
135
136
137
138
139
140
141
142
143
144 public void testCrudPlanItem_setDTOFieldsForTestCreate(PlanItemInfo expected)
145 {
146 expected.setRefObjectId("ENGL101ind");
147 expected.setRefObjectType(CluServiceConstants.CREDIT_COURSE_LU_TYPE_KEY);
148 List<String> planTermIds= new ArrayList<String>();
149 planTermIds.add("planTermId01");
150 planTermIds.add("planTermid02");
151 expected.setPlanTermIds(planTermIds);
152 expected.setCredit(new BigDecimal("3.10"));
153 expected.setCategory(AcademicPlanServiceConstants.ItemCategory.PLANNED);
154 expected.setTypeKey(AcademicPlanServiceConstants.LEARNING_PLAN_ITEM_TYPE);
155 expected.setStateKey("stateKey01");
156 expected.setName("item name 01");
157 expected.setDescr(RichTextHelper.buildRichTextInfo("descr01", "<span>descr01</span>"));
158 }
159
160
161
162
163
164
165
166 public void testCrudPlanItem_testDTOFieldsForTestCreateUpdate(PlanItemInfo expected, PlanItemInfo actual)
167 {
168 assertEquals (expected.getRefObjectId(), actual.getRefObjectId());
169 assertEquals (expected.getRefObjectType(), actual.getRefObjectType());
170 assertEquals (expected.getLearningPlanId(), actual.getLearningPlanId());
171 Collections.sort(expected.getPlanTermIds());
172 Collections.sort(actual.getPlanTermIds());
173 assertEquals (expected.getPlanTermIds(), actual.getPlanTermIds());
174 assertEquals(expected.getCredits(), actual.getCredits());
175 assertEquals(expected.getCategory(), actual.getCategory());
176 assertEquals (expected.getTypeKey(), actual.getTypeKey());
177 assertEquals (expected.getStateKey(), actual.getStateKey());
178 assertEquals (expected.getName(), actual.getName());
179 new RichTextTester().check(expected.getDescr(), actual.getDescr());
180 }
181
182
183
184
185 public void testCrudPlanItem_setDTOFieldsForTestUpdate(PlanItemInfo expected)
186 {
187 expected.setRefObjectId("CHEM131ind");
188 expected.setRefObjectType(CluServiceConstants.CREDIT_COURSE_LU_TYPE_KEY);
189 expected.getPlanTermIds().remove("planTermId01");
190 expected.getPlanTermIds().add("planTermId03");
191 expected.setCredit(new BigDecimal("4.00"));
192 expected.setCategory(AcademicPlanServiceConstants.ItemCategory.BACKUP);
193 expected.setStateKey("stateKeyUpdated");
194 expected.setName("item name 01 updated");
195 expected.setDescr(RichTextHelper.buildRichTextInfo("descr_Updated", "<span>descr_Updated</span>"));
196 }
197
198
199
200
201
202 public void testCrudPlanItem_testDTOFieldsForTestReadAfterUpdate(PlanItemInfo expected, PlanItemInfo actual)
203 {
204 assertEquals (expected.getRefObjectId(), actual.getRefObjectId());
205 assertEquals (expected.getRefObjectType(), actual.getRefObjectType());
206 assertEquals (expected.getLearningPlanId(), actual.getLearningPlanId());
207 Collections.sort(expected.getPlanTermIds());
208 Collections.sort(actual.getPlanTermIds());
209 assertEquals (expected.getPlanTermIds(), actual.getPlanTermIds());
210 assertEquals (expected.getId(), actual.getId());
211 assertEquals (expected.getCredits(), actual.getCredits());
212 assertEquals (expected.getCategory(), actual.getCategory());
213 assertEquals (expected.getTypeKey(), actual.getTypeKey());
214 assertEquals (expected.getStateKey(), actual.getStateKey());
215 assertEquals (expected.getName(), actual.getName());
216 new RichTextTester().check(expected.getDescr(), actual.getDescr());
217 }
218
219
220
221
222
223 public void testCrudPlanItem_setDTOFieldsForTestReadAfterUpdate(PlanItemInfo expected)
224 {
225 expected.setRefObjectId("CHEM131ind");
226 expected.setRefObjectType(CluServiceConstants.CREDIT_COURSE_LU_TYPE_KEY);
227 expected.setLearningPlanId("learningPlanId_Updated");
228 expected.getPlanTermIds().add("planTermId02");
229 expected.getPlanTermIds().add("planTermId03");
230 expected.setCredit(new BigDecimal("4.00"));
231 expected.setName("item name 01 updated again");
232 expected.setDescr(RichTextHelper.buildRichTextInfo("descr_Updated2", "<span>descr_Updated2</span>"));
233 expected.setCategory(AcademicPlanServiceConstants.ItemCategory.BACKUP);
234 }
235
236
237
238
239
240
241
242 @Test
243 public void test_getPlanItemsInPlanByCategory()
244 throws DoesNotExistException ,InvalidParameterException ,MissingParameterException ,OperationFailedException {
245 }
246
247
248 @Test
249 public void test_getPlanItemsByPlanTermAndCategories()
250 throws DoesNotExistException, InvalidParameterException, MissingParameterException,
251 OperationFailedException, PermissionDeniedException {
252
253 String studentId = "student1";
254 List<LearningPlanInfo> learningPlans;
255 learningPlans = KsapFrameworkServiceLocator.getAcademicPlanService().getLearningPlansForStudentByType(
256 studentId,
257 AcademicPlanServiceConstants.LEARNING_PLAN_TYPE_PLAN,
258 KsapFrameworkServiceLocator.getContext().getContextInfo());
259 assertNotNull(learningPlans);
260 assertTrue(String.format("no learning plans found for studenId=%s to test",studentId),
261 learningPlans.size()>1);
262 int plansThatHaveItems=0;
263 String useThisTerm=null;
264 for (LearningPlan plan : learningPlans) {
265 int categoryCount=0;
266 boolean planHasMultipleCategories=false;
267 HashMap<String,HashMap<AcademicPlanServiceConstants.ItemCategory,MutableLong>> termCategoryMap = new
268 HashMap<>();
269
270 List<PlanItemInfo> items = KsapFrameworkServiceLocator.getAcademicPlanService()
271 .getPlanItemsInPlan(plan.getId(),KsapFrameworkServiceLocator.getContext().getContextInfo());
272
273 if (items.size()>0)
274 ++plansThatHaveItems;
275
276
277 if (items.size()>1) {
278 for (PlanItemInfo item : items) {
279 for (String term : item.getPlanTermIds()) {
280 if (!termCategoryMap.containsKey(term)) {
281 termCategoryMap.put(term,new HashMap<AcademicPlanServiceConstants.ItemCategory,MutableLong>());
282 }
283 if (!termCategoryMap.get(term).containsKey(item.getCategory())) {
284 termCategoryMap.get(term).put(item.getCategory(),new MutableLong(0L));
285 }
286 termCategoryMap.get(term).get(item.getCategory()).add(1L);
287 }
288 }
289 }
290
291 for (String term : termCategoryMap.keySet()) {
292 if (useThisTerm==null && termCategoryMap.get(term).size()>1 ) {
293 planHasMultipleCategories=true;
294 useThisTerm=term;
295 continue;
296 }
297 }
298
299
300
301 if (planHasMultipleCategories) {
302 int totalItemsPerTermSoFar=0;
303 List<AcademicPlanServiceConstants.ItemCategory> categories = new ArrayList<>();
304
305
306 for (AcademicPlanServiceConstants.ItemCategory category : termCategoryMap.get(useThisTerm).keySet()) {
307 totalItemsPerTermSoFar+=termCategoryMap.get(useThisTerm).get(category).longValue();
308 categories.add(category);
309 List<PlanItemInfo> itemsSoFar = getAcademicPlanService().
310 getPlanItemsByPlanTermAndCategories(plan.getId(), useThisTerm, categories, contextInfo);
311
312
313 assertEquals("wrong item count returned by getPlanItemsByPlanTermAndCategories",
314 totalItemsPerTermSoFar,itemsSoFar.size());
315 }
316 }
317 }
318 assertTrue(String.format("this test expects multiple plans to exist for student %s",studentId),
319 plansThatHaveItems > 1);
320 assertTrue("this test expects a learning plan having items in more than one category in a term",
321 useThisTerm!=null);
322 }
323
324
325 @Test
326 public void test_getPlanItemsInPlan()
327 throws DoesNotExistException ,InvalidParameterException ,MissingParameterException ,OperationFailedException {
328 }
329
330
331 @Test
332 public void test_getPlanItemsInPlanByAtp()
333 throws DoesNotExistException ,InvalidParameterException ,MissingParameterException ,OperationFailedException {
334 }
335
336
337 @Test
338 public void test_getPlanItemsInPlanByRefObjectIdByRefObjectType()
339 throws DoesNotExistException, InvalidParameterException, MissingParameterException,
340 OperationFailedException, PermissionDeniedException {
341 }
342
343
344 @Test
345 public void test_validateLearningPlan()
346 throws DoesNotExistException ,InvalidParameterException ,MissingParameterException ,OperationFailedException {
347 }
348
349
350 @Test
351 public void test_validatePlanItem()
352 throws DoesNotExistException ,InvalidParameterException ,MissingParameterException ,OperationFailedException ,AlreadyExistsException {
353 }
354
355 }
356
357