Source Code Cross Referenced for MethodInvocationExceptionTestCase.java in  » Template-Engine » Velocity » org » apache » velocity » test » 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 » Template Engine » Velocity » org.apache.velocity.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.velocity.test;
002:
003:        /*
004:         * Licensed to the Apache Software Foundation (ASF) under one
005:         * or more contributor license agreements.  See the NOTICE file
006:         * distributed with this work for additional information
007:         * regarding copyright ownership.  The ASF licenses this file
008:         * to you under the Apache License, Version 2.0 (the
009:         * "License"); you may not use this file except in compliance
010:         * with the License.  You may obtain a copy of the License at
011:         *
012:         *   http://www.apache.org/licenses/LICENSE-2.0
013:         *
014:         * Unless required by applicable law or agreed to in writing,
015:         * software distributed under the License is distributed on an
016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017:         * KIND, either express or implied.  See the License for the
018:         * specific language governing permissions and limitations
019:         * under the License.    
020:         */
021:
022:        import java.io.StringWriter;
023:
024:        import junit.framework.Test;
025:        import junit.framework.TestCase;
026:        import junit.framework.TestSuite;
027:
028:        import org.apache.velocity.VelocityContext;
029:        import org.apache.velocity.app.Velocity;
030:        import org.apache.velocity.exception.MethodInvocationException;
031:        import org.apache.velocity.runtime.log.NullLogChute;
032:
033:        /**
034:         * Tests if we can hand Velocity an arbitrary class for logging.
035:         *
036:         * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
037:         * @version $Id: MethodInvocationExceptionTestCase.java 477002 2006-11-20 01:07:43Z henning $
038:         */
039:        public class MethodInvocationExceptionTestCase extends TestCase {
040:            /**
041:             * Default constructor.
042:             * @param name
043:             */
044:            public MethodInvocationExceptionTestCase(String name) {
045:                super (name);
046:            }
047:
048:            public void setUp() throws Exception {
049:                /*
050:                 *  init() Runtime with defaults
051:                 */
052:
053:                Velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS,
054:                        NullLogChute.class.getName());
055:
056:                Velocity.init();
057:            }
058:
059:            public static Test suite() {
060:                return new TestSuite(MethodInvocationExceptionTestCase.class);
061:            }
062:
063:            /**
064:             * Runs the test :
065:             *
066:             *  uses the Velocity class to eval a string
067:             *  which accesses a method that throws an
068:             *  exception.
069:             *  @throws Exception
070:             */
071:            public void testNormalMethodInvocationException() throws Exception {
072:                String template = "$woogie.doException() boing!";
073:
074:                VelocityContext vc = new VelocityContext();
075:
076:                vc.put("woogie", this );
077:
078:                StringWriter w = new StringWriter();
079:
080:                try {
081:                    Velocity.evaluate(vc, w, "test", template);
082:                    fail("No exception thrown");
083:                } catch (MethodInvocationException mie) {
084:                    System.out.println("Caught MIE (good!) :");
085:                    System.out.println("  reference = "
086:                            + mie.getReferenceName());
087:                    System.out.println("  method    = " + mie.getMethodName());
088:
089:                    Throwable t = mie.getWrappedThrowable();
090:                    System.out.println("  throwable = " + t);
091:
092:                    if (t instanceof  Exception) {
093:                        System.out.println("  exception = "
094:                                + ((Exception) t).getMessage());
095:                    }
096:                }
097:            }
098:
099:            public void testGetterMethodInvocationException() throws Exception {
100:                VelocityContext vc = new VelocityContext();
101:                vc.put("woogie", this );
102:
103:                StringWriter w = new StringWriter();
104:
105:                /*
106:                 *  second test - to ensure that methods accessed via get+ construction
107:                 *  also work
108:                 */
109:
110:                String template = "$woogie.foo boing!";
111:
112:                try {
113:                    Velocity.evaluate(vc, w, "test", template);
114:                    fail("No exception thrown, second test.");
115:                } catch (MethodInvocationException mie) {
116:                    System.out.println("Caught MIE (good!) :");
117:                    System.out.println("  reference = "
118:                            + mie.getReferenceName());
119:                    System.out.println("  method    = " + mie.getMethodName());
120:
121:                    Throwable t = mie.getWrappedThrowable();
122:                    System.out.println("  throwable = " + t);
123:
124:                    if (t instanceof  Exception) {
125:                        System.out.println("  exception = "
126:                                + ((Exception) t).getMessage());
127:                    }
128:                }
129:            }
130:
131:            public void testCapitalizedGetterMethodInvocationException()
132:                    throws Exception {
133:                VelocityContext vc = new VelocityContext();
134:                vc.put("woogie", this );
135:
136:                StringWriter w = new StringWriter();
137:
138:                String template = "$woogie.Foo boing!";
139:
140:                try {
141:                    Velocity.evaluate(vc, w, "test", template);
142:                    fail("No exception thrown, third test.");
143:                } catch (MethodInvocationException mie) {
144:                    System.out.println("Caught MIE (good!) :");
145:                    System.out.println("  reference = "
146:                            + mie.getReferenceName());
147:                    System.out.println("  method    = " + mie.getMethodName());
148:
149:                    Throwable t = mie.getWrappedThrowable();
150:                    System.out.println("  throwable = " + t);
151:
152:                    if (t instanceof  Exception) {
153:                        System.out.println("  exception = "
154:                                + ((Exception) t).getMessage());
155:                    }
156:                }
157:            }
158:
159:            public void testSetterMethodInvocationException() throws Exception {
160:                VelocityContext vc = new VelocityContext();
161:                vc.put("woogie", this );
162:
163:                StringWriter w = new StringWriter();
164:
165:                String template = "#set($woogie.foo = 'lala') boing!";
166:
167:                try {
168:                    Velocity.evaluate(vc, w, "test", template);
169:                    fail("No exception thrown, set test.");
170:                } catch (MethodInvocationException mie) {
171:                    System.out.println("Caught MIE (good!) :");
172:                    System.out.println("  reference = "
173:                            + mie.getReferenceName());
174:                    System.out.println("  method    = " + mie.getMethodName());
175:
176:                    Throwable t = mie.getWrappedThrowable();
177:                    System.out.println("  throwable = " + t);
178:
179:                    if (t instanceof  Exception) {
180:                        System.out.println("  exception = "
181:                                + ((Exception) t).getMessage());
182:                    }
183:                }
184:            }
185:
186:            /**
187:             * test that no exception is thrown when in parameter to macro.
188:             * This is the way we expect the system to work, but it would be better
189:             * to throw an exception.
190:             * @throws Exception
191:             */
192:            public void testMacroInvocationException() throws Exception {
193:                VelocityContext vc = new VelocityContext();
194:                vc.put("woogie", this );
195:
196:                StringWriter w = new StringWriter();
197:
198:                String template = "#macro (macro1 $param) $param #end  #macro1($woogie.getFoo())";
199:
200:                try {
201:                    Velocity.evaluate(vc, w, "test", template);
202:                    fail("No exception thrown, macro invocation test.");
203:                } catch (MethodInvocationException mie) {
204:                    System.out.println("Caught MIE (good!) :");
205:                    System.out.println("  reference = "
206:                            + mie.getReferenceName());
207:                    System.out.println("  method    = " + mie.getMethodName());
208:
209:                    Throwable t = mie.getWrappedThrowable();
210:                    System.out.println("  throwable = " + t);
211:
212:                    if (t instanceof  Exception) {
213:                        System.out.println("  exception = "
214:                                + ((Exception) t).getMessage());
215:                    }
216:                } catch (Exception e) {
217:                    fail("Wrong exception thrown, test of exception within macro parameter");
218:                }
219:            }
220:
221:            public void doException() throws Exception {
222:                throw new NullPointerException();
223:            }
224:
225:            public void getFoo() throws Exception {
226:                throw new Exception("Hello from getFoo()");
227:            }
228:
229:            public void setFoo(String foo) throws Exception {
230:                throw new Exception("Hello from setFoo()");
231:            }
232:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.