001package org.kuali.student.lum.statement.config.context; 002 003import java.util.ArrayList; 004import java.util.List; 005import java.util.Map; 006 007import org.junit.Assert; 008import org.junit.Before; 009import org.junit.Test; 010import org.kuali.student.common.test.spring.AbstractServiceTest; 011import org.kuali.student.common.test.spring.Client; 012import org.kuali.student.common.test.spring.Dao; 013import org.kuali.student.common.test.spring.Daos; 014import org.kuali.student.common.test.spring.PersistenceFileLocation; 015import org.kuali.student.r2.lum.statement.config.context.util.NLCluSet; 016import org.kuali.student.r1.core.statement.dto.ReqCompFieldInfo; 017import org.kuali.student.r1.core.statement.dto.ReqComponentInfo; 018import org.kuali.student.r1.lum.statement.typekey.ReqComponentFieldTypes; 019import org.kuali.student.r2.common.exceptions.OperationFailedException; 020import org.kuali.student.r2.common.util.ContextUtils; 021import org.kuali.student.r2.lum.clu.dto.CluInfo; 022import org.kuali.student.r2.lum.clu.service.CluService; 023import org.kuali.student.r2.lum.statement.config.context.CluContextImpl; 024 025@Daos( { @Dao(value = "org.kuali.student.r2.lum.lu.dao.impl.LuDaoImpl", testSqlFile = "classpath:ks-lu.sql") }) 026@PersistenceFileLocation("classpath:META-INF/lu-persistence.xml") 027public class CluContextImplTest extends AbstractServiceTest { 028 029 @Client(value = "org.kuali.student.r2.lum.lu.service.impl.CluServiceImpl", additionalContextFile = "classpath:clu-additional-context.xml") 030 private CluService cluService; 031 private CluContextImpl cluContext = new CluContextImpl(); 032 033 private ReqComponentInfo reqComponent1; 034 private ReqComponentInfo reqComponent2; 035 036 037 private void setupReqComponent1() { 038 reqComponent1 = new ReqComponentInfo(); 039 List<ReqCompFieldInfo> reqCompFieldList = new ArrayList<ReqCompFieldInfo>(); 040 ReqCompFieldInfo reqCompField1 = new ReqCompFieldInfo(); 041 reqCompField1.setType(ReqComponentFieldTypes.CLU_KEY.getId()); 042 reqCompField1.setValue("CLU-1"); 043 reqCompFieldList.add(reqCompField1); 044 reqComponent1.setReqCompFields(reqCompFieldList); 045 046 ReqCompFieldInfo reqCompField2 = new ReqCompFieldInfo(); 047 reqCompField2.setType(ReqComponentFieldTypes.COURSE_CLU_KEY.getId()); 048 reqCompField2.setValue("CLU-1"); 049 reqCompFieldList.add(reqCompField2); 050 reqComponent1.setReqCompFields(reqCompFieldList); 051 052 ReqCompFieldInfo reqCompField3 = new ReqCompFieldInfo(); 053 reqCompField3.setType(ReqComponentFieldTypes.PROGRAM_CLU_KEY.getId()); 054 reqCompField3.setValue("CLU-1"); 055 reqCompFieldList.add(reqCompField3); 056 reqComponent1.setReqCompFields(reqCompFieldList); 057 058 ReqCompFieldInfo reqCompField4 = new ReqCompFieldInfo(); 059 reqCompField4.setType(ReqComponentFieldTypes.TEST_CLU_KEY.getId()); 060 reqCompField4.setValue("CLU-1"); 061 reqCompFieldList.add(reqCompField4); 062 reqComponent1.setReqCompFields(reqCompFieldList); 063 064 ReqCompFieldInfo reqCompField5 = new ReqCompFieldInfo(); 065 reqCompField5.setType(ReqComponentFieldTypes.CLUSET_KEY.getId()); 066 reqCompField5.setValue("CLUSET-1"); 067 reqCompFieldList.add(reqCompField5); 068 reqComponent1.setReqCompFields(reqCompFieldList); 069 070 ReqCompFieldInfo reqCompField6 = new ReqCompFieldInfo(); 071 reqCompField6.setType(ReqComponentFieldTypes.COURSE_CLUSET_KEY.getId()); 072 reqCompField6.setValue("CLUSET-1"); 073 reqCompFieldList.add(reqCompField6); 074 reqComponent1.setReqCompFields(reqCompFieldList); 075 076 ReqCompFieldInfo reqCompField7 = new ReqCompFieldInfo(); 077 reqCompField7.setType(ReqComponentFieldTypes.PROGRAM_CLUSET_KEY.getId()); 078 reqCompField7.setValue("CLUSET-1"); 079 reqCompFieldList.add(reqCompField7); 080 reqComponent1.setReqCompFields(reqCompFieldList); 081 082 ReqCompFieldInfo reqCompField8 = new ReqCompFieldInfo(); 083 reqCompField8.setType(ReqComponentFieldTypes.TEST_CLUSET_KEY.getId()); 084 reqCompField8.setValue("CLUSET-1"); 085 reqCompFieldList.add(reqCompField8); 086 reqComponent1.setReqCompFields(reqCompFieldList); 087 } 088 089 private void setupReqComponent2() { 090 reqComponent2 = new ReqComponentInfo(); 091 List<ReqCompFieldInfo> reqCompFieldList = new ArrayList<ReqCompFieldInfo>(); 092 ReqCompFieldInfo reqCompField1 = new ReqCompFieldInfo(); 093 reqCompField1.setType(ReqComponentFieldTypes.CLU_KEY.getId()); 094 reqCompField1.setValue(null); 095 reqCompFieldList.add(reqCompField1); 096 reqComponent2.setReqCompFields(reqCompFieldList); 097 098 ReqCompFieldInfo reqCompField2 = new ReqCompFieldInfo(); 099 reqCompField2.setType(ReqComponentFieldTypes.COURSE_CLU_KEY.getId()); 100 reqCompField2.setValue(null); 101 reqCompFieldList.add(reqCompField2); 102 reqComponent2.setReqCompFields(reqCompFieldList); 103 104 ReqCompFieldInfo reqCompField3 = new ReqCompFieldInfo(); 105 reqCompField3.setType(ReqComponentFieldTypes.PROGRAM_CLU_KEY.getId()); 106 reqCompField3.setValue(null); 107 reqCompFieldList.add(reqCompField3); 108 reqComponent2.setReqCompFields(reqCompFieldList); 109 110 ReqCompFieldInfo reqCompField4 = new ReqCompFieldInfo(); 111 reqCompField4.setType(ReqComponentFieldTypes.TEST_CLU_KEY.getId()); 112 reqCompField4.setValue(null); 113 reqCompFieldList.add(reqCompField4); 114 reqComponent2.setReqCompFields(reqCompFieldList); 115 116 ReqCompFieldInfo reqCompField5 = new ReqCompFieldInfo(); 117 reqCompField5.setType(ReqComponentFieldTypes.CLUSET_KEY.getId()); 118 reqCompField5.setValue(null); 119 reqCompFieldList.add(reqCompField5); 120 reqComponent2.setReqCompFields(reqCompFieldList); 121 122 ReqCompFieldInfo reqCompField6 = new ReqCompFieldInfo(); 123 reqCompField6.setType(ReqComponentFieldTypes.COURSE_CLUSET_KEY.getId()); 124 reqCompField6.setValue(null); 125 reqCompFieldList.add(reqCompField6); 126 reqComponent2.setReqCompFields(reqCompFieldList); 127 128 ReqCompFieldInfo reqCompField7 = new ReqCompFieldInfo(); 129 reqCompField7.setType(ReqComponentFieldTypes.PROGRAM_CLUSET_KEY.getId()); 130 reqCompField7.setValue(null); 131 reqCompFieldList.add(reqCompField7); 132 reqComponent2.setReqCompFields(reqCompFieldList); 133 134 ReqCompFieldInfo reqCompField8 = new ReqCompFieldInfo(); 135 reqCompField8.setType(ReqComponentFieldTypes.TEST_CLUSET_KEY.getId()); 136 reqCompField8.setValue(null); 137 reqCompFieldList.add(reqCompField8); 138 reqComponent2.setReqCompFields(reqCompFieldList); 139 } 140 141 @Before 142 public void beforeMethod() { 143 cluContext.setCluService(cluService); 144 setupReqComponent1(); 145 setupReqComponent2(); 146 } 147 148 @Test 149 public void testCreateContextMap_Clu() throws OperationFailedException { 150 Map<String, Object> contextMap = cluContext.createContextMap(reqComponent1, ContextUtils.getContextInfo()); 151 CluInfo clu = (CluInfo) contextMap.get(CluContextImpl.CLU_TOKEN); 152 CluInfo courseClu = (CluInfo) contextMap.get(CluContextImpl.COURSE_CLU_TOKEN); 153 CluInfo programClu = (CluInfo) contextMap.get(CluContextImpl.PROGRAM_CLU_TOKEN); 154 CluInfo testClu = (CluInfo) contextMap.get(CluContextImpl.TEST_CLU_TOKEN); 155 156 Assert.assertNotNull(contextMap); 157 Assert.assertEquals("CLU-1", clu.getId()); 158 Assert.assertEquals("CLU-1", courseClu.getId()); 159 Assert.assertEquals("CLU-1", programClu.getId()); 160 Assert.assertEquals("CLU-1", testClu.getId()); 161 162 Assert.assertEquals("kuali.lu.type.CreditCourse", clu.getTypeKey()); 163 Assert.assertEquals("Chem 123", clu.getOfficialIdentifier().getShortName()); 164 Assert.assertEquals("Chemistry 123", clu.getOfficialIdentifier().getLongName()); 165 } 166 167 @Test 168 public void testCreateContextMap_CluSet() throws OperationFailedException { 169 Map<String, Object> contextMap = cluContext.createContextMap(reqComponent1, ContextUtils.getContextInfo()); 170 NLCluSet cluSet = (NLCluSet) contextMap.get(CluContextImpl.CLU_SET_TOKEN); 171 NLCluSet courseCluSet = (NLCluSet) contextMap.get(CluContextImpl.COURSE_CLU_SET_TOKEN); 172 NLCluSet programCluSet = (NLCluSet) contextMap.get(CluContextImpl.PROGRAM_CLU_SET_TOKEN); 173 NLCluSet testCluSet = (NLCluSet) contextMap.get(CluContextImpl.TEST_CLU_SET_TOKEN); 174 175 176 Assert.assertNotNull(contextMap); 177 Assert.assertEquals("CLUSET-1", cluSet.getCluSetId()); 178 Assert.assertEquals("CLUSET-1", courseCluSet.getCluSetId()); 179 Assert.assertEquals("CLUSET-1", programCluSet.getCluSetId()); 180 Assert.assertEquals("CLUSET-1", testCluSet.getCluSetId()); 181 182 Assert.assertEquals("(CHEM456, CHEM456)", cluSet.getCluSetAsCode()); 183 Assert.assertEquals("(Chem 456, Chem 456)", cluSet.getCluSetAsShortName()); 184 Assert.assertEquals("(Chemistry 456, Chemistry 456)", cluSet.getCluSetAsLongName()); 185 186 Assert.assertEquals("CHEM456", cluSet.getCluAsCode(0)); 187 Assert.assertEquals("Chem 456", cluSet.getCluAsShortName(0)); 188 Assert.assertEquals("CHEM456", cluSet.getCluAsCode(1)); 189 Assert.assertEquals("Chem 456", cluSet.getCluAsShortName(1)); 190 } 191 192 @Test 193 public void testCreateContextMap_NullTokenValues() throws OperationFailedException { 194 Map<String, Object> contextMap = cluContext.createContextMap(reqComponent2, ContextUtils.getContextInfo()); 195 CluInfo clu = (CluInfo) contextMap.get(CluContextImpl.CLU_TOKEN); 196 CluInfo courseClu = (CluInfo) contextMap.get(CluContextImpl.COURSE_CLU_TOKEN); 197 CluInfo programClu = (CluInfo) contextMap.get(CluContextImpl.PROGRAM_CLU_TOKEN); 198 CluInfo testClu = (CluInfo) contextMap.get(CluContextImpl.TEST_CLU_TOKEN); 199 NLCluSet cluSet = (NLCluSet) contextMap.get(CluContextImpl.CLU_SET_TOKEN); 200 NLCluSet courseCluSet = (NLCluSet) contextMap.get(CluContextImpl.COURSE_CLU_SET_TOKEN); 201 NLCluSet programCluSet = (NLCluSet) contextMap.get(CluContextImpl.PROGRAM_CLU_SET_TOKEN); 202 NLCluSet testCluSet = (NLCluSet) contextMap.get(CluContextImpl.TEST_CLU_SET_TOKEN); 203 204 Assert.assertNotNull(contextMap); 205 Assert.assertEquals(null, clu); 206 Assert.assertEquals(null, courseClu); 207 Assert.assertEquals(null, programClu); 208 Assert.assertEquals(null, testClu); 209 Assert.assertEquals(null, cluSet); 210 Assert.assertEquals(null, courseCluSet); 211 Assert.assertEquals(null, programCluSet); 212 Assert.assertEquals(null, testCluSet); 213 214 } 215 216}