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