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 java.io.File;
19  import java.util.ArrayList;
20  import java.util.Collection;
21  import java.util.List;
22  import org.junit.After;
23  import org.junit.AfterClass;
24  import org.junit.Before;
25  import org.junit.BeforeClass;
26  import org.junit.Test;
27  import org.kuali.student.contract.model.ServiceContractModel;
28  import org.kuali.student.contract.model.impl.ServiceContractModelCache;
29  import org.kuali.student.contract.model.impl.ServiceContractModelQDoxLoader;
30  import org.kuali.student.contract.model.validation.ServiceContractModelValidator;
31  
32  
33  import static org.junit.Assert.*;
34  
35  /**
36   * 
37   * @author nwright
38   */
39  public class XmlKradBaseDictionaryCreatorTest {
40  
41      public XmlKradBaseDictionaryCreatorTest() {
42      }
43  
44      @BeforeClass
45      public static void setUpClass() throws Exception {
46      }
47  
48      @AfterClass
49      public static void tearDownClass() throws Exception {
50      }
51  
52      @Before
53      public void setUp() {
54      }
55  
56      @After
57      public void tearDown() {
58      }
59      private static final String CORE_DIRECTORY =
60              "C:/svn/ks-1.3/ks-core/ks-core-api/src/main/java";
61      // "C:/svn/maven-dictionary-generator/trunk/src/main/java/org/kuali/student/core";
62      private static final String COMMON_DIRECTORY =
63              "C:/svn/ks-1.3/ks-common/ks-common-api/src/main/java";
64      private static final String ENROLL_DIRECTORY =
65              "C:/svn/ks-1.3/ks-enroll/ks-enroll-api/src/main/java";
66      private static final String LUM_DIRECTORY =
67              "C:/svn/ks-1.3/ks-lum/ks-lum-api/src/main/java";
68      private static final String RICE_DIRECTORY =
69              "C:/svn/rice/rice-release-1-0-2-1-br/api/src/main/java";
70      private static final String TEST_SOURCE_DIRECTORY =
71              "src/test/java/org/kuali/student/contract/model/test/source";
72      private static final String XML_DICTIONARY_DIRECTORY = "target/xml/dictionary";
73      private static final String RESOURCES_DIRECTORY =
74              // "C:/svn/student/ks-core/ks-core-api/src/main/java";
75              "src/main/resources";
76      private static final String PESC_CORE_MAIN = RESOURCES_DIRECTORY
77              + "/CoreMain_v1.8.0.xsd";
78  
79      private ServiceContractModel getModel() {
80          List<String> srcDirs = new ArrayList<String>();
81  //        srcDirs.add(TEST_SOURCE_DIRECTORY);
82          srcDirs.add(ENROLL_DIRECTORY);
83  //		srcDirs.add(CORE_DIRECTORY);
84  //		srcDirs.add(COMMON_DIRECTORY);
85  //		srcDirs.add(LUM_DIRECTORY);
86          ServiceContractModel instance = new ServiceContractModelQDoxLoader(
87                  srcDirs);
88          return new ServiceContractModelCache(instance);
89  
90      }
91  
92      private void validate(ServiceContractModel model) {
93          Collection<String> errors =
94                  new ServiceContractModelValidator(model).validate();
95          if (errors.size() > 0) {
96              StringBuilder buf = new StringBuilder();
97              buf.append(errors.size()
98                      + " errors found while validating the data.");
99              int cnt = 0;
100             for (String msg : errors) {
101                 cnt++;
102                 buf.append("\n");
103                 buf.append("*error*" + cnt + ":" + msg);
104             }
105 
106             fail(buf.toString());
107         }
108     }
109 
110     /**
111      * Test of run
112      */
113     @Test
114     public void testRun() {
115         ServiceContractModel model = null;
116         XmlKradBaseDictionaryCreator writer = null;
117 
118         model = this.getModel();
119         this.validate(model);
120         String xmlObject = null;
121 
122         xmlObject = "atpInfo";
123         writer = new XmlKradBaseDictionaryCreator(XML_DICTIONARY_DIRECTORY, model, xmlObject);
124         writer.write();
125         assertTrue(new File(XML_DICTIONARY_DIRECTORY + "/" + "ks-" + xmlObject + "-dictionary.xml").exists());
126 
127         xmlObject = "atpInfo";
128         writer = new XmlKradBaseDictionaryCreator(XML_DICTIONARY_DIRECTORY, model, xmlObject);
129         writer.write();
130         assertTrue(new File(XML_DICTIONARY_DIRECTORY + "/" + "ks-" + xmlObject + "-dictionary.xml").exists());
131 
132     }
133 }