1 22 package org.jboss.test.aop.jdk15; 23 24 import junit.framework.Test; 25 import junit.framework.TestSuite; 26 import junit.textui.TestRunner; 27 28 import org.jboss.aop.annotation.factory.duplicate.AnnotationCreator; 29 import org.jboss.test.aop.AOPTestWithSetup; 30 31 35 public class AOPTester extends AOPTestWithSetup 36 { 37 public static void main(String [] args) 38 { 39 TestRunner.run(suite()); 40 } 41 42 private void printComplex(complex c) 43 { 44 System.out.print("@complex (ch='" + c.ch() + "', "); 45 System.out.print("\"" + c.string() + "\", "); 46 System.out.print("flt=" + c.flt() + ", "); 47 System.out.print("enumVal=" + c.enumVal() + ", "); 48 System.out.println("dbl=" + c.dbl() + ", ...blah blah blah YOU GET THE IDEA..."); 49 50 } 51 52 public static Test suite() 53 { 54 TestSuite suite = new TestSuite("AOPTester"); 55 suite.addTestSuite(AOPTester.class); 56 return suite; 57 } 58 59 public AOPTester(String name) 60 { 61 super(name); 62 } 63 64 66 public void testCreateAnnotation() throws Exception 67 { 68 String expr = "@org.jboss.test.aop.jdk15.complex (ch='a', string=\"hello world\", flt=5.5, dbl=6.6, shrt=5, lng=6, integer=7, bool=true, annotation=@org.jboss.test.aop.jdk15.single(\"hello\"), array={\"hello\", \"world\"}, clazz=java.lang.String, enumVal=org.jboss.test.aop.jdk15.MyEnum.ONE)"; 69 complex c = (complex) AnnotationCreator.createAnnotation(expr, complex.class); 70 if (c == null) throw new RuntimeException ("failed to get @complex"); 71 if (c.ch() != 'a') throw new RuntimeException ("@complex.ch has wrong value"); 72 if (!c.string().equals("hello world")) throw new RuntimeException ("@complex.string has wrong value"); 73 if (c.flt() != 5.5) throw new RuntimeException ("@complex.flt has wrong value"); 74 if (c.dbl() != 6.6) throw new RuntimeException ("@complex.dbl has wrong value"); 75 if (c.shrt() != 5) throw new RuntimeException ("@complex.shrt has wrong value"); 76 if (c.lng() != 6) throw new RuntimeException ("@complex.lng has wrong value"); 77 if (c.integer() != 7) throw new RuntimeException ("@complex.integer has wrong value"); 78 if (c.bool() == false) throw new RuntimeException ("@complex.bool has wrong value"); 79 single s = c.annotation(); 80 if (s == null) throw new RuntimeException ("@complex.annotation is null"); 81 if (!s.value().equals("hello")) throw new RuntimeException ("@complex.annotation has wrong value"); 82 if (!c.array()[0].equals("hello")) throw new RuntimeException ("@complex.array[0] has wrong value"); 83 if (!c.array()[1].equals("world")) throw new RuntimeException ("@complex.array[1] has wrong value"); 84 if (!java.lang.String .class.equals(c.clazz())) throw new RuntimeException ("@complex.clazz has wrong value"); 85 if (c.enumVal() != MyEnum.ONE) throw new RuntimeException ("@complex.enumVal has wrong value"); 86 } 87 88 public void testAnnotation() 89 { 90 System.out.println("RUNNING TEST BASIC"); 91 92 SimpleInterceptor.intercepted = false; 93 AnnotatedPOJO pojo = new AnnotatedPOJO(); 94 if (!SimpleInterceptor.intercepted) throw new RuntimeException ("failed to intercept tagged constructor"); 95 96 complex c = (complex) AnnotatedPOJO.class.getAnnotation(complex.class); 97 printComplex(c); 98 99 SimpleInterceptor.intercepted = false; 100 pojo = new AnnotatedPOJO("no interception"); 101 if (SimpleInterceptor.intercepted) throw new RuntimeException ("should not intercept non-tagged constructor"); 102 103 pojo.someMethod(); 104 if (!SimpleInterceptor.intercepted) throw new RuntimeException ("failed to intercept tagged method"); 105 106 SimpleInterceptor.intercepted = false; 107 pojo.nontraceableMethod(); 108 if (SimpleInterceptor.intercepted) throw new RuntimeException ("should not intercept non-tagged method"); 109 110 pojo.field = 5; 111 if (!SimpleInterceptor.intercepted) throw new RuntimeException ("failed to intercept tagged field"); 112 113 SimpleInterceptor.intercepted = false; 114 pojo.nontraceable = 25; 115 if (SimpleInterceptor.intercepted) throw new RuntimeException ("should not intercept non-tagged field"); 116 117 Introduction intro = (Introduction) pojo; 118 intro.helloWorld("hello"); 119 } 120 } 121 122 | Popular Tags |