001 /**
002 * Copyright 2005-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package edu.samplu.common;
017
018 import java.io.File;
019 import java.util.Properties;
020
021 import org.junit.Test;
022
023 import freemarker.cache.ClassTemplateLoader;
024 import freemarker.template.Configuration;
025
026 /**
027 * TODO Setup as command line tool or implement gold standard/acceptance testing for the templated result.
028 * @author Kuali Rice Team (rice.collab@kuali.org)
029 */
030 public class NeustarJSTemplate extends FreemarkerSTBase {
031
032 /**
033 * This is ugly, I'm doing it to remove the loading property duplication, we should probably turn this class into a
034 * command line tool and do extractions to support that, but isn't the current focus...
035 * @return
036 */
037 @Override
038 public String getTestUrl() {
039 return null;
040 }
041
042 // File generation
043 private String PROPS_LOCATION = System.getProperty("neustarJS.props.location", null);
044 private String DEFAULT_PROPS_LOCATION = "NeustarJSTemplate/neustarJS.properties";
045
046 // Templates for File Generation
047 private static final String DIR_TMPL = "/NeustarJSTemplate/";
048 private static final String TMPL_CONTENT = "CreateNewTmpl.ftl";
049
050
051 @Override
052 public void setUp() throws Exception {
053 super.setUp();
054 // generated load users and group resources
055 cfg = new Configuration();
056 cfg.setTemplateLoader(new ClassTemplateLoader(getClass().getClassLoader().getClass(), DIR_TMPL));
057 }
058
059 private void buildFileList(Properties props) throws Exception {
060 Integer pageCount= Integer.parseInt(props.getProperty("pageCount"));
061
062 for(int count=1; count<= pageCount;count++ ){
063 try {
064 String subTitle= props.getProperty("page"+count);
065 props.setProperty("pageId",""+ props.get("page")+count);
066
067 // Setting props and building files of KRAD tab
068 props.setProperty("viewId",""+ props.get("view"));
069 File f1= new File("Temp" + File.separatorChar + "Env11 Kitchen Sink "+subTitle +" KRAD WebDriver.txt");
070 writeTemplateToFile(f1, cfg.getTemplate(TMPL_CONTENT), props);
071
072 // Setting props and building files of KRAD tab
073 props.setProperty("viewId",""+ props.get("view")+"_KNS");
074 File f2= new File("Temp" + File.separatorChar + "Env11 Kitchen Sink "+subTitle +" KNS WebDriver.txt");
075 writeTemplateToFile(f2, cfg.getTemplate(TMPL_CONTENT), props);
076
077 } catch( Exception e) {
078 throw new Exception("Unable to generate files for upload", e);
079 }
080 }
081 }
082
083 @Test
084 public void testNeustarTemplating() throws Exception {
085 // update properties with timestamp value if includeDTSinPrefix is true
086 Properties props = loadProperties(PROPS_LOCATION, DEFAULT_PROPS_LOCATION);
087 systemPropertiesOverride(props, "NeustarJS");
088 //Generate Files
089 buildFileList(props);
090 // TODO gold standard or acceptance testing on generated file.
091 }
092 }