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