/*
* Name: GeneratorTest
* Authors: Richard Rodger
*
* Copyright (c) 2003-2006 Richard Rodger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
// package
package org.jostraca.test;
// import
import org.jostraca.Generator;
import org.jostraca.Property;
import org.jostraca.Template;
import org.jostraca.util.PropertySet;
import org.jostraca.util.FileUtil;
import org.jostraca.util.Standard;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
import java.io.File;
/** Test cases for org.jostraca.Generator
*/
public class TemplateTest extends TestCase {
public TemplateTest( String pName ) {
super( pName );
}
public static TestSuite suite() {
return new TestSuite( TemplateTest.class );
}
public static void main( String[] pArgs ) {
TestRunner.run( suite() );
}
// use cases
// run generate and get output details
// data exchange via json output
public void testSimple() throws Exception {
File simple_txt = FileUtil.findFile( "org/jostraca/test/simple.txt" );
if( simple_txt.exists() ) {
simple_txt.delete();
}
// settings to just parse template
Generator g = new Generator();
PropertySet ps = new PropertySet();
ps.set( Property.main_MakeBackup, Standard.NO );
ps.set( Property.main_CompileCodeWriter, Standard.NO );
ps.set( Property.main_ExecuteCodeWriter, Standard.NO );
g.setCmdPropertySet( ps );
Template tm = g.generate( FileUtil.findFile( "org/jostraca/test/simple.jtm" ) );
// get full properties
PropertySet mergedps = tm.getMergedPropertySet();
assertEquals( ".jostraca", mergedps.get( Property.main_WorkFolder ) );
// this is how you can get the canonical template script language name
assertEquals( "java", tm.getCodeWriterLang() );
ps = new PropertySet();
ps.set( Property.main_MakeBackup, Standard.NO );
ps.set( Property.main_CompileCodeWriter, Standard.YES );
ps.set( Property.main_ExecuteCodeWriter, Standard.YES );
g.setCmdPropertySet( ps );
tm = g.generate( FileUtil.findFile( "org/jostraca/test/simple.jtm" ) );
// get the codewriter path
assertEquals( ".jostraca\\SimpleWriter.java", tm.getCodeWriterPath().toString() );
// get the codewriter class file / executable file
assertEquals( ".jostraca\\SimpleWriter.class", tm.getCodeWriterExecutablePath().toString() );
assertEquals("[.\\simple.txt]", tm.getSavedFiles().toString() );
}
}