View Javadoc

1   /**
2    * Copyright 2005-2013 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.opensource.org/licenses/ecl2.php
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 edu.samplu.common;
17  
18  import java.io.File;
19  import java.util.Properties;
20  
21  import org.junit.Test;
22  
23  import freemarker.cache.ClassTemplateLoader;
24  import freemarker.template.Configuration;
25  
26  /**
27   * TODO Setup as command line tool or implement gold standard/acceptance testing for the templated result.
28   * @author Kuali Rice Team (rice.collab@kuali.org)
29   */
30  public class NeustarJSTemplate extends FreemarkerSTBase {
31  
32      /**
33       * This is ugly, I'm doing it to remove the loading property duplication, we should probably turn this class into a
34       * command line tool and do extractions to support that, but isn't the current focus...
35       * @return
36       */
37      @Override
38      public String getTestUrl() {
39          return null;
40      }
41  
42      // File generation
43      private String PROPS_LOCATION = System.getProperty("neustarJS.props.location", null);
44      private String DEFAULT_PROPS_LOCATION = "NeustarJSTemplate/neustarJS.properties";
45  
46      // Templates for File Generation
47      private static final String DIR_TMPL = "/NeustarJSTemplate/";
48      private static final String TMPL_CONTENT = "CreateNewTmpl.ftl";
49  
50  
51      @Override
52      public void setUp() throws Exception {
53          super.setUp();
54          // generated load users and group resources
55          cfg = new Configuration();
56          cfg.setTemplateLoader(new ClassTemplateLoader(getClass().getClassLoader().getClass(), DIR_TMPL));
57      }
58  
59      private void buildFileList(Properties props) throws Exception {
60          Integer pageCount= Integer.parseInt(props.getProperty("pageCount"));
61          
62          for(int count=1; count<= pageCount;count++ ){
63              try {
64                  String subTitle= props.getProperty("page"+count);
65                  props.setProperty("pageId",""+ props.get("page")+count);
66                  
67                  // Setting props and building files of KRAD tab
68                  props.setProperty("viewId",""+ props.get("view"));                          
69                  File f1= new File("Temp" + File.separatorChar + "Env11 Kitchen Sink "+subTitle +" KRAD WebDriver.txt");
70                  writeTemplateToFile(f1, cfg.getTemplate(TMPL_CONTENT), props);
71  
72                  // Setting props and building files of KRAD tab
73                  props.setProperty("viewId",""+ props.get("view")+"_KNS");
74                  File f2= new File("Temp" + File.separatorChar + "Env11 Kitchen Sink "+subTitle +" KNS WebDriver.txt");
75                  writeTemplateToFile(f2, cfg.getTemplate(TMPL_CONTENT), props);
76  
77              } catch( Exception e) {
78                  throw new Exception("Unable to generate files for upload", e);
79              }
80          }
81      }
82  
83      @Test
84      public void testNeustarTemplating() throws Exception {
85          // update properties with timestamp value if includeDTSinPrefix is true
86          Properties props = loadProperties(PROPS_LOCATION, DEFAULT_PROPS_LOCATION);
87          systemPropertiesOverride(props, "NeustarJS");
88          //Generate Files
89          buildFileList(props);
90          // TODO gold standard or acceptance testing on generated file.
91      }
92  }