From: Kabir K. <kk...@jb...> - 2006-07-10 15:00:30
|
User: kkhan Date: 06/07/10 11:00:24 Added: src/test/org/jboss/test/aop/jdk15base AnnotatedPOJO.java traceable.java SomeIntroduction.java complex.java single.java trace.java MyEnum.java AOPTester.java SimpleInterceptor.java Introduction.java Log: Make a start migrating to jboss retro Revision Changes Path 1.1 date: 2006/07/10 15:00:23; author: kkhan; state: Exp;jboss-aop/src/test/org/jboss/test/aop/jdk15base/AnnotatedPOJO.java Index: AnnotatedPOJO.java =================================================================== /* * JBoss, Home of Professional Open Source * Copyright 2005, JBoss Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.test.aop.jdk15base; /** * @author <a href="mailto:bi...@jb...">Bill Burke</a> * @version $Revision: 1.1 $ */ @trace @traceable public class AnnotatedPOJO { @trace public int field; public int nontraceable; @trace public AnnotatedPOJO() { } public AnnotatedPOJO(String s) { System.out.println("POJO Constructor: " + s); } @trace public void someMethod() { System.out.println("POJO.someMethod"); } public void nontraceableMethod() { System.out.println("POJO.anotherMethod"); } } 1.1 date: 2006/07/10 15:00:23; author: kkhan; state: Exp;jboss-aop/src/test/org/jboss/test/aop/jdk15base/traceable.java Index: traceable.java =================================================================== /* * JBoss, Home of Professional Open Source * Copyright 2005, JBoss Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.test.aop.jdk15base; /** * @author <a href="mailto:bi...@jb...">Bill Burke</a> * @version $Revision: 1.1 $ */ public @interface traceable { } 1.1 date: 2006/07/10 15:00:24; author: kkhan; state: Exp;jboss-aop/src/test/org/jboss/test/aop/jdk15base/SomeIntroduction.java Index: SomeIntroduction.java =================================================================== /* * JBoss, Home of Professional Open Source * Copyright 2005, JBoss Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.test.aop.jdk15base; /** * @author <a href="mailto:bi...@jb...">Bill Burke</a> * @version $Revision: 1.1 $ */ public class SomeIntroduction implements Introduction { public SomeIntroduction(Object objIntroduced) { } public String helloWorld(String str) { return "hello " + str; } } 1.1 date: 2006/07/10 15:00:24; author: kkhan; state: Exp;jboss-aop/src/test/org/jboss/test/aop/jdk15base/complex.java Index: complex.java =================================================================== /* * JBoss, Home of Professional Open Source * Copyright 2005, JBoss Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.test.aop.jdk15base; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; /** * Comment * * @author <a href="mailto:bi...@jb...">Bill Burke</a> * @version $Revision: 1.1 $ */ @Retention(RetentionPolicy.RUNTIME) public @interface complex { char ch(); String string(); float flt(); double dbl(); short shrt(); long lng(); int integer(); boolean bool(); single annotation(); String[] array(); Class clazz(); MyEnum enumVal(); } 1.1 date: 2006/07/10 15:00:24; author: kkhan; state: Exp;jboss-aop/src/test/org/jboss/test/aop/jdk15base/single.java Index: single.java =================================================================== /* * JBoss, Home of Professional Open Source * Copyright 2005, JBoss Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.test.aop.jdk15base; /** * Comment * * @author <a href="mailto:bi...@jb...">Bill Burke</a> * @version $Revision: 1.1 $ */ public @interface single { String value(); } 1.1 date: 2006/07/10 15:00:24; author: kkhan; state: Exp;jboss-aop/src/test/org/jboss/test/aop/jdk15base/trace.java Index: trace.java =================================================================== /* * JBoss, Home of Professional Open Source * Copyright 2005, JBoss Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.test.aop.jdk15base; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; /** * @author <a href="mailto:bi...@jb...">Bill Burke</a> * @version $Revision: 1.1 $ */ @Retention(RetentionPolicy.RUNTIME) public @interface trace { } 1.1 date: 2006/07/10 15:00:24; author: kkhan; state: Exp;jboss-aop/src/test/org/jboss/test/aop/jdk15base/MyEnum.java Index: MyEnum.java =================================================================== /* * JBoss, Home of Professional Open Source * Copyright 2005, JBoss Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.test.aop.jdk15base; /** * Comment * * @author <a href="mailto:bi...@jb...">Bill Burke</a> * @version $Revision: 1.1 $ */ public enum MyEnum { ONE, TWO; } 1.1 date: 2006/07/10 15:00:24; author: kkhan; state: Exp;jboss-aop/src/test/org/jboss/test/aop/jdk15base/AOPTester.java Index: AOPTester.java =================================================================== /* * JBoss, Home of Professional Open Source * Copyright 2005, JBoss Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.test.aop.jdk15base; import junit.framework.Test; import junit.framework.TestSuite; import junit.textui.TestRunner; import org.jboss.aop.annotation.AnnotationCreator; import org.jboss.test.aop.AOPTestWithSetup; /** * @author <a href="mailto:bi...@jb...">Bill Burke</a> * @version $Revision: 1.1 $ */ public class AOPTester extends AOPTestWithSetup { public static void main(String[] args) { TestRunner.run(suite()); } private void printComplex(complex c) { System.out.print("@complex (ch='" + c.ch() + "', "); System.out.print("\"" + c.string() + "\", "); System.out.print("flt=" + c.flt() + ", "); System.out.print("enumVal=" + c.enumVal() + ", "); System.out.println("dbl=" + c.dbl() + ", ...blah blah blah YOU GET THE IDEA..."); } public static Test suite() { TestSuite suite = new TestSuite("AOPTester"); suite.addTestSuite(AOPTester.class); return suite; } public AOPTester(String name) { super(name); } // Public ------------------------------------------------------- public void testCreateAnnotation() throws Exception { String expr = "@org.jboss.test.aop.jdk15base.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.jdk15base.single(\"hello\"), array={\"hello\", \"world\"}, clazz=java.lang.String, enumVal=org.jboss.test.aop.jdk15base.MyEnum.ONE)"; complex c = (complex) AnnotationCreator.createAnnotation(expr, complex.class); if (c == null) throw new RuntimeException("failed to get @complex"); if (c.ch() != 'a') throw new RuntimeException("@complex.ch has wrong value"); if (!c.string().equals("hello world")) throw new RuntimeException("@complex.string has wrong value"); if (c.flt() != 5.5) throw new RuntimeException("@complex.flt has wrong value"); if (c.dbl() != 6.6) throw new RuntimeException("@complex.dbl has wrong value"); if (c.shrt() != 5) throw new RuntimeException("@complex.shrt has wrong value"); if (c.lng() != 6) throw new RuntimeException("@complex.lng has wrong value"); if (c.integer() != 7) throw new RuntimeException("@complex.integer has wrong value"); if (c.bool() == false) throw new RuntimeException("@complex.bool has wrong value"); single s = c.annotation(); if (s == null) throw new RuntimeException("@complex.annotation is null"); if (!s.value().equals("hello")) throw new RuntimeException("@complex.annotation has wrong value"); if (!c.array()[0].equals("hello")) throw new RuntimeException("@complex.array[0] has wrong value"); if (!c.array()[1].equals("world")) throw new RuntimeException("@complex.array[1] has wrong value"); if (!java.lang.String.class.equals(c.clazz())) throw new RuntimeException("@complex.clazz has wrong value"); if (c.enumVal() != MyEnum.ONE) throw new RuntimeException("@complex.enumVal has wrong value"); } public void testAnnotation() { System.out.println("RUNNING TEST BASIC"); SimpleInterceptor.intercepted = false; AnnotatedPOJO pojo = new AnnotatedPOJO(); if (!SimpleInterceptor.intercepted) throw new RuntimeException("failed to intercept tagged constructor"); complex c = (complex) AnnotatedPOJO.class.getAnnotation(complex.class); printComplex(c); SimpleInterceptor.intercepted = false; pojo = new AnnotatedPOJO("no interception"); if (SimpleInterceptor.intercepted) throw new RuntimeException("should not intercept non-tagged constructor"); pojo.someMethod(); if (!SimpleInterceptor.intercepted) throw new RuntimeException("failed to intercept tagged method"); SimpleInterceptor.intercepted = false; pojo.nontraceableMethod(); if (SimpleInterceptor.intercepted) throw new RuntimeException("should not intercept non-tagged method"); pojo.field = 5; if (!SimpleInterceptor.intercepted) throw new RuntimeException("failed to intercept tagged field"); SimpleInterceptor.intercepted = false; pojo.nontraceable = 25; if (SimpleInterceptor.intercepted) throw new RuntimeException("should not intercept non-tagged field"); Introduction intro = (Introduction) pojo; intro.helloWorld("hello"); } } 1.1 date: 2006/07/10 15:00:24; author: kkhan; state: Exp;jboss-aop/src/test/org/jboss/test/aop/jdk15base/SimpleInterceptor.java Index: SimpleInterceptor.java =================================================================== /* * JBoss, Home of Professional Open Source * Copyright 2005, JBoss Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.test.aop.jdk15base; /** * @author <a href="mailto:bi...@jb...">Bill Burke</a> * @version $Revision: 1.1 $ */ public class SimpleInterceptor implements org.jboss.aop.advice.Interceptor { public String getName() { return "SimpleInterceptor"; } public Object invoke(org.jboss.aop.joinpoint.Invocation invocation) throws Throwable { intercepted = true; return invocation.invokeNext(); } public static boolean intercepted; } 1.1 date: 2006/07/10 15:00:24; author: kkhan; state: Exp;jboss-aop/src/test/org/jboss/test/aop/jdk15base/Introduction.java Index: Introduction.java =================================================================== /* * JBoss, Home of Professional Open Source * Copyright 2005, JBoss Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.test.aop.jdk15base; /** * @author <a href="mailto:bi...@jb...">Bill Burke</a> * @version $Revision: 1.1 $ */ public interface Introduction { public String helloWorld(String str); } |