View Javadoc

1   package org.kuali.student.lum.statement.config.context;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   import java.util.Map;
6   
7   import org.junit.Assert;
8   import org.junit.Before;
9   import org.junit.Test;
10  import org.kuali.student.common.test.spring.AbstractServiceTest;
11  import org.kuali.student.common.test.spring.Client;
12  import org.kuali.student.common.test.spring.Dao;
13  import org.kuali.student.common.test.spring.Daos;
14  import org.kuali.student.common.test.spring.PersistenceFileLocation;
15  import org.kuali.student.r2.lum.statement.config.context.util.NLCluSet;
16  import org.kuali.student.r1.core.statement.dto.ReqCompFieldInfo;
17  import org.kuali.student.r1.core.statement.dto.ReqComponentInfo;
18  import org.kuali.student.r1.lum.statement.typekey.ReqComponentFieldTypes;
19  import org.kuali.student.r2.common.exceptions.OperationFailedException;
20  import org.kuali.student.r2.common.util.ContextUtils;
21  import org.kuali.student.r2.lum.clu.dto.CluInfo;
22  import org.kuali.student.r2.lum.clu.service.CluService;
23  import org.kuali.student.r2.lum.statement.config.context.CluContextImpl;
24  
25  @Daos( { @Dao(value = "org.kuali.student.r2.lum.lu.dao.impl.LuDaoImpl", testSqlFile = "classpath:ks-lu.sql") })
26  @PersistenceFileLocation("classpath:META-INF/lu-persistence.xml")
27  public class CluContextImplTest extends AbstractServiceTest {
28  
29      @Client(value = "org.kuali.student.r2.lum.lu.service.impl.CluServiceImpl", additionalContextFile = "classpath:clu-additional-context.xml")
30      private CluService cluService;
31  	private CluContextImpl cluContext = new CluContextImpl();
32  
33  	private ReqComponentInfo reqComponent1;
34  	private ReqComponentInfo reqComponent2;
35  	
36  	
37  	private void setupReqComponent1() {
38  		reqComponent1 = new ReqComponentInfo();
39          List<ReqCompFieldInfo> reqCompFieldList = new ArrayList<ReqCompFieldInfo>();
40          ReqCompFieldInfo reqCompField1 = new ReqCompFieldInfo();
41          reqCompField1.setType(ReqComponentFieldTypes.CLU_KEY.getId());
42          reqCompField1.setValue("CLU-1");
43          reqCompFieldList.add(reqCompField1);
44  		reqComponent1.setReqCompFields(reqCompFieldList);
45  
46          ReqCompFieldInfo reqCompField2 = new ReqCompFieldInfo();
47          reqCompField2.setType(ReqComponentFieldTypes.COURSE_CLU_KEY.getId());
48          reqCompField2.setValue("CLU-1");
49          reqCompFieldList.add(reqCompField2);
50  		reqComponent1.setReqCompFields(reqCompFieldList);
51  
52          ReqCompFieldInfo reqCompField3 = new ReqCompFieldInfo();
53          reqCompField3.setType(ReqComponentFieldTypes.PROGRAM_CLU_KEY.getId());
54          reqCompField3.setValue("CLU-1");
55          reqCompFieldList.add(reqCompField3);
56  		reqComponent1.setReqCompFields(reqCompFieldList);
57  
58          ReqCompFieldInfo reqCompField4 = new ReqCompFieldInfo();
59          reqCompField4.setType(ReqComponentFieldTypes.TEST_CLU_KEY.getId());
60          reqCompField4.setValue("CLU-1");
61          reqCompFieldList.add(reqCompField4);
62  		reqComponent1.setReqCompFields(reqCompFieldList);
63  		
64  		ReqCompFieldInfo reqCompField5 = new ReqCompFieldInfo();
65          reqCompField5.setType(ReqComponentFieldTypes.CLUSET_KEY.getId());
66          reqCompField5.setValue("CLUSET-1");
67          reqCompFieldList.add(reqCompField5);
68  		reqComponent1.setReqCompFields(reqCompFieldList);
69  
70  		ReqCompFieldInfo reqCompField6 = new ReqCompFieldInfo();
71          reqCompField6.setType(ReqComponentFieldTypes.COURSE_CLUSET_KEY.getId());
72          reqCompField6.setValue("CLUSET-1");
73          reqCompFieldList.add(reqCompField6);
74  		reqComponent1.setReqCompFields(reqCompFieldList);
75  
76  		ReqCompFieldInfo reqCompField7 = new ReqCompFieldInfo();
77          reqCompField7.setType(ReqComponentFieldTypes.PROGRAM_CLUSET_KEY.getId());
78          reqCompField7.setValue("CLUSET-1");
79          reqCompFieldList.add(reqCompField7);
80  		reqComponent1.setReqCompFields(reqCompFieldList);
81  
82  		ReqCompFieldInfo reqCompField8 = new ReqCompFieldInfo();
83          reqCompField8.setType(ReqComponentFieldTypes.TEST_CLUSET_KEY.getId());
84          reqCompField8.setValue("CLUSET-1");
85          reqCompFieldList.add(reqCompField8);
86  		reqComponent1.setReqCompFields(reqCompFieldList);
87  	}
88  
89  	private void setupReqComponent2() {
90  		reqComponent2 = new ReqComponentInfo();
91          List<ReqCompFieldInfo> reqCompFieldList = new ArrayList<ReqCompFieldInfo>();
92          ReqCompFieldInfo reqCompField1 = new ReqCompFieldInfo();
93          reqCompField1.setType(ReqComponentFieldTypes.CLU_KEY.getId());
94          reqCompField1.setValue(null);
95          reqCompFieldList.add(reqCompField1);
96  		reqComponent2.setReqCompFields(reqCompFieldList);
97  
98          ReqCompFieldInfo reqCompField2 = new ReqCompFieldInfo();
99          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 }