Source Code Cross Referenced for IntroductionTest.java in  » Aspect-oriented » aspectwerkz-2.0 » test » mixin » perinstance » 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.mixin.perinstance 
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.mixin.perinstance;
008:
009:        import java.lang.reflect.Method;
010:        import java.io.Serializable;
011:
012:        import junit.framework.TestCase;
013:
014:        /**
015:         * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
016:         * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur </a>
017:         */
018:        public class IntroductionTest extends TestCase {
019:            private ToBeIntroduced m_toBeIntroduced;
020:            private ToBeIntroducedUsingHasMethod m_toBeIntroducedUsingHasMethod;
021:            private ToBeIntroducedUsingHasField m_toBeIntroducedUsingHasField;
022:
023:            public IntroductionTest(String name) {
024:                super (name);
025:                try {
026:                    m_toBeIntroduced = new ToBeIntroduced();
027:                } catch (Exception e) {
028:                    e.printStackTrace();
029:                }
030:                m_toBeIntroducedUsingHasMethod = new ToBeIntroducedUsingHasMethod();
031:                m_toBeIntroducedUsingHasField = new ToBeIntroducedUsingHasField();
032:            }
033:
034:            public void testInterfaceIntroduction() {
035:                assertTrue(m_toBeIntroduced instanceof  java.io.Serializable);
036:            }
037:
038:            public void testMixinInterfaceIntroduction() {
039:                assertTrue(m_toBeIntroduced instanceof  test.mixin.perinstance.Introductions);
040:                assertTrue(m_toBeIntroduced instanceof  Cloneable);
041:            }
042:
043:            public void testIntroducedComesFromInterfaces() {
044:                Class klass = m_toBeIntroduced.getClass();
045:                try {
046:                    Method m = klass.getDeclaredMethod("NOT_IN_MIXIN_INTF",
047:                            new Class[0]);
048:                    fail("should not have introduced : " + m);
049:                } catch (NoSuchMethodException e) {
050:                    ;//ok
051:                }
052:            }
053:
054:            public void testReturnVoid() {
055:                try {
056:                    ((Introductions) m_toBeIntroduced).getVoid();
057:                } catch (RuntimeException e) {
058:                    fail(e.getMessage());
059:                }
060:            }
061:
062:            public void testParent() {
063:                ToBeIntroducedParent parent = new ToBeIntroducedParent();
064:                assertTrue(parent instanceof  Serializable);
065:            }
066:
067:            public void testReturnLong() {
068:                assertEquals(1L, ((Introductions) m_toBeIntroduced).getLong());
069:            }
070:
071:            public void testReturnInt() {
072:                assertEquals(1, ((Introductions) m_toBeIntroduced).getInt());
073:            }
074:
075:            public void testReturnShort() {
076:                assertEquals(1, ((Introductions) m_toBeIntroduced).getShort());
077:            }
078:
079:            public void testReturnDouble() {
080:                assertEquals(new Double(1.1D), new Double(
081:                        ((Introductions) m_toBeIntroduced).getDouble()));
082:            }
083:
084:            public void testReturnFloat() {
085:                assertEquals(new Float(1.1F), new Float(
086:                        ((Introductions) m_toBeIntroduced).getFloat()));
087:            }
088:
089:            public void testReturnByte() {
090:                assertEquals(Byte.parseByte("1"),
091:                        ((Introductions) m_toBeIntroduced).getByte());
092:            }
093:
094:            public void testReturnChar() {
095:                assertEquals('A', ((Introductions) m_toBeIntroduced).getChar());
096:            }
097:
098:            public void testReturnBoolean() {
099:                assertEquals(true, ((Introductions) m_toBeIntroduced)
100:                        .getBoolean());
101:            }
102:
103:            public void testNoArgs() {
104:                try {
105:                    ((Introductions) m_toBeIntroduced).noArgs();
106:                } catch (Exception e) {
107:                    fail();
108:                }
109:            }
110:
111:            public void testIntArg() {
112:                assertEquals(12, ((Introductions) m_toBeIntroduced).intArg(12));
113:            }
114:
115:            public void testLongArg() {
116:                long result = ((Introductions) m_toBeIntroduced).longArg(12L);
117:                assertEquals(12L, result);
118:            }
119:
120:            public void testShortArg() {
121:                assertEquals((short) 3, ((Introductions) m_toBeIntroduced)
122:                        .shortArg((short) 3));
123:            }
124:
125:            public void testDoubleArg() {
126:                assertEquals(new Double(2.3D), new Double(
127:                        ((Introductions) m_toBeIntroduced).doubleArg(2.3D)));
128:            }
129:
130:            public void testFloatArg() {
131:                assertEquals(new Float(2.3F), new Float(
132:                        ((Introductions) m_toBeIntroduced).floatArg(2.3F)));
133:            }
134:
135:            public void testByteArg() {
136:                assertEquals(Byte.parseByte("1"),
137:                        ((Introductions) m_toBeIntroduced).byteArg(Byte
138:                                .parseByte("1")));
139:            }
140:
141:            public void testCharArg() {
142:                assertEquals('B', ((Introductions) m_toBeIntroduced)
143:                        .charArg('B'));
144:            }
145:
146:            public void testBooleanArg() {
147:                assertTrue(!((Introductions) m_toBeIntroduced)
148:                        .booleanArg(false));
149:            }
150:
151:            public void testObjectArg() {
152:                assertEquals("test", ((Introductions) m_toBeIntroduced)
153:                        .objectArg("test"));
154:            }
155:
156:            public void testArrayArg() {
157:                String[] strings = new String[0];
158:                try {
159:                    strings = ((Introductions) m_toBeIntroduced)
160:                            .arrayArg(new String[] { "test1", "test2" });
161:                } catch (Throwable e) {
162:                    System.out.println("e = " + e);
163:                }
164:                assertEquals("test1", strings[0]);
165:                assertEquals("test2", strings[1]);
166:            }
167:
168:            public void testVariousArguments1() {
169:                assertEquals("dummy".hashCode() + 1 + (int) 2.3F, this 
170:                        .hashCode()
171:                        + (int) 34L, ((Introductions) m_toBeIntroduced)
172:                        .variousArguments1("dummy", 1, 2.3F, this , 34L));
173:            }
174:
175:            public void testVariousArguments2() {
176:                assertEquals((int) 2.3F + 1 + "dummy".hashCode()
177:                        + this .hashCode() + (int) 34L + "test".hashCode(),
178:                        ((Introductions) m_toBeIntroduced).variousArguments2(
179:                                2.3F, 1, "dummy", this , 34L, "test"));
180:            }
181:
182:            public void testThrowException() {
183:                try {
184:                    ((Introductions) m_toBeIntroduced).exceptionThrower();
185:                } catch (Throwable e) {
186:                    assertTrue(e instanceof  UnsupportedOperationException);
187:                    return;
188:                }
189:                fail("this point should never be reached");
190:            }
191:
192:            public void testThrowExceptionChecked() {
193:                try {
194:                    ((Introductions) m_toBeIntroduced)
195:                            .exceptionThrowerChecked();
196:                } catch (Throwable e) {
197:                    assertTrue(e instanceof  Introductions.CheckedException);
198:                    return;
199:                }
200:                fail("this point should never be reached");
201:            }
202:
203:            // FIXME XXX implement mixin and comment out tests
204:
205:            //    public void testReplaceImplementation() {
206:            //        assertEquals("test.mixin.perinstance.IntroductionTestAspect$MyImpl", SystemLoader.getCflowStack(this)
207:            //                .getAspectManager("tests").getMixin("test.mixin.perinstance.IntroductionTestAspect$MyImpl")
208:            //                .getImplementationClassName());
209:            //        assertEquals(1, ((Introductions) m_toBeIntroduced).intArg(1));
210:            //
211:            //        // swap with an inner class
212:            //        SystemLoader.getCflowStack(this).getAspectManager("tests").getMixin(
213:            //            "test.mixin.perinstance.IntroductionTestAspect$MyImpl").swapImplementation(
214:            //            "test.mixin.perinstance.IntroductionTestAspect$MyOtherImpl");
215:            //        assertEquals(-1, ((Introductions) m_toBeIntroduced).intArg(1));
216:            //        assertEquals("test.mixin.perinstance.IntroductionTestAspect$MyOtherImpl", SystemLoader.getCflowStack(this)
217:            //                .getAspectManager("tests").getMixin("test.mixin.perinstance.IntroductionTestAspect$MyImpl")
218:            //                .getImplementationClassName());
219:            //    }
220:            //
221:            //    public void testReplaceImplementationToAutonomousOne() {
222:            //        assertEquals("test.mixin.perinstance.IntroductionTestAspect$MyOtherImpl", SystemLoader.getCflowStack(this)
223:            //                .getAspectManager("tests").getMixin("test.mixin.perinstance.IntroductionTestAspect$MyImpl")
224:            //                .getImplementationClassName());
225:            //        assertEquals(-1, ((Introductions) m_toBeIntroduced).intArg(1));
226:            //
227:            //        // swap with an outer class
228:            //        SystemLoader.getCflowStack(this).getAspectManager("tests").getMixin(
229:            //            "test.mixin.perinstance.IntroductionTestAspect$MyImpl").swapImplementation(
230:            //            "test.mixin.IntroductionTestAspectMyImplReplacement");
231:            //        assertEquals(-2, ((Introductions) m_toBeIntroduced).intArg(1));
232:            //        assertEquals("test.mixin.IntroductionTestAspectMyImplReplacement", SystemLoader.getCflowStack(
233:            //            this).getAspectManager("tests").getMixin("test.mixin.perinstance.IntroductionTestAspect$MyImpl")
234:            //                .getImplementationClassName());
235:            //    }
236:            public void testIntroductionUsingHasMethod() {
237:                assertTrue(m_toBeIntroducedUsingHasMethod instanceof  Introductions);
238:                assertTrue(m_toBeIntroducedUsingHasMethod instanceof  Cloneable);
239:            }
240:
241:            public void testIntroductionUsingHasField() {
242:                assertTrue(m_toBeIntroducedUsingHasField instanceof  Introductions);
243:                assertTrue(m_toBeIntroducedUsingHasField instanceof  Cloneable);
244:            }
245:
246:            public static void main(String[] args) {
247:                junit.textui.TestRunner.run(suite());
248:            }
249:
250:            public static junit.framework.Test suite() {
251:                //TODO: on IBM JRE, test method order is changed, and thus mixin replacement is done first
252:                // leading to some test
253:                // failure.
254:                return new junit.framework.TestSuite(IntroductionTest.class);
255:            }
256:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.