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