Source Code Cross Referenced for LoggingDecoratorImplTest.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 org.apache.commons.logging.Log;
018:        import org.apache.tapestry.ioc.services.LoggingDecorator;
019:        import org.apache.tapestry.ioc.test.IOCTestCase;
020:        import org.testng.Assert;
021:        import org.testng.annotations.Test;
022:        import org.xml.sax.SAXParseException;
023:
024:        /**
025:         * Use the LoggingDecorator in a number of ways to verify its behavior. In some ways we are testing
026:         * the code dynamically generated by the LoggingDecorator as much as we are testing the decorator
027:         * itself -- one proves the other.
028:         */
029:        public class LoggingDecoratorImplTest extends IOCTestCase {
030:            public interface UpcaseService {
031:                String upcase(String input);
032:            }
033:
034:            public interface AdderService {
035:                long add(long operand1, long operand2);
036:            }
037:
038:            public interface ToStringService {
039:                String toString();
040:            }
041:
042:            public interface ExceptionService {
043:                void parse() throws SAXParseException;
044:            }
045:
046:            @Test
047:            public void void_method() {
048:                Log log = mockLog();
049:                Runnable delegate = mockRunnable();
050:
051:                train_isDebugEnabled(log, true);
052:                log.debug("[ENTER] run()");
053:
054:                delegate.run();
055:
056:                log.debug("[ EXIT] run");
057:
058:                replay();
059:
060:                LoggingDecorator ld = newLoggingDecorator();
061:                Runnable interceptor = ld.build(Runnable.class, delegate,
062:                        "foo.Bar", log);
063:
064:                interceptor.run();
065:
066:                assertEquals(interceptor.toString(),
067:                        "<Logging interceptor for foo.Bar(java.lang.Runnable)>");
068:
069:                verify();
070:            }
071:
072:            private LoggingDecoratorImpl newLoggingDecorator() {
073:                return new LoggingDecoratorImpl(new ClassFactoryImpl(),
074:                        new ExceptionTrackerImpl());
075:            }
076:
077:            @Test
078:            public void method_throws_runtime_exception() {
079:                Throwable t = new RuntimeException("From delegate.");
080:                Log log = mockLog();
081:                Runnable delegate = mockRunnable();
082:
083:                train_isDebugEnabled(log, true);
084:                log.debug("[ENTER] run()");
085:
086:                delegate.run();
087:                setThrowable(t);
088:
089:                train_isDebugEnabled(log, true);
090:
091:                log.debug("[ FAIL] run -- " + t.getClass().getName(), t);
092:
093:                replay();
094:
095:                LoggingDecorator ld = newLoggingDecorator();
096:                Runnable interceptor = ld.build(Runnable.class, delegate,
097:                        "foo.Bar", log);
098:
099:                try {
100:                    interceptor.run();
101:                    unreachable();
102:                } catch (RuntimeException ex) {
103:                    Assert.assertSame(ex, t);
104:                }
105:
106:                verify();
107:            }
108:
109:            @Test
110:            public void method_throws_checked_exception() throws Exception {
111:                Throwable t = new SAXParseException("From delegate.", null);
112:                Log log = mockLog();
113:                ExceptionService delegate = newMock(ExceptionService.class);
114:
115:                train_isDebugEnabled(log, true);
116:                log.debug("[ENTER] parse()");
117:
118:                delegate.parse();
119:                setThrowable(t);
120:
121:                train_isDebugEnabled(log, true);
122:
123:                log.debug("[ FAIL] parse -- " + t.getClass().getName(), t);
124:
125:                replay();
126:
127:                LoggingDecorator ld = newLoggingDecorator();
128:                ExceptionService interceptor = ld.build(ExceptionService.class,
129:                        delegate, "foo.Bar", log);
130:
131:                try {
132:                    interceptor.parse();
133:                    unreachable();
134:                } catch (SAXParseException ex) {
135:                    Assert.assertSame(ex, t);
136:                }
137:
138:                verify();
139:            }
140:
141:            @Test
142:            public void object_parameter_and_return_type() {
143:                Log log = mockLog();
144:                UpcaseService delegate = new UpcaseService() {
145:                    public String upcase(String input) {
146:                        return input.toUpperCase();
147:                    }
148:                };
149:
150:                train_isDebugEnabled(log, true);
151:                log.debug("[ENTER] upcase(\"barney\")");
152:
153:                log.debug("[ EXIT] upcase [\"BARNEY\"]");
154:
155:                replay();
156:
157:                LoggingDecorator ld = newLoggingDecorator();
158:                UpcaseService interceptor = ld.build(UpcaseService.class,
159:                        delegate, "foo.Bar", log);
160:
161:                assertEquals(interceptor.upcase("barney"), "BARNEY");
162:
163:                verify();
164:            }
165:
166:            @Test
167:            public void primitive_parameter_and_return_type() {
168:                Log log = mockLog();
169:                AdderService delegate = new AdderService() {
170:                    public long add(long operand1, long operand2) {
171:                        return operand1 + operand2;
172:                    }
173:                };
174:
175:                train_isDebugEnabled(log, true);
176:                log.debug("[ENTER] add(6, 13)");
177:
178:                log.debug("[ EXIT] add [19]");
179:
180:                replay();
181:
182:                LoggingDecorator ld = newLoggingDecorator();
183:                AdderService interceptor = ld.build(AdderService.class,
184:                        delegate, "foo.Bar", log);
185:
186:                assertEquals(interceptor.add(6, 13), 19);
187:
188:                verify();
189:            }
190:
191:            @Test
192:            public void to_string_method_in_service_interface_is_delegated() {
193:                Log log = mockLog();
194:                ToStringService delegate = new ToStringService() {
195:                    @Override
196:                    public String toString() {
197:                        return "FROM DELEGATE";
198:                    }
199:                };
200:
201:                train_isDebugEnabled(log, true);
202:                log.debug("[ENTER] toString()");
203:
204:                log.debug("[ EXIT] toString [\"FROM DELEGATE\"]");
205:
206:                replay();
207:
208:                LoggingDecorator ld = newLoggingDecorator();
209:                ToStringService interceptor = ld.build(ToStringService.class,
210:                        delegate, "foo.Bar", log);
211:
212:                assertEquals(interceptor.toString(), "FROM DELEGATE");
213:
214:                verify();
215:            }
216:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.