AppTest.java 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package com.java110;
  2. import junit.framework.Test;
  3. import junit.framework.TestCase;
  4. import junit.framework.TestSuite;
  5. import org.apache.ibatis.ognl.Ognl;
  6. import org.apache.ibatis.ognl.OgnlContext;
  7. import java.util.HashMap;
  8. import java.util.Map;
  9. /**
  10. * Unit test for simple App.
  11. */
  12. public class AppTest
  13. extends TestCase {
  14. /**
  15. * Create the test case
  16. *
  17. * @param testName name of the test case
  18. */
  19. public AppTest(String testName) {
  20. super(testName);
  21. }
  22. /**
  23. * @return the suite of tests being tested
  24. */
  25. public static Test suite() {
  26. return new TestSuite(AppTest.class);
  27. }
  28. /**
  29. * Rigourous Test :-)
  30. */
  31. public void testApp() {
  32. assertTrue(true);
  33. }
  34. public void testOgnl() throws Exception{
  35. //创建一个Ognl上下文对象
  36. OgnlContext context = new OgnlContext();
  37. Map user = new HashMap();
  38. user.put("id", "123213");
  39. user.put("name", "张三");
  40. context.putAll(user);
  41. Object node = Ognl.parseExpression("id != null and name != null");
  42. Object value = Ognl.getValue(node,context);
  43. System.out.printf("value : " + value);
  44. }
  45. }