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