Exemplo n.º 1
0
 @Test
 public void testConcat() {
   Object result = elp.eval("'10' + 1");
   assertEquals(result, 11L);
   result = elp.eval("10 += '1'");
   assertEquals(result.toString(), "101");
 }
Exemplo n.º 2
0
  @Test
  public void defineFuncTest() {
    Class c = MyBean.class;
    Method meth = null;
    Method meth2 = null;
    try {
      meth = c.getMethod("getBar", new Class<?>[] {});
      meth2 = c.getMethod("getFoo", new Class<?>[] {});
    } catch (Exception e) {
      System.out.printf("Exception: ", e);
    }
    try {
      elp.defineFunction("xx", "", meth);
      Object ret = elp.eval("xx:getBar() == 64");
      assertTrue((Boolean) ret);
    } catch (NoSuchMethodException ex) {

    }

    boolean caught = false;
    try {
      elp.defineFunction("", "", meth2);
      Object ret = elp.eval("getFoo() == 100");
      assertTrue((Boolean) ret);
    } catch (NoSuchMethodException ex) {
      caught = true;
    }
    assertTrue(caught);

    try {
      elp.defineFunction("yy", "", "org.glassfish.el.test.ELProcessorTest$MyBean", "getBar");
      Object ret = elp.eval("yy:getBar() == 64");
      assertTrue((Boolean) ret);
    } catch (ClassNotFoundException | NoSuchMethodException ex) {

    }

    caught = false;
    try {
      elp.defineFunction("yy", "", "org.glassfish.el.test.ELProcessorTest$MyBean", "getFooBar");
      Object ret = elp.eval("yy:getBar() == 100");
      assertTrue((Boolean) ret);
    } catch (ClassNotFoundException | NoSuchMethodException ex) {
      caught = true;
    }
    assertTrue(caught);

    caught = false;
    try {
      elp.defineFunction("yy", "", "testBean", "getFoo");
      Object ret = elp.eval("yy:getBar() == 100");
      assertTrue((Boolean) ret);
    } catch (ClassNotFoundException | NoSuchMethodException ex) {
      caught = true;
    }
    assertTrue(caught);
  }
Exemplo n.º 3
0
 @Test
 public void testSetVariable() {
   elp.setVariable("xx", "100");
   Object result = elp.getValue("xx + 11", String.class);
   assertEquals(result, "111");
   elp.setVariable("xx", null);
   assertEquals(elp.eval("xx"), null);
   elp.setVariable("yy", "abc");
   assertEquals(elp.eval("yy = 123; abc"), 123L);
   assertEquals(elp.eval("abc = 456; yy"), 456L);
 }
Exemplo n.º 4
0
 @Test
 public void testImport() {
   elm.importClass("org.glassfish.el.test.ELProcessorTest$MyBean");
   assertTrue((Boolean) elp.eval("ELProcessorTest$MyBean.aaaa == 101"));
   assertTrue((Boolean) elp.eval("ELProcessorTest$MyBean.getBar() == 64"));
   elm.importStatic("org.glassfish.el.test.ELProcessorTest$MyBean.aaaa");
   assertEquals(new Integer(101), elp.eval("aaaa"));
   elm.importStatic("org.glassfish.el.test.ELProcessorTest$MyBean.getBar");
   assertEquals(new Integer(64), elp.eval("getBar()"));
   /*
   elm.importStatic("a.b.NonExisting.foobar");
   elp.eval("foobar");
   elp.eval("ELProcessorTest$MyBean.getFoo()");
   */
 }
Exemplo n.º 5
0
 @Test
 public void testGetValue() {
   Object result = elp.eval("10 + 1");
   assertEquals(result.toString(), "11");
   result = elp.getValue("10 + 2", String.class);
   assertEquals(result, "12");
 }