001/**
002 * Copyright 2005-2016 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 */
016package edu.sampleu.common;
017
018import org.junit.Assert;
019import org.junit.Test;
020import org.kuali.rice.testtools.common.PropertiesUtils;
021
022import java.io.File;
023import java.util.Properties;
024
025/**
026 * TODO Setup as command line tool or implement gold standard/acceptance testing for the templated result.
027 * @author Kuali Rice Team (rice.collab@kuali.org)
028 */
029public class NeustarJavaScriptTemplate extends FreemarkerAftBase {
030
031    @Override
032    protected String getBookmarkUrl() {
033        return null;
034    }
035
036    // File generation
037    private String PROPS_LOCATION = System.getProperty("neustarJS.props.location", null);
038    private String DEFAULT_PROPS_LOCATION = "NeustarJSTemplate/neustarJS.properties";
039
040    // Templates for File Generation
041    private static final String DIR_TMPL = "/NeustarJSTemplate/";
042    private static final String TMPL_CONTENT = "CreateNewTmpl.ftl";
043
044    private void buildFileList(Properties props) throws Exception {
045        Integer pageCount= Integer.parseInt(props.getProperty("pageCount"));
046        
047        for(int count=1; count<= pageCount;count++ ){
048            try {
049                String subTitle= props.getProperty("page"+count);
050                props.setProperty("pageId",""+ props.get("page")+count);
051                
052                // Setting props and building files of KRAD tab
053                props.setProperty("viewId",""+ props.get("view"));                          
054                File f1= new File("Temp" + File.separatorChar + "Env11 Kitchen Sink "+subTitle +" KRAD WebDriver.txt");
055                writeTemplateToFile(f1, cfg.getTemplate(TMPL_CONTENT), props);
056
057                // Setting props and building files of KRAD tab
058                props.setProperty("viewId",""+ props.get("view"));
059                File f2= new File("Temp" + File.separatorChar + "Env11 Kitchen Sink "+subTitle +" KNS WebDriver.txt");
060                writeTemplateToFile(f2, cfg.getTemplate(TMPL_CONTENT), props);
061
062            } catch( Exception e) {
063                throw new Exception("Unable to generate files for upload", e);
064            }
065        }
066    }
067
068    /**
069     * {@inheritDoc}
070     * {@link #DIR_TMPL}
071     * @return
072     */
073    @Override
074    protected String getTemplateDir() {
075        return DIR_TMPL;
076    }
077
078    @Test
079    public void testNeustarTemplating() throws Exception {
080        // update properties with timestamp value if includeDTSinPrefix is true
081        Properties props = loadProperties(PROPS_LOCATION, DEFAULT_PROPS_LOCATION);
082        props = new PropertiesUtils().systemPropertiesOverride(props, "NeustarJS");
083        //Generate Files
084        buildFileList(props);
085        // TODO gold standard or acceptance testing on generated file.
086    }
087}