View Javadoc

1   /**
2    * Copyright 2012 The Kuali Foundation
3    *
4    * Licensed under the the Educational Community License, Version 1.0
5    * (the "License"); you may not use this file except in compliance
6    * with the License.  You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl1.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.kuali.student.enrollment.class1.lui.service.impl;
18  
19  import org.junit.Before;
20  import org.junit.Test;
21  import org.junit.runner.RunWith;
22  import org.kuali.rice.core.api.criteria.GenericQueryResults;
23  import org.kuali.rice.core.api.criteria.PredicateFactory;
24  import org.kuali.rice.core.api.criteria.QueryByCriteria;
25  import org.kuali.student.enrollment.class1.lui.dao.LuiDao;
26  import org.kuali.student.enrollment.class1.lui.dao.LuiLuiRelationDao;
27  import org.kuali.student.enrollment.class1.lui.model.LuiEntity;
28  import org.kuali.student.enrollment.lui.dto.LuiIdentifierInfo;
29  import org.kuali.student.enrollment.lui.dto.LuiInfo;
30  import org.kuali.student.enrollment.lui.dto.LuiLuiRelationInfo;
31  import org.kuali.student.enrollment.lui.service.LuiService;
32  import org.kuali.student.r2.common.criteria.CriteriaLookupService;
33  import org.kuali.student.r2.common.dto.AttributeInfo;
34  import org.kuali.student.r2.common.dto.ContextInfo;
35  import org.kuali.student.r2.common.dto.RichTextInfo;
36  import org.kuali.student.r2.common.dto.StatusInfo;
37  import org.kuali.student.r2.common.exceptions.DoesNotExistException;
38  import org.kuali.student.r2.common.util.constants.LuiServiceConstants;
39  import org.kuali.student.r2.lum.clu.dto.LuCodeInfo;
40  import org.springframework.test.context.ContextConfiguration;
41  import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
42  import org.springframework.test.context.transaction.TransactionConfiguration;
43  import org.springframework.transaction.annotation.Transactional;
44  
45  import javax.annotation.Resource;
46  import java.util.ArrayList;
47  import java.util.Calendar;
48  import java.util.HashMap;
49  import java.util.List;
50  
51  import static org.junit.Assert.assertEquals;
52  import static org.junit.Assert.assertFalse;
53  import static org.junit.Assert.assertNotNull;
54  import static org.junit.Assert.assertTrue;
55  import static org.junit.Assert.fail;
56  
57  @RunWith(SpringJUnit4ClassRunner.class)
58  @ContextConfiguration(locations = {"classpath:lui-test-context.xml"})
59  @TransactionConfiguration(transactionManager = "JtaTxManager", defaultRollback = true)
60  @Transactional
61  public class TestLuiServiceImpl {
62  
63      @Resource(name = "luiService")
64      private LuiService luiService;
65  
66      @Resource(name = "luiDao")
67      private LuiDao luiDao;
68  
69      @Resource(name= "criteriaLookupService")
70      private CriteriaLookupService criteriaLookupService;
71  
72  
73      public LuiLuiRelationDao getLuiLuiRelationDao() {
74          return luiLuiRelationDao;
75      }
76  
77      public void setLuiLuiRelationDao(LuiLuiRelationDao luiLuiRelationDao) {
78          this.luiLuiRelationDao = luiLuiRelationDao;
79      }
80  
81      @Resource(name = "luiLuiRelationDao")
82      private LuiLuiRelationDao luiLuiRelationDao;
83  
84      public LuiService getLuiService() {
85          return  luiService;
86      }
87  
88      public void setLuiService(LuiService luiService) {
89          this.luiService = luiService;
90      }
91  
92      public LuiDao getLuiDao() {
93          return luiDao;
94      }
95  
96      public void setLuiDao(LuiDao luiDao) {
97          this.luiDao = luiDao;
98      }
99  
100     public static String principalId = "123";
101     public ContextInfo callContext = null;
102 
103     @Before
104     public void setUp() {
105         principalId = "123";
106         callContext = new ContextInfo();
107         callContext.setPrincipalId(principalId);
108         try {
109             new LuiTestDataLoader(luiDao, luiLuiRelationDao).loadData();
110         } catch (Exception ex) {
111             throw new RuntimeException (ex);
112         }
113     }
114 
115     @Test
116     public void testLuiServiceSetup() {
117         assertNotNull(luiService);
118     }
119 
120     @Test
121     public void testGetLui() throws Exception {
122 
123         try {
124             luiService.getLui("Lui-blah", callContext);
125             fail("should not exist");
126         } catch (DoesNotExistException ex) {
127             // expected
128         }
129 
130         LuiInfo obj = luiService.getLui("Lui-1", callContext);
131         assertNotNull(obj);
132         assertEquals("Lui one", obj.getName());
133         assertEquals(LuiServiceConstants.LUI_DRAFT_STATE_KEY, obj.getStateKey());
134         assertEquals(LuiServiceConstants.COURSE_OFFERING_TYPE_KEY, obj.getTypeKey());
135 
136         assertEquals("Lui Desc 101", obj.getDescr().getPlain());
137 
138         assertTrue(obj.getResultValuesGroupKeys().contains("Lu-Rvgr-Lui-1"));
139 
140         assertNotNull(obj.getOfficialIdentifier());
141         assertEquals("Chem 123", obj.getOfficialIdentifier().getShortName());
142         assertNotNull(obj.getAlternateIdentifiers());
143         assertEquals("LUI-IDENT-2", obj.getAlternateIdentifiers().get(0).getId());
144 
145         assertNotNull(obj.getEffectiveDate());
146 
147         assertEquals("cluId1", obj.getCluId());
148         assertEquals("atpId1", obj.getAtpId());
149         assertEquals(1, obj.getLuiCodes().size());
150         assertEquals("Lu-Code-Lui-1", obj.getLuiCodes().get(0).getId());
151 
152         assertNotNull(obj.getMaximumEnrollment());
153         assertEquals(200, obj.getMaximumEnrollment().intValue());
154         assertNotNull(obj.getMinimumEnrollment());
155         assertEquals(50, obj.getMinimumEnrollment().intValue());
156         assertEquals("ref.url", obj.getReferenceURL());
157 
158         //Attributes
159         HashMap<String, String> attributes = new HashMap<String, String>();
160         for (AttributeInfo attributeInfo:obj.getAttributes()){
161             attributes.put(attributeInfo.getKey(), attributeInfo.getValue());
162         }
163         assertTrue(attributes.containsKey("attr1"));
164         assertTrue(attributes.containsKey("attr2"));
165 
166 //        assertNotNull(obj.getCluCluRelationIds());
167 //        assertEquals(2, obj.getCluCluRelationIds().size());
168 //        assertTrue(obj.getCluCluRelationIds().contains("CluClu-2"));
169 //        assertNotNull(obj.getUnitsContentOwnerOrgIds());
170 //        assertEquals(1, obj.getUnitsContentOwnerOrgIds().size());
171 //        assertTrue(obj.getUnitsContentOwnerOrgIds().contains("Org-2"));
172 //        assertNotNull(obj.getUnitsDeploymentOrgIds());
173 //        assertEquals(1, obj.getUnitsDeploymentOrgIds().size());
174 //        assertTrue(obj.getUnitsDeploymentOrgIds().contains("Org-1"));
175 //        assertNotNull(obj.getResultValuesGroupKeys());
176 //        assertEquals(3, obj.getResultValuesGroupKeys().size());
177 //        assertTrue(obj.getResultValuesGroupKeys().contains("Val-Group-3"));
178 //
179 //        assertNotNull(obj.getFeeIds());
180 //        assertEquals(3, obj.getFeeIds().size());
181 //        assertNotNull(obj.getRevenues());
182 //        assertEquals(2, obj.getRevenues().size());
183 //        assertNotNull(obj.getExpenditure());
184 //        assertEquals("LUI-Expen-1", obj.getExpenditure().getId());
185     }
186 
187     @Test
188     public void testGetLuiIdsByRelation() throws Exception {
189         try {
190             List<String> luiIds = luiService.getLuiIdsByRelatedLuiAndRelationType("Lui-2", "kuali.lui.lui.relation.associated", callContext);
191             assertNotNull(luiIds);
192             assertEquals(2, luiIds.size());
193             assertEquals("Lui-1", luiIds.get(0));
194             assertEquals("Lui-5", luiIds.get(1));
195         } catch (Exception e) {
196             fail(e.getMessage());
197         }
198     }
199 
200     @Test
201 //    @Ignore
202     public void testGetLuisByRelation() throws Exception {
203         try {
204             List<LuiInfo> luis = luiService.getLuisByRelatedLuiAndRelationType("Lui-2", "kuali.lui.lui.relation.associated", callContext);
205             assertNotNull(luis);
206             assertEquals(2, luis.size());
207             assertEquals("Lui-1", luis.get(0).getId());
208             assertEquals("Lui-5", luis.get(1).getId());
209         } catch (Exception e) {
210             e.printStackTrace();
211             fail(e.getMessage());
212         }
213     }
214 
215     @Test
216     public void testGenericLookup() throws Exception {
217         QueryByCriteria.Builder qbcBuilder = QueryByCriteria.Builder.create();
218         qbcBuilder.setPredicates(PredicateFactory.like("80", "maxSeats"));
219         QueryByCriteria criteria = qbcBuilder.build();
220         try{
221 
222             ArrayList<String> fields = new ArrayList<String>();
223             fields.add("name");
224             GenericQueryResults<List<String>> results = criteriaLookupService.genericLookup(LuiEntity.class, criteria, fields);
225             for(List<String> listString: results.getResults()){
226                 assertTrue(listString.size()==1);
227             }
228             fields.add("luiType");
229             results = criteriaLookupService.genericLookup(LuiEntity.class, criteria, fields);
230             for(List<String> listString: results.getResults()){
231                 assertTrue(listString.size()==2);
232             }
233         }   catch (Exception e){
234             e.printStackTrace();
235             fail(e.getMessage());
236         }
237 
238     }
239 
240     @Test
241     public void testCreateLui() throws Exception {
242         LuiInfo orig = new LuiInfo();
243         orig.setName("Test lui one");
244         orig.setStateKey(LuiServiceConstants.LUI_DRAFT_STATE_KEY);
245         orig.setTypeKey(LuiServiceConstants.COURSE_OFFERING_TYPE_KEY);
246         RichTextInfo rtInfo = new RichTextInfo();
247         rtInfo.setFormatted("<p>Test lui one description</p>");
248         rtInfo.setPlain("Test lui one description");
249         orig.setDescr(rtInfo);
250         orig.setEffectiveDate(Calendar.getInstance().getTime());
251         orig.setMaximumEnrollment(25);
252         orig.setMinimumEnrollment(10);
253         orig.setReferenceURL("ref.create.url");
254 
255         orig.getResultValuesGroupKeys().add("Rvgr-2");
256 
257         LuiIdentifierInfo identifier = new LuiIdentifierInfo();
258         identifier.setShortName("identifier.shortname");
259         identifier.setTypeKey(LuiServiceConstants.LUI_IDENTIFIER_OFFICIAL_TYPE_KEY);
260         identifier.setStateKey(LuiServiceConstants.LUI_IDENTIFIER_ACTIVE_STATE_KEY);
261         orig.setOfficialIdentifier(identifier);
262 
263         LuiIdentifierInfo identifier2 = new LuiIdentifierInfo();
264         identifier2.setShortName("alternate.identifier.shortname");
265         identifier2.setTypeKey(LuiServiceConstants.LUI_IDENTIFIER_CROSSLISTED_TYPE_KEY);
266         identifier2.setStateKey(LuiServiceConstants.LUI_IDENTIFIER_ACTIVE_STATE_KEY);
267         orig.getAlternateIdentifiers().add(identifier2);
268 
269         orig.setCluId("testCluId");
270         orig.setAtpId("testAtpId1");
271 
272         List<String> unitsContentOwner = new ArrayList<String>();
273         unitsContentOwner.add("Org-2");
274         orig.setUnitsContentOwner(unitsContentOwner);
275 
276         List<String> unitsDeployment = new ArrayList<String>();
277         unitsDeployment.add("Org-1");
278         orig.setUnitsDeployment(unitsDeployment);
279 
280         List<String> resultValueGroupKeys = new ArrayList<String>();
281         resultValueGroupKeys.add("Val-Group-3");
282         orig.setResultValuesGroupKeys(resultValueGroupKeys);
283 
284         LuCodeInfo luCode = new LuCodeInfo();
285         RichTextInfo rt = new RichTextInfo();
286         rt.setPlain("fee.plain");
287         rt.setFormatted("fee.formatted");
288         luCode.setDescr(rt);
289         orig.getLuiCodes().add(luCode);
290 
291         LuiInfo info = luiService.createLui(orig.getCluId(), orig.getAtpId(), orig.getTypeKey(), orig, callContext);
292         assertNotNull(info);
293         assertEquals(orig.getName(), info.getName());
294         assertEquals(orig.getStateKey(), info.getStateKey());
295         assertEquals(orig.getTypeKey(), info.getTypeKey());
296         assertEquals(orig.getEffectiveDate(), info.getEffectiveDate());
297         assertEquals(orig.getExpirationDate(), info.getExpirationDate());
298 
299         assertNotNull(info.getOfficialIdentifier());
300         assertEquals(orig.getOfficialIdentifier().getShortName(), info.getOfficialIdentifier().getShortName());
301         assertEquals(orig.getAlternateIdentifiers().size(), info.getAlternateIdentifiers().size());
302         assertEquals(orig.getAlternateIdentifiers().get(0).getShortName(), info.getAlternateIdentifiers().get(0).getShortName());
303 
304         assertEquals(orig.getMaximumEnrollment(), info.getMaximumEnrollment());
305         assertEquals(orig.getMinimumEnrollment(), info.getMinimumEnrollment());
306         assertEquals(orig.getCluId(), info.getCluId());
307         assertEquals(orig.getAtpId(), info.getAtpId());
308         assertEquals(orig.getReferenceURL(), info.getReferenceURL());
309 
310         assertTrue(info.getUnitsContentOwner().contains("Org-2"));
311         assertTrue(info.getUnitsDeployment().contains("Org-1"));
312         assertTrue(info.getResultValuesGroupKeys().contains("Val-Group-3"));
313 
314         assertEquals(1, info.getLuiCodes().size());
315 
316         info = luiService.getLui(info.getId(), callContext);
317         assertNotNull(info);
318         assertEquals(orig.getName(), info.getName());
319         assertEquals(orig.getStateKey(), info.getStateKey());
320         assertEquals(orig.getTypeKey(), info.getTypeKey());
321         assertEquals(orig.getEffectiveDate(), info.getEffectiveDate());
322         assertEquals(orig.getExpirationDate(), info.getExpirationDate());
323 
324         assertNotNull(info.getOfficialIdentifier());
325         assertEquals(orig.getOfficialIdentifier().getShortName(), info.getOfficialIdentifier().getShortName());
326         assertEquals(orig.getAlternateIdentifiers().size(), info.getAlternateIdentifiers().size());
327         assertEquals(orig.getAlternateIdentifiers().get(0).getShortName(), info.getAlternateIdentifiers().get(0).getShortName());
328 
329         assertEquals(orig.getMaximumEnrollment(), info.getMaximumEnrollment());
330         assertEquals(orig.getMinimumEnrollment(), info.getMinimumEnrollment());
331         assertEquals(orig.getCluId(), info.getCluId());
332         assertEquals(orig.getAtpId(), info.getAtpId());
333         assertEquals(orig.getReferenceURL(), info.getReferenceURL());
334     }
335 
336     @Test
337     public void  testGetLuisByAtpAndClu() throws Exception{
338         List<LuiInfo> luis =  luiService.getLuisByAtpAndClu("cluId1", "atpId1", callContext)  ;
339         assertTrue(luis.size()>0);
340         assertNotNull(luis);
341         assertEquals(1, luis.size());
342         LuiInfo onlyLui = luis.get(0);
343         assertNotNull(onlyLui);
344         assertEquals("Lui-1",  onlyLui.getId() );
345         assertEquals("Lui one", onlyLui.getName());
346         assertEquals("cluId1", onlyLui.getCluId());
347         assertEquals("atpId1", onlyLui.getAtpId());
348     }
349 
350     @Test
351     public void testUpdateLui() throws Exception {
352         LuiInfo info = luiService.getLui("Lui-1", callContext);
353         assertNotNull(info);
354         assertEquals("Lui-1", info.getId());
355         assertEquals("Lui one", info.getName());
356 
357         LuiInfo modified = new LuiInfo(info);
358         modified.setName("Lui one modified");
359         modified.setStateKey(LuiServiceConstants.LUI_AO_STATE_APPROVED_KEY);
360         modified.setMaximumEnrollment(25);
361         modified.setMinimumEnrollment(10);
362         assertNotNull(modified.getOfficialIdentifier());
363         modified.getOfficialIdentifier().setTypeKey(LuiServiceConstants.LUI_IDENTIFIER_OFFICIAL_TYPE_KEY);
364         modified.getOfficialIdentifier().setStateKey(LuiServiceConstants.LUI_IDENTIFIER_ACTIVE_STATE_KEY);
365         modified.getOfficialIdentifier().setShortName("identifier.shortname");
366 
367         modified.getAlternateIdentifiers().clear();
368         LuiIdentifierInfo identifier2 = new LuiIdentifierInfo();
369         identifier2.setShortName("alternate.identifier.shortname");
370         identifier2.setTypeKey(LuiServiceConstants.LUI_IDENTIFIER_CROSSLISTED_TYPE_KEY);
371         identifier2.setStateKey(LuiServiceConstants.LUI_IDENTIFIER_ACTIVE_STATE_KEY);
372         modified.getAlternateIdentifiers().add(identifier2);
373 
374         modified.setReferenceURL("ref.update.url");
375         modified.setCluId("updateCluId");
376         modified.setAtpId("updateAtpId1");
377 
378         modified.getResultValuesGroupKeys().add("Val-Group-11");
379 
380         //Attributes
381         List<AttributeInfo> attributes = new ArrayList<AttributeInfo>();
382         for (AttributeInfo attrInfo:modified.getAttributes()){
383             if (attrInfo.getKey().equals("attr2")){
384                 attributes.add(attrInfo);
385             }
386         }
387         AttributeInfo modAttr1 = new AttributeInfo();
388         modAttr1.setKey("modattr1");
389         modAttr1.setValue("modattr1");
390         attributes.add(modAttr1);
391 
392         AttributeInfo modAttr2 = new AttributeInfo();
393         modAttr2.setKey("modattr2");
394         modAttr2.setValue("modattr2");
395         attributes.add(modAttr2);
396         modified.setAttributes(attributes);
397 
398         LuCodeInfo luCode = new LuCodeInfo();
399         RichTextInfo rt = new RichTextInfo();
400         rt.setPlain("fee.plain");
401         rt.setFormatted("fee.formatted");
402         luCode.setDescr(rt);
403         luCode.setId("Modified Lu Code");
404         modified.getLuiCodes().clear();
405         modified.getLuiCodes().add(luCode);
406 
407         modified.getUnitsContentOwner().add("Org-22");
408 
409         modified.getUnitsDeployment().add("Org-11");
410 
411         LuiInfo updated = luiService.updateLui("Lui-1", modified, callContext);
412 
413         assertNotNull(updated);
414         assertEquals("Lui one modified", updated.getName());
415         assertEquals(LuiServiceConstants.LUI_AO_STATE_APPROVED_KEY, updated.getStateKey());
416         assertEquals(LuiServiceConstants.COURSE_OFFERING_TYPE_KEY, updated.getTypeKey());
417         assertEquals(Integer.valueOf(25), updated.getMaximumEnrollment());
418         assertEquals(Integer.valueOf(10), updated.getMinimumEnrollment());
419         assertEquals("ref.update.url", updated.getReferenceURL());
420         assertNotNull(updated.getEffectiveDate());
421 
422         assertEquals(2, updated.getResultValuesGroupKeys().size());
423         assertTrue(updated.getResultValuesGroupKeys().contains("Val-Group-11"));
424 
425         assertNotNull(updated.getOfficialIdentifier());
426         assertEquals("identifier.shortname", updated.getOfficialIdentifier().getShortName());
427         assertEquals(1, updated.getAlternateIdentifiers().size());
428         assertEquals("alternate.identifier.shortname", updated.getAlternateIdentifiers().get(0).getShortName());
429 
430         //Attributes
431         HashMap<String, String> updatedAttributes = new HashMap<String, String>();
432         for (AttributeInfo attributeInfo:updated.getAttributes()){
433             updatedAttributes.put(attributeInfo.getKey(), attributeInfo.getValue());
434         }
435         assertFalse(updatedAttributes.containsKey("attr1"));
436         assertTrue(updatedAttributes.containsKey("attr2"));
437         assertTrue(updatedAttributes.containsKey("modattr1"));
438         assertTrue(updatedAttributes.containsKey("modattr2"));
439 
440         assertTrue(updated.getUnitsContentOwner().contains("Org-22"));
441         assertTrue(updated.getUnitsDeployment().contains("Org-11"));
442 
443         assertEquals(1, info.getLuiCodes().size());
444         assertEquals("Lu-Code-Lui-1", info.getLuiCodes().get(0).getId());
445         assertEquals(1, updated.getLuiCodes().size());
446         assertEquals("Modified Lu Code", updated.getLuiCodes().get(0).getId());
447     }
448 
449     @Test
450     public void testUpdateLuiLuiRelation() throws Exception{
451         LuiLuiRelationInfo info = luiService.getLuiLuiRelation("LUILUIREL-2", callContext);
452         assertNotNull(info);
453         info.setStateKey(LuiServiceConstants.LUI_LUI_RELATION_INACTIVE_STATE_KEY);
454         luiService.updateLuiLuiRelation(info.getId(), info, callContext);
455         assertEquals(info.getStateKey(), LuiServiceConstants.LUI_LUI_RELATION_INACTIVE_STATE_KEY);
456     }
457 
458     @Test
459     public void testGetLuiLuiRelation() throws Exception {
460         try {
461             LuiLuiRelationInfo obj = luiService.getLuiLuiRelation("LUILUIREL-1", callContext);
462             assertNotNull(obj);
463             assertEquals("Lui-1", obj.getLuiId());
464             assertEquals("Lui-2", obj.getRelatedLuiId());
465 
466         } catch (Exception ex) {
467             fail("exception from service call :" + ex.getMessage());
468         }
469     }
470 
471     @Test
472     public void testGetLuiLuiRelationsByLui() throws Exception {
473 
474         luiService.getLuiLuiRelationsByLui("Lui-Lui-Blah", callContext);
475         List<LuiLuiRelationInfo> objs = luiService.getLuiLuiRelationsByLui("Lui-1", callContext);
476         assertNotNull(objs);
477         assertEquals(1, objs.size());
478     }
479 
480     @Test
481     public void testCreateLuiLuiRelation() throws Exception{
482         LuiInfo info = new LuiInfo();
483         info.setCluId("testCluId");
484         info.setAtpId("testAtpId1");
485         info.setName("Test lui-Lui relation");
486         info.setStateKey(LuiServiceConstants.LUI_DRAFT_STATE_KEY);
487         info.setTypeKey(LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY);
488         info.setEffectiveDate(Calendar.getInstance().getTime());
489         info.setMaximumEnrollment(25);
490         info.setMinimumEnrollment(10);
491         RichTextInfo rtInfo = new RichTextInfo();
492         rtInfo.setFormatted("<p>Test lui-Lui relation description</p>");
493         rtInfo.setPlain("Test lui-Lui relation description");
494         info.setDescr(rtInfo);
495 
496         LuiInfo newLui = luiService.createLui(info.getCluId(), info.getAtpId(), info.getTypeKey(), info, callContext);
497         LuiLuiRelationInfo created = null;
498         LuiLuiRelationInfo rel = new LuiLuiRelationInfo();
499         rel.setLuiId("Lui-1");
500         rel.setRelatedLuiId(newLui.getId());
501         rel.setStateKey(LuiServiceConstants.LUI_LUI_RELATION_ACTIVE_STATE_KEY);
502         rel.setTypeKey(LuiServiceConstants.LUI_LUI_RELATION_DELIVERED_VIA_FO_TO_AO_TYPE_KEY);
503         rel.setEffectiveDate(Calendar.getInstance().getTime());
504         rtInfo = new RichTextInfo();
505         rtInfo.setFormatted("<p>Test lui-Lui relation description</p>");
506         rtInfo.setPlain("Test lui-Lui relation description");
507         rel.setDescr(rtInfo);
508         created = luiService.createLuiLuiRelation("Lui-1", newLui.getId(), LuiServiceConstants.LUI_LUI_RELATION_DELIVERED_VIA_FO_TO_AO_TYPE_KEY, rel, callContext);
509 
510         assertNotNull(created);
511         assertEquals(LuiServiceConstants.LUI_LUI_RELATION_ACTIVE_STATE_KEY, created.getStateKey());
512         assertEquals(LuiServiceConstants.LUI_LUI_RELATION_DELIVERED_VIA_FO_TO_AO_TYPE_KEY, created.getTypeKey());
513 
514 
515 
516         LuiLuiRelationInfo retrieved = luiService.getLuiLuiRelation(created.getId(), callContext);
517         assertNotNull(retrieved);
518         assertEquals(LuiServiceConstants.LUI_LUI_RELATION_ACTIVE_STATE_KEY, retrieved.getStateKey());
519         assertEquals(LuiServiceConstants.LUI_LUI_RELATION_DELIVERED_VIA_FO_TO_AO_TYPE_KEY, retrieved.getTypeKey());
520 
521         List<LuiLuiRelationInfo> objs = luiService.getLuiLuiRelationsByLui("Lui-1", callContext);
522         assertNotNull(objs);
523         assertEquals(2, objs.size());
524         for (LuiLuiRelationInfo obj : objs) {
525             assertTrue(obj.getRelatedLuiId().equals("Lui-2") || obj.getRelatedLuiId().equals(newLui.getId()));
526         }
527     }
528 
529     @Test
530     public void testDeleteLui()
531             throws Exception{
532         LuiInfo info = luiService.getLui("Lui-3", callContext);
533         assertNotNull(info);
534 
535         List<LuiLuiRelationInfo> objs = luiService.getLuiLuiRelationsByLui("Lui-3", callContext);
536         assertNotNull(objs);
537         assertEquals(1, objs.size());
538 
539         try {
540             luiService.deleteLui("Lui-3-blah", callContext);
541         } catch (DoesNotExistException ee) {
542         }
543 
544         StatusInfo status = luiService.deleteLui("Lui-3", callContext);
545         assertTrue(status.getIsSuccess());
546 
547         luiService.getLuiLuiRelationsByLui("Lui-3", callContext);
548 
549         try {
550             luiService.getLui("Lui-3", callContext);
551         } catch (DoesNotExistException ee) {
552         }
553     }
554 
555     @Test
556     public void testGetLuisByIds() throws Exception {
557        List<String> luiIds = new ArrayList<String>();
558         luiIds.add("Lui-1");
559         luiIds.add("Lui-2");
560         luiIds.add("Lui-3");
561         List<LuiInfo> luis =  luiService.getLuisByIds(luiIds, callContext);
562 
563         assertNotNull(luis);
564         assertTrue(luis.size() == 3);
565 
566         try{
567             luiIds.add("Lui-3b");
568             luis =  luiService.getLuisByIds(luiIds, callContext);
569         }catch (DoesNotExistException ex) {
570             assertNotNull(ex.getMessage());
571         }
572 
573     }
574 
575 
576 
577     @Test
578     public void testGetLuiIdsByType() throws Exception {
579 
580         List<String> luis =  luiService.getLuiIdsByType("kuali.lui.type.course.offering", callContext);
581 
582         assertNotNull(luis);
583         assertTrue(luis.size() == 2);
584 
585     }
586 
587 
588     @Test
589     public void testGetLuiIdsByAtpAndType() throws Exception{
590         List<String> luiIds =  luiService.getLuiIdsByAtpAndType( "atpId1", "kuali.lui.type.course.offering", callContext);
591         assertNotNull(luiIds);
592         assertEquals(luiIds.size(), 1);
593         assertEquals(luiIds.get(0) ,"Lui-1");
594         List<String> luiIdsNonExistent =  luiService.getLuiIdsByAtpAndType( "atpId21", "kuali.lui.type.course.offering", callContext);
595         assertNotNull(luiIdsNonExistent);
596         assertEquals(luiIdsNonExistent.size(),0);
597 
598     }
599     @Test
600     public void testGetRelatedLuiIdsByLui() throws Exception{
601         List<String> luiRelationIds =  luiService.getLuiIdsByLuiAndRelationType("Lui-1", "kuali.lui.lui.relation.associated", callContext);
602         assertNotNull(luiRelationIds);
603         assertEquals( 1, luiRelationIds.size());
604         assertEquals("Lui-2", luiRelationIds.get(0) );
605 
606     }
607     @Test
608     public void testGetRelatedLuisByLui() throws Exception{
609         List<LuiInfo> luiRelations =  luiService.getRelatedLuisByLuiAndRelationType("Lui-3", "kuali.lui.lui.relation.associated", callContext);
610         assertNotNull(luiRelations);
611         assertEquals( 1, luiRelations.size());
612         assertEquals("Lui-4", luiRelations.get(0).getId() );
613 
614     }
615 
616 
617 
618 }