Package webit.script

Examples of webit.script.Context


    }

    public void mergeTemplate(String templatePath, Out out) throws ResourceNotFoundException {
        System.out.println("AUTO RUN: " + templatePath);
        Template template = EngineManager.getEngine().getTemplate(templatePath);
        Context context = template.merge(out);
        System.out.println("\tassert count: " + context.getLocal(webit.script.tools.testunit.AssertGlobalRegister.ASSERT_COUNT_KEY));
    }
View Full Code Here


    @Test
    public void test() throws ResourceNotFoundException {

        Template template = EngineManager.getTemplate("contextTest.wit");

        Context context = template.merge(new DiscardOut());

        Map map = new HashMap();

        assertEquals("a", context.get("a"));

        context.exportTo(map);
        assertTrue(map.containsKey("a"));
        assertTrue(map.containsKey("b"));
        assertFalse(map.containsKey("c"));

        assertEquals("a", map.get("a"));
View Full Code Here

public class FunctionExportTest {

    @Test
    public void test() throws ResourceNotFoundException {

        Context context = EngineManager.getTemplate("/functionExportTest.wit").merge(new DiscardOut());

        //plus
        Function plus = context.exportFunction("plus");

        assertNotNull(plus);

        assertEquals(1, plus.invoke(0, 1));
        assertEquals(5, plus.invoke(2, 3));
        assertEquals(1, plus.invoke(-2, 3));

        //counter
        Function counter = context.exportFunction("counter");

        assertNotNull(counter);

        assertEquals(0, counter.invoke());
        assertEquals(1, counter.invoke());
        assertEquals(2, counter.invoke());

        //counter
        Function counter2 = context.exportFunction("counter2");

        assertNotNull(counter2);

        assertEquals(0, counter2.invoke());
        assertEquals(1, counter2.invoke());
        assertEquals(2, counter2.invoke());

        //str_len
        Function str_len = context.exportFunction("str_len");

        assertNotNull(str_len);

        assertEquals(0, str_len.invoke(""));
        assertEquals(1, str_len.invoke("a"));
        assertEquals(4, str_len.invoke("abcd"));

        //print
        Function print = context.exportFunction("print");
        StringWriter writer;

        assertNotNull(print);

        writer = new StringWriter();
        print.invokeWithOut(writer, "");
        assertEquals("", writer.toString());
       
        writer = new StringWriter();
        print.invokeWithOut(writer, "hello function");
        assertEquals("hello function", writer.toString());

        //Exception cases:
        //
        Exception exception = null;
        try {
            context.exportFunction("notExistFunction");
        } catch (NotFunctionException e) {
            exception = e;
        }
        assertNotNull(exception);

        assertEquals("Not a function but a [null].", exception.getMessage());

        //
        exception = null;
        try {
            context.exportFunction("count");
        } catch (NotFunctionException e) {
            exception = e;
        }
        assertNotNull(exception);
View Full Code Here

   
    public void mergeTemplate(String templatePath, Out out) throws ResourceNotFoundException {
        System.out.println("AUTO RUN: " + templatePath);
        Template template = EngineManager.getEngine().getTemplate(templatePath);
        try {
            Context context = template.merge(out);
            System.out.println("\tassert count: " + context.getLocal(AssertGlobalRegister.ASSERT_COUNT_KEY));
        } catch (ScriptRuntimeException e) {
            throw e;
        }
    }
View Full Code Here

TOP

Related Classes of webit.script.Context

Copyright © 2018 www.massapicom. 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.