KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > aop > jdk15 > AOPTester


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

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 /**
32  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
33  * @version $Revision: 57019 $
34  */

35 public class AOPTester extends AOPTestWithSetup
36 {
37    public static void main(String JavaDoc[] 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 JavaDoc name)
60    {
61       super(name);
62    }
63
64    // Public -------------------------------------------------------
65

66    public void testCreateAnnotation() throws Exception JavaDoc
67    {
68       String JavaDoc 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 JavaDoc("failed to get @complex");
71       if (c.ch() != 'a') throw new RuntimeException JavaDoc("@complex.ch has wrong value");
72       if (!c.string().equals("hello world")) throw new RuntimeException JavaDoc("@complex.string has wrong value");
73       if (c.flt() != 5.5) throw new RuntimeException JavaDoc("@complex.flt has wrong value");
74       if (c.dbl() != 6.6) throw new RuntimeException JavaDoc("@complex.dbl has wrong value");
75       if (c.shrt() != 5) throw new RuntimeException JavaDoc("@complex.shrt has wrong value");
76       if (c.lng() != 6) throw new RuntimeException JavaDoc("@complex.lng has wrong value");
77       if (c.integer() != 7) throw new RuntimeException JavaDoc("@complex.integer has wrong value");
78       if (c.bool() == false) throw new RuntimeException JavaDoc("@complex.bool has wrong value");
79       single s = c.annotation();
80       if (s == null) throw new RuntimeException JavaDoc("@complex.annotation is null");
81       if (!s.value().equals("hello")) throw new RuntimeException JavaDoc("@complex.annotation has wrong value");
82       if (!c.array()[0].equals("hello")) throw new RuntimeException JavaDoc("@complex.array[0] has wrong value");
83       if (!c.array()[1].equals("world")) throw new RuntimeException JavaDoc("@complex.array[1] has wrong value");
84       if (!java.lang.String JavaDoc.class.equals(c.clazz())) throw new RuntimeException JavaDoc("@complex.clazz has wrong value");
85       if (c.enumVal() != MyEnum.ONE) throw new RuntimeException JavaDoc("@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 JavaDoc("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 JavaDoc("should not intercept non-tagged constructor");
102
103       pojo.someMethod();
104       if (!SimpleInterceptor.intercepted) throw new RuntimeException JavaDoc("failed to intercept tagged method");
105
106       SimpleInterceptor.intercepted = false;
107       pojo.nontraceableMethod();
108       if (SimpleInterceptor.intercepted) throw new RuntimeException JavaDoc("should not intercept non-tagged method");
109
110       pojo.field = 5;
111       if (!SimpleInterceptor.intercepted) throw new RuntimeException JavaDoc("failed to intercept tagged field");
112
113       SimpleInterceptor.intercepted = false;
114       pojo.nontraceable = 25;
115       if (SimpleInterceptor.intercepted) throw new RuntimeException JavaDoc("should not intercept non-tagged field");
116
117       Introduction intro = (Introduction) pojo;
118       intro.helloWorld("hello");
119    }
120 }
121
122
Popular Tags