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