Package org.jostraca.test

Source Code of org.jostraca.test.VirtualTest

package org.jostraca.test;

import java.io.File;

import org.jostraca.BasicWriterFormat;
import org.jostraca.Generator;
import org.jostraca.Property;
import org.jostraca.Template;
import org.jostraca.VirtualTemplate;
import org.jostraca.VirtualWriterFormat;
import org.jostraca.WriterFormat;
import org.jostraca.util.PropertySet;
import org.jostraca.util.Tracker;

import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;

public class VirtualTest extends TestCase {

  public VirtualTest( String pName ) {
    super( pName );
  }

  public static TestSuite suite() {
    return new TestSuite( VirtualTest.class );
  }

  public static void main( String[] pArgs ) {
    TestRunner.run( suite() );
  }
 
 
  private static final String WF_SOURCE_01 = "var codewriter = function(){ var self = this; self.result = [];\n"
    +"self._setContext = function($context){ self.context = $context; }\n"
    +"self._insert = function( text ) { self.result.push(text); }\n"
    +"self._getText = function() { return self.result.join('');}\n"
    +"self._generate = function($params){ !<body> return _getText(); }; return self;}();";
 
  private static final String TM_SOURCE_01 =
    "<% @conf main.JostracaVersion = 0.4 \n main.TemplateScript = javascript %>"
    +"<% var name = 'Bob'; %>Hi <%=name%>";
 
 
  public void testVirtualFormat() throws Exception {
   
    //Tracker.activate(new File("/log/jostraca.log"));
   
    Generator g = makeVirtualGenerator(null);
   
    Template t = new VirtualTemplate("test01.js",TM_SOURCE_01);
    g.generate(t);
   
    assertEquals("Hi Bob",t.getResult());
  }

 
  public static Generator makeVirtualGenerator( PropertySet pPropertySet ) {
    Generator g = new Generator();
    WriterFormat wf = new VirtualWriterFormat("VWF01", WF_SOURCE_01);
    g.getFormatManager().addFormat(wf);
   
    PropertySet ps = null == pPropertySet ? new PropertySet() : pPropertySet;
    ps.set(Property.main_CodeWriterFormat,"VWF01");
    ps.set(Property.main_MakeBackup,"no");
    ps.set(Property.main_SaveCodeWriter,"no");
    ps.set(Property.main_EnableMeta,"no");

    g.setCmdPropertySet(ps);
    return g;
  }
 
 
}
TOP

Related Classes of org.jostraca.test.VirtualTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.