1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
package org.kuali.student.common.ui.server.screenreport; |
10 |
|
|
11 |
|
import java.io.FileNotFoundException; |
12 |
|
import java.io.FileOutputStream; |
13 |
|
import java.io.IOException; |
14 |
|
import java.io.OutputStream; |
15 |
|
import java.util.ArrayList; |
16 |
|
import java.util.List; |
17 |
|
|
18 |
|
import org.junit.Assert; |
19 |
|
import org.junit.Before; |
20 |
|
import org.junit.Test; |
21 |
|
import org.kuali.student.common.assembly.data.Data; |
22 |
|
import org.kuali.student.common.ui.client.util.ExportElement; |
23 |
|
import org.kuali.student.common.ui.server.screenreport.jasper.JasperScreenReportProcessorImpl; |
24 |
|
|
|
|
| 98.6% |
Uncovered Elements: 2 (139) |
Complexity: 5 |
Complexity Density: 0.04 |
|
25 |
|
public class TestScreenReport { |
26 |
|
|
27 |
|
private Data dataMap; |
28 |
|
|
29 |
|
private List<ExportElement> dataList; |
30 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (100) |
Complexity: 1 |
Complexity Density: 0.01 |
|
31 |
1
|
@Before... |
32 |
|
public void setup() { |
33 |
|
|
34 |
1
|
dataMap = new Data(); |
35 |
|
|
36 |
1
|
dataMap.set("key1", "value1"); |
37 |
1
|
Data subData = new Data(); |
38 |
1
|
subData.set("firstName", "Jon"); |
39 |
1
|
subData.set("ssn", "123456789"); |
40 |
1
|
dataMap.set("key2", subData); |
41 |
|
|
42 |
1
|
Data subData2 = new Data(); |
43 |
1
|
subData2.set("firstName", "who"); |
44 |
1
|
subData2.set("ssn", "123456789"); |
45 |
|
|
46 |
1
|
Data subData2a = new Data(); |
47 |
1
|
subData2a.set("third", "value"); |
48 |
1
|
subData2.set("level", subData2a); |
49 |
1
|
dataMap.set("key3", subData2); |
50 |
|
|
51 |
1
|
Data subData3 = new Data(); |
52 |
1
|
subData3.set("firstName", "Me"); |
53 |
1
|
subData3.set("ssn", "123456789"); |
54 |
1
|
dataMap.set("key4", subData3); |
55 |
|
|
56 |
1
|
dataMap.set("key5", "value5"); |
57 |
|
|
58 |
1
|
String value = null; |
59 |
1
|
dataMap.set("key6", value); |
60 |
|
|
61 |
1
|
dataMap.set("key7", "This is a very long description. The impact of public policies on the black community and the role of the policy process in affecting the social, economic and political well-being of minorities. Particular attention given to the post-1960 to present era."); |
62 |
|
|
63 |
|
|
64 |
1
|
dataMap.set("key8", "simple value"); |
65 |
1
|
dataMap.set("key9", "simple value"); |
66 |
1
|
dataMap.set("key10", "simple value"); |
67 |
1
|
dataMap.set("key11", "simple value"); |
68 |
1
|
dataMap.set("key12", "simple value"); |
69 |
1
|
dataMap.set("key13", "simple value"); |
70 |
1
|
dataMap.set("key14", "simple value"); |
71 |
1
|
dataMap.set("key15", "simple value"); |
72 |
1
|
dataMap.set("key16", "simple value"); |
73 |
1
|
dataMap.set("key17", "simple value"); |
74 |
1
|
dataMap.set("key18", "simple value"); |
75 |
1
|
dataMap.set("key19", "simple value"); |
76 |
1
|
dataMap.set("key20", "simple value"); |
77 |
|
|
78 |
1
|
dataList = new ArrayList<ExportElement>(); |
79 |
|
|
80 |
1
|
ExportElement element0 = new ExportElement(); |
81 |
1
|
element0.setFieldLabel("My label"); |
82 |
1
|
element0.setFieldValue("Proposal"); |
83 |
1
|
element0.setFieldValue2("Original Course"); |
84 |
1
|
dataList.add(element0); |
85 |
|
|
86 |
1
|
ExportElement element1 = new ExportElement(); |
87 |
1
|
element1.setFieldLabel("First label"); |
88 |
1
|
element1.setFieldValue("First value"); |
89 |
1
|
dataList.add(element1); |
90 |
|
|
91 |
1
|
ExportElement element2 = new ExportElement(); |
92 |
1
|
element2.setSectionName("Section 1"); |
93 |
1
|
element2.setFieldLabel("Second label"); |
94 |
1
|
element2.setFieldValue("Second value"); |
95 |
1
|
element2.setMandatory(true); |
96 |
1
|
dataList.add(element2); |
97 |
|
|
98 |
1
|
ExportElement element3 = new ExportElement(); |
99 |
1
|
element3.setSectionName("Section 1"); |
100 |
1
|
element3.setFieldLabel("Third label"); |
101 |
1
|
element3.setFieldValue("Third value"); |
102 |
1
|
element3.setFieldValue2("Third value O"); |
103 |
1
|
dataList.add(element3); |
104 |
|
|
105 |
1
|
List<ExportElement> subElements = new ArrayList<ExportElement>(); |
106 |
1
|
ExportElement subElement1 = new ExportElement(); |
107 |
1
|
subElement1.setSectionName("Subsection"); |
108 |
1
|
subElement1.setFieldLabel("First sublabel"); |
109 |
1
|
subElement1.setFieldValue("First subvalue"); |
110 |
1
|
subElement1.setFieldValue2("First subvalue O"); |
111 |
1
|
subElements.add(subElement1); |
112 |
|
|
113 |
1
|
ExportElement subElement2 = new ExportElement(); |
114 |
1
|
subElement1.setSectionName("Subsection"); |
115 |
1
|
subElement2.setFieldLabel("Second sublabel"); |
116 |
1
|
subElement2.setFieldValue("Second subvalue"); |
117 |
1
|
subElement2.setFieldValue2("Second subvalue"); |
118 |
1
|
subElements.add(subElement2); |
119 |
|
|
120 |
1
|
List<ExportElement> subsubElements = new ArrayList<ExportElement>(); |
121 |
1
|
ExportElement subsubElement1 = new ExportElement(); |
122 |
1
|
subsubElement1.setSectionName("Subsection"); |
123 |
1
|
subsubElement1.setFieldLabel("First sublabel"); |
124 |
1
|
subsubElement1.setFieldValue("First subvalue"); |
125 |
1
|
subsubElement1.setFieldValue2("First subvalue O"); |
126 |
1
|
subsubElements.add(subsubElement1); |
127 |
|
|
128 |
1
|
ExportElement subelement3 = new ExportElement(); |
129 |
1
|
subelement3.setSectionName("Subsection"); |
130 |
1
|
subelement3.setFieldLabel("Subsubset label"); |
131 |
1
|
subelement3.setSubset(subsubElements); |
132 |
1
|
subElements.add(subelement3); |
133 |
|
|
134 |
1
|
ExportElement element4 = new ExportElement(); |
135 |
1
|
element4.setSectionName("Section 1"); |
136 |
1
|
element4.setFieldLabel("Subset label"); |
137 |
1
|
element4.setSubset(subElements); |
138 |
1
|
dataList.add(element4); |
139 |
|
|
140 |
1
|
dataList.add(new ExportElement()); |
141 |
|
|
142 |
1
|
ExportElement element5 = new ExportElement(); |
143 |
1
|
element5.setSectionName("Section 2"); |
144 |
1
|
element5.setFieldLabel("5th label"); |
145 |
1
|
element5.setFieldValue("5th value"); |
146 |
1
|
element5.setFieldValue2("5th value"); |
147 |
1
|
dataList.add(element5); |
148 |
|
|
149 |
1
|
ExportElement element6 = new ExportElement(); |
150 |
1
|
element6.setSectionName("Section 2"); |
151 |
1
|
element6.setFieldLabel("6th label"); |
152 |
1
|
element6.setFieldValue("6th value"); |
153 |
1
|
element6.setFieldValue2("6th value"); |
154 |
1
|
element6.setMandatory(true); |
155 |
1
|
dataList.add(element6); |
156 |
|
|
157 |
|
} |
158 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (29) |
Complexity: 1 |
Complexity Density: 0.03 |
1
PASS
|
|
159 |
1
|
@Test... |
160 |
|
public void testScreenReport() { |
161 |
|
|
162 |
1
|
ScreenReportProcessor processor = new JasperScreenReportProcessorImpl(); |
163 |
|
|
164 |
1
|
byte[] bytes = processor.createPdf(dataMap, "base.template", "Course Information"); |
165 |
1
|
Assert.assertNotNull(bytes); |
166 |
1
|
printToFile(bytes, "c:\\dataMap.pdf"); |
167 |
1
|
Assert.assertTrue(bytes.length > 0); |
168 |
|
|
169 |
1
|
bytes = processor.createDoc(dataMap, "base.template", "Course Information"); |
170 |
1
|
Assert.assertNotNull(bytes); |
171 |
1
|
printToFile(bytes, "c:\\dataMap.doc"); |
172 |
1
|
Assert.assertTrue(bytes.length > 0); |
173 |
|
|
174 |
1
|
bytes = processor.createXls(dataMap, "base.template", "Course Information"); |
175 |
1
|
Assert.assertNotNull(bytes); |
176 |
1
|
printToFile(bytes, "c:\\dataMap.xls"); |
177 |
1
|
Assert.assertTrue(bytes.length > 0); |
178 |
|
|
179 |
1
|
bytes = processor.createPdf(dataList, "base.template", "Course Information"); |
180 |
1
|
Assert.assertNotNull(bytes); |
181 |
1
|
printToFile(bytes, "c:\\dataList.pdf"); |
182 |
1
|
Assert.assertTrue(bytes.length > 0); |
183 |
|
|
184 |
1
|
bytes = processor.createPdf(dataList, "proposal.template", "Course Information"); |
185 |
1
|
Assert.assertNotNull(bytes); |
186 |
1
|
printToFile(bytes, "c:\\dataList2.pdf"); |
187 |
1
|
Assert.assertTrue(bytes.length > 0); |
188 |
|
|
189 |
1
|
bytes = processor.createDoc(dataList, "base.template", "Course Information"); |
190 |
1
|
Assert.assertNotNull(bytes); |
191 |
1
|
printToFile(bytes, "c:\\dataList.doc"); |
192 |
1
|
Assert.assertTrue(bytes.length > 0); |
193 |
|
|
194 |
1
|
bytes = processor.createXls(dataList, "base.template", "Course Information"); |
195 |
1
|
Assert.assertNotNull(bytes); |
196 |
1
|
printToFile(bytes, "c:\\dataList.xls"); |
197 |
1
|
Assert.assertTrue(bytes.length > 0); |
198 |
|
|
199 |
|
} |
200 |
|
|
|
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 3 |
Complexity Density: 0.43 |
|
201 |
7
|
private void printToFile(byte[] bytes, String fileName) {... |
202 |
7
|
OutputStream out; |
203 |
7
|
try { |
204 |
7
|
out = new FileOutputStream(fileName); |
205 |
7
|
out.write(bytes); |
206 |
7
|
out.close(); |
207 |
|
} catch (FileNotFoundException e) { |
208 |
0
|
e.printStackTrace(); |
209 |
|
} catch (IOException e) { |
210 |
0
|
e.printStackTrace(); |
211 |
|
} |
212 |
|
} |
213 |
|
|
214 |
|
} |