001/**
002 * Copyright 2010 The Kuali Foundation Licensed under the
003 * Educational Community License, Version 2.0 (the "License"); you may
004 * not use this file except in compliance with the License. You may
005 * obtain a copy of the License at
006 *
007 * http://www.osedu.org/licenses/ECL-2.0
008 *
009 * Unless required by applicable law or agreed to in writing,
010 * software distributed under the License is distributed on an "AS IS"
011 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
012 * or implied. See the License for the specific language governing
013 * permissions and limitations under the License.
014 */
015
016package org.kuali.student.lum.lu.service.impl;
017
018import edu.emory.mathcs.backport.java.util.Collections;
019import org.junit.Assert;
020import org.junit.Before;
021import org.junit.FixMethodOrder;
022import org.junit.Test;
023import org.kuali.rice.core.api.criteria.PredicateFactory;
024import org.kuali.rice.core.api.criteria.QueryByCriteria;
025import org.kuali.student.common.test.spring.AbstractServiceTest;
026import org.kuali.student.common.test.spring.Client;
027import org.kuali.student.common.test.spring.Dao;
028import org.kuali.student.common.test.spring.Daos;
029import org.kuali.student.common.test.spring.PersistenceFileLocation;
030import org.kuali.student.common.test.util.ContextInfoTestUtility;
031import org.kuali.student.r2.common.dto.AmountInfo;
032import org.kuali.student.r2.common.dto.AttributeInfo;
033import org.kuali.student.r2.common.dto.ContextInfo;
034import org.kuali.student.r2.common.dto.CurrencyAmountInfo;
035import org.kuali.student.r2.common.dto.RichTextInfo;
036import org.kuali.student.r2.common.dto.StatusInfo;
037import org.kuali.student.r2.common.dto.TimeAmountInfo;
038import org.kuali.student.r2.common.dto.ValidationResultInfo;
039import org.kuali.student.r2.common.exceptions.AlreadyExistsException;
040import org.kuali.student.r2.common.exceptions.CircularRelationshipException;
041import org.kuali.student.r2.common.exceptions.DataValidationErrorException;
042import org.kuali.student.r2.common.exceptions.DependentObjectsExistException;
043import org.kuali.student.r2.common.exceptions.DoesNotExistException;
044import org.kuali.student.r2.common.exceptions.IllegalVersionSequencingException;
045import org.kuali.student.r2.common.exceptions.InvalidParameterException;
046import org.kuali.student.r2.common.exceptions.MissingParameterException;
047import org.kuali.student.r2.common.exceptions.OperationFailedException;
048import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
049import org.kuali.student.r2.common.exceptions.ReadOnlyException;
050import org.kuali.student.r2.common.exceptions.UnsupportedActionException;
051import org.kuali.student.r2.common.exceptions.VersionMismatchException;
052import org.kuali.student.common.util.security.ContextUtils;
053import org.kuali.student.r2.common.util.date.DateFormatters;
054import org.kuali.student.r2.core.search.dto.SearchParamInfo;
055import org.kuali.student.r2.core.search.dto.SearchRequestInfo;
056import org.kuali.student.r2.core.search.dto.SearchResultCellInfo;
057import org.kuali.student.r2.core.search.dto.SearchResultInfo;
058import org.kuali.student.r2.core.search.dto.SearchResultRowInfo;
059import org.kuali.student.r2.core.versionmanagement.dto.VersionDisplayInfo;
060import org.kuali.student.r2.lum.clu.dto.AccreditationInfo;
061import org.kuali.student.r2.lum.clu.dto.AdminOrgInfo;
062import org.kuali.student.r2.lum.clu.dto.AffiliatedOrgInfo;
063import org.kuali.student.r2.lum.clu.dto.CluAccountingInfo;
064import org.kuali.student.r2.lum.clu.dto.CluCluRelationInfo;
065import org.kuali.student.r2.lum.clu.dto.CluFeeInfo;
066import org.kuali.student.r2.lum.clu.dto.CluFeeRecordInfo;
067import org.kuali.student.r2.lum.clu.dto.CluIdentifierInfo;
068import org.kuali.student.r2.lum.clu.dto.CluInfo;
069import org.kuali.student.r2.lum.clu.dto.CluInstructorInfo;
070import org.kuali.student.r2.lum.clu.dto.CluLoRelationInfo;
071import org.kuali.student.r2.lum.clu.dto.CluPublicationInfo;
072import org.kuali.student.r2.lum.clu.dto.CluResultInfo;
073import org.kuali.student.r2.lum.clu.dto.CluSetInfo;
074import org.kuali.student.r2.lum.clu.dto.CluSetTreeViewInfo;
075import org.kuali.student.r2.lum.clu.dto.FieldInfo;
076import org.kuali.student.r2.lum.clu.dto.LuCodeInfo;
077import org.kuali.student.r2.lum.clu.dto.MembershipQueryInfo;
078import org.kuali.student.r2.lum.clu.dto.ResultOptionInfo;
079import org.kuali.student.r2.lum.clu.service.CluService;
080import org.kuali.student.r2.lum.lu.dao.LuDao;
081import org.kuali.student.r2.lum.util.constants.CluServiceConstants;
082import org.springframework.beans.factory.annotation.Autowired;
083import org.springframework.test.context.ContextConfiguration;
084
085import java.text.ParseException;
086import java.util.ArrayList;
087import java.util.Arrays;
088import java.util.Comparator;
089import java.util.Date;
090import java.util.List;
091
092import static org.junit.Assert.assertEquals;
093import static org.junit.Assert.assertFalse;
094import static org.junit.Assert.assertNotNull;
095import static org.junit.Assert.assertNull;
096import static org.junit.Assert.assertTrue;
097import static org.junit.Assert.fail;
098import static org.junit.runners.MethodSorters.NAME_ASCENDING;
099
100@Daos({@Dao(value = "org.kuali.student.r2.lum.lu.dao.impl.LuDaoImpl", testSqlFile = "classpath:ks-lu.sql")})
101@PersistenceFileLocation("classpath:META-INF/lu-persistence.xml")
102@FixMethodOrder(NAME_ASCENDING)
103@ContextConfiguration(locations = {"classpath:course-test-context.xml"})
104public class TestCluServiceImpl extends AbstractServiceTest {
105
106    @Autowired
107    LuDao luDao;
108    @Client(value = "org.kuali.student.r2.lum.lu.service.impl.CluServiceImpl", additionalContextFile = "classpath:clu-additional-context.xml")
109    public CluService client;
110
111    private  CluResultInfo dto;
112    private ContextInfo contextInfo;
113
114    @Before
115    public void setUp(){
116        contextInfo = ContextInfoTestUtility.getEnglishContextInfo();
117        contextInfo.setPrincipalId("123");
118
119        dto = new CluResultInfo();
120        RichTextInfo desc1 = new RichTextInfo();
121        desc1.setPlain("Plain description");
122        dto.setDescr(desc1);
123        dto.setCluId("CLU-1");
124        dto.setStateKey("Suspended");
125        dto.setTypeKey("kuali.resultType.gradeCourseResult");
126        dto.setEffectiveDate(new Date());
127        dto.setExpirationDate(new Date());
128
129        List<ResultOptionInfo> resultOptions = new ArrayList<ResultOptionInfo>();
130        ResultOptionInfo option = new ResultOptionInfo();
131        RichTextInfo desc2 = new RichTextInfo();
132        desc2.setPlain("Plain description");
133        option.setDescr(desc2);
134        option.setEffectiveDate(new Date());
135        option.setExpirationDate(new Date());
136        option.setResultComponentId("kuali.resultComponent.grade.letter");
137        option.setStateKey("Suspended");
138        resultOptions.add(option);
139        dto.setResultOptions(resultOptions);
140    }
141
142
143
144    @Test
145    public void test00Clu() throws DoesNotExistException,
146            InvalidParameterException, MissingParameterException,
147            OperationFailedException, PermissionDeniedException {
148        // getClu
149
150        CluInfo clu = client.getClu("CLU-1", contextInfo);
151        assertNotNull(clu);
152        assertEquals(clu.getId(), "CLU-1");
153
154        try {
155            client.getClu("CLX-1", contextInfo);
156            fail("DoesNotExistException should have been thrown");
157        } catch (DoesNotExistException e) {
158            assertNotNull(e.getMessage());
159            assertEquals("CLX-1", e.getMessage());
160        }
161
162        try {
163            client.getClu(null, contextInfo);
164            fail("MissingParameterException should have been thrown");
165        } catch (MissingParameterException e) {
166            assertNotNull(e.getMessage());
167            assertEquals("cluId can not be null", e.getMessage());
168        }
169
170        // getClusByIdList
171        List<String> ids = new ArrayList<String>(1);
172        ids.add("CLU-2");
173        List<CluInfo> clus = client.getClusByIds(ids, contextInfo);
174        assertNotNull(clus);
175        assertEquals(1, clus.size());
176
177        ids.clear();
178        ids.add("CLX-42");
179        clus = client.getClusByIds(ids, contextInfo);
180        assertTrue(clus == null || clus.size() == 0);
181
182        try {
183            client.getClusByIds(null, contextInfo);
184            fail("MissingParameterException should have been thrown");
185        } catch (MissingParameterException e) {
186            assertNotNull(e.getMessage());
187            assertEquals("cluIds can not be null", e.getMessage());
188        }
189
190        // getCluIdsByLuType
191        ids = client.getCluIdsByLuType("luType.shell.program", "STATE2", contextInfo);
192        assertNotNull(null != ids);
193        assertEquals(1, ids.size());
194        assertEquals("CLU-2", ids.get(0));
195
196        ids = client.getCluIdsByLuType("LUTYPE-1X", "STATE1", contextInfo);
197        assertTrue(ids == null || ids.size() == 0);
198        ids = client.getCluIdsByLuType("luType.shell.course", "STATE1X", contextInfo);
199        assertTrue(ids == null || ids.size() == 0);
200
201        try {
202            client.getCluIdsByLuType(null, "STATE1", contextInfo);
203            fail("MissingParameterException should have been thrown");
204        } catch (MissingParameterException e) {
205            assertNotNull(e.getMessage());
206            assertEquals("luTypeKey can not be null", e.getMessage());
207        }
208
209        try {
210            client.getCluIdsByLuType("luType.shell.course", null, contextInfo);
211            fail("MissingParameterException should have been thrown");
212        } catch (MissingParameterException e) {
213            assertNotNull(e.getMessage());
214            assertEquals("luState can not be null", e.getMessage());
215        }
216
217        // getClusByLuType
218        clus = client.getClusByLuType("luType.shell.program", "STATE2", contextInfo);
219        assertNotNull(clus);
220        assertEquals(1, clus.size());
221        assertEquals("CLU-2", clus.get(0).getId());
222
223        clus = client.getClusByLuType("LUTYPE-1X", "STATE1", contextInfo);
224        assertTrue(clus == null || clus.size() == 0);
225        clus = client.getClusByLuType("luType.shell.course", "STATE1X", contextInfo);
226        assertTrue(clus == null || clus.size() == 0);
227
228        try {
229            client.getClusByLuType(null, "STATE1", contextInfo);
230            fail("MissingParameterException should have been thrown");
231        } catch (MissingParameterException e) {
232            assertNotNull(e.getMessage());
233            assertEquals("luTypeKey can not be null", e.getMessage());
234        }
235
236        try {
237            client.getClusByLuType("luType.shell.course", null, contextInfo);
238            fail("MissingParameterException should have been thrown");
239        } catch (MissingParameterException e) {
240            assertNotNull(e.getMessage());
241            assertEquals("lustate can not be null", e.getMessage());
242        }
243    }
244
245    @Test
246    public void test01CluSet() throws DoesNotExistException,
247            InvalidParameterException, MissingParameterException,
248            OperationFailedException, PermissionDeniedException {
249        // getCluSetInfo
250        CluSetInfo csi = client.getCluSet("CLUSET-2", contextInfo);
251        assertNotNull(csi);
252
253        csi = client.getCluSet("CLUSET-1", contextInfo);
254        assertNotNull(csi);
255
256        try {
257            client.getCluSet("CLUSETXX-42", contextInfo);
258            fail("DoesNotExistException should have been thrown");
259        } catch (DoesNotExistException e1) {
260            assertNotNull(e1.getMessage());
261            assertEquals("CLUSETXX-42", e1.getMessage());
262        }
263
264        try {
265            client.getCluSet(null, contextInfo);
266            fail("MissingParameterException should have been thrown");
267        } catch (MissingParameterException e) {
268            assertNotNull(e.getMessage());
269            assertEquals("cluSetId can not be null", e.getMessage());
270        }
271
272        // getCluSetInfoByIdList
273        List<String> ids = new ArrayList<String>(1);
274        ids.add("CLUSET-2");
275        List<CluSetInfo> cluSets = client.getCluSetsByIds(ids, contextInfo);
276        assertEquals(1, cluSets.size());
277
278        ids.clear();
279        ids.add("CLUSETXXX-42");
280        cluSets = client.getCluSetsByIds(ids, contextInfo);
281        assertTrue(cluSets == null || cluSets.size() == 0);
282
283        try {
284            client.getCluSetsByIds(null, contextInfo);
285            fail("MissingParameterException should have been thrown");
286        } catch (MissingParameterException e) {
287            assertNotNull(e.getMessage());
288            assertEquals("cluSetIds can not be null", e.getMessage());
289        }
290
291        // getCluIdsFromCluSet
292        ids = client.getCluIdsFromCluSet("CLUSET-2", contextInfo);
293        assertEquals(2, ids.size());
294        assertEquals("CLU-1", ids.get(0));
295
296        try {
297            client.getCluIdsFromCluSet("CLUSETXXX-42", contextInfo);
298            fail("MissingParameterException should have been thrown");
299        } catch (DoesNotExistException e) {
300            assertNotNull(e.getMessage());
301            assertEquals("CLUSETXXX-42", e.getMessage());
302        }
303
304        try {
305            client.getCluIdsFromCluSet(null, contextInfo);
306            fail("MissingParameterException should have been thrown");
307        } catch (MissingParameterException e) {
308            assertNotNull(e.getMessage());
309            assertEquals("cluSetId can not be null", e.getMessage());
310        }
311
312        // getAllClusInCluSet
313        List<CluInfo> clus = client.getClusFromCluSet("CLUSET-2", contextInfo);
314        assertEquals(2, clus.size());
315        assertEquals("CLU-1", clus.get(0).getId());
316
317        try {
318            client.getClusFromCluSet("CLUSETXXX-42", contextInfo);
319            fail("MissingParameterException should have been thrown");
320        } catch (DoesNotExistException e) {
321            assertNotNull(e.getMessage());
322            assertEquals("CLUSETXXX-42", e.getMessage());
323        }
324
325        try {
326            client.getClusFromCluSet(null, contextInfo);
327            fail("MissingParameterException should have been thrown");
328        } catch (MissingParameterException e) {
329            assertNotNull(e.getMessage());
330            assertEquals("cluSetId can not be null", e.getMessage());
331        }
332
333        clus = client.getAllClusInCluSet("CLUSET-4", contextInfo);
334        assertEquals(2, clus.size());
335
336        try {
337            client.getAllCluIdsInCluSet(null, contextInfo);
338            fail("MissingParameterException should have been thrown");
339        } catch (MissingParameterException e) {
340            assertNotNull(e.getMessage());
341            assertEquals("cluSetId can not be null", e.getMessage());
342        }
343
344        clus = client.getAllClusInCluSet("CLUSET-2", contextInfo);
345        assertEquals(3, clus.size());
346
347        // isCluInCluSet
348        Boolean inSet = client.isCluInCluSet("CLU-2", "CLUSET-4", contextInfo);
349        assertTrue(inSet);
350
351        inSet = client.isCluInCluSet("CLU-3", "CLUSET-4", contextInfo);
352        assertTrue(inSet);
353
354        inSet = client.isCluInCluSet("CLUXX-42", "CLUSET-4", contextInfo);
355        assertFalse(inSet);
356
357        inSet = client.isCluInCluSet("CLU-2", "CLUSETXX-42", contextInfo);
358        assertFalse(inSet);
359
360        try {
361            client.isCluInCluSet(null, "CLUSET-4", contextInfo);
362            fail("MissingParameterException should have been thrown");
363        } catch (MissingParameterException e) {
364            assertNotNull(e.getMessage());
365            assertEquals("cluId can not be null", e.getMessage());
366        }
367        try {
368            client.isCluInCluSet("CLU-2", null, contextInfo);
369            fail("MissingParameterException should have been thrown");
370        } catch (MissingParameterException e) {
371            assertNotNull(e.getMessage());
372            assertEquals("cluSetId can not be null", e.getMessage());
373        }
374    }
375
376    @Test
377    public void test02CluSetCrud() throws AlreadyExistsException,
378            DataValidationErrorException, InvalidParameterException,
379            MissingParameterException, OperationFailedException,
380            PermissionDeniedException, DoesNotExistException, ParseException,
381            VersionMismatchException, UnsupportedActionException,
382            CircularRelationshipException, ReadOnlyException {
383
384        CluSetInfo cluSetInfo = new CluSetInfo();
385
386        RichTextInfo desc = new RichTextInfo();
387        desc.setFormatted("<p>Formatted Desc</p>");
388        desc.setPlain("plain");
389        cluSetInfo.setTypeKey(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE);
390        cluSetInfo.setStateKey("draft");
391        cluSetInfo.setAdminOrg("uuid-1234");
392        cluSetInfo.setDescr(desc);
393        cluSetInfo.setEffectiveDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20080101"));
394        cluSetInfo.setExpirationDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20180101"));
395        cluSetInfo.setName("testCluSet1");
396        cluSetInfo.getCluIds().add("CLU-1");
397        cluSetInfo.getCluIds().add("CLU-2");
398//              cluSetInfo.getCluSetIds().add("CLUSET-1");
399//              cluSetInfo.getCluSetIds().add("CLUSET-2");
400
401        cluSetInfo.getAttributes().add(new AttributeInfo("cluSet1ArrtKey1", "cluSet1ArrtValue1"));
402        cluSetInfo.getAttributes().add(new AttributeInfo("cluSet1ArrtKey2", "cluSet1ArrtValue2"));
403
404        CluSetInfo createdSet1 = client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, cluSetInfo, contextInfo);
405
406        assertEquals(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, createdSet1.getTypeKey());
407        assertEquals("uuid-1234", createdSet1.getAdminOrg());
408        assertEquals("<p>Formatted Desc</p>", createdSet1.getDescr().getFormatted());
409        assertEquals("plain", createdSet1.getDescr().getPlain());
410        assertEquals(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20080101"), createdSet1.getEffectiveDate());
411        assertEquals(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20180101"), createdSet1.getExpirationDate());
412        assertEquals("testCluSet1", createdSet1.getName());
413        assertEquals("CLU-1", createdSet1.getCluIds().get(0));
414        assertEquals("CLU-2", createdSet1.getCluIds().get(1));
415//              assertEquals("CLUSET-1", createdSet1.getCluSetIds().get(0));
416//              assertEquals("CLUSET-2", createdSet1.getCluSetIds().get(1));
417        assertEquals("cluSet1ArrtValue1", createdSet1.getAttributeValue("cluSet1ArrtKey1"));
418        assertEquals("cluSet1ArrtValue2", createdSet1.getAttributeValue("cluSet1ArrtKey2"));
419        assertNotNull(createdSet1.getMeta().getCreateTime());
420        assertNotNull(createdSet1.getMeta().getUpdateTime());
421        assertNotNull(createdSet1.getId());
422
423        createdSet1.setAdminOrg("uuid-1234-5678");
424        createdSet1.getDescr().setFormatted("UP<p>Formatted Desc</p>");
425        createdSet1.getDescr().setPlain("UPplain");
426        createdSet1.setEffectiveDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20090101"));
427        createdSet1.setExpirationDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20190101"));
428        createdSet1.setName("UPtestCluSet1");
429        createdSet1.getCluIds().remove(1);
430        createdSet1.getCluIds().add("CLU-3");
431//              createdSet1.getCluSetIds().remove(1);
432//              createdSet1.getCluSetIds().add("CLUSET-3");
433        createdSet1.getAttributes().set(0, new AttributeInfo("cluSet1ArrtKey1", "UPcluSet1ArrtValue1"));
434        createdSet1.getAttributes().remove(1);
435        createdSet1.getAttributes().add(new AttributeInfo("cluSet1ArrtKey3", "cluSet1ArrtValue3"));
436
437        CluSetInfo updatedSet1 = client.updateCluSet(createdSet1.getId(), createdSet1, contextInfo);
438
439        assertEquals("uuid-1234-5678", updatedSet1.getAdminOrg());
440        assertEquals("UP<p>Formatted Desc</p>", updatedSet1.getDescr().getFormatted());
441        assertEquals("UPplain", updatedSet1.getDescr().getPlain());
442        assertEquals(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20090101"), updatedSet1.getEffectiveDate());
443        assertEquals(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20190101"), updatedSet1.getExpirationDate());
444        assertEquals("UPtestCluSet1", updatedSet1.getName());
445        assertEquals("CLU-1", updatedSet1.getCluIds().get(0));
446        assertEquals("CLU-3", updatedSet1.getCluIds().get(1));
447        assertEquals(2, updatedSet1.getCluIds().size());
448//              assertEquals("CLUSET-1", updatedSet1.getCluSetIds().get(0));
449//              assertEquals("CLUSET-3", updatedSet1.getCluSetIds().get(1));
450//              assertEquals(2, updatedSet1.getCluSetIds().size());
451        assertEquals("UPcluSet1ArrtValue1", updatedSet1.getAttributeValue("cluSet1ArrtKey1"));
452        assertEquals("cluSet1ArrtValue3", updatedSet1.getAttributeValue("cluSet1ArrtKey3"));
453        assertEquals(2, updatedSet1.getAttributes().size());
454        assertNotNull(updatedSet1.getMeta().getUpdateTime());
455    }
456
457    @Test
458    public void test03RemoveCluFromCluSet() throws ParseException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, UnsupportedActionException, ReadOnlyException {
459        CluSetInfo createCluSet = createCluSetInfo();
460        createCluSet.getCluIds().add("CLU-1");
461        createCluSet.getCluIds().add("CLU-2");
462        createCluSet.getCluIds().add("CLU-3");
463
464        CluSetInfo createdCluSet1 = client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, createCluSet, contextInfo);
465        assertEquals(3, createdCluSet1.getCluIds().size());
466
467        StatusInfo status = client.removeCluFromCluSet("CLU-2", createdCluSet1.getId(), contextInfo);
468        assertTrue(status.getIsSuccess());
469
470        createdCluSet1 = client.getCluSet(createdCluSet1.getId(), contextInfo);
471
472        assertEquals(2, createdCluSet1.getCluIds().size());
473        assertTrue(createdCluSet1.getCluIds().contains("CLU-1"));
474        assertFalse(createdCluSet1.getCluIds().contains("CLU-2"));
475        assertTrue(createdCluSet1.getCluIds().contains("CLU-3"));
476    }
477
478    @Test
479    public void test04RemoveCluSetFromCluSet() throws ParseException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, UnsupportedActionException, ReadOnlyException {
480        CluSetInfo createCluSet = createCluSetInfo();
481        createCluSet.getCluSetIds().add("CLUSET-1");
482        createCluSet.getCluSetIds().add("CLUSET-2");
483        createCluSet.getCluSetIds().add("CLUSET-3");
484
485        CluSetInfo createdCluSet1 = client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, createCluSet, contextInfo);
486        assertEquals(3, createdCluSet1.getCluSetIds().size());
487
488        StatusInfo status = client.removeCluSetFromCluSet(createdCluSet1.getId(), "CLUSET-2", contextInfo);
489        assertTrue(status.getIsSuccess());
490
491        createdCluSet1 = client.getCluSet(createdCluSet1.getId(), contextInfo);
492
493        assertEquals(2, createdCluSet1.getCluSetIds().size());
494        assertTrue(createdCluSet1.getCluSetIds().contains("CLUSET-1"));
495        assertFalse(createdCluSet1.getCluSetIds().contains("CLUSET-2"));
496        assertTrue(createdCluSet1.getCluSetIds().contains("CLUSET-3"));
497    }
498
499    @Test
500    public void test05DeleteCluSet() throws ParseException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, UnsupportedActionException, ReadOnlyException {
501        CluSetInfo createCluSet = createCluSetInfo();
502
503        CluSetInfo createdCluSet1 = client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, createCluSet, contextInfo);
504
505        StatusInfo status = client.deleteCluSet(createdCluSet1.getId(), contextInfo);
506        assertTrue(status.getIsSuccess());
507
508        try {
509            client.getCluSet(createdCluSet1.getId(), contextInfo);
510            fail("Should have thrown DoesNotExistException");
511        } catch (DoesNotExistException e) {
512            assertNotNull(e.getMessage());
513            assertEquals(createdCluSet1.getId(), e.getMessage());
514        }
515    }
516
517    @Test
518    public void test06CluCluRelation() throws ParseException,
519            AlreadyExistsException, DataValidationErrorException,
520            DoesNotExistException, InvalidParameterException,
521            MissingParameterException, OperationFailedException,
522            PermissionDeniedException, VersionMismatchException,
523            DependentObjectsExistException {
524        List<CluCluRelationInfo> ccrs = client.getCluCluRelationsByClu("CLU-1", contextInfo);
525        assertNotNull(ccrs);
526        assertEquals(2, ccrs.size());
527
528        ccrs = client.getCluCluRelationsByClu("CLUXX-42", contextInfo);
529        assertTrue(ccrs == null || ccrs.size() == 0);
530
531        try {
532            client.getCluCluRelationsByClu(null, contextInfo);
533            fail("MissingParameterException should have been thrown");
534        } catch (MissingParameterException e) {
535            assertNotNull(e.getMessage());
536            assertEquals("cluId can not be null", e.getMessage());
537        }
538
539    }
540
541    // KSCM-484 TODO CluAdminOrg missing parameter state
542    @Test
543    public void test07CluCrud() throws ParseException, AlreadyExistsException,
544            DataValidationErrorException, DoesNotExistException,
545            InvalidParameterException, MissingParameterException,
546            OperationFailedException, PermissionDeniedException,
547            VersionMismatchException, DependentObjectsExistException, ReadOnlyException {
548
549        CluInfo clu = createCluInfo();
550
551        clu.getOfficialIdentifier().setCode("offId-divisionoffId-suffixcode");
552        clu.getOfficialIdentifier().getAttributes().add(new AttributeInfo("OfficialIdentKey", "OfficialIdentValue"));
553
554        clu.getAlternateIdentifiers().get(0).setCode("cluId1-divisioncluId1-suffixcode");
555        clu.getAlternateIdentifiers().get(0).getAttributes().add(new AttributeInfo("AltIdentKey", "AltIdentValue"));
556        clu.getAlternateIdentifiers().get(1).setCode("cluId2-divisioncluId2-suffixcode");
557        clu.getAlternateIdentifiers().get(1).getAttributes().add(new AttributeInfo("AltIdentKey", "AltIdentValue"));
558
559
560        // Do the actual create call
561        CluInfo createdClu = client.createClu("luType.shell.course", clu, contextInfo);
562        createdClu = client.getClu(createdClu.getId(), contextInfo);
563        // Validate Results
564        assertNotNull(createdClu);
565
566        assertEquals("AccountingAttrValue1", createdClu.getAccountingInfo().getAttributeValue("AccountingAttrKey1"));
567        assertEquals("AccountingAttrValue2", createdClu.getAccountingInfo().getAttributeValue("AccountingAttrKey2"));
568
569        assertEquals("offId-divisionoffId-suffixcode", createdClu.getOfficialIdentifier().getCode());
570        assertEquals("offId-division", createdClu.getOfficialIdentifier().getDivision());
571        assertEquals("offId-level", createdClu.getOfficialIdentifier().getLevel());
572        assertEquals("offId-longName", createdClu.getOfficialIdentifier().getLongName());
573        assertEquals("offId-shortName", createdClu.getOfficialIdentifier().getShortName());
574        assertEquals("offId-state", createdClu.getOfficialIdentifier().getStateKey());
575        assertEquals("offId-type", createdClu.getOfficialIdentifier().getTypeKey());
576        assertEquals("offId-variation", createdClu.getOfficialIdentifier().getVariation());
577        assertEquals("offId-suffixcode", createdClu.getOfficialIdentifier().getSuffixCode());
578        assertEquals("offId-orgid", createdClu.getOfficialIdentifier().getOrgId());
579        assertEquals("OfficialIdentValue", createdClu.getOfficialIdentifier().getAttributeValue("OfficialIdentKey"));
580
581        assertEquals("cluId1-divisioncluId1-suffixcode", createdClu.getAlternateIdentifiers().get(0).getCode());
582        assertEquals("cluId1-division", createdClu.getAlternateIdentifiers().get(0).getDivision());
583        assertEquals("cluId1-level", createdClu.getAlternateIdentifiers().get(0).getLevel());
584        assertEquals("cluId1-longName", createdClu.getAlternateIdentifiers().get(0).getLongName());
585        assertEquals("cluId1-shortName", createdClu.getAlternateIdentifiers().get(0).getShortName());
586        assertEquals("cluId1-state", createdClu.getAlternateIdentifiers().get(0).getStateKey());
587        assertEquals("cluId1-type", createdClu.getAlternateIdentifiers().get(0).getTypeKey());
588        assertEquals("cluId1-variation", createdClu.getAlternateIdentifiers().get(0).getVariation());
589        assertEquals("cluId1-suffixcode", createdClu.getAlternateIdentifiers().get(0).getSuffixCode());
590        assertEquals("cluId1-orgid", createdClu.getAlternateIdentifiers().get(0).getOrgId());
591        assertEquals("AltIdentValue", createdClu.getAlternateIdentifiers().get(0).getAttributeValue("AltIdentKey"));
592
593        assertEquals("cluId2-divisioncluId2-suffixcode", createdClu.getAlternateIdentifiers().get(1).getCode());
594        assertEquals("cluId2-division", createdClu.getAlternateIdentifiers().get(1).getDivision());
595        assertEquals("cluId2-level", createdClu.getAlternateIdentifiers().get(1).getLevel());
596        assertEquals("cluId2-longName", createdClu.getAlternateIdentifiers()
597                .get(1).getLongName());
598        assertEquals("cluId2-shortName", createdClu.getAlternateIdentifiers()
599                .get(1).getShortName());
600        assertEquals("cluId2-state", createdClu.getAlternateIdentifiers()
601                .get(1).getStateKey());
602        assertEquals("cluId2-type", createdClu.getAlternateIdentifiers().get(1)
603                .getTypeKey());
604        assertEquals("cluId2-variation", createdClu.getAlternateIdentifiers()
605                .get(1).getVariation());
606        assertEquals("cluId2-suffixcode", createdClu.getAlternateIdentifiers()
607                .get(1).getSuffixCode());
608        assertEquals("cluId2-orgid", createdClu.getAlternateIdentifiers()
609                .get(1).getOrgId());
610        assertEquals("AltIdentValue", createdClu.getAlternateIdentifiers().get(1).getAttributeValue("AltIdentKey"));
611
612        assertEquals("cluAttrValue1", createdClu.getAttributeValue("cluAttrKey1"));
613        assertEquals("cluAttrValue2", createdClu.getAttributeValue("cluAttrKey2"));
614
615        assertTrue(createdClu.getCanCreateLui());
616
617        assertEquals(545, createdClu.getDefaultEnrollmentEstimate());
618        assertEquals(999, createdClu.getDefaultMaximumEnrollment());
619
620        assertEquals("<p>DESC FORMATTED</p>", createdClu.getDescr()
621                .getFormatted());
622        assertEquals("DESC PLAIN", createdClu.getDescr().getPlain());
623
624        assertEquals(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20100203"), createdClu.getEffectiveDate());
625        assertEquals(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("21001231"), createdClu.getExpirationDate());
626
627        assertTrue(createdClu.getIsEnrollable());
628
629        assertEquals("FeeAttrValue1", createdClu.getFeeInfo().getAttributeValue("FeeAttrKey1"));
630        assertEquals("FeeAttrValue2", createdClu.getFeeInfo().getAttributeValue("FeeAttrKey2"));
631
632        assertEquals("Clu Fee", createdClu.getFeeInfo().getDescr().getPlain());
633        assertEquals(2, createdClu.getFeeInfo().getCluFeeRecords().size());
634        assertEquals("FEE-TYPE-X", createdClu.getFeeInfo().getCluFeeRecords().get(0).getFeeType());
635        assertEquals("RATE-TYPE-X", createdClu.getFeeInfo().getCluFeeRecords().get(0).getRateType());
636        assertEquals("Clu Fee Record", createdClu.getFeeInfo().getCluFeeRecords().get(0).getDescr().getPlain());
637        assertEquals(3, createdClu.getFeeInfo().getCluFeeRecords().get(0).getFeeAmounts().size());
638        assertEquals(Integer.valueOf(200), createdClu.getFeeInfo().getCluFeeRecords().get(0).getFeeAmounts().get(0).getCurrencyQuantity());
639        assertTrue(createdClu.getFeeInfo().getCluFeeRecords().get(1).getFeeAmounts().isEmpty());
640
641        assertEquals(2, createdClu.getFeeInfo().getCluFeeRecords().get(0).getAffiliatedOrgs().size());
642        assertEquals(35l, (long) createdClu.getFeeInfo().getCluFeeRecords().get(0).getAffiliatedOrgs().get(0).getPercentage());
643
644        assertTrue(createdClu.getIsHasEarlyDropDeadline());
645        assertTrue(createdClu.getIsHazardousForDisabledStudents());
646
647        assertEquals("EXT-orgId-1", createdClu.getPrimaryInstructor()
648                .getOrgId());
649        assertEquals("EXT-personId-1", createdClu.getPrimaryInstructor()
650                .getPersonId());
651        assertEquals("PrimaryInstAttrValue1", createdClu.getPrimaryInstructor().getAttributeValue("PrimaryInstAttrKey1"));
652        assertEquals("PrimaryInstAttrValue2", createdClu.getPrimaryInstructor().getAttributeValue("PrimaryInstAttrKey2"));
653
654        assertEquals("EXT-orgId-2", createdClu.getInstructors().get(0)
655                .getOrgId());
656        assertEquals("EXT-personId-2", createdClu.getInstructors().get(0)
657                .getPersonId());
658        assertEquals("Inst1AttrValue1", createdClu.getInstructors().get(0).getAttributeValue("Inst1AttrKey1"));
659        assertEquals("Inst1AttrValue2", createdClu.getInstructors().get(0).getAttributeValue("Inst1AttrKey2"));
660
661        assertEquals("EXT-orgId-3", createdClu.getInstructors().get(1)
662                .getOrgId());
663        assertEquals("EXT-personId-3", createdClu.getInstructors().get(1)
664                .getPersonId());
665        assertEquals("Inst2AttrValue1", createdClu.getInstructors().get(1).getAttributeValue("Inst2AttrKey1"));
666        assertEquals("Inst2AttrValue2", createdClu.getInstructors().get(1).getAttributeValue("Inst2AttrKey2"));
667
668        assertEquals("luCode1.key", createdClu.getLuCodes().get(0).getId());
669        assertEquals("luCode1-desc", createdClu.getLuCodes().get(0).getDescr().getPlain());
670        assertEquals("luCode1-value", createdClu.getLuCodes().get(0).getValue());
671        assertEquals("luCode1AttrValue1", createdClu.getLuCodes().get(0).getAttributeValue("luCode1AttrKey1"));
672        assertEquals("luCode1AttrValue2", createdClu.getLuCodes().get(0).getAttributeValue("luCode1AttrKey2"));
673        assertNotNull(createdClu.getLuCodes().get(0).getMeta());
674        assertNotNull(createdClu.getLuCodes().get(0).getMeta()
675                .getVersionInd());
676        assertNotNull(createdClu.getLuCodes().get(0).getMeta()
677                .getCreateTime());
678
679        assertEquals("luCode2.key", createdClu.getLuCodes().get(1).getId());
680        assertEquals("luCode2-desc", createdClu.getLuCodes().get(1).getDescr().getPlain());
681        assertEquals("luCode2-value", createdClu.getLuCodes().get(1).getValue());
682        assertEquals("luCode2AttrValue1", createdClu.getLuCodes().get(1).getAttributeValue("luCode2AttrKey1"));
683        assertEquals("luCode2AttrValue2", createdClu.getLuCodes().get(1).getAttributeValue("luCode2AttrKey2"));
684        assertNotNull(createdClu.getLuCodes().get(1).getMeta());
685        assertNotNull(createdClu.getLuCodes().get(1).getMeta()
686                .getVersionInd());
687        assertNotNull(createdClu.getLuCodes().get(1).getMeta()
688                .getCreateTime());
689
690
691        assertEquals("nextReviewPeriod", createdClu.getNextReviewPeriod());
692
693        assertEquals("offeredAtpType1", createdClu.getOfferedAtpTypes().get(0));
694        assertEquals("offeredAtpType2", createdClu.getOfferedAtpTypes().get(1));
695
696
697        assertEquals("http://student.kuali.org/clus", createdClu
698                .getReferenceURL());
699
700        assertEquals("Clu-state", createdClu.getStateKey());
701
702        assertEquals("EXT-stdDuration-Id1", createdClu.getStdDuration()
703                .getAtpDurationTypeKey());
704        assertEquals(Integer.valueOf(7867), createdClu.getStdDuration()
705                .getTimeQuantity());
706
707        assertEquals("luType.shell.course", createdClu.getTypeKey());
708
709        assertNotNull(createdClu.getMeta());
710        assertNotNull(createdClu.getMeta().getVersionInd());
711        assertNotNull(createdClu.getMeta().getCreateTime());
712
713        assertNotNull(createdClu.getId());
714
715        checkCampusLocationCreate(createdClu);
716
717        checkIntensityCreate(createdClu);
718
719        checkAccreditationListCreate(createdClu);
720
721        checkAdminOrgsCreate(createdClu);
722
723        // Now Update the Clu!
724        for (int i = 0; i < createdClu.getAccountingInfo().getAttributes().size(); i++) {
725            String attributeKey = createdClu.getAccountingInfo().getAttributes().get(i).getKey();
726            if (attributeKey.equals("AccountingAttrKey1")) {
727                createdClu.getAccountingInfo().getAttributes().set(i, new AttributeInfo("AccountingAttrKey1", "AccountingAttrValue1"));
728            } else if (attributeKey.equals("AccountingAttrKey2")) {
729                createdClu.getAccountingInfo().getAttributes().remove(i);
730            }
731        }
732        createdClu.getAccountingInfo().getAttributes().add(new AttributeInfo("AccountingAttrKey3", "AccountingAttrValue3"));
733
734        createdClu.getOfficialIdentifier().setCode("UPoffId-code");
735        createdClu.getOfficialIdentifier().setDivision("UPoffId-division");
736        createdClu.getOfficialIdentifier().setLevel("UPoffId-level");
737        createdClu.getOfficialIdentifier().setSuffixCode("UPoffId-suffixcode");
738        createdClu.getOfficialIdentifier().setLongName("UPoffId-longName");
739        createdClu.getOfficialIdentifier().setShortName("UPoffId-shortName");
740        createdClu.getOfficialIdentifier().setStateKey("UPoffId-state");
741        createdClu.getOfficialIdentifier().setTypeKey("UPoffId-type");
742        createdClu.getOfficialIdentifier().setVariation("UPoffId-variation");
743        createdClu.getOfficialIdentifier().getAttributes().add(new AttributeInfo("OfficialIdentKeyUptd", "OfficialIdentValueUptd"));
744
745
746        createdClu.getAlternateIdentifiers().get(0).setCode("UPcluId1-code");
747        createdClu.getAlternateIdentifiers().get(0).setDivision("UPcluId1-division");
748        createdClu.getAlternateIdentifiers().get(0).setLevel("UPcluId1-level");
749        createdClu.getAlternateIdentifiers().get(0).setSuffixCode("UPcluId1-suffixcode");
750        createdClu.getAlternateIdentifiers().get(0).setLongName("UPcluId1-longName");
751        createdClu.getAlternateIdentifiers().get(0).setShortName("UPcluId1-shortName");
752        createdClu.getAlternateIdentifiers().get(0).setStateKey("UPcluId1-state");
753        createdClu.getAlternateIdentifiers().get(0).setTypeKey("UPcluId1-type");
754        createdClu.getAlternateIdentifiers().get(0).setVariation("UPcluId1-variation");
755        createdClu.getAlternateIdentifiers().get(0).getAttributes().add(new AttributeInfo("AltIdentKeyUptd", "AltIdentValueUptd"));
756
757        createdClu.getAlternateIdentifiers().remove(1);
758
759        CluIdentifierInfo cluId3 = new CluIdentifierInfo();
760        cluId3.setCode("cluId3-code");
761        cluId3.setDivision("cluId3-division");
762        cluId3.setSuffixCode("cluId3-suffixcode");
763        cluId3.setLevel("cluId3-level");
764        cluId3.setLongName("cluId3-longName");
765        cluId3.setShortName("cluId3-shortName");
766        cluId3.setStateKey("cluId3-state");
767        cluId3.setTypeKey("cluId3-type");
768        cluId3.setVariation("cluId3-variation");
769
770
771        createdClu.getAlternateIdentifiers().add(cluId3);
772
773        for (int i = 0; i < createdClu.getAttributes().size(); i++) {
774            String attributeKey = createdClu.getAttributes().get(i).getKey();
775            if (attributeKey.equals("cluAttrKey1")) {
776                createdClu.getAttributes().set(i, new AttributeInfo("cluAttrKey1", "cluAttrValue1"));
777            } else if (attributeKey.equals("cluAttrKey2")) {
778                createdClu.getAttributes().remove(i);
779            }
780        }
781        createdClu.getAttributes().add(new AttributeInfo("cluAttrKey3", "cluAttrValue3"));
782
783        createdClu.setCanCreateLui(false);
784
785        createdClu.setDefaultEnrollmentEstimate(9545);
786        createdClu.setDefaultMaximumEnrollment(9999);
787
788        createdClu.getDescr().setFormatted("UP<p>DESC FORMATTED</p>");
789        createdClu.getDescr().setPlain("UPDESC PLAIN");
790
791        createdClu.setEffectiveDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20190203"));
792        createdClu.setExpirationDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("21091231"));
793
794        createdClu.setIsEnrollable(false);
795
796        for (int i = 0; i < createdClu.getFeeInfo().getAttributes().size(); i++) {
797            String attributeKey = createdClu.getFeeInfo().getAttributes().get(i).getKey();
798            if (attributeKey.equals("FeeAttrKey1")) {
799                createdClu.getFeeInfo().getAttributes().set(i, new AttributeInfo("FeeAttrKey1", "FeeAttrValue1"));
800            } else if (attributeKey.equals("FeeAttrKey2")) {
801                createdClu.getFeeInfo().getAttributes().remove(i);
802            }
803        }
804        createdClu.getFeeInfo().getAttributes().add(new AttributeInfo("FeeAttrKey3", "FeeAttrValue3"));
805
806        createdClu.getFeeInfo().getCluFeeRecords().get(0).getAffiliatedOrgs().remove(0);
807        createdClu.getFeeInfo().getCluFeeRecords().get(1).setFeeType("FEE-TYPE-Z");
808
809        createdClu.setIsHasEarlyDropDeadline(false);
810
811        createdClu.setIsHazardousForDisabledStudents(false);
812
813        createdClu.getPrimaryInstructor().setOrgId("UPEXT-orgId-1");
814        createdClu.getPrimaryInstructor().setPersonId("UPEXT-personId-1");
815        for (int i = 0; i < createdClu.getPrimaryInstructor().getAttributes().size(); i++) {
816            String attributeKey = createdClu.getPrimaryInstructor().getAttributes().get(i).getKey();
817            if (attributeKey.equals("PrimaryInstAttrKey1")) {
818                createdClu.getPrimaryInstructor().getAttributes().set(i, new AttributeInfo("PrimaryInstAttrKey1", "PrimaryInstAttrValue1"));
819            } else if (attributeKey.equals("PrimaryInstAttrKey2")) {
820                createdClu.getPrimaryInstructor().getAttributes().remove(i);
821            }
822        }
823        createdClu.getPrimaryInstructor().getAttributes().add(new AttributeInfo("PrimaryInstAttrKey3", "PrimaryInstAttrValue3"));
824
825        createdClu.getInstructors().get(0).setOrgId("UPEXT-orgId-2");
826        createdClu.getInstructors().get(0).setPersonId("UPEXT-personId-2");
827        for (int i = 0; i < createdClu.getInstructors().get(0).getAttributes().size(); i++) {
828            String attributeKey = createdClu.getInstructors().get(0).getAttributes().get(i).getKey();
829            if (attributeKey.equals("Inst1AttrKey1")) {
830                createdClu.getInstructors().get(0).getAttributes().set(i, new AttributeInfo("Inst1AttrKey1", "Inst1AttrValue1"));
831            } else if (attributeKey.equals("Inst1AttrKey2")) {
832                createdClu.getInstructors().get(0).getAttributes().remove(i);
833            }
834        }
835        createdClu.getInstructors().get(0).getAttributes().add(new AttributeInfo("Inst1AttrKey3", "Inst1AttrValue3"));
836
837        createdClu.getInstructors().remove(1);
838
839        CluInstructorInfo instructor3 = new CluInstructorInfo();
840        instructor3.setOrgId("EXT-orgId-3");
841        instructor3.setPersonId("EXT-personId-3");
842        instructor3.getAttributes().add(new AttributeInfo("Inst3AttrKey1", "Inst3AttrValue1"));
843        instructor3.getAttributes().add(new AttributeInfo("Inst3AttrKey2", "Inst3AttrValue2"));
844        createdClu.getInstructors().add(instructor3);
845        RichTextInfo UPLuCode1Desc = new RichTextInfo();
846        UPLuCode1Desc.setPlain("luCodetwodesc");
847        createdClu.getLuCodes().get(0).setDescr(UPLuCode1Desc);
848        createdClu.getLuCodes().get(0).setValue("UPluCode1-value");
849        for (int i = 0; i < createdClu.getLuCodes().get(0).getAttributes().size(); i++) {
850            String attributeKey = createdClu.getLuCodes().get(0).getAttributes().get(i).getKey();
851            if (attributeKey.equals("luCode1AttrKey1")) {
852                createdClu.getLuCodes().get(0).getAttributes().set(i, new AttributeInfo("luCode1AttrKey1", "luCode1AttrValue1"));
853            } else if (attributeKey.equals("luCode1AttrKey2")) {
854                createdClu.getLuCodes().get(0).getAttributes().remove(i);
855            }
856        }
857        createdClu.getLuCodes().get(0).getAttributes().add(new AttributeInfo("luCode1AttrKey3", "luCode1AttrValue3"));
858        createdClu.getLuCodes().get(0).setTypeKey("updatedType");
859
860        createdClu.getLuCodes().remove(1);
861
862        LuCodeInfo luCode3 = new LuCodeInfo();
863        luCode3.setId("luCode3.key");
864        RichTextInfo luCode3Desc = new RichTextInfo();
865        luCode3Desc.setPlain("luCode3-desc");
866        luCode3.setDescr(luCode3Desc);
867        luCode3.setValue("luCode3-value");
868        luCode3.getAttributes().add(new AttributeInfo("luCode3AttrKey1", "luCode3AttrValue1"));
869        luCode3.getAttributes().add(new AttributeInfo("luCode3AttrKey2", "luCode3AttrValue2"));
870        luCode3.setTypeKey("updatedType");
871        createdClu.getLuCodes().add(luCode3);
872
873
874        createdClu.setNextReviewPeriod("UPnextReviewPeriod");
875
876        createdClu.getOfferedAtpTypes().remove(1);
877        createdClu.getOfferedAtpTypes().add("offeredAtpType3");
878
879
880        CluInstructorInfo pubInstructor3 = new CluInstructorInfo();
881        pubInstructor3.setOrgId("EXT-orgId-3");
882        pubInstructor3.setPersonId("EXT-personId-3");
883        pubInstructor3.getAttributes().add(new AttributeInfo("PubInst3AttrKey1", "PubInst3AttrValue1"));
884        pubInstructor3.getAttributes().add(new AttributeInfo("PubInst3AttrKey2", "PubInst3AttrValue2"));
885
886        createdClu.setReferenceURL("UPhttp://student.kuali.org/clus");
887
888        createdClu.setStateKey("UPClu-state");
889
890        createdClu.getStdDuration().setAtpDurationTypeKey(
891                "UPEXT-stdDuration-Id1");
892        createdClu.getStdDuration().setTimeQuantity(97867);
893
894        createdClu.setTypeKey("luType.shell.program");
895
896        updateAdminOrgs(createdClu);
897
898        updateAccreditationList(createdClu);
899
900        updateIntensity(createdClu);
901
902        updateCampusLocationList(createdClu);
903
904        // Do Update
905        CluInfo updatedClu = client.updateClu(createdClu.getId(), createdClu, contextInfo);
906
907        // Validate Results
908        assertNotNull(updatedClu);
909
910        assertEquals("AccountingAttrValue1", updatedClu.getAccountingInfo().getAttributeValue("AccountingAttrKey1"));
911        assertEquals("AccountingAttrValue3", updatedClu.getAccountingInfo().getAttributeValue("AccountingAttrKey3"));
912        assertEquals(2, updatedClu.getAccountingInfo().getAttributes().size());
913
914        assertEquals("UPoffId-code", updatedClu
915                .getOfficialIdentifier().getCode());
916        assertEquals("UPoffId-division", updatedClu.getOfficialIdentifier()
917                .getDivision());
918        assertEquals("UPoffId-level", updatedClu.getOfficialIdentifier()
919                .getLevel());
920        assertEquals("UPoffId-suffixcode", updatedClu.getOfficialIdentifier()
921                .getSuffixCode());
922        assertEquals("UPoffId-longName", updatedClu.getOfficialIdentifier()
923                .getLongName());
924        assertEquals("UPoffId-shortName", updatedClu.getOfficialIdentifier()
925                .getShortName());
926        assertEquals("UPoffId-state", updatedClu.getOfficialIdentifier()
927                .getStateKey());
928        assertEquals("UPoffId-type", updatedClu.getOfficialIdentifier()
929                .getTypeKey());
930        assertEquals("UPoffId-variation", updatedClu.getOfficialIdentifier()
931                .getVariation());
932        assertEquals(2, updatedClu.getOfficialIdentifier().getAttributes().size());
933        assertEquals("OfficialIdentValueUptd", updatedClu.getOfficialIdentifier().getAttributeValue("OfficialIdentKeyUptd"));
934
935        assertEquals("UPcluId1-code", updatedClu
936                .getAlternateIdentifiers().get(0).getCode());
937        assertEquals("UPcluId1-division", updatedClu.getAlternateIdentifiers()
938                .get(0).getDivision());
939        assertEquals("UPcluId1-level", updatedClu.getAlternateIdentifiers()
940                .get(0).getLevel());
941        assertEquals("UPcluId1-suffixcode", updatedClu
942                .getAlternateIdentifiers().get(0).getSuffixCode());
943        assertEquals("UPcluId1-longName", updatedClu.getAlternateIdentifiers()
944                .get(0).getLongName());
945        assertEquals("UPcluId1-shortName", updatedClu.getAlternateIdentifiers()
946                .get(0).getShortName());
947        assertEquals("UPcluId1-state", updatedClu.getAlternateIdentifiers()
948                .get(0).getStateKey());
949        assertEquals("UPcluId1-type", updatedClu.getAlternateIdentifiers().get(
950                0).getTypeKey());
951        assertEquals("UPcluId1-variation", updatedClu.getAlternateIdentifiers()
952                .get(0).getVariation());
953        assertEquals(2, updatedClu.getAlternateIdentifiers().get(0).getAttributes().size());
954        assertEquals("AltIdentValueUptd", createdClu.getAlternateIdentifiers().get(0).getAttributeValue("AltIdentKeyUptd"));
955
956        assertEquals("cluId3-code", updatedClu
957                .getAlternateIdentifiers().get(1).getCode());
958        assertEquals("cluId3-division", updatedClu.getAlternateIdentifiers()
959                .get(1).getDivision());
960        assertEquals("cluId3-level", updatedClu.getAlternateIdentifiers()
961                .get(1).getLevel());
962        assertEquals("cluId3-suffixcode", updatedClu.getAlternateIdentifiers()
963                .get(1).getSuffixCode());
964        assertEquals("cluId3-longName", updatedClu.getAlternateIdentifiers()
965                .get(1).getLongName());
966        assertEquals("cluId3-shortName", updatedClu.getAlternateIdentifiers()
967                .get(1).getShortName());
968        assertEquals("cluId3-state", updatedClu.getAlternateIdentifiers()
969                .get(1).getStateKey());
970        assertEquals("cluId3-type", updatedClu.getAlternateIdentifiers().get(1)
971                .getTypeKey());
972        assertEquals("cluId3-variation", updatedClu.getAlternateIdentifiers()
973                .get(1).getVariation());
974
975        assertEquals(2, updatedClu.getAlternateIdentifiers().size());
976
977        assertEquals("cluAttrValue1", updatedClu.getAttributeValue("cluAttrKey1"));
978        assertEquals("cluAttrValue3", updatedClu.getAttributeValue("cluAttrKey3"));
979        assertEquals(2, updatedClu.getAttributes().size());
980
981        assertFalse(updatedClu.getCanCreateLui());
982
983        assertEquals(9545, updatedClu.getDefaultEnrollmentEstimate());
984        assertEquals(9999, updatedClu.getDefaultMaximumEnrollment());
985
986        assertEquals("UP<p>DESC FORMATTED</p>", updatedClu.getDescr()
987                .getFormatted());
988        assertEquals("UPDESC PLAIN", updatedClu.getDescr().getPlain());
989
990        assertEquals(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20190203"), updatedClu.getEffectiveDate());
991        assertEquals(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("21091231"), updatedClu.getExpirationDate());
992
993        assertFalse(updatedClu.getIsEnrollable());
994
995        assertEquals("FeeAttrValue1", updatedClu.getFeeInfo().getAttributeValue("FeeAttrKey1"));
996        assertEquals("FeeAttrValue3", updatedClu.getFeeInfo().getAttributeValue("FeeAttrKey3"));
997        assertEquals(2, updatedClu.getFeeInfo().getAttributes().size());
998
999        assertEquals(2, createdClu.getFeeInfo().getCluFeeRecords().size());
1000        assertEquals("FEE-TYPE-Z", createdClu.getFeeInfo().getCluFeeRecords().get(1).getFeeType());
1001
1002        assertEquals(1, createdClu.getFeeInfo().getCluFeeRecords().get(0).getAffiliatedOrgs().size());
1003        assertEquals(65l, (long) createdClu.getFeeInfo().getCluFeeRecords().get(0).getAffiliatedOrgs().get(0).getPercentage());
1004
1005        assertFalse(updatedClu.getIsHasEarlyDropDeadline());
1006        assertFalse(updatedClu.getIsHazardousForDisabledStudents());
1007
1008        assertEquals("UPEXT-orgId-1", updatedClu.getPrimaryInstructor()
1009                .getOrgId());
1010        assertEquals("UPEXT-personId-1", updatedClu.getPrimaryInstructor()
1011                .getPersonId());
1012        assertEquals("PrimaryInstAttrValue1", updatedClu.getPrimaryInstructor().getAttributeValue("PrimaryInstAttrKey1"));
1013        assertEquals("PrimaryInstAttrValue3", updatedClu.getPrimaryInstructor().getAttributeValue("PrimaryInstAttrKey3"));
1014        assertEquals(2, updatedClu.getPrimaryInstructor().getAttributes()
1015                .size());
1016
1017        assertEquals(2, updatedClu.getInstructors().size());
1018
1019        assertEquals("UPEXT-orgId-2", updatedClu.getInstructors().get(0)
1020                .getOrgId());
1021        assertEquals("UPEXT-personId-2", updatedClu.getInstructors().get(0)
1022                .getPersonId());
1023        assertEquals("Inst1AttrValue1", updatedClu.getInstructors().get(0).getAttributeValue("Inst1AttrKey1"));
1024        assertEquals("Inst1AttrValue3", updatedClu.getInstructors().get(0).getAttributeValue("Inst1AttrKey3"));
1025        assertEquals(2, updatedClu.getInstructors().get(0).getAttributes()
1026                .size());
1027
1028        assertEquals("EXT-orgId-3", updatedClu.getInstructors().get(1)
1029                .getOrgId());
1030        assertEquals("EXT-personId-3", updatedClu.getInstructors().get(1)
1031                .getPersonId());
1032        assertEquals("Inst3AttrValue1", updatedClu.getInstructors().get(1).getAttributeValue("Inst3AttrKey1"));
1033        assertEquals("Inst3AttrValue2", updatedClu.getInstructors().get(1).getAttributeValue("Inst3AttrKey2"));
1034        assertEquals(2, updatedClu.getInstructors().get(1).getAttributes()
1035                .size());
1036
1037        assertEquals(2, updatedClu.getLuCodes().size());
1038
1039        assertEquals("luCode1.key", updatedClu.getLuCodes().get(0).getId());
1040        assertEquals("luCodetwodesc", updatedClu.getLuCodes().get(0).getDescr().getPlain());
1041        assertEquals("UPluCode1-value", updatedClu.getLuCodes().get(0)
1042                .getValue());
1043        assertEquals("luCode1AttrValue1", updatedClu.getLuCodes().get(0).getAttributeValue("luCode1AttrKey1"));
1044        assertEquals("luCode1AttrValue3", updatedClu.getLuCodes().get(0).getAttributeValue("luCode1AttrKey3"));
1045        assertEquals(2, updatedClu.getLuCodes().get(0).getAttributes().size());
1046        assertNotNull(updatedClu.getLuCodes().get(0).getMeta());
1047        assertNotNull(updatedClu.getLuCodes().get(0).getMeta()
1048                .getVersionInd());
1049        assertNotNull(updatedClu.getLuCodes().get(0).getMeta()
1050                .getCreateTime());
1051        assertNotNull(updatedClu.getLuCodes().get(0).getMeta()
1052                .getUpdateTime());
1053
1054        // id is nulled and subsequently set to a uuid
1055        //assertEquals("luCode3.key", updatedClu.getLuCodes().get(1).getId());
1056        assertEquals("luCode3-desc", updatedClu.getLuCodes().get(1).getDescr().getPlain());
1057        assertEquals("luCode3-value", updatedClu.getLuCodes().get(1).getValue());
1058        assertEquals("luCode3AttrValue1", updatedClu.getLuCodes().get(1).getAttributeValue("luCode3AttrKey1"));
1059        assertEquals("luCode3AttrValue2", updatedClu.getLuCodes().get(1).getAttributeValue("luCode3AttrKey2"));
1060        assertNotNull(updatedClu.getLuCodes().get(1).getMeta());
1061        assertNotNull(updatedClu.getLuCodes().get(1).getMeta()
1062                .getVersionInd());
1063        assertNotNull(updatedClu.getLuCodes().get(1).getMeta()
1064                .getCreateTime());
1065        assertNotNull(updatedClu.getLuCodes().get(1).getMeta()
1066                .getUpdateTime());
1067
1068        assertEquals("UPnextReviewPeriod", updatedClu.getNextReviewPeriod());
1069
1070        assertEquals("offeredAtpType1", updatedClu.getOfferedAtpTypes().get(0));
1071        assertEquals("offeredAtpType3", updatedClu.getOfferedAtpTypes().get(1));
1072        assertEquals(2, updatedClu.getOfferedAtpTypes().size());
1073
1074
1075        assertEquals("UPhttp://student.kuali.org/clus", updatedClu
1076                .getReferenceURL());
1077
1078        assertEquals("UPClu-state", updatedClu.getStateKey());
1079
1080        assertEquals("UPEXT-stdDuration-Id1", updatedClu.getStdDuration()
1081                .getAtpDurationTypeKey());
1082        assertEquals(Integer.valueOf(97867), updatedClu.getStdDuration()
1083                .getTimeQuantity());
1084
1085        assertEquals("luType.shell.program", updatedClu.getTypeKey());
1086
1087        assertEquals(false, updatedClu.getIsEnrollable());
1088        assertEquals(false, updatedClu.getIsHazardousForDisabledStudents());
1089
1090        assertNotNull(updatedClu.getMeta());
1091        assertNotNull(updatedClu.getMeta().getVersionInd());
1092        assertNotNull(updatedClu.getMeta().getCreateTime());
1093        assertNotNull(updatedClu.getMeta().getUpdateTime());
1094
1095        assertEquals(createdClu.getId(), updatedClu.getId());
1096
1097        checkAdminOrgUpdate(updatedClu);
1098
1099        checkAccreditationListUpdate(updatedClu);
1100
1101        checkCampusLocationUpdate(updatedClu);
1102
1103        checkIntensityUpdate(updatedClu);
1104
1105        // Test Optimistic locking
1106        try {
1107            client.updateClu(createdClu.getId(), createdClu, contextInfo);
1108            fail("Should have thrown VersionMismatchException");
1109        } catch (VersionMismatchException e) {
1110            assertNotNull(e.getMessage());
1111            assertEquals("Clu to be updated is not the current version", e.getMessage());
1112        }
1113
1114        client.getClu(createdClu.getId(), contextInfo);
1115
1116        StatusInfo status = client.deleteClu(createdClu.getId(), contextInfo);
1117        assertTrue(status.getIsSuccess());
1118
1119        try {
1120            client.getClu(createdClu.getId(), contextInfo);
1121            fail("Should have thrown DoesNotExistException");
1122        } catch (DoesNotExistException e) {
1123            assertNotNull(e.getMessage());
1124            assertEquals(createdClu.getId(), e.getMessage());
1125        }
1126
1127    }
1128
1129    @Test
1130    public void test08CluCluRelationCrud() throws Exception {
1131
1132        final CluCluRelationInfo cluCluRelationInfo = new CluCluRelationInfo();
1133
1134        final Date effectiveDate = DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20080101"),
1135                expirationDate = DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20100101");
1136        cluCluRelationInfo.setEffectiveDate(effectiveDate);
1137        cluCluRelationInfo.setExpirationDate(expirationDate);
1138        cluCluRelationInfo.setIsCluRelationRequired(true);
1139        cluCluRelationInfo.setStateKey("hello");
1140
1141        if (cluCluRelationInfo.getAttributes() == null) {
1142            cluCluRelationInfo.setAttributes(new ArrayList<AttributeInfo>());
1143        }
1144        cluCluRelationInfo.getAttributes().add(new AttributeInfo("clucluAttrKey1", "clucluAttrValue1"));
1145        cluCluRelationInfo.getAttributes().add(new AttributeInfo("clucluAttrKey2", "clucluAttrValue2"));
1146        cluCluRelationInfo.getAttributes().add(new AttributeInfo("clucluAttrKey3", "clucluAttrValue3"));
1147
1148        CluCluRelationInfo created = client.createCluCluRelation("CLU-1",
1149                "CLU-2", "luLuType.type1", cluCluRelationInfo, contextInfo);
1150
1151        assertEquals(effectiveDate, created.getEffectiveDate());
1152        assertEquals(expirationDate, created.getExpirationDate());
1153        assertEquals(true, created.getIsCluRelationRequired());
1154        assertEquals("hello", created.getStateKey());
1155        assertEquals("CLU-1", created.getCluId());
1156        assertEquals("CLU-2", created.getRelatedCluId());
1157        assertEquals("luLuType.type1", created.getTypeKey());
1158        assertEquals("clucluAttrValue1", created.getAttributeValue("clucluAttrKey1"));
1159        assertEquals("clucluAttrValue2", created.getAttributeValue("clucluAttrKey2"));
1160        assertEquals("clucluAttrValue3", created.getAttributeValue("clucluAttrKey3"));
1161        assertNotNull(created.getId());
1162        assertNotNull(created.getMeta().getCreateTime());
1163        assertNotNull(created.getMeta().getVersionInd());
1164
1165        created.getAttributes().remove(1);
1166        created.getAttributes().set(1, new AttributeInfo("clucluAttrKey3", "clucluAttrValue3-A"));
1167        created.getAttributes().add(new AttributeInfo("clucluAttrKey4", "clucluAttrValue4"));
1168        created.setCluId("CLU-2");
1169        created.setEffectiveDate(expirationDate);
1170        created.setExpirationDate(effectiveDate);
1171        created.setIsCluRelationRequired(false);
1172        created.setRelatedCluId("CLU-3");
1173        created.setStateKey("updated-hello");
1174        created.setTypeKey("luLuType.type2");
1175
1176        CluCluRelationInfo updated = client.updateCluCluRelation(created.getId(), created, contextInfo);
1177
1178        assertEquals(expirationDate, updated.getEffectiveDate());
1179        assertEquals(effectiveDate, updated.getExpirationDate());
1180        assertEquals(false, updated.getIsCluRelationRequired());
1181        assertEquals("updated-hello", updated.getStateKey());
1182        assertEquals("CLU-2", updated.getCluId());
1183        assertEquals("CLU-3", updated.getRelatedCluId());
1184        assertEquals("luLuType.type2", updated.getTypeKey());
1185        assertEquals("clucluAttrValue1", updated.getAttributeValue("clucluAttrKey1"));
1186        assertNull(updated.getAttributeValue("clucluAttrKey2"));
1187        assertEquals("clucluAttrValue3-A", updated.getAttributeValue("clucluAttrKey3"));
1188        assertEquals("clucluAttrValue4", updated.getAttributeValue("clucluAttrKey4"));
1189        assertNotNull(created.getId());
1190        assertNotNull(created.getMeta().getCreateTime());
1191        assertNotNull(created.getMeta().getVersionInd());
1192
1193        // Test Delete
1194        client.getCluCluRelation(created.getId(), contextInfo);
1195
1196        StatusInfo status = client.deleteCluCluRelation(created.getId(), contextInfo);
1197        assertTrue(status.getIsSuccess());
1198
1199        try {
1200            client.getCluCluRelation(created.getId(), contextInfo);
1201            fail("Should have thrown DoesNotExistException");
1202        } catch (DoesNotExistException e) {
1203            assertNotNull(e.getMessage());
1204            assertEquals(created.getId(), e.getMessage());
1205        }
1206
1207        List<String> relatedCluIdsByCluId = client.getRelatedCluIdsByCluAndRelationType(
1208                "CLU-1", "luLuType.type1", contextInfo);
1209
1210        assertEquals(2, relatedCluIdsByCluId.size());
1211        assertTrue(relatedCluIdsByCluId.contains("CLU-2"));
1212        assertTrue(relatedCluIdsByCluId.contains("CLU-3"));
1213
1214        List<CluInfo> relatedClusByCluId = client.getRelatedClusByCluAndRelationType(
1215                "CLU-1", "luLuType.type1", contextInfo);
1216        assertEquals(2, relatedClusByCluId.size());
1217    }
1218
1219    /* LuiService not used in CM     @Test
1220     public void test09LuiLuiRelationCrud() throws Exception {
1221
1222         ContextInfo contextInfo = ContextInfoTestUtility.getEnglishContextInfo();
1223
1224         LuiLuiRelationInfo luiLuiRelationInfo = new LuiLuiRelationInfo();
1225
1226         luiLuiRelationInfo.setEffectiveDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20080101"));
1227         luiLuiRelationInfo.setExpirationDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20100101"));
1228         luiLuiRelationInfo.setState("hello");
1229         luiLuiRelationInfo.setType("goodbye");
1230         luiLuiRelationInfo.getAttributes().add(new AttributeInfo("luiluiAttrKey1","luiluiAttrValue1"));
1231         luiLuiRelationInfo.getAttributes().add(new AttributeInfo("luiluiAttrKey2","luiluiAttrValue2"));
1232
1233         LuiLuiRelationInfo created = atpService.createLuiLuiRelation("LUI-1",
1234                 "LUI-2", "luLuType.type1", luiLuiRelationInfo, contextInfo);
1235
1236         assertEquals(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20080101"), created.getEffectiveDate());
1237         assertEquals(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20100101"), created.getExpirationDate());
1238         assertEquals("hello", created.getState());
1239         assertEquals("luLuType.type1", created.getType());
1240         assertEquals("LUI-1", created.getLuiId());
1241         assertEquals("LUI-2", created.getRelatedLuiId());
1242         assertEquals("luiluiAttrValue1", created.getAttributeValue("luiluiAttrKey1"));
1243         assertEquals("luiluiAttrValue2", created.getAttributeValue("luiluiAttrKey2"));
1244         assertNotNull(created.getId());
1245         assertNotNull(created.getMetaInfo().getCreateTime());
1246         assertNotNull(created.getMetaInfo().getVersionInd());
1247
1248         created.setEffectiveDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20980101"));
1249         created.setExpirationDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20190101"));
1250         created.setState("sawyer");
1251         created.setType("luLuType.type2");
1252         created.setLuiId("LUI-2");
1253         created.setRelatedLuiId("LUI-3");
1254         created.getAttributes().add(new AttributeInfo("luiluiAttrKey1", "UPluiluiAttrValue1"));
1255         created.getAttributes().remove("luiluiAttrKey2");
1256         created.getAttributes().add(new AttributeInfo("luiluiAttrKey3", "luiluiAttrValue3"));
1257
1258         LuiLuiRelationInfo updated = atpService.updateLuiLuiRelation(created
1259                 .getId(), created, contextInfo);
1260
1261         assertEquals(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20980101"), updated.getEffectiveDate());
1262         assertEquals(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20190101"), updated.getExpirationDate());
1263         assertEquals("sawyer", updated.getState());
1264         assertEquals("luLuType.type2", updated.getType());
1265         assertEquals("LUI-2", updated.getLuiId());
1266         assertEquals("LUI-3", updated.getRelatedLuiId());
1267         assertEquals("UPluiluiAttrValue1", updated.getAttributeValue("luiluiAttrKey1"));
1268         assertEquals("luiluiAttrValue3", updated.getAttributeValue("luiluiAttrKey3"));
1269         assertEquals(2, updated.getAttributes().size());
1270         assertEquals(created.getId(), updated.getId());
1271         assertNotNull(updated.getMetaInfo().getUpdateTime());
1272
1273         try {
1274             updated = atpService.updateLuiLuiRelation(created.getId(), created, contextInfo);
1275             fail("Should have thrown VersionMismatchException");
1276         } catch (VersionMismatchException e) {
1277         }
1278
1279         try {
1280             atpService.getLuiLuiRelation(created.getId(), contextInfo);
1281         } catch (DoesNotExistException e) {
1282             fail("Should not have thrown DoesNotExistException");
1283         }
1284
1285         StatusInfo status = R1R2ConverterUtil.convert(atpService.deleteLuiLuiRelation(updated.getId(), contextInfo), StatusInfo.class);
1286
1287         assertTrue(status.getIsSuccess());
1288
1289         try {
1290             atpService.getLuiLuiRelation(created.getId(), contextInfo);
1291             fail("Should have thrown DoesNotExistException");
1292         } catch (DoesNotExistException e) {
1293
1294         }
1295
1296         // TestFind
1297         List<LuiLuiRelationInfo> relations = atpService
1298                 .getLuiLuiRelationsByLui("LUI-1", contextInfo);
1299         assertEquals(2, relations.size());
1300         relations = atpService.getLuiLuiRelationsByLui("LUI-2", contextInfo);
1301         assertEquals(1, relations.size());
1302         relations = atpService.getLuiLuiRelationsByLui("LUI-3", contextInfo);
1303         assertTrue(relations == null || relations.size() == 0);
1304
1305         List<String> relatedLuiIdsByLuiId = atpService.getRelatedLuiIdsByLuiId(
1306                 "LUI-1", "luLuType.type1", contextInfo);
1307         assertEquals(2, relatedLuiIdsByLuiId.size());
1308         assertTrue(relatedLuiIdsByLuiId.contains("LUI-2"));
1309         assertTrue(relatedLuiIdsByLuiId.contains("LUI-3"));
1310
1311         List<LuiInfo> relatedLuisByLuiId = atpService.getRelatedLuisByLuiId(
1312                 "LUI-1", "luLuType.type1", contextInfo);
1313         assertEquals(2, relatedLuisByLuiId.size());
1314
1315     }
1316
1317     @Test
1318     public void test10GetLuisByIdList() throws DoesNotExistException,
1319             InvalidParameterException, MissingParameterException,
1320             OperationFailedException {
1321
1322         List<LuiInfo> luiInfos;
1323         try {
1324             luiInfos = atpService.getLuisByIds(null, contextInfo);
1325             fail("CluService.getLuiByIdList() did not throw MissingParameterException for null Lui ID");
1326         } catch (MissingParameterException mpe) {
1327         } catch (Exception e) {
1328             fail("CluService.getLuiByIdList() threw unexpected "
1329                     + e.getClass().getSimpleName() + " for null Lui ID");
1330         }
1331         luiInfos = atpService.getLuisByIds(Arrays.asList("Not a LUI ID",
1332                 "Another one that ain't"), contextInfo);
1333         assertTrue(luiInfos == null || luiInfos.size() == 0);
1334
1335         luiInfos = atpService.getLuisByIds(Arrays.asList("LUI-1", "LUI-4"), contextInfo);
1336         Collections.sort(luiInfos, new Comparator<LuiInfo>() {
1337             @Override
1338             public int compare(LuiInfo o1, LuiInfo o2) {
1339                 return o1.getId().compareTo(o2.getId());
1340             }
1341         });
1342         assertEquals("CLU-1", luiInfos.get(0).getCluId());
1343         assertEquals("CLU-2", luiInfos.get(1).getCluId());
1344     }
1345
1346     @Test
1347     public void test11LuiCrud() throws AlreadyExistsException,
1348             DataValidationErrorException, DoesNotExistException,
1349             InvalidParameterException, MissingParameterException,
1350             OperationFailedException, PermissionDeniedException,
1351             ParseException, DependentObjectsExistException {
1352
1353         ContextInfo contextInfo = ContextInfoTestUtility.getEnglishContextInfo();
1354
1355         LuiInfo luiInfo;
1356
1357         // Read
1358         try {
1359             luiInfo = atpService.getLui("notARealLui", contextInfo);
1360             fail("CluService.getLui() did not throw DoesNotExistException for non-existent Lui");
1361         } catch (DoesNotExistException dnee) {
1362         } catch (Exception e) {
1363             fail("CluService.getLui() threw unexpected "
1364                     + e.getClass().getSimpleName() + " for null Lui ID");
1365         }
1366         try {
1367             luiInfo = atpService.getLui(null, contextInfo);
1368             fail("CluService.getLui() did not throw MissingParameterException for null Lui ID");
1369         } catch (MissingParameterException mpe) {
1370         }
1371         luiInfo = atpService.getLui("LUI-1", contextInfo);
1372         assertEquals("CLU-1", luiInfo.getCluId());
1373
1374         // Create
1375         luiInfo = new LuiInfo();
1376
1377         luiInfo.setLuiCode("LUI Test Code");
1378         luiInfo.setMaxSeats(100);
1379         luiInfo.setState("Test Lui State");
1380         luiInfo.setEffectiveDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20101203"));
1381         luiInfo.setExpirationDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20801231"));
1382         luiInfo.getAttributes().add(new AttributeInfo("luiAttrKey1", "luiAttrValue1"));
1383         luiInfo.getAttributes().add(new AttributeInfo("luiAttrKey2", "luiAttrValue2"));
1384
1385         LuiInfo createdLui = atpService.createLui("CLU-2", "ATP-3", luiInfo, contextInfo);
1386
1387         assertEquals("ATP-3", createdLui.getAtpId());
1388         assertEquals("LUI Test Code", createdLui.getLuiCode());
1389         assertEquals(100L, (long) createdLui.getMaxSeats());
1390         assertEquals(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20101203"), luiInfo.getEffectiveDate());
1391         assertEquals(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20801231"), luiInfo.getExpirationDate());
1392         assertEquals("CLU-2", createdLui.getCluId());
1393         assertEquals(2, createdLui.getAttributes().size());
1394         assertEquals("luiAttrValue1", createdLui.getAttributeValue(createdLui.getAttributes(),"luiAttrKey1"));
1395         assertEquals("luiAttrValue2", createdLui.getAttributeValue(createdLui.getAttributes(),"luiAttrKey2"));
1396
1397         // update
1398         createdLui.setAtpId("ATP-2");
1399         createdLui.setCluId("CLU-1");
1400         createdLui.setLuiCode("LUI Test Code Update");
1401         createdLui.setMaxSeats(75);
1402         createdLui.setState("Test Lui State Update");
1403         createdLui.setEffectiveDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20111203"));
1404         createdLui.setExpirationDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20811231"));
1405         createdLui.getAttributes().add(new AttributeInfo("luiAttrKey1", "luiAttrValue1Updated"));
1406         createdLui.getAttributes().add(new AttributeInfo("luiAttrKey2", "luiAttrValue2Updated"));
1407
1408         LuiInfo updatedLui = null;
1409         try {
1410             updatedLui = atpService.updateLui(createdLui.getId(), createdLui, contextInfo);
1411         } catch (VersionMismatchException vme) {
1412             fail("CluService.updateLui() threw unexpected VersionMismatchException");
1413         }
1414
1415         // confirm update worked
1416         assertTrue(null != updatedLui);
1417         assertEquals("ATP-2", updatedLui.getAtpId());
1418         assertEquals("CLU-1", updatedLui.getCluId());
1419         assertEquals("LUI Test Code Update", updatedLui.getLuiCode());
1420         assertEquals(75L, (long) createdLui.getMaxSeats());
1421         assertEquals(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20111203"), updatedLui.getEffectiveDate());
1422         assertEquals(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20811231"), updatedLui.getExpirationDate());
1423         assertEquals(2, updatedLui.getAttributes().size());
1424         assertEquals("luiAttrValue1Updated", updatedLui.getAttributeValue(updatedLui.getAttributes(),"luiAttrKey1"));
1425         assertEquals("luiAttrValue2Updated", updatedLui.getAttributeValue(updatedLui.getAttributes(),"luiAttrKey2"));
1426
1427         // optimistic locking working?
1428         try {
1429             atpService.updateLui(createdLui.getId(), createdLui, contextInfo);
1430             fail("CluService.updateLui did not throw expected VersionMismatchException");
1431         } catch (VersionMismatchException e) {
1432         }
1433
1434         // delete what we created
1435         atpService.deleteLui(createdLui.getId(), contextInfo);
1436         // and try it again
1437         try {
1438             atpService.deleteLui(createdLui.getId(), contextInfo);
1439             fail("CluService.deleteLui() of previously-delete Lui did not throw expected DoesNotExistException");
1440         } catch (DoesNotExistException dnee) {
1441         }
1442     }
1443
1444     @Test
1445     public void test12GetLuiIdsByCluId() throws DoesNotExistException,
1446             InvalidParameterException, MissingParameterException,
1447             OperationFailedException {
1448
1449         List<String> luiIds = null;
1450         try {
1451             luiIds = atpService.getLuiIdsByCluId(null, contextInfo);
1452             fail("CluService.getLuiIdsByCluId() did not throw MissingParameterException for null Clu ID");
1453         } catch (MissingParameterException e) {
1454         }
1455         luiIds = atpService.getLuiIdsByCluId("CLU-1", contextInfo);
1456
1457         Collections.sort(luiIds);
1458
1459         assertTrue(null != luiIds);
1460         assertEquals(3, luiIds.size());
1461
1462         assertEquals("LUI-1", luiIds.get(0));
1463         assertEquals("LUI-3", luiIds.get(2));
1464         luiIds = atpService.getLuiIdsByCluId("CLU-2", contextInfo);
1465         assertEquals(1, luiIds.size());
1466         luiIds = atpService.getLuiIdsByCluId("Non-existent Clu", contextInfo);
1467         assertTrue(null == luiIds || luiIds.size() == 0);
1468     }
1469
1470     @Test
1471     public void test13GetLuiIdsInAtpByCluId() throws DoesNotExistException,
1472             InvalidParameterException, OperationFailedException,
1473             MissingParameterException {
1474
1475         List<String> luiIds = null;
1476         try {
1477             luiIds = atpService.getLuiIdsInAtpByCluId(null, "ATP-1", contextInfo);
1478             fail("CluService.getLuiIdsInAtpByCluId() did not throw MissingParameterException for null Clu ID");
1479         } catch (MissingParameterException e) {
1480         }
1481         try {
1482             luiIds = atpService.getLuiIdsInAtpByCluId("CLU-1", null, contextInfo);
1483             fail("CluService.getLuiIdsInAtpByCluId() did not throw MissingParameterException for null AtpKey");
1484         } catch (MissingParameterException e) {
1485         }
1486         luiIds = atpService.getLuiIdsInAtpByCluId("CLU-1", "ATP-2", contextInfo);
1487         Collections.sort(luiIds);
1488         assertTrue(null != luiIds);
1489         assertEquals(2, luiIds.size());
1490         assertEquals("LUI-2", luiIds.get(0));
1491         assertEquals("LUI-3", luiIds.get(1));
1492         luiIds = atpService.getLuiIdsInAtpByCluId("CLU-1", "ATP-1", contextInfo);
1493         assertEquals(1, luiIds.size());
1494         luiIds = atpService.getLuiIdsInAtpByCluId("Non-existent Clu", "ATP-2", contextInfo);
1495         assertTrue(null == luiIds || luiIds.size() == 0);
1496         luiIds = atpService.getLuiIdsInAtpByCluId("CLU-2", "Non-existent ATP", contextInfo);
1497         assertTrue(null == luiIds || luiIds.size() == 0);
1498     }*/
1499
1500    /* KSCM Unsupported in KSCM     @Test
1501     public void test14GetLuLuRelationTypeInfo() throws OperationFailedException,
1502             DoesNotExistException, MissingParameterException, InvalidParameterException, PermissionDeniedException {
1503
1504         TypeInfo luLuRelTypeInfo;
1505
1506         try {
1507             atpService.getLuLuRelationType(null, contextInfo);
1508             fail("CluService.getLuLuRelationTypeInfo() did not throw MissingParameterException for null LuLuRelationType key");
1509         } catch (MissingParameterException e) {
1510         }
1511         luLuRelTypeInfo = atpService.getLuLuRelationType("luLuType.type1", contextInfo);
1512         assertEquals("bob", luLuRelTypeInfo.getName());
1513         luLuRelTypeInfo = atpService.getLuLuRelationType("luLuType.type2", contextInfo);
1514         assertEquals("my desc2", luLuRelTypeInfo.getDescr());
1515         assertEquals("rev name2", luLuRelTypeInfo.getName());
1516         assertEquals("rev desc2", luLuRelTypeInfo.getDescr());
1517         try {
1518             atpService.getLuLuRelationType("Non-existent LuLuRelationType", contextInfo);
1519             fail("CluService.getLuLuRelationTypeInfo() did not throw DoesNotExistException when retrieving non-existent LuLuRelationType");
1520         } catch (DoesNotExistException dnee) {
1521         }
1522     }*/
1523
1524    /* KSCM Unsupported in KSCM    @Test
1525     public void test15GetLuLuRelationTypeInfos() throws OperationFailedException,
1526             DoesNotExistException, MissingParameterException {
1527
1528         List<TypeInfo> luLuRelTypeInfos;
1529         luLuRelTypeInfos = atpService.getLuLuRelationTypes(contextInfo);
1530         Collections.sort(luLuRelTypeInfos,
1531                 new Comparator<LuLuRelationTypeInfo>() {
1532                     @Override
1533                     public int compare(LuLuRelationTypeInfo o1,
1534                             LuLuRelationTypeInfo o2) {
1535                         return o1.getId().compareTo(o2.getId());
1536                     }
1537                 });
1538         assertEquals(13, luLuRelTypeInfos.size());
1539         assertEquals("kuali.lu.lu.relation.type.hasCoreProgram", luLuRelTypeInfos.get(0).getKey());
1540     }*/
1541
1542    /* LuiService not used in CM      @Test
1543     public void test16UpdateLuiState() throws DataValidationErrorException,
1544             DoesNotExistException, InvalidParameterException,
1545             OperationFailedException, PermissionDeniedException,
1546             ParseException, AlreadyExistsException, MissingParameterException,
1547             DependentObjectsExistException {
1548
1549         try {
1550             atpService.updateLuiState(null, "Suspended", contextInfo);
1551             fail("CluService.updateLuiState() did not throw MissingParameterException for null Lui ID");
1552         } catch (MissingParameterException e) {
1553         }
1554         try {
1555             atpService.updateLuiState("LUI-1", null, contextInfo);
1556             fail("CluService.updateLuiState() did not throw MissingParameterException for null state");
1557         } catch (MissingParameterException e) {
1558         }
1559
1560         // create a Lui whose state we'll update. Create a new one so its
1561         // MetaInfo gets created in prePersist()
1562         LuiInfo luiInfo = new LuiInfo();
1563
1564         luiInfo.setLuiCode("LUI Test Code");
1565         luiInfo.setMaxSeats(100);
1566         luiInfo.setState("Approved");
1567         luiInfo.setEffectiveDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20101203"));
1568         luiInfo.setExpirationDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20801231"));
1569         luiInfo.getAttributes().add(new AttributeInfo("luiAttrKey1", "luiAttrValue1"));
1570         luiInfo.getAttributes().add(new AttributeInfo("luiAttrKey2", "luiAttrValue2"));
1571
1572         LuiInfo createdLui = atpService.createLui("CLU-2", "ATP-3", luiInfo, contextInfo);
1573         // make sure the db's in the state we expect
1574         assertEquals("Approved", createdLui.getState());
1575
1576         // update and confirm it was updated
1577         LuiInfo updatedLui = atpService.updateLuiState(createdLui.getId(),
1578                 "Active", contextInfo);
1579         assertEquals("Active", updatedLui.getState());
1580
1581         // and now explicitly retrieve it without a call to updateLuiState and
1582         // confirm same
1583         updatedLui = atpService.getLui(createdLui.getId(), contextInfo);
1584         assertEquals("Active", updatedLui.getState());
1585
1586         // and delete it to keep db consistent for other tests
1587         atpService.deleteLui(updatedLui.getId(), contextInfo);
1588     }
1589
1590     @Test
1591     public void test17GetLuisByRelation() throws DoesNotExistException,
1592             InvalidParameterException, MissingParameterException,
1593             OperationFailedException {
1594
1595         List<LuiInfo> luis = atpService.getLuisByRelation("LUI-1", "luLuType.type1", contextInfo);
1596         assertTrue(luis == null || luis.size() == 0);
1597         luis = atpService.getLuisByRelation("LUI-2", "luLuType.type1", contextInfo);
1598         Collections.sort(luis, new Comparator<LuiInfo>() {
1599             @Override
1600             public int compare(LuiInfo o1, LuiInfo o2) {
1601                 return o1.getId().compareTo(o2.getId());
1602             }
1603         });
1604         assertEquals(1, luis.size());
1605         assertEquals("LUI-1", luis.get(0).getId());
1606     }
1607
1608     @Test
1609     public void test18GetLuiIdsByRelation() throws DoesNotExistException,
1610             InvalidParameterException, MissingParameterException,
1611             OperationFailedException {
1612
1613         List<String> luis = atpService.getLuiIdsByRelation("LUI-1",      "luLuType.type1", contextInfo);
1614         assertTrue(luis == null || luis.size() == 0);
1615         luis = atpService.getLuiIdsByRelation("LUI-2", "luLuType.type1", contextInfo);
1616         Collections.sort(luis);
1617         assertEquals(1, luis.size());
1618         assertEquals("LUI-1", luis.get(0));
1619     }*/
1620
1621    @Test
1622    public void test19OutcomeLO() throws AlreadyExistsException,
1623            DoesNotExistException, InvalidParameterException,
1624            MissingParameterException, OperationFailedException,
1625            PermissionDeniedException, DependentObjectsExistException,
1626            ParseException, DataValidationErrorException,
1627            VersionMismatchException, ReadOnlyException {
1628
1629        CluLoRelationInfo reltnInfo = new CluLoRelationInfo();
1630        reltnInfo.setCluId("CLU-1");
1631        reltnInfo.setLoId("LO-1");
1632        reltnInfo.setStateKey("FINAL");
1633        reltnInfo.setTypeKey("kuali.lu.lo.relation.type.includes");
1634        reltnInfo.setEffectiveDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20101203"));
1635        reltnInfo.setExpirationDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20801231"));
1636
1637        CluLoRelationInfo crReltnInfo = client.createCluLoRelation("CLU-1",
1638                "LO-1", "kuali.lu.lo.relation.type.includes", reltnInfo, contextInfo);
1639
1640        assertEquals(crReltnInfo.getCluId(), "CLU-1");
1641        assertEquals(crReltnInfo.getLoId(), "LO-1");
1642        assertEquals(crReltnInfo.getStateKey(), "FINAL");
1643        assertEquals(crReltnInfo.getTypeKey(), "kuali.lu.lo.relation.type.includes");
1644
1645        try {
1646            reltnInfo.setCluId("MISSING CLU");
1647            client.createCluLoRelation("MISSING CLU", "LO-1", "kuali.lu.lo.relation.type.includes",
1648                    reltnInfo, contextInfo);
1649            fail("Should have thrown DoesNotExistException");
1650        } catch (DoesNotExistException e) {
1651            assertNotNull(e.getMessage());
1652            assertEquals("MISSING CLU", e.getMessage());
1653        }
1654
1655        CluLoRelationInfo gtReltnInfo = client.getCluLoRelation(crReltnInfo
1656                .getId(), contextInfo);
1657
1658        assertEquals(gtReltnInfo.getCluId(), "CLU-1");
1659        assertEquals(gtReltnInfo.getLoId(), "LO-1");
1660        assertEquals(gtReltnInfo.getStateKey(), "FINAL");
1661        assertEquals(gtReltnInfo.getTypeKey(), "kuali.lu.lo.relation.type.includes");
1662
1663        CluLoRelationInfo reltnInfo1 = new CluLoRelationInfo();
1664        reltnInfo1.setCluId("CLU-1");
1665        reltnInfo1.setLoId("LO-2");
1666        reltnInfo1.setStateKey("FINAL");
1667        reltnInfo1.setTypeKey("kuali.lu.lo.relation.type.includes");
1668        reltnInfo1.setEffectiveDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20101203"));
1669        reltnInfo1.setExpirationDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20801231"));
1670
1671        CluLoRelationInfo crReltnInfo1 = client.createCluLoRelation("CLU-1",
1672                "LO-2", "kuali.lu.lo.relation.type.includes", reltnInfo1, contextInfo);
1673
1674        List<CluLoRelationInfo> reltns = client.getCluLoRelationsByClu("CLU-1", contextInfo);
1675        assertEquals(2, reltns.size());
1676
1677        List<CluLoRelationInfo> reltns1 = client.getCluLoRelationsByLo("LO-1", contextInfo);
1678        assertEquals(1, reltns1.size());
1679        assertEquals(reltns1.get(0).getCluId(), "CLU-1");
1680
1681        // Test update relation
1682        crReltnInfo1.setStateKey("NEW");
1683        CluLoRelationInfo updateReltn = client.updateCluLoRelation(crReltnInfo1
1684                .getId(), crReltnInfo1, contextInfo);
1685        assertEquals("NEW", updateReltn.getStateKey());
1686
1687        StatusInfo status = client.deleteCluLoRelation(crReltnInfo.getId(), contextInfo);
1688        assertTrue(status.getIsSuccess());
1689
1690        status = client.deleteCluLoRelation(updateReltn.getId(), contextInfo);
1691        assertTrue(status.getIsSuccess());
1692
1693    }
1694
1695    /* KSCM Unsupported in KSCM     @Test
1696     public void test20ResultUsageType() throws DoesNotExistException,
1697             InvalidParameterException, MissingParameterException,
1698             OperationFailedException, PermissionDeniedException {
1699
1700         TypeInfo lrType = atpService.getResultUsageType("lrType.finalGrade", contextInfo);
1701         assertEquals("Final Grade", lrType.getName());
1702         List<TypeInfo> lrTypes = atpService.getResultUsageTypes(contextInfo);
1703         assertEquals(2, lrTypes.size());
1704
1705     }*/
1706
1707    @Test
1708    public void test21GetClusByRelation() throws AlreadyExistsException,
1709            DataValidationErrorException, DoesNotExistException,
1710            InvalidParameterException, MissingParameterException,
1711            OperationFailedException, PermissionDeniedException,
1712            ParseException, VersionMismatchException {
1713        List<CluInfo> clus = client
1714                .getClusByRelatedCluAndRelationType("CLU-1", "luLuType.type1", contextInfo);
1715        assertNotNull(clus);
1716        assertEquals(2, clus.size());
1717
1718        clus = client.getClusByRelatedCluAndRelationType("CLUXX-2", "luLuType.type1", contextInfo);
1719        assertTrue(clus == null || clus.size() == 0);
1720
1721        clus = client.getClusByRelatedCluAndRelationType("CLU-2", "luLuType.type1XX", contextInfo);
1722        assertTrue(clus == null || clus.size() == 0);
1723
1724        try {
1725            client.getClusByRelatedCluAndRelationType(null, "luLuType.type1XX", contextInfo);
1726            fail("MissingParameterException should have been thrown");
1727        } catch (MissingParameterException e) {
1728            assertNotNull(e.getMessage());
1729            assertEquals("relatedCluId can not be null", e.getMessage());
1730        }
1731        try {
1732            client.getClusByRelatedCluAndRelationType("CLU-2", null, contextInfo);
1733            fail("MissingParameterException should have been thrown");
1734        } catch (MissingParameterException e) {
1735            assertNotNull(e.getMessage());
1736            assertEquals("luLuRelationTypeKey can not be null", e.getMessage());
1737        }
1738
1739        List<String> ids = client.getCluIdsByRelatedCluAndRelationType("CLU-2", "luLuType.type1", contextInfo);
1740        assertNotNull(ids);
1741        assertEquals(1, ids.size());
1742
1743        ids = client.getCluIdsByRelatedCluAndRelationType("CLUXX-2", "luLuType.type1", contextInfo);
1744        assertTrue(null == ids || ids.size() == 0);
1745
1746        ids = client.getCluIdsByRelatedCluAndRelationType("CLU-2", "luLuType.type1XX", contextInfo);
1747        assertTrue(null == ids || ids.size() == 0);
1748
1749        try {
1750            client.getCluIdsByRelatedCluAndRelationType(null, "luLuType.type1XX", contextInfo);
1751            fail("MissingParameterException should have been thrown");
1752        } catch (MissingParameterException e) {
1753            assertNotNull(e.getMessage());
1754            assertEquals("relatedCluId can not be null", e.getMessage());
1755        }
1756        try {
1757            client.getCluIdsByRelatedCluAndRelationType("CLU-2", null, contextInfo);
1758            fail("MissingParameterException should have been thrown");
1759        } catch (MissingParameterException e) {
1760            assertNotNull(e.getMessage());
1761            assertEquals("cluCluRelationTypeKey can not be null", e.getMessage());
1762        }
1763    }
1764
1765    @Test
1766    public void test22SearchForResults() throws AlreadyExistsException,
1767            DataValidationErrorException, DoesNotExistException,
1768            InvalidParameterException, MissingParameterException,
1769            OperationFailedException, PermissionDeniedException,
1770            ParseException, VersionMismatchException {
1771        List<SearchParamInfo> queryParamValueList = new ArrayList<SearchParamInfo>(
1772                0);
1773        SearchRequestInfo searchRequest = new SearchRequestInfo();
1774        searchRequest.setSearchKey("lu.search.clus");
1775        searchRequest.setParams(queryParamValueList);
1776        SearchResultInfo clus = client.search(searchRequest, ContextInfoTestUtility.getEnglishContextInfo());
1777        Collections.sort(clus.getRows(), new Comparator<SearchResultRowInfo>() {
1778            @Override
1779            public int compare(SearchResultRowInfo o1, SearchResultRowInfo o2) {
1780                return o1.getCells().get(0).getValue().compareTo(
1781                        o2.getCells().get(0).getValue());
1782            }
1783        });
1784        assertNotNull(clus);
1785        assertEquals(111, clus.getRows().size());
1786        SearchResultRowInfo result = clus.getRows().get(0);
1787        assertNotNull(result);
1788
1789        List<SearchResultCellInfo> resultCells = result.getCells();
1790        assertNotNull(resultCells);
1791        assertEquals(3, resultCells.size());
1792
1793        SearchResultCellInfo resultCell = resultCells.get(0);
1794        assertEquals("lu.resultColumn.cluId", resultCell.getKey());
1795        assertEquals("00000000-a389-4fd0-b349-1e649c20fd08", resultCell
1796                .getValue());
1797        resultCell = resultCells.get(1);
1798        assertEquals("lu.resultColumn.cluOfficialIdentifier.longName",
1799                resultCell.getKey());
1800        assertEquals("Advanced Applied Linear Algebra", resultCell.getValue());
1801    }
1802
1803
1804    @Test
1805    public void test23SearchForClus() throws AlreadyExistsException,
1806            DataValidationErrorException, DoesNotExistException,
1807            InvalidParameterException, MissingParameterException,
1808            OperationFailedException, PermissionDeniedException,
1809            ParseException, VersionMismatchException {
1810
1811        List<SearchParamInfo> queryParamValueList = new ArrayList<SearchParamInfo>();
1812        SearchParamInfo typeParm = new SearchParamInfo();
1813        typeParm.setKey("lu.queryParam.luOptionalType");
1814        typeParm.getValues().add(CluServiceConstants.CREDIT_COURSE_LU_TYPE_KEY);
1815        queryParamValueList.add(typeParm);
1816        SearchParamInfo stateParm = new SearchParamInfo();
1817        stateParm.setKey("lu.queryParam.luOptionalState");
1818        stateParm.getValues().add("Approved");
1819        stateParm.getValues().add("Active");
1820        stateParm.getValues().add("Retired");
1821        queryParamValueList.add(stateParm);
1822
1823        SearchRequestInfo searchRequest = new SearchRequestInfo();
1824        searchRequest.setSearchKey("lu.search.current");
1825        searchRequest.setParams(queryParamValueList);
1826        SearchResultInfo clus = client.search(searchRequest, ContextInfoTestUtility.getEnglishContextInfo());
1827        assertEquals(98, clus.getRows().size());
1828    }
1829
1830    @Test
1831    public void test24SearchCourseLevelRanges() throws MissingParameterException, PermissionDeniedException, OperationFailedException, InvalidParameterException {
1832        List<SearchParamInfo> queryParamValueList = new ArrayList<SearchParamInfo>();
1833        SearchParamInfo courseLevelsParam = new SearchParamInfo();
1834        courseLevelsParam.setKey("lu.queryParam.luOptionalCrsNoRange");
1835        courseLevelsParam.getValues().add("100 -200");
1836        queryParamValueList.add(courseLevelsParam);
1837        SearchRequestInfo searchRequest = new SearchRequestInfo();
1838        searchRequest.setSearchKey("lu.search.generic");
1839        searchRequest.setParams(queryParamValueList);
1840        SearchResultInfo clus = client.search(searchRequest, ContextInfoTestUtility.getEnglishContextInfo());
1841        Collections.sort(clus.getRows(), new Comparator<SearchResultRowInfo>() {
1842            @Override
1843            public int compare(SearchResultRowInfo o1, SearchResultRowInfo o2) {
1844                return o1.getCells().get(0).getValue().compareTo(
1845                        o2.getCells().get(0).getValue());
1846            }
1847        });
1848        assertNotNull(clus);
1849    }
1850
1851    @Test
1852    public void test25CluValidation() throws ParseException, AlreadyExistsException,
1853            DataValidationErrorException, DoesNotExistException,
1854            InvalidParameterException, MissingParameterException,
1855            OperationFailedException, PermissionDeniedException,
1856            VersionMismatchException, DependentObjectsExistException {
1857
1858        CluInfo clu = new CluInfo();
1859
1860        CluAccountingInfo accountingInfo = new CluAccountingInfo();
1861        accountingInfo.getAttributes().add(new AttributeInfo("AccountingAttrKey1", "AccountingAttrValue1"));
1862        accountingInfo.getAttributes().add(new AttributeInfo("AccountingAttrKey2", "AccountingAttrValue2"));
1863        clu.setAccountingInfo(accountingInfo);
1864
1865        CluIdentifierInfo officialIdentifier = new CluIdentifierInfo();
1866        officialIdentifier.setTypeKey("kuali.lu.type.CreditCourse.identifier.official");
1867        officialIdentifier.setStateKey("active");
1868        officialIdentifier.setCode("offIdcode");
1869        officialIdentifier.setDivision("offIddivision");
1870        officialIdentifier.setLevel("offIdlevel");
1871        officialIdentifier.setLongName("offIdlongName");
1872        // ERROR: Short name should be less than 20 chars
1873        officialIdentifier.setShortName("offId-shortName-should-be-longer-than-twenty-characters");
1874        officialIdentifier.setVariation("offIdvariation");
1875        officialIdentifier.setSuffixCode("offIdsuffixcode");
1876        officialIdentifier.setOrgId("offIdorgid");
1877        clu.setOfficialIdentifier(officialIdentifier);
1878
1879        CluIdentifierInfo cluId1 = new CluIdentifierInfo();
1880        cluId1.setTypeKey("kuali.lu.type.CreditCourse.identifier.cross-listed");
1881        cluId1.setStateKey("Sctive");
1882        cluId1.setCode("cluIdonecode");
1883        cluId1.setDivision("cluIdonedivision");
1884        cluId1.setLevel("cluIdonelevel");
1885        cluId1.setLongName("cluIdonelongName");
1886        cluId1.setShortName("cluIdoneshortName");
1887        // ERROR: Min length 3
1888        // ERROR: Only numbers allowed
1889        cluId1.setSuffixCode("cl");
1890        cluId1.setOrgId("cluIdoneorgid");
1891
1892        clu.getAlternateIdentifiers().add(cluId1);
1893
1894        CluIdentifierInfo cluId2 = new CluIdentifierInfo();
1895        // Check for different type validations
1896        cluId2.setTypeKey("kuali.lu.type.CreditCourse.identifier.version");
1897        cluId2.setStateKey("Sctive");
1898        cluId2.setCode("cluIdtwocode");
1899        cluId2.setDivision("cluIdtwodivision");
1900        cluId2.setLevel("cluIdtwolevel");
1901        cluId2.setLongName("cluIdtwolongName");
1902        cluId2.setShortName("cluIdtwoshortName");
1903        // ERROR: Should be uppper case
1904        // ERROR: should be of size 1
1905        cluId2.setVariation("ab");
1906        cluId2.setSuffixCode("cluIdtwosuffixcode");
1907        // ERROR OrgId required
1908        // cluId.setOrgId();
1909        clu.getAlternateIdentifiers().add(cluId2);
1910
1911        clu.getAttributes().add(new AttributeInfo("cluAttrKey1", "cluAttrValue1"));
1912        clu.getAttributes().add(new AttributeInfo("cluAttrKey2", "cluAttrValue2"));
1913
1914        clu.setCanCreateLui(true);
1915
1916        // ERROR non negative integer
1917        clu.setDefaultEnrollmentEstimate(-545);
1918        clu.setDefaultMaximumEnrollment(999);
1919
1920        RichTextInfo desc = new RichTextInfo();
1921        desc.setFormatted("<p>DESC FORMATTED</p>");
1922        desc.setPlain("DESC PLAIN");
1923        clu.setDescr(desc);
1924
1925        clu.setEffectiveDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20100203"));
1926        clu.setExpirationDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("21001231"));
1927
1928        clu.setIsEnrollable(true);
1929
1930        AffiliatedOrgInfo aforg = new AffiliatedOrgInfo();
1931        aforg.setOrgId("AFFORGone");
1932        aforg.setPercentage(35l);
1933
1934        AffiliatedOrgInfo aforg1 = new AffiliatedOrgInfo();
1935        aforg1.setOrgId("AFForgtwo");
1936        aforg1.setPercentage(65l);
1937
1938        List<AffiliatedOrgInfo> affiliatedOrgs = new ArrayList<AffiliatedOrgInfo>();
1939        affiliatedOrgs.add(aforg);
1940        affiliatedOrgs.add(aforg1);
1941
1942        CurrencyAmountInfo ca = new CurrencyAmountInfo();
1943        ca.setCurrencyQuantity(100);
1944        ca.setCurrencyTypeKey("DLLR");
1945
1946        CurrencyAmountInfo ca1 = new CurrencyAmountInfo();
1947        ca.setCurrencyQuantity(200);
1948        ca.setCurrencyTypeKey("DLLR");
1949
1950        List<CurrencyAmountInfo> caList = new ArrayList<CurrencyAmountInfo>();
1951        caList.add(ca);
1952
1953        List<CurrencyAmountInfo> caList1 = new ArrayList<CurrencyAmountInfo>();
1954        caList.add(ca);
1955        caList.add(ca1);
1956
1957        RichTextInfo cfRecDesc = new RichTextInfo();
1958        cfRecDesc.setPlain("Clu Fee Record");
1959
1960        CluFeeRecordInfo feeRec = new CluFeeRecordInfo();
1961        feeRec.setAffiliatedOrgs(affiliatedOrgs);
1962        feeRec.setFeeAmounts(caList);
1963        feeRec.setFeeType("FEE-TYPE-X");
1964        feeRec.setRateType("RATE-TYPE-X");
1965        feeRec.setDescr(cfRecDesc);
1966
1967        CluFeeRecordInfo feeRec1 = new CluFeeRecordInfo();
1968        feeRec1.setAffiliatedOrgs(affiliatedOrgs);
1969        feeRec1.setFeeAmounts(caList1);
1970        feeRec1.setFeeType("FEE-TYPE-Y");
1971        feeRec1.setRateType("RATE-TYPE-Y");
1972
1973        List<CluFeeRecordInfo> feeRecList = new ArrayList<CluFeeRecordInfo>();
1974        feeRecList.add(feeRec);
1975        feeRecList.add(feeRec1);
1976
1977        RichTextInfo cfDesc = new RichTextInfo();
1978        cfDesc.setPlain("Clu Fee");
1979
1980        CluFeeInfo feeInfo = new CluFeeInfo();
1981        feeInfo.getAttributes().add(new AttributeInfo("FeeAttrKey1", "FeeAttrValue1"));
1982        feeInfo.getAttributes().add(new AttributeInfo("FeeAttrKey2", "FeeAttrValue2"));
1983        feeInfo.setCluFeeRecords(feeRecList);
1984        feeInfo.setDescr(cfDesc);
1985        clu.setFeeInfo(feeInfo);
1986
1987        clu.setIsHasEarlyDropDeadline(true);
1988
1989        clu.setIsHazardousForDisabledStudents(true);
1990
1991        CluInstructorInfo primaryInstructor = new CluInstructorInfo();
1992        primaryInstructor.setOrgId("EXTorgIdone");
1993        primaryInstructor.setPersonId("EXTpersonIdone");
1994        primaryInstructor.getAttributes().add(new AttributeInfo("PrimaryInstAttrKey1", "PrimaryInstAttrValue1"));
1995        primaryInstructor.getAttributes().add(new AttributeInfo("PrimaryInstAttrKey2", "PrimaryInstAttrValue2"));
1996        clu.setPrimaryInstructor(primaryInstructor);
1997
1998        CluInstructorInfo instructor1 = new CluInstructorInfo();
1999        instructor1.setOrgId("EXTorgIdtwo");
2000        instructor1.setPersonId("EXTpersonIdtwo");
2001        instructor1.getAttributes().add(new AttributeInfo("Inst1AttrKey1", "Inst1AttrValue1"));
2002        instructor1.getAttributes().add(new AttributeInfo("Inst1AttrKey2", "Inst1AttrValue2"));
2003        clu.getInstructors().add(instructor1);
2004
2005        CluInstructorInfo instructor2 = new CluInstructorInfo();
2006        instructor2.setOrgId("EXTorgIdthree");
2007        instructor2.setPersonId("EXTpersonIdthree");
2008        instructor2.getAttributes().add(new AttributeInfo("Inst2AttrKey1", "Inst2AttrValue1"));
2009        instructor2.getAttributes().add(new AttributeInfo("Inst2AttrKey2", "Inst2AttrValue2"));
2010        clu.getInstructors().add(instructor2);
2011
2012        LuCodeInfo luCode1 = new LuCodeInfo();
2013        luCode1.setId("luCode1.key");
2014        RichTextInfo luCode1Desc = new RichTextInfo();
2015        luCode1Desc.setPlain("luCode1desc");
2016        luCode1.setDescr(luCode1Desc);
2017        luCode1.setValue("luCode1value");
2018        luCode1.getAttributes().add(new AttributeInfo("luCode1AttrKey1", "luCode1AttrValue1"));
2019        luCode1.getAttributes().add(new AttributeInfo("luCode1AttrKey2", "luCode1AttrValue2"));
2020        clu.getLuCodes().add(luCode1);
2021
2022        LuCodeInfo luCode2 = new LuCodeInfo();
2023        luCode2.setId("luCode2.key");
2024        RichTextInfo luCodetwodesc = new RichTextInfo();
2025        luCodetwodesc.setPlain("luCodetwodesc");
2026        luCode2.setDescr(luCodetwodesc);
2027        luCode2.setValue("luCodetwovalue");
2028        luCode2.getAttributes().add(new AttributeInfo("luCode2AttrKey1", "luCode2AttrValue1"));
2029        luCode2.getAttributes().add(new AttributeInfo("luCode2AttrKey2", "luCode2AttrValue2"));
2030        clu.getLuCodes().add(luCode2);
2031
2032        RichTextInfo marketingDesc = new RichTextInfo();
2033        marketingDesc.setFormatted("<p>marketingDesc FORMATTED</p>");
2034        marketingDesc.setPlain("marketingDesc PLAIN");
2035
2036        clu.setNextReviewPeriod("nextReviewPeriod");
2037
2038        clu.getOfferedAtpTypes().add("offeredAtpType1");
2039        clu.getOfferedAtpTypes().add("offeredAtpType2");
2040
2041
2042        CluInstructorInfo pubPrimaryInstructor = new CluInstructorInfo();
2043        pubPrimaryInstructor.setOrgId("EXTorgId");
2044        pubPrimaryInstructor.setPersonId("EXTpersonId");
2045        pubPrimaryInstructor.getAttributes().add(new AttributeInfo("PubPrimaryInstAttrKey1", "PubPrimaryInstAttrValue1"));
2046        pubPrimaryInstructor.getAttributes().add(new AttributeInfo("PubPrimaryInstAttrKey2", "PubPrimaryInstAttrValue2"));
2047
2048        CluInstructorInfo pubInstructor1 = new CluInstructorInfo();
2049        pubInstructor1.setOrgId("EXTorgIdtwo");
2050        pubInstructor1.setPersonId("EXT-personId-two");
2051        pubInstructor1.getAttributes().add(new AttributeInfo("PubInst1AttrKey1", "PubInst1AttrValue1"));
2052        pubInstructor1.getAttributes().add(new AttributeInfo("PubInst1AttrKey2", "PubInst1AttrValue2"));
2053
2054        CluInstructorInfo pubInstructor2 = new CluInstructorInfo();
2055        pubInstructor2.setOrgId("EXTorgIdthree");
2056        pubInstructor2.setPersonId("EXTpersonIdthree");
2057        pubInstructor2.getAttributes().add(new AttributeInfo("PubInst2AttrKey1", "PubInst2AttrValue1"));
2058        pubInstructor2.getAttributes().add(new AttributeInfo("PubInst2AttrKey2", "PubInst2AttrValue2"));
2059
2060        clu.setReferenceURL("http://student.kuali.org/clus");
2061
2062        TimeAmountInfo stdDuration = new TimeAmountInfo();
2063        stdDuration.setAtpDurationTypeKey("EXTstdDurationId");
2064        stdDuration.setTimeQuantity(7867);
2065        clu.setStdDuration(stdDuration);
2066
2067        createCampusLocationList(clu);
2068
2069        createIntensity(clu);
2070
2071        createAccreditationList(clu);
2072
2073        createAdminOrgs(clu);
2074
2075        clu.setTypeKey(CluServiceConstants.CREDIT_COURSE_LU_TYPE_KEY);
2076        clu.setStateKey("template");
2077
2078        List<ValidationResultInfo> valerros = client.validateClu("SYSTEM", clu, contextInfo);
2079
2080        assertEquals(2, valerros.size());
2081    }
2082
2083    @Test
2084    public void test26AddCluToCluSet() throws ParseException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, UnsupportedActionException, ReadOnlyException {
2085        CluSetInfo createdCluSet = client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, createCluSetInfo(), contextInfo);
2086
2087        StatusInfo status = client.addCluToCluSet("CLU-1", createdCluSet.getId(), contextInfo);
2088        CluSetInfo getCluSetInfo = client.getCluSet(createdCluSet.getId(), contextInfo);
2089
2090        assertTrue(status.getIsSuccess());
2091        assertEquals(1, getCluSetInfo.getCluIds().size());
2092        assertEquals("CLU-1", getCluSetInfo.getCluIds().get(0));
2093    }
2094
2095    @Test
2096    public void test27AddCluToCluSet_DuplicateCluId() throws ParseException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, UnsupportedActionException, ReadOnlyException {
2097        CluSetInfo createdCluSet = client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, createCluSetInfo(), contextInfo);
2098
2099        StatusInfo status = client.addCluToCluSet("CLU-1", createdCluSet.getId(), contextInfo);
2100        assertTrue(status.getIsSuccess());
2101
2102        status = client.addCluToCluSet("CLU-1", createdCluSet.getId(), contextInfo);
2103        assertFalse(status.getIsSuccess());
2104    }
2105
2106    @Test
2107    public void test28AddClusToCluSet() throws ParseException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, UnsupportedActionException, ReadOnlyException {
2108        CluSetInfo createdCluSet = client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, createCluSetInfo(), contextInfo);
2109
2110        // Somehow cannot add 2 CLUs in sequence (JTA rollback exception) but adding a single CLU works
2111        //CluInfo clu1 = createCluInfo();
2112        //CluInfo clu2 = createCluInfo();
2113        //CluInfo createdClu1 = atpService.createClu("luType.shell.course", clu1);
2114        //CluInfo createdClu2 = atpService.createClu("luType.shell.course", clu2);
2115        //List<String> cluIdList = Arrays.asList(new String[] {createdClu1.getId(), createdClu2.getId()});
2116
2117        List<String> cluIdList = Arrays.asList("CLU-1", "CLU-2", "CLU-3", "CLU-4");
2118
2119        StatusInfo status = client.addClusToCluSet(cluIdList, createdCluSet.getId(), contextInfo);
2120        CluSetInfo getCluSetInfo = client.getCluSet(createdCluSet.getId(), contextInfo);
2121        assertTrue(status.getIsSuccess());
2122        assertEquals(4, getCluSetInfo.getCluIds().size());
2123        assertTrue(getCluSetInfo.getCluIds().contains("CLU-1"));
2124        assertTrue(getCluSetInfo.getCluIds().contains("CLU-2"));
2125        assertTrue(getCluSetInfo.getCluIds().contains("CLU-3"));
2126        assertTrue(getCluSetInfo.getCluIds().contains("CLU-4"));
2127    }
2128
2129    @Test
2130    public void test29AddClusToCluSet_InvalidCluId() throws ParseException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, UnsupportedActionException, ReadOnlyException {
2131        CluSetInfo createdCluSet = client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, createCluSetInfo(), contextInfo);
2132
2133        List<String> cluIdList = Arrays.asList("CLU-1", "CLU-2", "CLU-INVALID-ID", "CLU-4");
2134
2135        try {
2136            client.addClusToCluSet(cluIdList, createdCluSet.getId(), contextInfo);
2137            fail("Adding a non-existent CLU (id='CLU-INVALID-ID') to CluSet should have failed");
2138        } catch (DoesNotExistException e) {
2139            assertNotNull(e.getMessage());
2140            assertEquals("Could not get current clu version info by cluId", e.getMessage());
2141        }
2142    }
2143
2144    @Test
2145    public void test30AddClusToCluSet_DuplicateCluId() throws ParseException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, UnsupportedActionException, ReadOnlyException {
2146        CluSetInfo createdCluSet = client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, createCluSetInfo(), contextInfo);
2147
2148        List<String> cluIdList = Arrays.asList("CLU-1", "CLU-2", "CLU-2", "CLU-4");
2149
2150        StatusInfo status = client.addClusToCluSet(cluIdList, createdCluSet.getId(), contextInfo);
2151        assertEquals("CluSet already contains Clu (id='CLU-2')", status.getMessage());
2152    }
2153
2154    @Test
2155    public void test31AddClusToCluSet_InvalidCluSetId() throws ParseException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, UnsupportedActionException {
2156        List<String> cluIdList = Arrays.asList("CLU-1", "CLU-2", "CLU-3", "CLU-4");
2157
2158        try {
2159            client.addClusToCluSet(cluIdList, "CLUSET-INVALID-ID", contextInfo);
2160            fail("Adding CLUs to a non-existent CluSet (id='CLUSET-INVALID-ID') should have failed");
2161        } catch (DoesNotExistException e) {
2162            assertNotNull(e.getMessage());
2163            assertEquals("CLUSET-INVALID-ID", e.getMessage());
2164        }
2165    }
2166
2167    @Test
2168    public void test32AddCluSetToCluSet() throws ParseException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, UnsupportedActionException, CircularRelationshipException, ReadOnlyException {
2169        CluSetInfo createdCluSet = client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, createCluSetInfo(), contextInfo);
2170
2171        StatusInfo status = client.addCluSetToCluSet(createdCluSet.getId(), "CLUSET-1", contextInfo);
2172        CluSetInfo getCluSetInfo = client.getCluSet(createdCluSet.getId(), contextInfo);
2173
2174        assertTrue(status.getIsSuccess());
2175        assertEquals(1, getCluSetInfo.getCluSetIds().size());
2176        assertTrue(getCluSetInfo.getCluSetIds().contains("CLUSET-1"));
2177    }
2178
2179    @Test
2180    public void test33AddCluSetToCluSet_CircularRelationshipException() throws ParseException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, UnsupportedActionException, CircularRelationshipException, ReadOnlyException {
2181        CluSetInfo createdCluSet = client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, createCluSetInfo(), contextInfo);
2182
2183        try {
2184            client.addCluSetToCluSet(createdCluSet.getId(), createdCluSet.getId(), contextInfo);
2185            fail("Adding a CluSet to itself should have failed");
2186        } catch (CircularRelationshipException e) {
2187            assertNotNull(e.getMessage());
2188            assertEquals("Cannot add a CluSet (id=" + createdCluSet.getId() + ") to ifself", e.getMessage());
2189        }
2190    }
2191
2192    @Test
2193    public void test34AddCluSetToCluSet_NestedCircularRelationshipException() throws ParseException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, UnsupportedActionException, CircularRelationshipException, ReadOnlyException {
2194        CluSetInfo createdCluSet1 = client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, createCluSetInfo(), contextInfo);
2195        CluSetInfo createdCluSet2 = client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, createCluSetInfo(), contextInfo);
2196        CluSetInfo createdCluSet3 = client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, createCluSetInfo(), contextInfo);
2197
2198        client.addCluSetToCluSet(createdCluSet3.getId(), createdCluSet1.getId(), contextInfo);
2199        client.addCluSetToCluSet(createdCluSet2.getId(), createdCluSet3.getId(), contextInfo);
2200
2201        try {
2202            client.addCluSetToCluSet(createdCluSet1.getId(), createdCluSet2.getId(), contextInfo);
2203            fail("Adding CluSet should have thrown a CircularRelationshipException");
2204        } catch (CircularRelationshipException e) {
2205            assertNotNull(e.getMessage());
2206            assertEquals("CluSet (id=" + createdCluSet1.getId() + ") already contains this CluSet (id=" + createdCluSet1.getId() + ")", e.getMessage());
2207        }
2208    }
2209
2210    @Test
2211    public void test35AddCluSetToCluSet_DuplicateCluSetId() throws ParseException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, UnsupportedActionException, CircularRelationshipException, ReadOnlyException {
2212
2213        CluSetInfo createdCluSet = client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, createCluSetInfo(), contextInfo);
2214
2215        StatusInfo status = client.addCluSetToCluSet(createdCluSet.getId(), "CLUSET-1", contextInfo);
2216        assertTrue(status.getIsSuccess());
2217
2218        try {
2219            client.addCluSetToCluSet(createdCluSet.getId(), "CLUSET-1", contextInfo);
2220            fail("Adding a duplicate CluSet (id='CLUSET-1') to CluSet should have failed");
2221        } catch (OperationFailedException e) {
2222            assertNotNull(e.getMessage());
2223            assertEquals("CluSet (id=" + createdCluSet.getId() + ") already contains CluSet (id='CLUSET-1')", e.getMessage());
2224        }
2225    }
2226
2227    @Test
2228    public void test36AddCluSetToCluSet_InvalidCluSetId() throws ParseException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, UnsupportedActionException, CircularRelationshipException, ReadOnlyException {
2229
2230        CluSetInfo createdCluSet = client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, createCluSetInfo(), contextInfo);
2231
2232        try {
2233            client.addCluSetToCluSet(createdCluSet.getId(), "CLUSET-INVALID-ID", contextInfo);
2234            fail("Adding a non-existent CluSet (id='CLUSET-INVALID-ID') to CluSet should have failed");
2235        } catch (DoesNotExistException e) {
2236            assertNotNull(e.getMessage());
2237            assertEquals("CLUSET-INVALID-ID", e.getMessage());
2238        }
2239    }
2240
2241    @Test
2242    public void test37AddCluSetsToCluSet() throws ParseException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, UnsupportedActionException, CircularRelationshipException, ReadOnlyException {
2243
2244        CluSetInfo createdCluSet = client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, createCluSetInfo(), contextInfo);
2245
2246        List<String> cluIdList = Arrays.asList("CLUSET-1", "CLUSET-2", "CLUSET-3", "CLUSET-4");
2247
2248        StatusInfo status = client.addCluSetsToCluSet(createdCluSet.getId(), cluIdList, contextInfo);
2249        CluSetInfo getCluSetInfo = client.getCluSet(createdCluSet.getId(), contextInfo);
2250
2251        assertTrue(status.getIsSuccess());
2252        assertEquals(4, getCluSetInfo.getCluSetIds().size());
2253        assertTrue(getCluSetInfo.getCluSetIds().contains("CLUSET-1"));
2254        assertTrue(getCluSetInfo.getCluSetIds().contains("CLUSET-2"));
2255        assertTrue(getCluSetInfo.getCluSetIds().contains("CLUSET-3"));
2256        assertTrue(getCluSetInfo.getCluSetIds().contains("CLUSET-4"));
2257    }
2258
2259    @Test
2260    public void test38AddCluSetsToCluSet_InvalidCluSetId() throws ParseException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, UnsupportedActionException, CircularRelationshipException, ReadOnlyException {
2261
2262        CluSetInfo createdCluSet = client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, createCluSetInfo(), contextInfo);
2263
2264        List<String> cluIdList = Arrays.asList("CLUSET-1", "CLUSET-INVALID-ID", "CLUSET-3", "CLUSET-4");
2265
2266        try {
2267            client.addCluSetsToCluSet(createdCluSet.getId(), cluIdList, contextInfo);
2268            fail("Adding a non-existent CluSet (id='CLUSET-INVALID-ID') to CluSet should have failed");
2269        } catch (DoesNotExistException e) {
2270            assertNotNull(e.getMessage());
2271            assertEquals("CLUSET-INVALID-ID", e.getMessage());
2272        }
2273    }
2274
2275    @Test
2276    public void test39AddCluSetsToCluSet_DuplicateCluSetId() throws ParseException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, UnsupportedActionException, CircularRelationshipException, ReadOnlyException {
2277
2278        CluSetInfo createdCluSet = client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, createCluSetInfo(), contextInfo);
2279
2280        List<String> cluIdList = Arrays.asList("CLUSET-1", "CLUSET-2", "CLUSET-3", "CLUSET-2");
2281
2282        try {
2283            client.addCluSetsToCluSet(createdCluSet.getId(), cluIdList, contextInfo);
2284            fail("Adding a duplicate CluSet (id='CLUSET-2') to CluSet should have failed");
2285        } catch (OperationFailedException e) {
2286            assertNotNull(e.getMessage());
2287            assertEquals("CluSet (id=" + createdCluSet.getId() + ") already contains CluSet (id='CLUSET-2')", e.getMessage());
2288        }
2289    }
2290
2291    @Test
2292    public void test40AddCluSetsToCluSet_CircularRelationshipException() throws ParseException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, UnsupportedActionException, CircularRelationshipException, ReadOnlyException {
2293
2294        CluSetInfo createdCluSet = client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, createCluSetInfo(), contextInfo);
2295        // Adding createdCluSet to itself
2296        List<String> cluIdList = Arrays.asList("CLUSET-1", "CLUSET-2", createdCluSet.getId(), "CLUSET-4");
2297
2298        try {
2299            client.addCluSetsToCluSet(createdCluSet.getId(), cluIdList, contextInfo);
2300            fail("Adding a CluSet to itself should have failed");
2301        } catch (CircularRelationshipException e) {
2302            assertNotNull(e.getMessage());
2303            assertEquals("Cannot add a CluSet (id=" + createdCluSet.getId() + ") to ifself", e.getMessage());
2304        }
2305    }
2306
2307    @Test
2308    public void test41AddCluSetsToCluSet_NestedCircularRelationshipException() throws ParseException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, UnsupportedActionException, CircularRelationshipException, ReadOnlyException {
2309
2310        CluSetInfo createdCluSet1 = client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, createCluSetInfo(), contextInfo);
2311        CluSetInfo createdCluSet2 = client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, createCluSetInfo(), contextInfo);
2312        CluSetInfo createdCluSet3 = client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, createCluSetInfo(), contextInfo);
2313
2314        List<String> cluIdList1 = Arrays.asList("CLUSET-1", "CLUSET-2", createdCluSet1.getId());
2315        client.addCluSetsToCluSet(createdCluSet3.getId(), cluIdList1, contextInfo);
2316
2317        // Adding createdCluSet to itself
2318        List<String> cluIdList2 = Arrays.asList("CLUSET-1", createdCluSet3.getId());
2319        client.addCluSetsToCluSet(createdCluSet2.getId(), cluIdList2, contextInfo);
2320
2321        try {
2322            List<String> cluIdList3 = Arrays.asList(createdCluSet2.getId());
2323            client.addCluSetsToCluSet(createdCluSet1.getId(), cluIdList3, contextInfo);
2324            fail("Adding CluSet should have thrown a CircularRelationshipException");
2325        } catch (CircularRelationshipException e) {
2326            assertNotNull(e.getMessage());
2327            assertEquals("CluSet (id=" + createdCluSet1.getId() + ") already contains this CluSet (id=" + createdCluSet1.getId() + ")", e.getMessage());
2328        }
2329    }
2330
2331
2332    @Test
2333    public void test42CreateDynamicCluSet_Simple() throws ParseException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, UnsupportedActionException, ReadOnlyException {
2334
2335        CluSetInfo cluSet = createCluSetInfo();
2336
2337        MembershipQueryInfo query = new MembershipQueryInfo();
2338        query.setSearchTypeKey("lu.search.clus");
2339
2340        cluSet.setMembershipQuery(query);
2341        CluSetInfo createdCluSet = client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, cluSet, contextInfo);
2342
2343        assertNotNull(createdCluSet);
2344        assertNotNull(createdCluSet.getMembershipQuery());
2345        assertNotNull(createdCluSet.getMembershipQuery().getId());
2346        assertNotNull(createdCluSet.getMembershipQuery().getSearchTypeKey());
2347        assertEquals(query.getSearchTypeKey(), createdCluSet.getMembershipQuery().getSearchTypeKey());
2348        assertNotNull(createdCluSet.getMembershipQuery().getQueryParamValues());
2349        assertNotNull(createdCluSet.getCluIds());
2350        assertEquals(107, createdCluSet.getCluIds().size());
2351    }
2352
2353    private MembershipQueryInfo getMembershipQueryInfo() {
2354        List<org.kuali.student.r2.core.search.dto.SearchParamInfo> queryParamValueList = new ArrayList<org.kuali.student.r2.core.search.dto.SearchParamInfo>();
2355        org.kuali.student.r2.core.search.dto.SearchParamInfo sp1 = new org.kuali.student.r2.core.search.dto.SearchParamInfo();
2356        sp1.setKey("lu.queryParam.startsWith.cluCode");
2357        sp1.setValues(Arrays.asList("AAST"));
2358        queryParamValueList.add(sp1);
2359        org.kuali.student.r2.core.search.dto.SearchParamInfo sp2 = new org.kuali.student.r2.core.search.dto.SearchParamInfo();
2360        sp2.setKey("lu.queryParam.cluState");
2361        sp2.setValues(Arrays.asList("Active"));
2362        queryParamValueList.add(sp2);
2363
2364        MembershipQueryInfo query = new MembershipQueryInfo();
2365        query.setSearchTypeKey("lu.search.cluByCodeAndState");
2366        query.setQueryParamValues(queryParamValueList);
2367
2368        return query;
2369    }
2370
2371    // KSCM-626 TODO SearchParamInfo mismatch between MembershipInfoQuery and SearchRequestInfo
2372    @Test
2373    public void test43CreateDynamicCluSet() throws ParseException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, UnsupportedActionException, ReadOnlyException {
2374
2375        CluSetInfo cluSet = createCluSetInfo();
2376
2377        MembershipQueryInfo query = getMembershipQueryInfo();
2378        cluSet.setMembershipQuery(query);
2379
2380        CluSetInfo createdCluSet = client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, cluSet, contextInfo);
2381
2382        assertNotNull(createdCluSet);
2383        assertNotNull(createdCluSet.getMembershipQuery());
2384        assertNotNull(createdCluSet.getMembershipQuery().getId());
2385        assertNotNull(createdCluSet.getMembershipQuery().getSearchTypeKey());
2386        assertEquals(query.getSearchTypeKey(), createdCluSet.getMembershipQuery().getSearchTypeKey());
2387        assertNotNull(createdCluSet.getMembershipQuery().getQueryParamValues());
2388        assertEquals(query.getQueryParamValues().size(), createdCluSet.getMembershipQuery().getQueryParamValues().size());
2389        assertNotNull(createdCluSet.getCluIds());
2390        assertEquals(10, createdCluSet.getCluIds().size());
2391
2392        CluSetInfo getCluSet = client.getCluSet(createdCluSet.getId(), contextInfo);
2393
2394        assertNotNull(getCluSet);
2395        assertNotNull(getCluSet.getMembershipQuery());
2396        assertNotNull(getCluSet.getMembershipQuery().getId());
2397        assertNotNull(getCluSet.getMembershipQuery().getSearchTypeKey());
2398        assertEquals(query.getSearchTypeKey(), getCluSet.getMembershipQuery().getSearchTypeKey());
2399        assertNotNull(getCluSet.getMembershipQuery().getQueryParamValues());
2400        assertEquals(query.getQueryParamValues().size(), getCluSet.getMembershipQuery().getQueryParamValues().size());
2401        assertNotNull(getCluSet.getCluIds());
2402        assertEquals(10, getCluSet.getCluIds().size());
2403    }
2404
2405    @Test
2406    public void test44CreateCluSet_InvalidCluSet1() throws ParseException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, UnsupportedActionException, ReadOnlyException {
2407
2408        CluSetInfo cluSet = createCluSetInfo();
2409        cluSet.getCluIds().add("CLU-1");
2410
2411        MembershipQueryInfo query = new MembershipQueryInfo();
2412        query.setSearchTypeKey("lu.search.clus");
2413
2414        cluSet.setMembershipQuery(query);
2415
2416        try {
2417            client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, cluSet, contextInfo);
2418            fail("Creating CluSet should have thrown an UnsupportedActionException. Cannot add CLUs and Dynamic CluSets into one CluSet");
2419        } catch (UnsupportedActionException e) {
2420            assertNotNull(e.getMessage());
2421            assertEquals("Dynamic CluSet cannot contain Clus and/or CluSets. CluSet id=null", e.getMessage());
2422        }
2423
2424    }
2425
2426    @Test
2427    public void test45CreateCluSet_InvalidCluSet2() throws ParseException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, UnsupportedActionException, ReadOnlyException {
2428
2429        CluSetInfo cluSet = createCluSetInfo();
2430        cluSet.getCluSetIds().add("CLUSET-1");
2431
2432        MembershipQueryInfo query = new MembershipQueryInfo();
2433        query.setSearchTypeKey("lu.search.clus");
2434
2435        cluSet.setMembershipQuery(query);
2436
2437        try {
2438            client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, cluSet, contextInfo);
2439            fail("Creating CluSet should have thrown an UnsupportedActionException. Cannot add CluSets and Dynamic CluSets into one CluSet");
2440        } catch (UnsupportedActionException e) {
2441            assertNotNull(e.getMessage());
2442            assertEquals("Dynamic CluSet cannot contain Clus and/or CluSets. CluSet id=null", e.getMessage());
2443        }
2444
2445    }
2446
2447    @Test
2448    public void test46CreateCluSet_InvalidCluSet3() throws ParseException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, UnsupportedActionException, ReadOnlyException {
2449
2450        CluSetInfo cluSet = createCluSetInfo();
2451        cluSet.getCluIds().add("CLU-1");
2452        cluSet.getCluSetIds().add("CLUSET-1");
2453
2454        try {
2455            client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, cluSet, contextInfo);
2456            fail("Creating CluSet should have thrown an UnsupportedActionException. Cannot add CLUs and CluSets into one CluSet");
2457        } catch (UnsupportedActionException e) {
2458            assertNotNull(e.getMessage());
2459            assertEquals("CluSet cannot contain both Clus and CluSets. CluSet id=null", e.getMessage());
2460        }
2461
2462    }
2463
2464    // KSCM-626 TODO SearchParamInfo mismatch between MembershipInfoQuery and SearchRequestInfo
2465    @Test
2466    public void test47GetDynamicCluSet() throws ParseException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, UnsupportedActionException, ReadOnlyException {
2467
2468        CluSetInfo cluSet = createCluSetInfo();
2469
2470        MembershipQueryInfo query = getMembershipQueryInfo();
2471        cluSet.setMembershipQuery(query);
2472        CluSetInfo createdCluSet = client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, cluSet, contextInfo);
2473        assertNotNull(createdCluSet);
2474        assertNotNull(createdCluSet.getCluIds());
2475
2476        CluSetInfo getCluSet = client.getCluSet(createdCluSet.getId(), contextInfo);
2477
2478        assertNotNull(getCluSet);
2479        assertNotNull(getCluSet.getMembershipQuery());
2480        assertNotNull(getCluSet.getMembershipQuery().getId());
2481        assertNotNull(getCluSet.getMembershipQuery().getSearchTypeKey());
2482        assertEquals(query.getSearchTypeKey(), getCluSet.getMembershipQuery().getSearchTypeKey());
2483        assertNotNull(getCluSet.getMembershipQuery().getQueryParamValues());
2484        assertEquals(query.getQueryParamValues().size(), getCluSet.getMembershipQuery().getQueryParamValues().size());
2485        assertEquals(createdCluSet.getCluIds().size(), getCluSet.getCluIds().size());
2486        assertNotNull(getCluSet.getCluIds());
2487        assertEquals(10, getCluSet.getCluIds().size());
2488    }
2489
2490    @Test
2491    public void test48GetDynamicCluSet_Simple() throws ParseException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, UnsupportedActionException, ReadOnlyException {
2492
2493        CluSetInfo cluSet = createCluSetInfo();
2494
2495        MembershipQueryInfo query = new MembershipQueryInfo();
2496        query.setSearchTypeKey("lu.search.clus");
2497
2498        cluSet.setMembershipQuery(query);
2499        CluSetInfo createdCluSet = client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, cluSet, contextInfo);
2500        assertNotNull(createdCluSet);
2501        assertNotNull(createdCluSet.getCluIds());
2502
2503        CluSetInfo getCluSet = client.getCluSet(createdCluSet.getId(), contextInfo);
2504        assertNotNull(getCluSet);
2505        assertNotNull(getCluSet.getCluIds());
2506        assertEquals(createdCluSet.getCluIds().size(), getCluSet.getCluIds().size());
2507    }
2508
2509    @Test
2510    public void test49GetCluSetTreeView() throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
2511
2512        CluSetTreeViewInfo treeView = client.getCluSetTreeView("CLUSET-2", contextInfo);
2513        assertNotNull(treeView);
2514        assertEquals(2, treeView.getCluSets().size());
2515
2516        CluSetTreeViewInfo cluSet = treeView.getCluSets().get(1);
2517        assertNotNull(cluSet);
2518        assertEquals("CLUSET-4", cluSet.getId());
2519        assertEquals(2, cluSet.getClus().size());
2520
2521        CluInfo clu = cluSet.getClus().get(1);
2522        assertNotNull(clu);
2523        assertEquals("CLU-3", clu.getId());
2524    }
2525
2526    @Test
2527    public void test50GetCluSetTreeView_dynamicCluSet() throws ParseException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, UnsupportedActionException, DoesNotExistException, ReadOnlyException {
2528
2529        CluSetInfo cluSet = createCluSetInfo();
2530
2531        MembershipQueryInfo query = new MembershipQueryInfo();
2532        query.setSearchTypeKey("lu.search.clus");
2533
2534        cluSet.setMembershipQuery(query);
2535        CluSetInfo createdCluSet = client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, cluSet, contextInfo);
2536        assertNotNull(createdCluSet);
2537        assertNotNull(createdCluSet.getCluIds());
2538
2539        CluSetTreeViewInfo treeView = client.getCluSetTreeView(createdCluSet.getId(), contextInfo);
2540        assertNotNull(treeView);
2541        assertEquals(createdCluSet.getCluIds().size(), treeView.getClus().size());
2542    }
2543
2544    @Test
2545    public void test51GetCluSetTreeView_invalidCluSet()
2546            throws InvalidParameterException, MissingParameterException,
2547            OperationFailedException, PermissionDeniedException {
2548
2549        try {
2550            client.getCluSetTreeView("CLUSET-XX", contextInfo);
2551            fail("DoesNotExistException should have been thrown");
2552        } catch (DoesNotExistException e) {
2553            assertNotNull(e.getMessage());
2554            assertEquals("CLUSET-XX", e.getMessage());
2555        }
2556    }
2557
2558    @Test
2559    public void test52GetCluSetTreeView_nullCluSet()
2560            throws DoesNotExistException, InvalidParameterException,
2561            OperationFailedException, PermissionDeniedException {
2562
2563        try {
2564            client.getCluSetTreeView(null, contextInfo);
2565            fail("MissingParameterException should have been thrown");
2566        } catch (MissingParameterException e) {
2567            assertNotNull(e.getMessage());
2568            assertEquals("cluSetId can not be null", e.getMessage());
2569        }
2570    }
2571
2572    // KSCM-626 TODO SearchParamInfo mismatch between MembershipInfoQuery and SearchRequestInfo
2573    @Test
2574    public void test53UpdateDynamicCluSet() throws ParseException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, VersionMismatchException, UnsupportedActionException, CircularRelationshipException, ReadOnlyException {
2575
2576        CluSetInfo cluSet1 = createCluSetInfo();
2577
2578        //Create clu set
2579        ArrayList<org.kuali.student.r2.core.search.dto.SearchParamInfo> queryParamValueList = new ArrayList<org.kuali.student.r2.core.search.dto.SearchParamInfo>();
2580        MembershipQueryInfo query1 = new MembershipQueryInfo();
2581        query1.setSearchTypeKey("lu.search.clus");
2582        query1.setQueryParamValues(queryParamValueList);
2583
2584        cluSet1.setMembershipQuery(query1);
2585        // Version 0
2586        CluSetInfo createdCluSet = client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, cluSet1, contextInfo);
2587        // createdCluSet should be version 1 but is 0
2588
2589        //Update clu set
2590        MembershipQueryInfo query2 = getMembershipQueryInfo();
2591
2592        createdCluSet.setMembershipQuery(query2);
2593
2594        // Dynamic CluSet so we can't have any CluSet ids or Clu ids
2595        createdCluSet.getCluSetIds().clear();
2596        createdCluSet.getCluIds().clear();
2597        CluSetInfo updatedCluSet = client.updateCluSet(createdCluSet.getId(), createdCluSet, contextInfo);
2598
2599        assertNotNull(updatedCluSet);
2600        assertNotNull(updatedCluSet.getCluIds());
2601        assertEquals(10, updatedCluSet.getCluIds().size());
2602        assertTrue(updatedCluSet.getCluSetIds().isEmpty());
2603    }
2604
2605    @Test
2606    public void test54UpdateCluSet_VersionMismatch() throws ParseException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, UnsupportedActionException, VersionMismatchException, CircularRelationshipException, ReadOnlyException {
2607
2608        CluSetInfo createCluSet = createCluSetInfo();
2609
2610        CluSetInfo createdCluSet1 = client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, createCluSet, contextInfo);
2611        createdCluSet1.getCluSetIds().add("CLUSET-1");
2612        createdCluSet1.getCluSetIds().add("CLUSET-2");
2613
2614        CluSetInfo updatedCluSet1 = client.updateCluSet(createdCluSet1.getId(), createdCluSet1, contextInfo);
2615        assertEquals(2, updatedCluSet1.getCluSetIds().size());
2616
2617        try {
2618            client.updateCluSet(updatedCluSet1.getId(), createdCluSet1, contextInfo);
2619            fail("Should have thrown VersionMismatchException.");
2620        } catch (VersionMismatchException e) {
2621            assertNotNull(e.getMessage());
2622            assertEquals("CluSet (id=" + updatedCluSet1.getId() + ") to be updated is not the current version (version=0), current version=2", e.getMessage());
2623        }
2624    }
2625
2626    @Test
2627    public void test55UpdateCluSet_ClearCluSets() throws ParseException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, UnsupportedActionException, VersionMismatchException, CircularRelationshipException, ReadOnlyException {
2628
2629        CluSetInfo createCluSet = createCluSetInfo();
2630        createCluSet.getCluSetIds().add("CLUSET-1");
2631        createCluSet.getCluSetIds().add("CLUSET-2");
2632        createCluSet.getCluSetIds().add("CLUSET-3");
2633
2634        CluSetInfo createdCluSet1 = client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, createCluSet, contextInfo);
2635        assertEquals(3, createdCluSet1.getCluSetIds().size());
2636
2637        createdCluSet1.getCluSetIds().clear();
2638
2639        CluSetInfo updatedCluSet1 = client.updateCluSet(createdCluSet1.getId(), createdCluSet1, contextInfo);
2640        assertTrue(updatedCluSet1.getCluSetIds().isEmpty());
2641
2642        CluSetInfo getCluSet1 = client.getCluSet(updatedCluSet1.getId(), contextInfo);
2643        assertTrue(getCluSet1.getCluSetIds().isEmpty());
2644    }
2645
2646    @Test
2647    public void test56UpdateCluSet_AddCluSets() throws ParseException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, UnsupportedActionException, VersionMismatchException, CircularRelationshipException, ReadOnlyException {
2648
2649        CluSetInfo createCluSet = createCluSetInfo();
2650
2651        CluSetInfo createdCluSet1 = client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, createCluSet, contextInfo);
2652        assertTrue(createdCluSet1.getCluSetIds().isEmpty());
2653
2654        createdCluSet1.getCluSetIds().add("CLUSET-1");
2655        createdCluSet1.getCluSetIds().add("CLUSET-2");
2656
2657        CluSetInfo updatedCluSet1 = client.updateCluSet(createdCluSet1.getId(), createdCluSet1, contextInfo);
2658        assertEquals(2, updatedCluSet1.getCluSetIds().size());
2659
2660        CluSetInfo getCluSet1 = client.getCluSet(updatedCluSet1.getId(), contextInfo);
2661        assertEquals(2, getCluSet1.getCluSetIds().size());
2662        assertTrue(getCluSet1.getCluSetIds().contains("CLUSET-1"));
2663        assertTrue(getCluSet1.getCluSetIds().contains("CLUSET-2"));
2664    }
2665
2666    @Test
2667    public void test57UpdateCluSet_removeCluSets() throws ParseException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, UnsupportedActionException, VersionMismatchException, CircularRelationshipException, ReadOnlyException {
2668
2669        CluSetInfo createCluSet = createCluSetInfo();
2670        createCluSet.getCluSetIds().add("CLUSET-1");
2671        createCluSet.getCluSetIds().add("CLUSET-2");
2672        createCluSet.getCluSetIds().add("CLUSET-3");
2673
2674        CluSetInfo createdCluSet1 = client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, createCluSet, contextInfo);
2675        assertEquals(3, createdCluSet1.getCluSetIds().size());
2676
2677        createdCluSet1.getCluSetIds().remove("CLUSET-2");
2678
2679        CluSetInfo updatedCluSet1 = client.updateCluSet(createdCluSet1.getId(), createdCluSet1, contextInfo);
2680        assertEquals(2, updatedCluSet1.getCluSetIds().size());
2681
2682        CluSetInfo getCluSet1 = client.getCluSet(updatedCluSet1.getId(), contextInfo);
2683        assertEquals(2, getCluSet1.getCluSetIds().size());
2684        assertTrue(getCluSet1.getCluSetIds().contains("CLUSET-1"));
2685        assertTrue(getCluSet1.getCluSetIds().contains("CLUSET-3"));
2686    }
2687
2688    @Test
2689    public void test58UpdateCluSet_ClearClus() throws ParseException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, UnsupportedActionException, VersionMismatchException, CircularRelationshipException, ReadOnlyException {
2690
2691        CluSetInfo createCluSet = createCluSetInfo();
2692        createCluSet.getCluIds().add("CLU-1");
2693        createCluSet.getCluIds().add("CLU-2");
2694        assertEquals(2, createCluSet.getCluIds().size());
2695
2696        CluSetInfo createdCluSet1 = client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, createCluSet, contextInfo);
2697        assertEquals(2, createdCluSet1.getCluIds().size());
2698
2699        assertNotNull(createdCluSet1);
2700        assertNotNull(createdCluSet1.getCluIds());
2701        assertEquals(2, createdCluSet1.getCluIds().size());
2702
2703        // Remove all CLUs
2704        createdCluSet1.getCluIds().clear();
2705
2706        CluSetInfo updatedCluSet1 = client.updateCluSet(createdCluSet1.getId(), createdCluSet1, contextInfo);
2707
2708        assertNotNull(updatedCluSet1);
2709        assertNotNull(updatedCluSet1.getCluIds());
2710        assertTrue(updatedCluSet1.getCluIds().isEmpty());
2711
2712        CluSetInfo getCluSet1 = client.getCluSet(updatedCluSet1.getId(), contextInfo);
2713
2714        assertNotNull(getCluSet1);
2715        assertNotNull(getCluSet1.getCluIds());
2716        assertTrue(getCluSet1.getCluIds().isEmpty());
2717    }
2718
2719    @Test
2720    public void test59UpdateCluSet_AddClu() throws ParseException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, UnsupportedActionException, VersionMismatchException, CircularRelationshipException, ReadOnlyException {
2721
2722        CluSetInfo createCluSet = createCluSetInfo();
2723        createCluSet.getCluIds().add("CLU-1");
2724        createCluSet.getCluIds().add("CLU-2");
2725        assertEquals(2, createCluSet.getCluIds().size());
2726
2727        CluSetInfo createdCluSet1 = client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, createCluSet, contextInfo);
2728        assertEquals(2, createdCluSet1.getCluIds().size());
2729
2730        createdCluSet1.getCluIds().add("CLU-3");
2731
2732        assertNotNull(createdCluSet1);
2733        assertNotNull(createdCluSet1.getCluIds());
2734        assertEquals(3, createdCluSet1.getCluIds().size());
2735
2736        CluSetInfo updatedCluSet1 = client.updateCluSet(createdCluSet1.getId(), createdCluSet1, contextInfo);
2737
2738        assertNotNull(updatedCluSet1);
2739        assertNotNull(updatedCluSet1.getCluIds());
2740        assertEquals(3, updatedCluSet1.getCluIds().size());
2741
2742        CluSetInfo getCluSet1 = client.getCluSet(updatedCluSet1.getId(), contextInfo);
2743
2744        assertNotNull(getCluSet1);
2745        assertNotNull(getCluSet1.getCluIds());
2746        assertEquals(3, getCluSet1.getCluIds().size());
2747    }
2748
2749    @Test
2750    public void test60UpdateCluSet_RemoveClu() throws ParseException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, UnsupportedActionException, VersionMismatchException, CircularRelationshipException, ReadOnlyException {
2751
2752        CluSetInfo createCluSet = createCluSetInfo();
2753        createCluSet.getCluIds().add("CLU-1");
2754        createCluSet.getCluIds().add("CLU-2");
2755        assertEquals(2, createCluSet.getCluIds().size());
2756
2757        CluSetInfo createdCluSet1 = client.createCluSet(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, createCluSet, contextInfo);
2758        assertEquals(2, createdCluSet1.getCluIds().size());
2759
2760        createdCluSet1.getCluIds().remove("CLU-1");
2761
2762        assertNotNull(createdCluSet1);
2763        assertNotNull(createdCluSet1.getCluIds());
2764        assertEquals(1, createdCluSet1.getCluIds().size());
2765
2766        CluSetInfo updatedCluSet1 = client.updateCluSet(createdCluSet1.getId(), createdCluSet1, contextInfo);
2767
2768        assertNotNull(updatedCluSet1);
2769        assertNotNull(updatedCluSet1.getCluIds());
2770        assertEquals(1, updatedCluSet1.getCluIds().size());
2771        assertTrue(updatedCluSet1.getCluIds().contains("CLU-2"));
2772
2773        CluSetInfo getCluSet1 = client.getCluSet(updatedCluSet1.getId(), contextInfo);
2774
2775        assertNotNull(getCluSet1);
2776        assertNotNull(getCluSet1.getCluIds());
2777        assertEquals(1, getCluSet1.getCluIds().size());
2778    }
2779
2780    @Test
2781    public void test61CreateCluResult() throws AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, ReadOnlyException {
2782
2783        contextInfo.setPrincipalId("123");
2784
2785        CluResultInfo dto = new CluResultInfo();
2786        RichTextInfo desc = new RichTextInfo();
2787        desc.setPlain("Plain description");
2788        dto.setDescr(desc);
2789        dto.setCluId("CLU-1");
2790        dto.setStateKey("active");
2791        dto.setTypeKey("kuali.resultType.gradeCourseResult");
2792        dto.setEffectiveDate(new Date());
2793        dto.setExpirationDate(new Date());
2794
2795        CluResultInfo cluResult = client.createCluResult("CLU-1", "kuali.resultType.gradeCourseResult", dto, contextInfo);
2796
2797        assertNotNull(cluResult);
2798        assertNotNull(cluResult.getDescr());
2799        assertEquals(dto.getDescr().getPlain(), cluResult.getDescr().getPlain());
2800        assertNotNull(cluResult.getId());
2801        assertNotNull(cluResult.getCluId());
2802        assertEquals(dto.getCluId(), cluResult.getCluId());
2803        assertNotNull(cluResult.getTypeKey());
2804        assertEquals(dto.getTypeKey(), cluResult.getTypeKey());
2805        assertEquals(dto.getEffectiveDate(), cluResult.getEffectiveDate());
2806        assertEquals(dto.getExpirationDate(), cluResult.getExpirationDate());
2807    }
2808
2809    @Test
2810    public void test62UpdateCluResult() throws AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, VersionMismatchException, ReadOnlyException {
2811
2812        contextInfo.setPrincipalId("123");
2813
2814        CluResultInfo dto = new CluResultInfo();
2815        RichTextInfo desc1 = new RichTextInfo();
2816        desc1.setPlain("Plain description");
2817        dto.setDescr(desc1);
2818        dto.setCluId("CLU-1");
2819        dto.setStateKey("Suspended");
2820        dto.setTypeKey("kuali.resultType.gradeCourseResult");
2821        dto.setEffectiveDate(new Date());
2822        dto.setExpirationDate(new Date());
2823
2824        List<ResultOptionInfo> resultOptions = new ArrayList<ResultOptionInfo>();
2825        ResultOptionInfo option = new ResultOptionInfo();
2826        RichTextInfo desc2 = new RichTextInfo();
2827        desc2.setPlain("Plain description");
2828        option.setDescr(desc2);
2829        option.setEffectiveDate(new Date());
2830        option.setExpirationDate(new Date());
2831        option.setResultComponentId("kuali.resultComponent.grade.letter");
2832        option.setResultUsageTypeKey(null);
2833        option.setStateKey("Suspended");
2834        resultOptions.add(option);
2835
2836        dto.setResultOptions(resultOptions);
2837
2838        CluResultInfo createCluResult = client.createCluResult("CLU-1", "kuali.resultType.gradeCourseResult", dto, contextInfo);
2839        createCluResult = client.getCluResult(createCluResult.getId(), contextInfo);
2840
2841        assertNotNull(createCluResult);
2842
2843        createCluResult.setCluId("CLU-2");
2844        RichTextInfo desc3 = new RichTextInfo();
2845        desc3.setPlain("Plain description again");
2846        createCluResult.setDescr(desc3);
2847        createCluResult.setEffectiveDate(new Date());
2848        createCluResult.setExpirationDate(new Date());
2849        createCluResult.setStateKey("active");
2850        createCluResult.setTypeKey("kuali.resultType.creditCourseResult");
2851
2852        RichTextInfo desc4 = new RichTextInfo();
2853        desc4.setPlain("Some more plain description");
2854        createCluResult.getResultOptions().get(0).setDescr(desc4);
2855        createCluResult.getResultOptions().get(0).setEffectiveDate(new Date());
2856        createCluResult.getResultOptions().get(0).setExpirationDate(new Date());
2857        createCluResult.getResultOptions().get(0).setResultComponentId("kuali.resultComponent.grade.passFail");
2858        createCluResult.getResultOptions().get(0).setResultUsageTypeKey("lrType.finalGrade");
2859        createCluResult.getResultOptions().get(0).setStateKey("active");
2860
2861        CluResultInfo updateCluResult = client.updateCluResult(createCluResult.getId(), createCluResult, contextInfo);
2862        updateCluResult = client.getCluResult(updateCluResult.getId(), contextInfo);
2863
2864        assertNotNull(updateCluResult);
2865        assertEquals(createCluResult.getId(), updateCluResult.getId());
2866        assertEquals(createCluResult.getDescr().getPlain(), updateCluResult.getDescr().getPlain());
2867        assertEquals(createCluResult.getEffectiveDate(), updateCluResult.getEffectiveDate());
2868        assertEquals(createCluResult.getExpirationDate(), updateCluResult.getExpirationDate());
2869        assertEquals(createCluResult.getStateKey(), updateCluResult.getStateKey());
2870        assertEquals(createCluResult.getTypeKey(), updateCluResult.getTypeKey());
2871        assertEquals(createCluResult.getResultOptions().get(0).getId(), updateCluResult.getResultOptions().get(0).getId());
2872        assertEquals(createCluResult.getResultOptions().get(0).getDescr().getPlain(), updateCluResult.getResultOptions().get(0).getDescr().getPlain());
2873        assertEquals(createCluResult.getResultOptions().get(0).getEffectiveDate(), updateCluResult.getResultOptions().get(0).getEffectiveDate());
2874        assertEquals(createCluResult.getResultOptions().get(0).getExpirationDate(), updateCluResult.getResultOptions().get(0).getExpirationDate());
2875        assertEquals(createCluResult.getResultOptions().get(0).getResultComponentId(), updateCluResult.getResultOptions().get(0).getResultComponentId());
2876        assertEquals(createCluResult.getResultOptions().get(0).getResultUsageTypeKey(), updateCluResult.getResultOptions().get(0).getResultUsageTypeKey());
2877        assertEquals(createCluResult.getResultOptions().get(0).getStateKey(), updateCluResult.getResultOptions().get(0).getStateKey());
2878    }
2879
2880    @Test
2881    public void test63UpdateCluResult_RemoveAllCluResultOptions() throws AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, VersionMismatchException, ReadOnlyException {
2882
2883        CluResultInfo createCluResult = client.createCluResult("CLU-1", "kuali.resultType.gradeCourseResult", dto, contextInfo);
2884        createCluResult = client.getCluResult(createCluResult.getId(), contextInfo);
2885
2886        assertNotNull(createCluResult);
2887
2888        // Clear all cluResultOptions
2889        createCluResult.getResultOptions().clear();
2890
2891        CluResultInfo updateCluResult = client.updateCluResult(createCluResult.getId(), createCluResult, contextInfo);
2892        updateCluResult = client.getCluResult(updateCluResult.getId(), contextInfo);
2893
2894        assertNotNull(updateCluResult);
2895        assertEquals(createCluResult.getId(), updateCluResult.getId());
2896        assertEquals(createCluResult.getResultOptions().isEmpty(), updateCluResult.getResultOptions().isEmpty());
2897    }
2898
2899    @Test
2900    public void test64Versioning() throws ParseException, AlreadyExistsException, DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException, IllegalVersionSequencingException, ReadOnlyException, DependentObjectsExistException {
2901
2902        CluInfo clu = createCluInfo();
2903        clu.setTypeKey("luType.shell.course");
2904        CluInfo cluV1 = client.createClu(clu.getTypeKey(), clu, contextInfo);
2905
2906        try {
2907            //Try to set the start date in the past
2908            client.setCurrentCluVersion(cluV1.getId(),
2909                    DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("19000101"), contextInfo);
2910            fail("InvalidParameterException should have been thrown");
2911        } catch (InvalidParameterException ipe) {
2912            assertNotNull(ipe.getMessage());
2913            assertEquals("currentVersionStart must be in the future.", ipe.getMessage());
2914        }
2915
2916
2917
2918        CluInfo justMadeCurrentClu = client.getClu(cluV1.getId(), contextInfo);
2919        assertTrue(justMadeCurrentClu.getVersion().getCurrentVersionStart().compareTo(new Date()) < 1);
2920        VersionDisplayInfo versionDisplayInfo = client.getCurrentVersion(CluServiceConstants.CLU_NAMESPACE_URI, justMadeCurrentClu.getVersion().getVersionIndId(), contextInfo);
2921        //Try to make a new versions from the current version
2922        CluInfo cluV2 = client.createNewCluVersion(cluV1.getVersion().getVersionIndId(), "CommentA", contextInfo);
2923        CluInfo cluV3 = client.createNewCluVersion(cluV1.getVersion().getVersionIndId(), "CommentB", contextInfo);
2924        versionDisplayInfo = client.getCurrentVersion(CluServiceConstants.CLU_NAMESPACE_URI, cluV1.getVersion().getVersionIndId(), contextInfo);
2925        assertEquals(cluV1.getId(), versionDisplayInfo.getId());
2926        assertEquals(cluV1.getVersion().getVersionIndId(), cluV2.getVersion().getVersionIndId());
2927        assertEquals(cluV1.getVersion().getVersionIndId(), cluV3.getVersion().getVersionIndId());
2928        client.setCurrentCluVersion(cluV3.getId(), null, contextInfo);
2929        versionDisplayInfo = client.getCurrentVersion(CluServiceConstants.CLU_NAMESPACE_URI, cluV1.getVersion().getVersionIndId(), contextInfo);
2930        assertEquals(versionDisplayInfo.getId(), cluV3.getId());
2931
2932
2933        SearchRequestInfo searchRequest = new SearchRequestInfo();
2934        SearchParamInfo param = new SearchParamInfo();
2935        param.setKey("lu.queryParam.cluVersionIndId");
2936        param.getValues().add(versionDisplayInfo.getVersionIndId());
2937        searchRequest.getParams().add(param);
2938        searchRequest.setSearchKey("lu.search.clu.versions");
2939        SearchResultInfo searchResult = client.search(searchRequest, ContextInfoTestUtility.getEnglishContextInfo());
2940        assertEquals(3, searchResult.getRows().size());
2941
2942        StatusInfo status = client.deleteClu(cluV1.getId(), contextInfo);
2943        assertTrue(status.getIsSuccess());
2944        status = client.deleteClu(cluV2.getId(), contextInfo);
2945        assertTrue(status.getIsSuccess());
2946        status = client.deleteClu(cluV3.getId(), contextInfo);
2947        assertTrue(status.getIsSuccess());
2948
2949    }
2950
2951    private CluSetInfo createCluSetInfo() throws ParseException {
2952        CluSetInfo cluSetInfo = new CluSetInfo();
2953
2954        RichTextInfo desc = new RichTextInfo();
2955        desc.setFormatted("<p>Formatted Desc</p>");
2956        desc.setPlain("plain");
2957        cluSetInfo.setDescr(desc);
2958        cluSetInfo.setEffectiveDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20080101"));
2959        cluSetInfo.setExpirationDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20180101"));
2960        cluSetInfo.setName("Clu set name");
2961        cluSetInfo.setStateKey("draft");
2962        cluSetInfo.setTypeKey("kuali.cluset.course");
2963        return cluSetInfo;
2964    }
2965
2966    private CluInfo createCluInfo() throws ParseException {
2967        CluInfo clu = new CluInfo();
2968
2969        CluAccountingInfo accountingInfo = new CluAccountingInfo();
2970
2971        if (accountingInfo.getAttributes() == null) {
2972            accountingInfo.setAttributes(new ArrayList<AttributeInfo>());
2973        }
2974        accountingInfo.getAttributes().add(new AttributeInfo("AccountingAttrKey1", "AccountingAttrValue1"));
2975        accountingInfo.getAttributes().add(new AttributeInfo("AccountingAttrKey2", "AccountingAttrValue2"));
2976        clu.setAccountingInfo(accountingInfo);
2977
2978        CluIdentifierInfo officialIdentifier = new CluIdentifierInfo();
2979        officialIdentifier.setCode("offId-code");
2980        officialIdentifier.setDivision("offId-division");
2981        officialIdentifier.setLevel("offId-level");
2982        officialIdentifier.setLongName("offId-longName");
2983        officialIdentifier.setShortName("offId-shortName");
2984        officialIdentifier.setStateKey("offId-state");
2985        officialIdentifier.setTypeKey("offId-type");
2986        officialIdentifier.setVariation("offId-variation");
2987        officialIdentifier.setSuffixCode("offId-suffixcode");
2988        officialIdentifier.setOrgId("offId-orgid");
2989        clu.setOfficialIdentifier(officialIdentifier);
2990
2991        CluIdentifierInfo cluId1 = new CluIdentifierInfo();
2992        cluId1.setCode("cluId1-code");
2993        cluId1.setDivision("cluId1-division");
2994        cluId1.setLevel("cluId1-level");
2995        cluId1.setLongName("cluId1-longName");
2996        cluId1.setShortName("cluId1-shortName");
2997        cluId1.setStateKey("cluId1-state");
2998        cluId1.setTypeKey("cluId1-type");
2999        cluId1.setVariation("cluId1-variation");
3000        cluId1.setSuffixCode("cluId1-suffixcode");
3001        cluId1.setOrgId("cluId1-orgid");
3002        clu.getAlternateIdentifiers().add(cluId1);
3003
3004        CluIdentifierInfo cluId2 = new CluIdentifierInfo();
3005        cluId2.setCode("cluId2-code");
3006        cluId2.setDivision("cluId2-division");
3007        cluId2.setLevel("cluId2-level");
3008        cluId2.setLongName("cluId2-longName");
3009        cluId2.setShortName("cluId2-shortName");
3010        cluId2.setStateKey("cluId2-state");
3011        cluId2.setTypeKey("cluId2-type");
3012        cluId2.setVariation("cluId2-variation");
3013        cluId2.setSuffixCode("cluId2-suffixcode");
3014        cluId2.setOrgId("cluId2-orgid");
3015        clu.getAlternateIdentifiers().add(cluId2);
3016
3017        if (clu.getAttributes() == null) {
3018            clu.setAttributes(new ArrayList<AttributeInfo>());
3019        }
3020        clu.getAttributes().add(new AttributeInfo("cluAttrKey1", "cluAttrValue1"));
3021        clu.getAttributes().add(new AttributeInfo("cluAttrKey2", "cluAttrValue2"));
3022
3023        clu.setCanCreateLui(true);
3024
3025        clu.setDefaultEnrollmentEstimate(545);
3026        clu.setDefaultMaximumEnrollment(999);
3027
3028        RichTextInfo desc = new RichTextInfo();
3029        desc.setFormatted("<p>DESC FORMATTED</p>");
3030        desc.setPlain("DESC PLAIN");
3031        clu.setDescr(desc);
3032
3033        clu.setEffectiveDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20100203"));
3034        clu.setExpirationDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("21001231"));
3035
3036        clu.setIsEnrollable(true);
3037        clu.setIsHazardousForDisabledStudents(true);
3038
3039        AffiliatedOrgInfo aforg = new AffiliatedOrgInfo();
3040        aforg.setOrgId("AFF-ORG1");
3041        aforg.setPercentage(35l);
3042
3043        AffiliatedOrgInfo aforg1 = new AffiliatedOrgInfo();
3044        aforg1.setOrgId("AFF-ORG2");
3045        aforg1.setPercentage(65l);
3046
3047        List<AffiliatedOrgInfo> affiliatedOrgs = new ArrayList<AffiliatedOrgInfo>();
3048        affiliatedOrgs.add(aforg);
3049        affiliatedOrgs.add(aforg1);
3050
3051        CurrencyAmountInfo ca = new CurrencyAmountInfo();
3052        ca.setCurrencyQuantity(100);
3053        ca.setCurrencyTypeKey("DLLR");
3054
3055        CurrencyAmountInfo ca1 = new CurrencyAmountInfo();
3056        ca.setCurrencyQuantity(200);
3057        ca.setCurrencyTypeKey("DLLR");
3058
3059        List<CurrencyAmountInfo> caList = new ArrayList<CurrencyAmountInfo>();
3060        caList.add(ca);
3061
3062        List<CurrencyAmountInfo> caList1 = new ArrayList<CurrencyAmountInfo>();
3063        caList.add(ca);
3064        caList.add(ca1);
3065
3066        RichTextInfo cfRecDesc = new RichTextInfo();
3067        cfRecDesc.setPlain("Clu Fee Record");
3068
3069        CluFeeRecordInfo feeRec = new CluFeeRecordInfo();
3070        feeRec.setAffiliatedOrgs(affiliatedOrgs);
3071        feeRec.setFeeAmounts(caList);
3072        feeRec.setFeeType("FEE-TYPE-X");
3073        feeRec.setRateType("RATE-TYPE-X");
3074        feeRec.setDescr(cfRecDesc);
3075
3076        CluFeeRecordInfo feeRec1 = new CluFeeRecordInfo();
3077        feeRec1.setAffiliatedOrgs(affiliatedOrgs);
3078        feeRec1.setFeeAmounts(caList1);
3079        feeRec1.setFeeType("FEE-TYPE-Y");
3080        feeRec1.setRateType("RATE-TYPE-Y");
3081
3082        List<CluFeeRecordInfo> feeRecList = new ArrayList<CluFeeRecordInfo>();
3083        feeRecList.add(feeRec);
3084        feeRecList.add(feeRec1);
3085
3086        RichTextInfo cfDesc = new RichTextInfo();
3087        cfDesc.setPlain("Clu Fee");
3088
3089        CluFeeInfo feeInfo = new CluFeeInfo();
3090        feeInfo.getAttributes().add(new AttributeInfo("FeeAttrKey1", "FeeAttrValue1"));
3091        feeInfo.getAttributes().add(new AttributeInfo("FeeAttrKey2", "FeeAttrValue2"));
3092        feeInfo.setCluFeeRecords(feeRecList);
3093        feeInfo.setDescr(cfDesc);
3094        clu.setFeeInfo(feeInfo);
3095
3096        clu.setIsHasEarlyDropDeadline(true);
3097
3098        clu.setIsHazardousForDisabledStudents(true);
3099
3100        CluInstructorInfo primaryInstructor = new CluInstructorInfo();
3101        primaryInstructor.setOrgId("EXT-orgId-1");
3102        primaryInstructor.setPersonId("EXT-personId-1");
3103        primaryInstructor.getAttributes().add(new AttributeInfo("PrimaryInstAttrKey1", "PrimaryInstAttrValue1"));
3104        primaryInstructor.getAttributes().add(new AttributeInfo("PrimaryInstAttrKey2", "PrimaryInstAttrValue2"));
3105        clu.setPrimaryInstructor(primaryInstructor);
3106
3107        CluInstructorInfo instructor1 = new CluInstructorInfo();
3108        instructor1.setOrgId("EXT-orgId-2");
3109        instructor1.setPersonId("EXT-personId-2");
3110        instructor1.getAttributes().add(new AttributeInfo("Inst1AttrKey1", "Inst1AttrValue1"));
3111        instructor1.getAttributes().add(new AttributeInfo("Inst1AttrKey2", "Inst1AttrValue2"));
3112        clu.getInstructors().add(instructor1);
3113
3114        CluInstructorInfo instructor2 = new CluInstructorInfo();
3115        instructor2.setOrgId("EXT-orgId-3");
3116        instructor2.setPersonId("EXT-personId-3");
3117        instructor2.getAttributes().add(new AttributeInfo("Inst2AttrKey1", "Inst2AttrValue1"));
3118        instructor2.getAttributes().add(new AttributeInfo("Inst2AttrKey2", "Inst2AttrValue2"));
3119        clu.getInstructors().add(instructor2);
3120
3121        LuCodeInfo luCode1 = new LuCodeInfo();
3122        luCode1.setId("luCode1.key");
3123        RichTextInfo loCode1desc = new RichTextInfo();
3124        loCode1desc.setPlain("luCode1-desc");
3125        luCode1.setDescr(loCode1desc);
3126        luCode1.setValue("luCode1-value");
3127        luCode1.getAttributes().add(new AttributeInfo("luCode1AttrKey1", "luCode1AttrValue1"));
3128        luCode1.getAttributes().add(new AttributeInfo("luCode1AttrKey2", "luCode1AttrValue2"));
3129        luCode1.setType("kuali.someKindOfLuCode");
3130        clu.getLuCodes().add(luCode1);
3131
3132        LuCodeInfo luCode2 = new LuCodeInfo();
3133        luCode2.setId("luCode2.key");
3134        RichTextInfo loCode2desc = new RichTextInfo();
3135        loCode2desc.setPlain("luCode2-desc");
3136        luCode2.setDescr(loCode2desc);
3137        luCode2.setValue("luCode2-value");
3138        luCode2.getAttributes().add(new AttributeInfo("luCode2AttrKey1", "luCode2AttrValue1"));
3139        luCode2.getAttributes().add(new AttributeInfo("luCode2AttrKey2", "luCode2AttrValue2"));
3140        luCode2.setType("kuali.someKindOfLuCode");
3141        clu.getLuCodes().add(luCode2);
3142
3143        RichTextInfo marketingDesc = new RichTextInfo();
3144        marketingDesc.setFormatted("<p>marketingDesc FORMATTED</p>");
3145        marketingDesc.setPlain("marketingDesc PLAIN");
3146
3147        clu.setNextReviewPeriod("nextReviewPeriod");
3148
3149        clu.getOfferedAtpTypes().add("offeredAtpType1");
3150        clu.getOfferedAtpTypes().add("offeredAtpType2");
3151
3152
3153        CluInstructorInfo pubPrimaryInstructor = new CluInstructorInfo();
3154        pubPrimaryInstructor.setOrgId("EXT-orgId-234");
3155        pubPrimaryInstructor.setPersonId("EXT-personId-2451");
3156        pubPrimaryInstructor.getAttributes().add(new AttributeInfo("PubPrimaryInstAttrKey1", "PubPrimaryInstAttrValue1"));
3157        pubPrimaryInstructor.getAttributes().add(new AttributeInfo("PubPrimaryInstAttrKey2", "PubPrimaryInstAttrValue2"));
3158
3159        CluInstructorInfo pubInstructor1 = new CluInstructorInfo();
3160        pubInstructor1.setOrgId("EXT-orgId-2");
3161        pubInstructor1.setPersonId("EXT-personId-2");
3162        pubInstructor1.getAttributes().add(new AttributeInfo("PubInst1AttrKey1", "PubInst1AttrValue1"));
3163        pubInstructor1.getAttributes().add(new AttributeInfo("PubInst1AttrKey2", "PubInst1AttrValue2"));
3164
3165        CluInstructorInfo pubInstructor2 = new CluInstructorInfo();
3166        pubInstructor2.setOrgId("EXT-orgId-3");
3167        pubInstructor2.setPersonId("EXT-personId-3");
3168        pubInstructor2.getAttributes().add(new AttributeInfo("PubInst2AttrKey1", "PubInst2AttrValue1"));
3169        pubInstructor2.getAttributes().add(new AttributeInfo("PubInst2AttrKey2", "PubInst2AttrValue2"));
3170
3171        clu.setReferenceURL("http://student.kuali.org/clus");
3172
3173        clu.setStateKey("Clu-state");
3174
3175        TimeAmountInfo stdDuration = new TimeAmountInfo();
3176        stdDuration.setAtpDurationTypeKey("EXT-stdDuration-Id1");
3177        stdDuration.setTimeQuantity(7867);
3178        clu.setStdDuration(stdDuration);
3179
3180        clu.setTypeKey("kuali.SomeKindOfClu");
3181
3182        createCampusLocationList(clu);
3183
3184        createIntensity(clu);
3185
3186        createAccreditationList(clu);
3187
3188        createAdminOrgs(clu);
3189
3190        return clu;
3191    }
3192
3193    private void createAdminOrgs(CluInfo clu) {
3194        AdminOrgInfo adminOrg = new AdminOrgInfo();
3195        adminOrg.setOrgId("PRIMARY-ADMIN-ORG-ID");
3196        adminOrg.getAttributes().add(new AttributeInfo("PrimaryAdminOrgAttrKey1", "PrimaryAdminOrgAttrValue1"));
3197        adminOrg.getAttributes().add(new AttributeInfo("PrimaryAdminOrgAttrKey2", "PrimaryAdminOrgAttrValue2"));
3198        adminOrg.setTypeKey("kuali.altadminType1");
3199        adminOrg.setStateKey("kuali.altAdminState1");
3200
3201        clu.getAdminOrgs().add(adminOrg);
3202        AdminOrgInfo altAdminOrg1 = new AdminOrgInfo();
3203        altAdminOrg1.setOrgId("ALT-ADMIN-ORG-ID1");
3204        altAdminOrg1.getAttributes().add(new AttributeInfo("AltAdminOrg1AttrKey1", "AltAdminOrg1AttrValue1"));
3205        altAdminOrg1.getAttributes().add(new AttributeInfo("AltAdminOrg1AttrKey2", "AltAdminOrg1AttrValue2"));
3206        altAdminOrg1.getAttributes().add(new AttributeInfo("AltAdminOrg1AttrKey3", "AltAdminOrg1AttrValue3"));
3207        altAdminOrg1.setTypeKey("kuali.altadminType1");
3208        altAdminOrg1.setStateKey("kuali.altadminState1");
3209
3210        AdminOrgInfo altAdminOrg2 = new AdminOrgInfo();
3211        altAdminOrg2.setOrgId("ALT-ADMIN-ORG-ID2");
3212        altAdminOrg2.getAttributes().add(new AttributeInfo("AltAdminOrg2AttrKey1", "AltAdminOrg2AttrValue1"));
3213        altAdminOrg2.getAttributes().add(new AttributeInfo("AltAdminOrg2AttrKey2", "AltAdminOrg2AttrValue2"));
3214        altAdminOrg2.setTypeKey("kuali.altadminType1");
3215        altAdminOrg2.setStateKey("kuali.altadminState1");
3216
3217        clu.getAdminOrgs().add(altAdminOrg1);
3218        clu.getAdminOrgs().add(altAdminOrg2);
3219
3220    }
3221
3222    private void checkAdminOrgsCreate(CluInfo clu) {
3223
3224        assertEquals("PRIMARY-ADMIN-ORG-ID", clu.getAdminOrgs().get(0)
3225                .getOrgId());
3226        assertEquals(2, clu.getAdminOrgs().get(0).getAttributes().size());
3227        assertEquals("PrimaryAdminOrgAttrValue1", clu.getAdminOrgs().get(0).getAttributeValue("PrimaryAdminOrgAttrKey1"));
3228        assertEquals("PrimaryAdminOrgAttrValue2", clu.getAdminOrgs().get(0).getAttributeValue("PrimaryAdminOrgAttrKey2"));
3229
3230        assertEquals("ALT-ADMIN-ORG-ID1", clu.getAdminOrgs().get(1).getOrgId());
3231        assertEquals(3, clu.getAdminOrgs().get(1).getAttributes().size());
3232        assertEquals("AltAdminOrg1AttrValue1", clu.getAdminOrgs().get(1).getAttributeValue("AltAdminOrg1AttrKey1"));
3233        assertEquals("AltAdminOrg1AttrValue2", clu.getAdminOrgs().get(1).getAttributeValue("AltAdminOrg1AttrKey2"));
3234        assertEquals("AltAdminOrg1AttrValue3", clu.getAdminOrgs().get(1).getAttributeValue("AltAdminOrg1AttrKey3"));
3235
3236        assertEquals("ALT-ADMIN-ORG-ID2", clu.getAdminOrgs().get(2).getOrgId());
3237        assertEquals(2, clu.getAdminOrgs().get(2).getAttributes().size());
3238        assertEquals("AltAdminOrg2AttrValue1", clu.getAdminOrgs().get(2).getAttributeValue("AltAdminOrg2AttrKey1"));
3239        assertEquals("AltAdminOrg2AttrValue2", clu.getAdminOrgs().get(2).getAttributeValue("AltAdminOrg2AttrKey2"));
3240    }
3241
3242    private void updateAdminOrgs(CluInfo clu) {
3243        clu.getAdminOrgs().get(0).setId("adminOrg121");
3244        clu.getAdminOrgs().get(0).setOrgId("UPD-PRIMARY-ADMIN-ORG-ID");
3245        clu.getAdminOrgs().get(0).getAttributes().add(new AttributeInfo("PrimaryAdminOrgAttrKey3", "PrimaryAdminOrgAttrValue3"));
3246        clu.getAdminOrgs().get(0).getAttributes().remove(1);
3247        clu.getAdminOrgs().get(0).getAttributes().add(new AttributeInfo("PrimaryAdminOrgAttrKey4", "PrimaryAdminOrgAttrValue4"));
3248
3249        AdminOrgInfo altAdminOrg3 = new AdminOrgInfo();
3250        altAdminOrg3.setOrgId("UPD-ADMIN-ORG-ID3");
3251        altAdminOrg3.getAttributes().add(new AttributeInfo("UPDAdminOrg3AttrKey1", "UPDAdminOrg3AttrKey1"));
3252        altAdminOrg3.getAttributes().add(new AttributeInfo("UPDAdminOrg3AttrKey2", "UPDAdminOrg3AttrKey1"));
3253        altAdminOrg3.setTypeKey("kuali.testType");
3254
3255        clu.getAdminOrgs().remove(1);
3256        clu.getAdminOrgs().add(altAdminOrg3);
3257    }
3258
3259    private void checkAdminOrgUpdate(CluInfo clu) {
3260
3261        assertEquals("UPD-PRIMARY-ADMIN-ORG-ID", clu.getAdminOrgs().get(0)
3262                .getOrgId());
3263        assertEquals(3, clu.getAdminOrgs().get(0).getAttributes().size());
3264        assertEquals("PrimaryAdminOrgAttrValue4", clu.getAdminOrgs().get(0).getAttributeValue("PrimaryAdminOrgAttrKey4"));
3265        assertNull(clu.getAdminOrgs().get(0).getAttributeValue("PrimaryAdminOrgAttrKey2"));
3266        assertEquals(3, clu.getAdminOrgs().size());
3267        assertEquals("UPD-PRIMARY-ADMIN-ORG-ID", clu.getAdminOrgs().get(0)
3268                .getOrgId());
3269        assertEquals(3, clu.getAdminOrgs().get(0).getAttributes()
3270                .size());
3271        assertEquals("PrimaryAdminOrgAttrValue1", clu.getAdminOrgs().get(0).getAttributeValue("PrimaryAdminOrgAttrKey1"));
3272        assertEquals("PrimaryAdminOrgAttrValue4", clu.getAdminOrgs().get(0).getAttributeValue("PrimaryAdminOrgAttrKey4"));
3273        assertEquals("PrimaryAdminOrgAttrValue3", clu.getAdminOrgs().get(0).getAttributeValue("PrimaryAdminOrgAttrKey3"));
3274        assertEquals("ALT-ADMIN-ORG-ID2", clu.getAdminOrgs().get(1)
3275                .getOrgId());
3276        assertEquals(2, clu.getAdminOrgs().get(1).getAttributes()
3277                .size());
3278        assertEquals("AltAdminOrg2AttrValue2", clu.getAdminOrgs().get(1).getAttributeValue("AltAdminOrg2AttrKey2"));
3279        assertEquals("AltAdminOrg2AttrValue1", clu.getAdminOrgs().get(1).getAttributeValue("AltAdminOrg2AttrKey1"));
3280    }
3281
3282    private void createAccreditationList(CluInfo clu) throws ParseException {
3283        AccreditationInfo accreditationOrg1 = new AccreditationInfo();
3284        accreditationOrg1.setOrgId("EXT-orgId-1");
3285        accreditationOrg1.setEffectiveDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20100203"));
3286        accreditationOrg1.setExpirationDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("21001231"));
3287        accreditationOrg1.getAttributes().add(new AttributeInfo("Accred1AttrKey1", "Accred1AttrValue1"));
3288        accreditationOrg1.getAttributes().add(new AttributeInfo("Accred1AttrKey2", "Accred1AttrValue2"));
3289
3290        AccreditationInfo accreditationOrg2 = new AccreditationInfo();
3291        accreditationOrg2.setOrgId("EXT-orgId-2");
3292        accreditationOrg2.setEffectiveDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20110203"));
3293        accreditationOrg2.setExpirationDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("21011231"));
3294        accreditationOrg2.getAttributes().add(new AttributeInfo("Accred2AttrKey1", "Accred2AttrValue1"));
3295        accreditationOrg2.getAttributes().add(new AttributeInfo("Accred2AttrKey2", "Accred2AttrValue2"));
3296
3297        clu.getAccreditations().add(accreditationOrg1);
3298        clu.getAccreditations().add(accreditationOrg2);
3299    }
3300
3301    private void checkAccreditationListCreate(CluInfo clu)
3302            throws ParseException {
3303
3304        assertEquals(2, clu.getAccreditations().size());
3305
3306        assertEquals("EXT-orgId-1", clu.getAccreditations().get(0)
3307                .getOrgId());
3308        assertEquals(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20100203"), clu.getAccreditations().get(0)
3309                .getEffectiveDate());
3310        assertEquals(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("21001231"), clu.getAccreditations().get(0)
3311                .getExpirationDate());
3312        assertEquals(2, clu.getAccreditations().get(0).getAttributes()
3313                .size());
3314        assertEquals("Accred1AttrValue1", clu.getAccreditations().get(0).getAttributeValue("Accred1AttrKey1"));
3315        assertEquals("Accred1AttrValue2", clu.getAccreditations().get(0).getAttributeValue("Accred1AttrKey2"));
3316
3317        assertEquals("EXT-orgId-2", clu.getAccreditations().get(1)
3318                .getOrgId());
3319        assertEquals(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20110203"), clu.getAccreditations().get(1)
3320                .getEffectiveDate());
3321        assertEquals(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("21011231"), clu.getAccreditations().get(1)
3322                .getExpirationDate());
3323        assertEquals(2, clu.getAccreditations().get(1).getAttributes()
3324                .size());
3325        assertEquals("Accred2AttrValue1", clu.getAccreditations().get(1).getAttributeValue("Accred2AttrKey1"));
3326        assertEquals("Accred2AttrValue2", clu.getAccreditations().get(1).getAttributeValue("Accred2AttrKey2"));
3327    }
3328
3329    private void updateAccreditationList(CluInfo clu) throws ParseException {
3330
3331        AccreditationInfo accreditationOrg3 = new AccreditationInfo();
3332        accreditationOrg3.setOrgId("EXT-orgId-3");
3333        accreditationOrg3.setEffectiveDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20120203"));
3334        accreditationOrg3.setExpirationDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("21021231"));
3335
3336        AccreditationInfo accreditationOrg4 = new AccreditationInfo();
3337        accreditationOrg4.setOrgId("EXT-orgId-4");
3338        accreditationOrg4.setEffectiveDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20130203"));
3339        accreditationOrg4.setExpirationDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("21031231"));
3340        accreditationOrg4.getAttributes().add(new AttributeInfo("Accred4AttrKey1", "Accred4AttrValue1"));
3341
3342        clu.getAccreditations().add(accreditationOrg3);
3343        clu.getAccreditations().add(accreditationOrg4);
3344
3345        for (int i = 0; i < clu.getAccreditations().get(0).getAttributes().size(); i++) {
3346            String attributeKey = clu.getAccreditations().get(0).getAttributes().get(i).getKey();
3347            if (attributeKey.equals("Accred1AttrKey1")) {
3348                clu.getAccreditations().get(0).getAttributes().set(i, new AttributeInfo("Accred1AttrKey1", "Accred1AttrValue1-UPD"));
3349            } else if (attributeKey.equals("Accred1AttrKey2")) {
3350                clu.getAccreditations().get(0).getAttributes().remove(i);
3351            }
3352        }
3353
3354        clu.getAccreditations().remove(1);
3355    }
3356
3357    private void checkAccreditationListUpdate(CluInfo clu)
3358            throws ParseException {
3359
3360        assertEquals(3, clu.getAccreditations().size());
3361
3362        assertEquals("EXT-orgId-1", clu.getAccreditations().get(0)
3363                .getOrgId());
3364        assertEquals(1, clu.getAccreditations().get(0).getAttributes()
3365                .size());
3366        assertEquals("Accred1AttrValue1-UPD", clu.getAccreditations().get(0).getAttributeValue("Accred1AttrKey1"));
3367
3368        assertEquals("EXT-orgId-3", clu.getAccreditations().get(1)
3369                .getOrgId());
3370        assertEquals(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20120203"), clu.getAccreditations().get(1)
3371                .getEffectiveDate());
3372        assertEquals(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("21021231"), clu.getAccreditations().get(1)
3373                .getExpirationDate());
3374        assertEquals(0, clu.getAccreditations().get(1).getAttributes()
3375                .size());
3376
3377        assertEquals("EXT-orgId-4", clu.getAccreditations().get(2)
3378                .getOrgId());
3379        assertEquals(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20130203"), clu.getAccreditations().get(2)
3380                .getEffectiveDate());
3381        assertEquals(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("21031231"), clu.getAccreditations().get(2)
3382                .getExpirationDate());
3383        assertEquals(1, clu.getAccreditations().get(2).getAttributes()
3384                .size());
3385        assertEquals("Accred4AttrValue1", clu.getAccreditations().get(2).getAttributeValue("Accred4AttrKey1"));
3386
3387    }
3388
3389    private void createIntensity(CluInfo clu) {
3390        AmountInfo intensity = new AmountInfo();
3391        intensity.setUnitTypeKey("EXT-intensity-Id1");
3392        intensity.setUnitQuantity("123");
3393        clu.setIntensity(intensity);
3394    }
3395
3396    private void checkIntensityCreate(CluInfo clu) {
3397        assertEquals("EXT-intensity-Id1", clu.getIntensity()
3398                .getUnitTypeKey());
3399        assertEquals("123", clu.getIntensity().getUnitQuantity());
3400    }
3401
3402    private void updateIntensity(CluInfo clu) {
3403        clu.getIntensity().setUnitTypeKey("UPD-intensity-Id1");
3404        clu.getIntensity().setUnitQuantity("456");
3405    }
3406
3407    private void checkIntensityUpdate(CluInfo clu) {
3408        assertEquals("UPD-intensity-Id1", clu.getIntensity()
3409                .getUnitTypeKey());
3410        assertEquals("456", clu.getIntensity().getUnitQuantity());
3411
3412    }
3413
3414    private void createCampusLocationList(CluInfo clu) {
3415        clu.getCampusLocations().add("EXT-Campus-Location-1");
3416        clu.getCampusLocations().add("EXT-Campus-Location-2");
3417    }
3418
3419    private void checkCampusLocationCreate(CluInfo clu) {
3420        assertEquals(2, clu.getCampusLocations().size());
3421        assertEquals("EXT-Campus-Location-1", clu.getCampusLocations()
3422                .get(0));
3423        assertEquals("EXT-Campus-Location-2", clu.getCampusLocations()
3424                .get(1));
3425    }
3426
3427    private void updateCampusLocationList(CluInfo clu) {
3428        clu.getCampusLocations().add("EXT-Campus-Location-3");
3429        clu.getCampusLocations().add("EXT-Campus-Location-4");
3430        clu.getCampusLocations().remove(0);
3431    }
3432
3433    private void checkCampusLocationUpdate(CluInfo clu) {
3434        assertEquals(3, clu.getCampusLocations().size());
3435        assertEquals("EXT-Campus-Location-2", clu.getCampusLocations()
3436                .get(0));
3437        assertEquals("EXT-Campus-Location-3", clu.getCampusLocations()
3438                .get(1));
3439        assertEquals("EXT-Campus-Location-4", clu.getCampusLocations()
3440                .get(2));
3441    }
3442
3443    @Test
3444    public void test65SearchForCluInCluSets() throws Exception {
3445        SearchRequestInfo searchRequest = new SearchRequestInfo();
3446        searchRequest.setSearchKey("cluset.search.generic");
3447
3448        List<SearchParamInfo> queryParamValueList = new ArrayList<SearchParamInfo>();
3449        SearchParamInfo searchParam = new SearchParamInfo();
3450        searchParam.setKey("cluset.queryParam.luOptionalId");
3451        searchParam.getValues().add("CLU-5");
3452        queryParamValueList.add(searchParam);
3453
3454        searchRequest.setParams(queryParamValueList);
3455        SearchResultInfo cluSets = client.search(searchRequest, ContextInfoTestUtility.getEnglishContextInfo());
3456
3457        Assert.assertEquals(2, cluSets.getRows().size());
3458    }
3459
3460    @Test
3461    public void test66SearchForCluInCluSets_EmptyResult() throws Exception {
3462        SearchRequestInfo searchRequest = new SearchRequestInfo();
3463        searchRequest.setSearchKey("cluset.search.generic");
3464
3465        List<SearchParamInfo> queryParamValueList = new ArrayList<SearchParamInfo>();
3466        SearchParamInfo searchParam = new SearchParamInfo();
3467        searchParam.setKey("lu.queryParam.luOptionalId");
3468        searchParam.getValues().add("XXX");
3469        queryParamValueList.add(searchParam);
3470
3471        searchRequest.setParams(queryParamValueList);
3472        SearchResultInfo cluSets = client.search(searchRequest, ContextInfoTestUtility.getEnglishContextInfo());
3473
3474        assertTrue(cluSets.getRows().isEmpty());
3475    }
3476
3477    @Test
3478    public void test67SearchForCluInCluRelations() throws Exception {
3479        SearchRequestInfo searchRequest = new SearchRequestInfo();
3480        searchRequest.setSearchKey("lu.search.cluCluRelation");
3481
3482        List<SearchParamInfo> queryParamValueList = new ArrayList<SearchParamInfo>();
3483        SearchParamInfo searchParam = new SearchParamInfo();
3484        searchParam.setKey("lu.queryParam.luOptionalId");
3485        searchParam.getValues().add("CLU-1");
3486        queryParamValueList.add(searchParam);
3487
3488        searchRequest.setParams(queryParamValueList);
3489        SearchResultInfo clus = client.search(searchRequest, ContextInfoTestUtility.getEnglishContextInfo());
3490
3491        assertEquals(2, clus.getRows().size());
3492    }
3493
3494    @Test
3495    public void test68SearchForCluInCluRelations_EmptyResult() throws Exception {
3496        SearchRequestInfo searchRequest = new SearchRequestInfo();
3497        searchRequest.setSearchKey("lu.search.cluCluRelation");
3498
3499        List<SearchParamInfo> queryParamValueList = new ArrayList<SearchParamInfo>();
3500        SearchParamInfo searchParam = new SearchParamInfo();
3501        searchParam.setKey("lu.queryParam.luOptionalId");
3502        searchParam.getValues().add("XXX");
3503        queryParamValueList.add(searchParam);
3504
3505        searchRequest.setParams(queryParamValueList);
3506        SearchResultInfo clus = client.search(searchRequest, ContextInfoTestUtility.getEnglishContextInfo());
3507
3508        assertTrue(clus.getRows().isEmpty());
3509    }
3510
3511    @Test
3512    public void test69CluPublicationCrud() throws ParseException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, VersionMismatchException, ReadOnlyException {
3513        //Setup
3514
3515        FieldInfo variant;
3516
3517        CluPublicationInfo cluPublication1 = new CluPublicationInfo();
3518        cluPublication1.setEffectiveDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20120203"));
3519        cluPublication1.setExpirationDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20130203"));
3520        cluPublication1.setStartCycle("StartCycle1");
3521        cluPublication1.setEndCycle("EndCycle1");
3522        cluPublication1.setStateKey("clupubState1");
3523        cluPublication1.setTypeKey("cluPublication.Test.Type.1");
3524        cluPublication1.setCluId("CLU-1");
3525        variant = new FieldInfo();
3526        variant.setId("field1.one");
3527        variant.setValue("value1.one");
3528        cluPublication1.getVariants().add(variant);
3529        variant = new FieldInfo();
3530        variant.setId("field1.two");
3531        variant.setValue("value1.two");
3532        cluPublication1.getVariants().add(variant);
3533
3534        CluPublicationInfo cluPublication2 = new CluPublicationInfo();
3535        cluPublication2.setEffectiveDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20120203"));
3536        cluPublication2.setExpirationDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20130203"));
3537        cluPublication2.setStartCycle("StartCycle2");
3538        cluPublication2.setEndCycle("EndCycle2");
3539        cluPublication2.setStateKey("clupubState2");
3540        cluPublication2.setTypeKey("cluPublication.Test.Type.1");
3541        cluPublication2.setCluId("CLU-2");
3542        variant = new FieldInfo();
3543        variant.setId("field2.one");
3544        variant.setValue("value2.one");
3545        cluPublication2.getVariants().add(variant);
3546        variant = new FieldInfo();
3547        variant.setId("field2.two");
3548        variant.setValue("value2.two");
3549        cluPublication2.getVariants().add(variant);
3550
3551        CluPublicationInfo cluPublication3 = new CluPublicationInfo();
3552        cluPublication3.setEffectiveDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20120203"));
3553        cluPublication3.setExpirationDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20130203"));
3554        cluPublication3.setStartCycle("StartCycle3");
3555        cluPublication3.setEndCycle("EndCycle3");
3556        cluPublication3.setStateKey("clupubState3");
3557        cluPublication3.setTypeKey("cluPublication.Test.Type.2");
3558        cluPublication3.setCluId("CLU-2");
3559        variant = new FieldInfo();
3560        variant.setId("field3.one");
3561        variant.setValue("value3.one");
3562        cluPublication3.getVariants().add(variant);
3563        variant = new FieldInfo();
3564        variant.setId("field3.two");
3565        variant.setValue("value3.two");
3566        cluPublication3.getVariants().add(variant);
3567
3568
3569        CluPublicationInfo createdCluPub1 = client.createCluPublication(cluPublication1.getCluId(), cluPublication1.getTypeKey(), cluPublication1, contextInfo);
3570        CluPublicationInfo createdCluPub2 = client.createCluPublication(cluPublication2.getCluId(), cluPublication2.getTypeKey(), cluPublication2, contextInfo);
3571        CluPublicationInfo createdCluPub3 = client.createCluPublication(cluPublication3.getCluId(), cluPublication3.getTypeKey(), cluPublication3, contextInfo);
3572
3573
3574        assertNotNull(createdCluPub1.getId());
3575        assertEquals(cluPublication1.getEffectiveDate(), createdCluPub1.getEffectiveDate());
3576        assertEquals(cluPublication1.getExpirationDate(), createdCluPub1.getExpirationDate());
3577        assertEquals(cluPublication1.getStartCycle(), createdCluPub1.getStartCycle());
3578        assertEquals(cluPublication1.getEndCycle(), createdCluPub1.getEndCycle());
3579        assertEquals(cluPublication1.getStateKey(), createdCluPub1.getStateKey());
3580        assertEquals(cluPublication1.getTypeKey(), createdCluPub1.getTypeKey());
3581        assertEquals(cluPublication1.getCluId(), createdCluPub1.getCluId());
3582        assertNotNull(createdCluPub3);
3583
3584        //Test gets
3585        CluPublicationInfo gotCluPub1 = client.getCluPublication(createdCluPub1.getId(), contextInfo);
3586        assertEquals(createdCluPub1.getId(), gotCluPub1.getId());
3587
3588        List<CluPublicationInfo> gotCluPubsByType = client.getCluPublicationsByType("cluPublication.Test.Type.1", contextInfo);
3589        assertEquals(2, gotCluPubsByType.size());
3590
3591        List<CluPublicationInfo> gotCluPubsByClu = client.getCluPublicationsByClu("CLU-2", contextInfo);
3592        assertEquals(2, gotCluPubsByClu.size());
3593
3594        //Change some values
3595        createdCluPub2.setEffectiveDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20020203"));
3596        createdCluPub2.setExpirationDate(DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20030203"));
3597        createdCluPub2.setStartCycle("StartCycle2U");
3598        createdCluPub2.setEndCycle("EndCycle2U");
3599        createdCluPub2.setStateKey("clupubState2U");
3600        createdCluPub2.setTypeKey("cluPublication.Test.Type.2");
3601        createdCluPub2.setCluId("CLU-1");
3602        createdCluPub2.getVariants().clear();
3603        variant = new FieldInfo();
3604        variant.setId("field2.oneU");
3605        variant.setValue("value2.oneU");
3606        createdCluPub2.getVariants().add(variant);
3607        variant = new FieldInfo();
3608        variant.setId("field2.twoU");
3609        variant.setValue("value2.twoU");
3610        createdCluPub2.getVariants().add(variant);
3611
3612        CluPublicationInfo updated = client.updateCluPublication(createdCluPub2.getId(), createdCluPub2, contextInfo);
3613        //Test version mismatch
3614        try {
3615            client.updateCluPublication(createdCluPub2.getId(), createdCluPub2, contextInfo);
3616            fail("VersionMismatchException should have been thrown");
3617        } catch (VersionMismatchException e) {
3618            assertNotNull(e.getMessage());
3619            assertEquals("CluPublication to be updated is not the current version", e.getMessage());
3620        }
3621
3622
3623        //check that updated has correct values
3624        assertEquals(createdCluPub2.getId(), updated.getId());
3625        assertEquals(createdCluPub2.getEffectiveDate(), updated.getEffectiveDate());
3626        assertEquals(createdCluPub2.getExpirationDate(), updated.getExpirationDate());
3627        assertEquals(createdCluPub2.getStartCycle(), updated.getStartCycle());
3628        assertEquals(createdCluPub2.getEndCycle(), updated.getEndCycle());
3629        assertEquals(createdCluPub2.getStateKey(), updated.getStateKey());
3630        assertEquals(createdCluPub2.getTypeKey(), updated.getTypeKey());
3631        assertEquals(createdCluPub2.getCluId(), updated.getCluId());
3632
3633        assertEquals(2, updated.getVariants().size());
3634        assertTrue(("field2.oneU".equals(updated.getVariants().get(0).getId())
3635                && "value2.oneU".equals(updated.getVariants().get(0).getValue()))
3636                ||
3637                ("field2.twoU".equals(updated.getVariants().get(0).getId())
3638                        && "value2.twoU".equals(updated.getVariants().get(0).getValue())));
3639    }
3640
3641    @Test
3642    public void SearchForClus() throws Exception {
3643
3644        String id ="83e46ae9-875e-4970-811f-0719a6b260a2";
3645
3646        QueryByCriteria.Builder qbcBuilder = QueryByCriteria.Builder.create();
3647        qbcBuilder.setPredicates(PredicateFactory.equal("id", id));
3648
3649        List<CluInfo> cluInfos = this.searchForClus(qbcBuilder.build());
3650        assertEquals(1, cluInfos.size());
3651
3652        Date firstDate = DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20010101");
3653        Date secondDate = DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20020201");
3654
3655        qbcBuilder = QueryByCriteria.Builder.create();
3656        qbcBuilder.setPredicates(PredicateFactory.greaterThanOrEqual("effectiveDate", firstDate),
3657                PredicateFactory.lessThanOrEqual("effectiveDate", secondDate));
3658
3659        cluInfos = this.searchForClus(qbcBuilder.build());
3660        assertEquals(37, cluInfos.size());
3661    }
3662
3663    private List<CluInfo> searchForClus(QueryByCriteria qbc) throws Exception {
3664        return client.searchForClus(qbc, ContextUtils.getContextInfo());
3665    }
3666
3667
3668    @Test
3669    public void test70GetCluResultsByClus() throws VersionMismatchException,DataValidationErrorException,ReadOnlyException,MissingParameterException, InvalidParameterException, OperationFailedException, DoesNotExistException, PermissionDeniedException {
3670        List<String> cluIds = new ArrayList<String>();
3671        cluIds.add("CLU-1");
3672        cluIds.add("CLU-2");
3673        cluIds.add("CLU-5");
3674
3675        CluResultInfo createCluResult = client.createCluResult("CLU-1", "kuali.resultType.gradeCourseResult", dto, contextInfo);
3676        createCluResult = client.getCluResult(createCluResult.getId(), contextInfo);
3677
3678        assertNotNull(createCluResult);
3679
3680        List<CluResultInfo> cluResultInfos = client.getCluResultsByClus(cluIds, ContextInfoTestUtility.getEnglishContextInfo());
3681        assertNotNull(cluResultInfos);
3682        boolean bool = false;
3683        for(CluResultInfo cluResultInfo : cluResultInfos) {
3684            if(cluResultInfo.getCluId().equals("CLU-1"))
3685                bool = true;
3686        }
3687        assertTrue(bool);
3688    }
3689
3690}