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 private void buildFileList(Properties props) throws Exception { 051 Integer pageCount= Integer.parseInt(props.getProperty("pageCount")); 052 053 for(int count=1; count<= pageCount;count++ ){ 054 try { 055 String subTitle= props.getProperty("page"+count); 056 props.setProperty("pageId",""+ props.get("page")+count); 057 058 // Setting props and building files of KRAD tab 059 props.setProperty("viewId",""+ props.get("view")); 060 File f1= new File("Temp" + File.separatorChar + "Env11 Kitchen Sink "+subTitle +" KRAD WebDriver.txt"); 061 writeTemplateToFile(f1, cfg.getTemplate(TMPL_CONTENT), props); 062 063 // Setting props and building files of KRAD tab 064 props.setProperty("viewId",""+ props.get("view")+"_KNS"); 065 File f2= new File("Temp" + File.separatorChar + "Env11 Kitchen Sink "+subTitle +" KNS WebDriver.txt"); 066 writeTemplateToFile(f2, cfg.getTemplate(TMPL_CONTENT), props); 067 068 } catch( Exception e) { 069 throw new Exception("Unable to generate files for upload", e); 070 } 071 } 072 } 073 074 /** 075 * {@inheritDoc} 076 * {@link #DIR_TMPL} 077 * @return 078 */ 079 @Override 080 protected String getTemplateDir() { 081 return DIR_TMPL; 082 } 083 084 @Test 085 public void testNeustarTemplating() throws Exception { 086 // update properties with timestamp value if includeDTSinPrefix is true 087 Properties props = loadProperties(PROPS_LOCATION, DEFAULT_PROPS_LOCATION); 088 systemPropertiesOverride(props, "NeustarJS"); 089 //Generate Files 090 buildFileList(props); 091 // TODO gold standard or acceptance testing on generated file. 092 } 093 }