Source Code Cross Referenced for BridgeBuilderTest.java in  » Web-Framework » Tapestry » org » apache » tapestry » ioc » internal » services » 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 » Web Framework » Tapestry » org.apache.tapestry.ioc.internal.services 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // Copyright 2006, 2007 The Apache Software Foundation
002:        //
003:        // Licensed under the Apache License, Version 2.0 (the "License");
004:        // you may not use this file except in compliance with the License.
005:        // You may obtain a copy of the License at
006:        //
007:        //     http://www.apache.org/licenses/LICENSE-2.0
008:        //
009:        // Unless required by applicable law or agreed to in writing, software
010:        // distributed under the License is distributed on an "AS IS" BASIS,
011:        // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012:        // See the License for the specific language governing permissions and
013:        // limitations under the License.
014:
015:        package org.apache.tapestry.ioc.internal.services;
016:
017:        import java.io.Serializable;
018:
019:        import org.apache.commons.logging.Log;
020:        import org.apache.tapestry.ioc.internal.IOCInternalTestCase;
021:        import org.apache.tapestry.ioc.services.ClassFactory;
022:        import org.testng.annotations.Test;
023:
024:        public class BridgeBuilderTest extends IOCInternalTestCase {
025:            private ClassFactory _classFactory = new ClassFactoryImpl();
026:
027:            @Test
028:            public void standard_interface_and_filter() {
029:                Log log = mockLog();
030:
031:                replay();
032:
033:                BridgeBuilder<StandardService, StandardFilter> bb = new BridgeBuilder<StandardService, StandardFilter>(
034:                        log, StandardService.class, StandardFilter.class,
035:                        _classFactory);
036:
037:                StandardFilter sf = new StandardFilter() {
038:                    public int run(int i, StandardService ss) {
039:                        return ss.run(i + 1);
040:                    }
041:                };
042:
043:                StandardService ss = new StandardService() {
044:                    public int run(int i) {
045:                        return i * 3;
046:                    }
047:                };
048:
049:                StandardService bridge = bb.instantiateBridge(ss, sf);
050:
051:                // The filter adds 1, then the service multiplies by 3.
052:                // (5 +_1) * 3 = 18.
053:
054:                assertEquals(bridge.run(5), 18);
055:
056:                // Since toString() is not part of the service interface,
057:                // it will be implemented in the bridge.
058:
059:                assertEquals(
060:                        bridge.toString(),
061:                        "<PipelineBridge from org.apache.tapestry.ioc.internal.services.StandardService to org.apache.tapestry.ioc.internal.services.StandardFilter>");
062:
063:                verify();
064:            }
065:
066:            @Test
067:            public void toString_part_of_service_interface() {
068:                Log log = mockLog();
069:
070:                replay();
071:
072:                BridgeBuilder<ToStringService, ToStringFilter> bb = new BridgeBuilder<ToStringService, ToStringFilter>(
073:                        log, ToStringService.class, ToStringFilter.class,
074:                        _classFactory);
075:
076:                ToStringFilter f = new ToStringFilter() {
077:                    public String toString(ToStringService s) {
078:                        return s.toString().toUpperCase();
079:                    }
080:                };
081:
082:                ToStringService s = new ToStringService() {
083:                    @Override
084:                    public String toString() {
085:                        return "Service";
086:                    }
087:                };
088:
089:                ToStringService bridge = bb.instantiateBridge(s, f);
090:
091:                assertEquals("SERVICE", bridge.toString());
092:
093:                verify();
094:            }
095:
096:            @Test
097:            public void service_interface_method_not_matched_in_filter_interface() {
098:                Log log = mockLog();
099:                ExtraServiceMethod next = newMock(ExtraServiceMethod.class);
100:                Serializable filter = newMock(Serializable.class);
101:
102:                log
103:                        .error(
104:                                "Method void extraServiceMethod() has no match in filter interface java.io.Serializable.",
105:                                null);
106:
107:                replay();
108:
109:                BridgeBuilder<ExtraServiceMethod, Serializable> bb = new BridgeBuilder<ExtraServiceMethod, Serializable>(
110:                        log, ExtraServiceMethod.class, Serializable.class,
111:                        _classFactory);
112:
113:                ExtraServiceMethod esm = bb.instantiateBridge(next, filter);
114:
115:                try {
116:                    esm.extraServiceMethod();
117:                    unreachable();
118:                } catch (RuntimeException ex) {
119:                    assertEquals(
120:                            ex.getMessage(),
121:                            "Method void extraServiceMethod() has no match in filter interface java.io.Serializable.");
122:                }
123:
124:                verify();
125:            }
126:
127:            @Test
128:            public void filter_interface_contains_extra_methods() {
129:                Log log = mockLog();
130:                Serializable next = newMock(Serializable.class);
131:                ExtraFilterMethod filter = newMock(ExtraFilterMethod.class);
132:
133:                log
134:                        .error(
135:                                "Method void extraFilterMethod() of filter interface "
136:                                        + "org.apache.tapestry.ioc.internal.services.ExtraFilterMethod does not have a matching method "
137:                                        + "in java.io.Serializable.", null);
138:
139:                replay();
140:
141:                BridgeBuilder<Serializable, ExtraFilterMethod> bb = new BridgeBuilder<Serializable, ExtraFilterMethod>(
142:                        log, Serializable.class, ExtraFilterMethod.class,
143:                        _classFactory);
144:
145:                assertNotNull(bb.instantiateBridge(next, filter));
146:
147:                verify();
148:            }
149:
150:            @Test
151:            public void service_parameter_in_middle_of_filter_method() {
152:                Log log = mockLog();
153:
154:                replay();
155:
156:                BridgeBuilder<MiddleService, MiddleFilter> bb = new BridgeBuilder<MiddleService, MiddleFilter>(
157:                        log, MiddleService.class, MiddleFilter.class,
158:                        _classFactory);
159:
160:                MiddleFilter mf = new MiddleFilter() {
161:                    public void execute(int count, char ch,
162:                            MiddleService service, StringBuilder buffer) {
163:                        service.execute(count, ch, buffer);
164:
165:                        buffer.append(' ');
166:
167:                        service.execute(count + 1, Character.toUpperCase(ch),
168:                                buffer);
169:
170:                    }
171:                };
172:
173:                MiddleService ms = new MiddleService() {
174:                    public void execute(int count, char ch, StringBuilder buffer) {
175:                        for (int i = 0; i < count; i++)
176:                            buffer.append(ch);
177:                    }
178:                };
179:
180:                // This also tests building the bridge methods with a void return type.
181:
182:                MiddleService bridge = bb.instantiateBridge(ms, mf);
183:
184:                StringBuilder buffer = new StringBuilder("CODE: ");
185:
186:                bridge.execute(3, 'a', buffer);
187:
188:                assertEquals("CODE: aaa AAAA", buffer.toString());
189:
190:                verify();
191:            }
192:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.