001/* 002 * To change this template, choose Tools | Templates 003 * and open the template in the editor. 004 */ 005package org.kuali.student.r2.lum.lu.service.impl; 006 007import java.util.ArrayList; 008import java.util.Date; 009import java.util.List; 010import org.junit.After; 011import org.junit.AfterClass; 012import org.junit.Before; 013import org.junit.BeforeClass; 014import org.junit.Test; 015import static org.junit.Assert.*; 016import org.kuali.student.r2.common.dto.ContextInfo; 017import org.kuali.student.r2.core.versionmanagement.dto.VersionDisplayInfo; 018import org.kuali.student.r2.lum.clu.dto.CluInfo; 019import org.kuali.student.r2.lum.clu.dto.CluSetInfo; 020import org.kuali.student.r2.lum.clu.service.CluService; 021import org.kuali.student.r2.lum.util.constants.CluServiceConstants; 022 023/** 024 * 025 * @author nwright 026 */ 027public class TestCluServiceMockImpl { 028 029 public TestCluServiceMockImpl() { 030 } 031 032 @BeforeClass 033 public static void setUpClass() { 034 } 035 036 @AfterClass 037 public static void tearDownClass() { 038 } 039 private CluService cluService = null; 040 private ContextInfo contextInfo = null; 041 042 protected void loadCluService () { 043 if (cluService == null) { 044 cluService = new CluServiceMockImpl(); 045 } 046 } 047 048 @Before 049 public void setUp() { 050 contextInfo = new ContextInfo(); 051 contextInfo.setPrincipalId("TESTUSER"); 052 contextInfo.setCurrentDate(new Date()); 053 054 // make sure it is loaded 055 loadCluService (); 056 057 CluDataLoader cluDataLoader = new CluDataLoader(); 058 cluDataLoader.setCluService(cluService); 059 cluDataLoader.setContextInfo(contextInfo); 060 cluDataLoader.load(); 061 062 CluSetDataLoader cluSetDataLoader = new CluSetDataLoader(); 063 cluSetDataLoader.setCluService(cluService); 064 cluSetDataLoader.setContextInfo(contextInfo); 065 cluSetDataLoader.load(); 066 } 067 068 @After 069 public void tearDown() { 070 } 071 072 @Test 073 public void testCluSet() throws Exception { 074 System.out.println("testCluSet"); 075 CluSetInfo orig = new CluSetInfo(); 076 orig.setTypeKey(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE); 077 orig.setStateKey("Active"); 078 orig.setName("MyCluSet"); 079 orig.setEffectiveDate(new Date()); 080 orig.setIsReferenceable(Boolean.TRUE); 081 orig.setIsReusable(Boolean.FALSE); 082 List<String> cluIds = new ArrayList<String>(); 083 CluInfo cluInfo1 = this.cluService.getClu("COURSE1", contextInfo); 084 cluIds.add(cluInfo1.getVersion().getVersionIndId()); 085 CluInfo cluInfo2 = this.cluService.getClu("COURSE2", contextInfo); 086 cluIds.add(cluInfo2.getVersion().getVersionIndId()); 087 orig.setCluIds(cluIds); 088 CluSetInfo info = this.cluService.createCluSet(orig.getTypeKey(), orig, contextInfo); 089 assertEquals(orig.getTypeKey(), info.getTypeKey()); 090 assertEquals(orig.getStateKey(), info.getStateKey()); 091 } 092 093 private CluInfo getCurrentCluInfoByVersionIndId(String id, ContextInfo contextInfo) { 094 VersionDisplayInfo versionDisplayInfo = null; 095 try { 096 versionDisplayInfo = this.cluService.getCurrentVersion(CluServiceConstants.CLU_NAMESPACE_URI, id, contextInfo); 097 } catch (Exception ex) { 098 throw new IllegalArgumentException("Unexpected", ex); 099 } 100 try { 101 return this.cluService.getClu(versionDisplayInfo.getId(), contextInfo); 102 } catch (Exception ex) { 103 throw new IllegalArgumentException("Unexpected", ex); 104 } 105 } 106}