Source Code Cross Referenced for AnnotationCTest.java in  » Aspect-oriented » aspectwerkz-2.0 » test » annotation » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Aspect oriented » aspectwerkz 2.0 » test.annotation 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**************************************************************************************
002:         * Copyright (c) Jonas Bon?r, Alexandre Vasseur. All rights reserved.                 *
003:         * http://aspectwerkz.codehaus.org                                                    *
004:         * ---------------------------------------------------------------------------------- *
005:         * The software in this package is published under the terms of the LGPL license      *
006:         * a copy of which has been included with this distribution in the license.txt file.  *
007:         **************************************************************************************/package test.annotation;
008:
009:        import junit.framework.TestCase;
010:        import org.codehaus.aspectwerkz.annotation.Annotations;
011:        import org.codehaus.aspectwerkz.annotation.UntypedAnnotation;
012:
013:        import java.util.List;
014:        import java.lang.reflect.Method;
015:
016:        /**
017:         * Note: when using untyped annotation, then the first space character(s) in the value part will be
018:         * resumed to only one space (untyped     type -> untyped type), due to QDox doclet handling.
019:         *
020:         * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur</a>
021:         * @BeforeAction some untype that starts with Before
022:         * @BeforeAction (other   untyped)
023:         * @BeforeAction("yet another untyped")
024:         * @packaged.BeforeAction
025:         * @Void
026:         * @Void()
027:         * @Simple()
028:         * @Simple(val="foo", s="foo")
029:         * @DefaultString("hello")
030:         * @packaged.DefaultString("hello")
031:         * @Complex(i=3, ls={1l,2l,6L},  klass=java.lang.String.class)
032:         * @Untyped
033:         * @Untyped "hello"
034:         * @Untyped ("hello2")
035:         * @Untyped "(hello) - see the space here !"
036:         * @Untyped("preserved hello")
037:         * @ComplexNested(nesteds={@Simple(val="foo"), @Simple(val="bar")})
038:         */
039:        public class AnnotationCTest extends TestCase {
040:
041:            public void testClassAnnotation() {
042:                Class me = AnnotationCTest.class;
043:
044:                List voids = Annotations.getAnnotations("Void", me);
045:                assertEquals(2, voids.size());
046:
047:                List simples = Annotations.getAnnotations("Simple", me);
048:                assertEquals(2, simples.size());
049:
050:                StringBuffer all = new StringBuffer();
051:                for (int i = 0; i < simples.size(); i++) {
052:                    all.append("[").append(
053:                            ((AnnotationParserTest.Simple) simples.get(i)).s())
054:                            .append("]");
055:                }
056:                String[] lookFor = new String[] { "[null]", "[foo]" };
057:                for (int i = 0; i < lookFor.length; i++) {
058:                    String s = lookFor[i];
059:                    if (all.toString().indexOf(s) < 0) {
060:                        fail("could not find " + lookFor[i] + " in "
061:                                + all.toString());
062:                    }
063:                }
064:
065:                List beforeActions = Annotations.getAnnotations("BeforeAction",
066:                        me);
067:                assertEquals(3, beforeActions.size());
068:                all = new StringBuffer();
069:                for (int i = 0; i < beforeActions.size(); i++) {
070:                    all.append("[").append(
071:                            ((UntypedAnnotation) beforeActions.get(i)).value())
072:                            .append("]");
073:                }
074:                lookFor = new String[] {
075:                        "[some untype that starts with Before]",
076:                        "[other untyped]", "[yet another untyped]",
077:
078:                };
079:                for (int i = 0; i < lookFor.length; i++) {
080:                    String s = lookFor[i];
081:                    if (all.toString().indexOf(s) < 0) {
082:                        fail("could not find " + lookFor[i] + " in "
083:                                + all.toString());
084:                    }
085:                }
086:
087:                assertEquals("hello",
088:                        ((AnnotationParserTest.DefaultString) Annotations
089:                                .getAnnotation("DefaultString", me)).value());
090:
091:                assertEquals(String.class,
092:                        ((AnnotationParserTest.Complex) Annotations
093:                                .getAnnotation("Complex", me)).klass());
094:
095:                List untypeds = Annotations.getAnnotations("Untyped", me);
096:                assertEquals(5, untypeds.size());
097:                all = new StringBuffer();
098:                for (int i = 0; i < untypeds.size(); i++) {
099:                    all.append("[").append(
100:                            ((AnnotationParserTest.Untyped) untypeds.get(i))
101:                                    .value()).append("]");
102:                }
103:                lookFor = new String[] { "[]", "[hello]",
104:                        "[(hello) - see the space here !]", "[hello2]",
105:                        "[preserved hello]" };
106:                for (int i = 0; i < lookFor.length; i++) {
107:                    String s = lookFor[i];
108:                    if (all.toString().indexOf(s) < 0) {
109:                        fail("could not find " + lookFor[i] + " in "
110:                                + all.toString());
111:                    }
112:                }
113:            }
114:
115:            /**
116:             * @Void
117:             * @Void()
118:             * @Simple()
119:             * @Simple(val="foo", s="foo")
120:             * @DefaultString("hello")
121:             * @Complex(i=3, ls={1l,2l,6L},  klass=java.lang.String.class)
122:             * @Untyped
123:             * @Untyped "hello"
124:             * @Untyped "hello"
125:             * @Untyped "(hello) - see the space here !"
126:             */
127:            public void testMethodAnnotation() throws Throwable {
128:                Class me = test.annotation.AnnotationCTest.class;
129:                Method m = me.getDeclaredMethod("testMethodAnnotation",
130:                        new Class[0]);
131:
132:                //QDOX bug..
133:                //        * @Around execution(* test.customproceed.CustomProceedTest.setInt(int)) && args(i)
134:                //        *
135:                //        * @Around("execution(* test.customproceed.CustomProceedTest.setInt(int)) && args(i)")
136:                //        List around = Annotations.getAnnotations(Around.class, m);
137:                //        assertEquals(2, around.size());
138:                //        assertEquals(((Around)around.get(0)).value(), "execution(* test.customproceed.CustomProceedTest.setInt(int)) && args(i)");
139:                //        assertEquals(((Around)around.get(1)).value(), "execution(* test.customproceed.CustomProceedTest.setInt(int)) && args(i)");
140:
141:                List voids = Annotations.getAnnotations("Void", me);
142:                assertEquals(2, voids.size());
143:
144:                List simples = Annotations.getAnnotations("Simple", me);
145:                assertEquals(2, simples.size());
146:                StringBuffer all = new StringBuffer();
147:                for (int i = 0; i < simples.size(); i++) {
148:                    all.append("[").append(
149:                            ((AnnotationParserTest.Simple) simples.get(i)).s())
150:                            .append("]");
151:                }
152:                String[] lookFor = new String[] { "[null]", "[foo]" };
153:                for (int i = 0; i < lookFor.length; i++) {
154:                    String s = lookFor[i];
155:                    if (all.toString().indexOf(s) < 0) {
156:                        fail("could not find " + lookFor[i] + " in "
157:                                + all.toString());
158:                    }
159:                }
160:
161:                assertEquals("hello",
162:                        ((AnnotationParserTest.DefaultString) Annotations
163:                                .getAnnotation("DefaultString", me)).value());
164:
165:                assertEquals(String.class,
166:                        ((AnnotationParserTest.Complex) Annotations
167:                                .getAnnotation("Complex", me)).klass());
168:
169:                List untypeds = Annotations.getAnnotations("Untyped", m);
170:                assertEquals(4, untypeds.size());
171:                all = new StringBuffer();
172:                for (int i = 0; i < untypeds.size(); i++) {
173:                    all.append("[").append(
174:                            ((AnnotationParserTest.Untyped) untypeds.get(i))
175:                                    .value()).append("]");
176:                }
177:                lookFor = new String[] { "[]", "[hello]",
178:                        "[(hello) - see the space here !]" };
179:                for (int i = 0; i < lookFor.length; i++) {
180:                    String s = lookFor[i];
181:                    if (all.toString().indexOf(s) < 0) {
182:                        fail("could not find " + lookFor[i] + " in "
183:                                + all.toString());
184:                    }
185:                }
186:            }
187:
188:            public void testNestedAnnotation() throws Throwable {
189:                Class me = AnnotationCTest.class;
190:                AnnotationParserTest.ComplexNested ann = (AnnotationParserTest.ComplexNested) Annotations
191:                        .getAnnotation("ComplexNested", me);
192:                AnnotationParserTest.Simple ann1 = ann.nesteds()[0];
193:                AnnotationParserTest.Simple ann2 = ann.nesteds()[1];
194:                String ann12 = ann1.val() + "." + ann2.val();
195:                if (ann12.equals("foo.bar") || ann12.equals("bar.foo")) {
196:                    ;//ok
197:                } else {
198:                    fail("Annotation is not correct " + ann.toString());
199:                }
200:            }
201:
202:            public static void main(String[] args) {
203:                junit.textui.TestRunner.run(suite());
204:            }
205:
206:            public static junit.framework.Test suite() {
207:                return new junit.framework.TestSuite(AnnotationCTest.class);
208:            }
209:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.