001    /*
002     * Copyright 2011 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may      obtain a copy of the License at
007     *
008     *      http://www.osedu.org/licenses/ECL-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.student.contract.model.util;
017    
018    import org.kuali.student.contract.model.impl.ServiceContractModelPescXsdLoader;
019    import java.io.File;
020    import java.util.ArrayList;
021    import java.util.Collection;
022    import java.util.List;
023    import org.junit.After;
024    import org.junit.AfterClass;
025    import org.junit.Before;
026    import org.junit.BeforeClass;
027    import org.junit.Test;
028    import org.kuali.student.contract.model.ServiceContractModel;
029    import org.kuali.student.contract.model.impl.ServiceContractModelCache;
030    import org.kuali.student.contract.model.impl.ServiceContractModelQDoxLoader;
031    import org.kuali.student.contract.model.validation.ServiceContractModelValidator;
032    
033    
034    import static org.junit.Assert.*;
035    
036    /**
037     * 
038     * @author nwright
039     */
040    public class HtmlContractWriterTest {
041    
042        public HtmlContractWriterTest() {
043        }
044    
045        @BeforeClass
046        public static void setUpClass() throws Exception {
047        }
048    
049        @AfterClass
050        public static void tearDownClass() throws Exception {
051        }
052    
053        @Before
054        public void setUp() {
055        }
056    
057        @After
058        public void tearDown() {
059        }
060        private static final String CORE_DIRECTORY =
061                "C:/svn/ks-1.3/ks-core/ks-core-api/src/main/java";
062        // "C:/svn/maven-dictionary-generator/trunk/src/main/java/org/kuali/student/core";
063        private static final String COMMON_DIRECTORY =
064                "C:/svn/ks-1.3/ks-common/ks-common-api/src/main/java";
065        private static final String ENROLL_PROJECT_SOURCE_DIRECTORY =
066                "C:/svn/ks-1.3/ks-enroll/ks-enroll-api/src/main/java";
067        private static final String LUM_DIRECTORY =
068                "C:/svn/ks-1.3/ks-lum/ks-lum-api/src/main/java";
069        private static final String RICE_DIRECTORY =
070                "C:/svn/rice/rice-release-1-0-2-1-br/api/src/main/java";
071        private static final String RICE_CORE_API_DIRECTORY = "C:/svn/rice/trunk/core/api/src/main/java";
072        private static final String RICE_KIM_API_DIRECTORY = "C:/svn/rice/trunk/kim/kim-api/src/main/java";
073        private static final String RICE_LOCATION_API_DIRECTORY = "C:/svn/rice/trunk/location/api/src/main/java";
074        private static final String RICE_KEW_API_DIRECTORY = "C:/svn/rice/trunk/kew/api/src/main/java";
075        private static final String RICE_KEN_API_DIRECTORY = "C:/svn/rice/trunk/ken/api/src/main/java";
076        private static final String RICE_KSB_API_DIRECTORY = "C:/svn/rice/trunk/ksb/api/src/main/java";
077        private static final String RICE_KRMS_API_DIRECTORY = "C:/svn/rice/trunk/krms/api/src/main/java";
078        private static final String RICE_KRMS_IMPL_DIRECTORY = "C:/svn/rice/trunk/krms/impl/src/main/java";
079        private static final String TEST_SOURCE_DIRECTORY =
080                "src/test/java/org/kuali/student/contract/model/test/source";
081        private static final String HTML_CONTRACT_DIRECTORY = "target/html/contract";
082        private static final String HTML_CONTRACT_DIRECTORY_TEST = HTML_CONTRACT_DIRECTORY + "/test";    
083        private static final String HTML_CONTRACT_DIRECTORY_ENROLL = HTML_CONTRACT_DIRECTORY + "/enroll";         
084        private static final String HTML_CONTRACT_DIRECTORY_RICE = HTML_CONTRACT_DIRECTORY + "/rice";      
085        private static final String HTML_CONTRACT_DIRECTORY_PESC = HTML_CONTRACT_DIRECTORY + "/pesc";    
086        private static final String RESOURCES_DIRECTORY =
087                // "C:/svn/student/ks-core/ks-core-api/src/main/java";
088                "src/main/resources";
089    
090        private ServiceContractModel getTestModel() {
091            List<String> srcDirs = new ArrayList<String>();
092            srcDirs.add(TEST_SOURCE_DIRECTORY);
093    //              srcDirs.add(ENROLL_PROJECT_SOURCE_DIRECTORY);
094    //              srcDirs.add(CORE_DIRECTORY);
095    //              srcDirs.add(COMMON_DIRECTORY);
096    //              srcDirs.add(LUM_DIRECTORY);
097            ServiceContractModel instance = new ServiceContractModelQDoxLoader(
098                    srcDirs);
099            return new ServiceContractModelCache(instance);
100    
101        }
102        
103        private ServiceContractModel getRiceModel() {
104            List<String> srcDirs = new ArrayList<String>();
105    //        srcDirs.add(TEST_SOURCE_DIRECTORY);
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    //              srcDirs.add(CORE_DIRECTORY);
115    //              srcDirs.add(COMMON_DIRECTORY);
116    //              srcDirs.add(LUM_DIRECTORY);
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    //        srcDirs.add(TEST_SOURCE_DIRECTORY);
126                    srcDirs.add(ENROLL_PROJECT_SOURCE_DIRECTORY);
127    //              srcDirs.add(CORE_DIRECTORY);
128    //              srcDirs.add(COMMON_DIRECTORY);
129    //              srcDirs.add(LUM_DIRECTORY);
130            ServiceContractModel instance = new ServiceContractModelQDoxLoader(
131                    srcDirs);
132            return new ServiceContractModelCache(instance);
133    
134        }
135        // pesc stuff
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    //        xsdFileNames.add(PESC_CORE_MAIN);
145    //        xsdFileNames.add(PESC_ACAD_REC);
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         * Test of run
173         */
174    //    @Test
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         * Test of run
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         * Test of run
219         */
220    //    @Test
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    //        assertTrue(new File(HTML_CONTRACT_DIRECTORY_ENROLL + "/" + "index.html").exists());
231        }
232        
233        /**
234         * Test of run
235         */
236    //    @Test
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    //        assertTrue(new File(HTML_CONTRACT_DIRECTORY_ENROLL + "/" + "index.html").exists());
247        }
248    }