소스 검색

调试 javassist

wuxw 6 년 전
부모
커밋
79006c218f

+ 35 - 12
java110-core/src/test/java/com/java110/AppTest.java

@@ -3,36 +3,59 @@ package com.java110;
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
+import org.apache.ibatis.ognl.Ognl;
+import org.apache.ibatis.ognl.OgnlContext;
+
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * Unit test for simple App.
  */
-public class AppTest 
-    extends TestCase
-{
+public class AppTest
+        extends TestCase {
     /**
      * Create the test case
      *
      * @param testName name of the test case
      */
-    public AppTest( String testName )
-    {
-        super( testName );
+    public AppTest(String testName) {
+        super(testName);
     }
 
     /**
      * @return the suite of tests being tested
      */
-    public static Test suite()
-    {
-        return new TestSuite( AppTest.class );
+    public static Test suite() {
+        return new TestSuite(AppTest.class);
     }
 
     /**
      * Rigourous Test :-)
      */
-    public void testApp()
-    {
-        assertTrue( true );
+    public void testApp() {
+        assertTrue(true);
+    }
+
+    public void testOgnl() throws Exception{
+
+        //创建一个Ognl上下文对象
+        OgnlContext context = new OgnlContext();
+
+        Map user = new HashMap();
+        user.put("id", "123213");
+        user.put("name", "张三");
+
+        context.putAll(user);
+
+        Object node = Ognl.parseExpression("id != null and name != null");
+
+        Object value = Ognl.getValue(node,context);
+
+        System.out.printf("value : " + value);
+
+
+
+
     }
 }

+ 19 - 0
java110-service/src/test/java/com/java110/service/smo/impl/QueryServiceSMOImplTest.java

@@ -33,4 +33,23 @@ public class QueryServiceSMOImplTest extends TestCase {
 
         move.invoke(con);
     }
+
+
+
+    public void testExistsJavaClass() throws Exception{
+        ClassPool classPool = ClassPool.getDefault();
+        CtClass ctClass = classPool.get("com.java110.core.javassist.Java110CoreTemplateJavassist");
+
+
+
+        String javaCode = "public static void testJava2() {        System.out.println(\"123213\");\n}\n";
+        String    javaCode2 ="public static void testJava1() {     testJava2();   System.out.println(\"223213\");\n}";
+        CtMethod helloM = CtNewMethod.make(javaCode, ctClass);
+        ctClass.addMethod(helloM);
+
+        CtMethod helloM1 = CtNewMethod.make(javaCode2, ctClass);
+        ctClass.addMethod(helloM1);
+        //ctClass
+        ctClass.writeFile("E:\\project\\HC\\MicroCommunity\\11");
+    }
 }