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.Assert; 022 import org.junit.Test; 023 024 /** 025 * TODO Setup as command line tool or implement gold standard/acceptance testing for the templated result. 026 * @author Kuali Rice Team (rice.collab@kuali.org) 027 */ 028 public class NeustarJSTemplate extends FreemarkerSTBase { 029 030 @Override 031 public void fail(String message) { 032 Assert.fail(message); 033 } 034 035 /** 036 * This is ugly, I'm doing it to remove the loading property duplication, we should probably turn this class into a 037 * command line tool and do extractions to support that, but isn't the current focus... 038 * @return 039 */ 040 @Override 041 public String getTestUrl() { 042 return null; 043 } 044 045 // File generation 046 private String PROPS_LOCATION = System.getProperty("neustarJS.props.location", null); 047 private String DEFAULT_PROPS_LOCATION = "NeustarJSTemplate/neustarJS.properties"; 048 049 // Templates for File Generation 050 private static final String DIR_TMPL = "/NeustarJSTemplate/"; 051 private static final String TMPL_CONTENT = "CreateNewTmpl.ftl"; 052 053 private void buildFileList(Properties props) throws Exception { 054 Integer pageCount= Integer.parseInt(props.getProperty("pageCount")); 055 056 for(int count=1; count<= pageCount;count++ ){ 057 try { 058 String subTitle= props.getProperty("page"+count); 059 props.setProperty("pageId",""+ props.get("page")+count); 060 061 // Setting props and building files of KRAD tab 062 props.setProperty("viewId",""+ props.get("view")); 063 File f1= new File("Temp" + File.separatorChar + "Env11 Kitchen Sink "+subTitle +" KRAD WebDriver.txt"); 064 writeTemplateToFile(f1, cfg.getTemplate(TMPL_CONTENT), props); 065 066 // Setting props and building files of KRAD tab 067 props.setProperty("viewId",""+ props.get("view")); 068 File f2= new File("Temp" + File.separatorChar + "Env11 Kitchen Sink "+subTitle +" KNS WebDriver.txt"); 069 writeTemplateToFile(f2, cfg.getTemplate(TMPL_CONTENT), props); 070 071 } catch( Exception e) { 072 throw new Exception("Unable to generate files for upload", e); 073 } 074 } 075 } 076 077 /** 078 * {@inheritDoc} 079 * {@link #DIR_TMPL} 080 * @return 081 */ 082 @Override 083 protected String getTemplateDir() { 084 return DIR_TMPL; 085 } 086 087 @Test 088 public void testNeustarTemplating() throws Exception { 089 // update properties with timestamp value if includeDTSinPrefix is true 090 Properties props = loadProperties(PROPS_LOCATION, DEFAULT_PROPS_LOCATION); 091 PropertiesUtils.systemPropertiesOverride(props, "NeustarJS"); 092 //Generate Files 093 buildFileList(props); 094 // TODO gold standard or acceptance testing on generated file. 095 } 096 }