View Javadoc

1   /*
2    * Copyright 2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may	obtain a copy of the License at
7    *
8    * 	http://www.osedu.org/licenses/ECL-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * @author nwright
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      // "C:/svn/maven-dictionary-generator/trunk/src/main/java/org/kuali/student/core";
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              // "C:/svn/student/ks-core/ks-core-api/src/main/java";
95              "src/main/resources";
96  
97      private ServiceContractModel getTestModel() {
98          List<String> srcDirs = new ArrayList<String>();
99          srcDirs.add(TEST_SOURCE_DIRECTORY);
100 //		srcDirs.add(ENROLL_PROJECT_SOURCE_DIRECTORY);
101 //		srcDirs.add(CORE_DIRECTORY);
102 //		srcDirs.add(COMMON_DIRECTORY);
103 //		srcDirs.add(LUM_DIRECTORY);
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 //        srcDirs.add(TEST_SOURCE_DIRECTORY);
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 //		srcDirs.add(CORE_DIRECTORY);
123 //		srcDirs.add(COMMON_DIRECTORY);
124 //		srcDirs.add(LUM_DIRECTORY);
125         ServiceContractModel instance = new ServiceContractModelQDoxLoader(
126                 srcDirs, false);
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, false);
136         return new ServiceContractModelCache(instance);
137 
138     }    
139     
140     private ServiceContractModel getEnrollModel() {
141         List<String> srcDirs = new ArrayList<String>();
142 //        srcDirs.add(TEST_SOURCE_DIRECTORY);
143 		srcDirs.add(ENROLL_PROJECT_SOURCE_DIRECTORY);
144 //		srcDirs.add(CORE_DIRECTORY);
145 //		srcDirs.add(COMMON_DIRECTORY);
146 //		srcDirs.add(LUM_DIRECTORY);
147         ServiceContractModel instance = new ServiceContractModelQDoxLoader(
148                 srcDirs);
149         return new ServiceContractModelCache(instance);
150 
151     }
152     // pesc stuff
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 //        xsdFileNames.add(PESC_CORE_MAIN);
162 //        xsdFileNames.add(PESC_ACAD_REC);
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      * Test of run
190      */
191 //    @Test
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      * Test of run
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      * Test of run
236      */
237 //    @Test
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 //        assertTrue(new File(HTML_CONTRACT_DIRECTORY_ENROLL + "/" + "index.html").exists());
248     }
249     
250     /**
251      * Test of run
252      */
253 //    @Test
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 //        assertTrue(new File(HTML_CONTRACT_DIRECTORY_ENROLL + "/" + "index.html").exists());
264     }
265     /**
266      * Test of run
267      */
268     @Test
269     @Ignore 
270     // Ignored because the ksa api is not known to the test.
271     // investigate if the api can be provisioned through maven.
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 //        assertTrue(new File(HTML_CONTRACT_DIRECTORY_ENROLL + "/" + "index.html").exists());
282     }
283 }