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.sampleu.common;
17  
18  import org.junit.Assert;
19  import org.junit.Test;
20  import org.kuali.rice.testtools.common.PropertiesUtils;
21  
22  import java.io.File;
23  import java.util.Properties;
24  
25  /**
26   * TODO Setup as command line tool or implement gold standard/acceptance testing for the templated result.
27   * @author Kuali Rice Team (rice.collab@kuali.org)
28   */
29  public class NeustarJavaScriptTemplate extends FreemarkerAftBase {
30  
31      @Override
32      protected String getBookmarkUrl() {
33          return null;
34      }
35  
36      // File generation
37      private String PROPS_LOCATION = System.getProperty("neustarJS.props.location", null);
38      private String DEFAULT_PROPS_LOCATION = "NeustarJSTemplate/neustarJS.properties";
39  
40      // Templates for File Generation
41      private static final String DIR_TMPL = "/NeustarJSTemplate/";
42      private static final String TMPL_CONTENT = "CreateNewTmpl.ftl";
43  
44      private void buildFileList(Properties props) throws Exception {
45          Integer pageCount= Integer.parseInt(props.getProperty("pageCount"));
46          
47          for(int count=1; count<= pageCount;count++ ){
48              try {
49                  String subTitle= props.getProperty("page"+count);
50                  props.setProperty("pageId",""+ props.get("page")+count);
51                  
52                  // Setting props and building files of KRAD tab
53                  props.setProperty("viewId",""+ props.get("view"));                          
54                  File f1= new File("Temp" + File.separatorChar + "Env11 Kitchen Sink "+subTitle +" KRAD WebDriver.txt");
55                  writeTemplateToFile(f1, cfg.getTemplate(TMPL_CONTENT), props);
56  
57                  // Setting props and building files of KRAD tab
58                  props.setProperty("viewId",""+ props.get("view"));
59                  File f2= new File("Temp" + File.separatorChar + "Env11 Kitchen Sink "+subTitle +" KNS WebDriver.txt");
60                  writeTemplateToFile(f2, cfg.getTemplate(TMPL_CONTENT), props);
61  
62              } catch( Exception e) {
63                  throw new Exception("Unable to generate files for upload", e);
64              }
65          }
66      }
67  
68      /**
69       * {@inheritDoc}
70       * {@link #DIR_TMPL}
71       * @return
72       */
73      @Override
74      protected String getTemplateDir() {
75          return DIR_TMPL;
76      }
77  
78      @Test
79      public void testNeustarTemplating() throws Exception {
80          // update properties with timestamp value if includeDTSinPrefix is true
81          Properties props = loadProperties(PROPS_LOCATION, DEFAULT_PROPS_LOCATION);
82          props = new PropertiesUtils().systemPropertiesOverride(props, "NeustarJS");
83          //Generate Files
84          buildFileList(props);
85          // TODO gold standard or acceptance testing on generated file.
86      }
87  }