1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.contract.model.util;
17
18 import static org.junit.Assert.assertTrue;
19 import static org.junit.Assert.fail;
20
21 import java.io.File;
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.Date;
25 import java.util.List;
26
27 import org.joda.time.DateTime;
28 import org.junit.After;
29 import org.junit.AfterClass;
30 import org.junit.Before;
31 import org.junit.BeforeClass;
32 import org.junit.Ignore;
33 import org.junit.Test;
34 import org.kuali.student.contract.model.ServiceContractModel;
35 import org.kuali.student.contract.model.impl.ServiceContractModelCache;
36 import org.kuali.student.contract.model.impl.ServiceContractModelPescXsdLoader;
37 import org.kuali.student.contract.model.impl.ServiceContractModelQDoxLoader;
38 import org.kuali.student.contract.model.validation.ServiceContractModelValidator;
39
40
41
42
43
44 public class HtmlContractWriterTest {
45
46 public HtmlContractWriterTest() {
47 }
48
49 @BeforeClass
50 public static void setUpClass() throws Exception {
51 }
52
53 @AfterClass
54 public static void tearDownClass() throws Exception {
55 }
56
57 @Before
58 public void setUp() {
59 }
60
61 @After
62 public void tearDown() {
63 }
64 private static final String CORE_DIRECTORY =
65 "C:/svn/ks-1.3/ks-core/ks-core-api/src/main/java";
66
67 private static final String COMMON_DIRECTORY =
68 "C:/svn/ks-1.3/ks-common/ks-common-api/src/main/java";
69 private static final String ENROLL_PROJECT_SOURCE_DIRECTORY =
70 "C:/svn/ks-1.3/ks-enroll/ks-enroll-api/src/main/java";
71 private static final String LUM_DIRECTORY =
72 "C:/svn/ks-1.3/ks-lum/ks-lum-api/src/main/java";
73 private static final String RICE_DIRECTORY =
74 "C:/svn/rice/rice-release-1-0-2-1-br/api/src/main/java";
75 private static final String RICE_CORE_API_DIRECTORY = "C:/svn/rice/trunk/core/api/src/main/java";
76 private static final String RICE_KIM_API_DIRECTORY = "C:/svn/rice/trunk/kim/kim-api/src/main/java";
77 private static final String RICE_LOCATION_API_DIRECTORY = "C:/svn/rice/trunk/location/api/src/main/java";
78 private static final String RICE_KEW_API_DIRECTORY = "C:/svn/rice/trunk/kew/api/src/main/java";
79 private static final String RICE_KEN_API_DIRECTORY = "C:/svn/rice/trunk/ken/api/src/main/java";
80 private static final String RICE_KSB_API_DIRECTORY = "C:/svn/rice/trunk/ksb/api/src/main/java";
81 private static final String RICE_KRMS_API_DIRECTORY = "C:/svn/rice/trunk/krms/api/src/main/java";
82 private static final String RICE_KRMS_IMPL_DIRECTORY = "C:/svn/rice/trunk/krms/impl/src/main/java";
83 private static final String TEST_SOURCE_DIRECTORY =
84 "src/test/java/org/kuali/student/contract/model/test/source";
85
86 private static final String KSA_DIRECTORY = "D:/svn/ks/ksa/ksa-core/src/main/java";
87 private static final String HTML_CONTRACT_DIRECTORY = "target/html/contract";
88 private static final String HTML_CONTRACT_DIRECTORY_TEST = HTML_CONTRACT_DIRECTORY + "/test";
89 private static final String HTML_CONTRACT_DIRECTORY_ENROLL = HTML_CONTRACT_DIRECTORY + "/enroll";
90 private static final String HTML_CONTRACT_DIRECTORY_RICE = HTML_CONTRACT_DIRECTORY + "/rice";
91 private static final String HTML_CONTRACT_DIRECTORY_KSA = HTML_CONTRACT_DIRECTORY + "/ksa";
92 private static final String HTML_CONTRACT_DIRECTORY_PESC = HTML_CONTRACT_DIRECTORY + "/pesc";
93 private static final String RESOURCES_DIRECTORY =
94
95 "src/main/resources";
96
97 private ServiceContractModel getTestModel() {
98 List<String> srcDirs = new ArrayList<String>();
99 srcDirs.add(TEST_SOURCE_DIRECTORY);
100
101
102
103
104 ServiceContractModel instance = new ServiceContractModelQDoxLoader(
105 srcDirs);
106 return new ServiceContractModelCache(instance);
107
108 }
109
110
111 private ServiceContractModel getRiceModel() {
112 List<String> srcDirs = new ArrayList<String>();
113
114 srcDirs.add(RICE_CORE_API_DIRECTORY);
115 srcDirs.add(RICE_KIM_API_DIRECTORY);
116 srcDirs.add(RICE_LOCATION_API_DIRECTORY);
117 srcDirs.add(RICE_KEW_API_DIRECTORY);
118 srcDirs.add(RICE_KEN_API_DIRECTORY);
119 srcDirs.add(RICE_KSB_API_DIRECTORY);
120 srcDirs.add(RICE_KRMS_API_DIRECTORY);
121 srcDirs.add(RICE_KRMS_IMPL_DIRECTORY);
122
123
124
125 ServiceContractModel instance = new ServiceContractModelQDoxLoader(
126 srcDirs);
127 return new ServiceContractModelCache(instance);
128
129 }
130
131 private ServiceContractModel getKSAModel() {
132 List<String> srcDirs = new ArrayList<String>();
133 srcDirs.add(KSA_DIRECTORY);
134 ServiceContractModel instance = new ServiceContractModelQDoxLoader(
135 srcDirs);
136 return new ServiceContractModelCache(instance);
137
138 }
139
140 private ServiceContractModel getEnrollModel() {
141 List<String> srcDirs = new ArrayList<String>();
142
143 srcDirs.add(ENROLL_PROJECT_SOURCE_DIRECTORY);
144
145
146
147 ServiceContractModel instance = new ServiceContractModelQDoxLoader(
148 srcDirs);
149 return new ServiceContractModelCache(instance);
150
151 }
152
153 private static final String PESC_DIRECTORY =
154 RESOURCES_DIRECTORY + "/pesc";
155 private static final String PESC_CORE_MAIN = PESC_DIRECTORY + "/CoreMain.xsd";
156 private static final String PESC_ACAD_REC = PESC_DIRECTORY + "/AcademicRecord_v1.5.0.xsd";
157 private static final String PESC_COLL_TRANS = PESC_DIRECTORY + "/CollegeTranscript_v1.2.0.xsd";
158
159 private ServiceContractModel getPescModel() {
160 List<String> xsdFileNames = new ArrayList();
161
162
163 xsdFileNames.add(PESC_COLL_TRANS);
164 ServiceContractModel instance = new ServiceContractModelPescXsdLoader(xsdFileNames);
165 instance = new ServiceContractModelCache(instance);
166 validate(instance);
167 return instance;
168 }
169
170
171 private void validate(ServiceContractModel model) {
172 Collection<String> errors =
173 new ServiceContractModelValidator(model).validate();
174 if (errors.size() > 0) {
175 StringBuilder buf = new StringBuilder();
176 buf.append(errors.size()).append(" errors found while validating the data.");
177 int cnt = 0;
178 for (String msg : errors) {
179 cnt++;
180 buf.append("\n");
181 buf.append("*error*").append(cnt).append(":").append(msg);
182 }
183
184 fail(buf.toString());
185 }
186 }
187
188
189
190
191
192 public void testRunPesc() {
193 ServiceContractModel model = null;
194 HtmlContractWriter writer = null;
195
196 model = this.getPescModel();
197 this.validate(model);
198 writer = new HtmlContractWriter(HTML_CONTRACT_DIRECTORY_PESC, model);
199 writer.write("testVersion", DateUtility.asYMD(new Date()));
200
201 assertTrue(new File(HTML_CONTRACT_DIRECTORY_PESC + "/" + "index.html").exists());
202 }
203
204
205
206
207 @Test
208 public void testTestRun () {
209 ServiceContractModel model = null;
210 HtmlContractWriter writer = null;
211
212 model = this.getTestModel();
213 this.validate(model);
214 writer = new HtmlContractWriter(HTML_CONTRACT_DIRECTORY_TEST, model);
215 writer.write("testVersion", DateUtility.asYMD(new Date()));
216
217 assertTrue(new File(HTML_CONTRACT_DIRECTORY_TEST + "/" + "index.html").exists());
218 assertTrue(
219 new File(HTML_CONTRACT_DIRECTORY_TEST + "/" + "LprService.html").exists());
220 assertTrue(
221 new File(HTML_CONTRACT_DIRECTORY_TEST + "/" + "LprInfo.html").exists());
222 assertTrue(new File(HTML_CONTRACT_DIRECTORY_TEST + "/" + "ContextInfo.html").exists());
223 assertTrue(new File(HTML_CONTRACT_DIRECTORY_TEST + "/" + "RichTextInfo.html").exists());
224 assertTrue(new File(HTML_CONTRACT_DIRECTORY_TEST + "/" + "MetaInfo.html").exists());
225
226 assertTrue(new File(HTML_CONTRACT_DIRECTORY_TEST + "/" + "StateService.html").exists());
227 assertTrue(new File(HTML_CONTRACT_DIRECTORY_TEST + "/" + "StateInfo.html").exists());
228
229 assertTrue(new File(HTML_CONTRACT_DIRECTORY_TEST + "/" + "TypeService.html").exists());
230 assertTrue(new File(HTML_CONTRACT_DIRECTORY_TEST + "/" + "TypeInfo.html").exists());
231 }
232
233
234
235
236
237
238 public void testEnrollRun () {
239 ServiceContractModel model = null;
240 HtmlContractWriter writer = null;
241
242 model = this.getEnrollModel();
243 this.validate(model);
244 writer = new HtmlContractWriter(HTML_CONTRACT_DIRECTORY_ENROLL, model);
245 writer.write("testVersion", DateUtility.asYMDHMInEasternTimeZone(new DateTime()));
246
247
248 }
249
250
251
252
253
254 public void testRiceRun () {
255 ServiceContractModel model = null;
256 HtmlContractWriter writer = null;
257
258 model = this.getRiceModel();
259 this.validate(model);
260 writer = new HtmlContractWriter(HTML_CONTRACT_DIRECTORY_RICE, model);
261 writer.write("testVersion", DateUtility.asYMD(new Date()));
262
263
264 }
265
266
267
268 @Test
269 @Ignore
270
271
272 public void testKSARun () {
273 ServiceContractModel model = null;
274 HtmlContractWriter writer = null;
275
276 model = this.getKSAModel();
277 this.validate(model);
278 writer = new HtmlContractWriter(HTML_CONTRACT_DIRECTORY_KSA, model);
279 writer.write("testVersion", DateUtility.asYMD(new Date()));
280
281
282 }
283 }