1 package org.kuali.student.lum.program.service.impl;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNotNull;
5 import static org.junit.Assert.assertTrue;
6 import static org.junit.Assert.fail;
7
8 import java.beans.IntrospectionException;
9 import java.lang.reflect.InvocationTargetException;
10 import java.lang.reflect.Method;
11 import java.util.ArrayList;
12 import java.util.Collection;
13 import java.util.Date;
14 import java.util.HashMap;
15 import java.util.List;
16 import java.util.Map;
17
18 import org.apache.commons.lang.builder.EqualsBuilder;
19 import org.junit.Ignore;
20 import org.junit.Test;
21 import org.junit.runner.RunWith;
22 import org.kuali.student.core.assembly.data.Metadata;
23 import org.kuali.student.core.assembly.dictionary.MetadataServiceImpl;
24 import org.kuali.student.core.dto.RichTextInfo;
25 import org.kuali.student.core.exceptions.AlreadyExistsException;
26 import org.kuali.student.core.exceptions.CircularRelationshipException;
27 import org.kuali.student.core.exceptions.DataValidationErrorException;
28 import org.kuali.student.core.exceptions.DependentObjectsExistException;
29 import org.kuali.student.core.exceptions.DoesNotExistException;
30 import org.kuali.student.core.exceptions.IllegalVersionSequencingException;
31 import org.kuali.student.core.exceptions.InvalidParameterException;
32 import org.kuali.student.core.exceptions.MissingParameterException;
33 import org.kuali.student.core.exceptions.OperationFailedException;
34 import org.kuali.student.core.exceptions.PermissionDeniedException;
35 import org.kuali.student.core.exceptions.UnsupportedActionException;
36 import org.kuali.student.core.exceptions.VersionMismatchException;
37 import org.kuali.student.core.statement.dto.ReqCompFieldInfo;
38 import org.kuali.student.core.statement.dto.ReqCompFieldTypeInfo;
39 import org.kuali.student.core.statement.dto.ReqComponentInfo;
40 import org.kuali.student.core.statement.dto.ReqComponentTypeInfo;
41 import org.kuali.student.core.statement.dto.StatementOperatorTypeKey;
42 import org.kuali.student.core.statement.dto.StatementTreeViewInfo;
43 import org.kuali.student.core.statement.service.StatementService;
44 import org.kuali.student.lum.course.dto.LoDisplayInfo;
45 import org.kuali.student.lum.course.service.assembler.CourseAssemblerConstants;
46 import org.kuali.student.lum.lo.dto.LoCategoryInfo;
47 import org.kuali.student.lum.lo.dto.LoInfo;
48 import org.kuali.student.lum.lu.dto.AdminOrgInfo;
49 import org.kuali.student.lum.program.dto.CoreProgramInfo;
50 import org.kuali.student.lum.program.dto.CredentialProgramInfo;
51 import org.kuali.student.lum.program.dto.MajorDisciplineInfo;
52 import org.kuali.student.lum.program.dto.ProgramRequirementInfo;
53 import org.kuali.student.lum.program.dto.ProgramVariationInfo;
54 import org.kuali.student.lum.program.service.ProgramService;
55 import org.kuali.student.lum.program.service.assembler.MajorDisciplineDataGenerator;
56 import org.kuali.student.lum.program.service.assembler.ProgramAssemblerConstants;
57 import org.springframework.beans.BeanUtils;
58 import org.springframework.beans.factory.annotation.Autowired;
59 import org.springframework.test.context.ContextConfiguration;
60 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
61
62 @RunWith(SpringJUnit4ClassRunner.class)
63 @ContextConfiguration(locations = {"classpath:program-test-context.xml"})
64 public class TestProgramServiceImpl {
65
66 @Autowired
67 public ProgramService programService;
68 @Autowired
69 public StatementService statementService;
70 private static final String OTHER_LO_CAT_ID = "550e8400-e29b-41d4-a716-446655440000";
71
72
73
74
75
76 private final String[] DUMMY_SERVICE_METHODS = {"createHonorsProgram", "createMinorDiscipline", "deleteHonorsProgram",
77 "deleteMinorDiscipline", "getCredentialProgramType", "getCredentialProgramTypes",
78 "getHonorsByCredentialProgramType", "getHonorsProgram", "getMajorIdsByCredentialProgramType",
79 "getMinorDiscipline", "getMinorsByCredentialProgramType", "updateHonorsProgram", "updateMinorDiscipline",
80 "validateHonorsProgram", "validateMinorDiscipline", "getSearchCriteriaType", "getSearchCriteriaTypes",
81 "getSearchResultType", "getSearchResultTypes", "getSearchType", "getSearchTypes", "getSearchTypesByCriteria",
82 "getSearchTypesByResult", "search"};
83
84 @Test
85 public void testProgramServiceSetup() {
86 assertNotNull(programService);
87 assertNotNull(statementService);
88 }
89
90 @Test
91 public void testGetMetaData() {
92 MetadataServiceImpl metadataService = new MetadataServiceImpl(programService);
93 metadataService.setUiLookupContext("classpath:lum-ui-test-lookup-context.xml");
94 Metadata metadata = metadataService.getMetadata("org.kuali.student.lum.program.dto.MajorDisciplineInfo");
95 assertNotNull(metadata);
96
97 Map<String, Metadata> properties = metadata.getProperties();
98 assertTrue(properties.size() > 0);
99
100 assertTrue(properties.containsKey("universityClassification"));
101 metadata = properties.get("universityClassification");
102 assertEquals("STRING", metadata.getDataType().name());
103 }
104
105
106 @Test
107 public void testGetProgramRequirement() throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
108 ProgramRequirementInfo progReqInfo = programService.getProgramRequirement("PROGREQ-1", null, null);
109 assertNotNull(progReqInfo);
110
111 checkTreeView(progReqInfo, false);
112
113
114 List<LoDisplayInfo> los = progReqInfo.getLearningObjectives();
115 assertNotNull(los);
116 assertEquals(1, los.size());
117 LoDisplayInfo ldi1 = los.get(0);
118 assertNotNull(ldi1);
119
120 LoInfo loInfo1 = ldi1.getLoInfo();
121 assertNotNull(loInfo1);
122 assertEquals("81abea67-3bcc-4088-8348-e265f3670145", loInfo1.getId());
123 assertEquals("Desc4", loInfo1.getDesc().getPlain());
124 assertEquals("Edit Wiki Message Structure", loInfo1.getName());
125 assertEquals("kuali.loRepository.key.singleUse", loInfo1.getLoRepositoryKey());
126 assertEquals("draft", loInfo1.getState());
127 assertEquals("kuali.lo.type.singleUse", loInfo1.getType());
128 }
129
130 @Test
131 @Ignore
132 public void testGetProgramRequirementNL() throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
133 ProgramRequirementInfo progReqInfo = programService.getProgramRequirement("PROGREQ-1", "KUALI.RULE", "en");
134 assertNotNull(progReqInfo);
135
136 checkTreeView(progReqInfo, true);
137 }
138
139 private void checkTreeView(final ProgramRequirementInfo progReqInfo, final boolean checkNaturalLanguage) {
140 StatementTreeViewInfo rootTree = progReqInfo.getStatement();
141 assertNotNull(rootTree);
142 List<StatementTreeViewInfo> subTreeView = rootTree.getStatements();
143 assertNotNull(subTreeView);
144 assertEquals(2, subTreeView.size());
145 StatementTreeViewInfo subTree1 = subTreeView.get(0);
146 StatementTreeViewInfo subTree2 = subTreeView.get(1);
147
148
149 assertNotNull(rootTree);
150 assertEquals(2, subTreeView.size());
151 assertNotNull(subTree1);
152 assertNotNull(subTree2);
153
154
155 assertEquals("STMT-TV-2", subTree1.getId());
156 assertEquals(2, subTree1.getReqComponents().size());
157 assertEquals("REQCOMP-TV-1", subTree1.getReqComponents().get(0).getId());
158 assertEquals("REQCOMP-TV-2", subTree1.getReqComponents().get(1).getId());
159 if (checkNaturalLanguage) {
160 assertEquals("Student must have completed all of MATH 152, MATH 180", subTree1.getReqComponents().get(0).getNaturalLanguageTranslation());
161 assertEquals("Student needs a minimum GPA of 3.5 in MATH 152, MATH 180", subTree1.getReqComponents().get(1).getNaturalLanguageTranslation());
162 }
163
164
165 assertEquals("STMT-TV-3", subTree2.getId());
166 assertEquals(2, subTree2.getReqComponents().size());
167 assertEquals("REQCOMP-TV-3", subTree2.getReqComponents().get(0).getId());
168 assertEquals("REQCOMP-TV-4", subTree2.getReqComponents().get(1).getId());
169 if (checkNaturalLanguage) {
170 assertEquals("Student must have completed 1 of MATH 152, MATH 180", subTree2.getReqComponents().get(0).getNaturalLanguageTranslation());
171 assertEquals("Student needs a minimum GPA of 4.0 in MATH 152, MATH 180", subTree2.getReqComponents().get(1).getNaturalLanguageTranslation());
172 }
173 }
174
175 @Test(expected = MissingParameterException.class)
176 public void testGetProgramRequirement_nullId() throws Exception {
177 programService.getProgramRequirement(null, null, null);
178 }
179
180 @Test(expected = DoesNotExistException.class)
181 public void testGetProgramRequirement_badId() throws Exception {
182 programService.getProgramRequirement("CLU-XXX ", null, null);
183 }
184
185 @Test
186 public void testGetCoreProgram() throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException {
187 CoreProgramInfo core = null;
188 try {
189 core = programService.getCoreProgram("d4ea77dd-b492-4554-b104-863e42c5f8b7");
190 fail("Should have received DoesNotExistException");
191 } catch (DoesNotExistException dnee) {
192 String expectedExceptionMessage = "Specified CLU is not a CoreProgram";
193 assertEquals("Expected DoesNotExistException has incorrect message:", expectedExceptionMessage, dnee.getMessage());
194 }
195 core = programService.getCoreProgram("00f5f8c5-fff1-4c8b-92fc-789b891e0849");
196
197 assertNotNull(core);
198
199 assertNotNull(core.getReferenceURL());
200 assertEquals("http://www.google.ca", core.getReferenceURL());
201 assertNotNull(core.getUniversityClassification());
202 assertEquals(core.getUniversityClassification(), "UNIVERSITYCLASSIFICATIONCODE");
203 assertNotNull(core.getStartTerm());
204 assertEquals("start_term", core.getStartTerm());
205 assertNotNull(core.getEndTerm());
206 assertEquals("end_term", core.getEndTerm());
207 assertNotNull(core.getEndProgramEntryTerm());
208 assertEquals("end_admit_term", core.getEndProgramEntryTerm());
209 assertNotNull(core.getCode());
210 assertEquals("BS", core.getCode());
211 assertNotNull(core.getShortTitle());
212 assertEquals("B.S.", core.getShortTitle());
213 assertNotNull(core.getLongTitle());
214 assertEquals("Bachelor of Science", core.getLongTitle());
215 assertNotNull(core.getTranscriptTitle());
216 assertEquals(core.getTranscriptTitle(), "TRANSCRIPT-TITLE");
217 assertNotNull(core.getDescr());
218 assertEquals("Anthropology Major", core.getDescr().getPlain());
219
220
221
222
223 assertNotNull(core.getLearningObjectives());
224 assertTrue(core.getLearningObjectives().size() ==1);
225 assertEquals("Core Program Learning objectives", core.getLearningObjectives().get(0).getLoInfo().getDesc().getPlain());
226
227 assertNotNull(core.getDivisionsContentOwner());
228 assertTrue(core.getDivisionsContentOwner().size() == 1);
229 assertEquals(core.getDivisionsContentOwner().get(0), "48");
230 assertNotNull(core.getDivisionsStudentOversight());
231 assertTrue(core.getDivisionsStudentOversight().size() == 1);
232 assertEquals(core.getDivisionsStudentOversight().get(0), "50");
233 assertNotNull(core.getUnitsContentOwner());
234 assertTrue(core.getUnitsContentOwner().size() == 1);
235 assertEquals(core.getUnitsContentOwner().get(0), "49");
236 assertNotNull(core.getUnitsStudentOversight());
237 assertTrue(core.getUnitsStudentOversight().size() == 1);
238 assertEquals(core.getUnitsStudentOversight().get(0), "51");
239
240 assertNotNull(core.getAttributes());
241 assertTrue(core.getAttributes().size() ==2);
242 assertEquals("GINGER GEM", core.getAttributes().get("COOKIES"));
243 assertEquals("JAM TART", core.getAttributes().get("CAKES"));
244
245 assertNotNull(core.getMetaInfo());
246 assertEquals("1", core.getMetaInfo().getVersionInd());
247 assertNotNull(core.getType());
248 assertEquals(ProgramAssemblerConstants.CORE_PROGRAM, core.getType());
249 assertNotNull(core.getState());
250 assertEquals(ProgramAssemblerConstants.ACTIVE, core.getState());
251 assertNotNull(core.getId());
252 assertEquals("00f5f8c5-fff1-4c8b-92fc-789b891e0849", core.getId());
253 }
254 @Test
255 public void testGetMajorDiscipline() throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException {
256 MajorDisciplineInfo major = null;
257
258
259 try {
260 major = programService.getMajorDiscipline("0d8c42bc-77ba-450e-ae0e-eecd76fae779");
261 fail("Should have received DoesNotExistException");
262 } catch (DoesNotExistException dnee) {
263 String expectedExceptionMessage = "Specified CLU is not a Major Discipline";
264 assertEquals("Expected DoesNotExistException has incorrect message:", expectedExceptionMessage, dnee.getMessage());
265 }
266 major = programService.getMajorDiscipline("d4ea77dd-b492-4554-b104-863e42c5f8b7");
267
268 assertNotNull(major);
269
270 assertNotNull(major.getIntensity());
271 assertEquals("kuali.atp.duration.full", major.getIntensity());
272 assertNotNull(major.getReferenceURL());
273 assertEquals("http://www.google.ca", major.getReferenceURL());
274 assertEquals(1, major.getPublishedInstructors().size());
275
276 assertEquals("INSTR-1", major.getPublishedInstructors().get(0).getPersonId());
277 assertNotNull(major.getCredentialProgramId());
278 assertEquals("d02dbbd3-20e2-410d-ab52-1bd6d362748b", major.getCredentialProgramId());
279
280 assertNotNull(major.getVariations());
281 assertTrue(major.getVariations().size() == 2);
282 assertEquals("ZOOA", major.getVariations().get(0).getCode());
283 assertEquals("ARCB", major.getVariations().get(1).getCode());
284
285 assertNotNull(major.getCode());
286 assertEquals("ANTH", major.getCode());
287 assertNotNull(major.getCip2000Code());
288 assertEquals("45.0202", major.getCip2000Code());
289 assertNotNull(major.getCip2010Code());
290 assertEquals("45.0201", major.getCip2010Code());
291 assertNotNull(major.getHegisCode());
292 assertEquals("220200", major.getHegisCode());
293 assertNotNull(major.getUniversityClassification());
294 assertEquals("UNIVERSITYCLASSIFICATIONCODE", major.getUniversityClassification());
295 assertNotNull(major.getSelectiveEnrollmentCode());
296 assertEquals("SELECTIVEENROLLMENTCODE", major.getSelectiveEnrollmentCode());
297
298 assertNotNull(major.getResultOptions());
299 assertTrue(major.getResultOptions().size() == 2);
300 assertEquals("kuali.resultComponent.degree.ba", major.getResultOptions().get(0));
301 assertEquals("kuali.resultComponent.degree.bsc", major.getResultOptions().get(1));
302
303 assertNotNull(major.getStdDuration());
304 assertEquals("kuali.atp.duration.Week", major.getStdDuration().getAtpDurationTypeKey());
305 assertEquals(new Integer(100), major.getStdDuration().getTimeQuantity());
306 assertNotNull(major.getStartTerm());
307 assertEquals("start_term", major.getStartTerm());
308 assertNotNull(major.getEndTerm());
309 assertEquals("end_term", major.getEndTerm());
310 assertNotNull(major.getEndProgramEntryTerm());
311 assertEquals("end_admit_term", major.getEndProgramEntryTerm());
312
313 assertNotNull(major.getNextReviewPeriod());
314 assertEquals("kuali.atp.SU2009-2010S1", major.getNextReviewPeriod());
315
316 assertNotNull(major.getEffectiveDate());
317
318
319
320
321
322
323 assertNotNull(major.getShortTitle());
324 assertEquals("Anthro", major.getShortTitle());
325 assertNotNull(major.getLongTitle());
326 assertEquals("Anthropology", major.getLongTitle());
327 assertNotNull(major.getTranscriptTitle());
328 assertEquals("TRANSCRIPT-TITLE", major.getTranscriptTitle());
329 assertNotNull(major.getDiplomaTitle());
330 assertEquals("DIPLOMA-TITLE", major.getDiplomaTitle() );
331 assertNotNull(major.getDescr());
332 assertEquals("Anthropology Major", major.getDescr().getPlain());
333
334
335
336 assertNotNull(major.getCatalogDescr());
337 assertEquals("This is the catalog description", major.getCatalogDescr().getPlain());
338 assertNotNull(major.getCatalogPublicationTargets());
339 assertEquals(1, major.getCatalogPublicationTargets().size());
340 assertEquals("kuali.lu.publication.UndergradCatalog", major.getCatalogPublicationTargets().get(0));
341 assertNotNull(major.getLearningObjectives());
342 assertTrue(major.getLearningObjectives().size() ==1);
343 assertEquals("Annihilate Wiki", major.getLearningObjectives().get(0).getLoInfo().getDesc().getPlain());
344 assertNotNull(major.getCampusLocations());
345 assertTrue(major.getCampusLocations().size() == 2);
346 assertEquals("NO", major.getCampusLocations().get(0));
347 assertEquals("SO", major.getCampusLocations().get(1));
348
349 assertNotNull(major.getOrgCoreProgram());
350 assertEquals("kuali.lu.type.CoreProgram", major.getOrgCoreProgram().getType());
351 assertEquals("00f5f8c5-fff1-4c8b-92fc-789b891e0849", major.getOrgCoreProgram().getId());
352 assertNotNull(major.getProgramRequirements());
353 assertTrue(major.getProgramRequirements().size() == 1);
354 assertEquals("REQ-200", major.getProgramRequirements().get(0));
355
356 assertNotNull(major.getAccreditingAgencies());
357 assertTrue(major.getAccreditingAgencies().size() == 1);
358 assertEquals("23", major.getAccreditingAgencies().get(0).getOrgId());
359 assertNotNull(major.getDivisionsContentOwner());
360 assertTrue(major.getDivisionsContentOwner().size() == 1);
361 assertEquals(major.getDivisionsContentOwner().get(0), "31");
362 assertNotNull(major.getDivisionsStudentOversight());
363 assertTrue(major.getDivisionsStudentOversight().size() == 1);
364 assertEquals(major.getDivisionsStudentOversight().get(0), "32");
365 assertNotNull(major.getDivisionsDeployment());
366 assertTrue(major.getDivisionsDeployment().size() == 1);
367 assertEquals(major.getDivisionsDeployment().get(0), "33");
368 assertNotNull(major.getDivisionsFinancialResources());
369 assertTrue(major.getDivisionsFinancialResources().size() == 1);
370 assertEquals(major.getDivisionsFinancialResources().get(0), "34");
371 assertNotNull(major.getDivisionsFinancialControl());
372 assertTrue(major.getDivisionsFinancialControl().size() == 1);
373 assertEquals(major.getDivisionsFinancialControl().get(0), "36");
374
375 assertNotNull(major.getUnitsContentOwner());
376 assertTrue(major.getUnitsContentOwner().size() == 1);
377 assertEquals(major.getUnitsContentOwner().get(0), "41");
378 assertNotNull(major.getUnitsStudentOversight());
379 assertTrue(major.getUnitsStudentOversight().size() == 1);
380 assertEquals(major.getUnitsStudentOversight().get(0), "42");
381 assertNotNull(major.getUnitsDeployment());
382 assertTrue(major.getUnitsDeployment().size() == 1);
383 assertEquals(major.getUnitsDeployment().get(0), "43");
384 assertNotNull(major.getUnitsFinancialResources());
385 assertTrue(major.getUnitsFinancialResources().size() == 1);
386 assertEquals(major.getUnitsFinancialResources().get(0), "44");
387 assertNotNull(major.getUnitsFinancialControl());
388 assertTrue(major.getUnitsFinancialControl().size() == 2);
389 assertEquals(major.getUnitsFinancialControl().get(0), "46");
390 assertEquals(major.getUnitsFinancialControl().get(1), "47");
391 assertNotNull(major.getAttributes());
392 assertEquals(2, major.getAttributes().size());
393 assertEquals("GINGER GEM", major.getAttributes().get("COOKIES"));
394 assertEquals("JAM TART", major.getAttributes().get("CAKES"));
395
396 assertNotNull(major.getMetaInfo());
397 assertEquals("1", major.getMetaInfo().getVersionInd());
398
399
400
401
402
403
404 assertNotNull(major.getType());
405 assertEquals(ProgramAssemblerConstants.MAJOR_DISCIPLINE, major.getType());
406 assertNotNull(major.getState());
407 assertEquals(ProgramAssemblerConstants.ACTIVE, major.getState());
408 assertNotNull(major.getId());
409 assertEquals("d4ea77dd-b492-4554-b104-863e42c5f8b7", major.getId());
410
411
412 }
413
414 @Test
415 public void testGetVariationsByMajorDisciplineId() throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException{
416 MajorDisciplineInfo majorDisciplineInfo = null;
417
418 majorDisciplineInfo = programService.getMajorDiscipline("d4ea77dd-b492-4554-b104-863e42c5f8b7");
419 assertNotNull(majorDisciplineInfo);
420
421 List<ProgramVariationInfo> pvInfos = programService.getVariationsByMajorDisciplineId("d4ea77dd-b492-4554-b104-863e42c5f8b7");
422 assertNotNull(pvInfos);
423 assertEquals(pvInfos.size(), majorDisciplineInfo.getVariations().size());
424
425 ProgramVariationInfo pvInfo = pvInfos.get(0);
426 assertEquals("ZOOA", pvInfo.getCode());
427 assertEquals("Zooarchaeology", pvInfo.getDescr().getPlain());
428 assertEquals("Zooarchaeology", pvInfo.getLongTitle());
429 assertEquals("ZooArch", pvInfo.getShortTitle());
430 assertEquals("VAR-200", pvInfo.getId());
431 assertEquals("Active", pvInfo.getState());
432
433 }
434
435 @Test
436 public void testGetBaccCredentialProgram() throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException{
437
438 String credentialProgramId = "d02dbbd3-20e2-410d-ab52-1bd6d362748b";
439 CredentialProgramInfo credentialProgramInfo = null;
440 credentialProgramInfo = programService.getCredentialProgram(credentialProgramId);
441 assertNotNull(credentialProgramInfo);
442 assertEquals("BS", credentialProgramInfo.getCode());
443 assertEquals("B.S.", credentialProgramInfo.getShortTitle());
444 assertEquals("Bachelor of Science", credentialProgramInfo.getLongTitle());
445 assertEquals("Bachelor of Science", credentialProgramInfo.getDescr().getPlain());
446 assertEquals(ProgramAssemblerConstants.ACTIVE, credentialProgramInfo.getState());
447 assertEquals(ProgramAssemblerConstants.BACCALAUREATE_PROGRAM, credentialProgramInfo.getCredentialProgramType());
448 assertEquals("52", credentialProgramInfo.getInstitution().getOrgId());
449 assertEquals(ProgramAssemblerConstants.UNDERGRAD_PROGRAM_LEVEL, credentialProgramInfo.getProgramLevel());
450 assertNotNull(credentialProgramInfo.getCoreProgramIds());
451 assertEquals(1, credentialProgramInfo.getCoreProgramIds().size());
452 assertEquals("00f5f8c5-fff1-4c8b-92fc-789b891e0849", credentialProgramInfo.getCoreProgramIds().get(0));
453 }
454
455 @Test
456 public void testCreateMajorDiscipline() throws IllegalArgumentException, SecurityException, IntrospectionException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchFieldException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
457 MajorDisciplineDataGenerator mdGenerator = new MajorDisciplineDataGenerator();
458 MajorDisciplineInfo major;
459 assertNotNull(major = mdGenerator.getMajorDisciplineInfoTestData());
460
461 MajorDisciplineInfo createdMD = programService.createMajorDiscipline(major);
462
463 assertNotNull(createdMD);
464
465 assertNotNull(createdMD.getId());
466
467 assertNotNull(createdMD.getState());
468 assertEquals(ProgramAssemblerConstants.DRAFT, createdMD.getState());
469
470 assertNotNull(createdMD.getType());
471 assertEquals(ProgramAssemblerConstants.MAJOR_DISCIPLINE, createdMD.getType());
472
473 assertNotNull(createdMD.getIntensity());
474 assertEquals("intensity-test", createdMD.getIntensity());
475 assertNotNull(createdMD.getReferenceURL());
476 assertEquals("referenceURL-test", createdMD.getReferenceURL());
477
478 assertEquals(2, createdMD.getPublishedInstructors().size());
479 assertEquals("personId-test", createdMD.getPublishedInstructors().get(0).getPersonId());
480
481 assertNotNull(createdMD.getCredentialProgramId());
482 assertEquals("00f5f8c5-fff1-4c8b-92fc-789b891e0849", createdMD.getCredentialProgramId());
483
484 assertNotNull(createdMD.getVariations());
485 assertTrue(createdMD.getVariations().size() == 2);
486 assertNotNull(createdMD.getVariations().get(0).getId());
487 assertNotNull(createdMD.getVariations().get(1).getId());
488 assertEquals("kuali.lu.type.Variation", createdMD.getVariations().get(0).getType());
489 assertEquals("kuali.lu.type.Variation", createdMD.getVariations().get(1).getType());
490
491 assertNotNull(createdMD.getCode());
492
493
494 assertNotNull(createdMD.getCip2000Code());
495 assertEquals(createdMD.getCip2000Code(), "cip2000Code-test");
496 assertNotNull(createdMD.getCip2010Code());
497 assertEquals(createdMD.getCip2010Code(), "cip2010Code-test");
498 assertNotNull(createdMD.getHegisCode());
499 assertEquals(createdMD.getHegisCode(), "hegisCode-test");
500 assertNotNull(createdMD.getUniversityClassification());
501 assertEquals(createdMD.getUniversityClassification(), "universityClassification-test");
502 assertNotNull(createdMD.getSelectiveEnrollmentCode());
503 assertEquals(createdMD.getSelectiveEnrollmentCode(), "selectiveEnrollmentCode-test");
504
505 assertNotNull(createdMD.getResultOptions());
506 assertTrue(createdMD.getResultOptions().size() == 2);
507 assertEquals("resultOptions-test", createdMD.getResultOptions().get(0));
508
509 assertNotNull(createdMD.getStdDuration());
510 assertEquals("atpDurationTypeKey-test", createdMD.getStdDuration().getAtpDurationTypeKey());
511 assertEquals(new Integer(63), createdMD.getStdDuration().getTimeQuantity());
512
513 assertNotNull(createdMD.getStartTerm());
514 assertEquals("startTerm-test", createdMD.getStartTerm());
515 assertNotNull(createdMD.getEndTerm());
516 assertEquals("endTerm-test", createdMD.getEndTerm());
517 assertNotNull(createdMD.getEndProgramEntryTerm());
518 assertEquals("endProgramEntryTerm-test", createdMD.getEndProgramEntryTerm());
519 assertNotNull(createdMD.getNextReviewPeriod());
520 assertEquals("nextReviewPeriod-test", createdMD.getNextReviewPeriod());
521
522 assertNotNull(createdMD.getEffectiveDate());
523
524
525
526
527
528
529 assertNotNull(createdMD.getShortTitle());
530 assertEquals("shortTitle-test", createdMD.getShortTitle());
531 assertNotNull(createdMD.getLongTitle());
532 assertEquals("longTitle-test", createdMD.getLongTitle());
533 assertNotNull(createdMD.getTranscriptTitle());
534 assertEquals(createdMD.getTranscriptTitle(), "transcriptTitle-test");
535 assertNotNull(createdMD.getDiplomaTitle());
536 assertEquals(createdMD.getDiplomaTitle(), "diplomaTitle-test");
537 assertNotNull(createdMD.getDescr());
538 assertEquals("plain-test", createdMD.getDescr().getPlain());
539 assertEquals("formatted-test", createdMD.getDescr().getFormatted());
540
541 assertNotNull(createdMD.getCatalogDescr());
542 assertEquals("plain-test", createdMD.getCatalogDescr().getPlain());
543 assertEquals("formatted-test", createdMD.getCatalogDescr().getFormatted());
544
545 assertNotNull(createdMD.getCatalogPublicationTargets());
546 assertTrue(createdMD.getCatalogPublicationTargets().size() == 2);
547 assertEquals("kuali.lu.publication.Catalog", createdMD.getCatalogPublicationTargets().get(0));
548
549 assertNotNull(createdMD.getLearningObjectives());
550 assertTrue(createdMD.getLearningObjectives().size() == 2);
551 assertEquals("plain-test", createdMD.getLearningObjectives().get(0).getLoInfo().getDesc().getPlain());
552
553 assertNotNull(createdMD.getCampusLocations());
554 assertTrue(createdMD.getCampusLocations().size() == 2);
555 assertEquals("SO", createdMD.getCampusLocations().get(0));
556 assertEquals("NO", createdMD.getCampusLocations().get(1));
557
558 assertNotNull(createdMD.getOrgCoreProgram());
559 assertEquals(ProgramAssemblerConstants.CORE_PROGRAM, createdMD.getOrgCoreProgram().getType());
560
561
562 assertNotNull(createdMD.getProgramRequirements());
563 assertTrue(createdMD.getProgramRequirements().size() == 2);
564 assertEquals("REQ-200", createdMD.getProgramRequirements().get(0));
565
566 assertNotNull(createdMD.getAccreditingAgencies());
567 assertTrue(createdMD.getAccreditingAgencies().size() == 2);
568 assertEquals("orgId-test", createdMD.getAccreditingAgencies().get(0).getOrgId());
569
570 assertNotNull(createdMD.getDivisionsContentOwner());
571 assertTrue(createdMD.getDivisionsContentOwner().size() == 2);
572 assertEquals("divisionsContentOwner-test", createdMD.getDivisionsContentOwner().get(0));
573
574 assertNotNull(createdMD.getDivisionsStudentOversight());
575 assertTrue(createdMD.getDivisionsStudentOversight().size() == 2);
576 assertEquals("divisionsStudentOversight-test", createdMD.getDivisionsStudentOversight().get(0));
577
578 assertNotNull(createdMD.getDivisionsDeployment());
579 assertTrue(createdMD.getDivisionsDeployment().size() == 2);
580 assertEquals("divisionsDeployment-test", createdMD.getDivisionsDeployment().get(0));
581
582 assertNotNull(createdMD.getDivisionsFinancialResources());
583 assertTrue(createdMD.getDivisionsFinancialResources().size() == 2);
584 assertEquals("divisionsFinancialResources-test", createdMD.getDivisionsFinancialResources().get(0));
585
586 assertNotNull(createdMD.getDivisionsFinancialControl());
587 assertTrue(createdMD.getDivisionsFinancialControl().size() == 2);
588 assertEquals("divisionsFinancialControl-test", createdMD.getDivisionsFinancialControl().get(0));
589
590 assertNotNull(createdMD.getUnitsContentOwner());
591 assertTrue(createdMD.getUnitsContentOwner().size() == 2);
592 assertEquals("unitsContentOwner-test", createdMD.getUnitsContentOwner().get(0));
593
594 assertNotNull(createdMD.getUnitsStudentOversight());
595 assertTrue(createdMD.getUnitsStudentOversight().size() == 2);
596 assertEquals("unitsStudentOversight-test", createdMD.getUnitsStudentOversight().get(0));
597
598 assertNotNull(createdMD.getUnitsDeployment());
599 assertTrue(createdMD.getUnitsDeployment().size() == 2);
600 assertEquals("unitsDeployment-test", createdMD.getUnitsDeployment().get(0));
601
602 assertNotNull(createdMD.getUnitsFinancialResources());
603 assertTrue(createdMD.getUnitsFinancialResources().size() == 2);
604 assertEquals("unitsFinancialResources-test", createdMD.getUnitsFinancialResources().get(0));
605
606 assertNotNull(createdMD.getUnitsFinancialControl());
607 assertTrue(createdMD.getUnitsFinancialControl().size() == 2);
608 assertEquals("unitsFinancialControl-test", createdMD.getUnitsFinancialControl().get(0));
609
610 assertNotNull(createdMD.getAttributes());
611 assertTrue(createdMD.getAttributes().size() ==2);
612 assertEquals("attributes-1", createdMD.getAttributes().get("attributes-1"));
613 assertEquals("attributes-2", createdMD.getAttributes().get("attributes-2"));
614
615 assertNotNull(createdMD.getMetaInfo());
616 assertEquals("0", createdMD.getMetaInfo().getVersionInd());
617
618
619
620
621
622 }
623
624 @Test
625 public void testMajorDisciplineVersioning() throws IllegalArgumentException, SecurityException, IntrospectionException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchFieldException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException, DoesNotExistException, CircularRelationshipException, DependentObjectsExistException, UnsupportedActionException, IllegalVersionSequencingException {
626 MajorDisciplineDataGenerator mdGenerator = new MajorDisciplineDataGenerator();
627 MajorDisciplineInfo mdInfo = mdGenerator.getMajorDisciplineInfoTestData();
628 mdInfo.getProgramRequirements().clear();
629 for(ProgramVariationInfo variation :mdInfo.getVariations()){
630 variation.getProgramRequirements().clear();
631 }
632 MajorDisciplineInfo createdMajor = programService.createMajorDiscipline(mdInfo);
633
634 MajorDisciplineInfo newMajorDiscipline = programService.createNewMajorDisciplineVersion(createdMajor.getVersionInfo().getVersionIndId(), "test make a new version");
635
636
637 programService.setCurrentMajorDisciplineVersion(newMajorDiscipline.getId(), null);
638
639 MajorDisciplineInfo newMajor = null;
640 try {
641 newMajor = programService.createNewMajorDisciplineVersion(createdMajor.getVersionInfo().getVersionIndId(), "test make a new version");
642 assertTrue(true);
643 } catch (Exception e) {
644 assertTrue(false);
645 }
646
647 assertNotNull(newMajor);
648
649 }
650
651 @Test
652 public void testCreateMajorDisciplineDeleteRule() throws AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, IllegalArgumentException, SecurityException, IntrospectionException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchFieldException {
653 MajorDisciplineDataGenerator mdGenerator = new MajorDisciplineDataGenerator();
654 MajorDisciplineInfo major;
655 assertNotNull(major = mdGenerator.getMajorDisciplineInfoTestData());
656
657 MajorDisciplineInfo createdMD = programService.createMajorDiscipline(major);
658
659 ProgramRequirementInfo progReq = createProgramRequirementTestData();
660 ProgramRequirementInfo createdProgReq = programService.createProgramRequirement(progReq);
661 }
662
663 @Test(expected = MissingParameterException.class)
664 public void testCreateProgramRequirement_null() throws Exception {
665 programService.createProgramRequirement(null);
666 }
667
668 @Test
669 public void testCreateProgramRequirement() throws AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException {
670 ProgramRequirementInfo progReq = createProgramRequirementTestData();
671 ProgramRequirementInfo createdProgReq = programService.createProgramRequirement(progReq);
672 checkProgramRequirement(progReq, createdProgReq);
673
674 ProgramRequirementInfo progReq2 = programService.getProgramRequirement(createdProgReq.getId(), null, null);
675 checkProgramRequirement(progReq, progReq2);
676 }
677
678 private ProgramRequirementInfo createProgramRequirementTestData() {
679 ProgramRequirementInfo progReq = new ProgramRequirementInfo();
680 progReq.setShortTitle("Short Title");
681 progReq.setLongTitle("Long title");
682 progReq.setDescr(toRichText("Program Requirement"));
683
684 List<LoDisplayInfo> los = new ArrayList<LoDisplayInfo>(0);
685
686 LoDisplayInfo loDisplayInfo = new LoDisplayInfo();
687 LoInfo loInfo = new LoInfo();
688 loInfo.setDesc(toRichText("Program Requirement LO Info"));
689 loInfo.setLoRepositoryKey("lo rep key");
690 loDisplayInfo.setLoInfo(loInfo);
691 los.add(loDisplayInfo);
692 progReq.setLearningObjectives(los);
693
694 StatementTreeViewInfo statement = createStatementTree();
695 progReq.setStatement(statement);
696 progReq.setType(ProgramAssemblerConstants.PROGRAM_REQUIREMENT);
697 return progReq;
698 }
699
700 private static void checkProgramRequirement(
701 ProgramRequirementInfo orig, ProgramRequirementInfo created) {
702 assertNotNull(orig);
703 assertNotNull(created);
704 assertTrue(EqualsBuilder.reflectionEquals(orig, created, new String[]{"id", "descr", "learningObjectives","statement","attributes","metaInfo"}));
705 checkLoDisplays(orig.getLearningObjectives(), created.getLearningObjectives());
706 if (orig.getId() == null && created.getId() == null) {
707 fail("both ProgramRequirements ids are null");
708 } else if (orig.getId() != null) {
709 assertEquals(orig.getId(), created.getId());
710 }
711
712 checkRichText(orig.getDescr(), created.getDescr());
713 checkStatementTreeView(orig.getStatement(), created.getStatement());
714 }
715
716 private static void checkStatementTreeView(StatementTreeViewInfo statement,
717 StatementTreeViewInfo statement2) {
718 assertNotNull(statement);
719 assertNotNull(statement2);
720 assertTrue(EqualsBuilder.reflectionEquals(statement, statement2, new String[]{"id", "desc", "attributes", "metaInfo", "statements", "reqComponents"}));
721 if (statement.getId() == null && statement2.getId() == null) {
722 fail("Both StatementTreeView ids are null");
723 } else if (statement.getId() != null) {
724 assertEquals(statement.getId(), statement2.getId());
725 }
726 checkRichText(statement.getDesc(), statement2.getDesc());
727 checkStatementTreeViews(statement.getStatements(), statement2.getStatements());
728 checkReqComponents(statement.getReqComponents(), statement2.getReqComponents());
729 }
730
731 private static void checkReqComponents(List<ReqComponentInfo> reqComponents,
732 List<ReqComponentInfo> reqComponents2) {
733 assertNotNull(reqComponents);
734 assertNotNull(reqComponents2);
735 assertEquals(reqComponents.size(), reqComponents2.size());
736 for (int i = 0; i < reqComponents.size(); i++) {
737 checkReqComponent(reqComponents.get(i), reqComponents2.get(i));
738 }
739 }
740
741 private static void checkReqComponent(ReqComponentInfo reqComponent,
742 ReqComponentInfo reqComponent2) {
743 assertNotNull(reqComponent);
744 assertNotNull(reqComponent2);
745 assertTrue(EqualsBuilder.reflectionEquals(reqComponent, reqComponent2, new String[]{"id", "desc", "reqCompFields", "requiredComponentType", "naturalLanguageTranslation", "metaInfo"}));
746 if (reqComponent.getId() == null && reqComponent2.getId() == null) {
747 fail("Both ReqComponent ids are null");
748 } else if (reqComponent.getId() != null) {
749 assertEquals(reqComponent.getId(), reqComponent2.getId());
750 }
751 checkRichText(reqComponent.getDesc(), reqComponent2.getDesc());
752 checkReqCompFields(reqComponent.getReqCompFields(), reqComponent.getReqCompFields());
753
754 }
755
756 private static void checkReqComponentType(
757 ReqComponentTypeInfo requiredComponentType,
758 ReqComponentTypeInfo requiredComponentType2) {
759 assertNotNull(requiredComponentType);
760 assertNotNull(requiredComponentType2);
761 checkReqCompFieldTypes(requiredComponentType.getReqCompFieldTypeInfos(), requiredComponentType2.getReqCompFieldTypeInfos());
762 }
763
764 private static void checkReqCompFieldTypes(
765 List<ReqCompFieldTypeInfo> reqCompFieldTypeInfos,
766 List<ReqCompFieldTypeInfo> reqCompFieldTypeInfos2) {
767 assertNotNull(reqCompFieldTypeInfos);
768 assertNotNull(reqCompFieldTypeInfos2);
769 assertEquals(reqCompFieldTypeInfos.size(), reqCompFieldTypeInfos2.size());
770 for (int i = 0; i < reqCompFieldTypeInfos.size(); i++) {
771 checkReqCompFieldType(reqCompFieldTypeInfos.get(i), reqCompFieldTypeInfos2.get(i));
772 }
773 }
774
775 private static void checkReqCompFieldType(
776 ReqCompFieldTypeInfo reqCompFieldTypeInfo,
777 ReqCompFieldTypeInfo reqCompFieldTypeInfo2) {
778 assertNotNull(reqCompFieldTypeInfo);
779 assertNotNull(reqCompFieldTypeInfo2);
780
781 }
782
783 private static void checkReqCompFields(List<ReqCompFieldInfo> reqCompFields,
784 List<ReqCompFieldInfo> reqCompFields2) {
785 assertNotNull(reqCompFields);
786 assertNotNull(reqCompFields2);
787 assertEquals(reqCompFields.size(), reqCompFields2.size());
788 for (int i = 0; i < reqCompFields.size(); i++) {
789 checkReqCompField(reqCompFields.get(i), reqCompFields2.get(i));
790 }
791 }
792
793 private static void checkReqCompField(ReqCompFieldInfo reqCompField,
794 ReqCompFieldInfo reqCompField2) {
795 assertNotNull(reqCompField);
796 assertNotNull(reqCompField2);
797 assertTrue(EqualsBuilder.reflectionEquals(reqCompField,reqCompField2));
798 }
799
800 private static void checkStatementTreeViews(List<StatementTreeViewInfo> statements,
801 List<StatementTreeViewInfo> statements2) {
802 assertNotNull(statements);
803 assertNotNull(statements2);
804 assertEquals(statements.size(), statements2.size());
805 for (int i = 0; i < statements.size(); i++) {
806 checkStatementTreeView(statements.get(i), statements2.get(i));
807 }
808 }
809
810 private static void checkLoDisplays(List<LoDisplayInfo> los,
811 List<LoDisplayInfo> los2) {
812 assertNotNull(los);
813 assertNotNull(los2);
814 assertEquals(los.size(), los2.size());
815 for (int i = 0; i < los.size(); i++) {
816 LoDisplayInfo ldi1 = los.get(i);
817 LoDisplayInfo ldi2 = los2.get(i);
818 checkLoDisplay(ldi1, ldi2);
819 }
820 }
821
822 private static void checkLoDisplay(LoDisplayInfo ldi1, LoDisplayInfo ldi2) {
823 assertNotNull(ldi1);
824 assertNotNull(ldi2);
825 assertTrue(EqualsBuilder.reflectionEquals(ldi1, ldi2, new String[]{"loInfo","loDisplayInfoList","loCategoryInfoList"}));
826
827 LoInfo li1 = ldi1.getLoInfo();
828 LoInfo li2 = ldi2.getLoInfo();
829 checkLo(li1, li2);
830 checkLoDisplayLists(ldi1.getLoDisplayInfoList(), ldi2.getLoDisplayInfoList());
831 checkLoCategorys(ldi1.getLoCategoryInfoList(), ldi2.getLoCategoryInfoList());
832 }
833
834 private static void checkLoCategorys(List<LoCategoryInfo> loCategoryInfoList,
835 List<LoCategoryInfo> loCategoryInfoList2) {
836 assertNotNull(loCategoryInfoList);
837 assertNotNull(loCategoryInfoList2);
838 assertEquals(loCategoryInfoList.size(), loCategoryInfoList2.size());
839 for (int i = 0; i < loCategoryInfoList.size(); i++) {
840 checkLoCategory(loCategoryInfoList.get(i), loCategoryInfoList2.get(i));
841 }
842 }
843
844 private static void checkLoCategory(LoCategoryInfo loCategoryInfo,
845 LoCategoryInfo loCategoryInfo2) {
846 assertNotNull(loCategoryInfo);
847 assertNotNull(loCategoryInfo2);
848 assertTrue(EqualsBuilder.reflectionEquals(loCategoryInfo, loCategoryInfo2, new String[]{"desc","attributes","metaInfo"}));
849 checkRichText(loCategoryInfo.getDesc(), loCategoryInfo2.getDesc());
850 }
851
852 private static void checkLoDisplayLists(List<LoDisplayInfo> di1, List<LoDisplayInfo> di2) {
853 assertNotNull(di1);
854 assertNotNull(di2);
855 assertEquals(di1.size(), di2.size());
856 for (int i = 0; i < di1.size(); i++) {
857 checkLoDisplay(di1.get(i), di2.get(i));
858 }
859 }
860
861 private static void checkLo(LoInfo li1, LoInfo li2) {
862 assertNotNull(li1);
863 assertNotNull(li2);
864
865 assertTrue(EqualsBuilder.reflectionEquals(li1, li2, new String[]{"desc","attributes","metaInfo"}));
866 checkRichText(li1.getDesc(), li2.getDesc());
867 }
868
869 private static void checkRichText(RichTextInfo desc, RichTextInfo desc2) {
870 assertNotNull(desc);
871 assertNotNull(desc2);
872
873 assertTrue(EqualsBuilder.reflectionEquals(desc, desc2));
874 }
875
876 private static StatementTreeViewInfo createStatementTree() {
877
878
879
880
881
882
883
884 List<StatementTreeViewInfo> subStatements = new ArrayList<StatementTreeViewInfo>(3);
885 List<ReqComponentInfo> reqCompList1 = new ArrayList<ReqComponentInfo>(3);
886 List<ReqComponentInfo> reqCompList2 = new ArrayList<ReqComponentInfo>(3);
887
888
889 ReqComponentInfo rc1 = new ReqComponentInfo();
890 rc1.setDesc(toRichText("REQCOMP-1"));
891 rc1.setType("kuali.reqComponent.type.course.courseset.completed.all");
892 ReqComponentInfo rc2 = new ReqComponentInfo();
893 rc2.setDesc(toRichText("REQCOMP-2"));
894 rc2.setType("kuali.reqComponent.type.course.courseset.gpa.min");
895 ReqComponentInfo rc3 = new ReqComponentInfo();
896 rc3.setDesc(toRichText("REQCOMP-3"));
897 rc3.setType("kuali.reqComponent.type.course.courseset.completed.nof");
898 ReqComponentInfo rc4 = new ReqComponentInfo();
899 rc4.setDesc(toRichText("REQCOMP-4"));
900 rc4.setType("kuali.reqComponent.type.course.permission.instructor.required");
901
902
903 StatementTreeViewInfo statementTree = new StatementTreeViewInfo();
904 statementTree.setDesc(toRichText("STMT-1"));
905 statementTree.setOperator(StatementOperatorTypeKey.OR);
906 statementTree.setType("kuali.statement.type.program.entrance");
907
908 StatementTreeViewInfo subTree1 = new StatementTreeViewInfo();
909 subTree1.setDesc(toRichText("STMT-2"));
910 subTree1.setOperator(StatementOperatorTypeKey.AND);
911 subTree1.setType("kuali.statement.type.program.entrance");
912
913 StatementTreeViewInfo subTree2 = new StatementTreeViewInfo();
914 subTree2.setDesc(toRichText("STMT-3"));
915 subTree2.setOperator(StatementOperatorTypeKey.AND);
916 subTree2.setType("kuali.statement.type.program.entrance");
917
918
919 reqCompList1.add(rc1);
920 reqCompList1.add(rc2);
921 subTree1.setReqComponents(reqCompList1);
922 reqCompList2.add(rc3);
923 reqCompList2.add(rc4);
924 subTree2.setReqComponents(reqCompList2);
925 subStatements.add(subTree1);
926 subStatements.add(subTree2);
927 statementTree.setStatements(subStatements);
928
929 return statementTree;
930 }
931
932 private static RichTextInfo toRichText(String text) {
933 RichTextInfo richTextInfo = new RichTextInfo();
934 if (text == null) {
935 return null;
936 }
937 richTextInfo.setPlain(text);
938 richTextInfo.setFormatted("<p>" + text + "</p>");
939 return richTextInfo;
940 }
941
942 @Test(expected=DoesNotExistException.class)
943 public void testUpdateProgramRequirement() throws Exception {
944 ProgramRequirementInfo progReq = programService.createProgramRequirement(createProgramRequirementTestData());
945 StatementTreeViewInfo treeView = progReq.getStatement();
946
947 List<ReqComponentInfo> reqCompList1 = new ArrayList<ReqComponentInfo>(3);
948 ReqComponentInfo rc1 = new ReqComponentInfo();
949 rc1.setDesc(toRichText("REQCOMP-1"));
950 rc1.setType("kuali.reqComponent.type.course.courseset.completed.all");
951 ReqComponentInfo rc2 = new ReqComponentInfo();
952 rc2.setDesc(toRichText("REQCOMP-2"));
953 rc2.setType("kuali.reqComponent.type.course.courseset.gpa.min");
954 StatementTreeViewInfo subTree1 = new StatementTreeViewInfo();
955 subTree1.setDesc(toRichText("STMT-5"));
956 subTree1.setOperator(StatementOperatorTypeKey.AND);
957 subTree1.setType("kuali.statement.type.program.entrance");
958 reqCompList1.add(rc1);
959 reqCompList1.add(rc2);
960 subTree1.setReqComponents(reqCompList1);
961
962 StatementTreeViewInfo oldSubTree1 = treeView.getStatements().get(0);
963 treeView.getStatements().set(0, subTree1);
964 ProgramRequirementInfo updated = programService.updateProgramRequirement(progReq);
965 checkProgramRequirement(progReq, updated);
966 statementService.getStatement(oldSubTree1.getId());
967 }
968
969 @Test
970 @Ignore public void testDeleteMajorDiscipline() throws IllegalArgumentException, SecurityException, IntrospectionException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchFieldException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, AlreadyExistsException, DataValidationErrorException {
971 MajorDisciplineDataGenerator generator = new MajorDisciplineDataGenerator();
972 MajorDisciplineInfo majorDisciplineInfo = generator.getMajorDisciplineInfoTestData();
973 assertNotNull(majorDisciplineInfo);
974 fixLoCategoryIds(majorDisciplineInfo.getLearningObjectives());
975 MajorDisciplineInfo createdMD = programService.createMajorDiscipline(majorDisciplineInfo);
976 assertNotNull(createdMD);
977 assertEquals(ProgramAssemblerConstants.DRAFT, createdMD.getState());
978 assertEquals(ProgramAssemblerConstants.MAJOR_DISCIPLINE, createdMD.getType());
979 assertEquals("00f5f8c5-fff1-4c8b-92fc-789b891e0849", createdMD.getCredentialProgramId());
980
981 String majorDisciplineId = createdMD.getId();
982 MajorDisciplineInfo retrievedMD = programService.getMajorDiscipline(majorDisciplineId);
983 assertNotNull(retrievedMD);
984
985 programService.deleteMajorDiscipline(majorDisciplineId);
986 try {
987 retrievedMD = programService.getMajorDiscipline(majorDisciplineId);
988 fail("Retrieval of deleted MajorDiscipline should have thrown exception");
989 } catch (DoesNotExistException e) {}
990 }
991
992 private void fixLoCategoryIds(List<LoDisplayInfo> loDisplayInfoList) {
993 for (LoDisplayInfo parentLo : loDisplayInfoList) {
994 fixLoCategoryId(parentLo.getLoCategoryInfoList());
995 fixLoCategoryIds(parentLo.getLoDisplayInfoList());
996 }
997 }
998 private void fixLoCategoryId(List<LoCategoryInfo> loCategoryInfoList) {
999 loCategoryInfoList.get(1).setId(OTHER_LO_CAT_ID);
1000 }
1001
1002 @Test
1003 public void testUpdateMajorDiscipline() throws IllegalArgumentException, SecurityException, IntrospectionException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchFieldException, DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, VersionMismatchException, OperationFailedException, PermissionDeniedException {
1004 MajorDisciplineDataGenerator generator = new MajorDisciplineDataGenerator();
1005 MajorDisciplineInfo majorDisciplineInfo = generator.getMajorDisciplineInfoTestData();
1006 assertNotNull(majorDisciplineInfo);
1007
1008 MajorDisciplineInfo major = programService.getMajorDiscipline("d4ea77dd-b492-4554-b104-863e42c5f8b7");
1009 assertNotNull(major);
1010
1011
1012 assertNotNull(major.getCode());
1013 assertEquals("ANTH", major.getCode());
1014 assertNotNull(major.getType());
1015 assertEquals(ProgramAssemblerConstants.MAJOR_DISCIPLINE, major.getType());
1016 assertNotNull(major.getState());
1017 assertEquals(ProgramAssemblerConstants.ACTIVE, major.getState());
1018 assertNotNull(major.getId());
1019 assertEquals("d4ea77dd-b492-4554-b104-863e42c5f8b7", major.getId());
1020 assertNotNull(major.getShortTitle());
1021 assertEquals("Anthro", major.getShortTitle());
1022 assertNotNull(major.getLongTitle());
1023 assertEquals("Anthropology", major.getLongTitle());
1024
1025
1026 major.getCampusLocations().add("MAIN");
1027 major.setLongTitle(major.getLongTitle() + "-updated");
1028 major.getAttributes().put("PIES", "APPLE");
1029
1030 major.setCip2000Code(major.getCip2000Code() + "-updated");
1031 major.setDiplomaTitle(major.getDiplomaTitle() + "-updated");
1032 major.setTranscriptTitle(major.getTranscriptTitle() + "-updated");
1033
1034
1035
1036 major.getCatalogDescr().setPlain(major.getCatalogDescr().getPlain() + "-updated");
1037 major.getCatalogPublicationTargets().add("kuali.lu.publication.GradCatalog");
1038
1039 for (String orgInfoId : major.getDivisionsFinancialControl()) {
1040 orgInfoId = orgInfoId + "-updated";
1041 }
1042 for (String orgInfoId : major.getUnitsDeployment()) {
1043 orgInfoId = orgInfoId + "-updated";
1044 }
1045
1046 List<String> reqIds = new ArrayList<String>();
1047 reqIds.add("REQ-200");
1048 reqIds.add("REQ-300");
1049 major.setProgramRequirements(reqIds);
1050
1051
1052 MajorDisciplineInfo updatedMD = programService.updateMajorDiscipline(major);
1053
1054
1055 verifyUpdate(updatedMD);
1056 assertEquals(2, updatedMD.getProgramRequirements().size());
1057
1058
1059 MajorDisciplineInfo retrievedMD = programService.getMajorDiscipline(major.getId());
1060 verifyUpdate(retrievedMD);
1061 assertEquals(2, retrievedMD.getProgramRequirements().size());
1062
1063
1064 }
1065
1066 @Test
1067 public void testUpdateMajorDisciplineRemoveRule() throws IllegalArgumentException, SecurityException, IntrospectionException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchFieldException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, VersionMismatchException {
1068 MajorDisciplineInfo major = programService.getMajorDiscipline("d4ea77dd-b492-4554-b104-863e42c5f8b7");
1069
1070 List<String> reqIds = new ArrayList<String>(1);
1071 ProgramRequirementInfo req1 = programService.createProgramRequirement(createProgramRequirementTestData());
1072 reqIds.add(req1.getId());
1073 major.setProgramRequirements(reqIds);
1074
1075
1076 MajorDisciplineInfo updatedMD = programService.updateMajorDiscipline(major);
1077 MajorDisciplineInfo retrievedMD = programService.getMajorDiscipline(major.getId());
1078
1079
1080 programService.deleteProgramRequirement(req1.getId());
1081 retrievedMD.getProgramRequirements().clear();
1082 MajorDisciplineInfo updatedMD2 = programService.updateMajorDiscipline(retrievedMD);
1083 assertEquals(0, updatedMD2.getProgramRequirements().size());
1084 retrievedMD = programService.getMajorDiscipline(major.getId());
1085 assertEquals(0, retrievedMD.getProgramRequirements().size());
1086 }
1087
1088
1089 private void verifyUpdate(MajorDisciplineInfo updatedMD) {
1090 assertNotNull(updatedMD);
1091
1092 assertEquals(3, updatedMD.getAttributes().size());
1093 assertNotNull(updatedMD.getAttributes().get("PIES"));
1094 assertEquals("APPLE", updatedMD.getAttributes().get("PIES"));
1095
1096 assertEquals(3, updatedMD.getCampusLocations().size());
1097 assertEquals("NO", updatedMD.getCampusLocations().get(0));
1098 assertEquals("SO", updatedMD.getCampusLocations().get(1));
1099 assertEquals("MAIN", updatedMD.getCampusLocations().get(2));
1100
1101
1102
1103 assertNotNull(updatedMD.getCatalogDescr());
1104 assertEquals("This is the catalog description-updated", updatedMD.getCatalogDescr().getPlain());
1105
1106 assertNotNull(updatedMD.getCatalogPublicationTargets());
1107 assertEquals(2, updatedMD.getCatalogPublicationTargets().size());
1108
1109 assertEquals("Anthropology-updated", updatedMD.getLongTitle());
1110 assertEquals("45.0202-updated", updatedMD.getCip2000Code());
1111 assertEquals("TRANSCRIPT-TITLE-updated", updatedMD.getTranscriptTitle());
1112 assertEquals("DIPLOMA-TITLE-updated", updatedMD.getDiplomaTitle() );
1113 }
1114
1115 @Test
1116 public void testCreateBaccCredentialProgram() throws IllegalArgumentException, SecurityException, IntrospectionException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchFieldException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
1117 CredentialProgramDataGenerator generator = new CredentialProgramDataGenerator(ProgramAssemblerConstants.BACCALAUREATE_PROGRAM);
1118 CredentialProgramInfo credentialProgramInfo = null;
1119 assertNotNull(credentialProgramInfo = generator.getCPTestData());
1120 List<String> coreProgramIds = new ArrayList<String>();
1121 coreProgramIds.add("00f5f8c5-fff1-4c8b-92fc-789b891e0849");
1122 credentialProgramInfo.setCoreProgramIds(coreProgramIds);
1123 CredentialProgramInfo createdCP = programService.createCredentialProgram(credentialProgramInfo);
1124 assertNotNull(createdCP);
1125 assertEquals(ProgramAssemblerConstants.DRAFT, createdCP.getState());
1126 assertEquals(ProgramAssemblerConstants.BACCALAUREATE_PROGRAM, createdCP.getCredentialProgramType());
1127 }
1128
1129 @Test
1130 public void testDeleteBaccCredentialProgram() throws DoesNotExistException, InvalidParameterException, MissingParameterException, PermissionDeniedException, OperationFailedException {
1131 String credentialProgramId = "d02dbbd3-20e2-410d-ab52-1bd6d362748b";
1132 CredentialProgramInfo retrievedCP = programService.getCredentialProgram(credentialProgramId);
1133 assertNotNull(retrievedCP);
1134
1135 try{
1136 programService.deleteCredentialProgram(credentialProgramId);
1137 try {
1138 retrievedCP = programService.getCredentialProgram(credentialProgramId);
1139 fail("Retrieval of deleted CredentialProgram should have thrown exception");
1140 } catch (DoesNotExistException e) {}
1141 }catch (OperationFailedException e) {}
1142 }
1143
1144 @Test
1145 public void testUpdateBaccCredentialProgram() throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, VersionMismatchException, OperationFailedException, PermissionDeniedException {
1146 String credentialProgramId = "d02dbbd3-20e2-410d-ab52-1bd6d362748b";
1147 CredentialProgramInfo credentialProgramInfo = programService.getCredentialProgram(credentialProgramId);
1148 assertNotNull(credentialProgramInfo);
1149
1150
1151 assertEquals("BS", credentialProgramInfo.getCode());
1152 assertEquals("B.S.", credentialProgramInfo.getShortTitle());
1153 assertEquals("Bachelor of Science", credentialProgramInfo.getLongTitle());
1154 assertEquals("Bachelor of Science", credentialProgramInfo.getDescr().getPlain());
1155 assertEquals(ProgramAssemblerConstants.ACTIVE, credentialProgramInfo.getState());
1156 assertEquals("52", credentialProgramInfo.getInstitution().getOrgId());
1157 assertEquals(ProgramAssemblerConstants.UNDERGRAD_PROGRAM_LEVEL, credentialProgramInfo.getProgramLevel());
1158
1159
1160
1161
1162
1163 credentialProgramInfo.setProgramLevel(ProgramAssemblerConstants.GRADUATE_PROGRAM_LEVEL);
1164 AdminOrgInfo institution = new AdminOrgInfo();
1165 institution.setOrgId("51");
1166 credentialProgramInfo.setInstitution(institution);
1167
1168
1169 CredentialProgramInfo updatedCP = programService.updateCredentialProgram(credentialProgramInfo);
1170
1171
1172 verifyUpdate(updatedCP);
1173
1174
1175 CredentialProgramInfo retrievedCP = programService.getCredentialProgram(credentialProgramInfo.getId());
1176 verifyUpdate(retrievedCP);
1177
1178
1179
1180 }
1181
1182 private void verifyUpdate(CredentialProgramInfo updatedCP) {
1183 assertNotNull(updatedCP);
1184
1185
1186
1187
1188 assertEquals(ProgramAssemblerConstants.GRADUATE_PROGRAM_LEVEL, updatedCP.getProgramLevel());
1189 assertEquals("51", updatedCP.getInstitution().getOrgId());
1190 }
1191
1192 @Test
1193 public void testCreateCoreProgram() throws IllegalArgumentException, SecurityException, IntrospectionException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchFieldException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
1194 CoreProgramDataGenerator generator = new CoreProgramDataGenerator();
1195 CoreProgramInfo coreProgramInfo = null;
1196 assertNotNull(coreProgramInfo = generator.getCoreProgramTestData());
1197 CoreProgramInfo createdCP = programService.createCoreProgram(coreProgramInfo);
1198 assertNotNull(createdCP);
1199 assertEquals(ProgramAssemblerConstants.DRAFT, createdCP.getState());
1200 assertEquals(ProgramAssemblerConstants.CORE_PROGRAM, createdCP.getType());
1201 }
1202
1203 @Test
1204 public void testUpdateVariationsByMajorDiscipline() throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DataValidationErrorException, VersionMismatchException{
1205 MajorDisciplineInfo majorDisciplineInfo = null;
1206
1207 majorDisciplineInfo = programService.getMajorDiscipline("d4ea77dd-b492-4554-b104-863e42c5f8b7");
1208 assertNotNull(majorDisciplineInfo);
1209
1210 List<ProgramVariationInfo> pvInfos = majorDisciplineInfo.getVariations();
1211 assertNotNull(pvInfos);
1212
1213
1214 ProgramVariationInfo pvInfo = pvInfos.get(0);
1215
1216 pvInfo.setLongTitle(pvInfo.getLongTitle() + "-updated");
1217 pvInfo.setCode(pvInfo.getCode() + "-updated");
1218 pvInfo.setShortTitle(pvInfo.getShortTitle() + "-updated");
1219 RichTextInfo testDesc = pvInfo.getDescr();
1220 testDesc.setPlain(testDesc.getPlain() + "-updated");
1221 pvInfo.setDescr(testDesc);
1222 pvInfo.setCip2000Code(pvInfo.getCip2000Code() + "-updated");
1223 pvInfo.setCip2010Code(pvInfo.getCip2010Code() + "-updated");
1224 pvInfo.setTranscriptTitle("transcriptTitle-updated");
1225 pvInfo.setDiplomaTitle(pvInfo.getDiplomaTitle() + "-updated");
1226
1227 List<String> campusLocations = new ArrayList<String>();
1228 campusLocations.add(CourseAssemblerConstants.COURSE_CAMPUS_LOCATION_CD_NORTH);
1229 campusLocations.add(CourseAssemblerConstants.COURSE_CAMPUS_LOCATION_CD_SOUTH);
1230 pvInfo.setCampusLocations(campusLocations);
1231
1232 List<String> testOrgs = new ArrayList<String>();
1233 testOrgs.add("testOrgId");
1234 if (pvInfo.getDivisionsContentOwner() != null) {
1235 pvInfo.getDivisionsContentOwner().clear();
1236 pvInfo.getDivisionsContentOwner().add("testOrgId");
1237 }
1238 else {
1239 pvInfo.setDivisionsContentOwner(testOrgs);
1240 }
1241
1242
1243 MajorDisciplineInfo updatedMD = programService.updateMajorDiscipline(majorDisciplineInfo);
1244 List<ProgramVariationInfo> updatedPvInfos = updatedMD.getVariations();
1245 assertNotNull(updatedPvInfos);
1246
1247
1248 verifyUpdatedPVinList(pvInfo, updatedPvInfos);
1249
1250
1251 List<ProgramVariationInfo> retrievedPVs = programService.getVariationsByMajorDisciplineId(majorDisciplineInfo.getId());
1252 assertNotNull(retrievedPVs);
1253
1254
1255 verifyUpdatedPVinList(pvInfo, retrievedPVs);
1256 }
1257
1258 private void verifyUpdatedPVinList(ProgramVariationInfo pvInfo, List<ProgramVariationInfo> updatedPvInfos) {
1259 boolean found = false;
1260 for (ProgramVariationInfo updatedPV : updatedPvInfos) {
1261 if (updatedPV.getId().equals(pvInfo.getId()) && updatedPV.getState().equals("Active")) {
1262 verifyUpdate(pvInfo, updatedPV);
1263 found = true;
1264 break;
1265 }
1266 }
1267 if (!found) {
1268 fail("Unable to find updated ProgramVariationInfo for comparison");
1269 }
1270 }
1271
1272 private void verifyUpdate(ProgramVariationInfo source, ProgramVariationInfo target) {
1273 assertNotNull(target);
1274
1275 assertEquals(source.getDescr().getPlain(), target.getDescr().getPlain());
1276 assertEquals(source.getLongTitle(), target.getLongTitle());
1277 assertEquals(source.getShortTitle(), target.getShortTitle());
1278
1279 assertEquals(source.getCip2000Code(), target.getCip2000Code());
1280 assertEquals(source.getCip2010Code(), target.getCip2010Code());
1281 assertEquals(source.getTranscriptTitle(), target.getTranscriptTitle());
1282 assertEquals(source.getDiplomaTitle(), target.getDiplomaTitle());
1283
1284 assertNotNull(target.getCampusLocations());
1285 for(String loc : target.getCampusLocations()){
1286 assertTrue(CourseAssemblerConstants.COURSE_CAMPUS_LOCATION_CD_NORTH.equals(loc) || CourseAssemblerConstants.COURSE_CAMPUS_LOCATION_CD_SOUTH.equals(loc));
1287 }
1288
1289 assertNotNull(target.getDivisionsContentOwner());
1290
1291
1292
1293 }
1294
1295 @Test
1296 public void testCreateVariationsByMajorDiscipline() throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, DataValidationErrorException, VersionMismatchException, PermissionDeniedException{
1297 MajorDisciplineInfo majorDisciplineInfo = null;
1298
1299 majorDisciplineInfo = programService.getMajorDiscipline("d4ea77dd-b492-4554-b104-863e42c5f8b7");
1300 assertNotNull(majorDisciplineInfo);
1301
1302 List<ProgramVariationInfo> pvInfos = majorDisciplineInfo.getVariations();
1303 assertNotNull(pvInfos);
1304
1305 ProgramVariationInfo pvInfoS = pvInfos.get(0);
1306 ProgramVariationInfo pvInfoT = new ProgramVariationInfo();
1307
1308 BeanUtils.copyProperties(pvInfoS, pvInfoT, new String[]{"id"});
1309
1310 pvInfoT.setLongTitle(pvInfoT.getLongTitle() + "-created");
1311 pvInfoT.setShortTitle(pvInfoT.getShortTitle() + "-created");
1312 RichTextInfo testDesc = pvInfoT.getDescr();
1313 testDesc.setPlain(testDesc.getPlain() + "-created");
1314 pvInfoT.setDescr(testDesc);
1315 pvInfoT.setCip2000Code(pvInfoT.getCip2000Code() + "-created");
1316 pvInfoT.setCip2010Code(pvInfoT.getCip2010Code() + "-created");
1317 pvInfoT.setTranscriptTitle(pvInfoT.getTranscriptTitle() + "-created");
1318 pvInfoT.setDiplomaTitle(pvInfoT.getDiplomaTitle() + "-created");
1319
1320
1321 pvInfos.add(pvInfoT);
1322 MajorDisciplineInfo updatedMD = programService.updateMajorDiscipline(majorDisciplineInfo);
1323 List<ProgramVariationInfo> updatedPvInfos = updatedMD.getVariations();
1324 assertNotNull(updatedPvInfos);
1325 assertEquals(3, updatedPvInfos.size());
1326
1327
1328 verifyUpdatedPVinList(pvInfoT, updatedPvInfos);
1329
1330
1331 MajorDisciplineInfo retrievedMD = programService.getMajorDiscipline(majorDisciplineInfo.getId());
1332 assertEquals(3, retrievedMD.getVariations().size());
1333
1334 List<ProgramVariationInfo> retrievedPVs = programService.getVariationsByMajorDisciplineId(majorDisciplineInfo.getId());
1335 assertNotNull(retrievedPVs);
1336 assertEquals(3, updatedPvInfos.size());
1337
1338 verifyUpdatedPVinList(pvInfoT, retrievedPVs);
1339 }
1340
1341 @Test
1342 public void testDeleteVariationsByMajorDiscipline() throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DataValidationErrorException, VersionMismatchException{
1343 MajorDisciplineInfo majorDisciplineInfo = null;
1344
1345 majorDisciplineInfo = programService.getMajorDiscipline("d4ea77dd-b492-4554-b104-863e42c5f8b7");
1346 assertNotNull(majorDisciplineInfo);
1347
1348 List<ProgramVariationInfo> pvInfos = majorDisciplineInfo.getVariations();
1349 assertNotNull(pvInfos);
1350
1351
1352 String var1 = pvInfos.get(1).getId();
1353 pvInfos.remove(1);
1354 MajorDisciplineInfo updatedMD = programService.updateMajorDiscipline(majorDisciplineInfo);
1355 List<ProgramVariationInfo> updatedPvInfos = updatedMD.getVariations();
1356 assertNotNull(updatedPvInfos);
1357 assertEquals(2, updatedPvInfos.size());
1358
1359
1360 MajorDisciplineInfo retrievedMD = programService.getMajorDiscipline(majorDisciplineInfo.getId());
1361 assertEquals(2, retrievedMD.getVariations().size());
1362
1363 List<ProgramVariationInfo> retrievedPVs = programService.getVariationsByMajorDisciplineId(majorDisciplineInfo.getId());
1364 assertNotNull(retrievedPVs);
1365 for(ProgramVariationInfo pvi : retrievedPVs){
1366 if(pvi.getId().equals(var1)){
1367 assertEquals("Inactive", pvi.getState());
1368 }
1369 }
1370 }
1371
1372 @Test(expected=DoesNotExistException.class)
1373 public void testDeleteProgramRequirement() throws Exception {
1374 ProgramRequirementInfo progReq = createProgramRequirementTestData();
1375 ProgramRequirementInfo createdProgReq = programService.createProgramRequirement(progReq);
1376 programService.deleteProgramRequirement(createdProgReq.getId());
1377 programService.getProgramRequirement(createdProgReq.getId(), null, null);
1378 }
1379
1380 @Test
1381 public void testUpdateCoreProgram() throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DataValidationErrorException, VersionMismatchException {
1382 CoreProgramInfo core = null;
1383 core = programService.getCoreProgram("00f5f8c5-fff1-4c8b-92fc-789b891e0849");
1384
1385
1386 assertNotNull(core);
1387 assertEquals("BS", core.getCode());
1388 assertNotNull(core.getShortTitle());
1389 assertEquals("B.S.", core.getShortTitle());
1390 assertNotNull(core.getLongTitle());
1391 assertEquals("Bachelor of Science", core.getLongTitle());
1392 assertNotNull(core.getDescr());
1393 assertEquals("Anthropology Major", core.getDescr().getPlain());
1394 assertEquals(ProgramAssemblerConstants.CORE_PROGRAM, core.getType());
1395 assertEquals(ProgramAssemblerConstants.ACTIVE, core.getState());
1396
1397
1398 core.setCode(core.getCode() + "-updated");
1399 core.setShortTitle(core.getShortTitle() + "-updated");
1400 core.setLongTitle(core.getLongTitle() + "-updated");
1401 core.setTranscriptTitle(core.getTranscriptTitle() + "-updated");
1402 core.setState(ProgramAssemblerConstants.RETIRED);
1403
1404
1405 CoreProgramInfo updatedCP = programService.updateCoreProgram(core);
1406
1407
1408 verifyUpdate(updatedCP);
1409
1410
1411 CoreProgramInfo retrievedCP = programService.getCoreProgram(core.getId());
1412 verifyUpdate(retrievedCP);
1413
1414
1415 }
1416
1417 private void verifyUpdate(CoreProgramInfo updatedCP) {
1418 assertNotNull(updatedCP);
1419 assertEquals("BS-updated", updatedCP.getCode());
1420 assertEquals("B.S.-updated", updatedCP.getShortTitle());
1421 assertEquals("Bachelor of Science-updated", updatedCP.getLongTitle());
1422 assertEquals("TRANSCRIPT-TITLE-updated", updatedCP.getTranscriptTitle());
1423 assertEquals(ProgramAssemblerConstants.RETIRED, updatedCP.getState());
1424 }
1425
1426 @Test
1427 public void testDeleteCoreProgram() throws AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, IllegalArgumentException, SecurityException, IntrospectionException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchFieldException, DoesNotExistException {
1428 CoreProgramDataGenerator generator = new CoreProgramDataGenerator();
1429 CoreProgramInfo coreProgramInfo = generator.getCoreProgramTestData();
1430
1431 assertNotNull(coreProgramInfo);
1432 fixLoCategoryIds(coreProgramInfo.getLearningObjectives());
1433 CoreProgramInfo createdCP = programService.createCoreProgram(coreProgramInfo);
1434 assertNotNull(createdCP);
1435 assertEquals(ProgramAssemblerConstants.DRAFT, createdCP.getState());
1436 assertEquals(ProgramAssemblerConstants.CORE_PROGRAM, createdCP.getType());
1437
1438
1439 String coreProgramId = createdCP.getId();
1440 CoreProgramInfo retrievedCP = programService.getCoreProgram(coreProgramId);
1441 assertNotNull(retrievedCP);
1442
1443 try{
1444 programService.deleteCoreProgram(coreProgramId);
1445 try {
1446 retrievedCP = programService.getCoreProgram(coreProgramId);
1447 fail("Retrieval of deleted coreProgram should have thrown exception");
1448 } catch (DoesNotExistException e) {}
1449 }catch (OperationFailedException e) {}
1450
1451 }
1452
1453 @Test
1454 public void testCreditsProgramRequirement() throws AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException {
1455 ProgramRequirementInfo progReq = createProgramRequirementTestData();
1456 progReq.setMinCredits(3);
1457 progReq.setMaxCredits(45);
1458 ProgramRequirementInfo createdProgReq = programService.createProgramRequirement(progReq);
1459 assertEquals("3", Integer.toString(createdProgReq.getMinCredits()));
1460 assertEquals("45", Integer.toString(createdProgReq.getMaxCredits()));
1461
1462 ProgramRequirementInfo progReq2 = programService.getProgramRequirement(createdProgReq.getId(), null, null);
1463 assertEquals("3", Integer.toString(progReq2.getMinCredits()));
1464 assertEquals("45", Integer.toString(progReq2.getMaxCredits()));
1465 }
1466
1467 private class ServiceMethodInvocationData {
1468 String methodName;
1469 Object[] parameters;
1470 Class<?>[] paramterTypes;
1471 }
1472
1473 private void invokeForExpectedException(Collection<ServiceMethodInvocationData> methods, Class<? extends Exception> expectedExceptionClass) throws Exception {
1474 for(ServiceMethodInvocationData methodData : methods) {
1475 Method method = programService.getClass().getMethod(methodData.methodName, methodData.paramterTypes);
1476 Throwable expected = null;
1477 Exception unexpected = null;
1478 try {
1479 method.invoke(programService, methodData.parameters);
1480 }
1481 catch(InvocationTargetException ex) {
1482 if(ex.getCause() != null && ex.getCause().getClass().equals(expectedExceptionClass)) {
1483 expected = ex.getCause();
1484 }
1485 else {
1486 unexpected = ex;
1487 unexpected.printStackTrace();
1488 }
1489 }
1490 catch(Exception other) {
1491 unexpected = other;
1492 }
1493 finally {
1494 assertNotNull("An exception of class: " + expectedExceptionClass.toString() + " was expected, but the method: " + methodData.methodName + " threw this exception: " + unexpected, expected);
1495 }
1496 }
1497 }
1498
1499 @Test
1500 public void testGetVersionMethodsForInvalidParameters() throws Exception {
1501 String[] getVersionMethods = {"getVersionBySequenceNumber", "getVersions", "getFirstVersion", "getVersionsInDateRange", "getCurrentVersion", "getCurrentVersionOnDate"};
1502
1503
1504 Object[][] getVersionParams = {new Object[3], new Object[2], new Object[2], new Object[4], new Object[2], new Object[3]};
1505
1506
1507 Class<?>[][] getVersionParamTypes = {{String.class, String.class, Long.class},
1508 {String.class, String.class},
1509 {String.class, String.class},
1510 {String.class, String.class, Date.class, Date.class},
1511 {String.class, String.class},
1512 {String.class, String.class, Date.class}};
1513
1514 String badRefObjectTypeURI = "BADBADBAD";
1515 Collection<ServiceMethodInvocationData> methods = new ArrayList<ServiceMethodInvocationData>(getVersionMethods.length);
1516 for(int i = 0; i < getVersionMethods.length; i++) {
1517 ServiceMethodInvocationData invocationData = new ServiceMethodInvocationData();
1518 invocationData.methodName = getVersionMethods[i];
1519
1520
1521 getVersionParams[i][0] = badRefObjectTypeURI;
1522
1523 invocationData.parameters = getVersionParams[i];
1524 invocationData.paramterTypes = getVersionParamTypes[i];
1525
1526 methods.add(invocationData);
1527 }
1528
1529 invokeForExpectedException(methods, InvalidParameterException.class);
1530 }
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543 @Test
1544 public void testCallDummyMethods() throws Exception {
1545
1546
1547 Method[] serviceMethods = ProgramService.class.getMethods();
1548 Map<String, Method> methodMap = new HashMap<String, Method>();
1549
1550 for(Method m : serviceMethods) {
1551
1552 if(!methodMap.containsKey(m.getName())) {
1553 methodMap.put(m.getName(), m);
1554 }
1555 }
1556
1557 for(String s : DUMMY_SERVICE_METHODS) {
1558 Method dummyMethod = methodMap.get(s);
1559
1560 if(dummyMethod == null) {
1561 throw new Exception("No method " + s + " defined in ProgramService");
1562 }
1563
1564
1565 Object[] params = new Object[dummyMethod.getParameterTypes().length];
1566
1567 Object returned = dummyMethod.invoke(programService, params);
1568
1569 assertTrue("The invocation of " + s + " returned a non-null value", returned == null);
1570 }
1571 }
1572
1573 @Test
1574 public void testCoreProgramVersioning() throws Exception {
1575 CoreProgramDataGenerator dataGen = new CoreProgramDataGenerator();
1576 CoreProgramInfo coreData = dataGen.getCoreProgramTestData();
1577
1578 coreData.getProgramRequirements().clear();
1579
1580 CoreProgramInfo core = programService.createCoreProgram(coreData);
1581
1582 CoreProgramInfo newCore = programService.createNewCoreProgramVersion(core.getVersionInfo().getVersionIndId(), "test core program versioning");
1583
1584 assertNotNull(newCore);
1585
1586 programService.setCurrentCoreProgramVersion(newCore.getId(), null);
1587
1588
1589 CoreProgramInfo secondVersion = null;
1590
1591 try {
1592 secondVersion = programService.createNewCoreProgramVersion(core.getVersionInfo().getVersionIndId(), "test core program second version");
1593 assertTrue(true);
1594 }
1595 catch (Exception e) {
1596 assertTrue(false);
1597 }
1598
1599 assertNotNull(secondVersion);
1600
1601 assertTrue(newCore.getVersionInfo().getSequenceNumber() != secondVersion.getVersionInfo().getSequenceNumber());
1602
1603 }
1604
1605 }