Source Code Cross Referenced for GenericFailureInteraction.java in  » Testing » mockrunner-0.4 » com » mockrunner » connector » 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 » Testing » mockrunner 0.4 » com.mockrunner.connector 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.mockrunner.connector;
002:
003:        import javax.resource.ResourceException;
004:        import javax.resource.cci.InteractionSpec;
005:        import javax.resource.cci.Record;
006:
007:        /**
008:         * This interaction implementor can be used to simulate failures. By default
009:         * it simply accepts every request and throws a <code>ResourceException</code>
010:         * for all <code>execute</code> calls. It can be disabled and it can be configured
011:         * to return <code>false</code> for {@link #execute(InteractionSpec, Record, Record)}
012:         * and <code>null</code> for {@link #execute(InteractionSpec, Record)} instead of
013:         * throwing an exception.
014:         */
015:        public class GenericFailureInteraction implements 
016:                InteractionImplementor {
017:            private boolean enabled;
018:            private boolean throwException;
019:            private ResourceException exception;
020:
021:            /**
022:             * Sets the default values, i.e. throwing a <code>ResourceException</code>.
023:             */
024:            public GenericFailureInteraction() {
025:                this (true);
026:            }
027:
028:            /**
029:             * Sets if failure values should be returned instead of throwing a
030:             * <code>ResourceException</code>.
031:             * @param throwException <code>true</code> thrown an exception,
032:             *                       <code>false</code> return failure values for <code>execute</code>
033:             */
034:            public GenericFailureInteraction(boolean throwException) {
035:                this (throwException, new ResourceException(
036:                        "Simulated test exception"));
037:            }
038:
039:            /**
040:             * Sets if failure values should be returned instead of throwing a
041:             * <code>ResourceException</code> and allows to set the exception
042:             * that will be thrown if exceptions are enabled.
043:             * @param throwException <code>true</code> thrown an exception,
044:             *                       <code>false</code> return failure values for <code>execute</code>
045:             * @param exception the exception to be thrown
046:             */
047:            public GenericFailureInteraction(boolean throwException,
048:                    ResourceException exception) {
049:                this .enabled = true;
050:                this .throwException = throwException;
051:                this .exception = exception;
052:            }
053:
054:            /**
055:             * Enables this implementor. {@link #canHandle(InteractionSpec, Record, Record)}
056:             * returns <code>true</code>, if this implementor is enabled.
057:             */
058:            public void enable() {
059:                this .enabled = true;
060:            }
061:
062:            /**
063:             * Disables this implementor. {@link #canHandle(InteractionSpec, Record, Record)}
064:             * returns <code>false</code>, if this implementor is disabled.
065:             */
066:            public void disable() {
067:                this .enabled = false;
068:            }
069:
070:            /**
071:             * Sets if failure values should be returned instead of throwing a
072:             * <code>ResourceException</code>.
073:             * @param throwException <code>true</code> thrown an exception,
074:             *                       <code>false</code> return failure values for <code>execute</code>
075:             */
076:            public void setThrowException(boolean throwException) {
077:                this .throwException = throwException;
078:            }
079:
080:            /**
081:             * Sets the exception that will be thrown if exceptions are enabled.
082:             * @param exception the exception to be thrown
083:             */
084:            public void setException(ResourceException exception) {
085:                this .exception = exception;
086:            }
087:
088:            /**
089:             * Returns <code>true</code> if this implementor is enabled and
090:             * <code>false</code> otherwise.
091:             */
092:            public boolean canHandle(InteractionSpec interactionSpec,
093:                    Record actualRequest, Record actualResponse) {
094:                return enabled;
095:            }
096:
097:            /**
098:             * Throws a <code>ResourceException</code> or returns <code>false</code>.
099:             * You can use {@link #setThrowException(boolean)} to configure this
100:             * behaviour.
101:             */
102:            public boolean execute(InteractionSpec interactionSpec,
103:                    Record actualRequest, Record actualResponse)
104:                    throws ResourceException {
105:                if (throwException) {
106:                    throw exception;
107:                }
108:                return false;
109:            }
110:
111:            /**
112:             * Throws a <code>ResourceException</code> or returns <code>null</code>.
113:             * You can use {@link #setThrowException(boolean)} to configure this
114:             * behaviour.
115:             */
116:            public Record execute(InteractionSpec interactionSpec,
117:                    Record actualRequest) throws ResourceException {
118:                if (throwException) {
119:                    throw exception;
120:                }
121:                return null;
122:            }
123:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.