Package cambridge.runtime

Examples of cambridge.runtime.ExpressionContext


   @Test
   public void testComplex() {
      try {
         TemplateTokenizer tokenizer = new TemplateTokenizer(ParserTest.class.getResourceAsStream("complex.html"));
         TemplateParser parser = new TemplateParser(tokenizer, Expressions.cambridgeExpressionLanguage);
         ExpressionContext context = new MapExpressionContext();
         context.put("a", "AAA");
         context.put("b", "BBB");
         TemplateDocument t = parser.parse();

         assertNotNull(t);

         Attribute a = t.locateTag("/div").getAttribute("id");
View Full Code Here


   @Test
   public void testDymnamic() {
      try {
         TemplateTokenizer tokenizer = new TemplateTokenizer(ParserTest.class.getResourceAsStream("dynamic.html"));
         TemplateParser parser = new TemplateParser(tokenizer, Expressions.cambridgeExpressionLanguage);
         ExpressionContext context = new MapExpressionContext();

         context.put("style", "style");

         TemplateDocument t = parser.parse();

         assertNotNull(t);
View Full Code Here

   @Test
   public void testWithBehavior() throws Exception {
      TemplateTokenizer tokenizer = new TemplateTokenizer(ConditionalAttributeBehaviorTest.class.getResourceAsStream("withbehavior.html"));
      TemplateParser parser = new TemplateParser(tokenizer, Expressions.cambridgeExpressionLanguage);
      ExpressionContext context = new MapExpressionContext();

      User user = new User("test", "test@test.com");
      context.put("user", user);

      TemplateDocument t = parser.parse();
      assertNotNull(t);
      FragmentList fragments = t.normalize();
View Full Code Here

   @Test
   public void testFirst() {
      try {
         TemplateTokenizer tokenizer = new TemplateTokenizer(IfElseTest.class.getResourceAsStream("ifelse.html"));
         TemplateParser parser = new TemplateParser(tokenizer, Expressions.cambridgeExpressionLanguage);
         ExpressionContext context = new MapExpressionContext();
         context.put("var1", true);

         TemplateDocument t = parser.parse();
         assertNotNull(t);
         FragmentList fragments = t.normalize();
View Full Code Here

   @Test
   public void testSecond() {
      try {
         TemplateTokenizer tokenizer = new TemplateTokenizer(IfElseTest.class.getResourceAsStream("ifelse.html"));
         TemplateParser parser = new TemplateParser(tokenizer, Expressions.cambridgeExpressionLanguage);
         ExpressionContext context = new MapExpressionContext();
         context.put("var2", true);

         TemplateDocument t = parser.parse();
         assertNotNull(t);
         FragmentList fragments = t.normalize();
View Full Code Here

    }

    @Test
    public void testSimple() throws ExpressionEvaluationException
    {
        ExpressionContext context = expressionLanguage.createNewContext();
        Expression expression = expressionLanguage.parse("5 + 8", 1, 1);

        Object result = expression.eval(context);
        assertEquals("Testing simple arithmetic", 13, result);
    }
View Full Code Here

    }

    @Test
    public void testComplexArithmetic() throws ExpressionEvaluationException
    {
        ExpressionContext context = expressionLanguage.createNewContext();
        assertEquals("Testing simple arithmetic", 20494, expressionLanguage.parse("(891 * 23 + 12 / 8)", 1, 1).asInt(context));
        assertEquals("Testing simple arithmetic", 20494.5, expressionLanguage.parse("(891 * 23 + 12.0 / 8)", 1, 1).eval(context));
        assertEquals("Testing simple arithmetic", 4.5, expressionLanguage.parse("(891 * 23 + 12.0 / 8) % 10", 1, 1).eval(context));
    }
View Full Code Here

    }

    @Test
    public void testVariableAccess() throws Exception
    {
        ExpressionContext context = expressionLanguage.createNewContext();
        context.put("name", "Cambridge");
        Expression expression = expressionLanguage.parse("name", 1, 1);

        Object result = expression.eval(context);
        assertEquals("Testing variable access", "Cambridge", result);
    }
View Full Code Here

    }

    @Test
    public void testBean() throws Exception
    {
        ExpressionContext context = expressionLanguage.createNewContext();
        context.put("sample", sample);
        Expression expression = expressionLanguage.parse("sample", 1, 1);

        Object result = expression.eval(context);
        assertEquals("Testing variable access", sample, result);
        assertTrue("Testing variable access", sample == result);
View Full Code Here

    SpringExpressionLanguage language = new SpringExpressionLanguage();

    @Test
    public void testParseSimple() throws Exception
    {
        ExpressionContext context = language.createNewContext();
        Expression expression = language.parse("5 + 8", 1, 1);

        int i = expression.asInt(context);
        assertEquals(13, i);
    }
View Full Code Here

TOP

Related Classes of cambridge.runtime.ExpressionContext

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.