Java Code Examples for org.apache.velocity.app.Velocity#reset()

The following examples show how to use org.apache.velocity.app.Velocity#reset() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultipleFileResourcePathTestCase.java    From velocity-engine with Apache License 2.0 6 votes vote down vote up
public void setUp()
        throws Exception
{
    assureResultsDirectoryExists(RESULTS_DIR);

    Velocity.reset();

    Velocity.addProperty(
            Velocity.FILE_RESOURCE_LOADER_PATH, FILE_RESOURCE_LOADER_PATH1);

    Velocity.addProperty(
            Velocity.FILE_RESOURCE_LOADER_PATH, FILE_RESOURCE_LOADER_PATH2);

    Velocity.setProperty(
            Velocity.RUNTIME_LOG_INSTANCE, new TestLogger());

    Velocity.init();
}
 
Example 2
Source File: StringResourceLoaderRepositoryTestCase.java    From velocity-engine with Apache License 2.0 6 votes vote down vote up
public void setUp() throws Exception
{
    Velocity.reset();
    Velocity.setProperty(Velocity.RESOURCE_LOADERS, "string");
    Velocity.addProperty("string.resource.loader.class", StringResourceLoader.class.getName());
    Velocity.addProperty("string.resource.loader.modificationCheckInterval", "1");
    Velocity.setProperty(Velocity.RUNTIME_LOG_INSTANCE, new TestLogger());
    Velocity.init();

    StringResourceRepository repo = getRepo(null, null);
    repo.putStringResource("foo", "This is $foo");
    repo.putStringResource("bar", "This is $bar");

    context = new VelocityContext();
    context.put("foo", "wonderful!");
    context.put("bar", "horrible!");
    context.put("woogie", "a woogie");
}
 
Example 3
Source File: InlineScopeVMTestCase.java    From velocity-engine with Apache License 2.0 6 votes vote down vote up
public void setUp()
        throws Exception
{
    /*
     *  do our properties locally, and just override the ones we want
     *  changed
     */

    Velocity.reset();

    Velocity.setProperty(
        Velocity.VM_PERM_ALLOW_INLINE_REPLACE_GLOBAL, "true");

    Velocity.setProperty(
            Velocity.VM_PERM_INLINE_LOCAL, "true");

    Velocity.setProperty(
        Velocity.FILE_RESOURCE_LOADER_PATH, FILE_RESOURCE_LOADER_PATH);

    Velocity.setProperty(
            Velocity.RUNTIME_LOG_INSTANCE, new TestLogger());

    Velocity.setProperty("space.gobbling", "bc");

    Velocity.init();
}
 
Example 4
Source File: StringResourceLoaderTestCase.java    From velocity-engine with Apache License 2.0 6 votes vote down vote up
public void setUp()
        throws Exception
{
    assureResultsDirectoryExists(RESULTS_DIR);

    Velocity.reset();

    Velocity.setProperty(Velocity.RESOURCE_LOADERS, "string");
    Velocity.addProperty("string.resource.loader.class", StringResourceLoader.class.getName());
    Velocity.addProperty("string.resource.loader.modificationCheckInterval", "1");

    // Silence the logger.
    Velocity.setProperty(Velocity.RUNTIME_LOG_INSTANCE, new TestLogger());

    Velocity.init();
}
 
Example 5
Source File: MacroForwardDefineTestCase.java    From velocity-engine with Apache License 2.0 6 votes vote down vote up
public void setUp()
    throws Exception
{
    assureResultsDirectoryExists(RESULTS_DIR);

    // use Velocity.setProperty (instead of properties file) so that we can use actual instance of log
    Velocity.reset();
    Velocity.setProperty(RuntimeConstants.RESOURCE_LOADERS,"file");
    Velocity.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, FILE_RESOURCE_LOADER_PATH );
    Velocity.setProperty(RuntimeConstants.RUNTIME_LOG_REFERENCE_LOG_INVALID,"true");

    // actual instance of logger
    logger.setEnabledLevel(TestLogger.LOG_LEVEL_DEBUG);
    Velocity.setProperty(RuntimeConstants.RUNTIME_LOG_INSTANCE, logger);
    Velocity.init();
}
 
Example 6
Source File: ResourceLoaderInstanceTestCase.java    From velocity-engine with Apache License 2.0 6 votes vote down vote up
public void setUp()
        throws Exception
{

    ResourceLoader rl = new FileResourceLoader();

    // pass in an instance to Velocity
    Velocity.reset();
    Velocity.setProperty( "resource.loader", "testrl" );
    Velocity.setProperty( "testrl.resource.loader.instance", rl );
    Velocity.setProperty( "testrl.resource.loader.path", FILE_RESOURCE_LOADER_PATH );

    // actual instance of logger
    logger.on();
    Velocity.setProperty(RuntimeConstants.RUNTIME_LOG_INSTANCE, logger);
    Velocity.setProperty("runtime.log.logsystem.test.level", "debug");

    Velocity.init();
}
 
Example 7
Source File: ContextSafetyTestCase.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
public void setUp()
        throws Exception
{
    Velocity.reset();
    Velocity.setProperty(
            Velocity.FILE_RESOURCE_LOADER_PATH, FILE_RESOURCE_LOADER_PATH);

    Velocity.setProperty(
            Velocity.RUNTIME_LOG_INSTANCE, new TestLogger());

    Velocity.init();
}
 
Example 8
Source File: ClasspathResourceTestCase.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
public void setUp()
        throws Exception
{
    assureResultsDirectoryExists(RESULTS_DIR);

    Velocity.reset();
    Velocity.setProperty(Velocity.RESOURCE_LOADERS, "classpath");

    /*
     * I don't think I should have to do this, these should
     * be in the default config file.
     */

    Velocity.addProperty(
            "classpath." + Velocity.RESOURCE_LOADER + ".class",
            "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");

    Velocity.setProperty(
            "classpath." + Velocity.RESOURCE_LOADER + ".cache", "false");

    Velocity.setProperty(
            "classpath." + Velocity.RESOURCE_LOADER + ".modificationCheckInterval",
            "2");

    Velocity.setProperty(
            Velocity.RUNTIME_LOG_INSTANCE, new TestLogger());

    Velocity.init();
}
 
Example 9
Source File: ChainedUberspectorsTestCase.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
public void setUp()
        throws Exception
{
    Velocity.reset();
    Velocity.setProperty(Velocity.RUNTIME_LOG_INSTANCE, new TestLogger());
    Velocity.addProperty(Velocity.UBERSPECT_CLASSNAME,"org.apache.velocity.util.introspection.UberspectImpl");
    Velocity.addProperty(Velocity.UBERSPECT_CLASSNAME,"org.apache.velocity.test.util.introspection.ChainedUberspectorsTestCase$ChainedUberspector");
    Velocity.addProperty(Velocity.UBERSPECT_CLASSNAME,"org.apache.velocity.test.util.introspection.ChainedUberspectorsTestCase$LinkedUberspector");
 Velocity.init();
}
 
Example 10
Source File: EncodingTestCase.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
public void setUp()
        throws Exception
{
    Velocity.reset();

    Velocity.setProperty(
            Velocity.FILE_RESOURCE_LOADER_PATH, FILE_RESOURCE_LOADER_PATH);

    Velocity.setProperty( Velocity.INPUT_ENCODING, "UTF-8" );

    Velocity.setProperty(
            Velocity.RUNTIME_LOG_INSTANCE, new TestLogger());

    Velocity.init();
}
 
Example 11
Source File: VelocimacroTestCase.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
public void setUp()
        throws Exception
{
    /*
     *  setup local scope for templates
     */
    Velocity.reset();
    Velocity.setProperty( Velocity.VM_PERM_INLINE_LOCAL, Boolean.TRUE);
    Velocity.setProperty( Velocity.VM_MAX_DEPTH, 5);
    Velocity.setProperty(
            Velocity.RUNTIME_LOG_INSTANCE, new TestLogger());
    Velocity.init();
}
 
Example 12
Source File: ParseExceptionTestCase.java    From velocity-engine with Apache License 2.0 4 votes vote down vote up
public void setUp() throws Exception
{
    Velocity.reset();
    super.setUp();
}
 
Example 13
Source File: TemplateTestCase.java    From velocity-engine with Apache License 2.0 4 votes vote down vote up
/**
 * Sets up the test.
 */
protected void setUp ()
   throws Exception
{
    super.setUp();
    Velocity.reset();
    Velocity.setProperty(
        Velocity.FILE_RESOURCE_LOADER_PATH, FILE_RESOURCE_LOADER_PATH);

    Velocity.setProperty(
            Velocity.RUNTIME_LOG_INSTANCE, new TestLogger());

    Velocity.setProperty("space.gobbling", "bc");

    Velocity.init();

    provider = new TestProvider();
    al = provider.getCustomers();
    h = new Hashtable();

    h.put("Bar", "this is from a hashtable!");
    h.put("Foo", "this is from a hashtable too!");

    /*
     *  lets set up a vector of objects to test late introspection. See ASTMethod.java
     */

    vec = new Vector();

    vec.addElement(new String("string1"));
    vec.addElement(new String("string2"));

    /*
     *  set up 3 chained contexts, and add our data
     *  throught the 3 of them.
     */

    context2 = new VelocityContext();
    context1 = new VelocityContext( context2 );
    context = new VelocityContext( context1 );

    context.put("provider", provider);
    context1.put("name", "jason");
    context1.put("name2", new StringBuffer("jason"));
    context1.put("name3", new StringBuffer("geoge"));
    context2.put("providers", provider.getCustomers2());
    context.put("list", al);
    context1.put("hashtable", h);
    context2.put("hashmap", new HashMap());
    context2.put("search", provider.getSearch());
    context.put("relatedSearches", provider.getRelSearches());
    context1.put("searchResults", provider.getRelSearches());
    context2.put("stringarray", provider.getArray());
    context.put("vector", vec );
    context.put("mystring", new String());
    context.put("runtime", new FieldMethodizer( "org.apache.velocity.runtime.RuntimeSingleton" ));
    context.put("fmprov", new FieldMethodizer( provider ));
    context.put("Floog", "floogie woogie");
    context.put("boolobj", new BoolObj() );

    /*
     *  we want to make sure we test all types of iterative objects
     *  in #foreach()
     */

    Object[] oarr = { "a","b","c","d" } ;
    int intarr[] = { 10, 20, 30, 40, 50 };
    int emptyarr[] = {};

    context.put( "collection", vec );
    context2.put("iterator", vec.iterator());
    context1.put("map", h );
    context.put("obarr", oarr );
    context.put("enumerator", vec.elements());
    context.put("intarr", intarr );
    context.put("emptyarr", emptyarr );

    // Add some Numbers
    context.put ("int1", 1000);
    context.put ("long1", 10000000000l);
    context.put ("float1", 1000.1234f);
    context.put ("double1", 10000000000d);

    // Add a TemplateNumber
    context.put ("templatenumber1", new TestNumber (999.125));

    /**
     * Test #foreach() with a list containing nulls
     */
    ArrayList nullList = new ArrayList();
    nullList.add("a");
    nullList.add("b");
    nullList.add(null);
    nullList.add("d");
    context.put("nullList", nullList);

    // test silent references with a null tostring
    context.put("nullToString",new NullToStringObject());
}
 
Example 14
Source File: MultiLoaderTestCase.java    From velocity-engine with Apache License 2.0 4 votes vote down vote up
public void setUp()
        throws Exception
{
    assureResultsDirectoryExists(RESULTS_DIR);

    /*
     * Set up the file loader.
     */

    Velocity.reset();

    Velocity.setProperty(Velocity.RESOURCE_LOADERS, "file");

    Velocity.setProperty(
        Velocity.FILE_RESOURCE_LOADER_PATH, FILE_RESOURCE_LOADER_PATH);

    Velocity.addProperty(Velocity.RESOURCE_LOADERS, "classpath");

    Velocity.addProperty(Velocity.RESOURCE_LOADERS, "jar");

    /*
     *  Set up the classpath loader.
     */

    Velocity.setProperty(
        Velocity.RESOURCE_LOADER + ".classpath.class",
        "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");

    Velocity.setProperty(
        Velocity.RESOURCE_LOADER + ".classpath.cache",
        "false");

    Velocity.setProperty(
        Velocity.RESOURCE_LOADER + ".classpath.modification_check_interval",
        "2");

    /*
     *  setup the Jar loader
     */

    Velocity.setProperty(
        Velocity.RESOURCE_LOADER + ".jar.class",
        "org.apache.velocity.runtime.resource.loader.JarResourceLoader");

    Velocity.setProperty(
        Velocity.RESOURCE_LOADER + ".jar.path",
        "jar:file:" + FILE_RESOURCE_LOADER_PATH + "/test2.jar" );


    Velocity.setProperty(
            Velocity.RUNTIME_LOG_INSTANCE, new TestLogger());

    Velocity.init();
}
 
Example 15
Source File: IncludeEventHandlingTestCase.java    From velocity-engine with Apache License 2.0 4 votes vote down vote up
public void setUp()
        throws Exception
{
    assureResultsDirectoryExists(RESULTS_DIR);

    Velocity.reset();
    Velocity.addProperty(
        Velocity.FILE_RESOURCE_LOADER_PATH, FILE_RESOURCE_LOADER_PATH);

    Velocity.setProperty(
            Velocity.RUNTIME_LOG_INSTANCE, new TestLogger());

    Velocity.init();


}
 
Example 16
Source File: Velocity580TestCase.java    From velocity-engine with Apache License 2.0 3 votes vote down vote up
public void setUp() throws Exception
{

    assureResultsDirectoryExists(RESULTS_DIR);

    Velocity.reset();

    Velocity.addProperty(Velocity.FILE_RESOURCE_LOADER_PATH, TEMPLATE_DIR);

    Velocity.setProperty(Velocity.RUNTIME_LOG_INSTANCE, new TestLogger());

    Velocity.init();
}