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.exceptions.OperationFailedException;
11  import org.kuali.student.core.statement.dto.ReqCompFieldInfo;
12  import org.kuali.student.core.statement.dto.ReqComponentInfo;
13  import org.kuali.student.lum.statement.typekey.ReqComponentFieldTypes;
14  
15  public class BasicContextImplTest {
16  	private BasicContextImpl basicContext = new BasicContextImpl();
17  	private ReqComponentInfo reqComponent1;
18  	private ReqComponentInfo reqComponent2;
19  	private ReqComponentInfo reqComponent3;
20  	private ReqComponentInfo reqComponent4;
21  	
22  	private void setupReqComponent1() {
23  		reqComponent1 = new ReqComponentInfo();
24          List<ReqCompFieldInfo> reqCompFieldList = new ArrayList<ReqCompFieldInfo>();
25          ReqCompFieldInfo reqCompField1 = new ReqCompFieldInfo();
26          reqCompField1.setType(ReqComponentFieldTypes.OPERATOR_KEY.getId());
27          reqCompField1.setValue(">");
28          reqCompFieldList.add(reqCompField1);
29          ReqCompFieldInfo reqCompField2 = new ReqCompFieldInfo();
30          reqCompField2.setType(ReqComponentFieldTypes.INTEGER_VALUE1_KEY.getId());
31          reqCompField2.setValue("1");
32          reqCompFieldList.add(reqCompField2);
33  		reqComponent1.setReqCompFields(reqCompFieldList);
34  	}
35  
36  	private void setupReqComponent2() {
37  		reqComponent2 = new ReqComponentInfo();
38          List<ReqCompFieldInfo> reqCompFieldList = new ArrayList<ReqCompFieldInfo>();
39          ReqCompFieldInfo reqCompField1 = new ReqCompFieldInfo();
40          reqCompField1.setType(ReqComponentFieldTypes.INTEGER_VALUE1_KEY.getId());
41          reqCompField1.setValue("1");
42          reqCompFieldList.add(reqCompField1);
43  		reqComponent2.setReqCompFields(reqCompFieldList);
44  	}
45  	
46  	private void setupReqComponent3() {
47  		reqComponent3 = new ReqComponentInfo();
48          List<ReqCompFieldInfo> reqCompFieldList = new ArrayList<ReqCompFieldInfo>();
49          ReqCompFieldInfo reqCompField1 = new ReqCompFieldInfo();
50          reqCompField1.setType(ReqComponentFieldTypes.INTEGER_VALUE1_KEY.getId());
51          reqCompField1.setValue(null);
52          reqCompFieldList.add(reqCompField1);
53  		reqComponent3.setReqCompFields(reqCompFieldList);
54  	}
55  	
56  	private void setupReqComponent4() {
57  		reqComponent4 = new ReqComponentInfo();
58          List<ReqCompFieldInfo> reqCompFieldList = new ArrayList<ReqCompFieldInfo>();
59          ReqCompFieldInfo reqCompField1 = new ReqCompFieldInfo();
60          reqCompField1.setType(ReqComponentFieldTypes.OPERATOR_KEY.getId());
61          reqCompField1.setValue(null);
62          reqCompFieldList.add(reqCompField1);
63          ReqCompFieldInfo reqCompField2 = new ReqCompFieldInfo();
64          reqCompField2.setType(ReqComponentFieldTypes.INTEGER_VALUE1_KEY.getId());
65          reqCompField2.setValue(null);
66          reqCompFieldList.add(reqCompField2);
67  		reqComponent4.setReqCompFields(reqCompFieldList);
68  	}
69  	
70  	@Before
71  	public void beforeMethod() {
72  		setupReqComponent1();
73  		setupReqComponent2();
74  		setupReqComponent3();
75  		setupReqComponent4();
76  	}
77  	
78  	@Test
79      public void testCreateContextMap() throws OperationFailedException {
80  		Map<String, Object> contextMap = basicContext.createContextMap(reqComponent1);
81  		Assert.assertNotNull(contextMap);
82  		Assert.assertTrue(contextMap.containsKey(BasicContextImpl.NL_HELPER_TOKEN));
83  		Assert.assertTrue(contextMap.containsKey(BasicContextImpl.OPERATOR_TOKEN));
84  		Assert.assertTrue(contextMap.containsKey(BasicContextImpl.INTEGER_VALUE_TOKEN));
85      }
86  
87  	@Test
88      public void testCreateContextMap_NullTokenValues() throws OperationFailedException {
89  		Map<String, Object> contextMap = basicContext.createContextMap(reqComponent4);
90  		Assert.assertNotNull(contextMap);
91  		Assert.assertFalse(contextMap.containsKey(BasicContextImpl.OPERATOR_TOKEN));
92  		Assert.assertFalse(contextMap.containsKey(BasicContextImpl.INTEGER_VALUE_TOKEN));
93      }
94  
95  	@Test
96      public void testCreateContextMap_CheckTokenValueDataType_Integer() throws OperationFailedException {
97  		Map<String, Object> contextMap = basicContext.createContextMap(reqComponent2);
98  		Object value = contextMap.get(BasicContextImpl.INTEGER_VALUE_TOKEN);
99  		
100 		Assert.assertEquals(Integer.class.getName(), value.getClass().getName());
101 		Assert.assertEquals("1", value.toString());
102     }
103 
104 	@Test
105     public void testCreateContextMap_CheckTokenValueDataType_NullInteger() throws OperationFailedException {
106 		Map<String, Object> contextMap = basicContext.createContextMap(reqComponent3);
107 		Object value = contextMap.get(BasicContextImpl.INTEGER_VALUE_TOKEN);
108 		
109 		Assert.assertEquals(null, value);
110     }
111 }