Source Code Cross Referenced for DynaopAspectablePicoContainerFactoryTestCase.java in  » Inversion-of-Control » nanocontainer » org » nanocontainer » aop » dynaop » 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 » Inversion of Control » nanocontainer » org.nanocontainer.aop.dynaop 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*****************************************************************************
002:         * Copyright (c) PicoContainer Organization. All rights reserved.            *
003:         * ------------------------------------------------------------------------- *
004:         * The software in this package is published under the terms of the BSD      *
005:         * style license a copy of which has been included with this distribution in *
006:         * the LICENSE.txt file.                                                     *
007:         *                                                                           *
008:         * Idea by Rachel Davies, Original code by various                           *
009:         *****************************************************************************/package org.nanocontainer.aop.dynaop;
010:
011:        import org.nanocontainer.aop.AbstractAopTestCase;
012:        import org.nanocontainer.aop.AspectablePicoContainer;
013:        import org.nanocontainer.aop.AspectablePicoContainerFactory;
014:        import org.nanocontainer.aop.LoggingInterceptor;
015:        import org.nanocontainer.aop.PointcutsFactory;
016:        import org.nanocontainer.testmodel.AnotherInterface;
017:        import org.nanocontainer.testmodel.Dao;
018:        import org.nanocontainer.testmodel.DaoImpl;
019:        import org.nanocontainer.testmodel.IdGenerator;
020:        import org.nanocontainer.testmodel.IdGeneratorImpl;
021:        import org.nanocontainer.testmodel.Identifiable;
022:        import org.nanocontainer.testmodel.IdentifiableMixin;
023:        import org.nanocontainer.testmodel.OrderEntity;
024:        import org.nanocontainer.testmodel.OrderEntityImpl;
025:        import org.picocontainer.MutablePicoContainer;
026:        import org.picocontainer.PicoContainer;
027:        import org.picocontainer.defaults.DefaultPicoContainer;
028:        import org.picocontainer.testmodel.SimpleTouchable;
029:
030:        /**
031:         * @author Stephen Molitor
032:         */
033:        public class DynaopAspectablePicoContainerFactoryTestCase extends
034:                AbstractAopTestCase {
035:
036:            private AspectablePicoContainerFactory containerFactory = new DynaopAspectablePicoContainerFactory();
037:            private AspectablePicoContainer pico = containerFactory
038:                    .createContainer();
039:            private PointcutsFactory cuts = pico.getPointcutsFactory();
040:
041:            public void testInterceptor() {
042:                StringBuffer log = new StringBuffer();
043:                pico.registerInterceptor(cuts.instancesOf(Dao.class), cuts
044:                        .allMethods(), new LoggingInterceptor(log));
045:                pico.registerComponentImplementation(Dao.class, DaoImpl.class);
046:                Dao dao = (Dao) pico.getComponentInstance(Dao.class);
047:                verifyIntercepted(dao, log);
048:            }
049:
050:            public void testContainerSuppliedInterceptor() {
051:                pico.registerInterceptor(cuts.instancesOf(Dao.class), cuts
052:                        .allMethods(), LoggingInterceptor.class);
053:
054:                pico.registerComponentImplementation("log", StringBuffer.class);
055:                pico.registerComponentImplementation(LoggingInterceptor.class);
056:                pico.registerComponentImplementation(Dao.class, DaoImpl.class);
057:
058:                Dao dao = (Dao) pico.getComponentInstance(Dao.class);
059:                StringBuffer log = (StringBuffer) pico
060:                        .getComponentInstance("log");
061:                verifyIntercepted(dao, log);
062:            }
063:
064:            public void testComponentInterceptor() {
065:                StringBuffer log = new StringBuffer();
066:
067:                pico.registerInterceptor(cuts.component("intercepted"), cuts
068:                        .allMethods(), new LoggingInterceptor(log));
069:                pico.registerComponentImplementation("intercepted",
070:                        DaoImpl.class);
071:                pico.registerComponentImplementation("notIntercepted",
072:                        DaoImpl.class);
073:
074:                Dao intercepted = (Dao) pico
075:                        .getComponentInstance("intercepted");
076:                Dao notIntercepted = (Dao) pico
077:                        .getComponentInstance("notIntercepted");
078:
079:                verifyIntercepted(intercepted, log);
080:                verifyNotIntercepted(notIntercepted, log);
081:            }
082:
083:            public void testContainerSuppliedComponentInterceptor() {
084:                pico.registerInterceptor(cuts.component("intercepted"), cuts
085:                        .allMethods(), LoggingInterceptor.class);
086:
087:                pico.registerComponentImplementation("log", StringBuffer.class);
088:                pico.registerComponentImplementation(LoggingInterceptor.class);
089:                pico.registerComponentImplementation("intercepted",
090:                        DaoImpl.class);
091:                pico.registerComponentImplementation("notIntercepted",
092:                        DaoImpl.class);
093:
094:                StringBuffer log = (StringBuffer) pico
095:                        .getComponentInstance("log");
096:                Dao intercepted = (Dao) pico
097:                        .getComponentInstance("intercepted");
098:                Dao notIntercepted = (Dao) pico
099:                        .getComponentInstance("notIntercepted");
100:
101:                verifyIntercepted(intercepted, log);
102:                verifyNotIntercepted(notIntercepted, log);
103:            }
104:
105:            public void testMixin() {
106:                pico.registerMixin(cuts.instancesOf(Dao.class),
107:                        IdentifiableMixin.class);
108:                pico.registerComponentImplementation(Dao.class, DaoImpl.class);
109:                Dao dao = (Dao) pico.getComponentInstance(Dao.class);
110:                verifyMixin(dao);
111:                assertTrue(dao instanceof  AnotherInterface);
112:            }
113:
114:            public void testContainerSuppliedMixin() {
115:                pico.registerComponentImplementation(IdGenerator.class,
116:                        IdGeneratorImpl.class);
117:                pico.registerComponentImplementation("order1",
118:                        OrderEntityImpl.class);
119:                pico.registerComponentImplementation("order2",
120:                        OrderEntityImpl.class);
121:                pico.registerMixin(cuts.instancesOf(OrderEntity.class),
122:                        new Class[] { Identifiable.class },
123:                        IdentifiableMixin.class);
124:
125:                Identifiable i1 = (Identifiable) pico
126:                        .getComponentInstance("order1");
127:                Identifiable i2 = (Identifiable) pico
128:                        .getComponentInstance("order2");
129:
130:                assertEquals(new Integer(1), i1.getId());
131:                assertEquals(new Integer(2), i2.getId());
132:
133:                i1.setId(new Integer(3));
134:                assertEquals(new Integer(3), i1.getId());
135:                assertEquals(new Integer(2), i2.getId());
136:            }
137:
138:            public void testComponentMixin() {
139:                pico.registerComponentImplementation("hasMixin", DaoImpl.class);
140:                pico.registerComponentImplementation("noMixin", DaoImpl.class);
141:
142:                pico.registerMixin(cuts.component("hasMixin"),
143:                        IdentifiableMixin.class);
144:
145:                Dao hasMixin = (Dao) pico.getComponentInstance("hasMixin");
146:                Dao noMixin = (Dao) pico.getComponentInstance("noMixin");
147:
148:                verifyMixin(hasMixin);
149:                verifyNoMixin(noMixin);
150:                assertTrue(hasMixin instanceof  AnotherInterface);
151:            }
152:
153:            public void testContainerSuppliedComponentMixin() {
154:                pico.registerComponentImplementation(IdGenerator.class,
155:                        IdGeneratorImpl.class);
156:                pico.registerMixin(cuts.componentName("hasMixin*"),
157:                        new Class[] { Identifiable.class },
158:                        IdentifiableMixin.class);
159:                pico.registerComponentImplementation("hasMixin1",
160:                        OrderEntityImpl.class);
161:                pico.registerComponentImplementation("hasMixin2",
162:                        OrderEntityImpl.class);
163:                pico.registerComponentImplementation("noMixin",
164:                        OrderEntityImpl.class);
165:
166:                OrderEntity hasMixin1 = (OrderEntity) pico
167:                        .getComponentInstance("hasMixin1");
168:                OrderEntity hasMixin2 = (OrderEntity) pico
169:                        .getComponentInstance("hasMixin2");
170:                OrderEntity noMixin = (OrderEntity) pico
171:                        .getComponentInstance("noMixin");
172:
173:                assertTrue(hasMixin1 instanceof  Identifiable);
174:                assertTrue(hasMixin2 instanceof  Identifiable);
175:                assertFalse(noMixin instanceof  Identifiable);
176:
177:                assertEquals(new Integer(1), ((Identifiable) hasMixin1).getId());
178:                assertEquals(new Integer(2), ((Identifiable) hasMixin2).getId());
179:            }
180:
181:            public void testMixinExplicitInterfaces() {
182:                pico.registerMixin(cuts.instancesOf(Dao.class),
183:                        new Class[] { Identifiable.class },
184:                        IdentifiableMixin.class);
185:                pico.registerComponentImplementation(Dao.class, DaoImpl.class);
186:                Dao dao = (Dao) pico.getComponentInstance(Dao.class);
187:                verifyMixin(dao);
188:                assertFalse(dao instanceof  AnotherInterface);
189:            }
190:
191:            public void testComponentMixinExplicitInterfaces() {
192:                pico.registerComponentImplementation("hasMixin", DaoImpl.class);
193:                pico.registerComponentImplementation("noMixin", DaoImpl.class);
194:
195:                pico.registerMixin(cuts.component("hasMixin"),
196:                        new Class[] { Identifiable.class },
197:                        IdentifiableMixin.class);
198:
199:                Dao hasMixin = (Dao) pico.getComponentInstance("hasMixin");
200:                Dao noMixin = (Dao) pico.getComponentInstance("noMixin");
201:
202:                verifyMixin(hasMixin);
203:                verifyNoMixin(noMixin);
204:
205:                assertFalse(hasMixin instanceof  AnotherInterface);
206:            }
207:
208:            public void testCreateWithParentContainer() {
209:                MutablePicoContainer parent = new DefaultPicoContainer();
210:                parent.registerComponentInstance("key", "value");
211:                AspectablePicoContainerFactory containerFactory = new DynaopAspectablePicoContainerFactory();
212:                PicoContainer child = containerFactory.createContainer(parent);
213:                assertEquals("value", child.getComponentInstance("key"));
214:            }
215:
216:            public void testMakeChildContainer() {
217:                AspectablePicoContainerFactory aspectableContainerFactory = new DynaopAspectablePicoContainerFactory();
218:                AspectablePicoContainer parent = aspectableContainerFactory
219:                        .createContainer();
220:                parent.registerComponentImplementation("t1",
221:                        SimpleTouchable.class);
222:                AspectablePicoContainer child = aspectableContainerFactory
223:                        .makeChildContainer(parent);
224:                Object t1 = child.getParent().getComponentInstance("t1");
225:                assertNotNull(t1);
226:                assertTrue(t1 instanceof  SimpleTouchable);
227:            }
228:
229:            public void testInterfacesWithClassPointcut() {
230:                pico.registerComponentImplementation(Dao.class, DaoImpl.class);
231:                pico.registerMixin(cuts.instancesOf(Dao.class),
232:                        IdentifiableMixin.class);
233:                pico.registerInterfaces(cuts.instancesOf(Dao.class),
234:                        new Class[] { AnotherInterface.class });
235:                Dao dao = (Dao) pico.getComponentInstance(Dao.class);
236:                assertTrue(dao instanceof  Identifiable);
237:                assertTrue(dao instanceof  AnotherInterface);
238:            }
239:
240:            public void testInterfacesWithClassPointcutNoAdvice() {
241:                pico.registerComponentImplementation(Dao.class, DaoImpl.class);
242:                pico.registerInterfaces(cuts.instancesOf(Dao.class),
243:                        new Class[] { AnotherInterface.class });
244:                Dao dao = (Dao) pico.getComponentInstance(Dao.class);
245:
246:                // dynaop doesn't add any interfaces if there's no advice applied to the
247:                // object:
248:                assertFalse(dao instanceof  AnotherInterface);
249:            }
250:
251:            public void testInterfacesWithComponentPointcut() {
252:                pico.registerComponentImplementation(Dao.class, DaoImpl.class);
253:                pico.registerMixin(cuts.component(Dao.class),
254:                        IdentifiableMixin.class);
255:                pico.registerInterfaces(cuts.component(Dao.class),
256:                        new Class[] { AnotherInterface.class });
257:                Dao dao = (Dao) pico.getComponentInstance(Dao.class);
258:                assertTrue(dao instanceof  Identifiable);
259:                assertTrue(dao instanceof  AnotherInterface);
260:            }
261:
262:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.