Source Code Cross Referenced for ConnectorTestModule.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 java.util.List;
004:
005:        import javax.resource.cci.RecordFactory;
006:
007:        import com.mockrunner.base.NestedApplicationException;
008:        import com.mockrunner.base.VerifyFailedException;
009:        import com.mockrunner.mock.connector.cci.ConnectorMockObjectFactory;
010:        import com.mockrunner.mock.connector.cci.MockInteraction;
011:        import com.mockrunner.mock.connector.cci.MockLocalTransaction;
012:        import com.mockrunner.mock.connector.cci.MockRecordFactory;
013:
014:        /**
015:         * Module for JCA tests.
016:         */
017:        public class ConnectorTestModule {
018:            private ConnectorMockObjectFactory mockFactory;
019:
020:            public ConnectorTestModule(ConnectorMockObjectFactory mockFactory) {
021:                this .mockFactory = mockFactory;
022:            }
023:
024:            /**
025:             * Returns the {@link InteractionHandler}.
026:             * @return the {@link InteractionHandler}
027:             */
028:            public InteractionHandler getInteractionHandler() {
029:                return mockFactory.getInteractionHandler();
030:            }
031:
032:            private MockRecordFactory getMockRecordFactory() {
033:                try {
034:                    RecordFactory factory = mockFactory
035:                            .getMockConnectionFactory().getRecordFactory();
036:                    if (factory instanceof  MockRecordFactory) {
037:                        return (MockRecordFactory) factory;
038:                    }
039:                    return null;
040:                } catch (Exception exc) {
041:                    throw new NestedApplicationException(exc);
042:                }
043:            }
044:
045:            /**
046:             * Returns a list of all created <code>Interaction</code> objects
047:             * by delegating to {@link com.mockrunner.mock.connector.cci.MockConnection#getInteractionList()}.
048:             * @return the <code>List</code> of all created <code>Interaction</code> objects
049:             */
050:            public List getInteractionList() {
051:                return mockFactory.getMockConnection().getInteractionList();
052:            }
053:
054:            /**
055:             * Returns a list of all created indexed records
056:             * by delegating to {@link com.mockrunner.mock.connector.cci.MockRecordFactory#getCreatedIndexedRecords()}.
057:             * @return the <code>List</code> of all created indexed records
058:             */
059:            public List getCreatedIndexedRecords() {
060:                return getMockRecordFactory().getCreatedIndexedRecords();
061:            }
062:
063:            /**
064:             * Returns a list of created indexed records that match the specified name
065:             * by delegating to {@link com.mockrunner.mock.connector.cci.MockRecordFactory#getCreatedIndexedRecords(String)}.
066:             * @param recordName the name of the record
067:             * @return the <code>List</code> of matching indexed records
068:             */
069:            public List getCreatedIndexedRecords(String recordName) {
070:                return getMockRecordFactory().getCreatedIndexedRecords(
071:                        recordName);
072:            }
073:
074:            /**
075:             * Returns a list of all created mapped records
076:             * by delegating to {@link com.mockrunner.mock.connector.cci.MockRecordFactory#getCreatedMappedRecords()}.
077:             * @return the <code>List</code> of all created mapped records
078:             */
079:            public List getCreatedMappedRecords() {
080:                return getMockRecordFactory().getCreatedMappedRecords();
081:            }
082:
083:            /**
084:             * Returns a list of created mapped records that match the specified name
085:             * by delegating to {@link com.mockrunner.mock.connector.cci.MockRecordFactory#getCreatedMappedRecords(String)}.
086:             * @param recordName the name of the record
087:             * @return the <code>List</code> of matching mapped records
088:             */
089:            public List getCreatedMappedRecords(String recordName) {
090:                return getMockRecordFactory().getCreatedMappedRecords(
091:                        recordName);
092:            }
093:
094:            /**
095:             * Verifies that the connection is closed.
096:             * @throws VerifyFailedException if verification fails
097:             */
098:            public void verifyConnectionClosed() {
099:                if (!mockFactory.getMockConnection().isClosed()) {
100:                    throw new VerifyFailedException("Connection is not closed.");
101:                }
102:            }
103:
104:            /**
105:             * Verifies that all interactions are closed.
106:             * @throws VerifyFailedException if verification fails
107:             */
108:            public void verifyAllInteractionsClosed() {
109:                List interactions = getInteractionList();
110:                for (int ii = 0; ii < interactions.size(); ii++) {
111:                    MockInteraction interaction = (MockInteraction) interactions
112:                            .get(ii);
113:                    if (!interaction.isClosed()) {
114:                        throw new VerifyFailedException(
115:                                "Interaction with index " + ii
116:                                        + " is not closed.");
117:                    }
118:                }
119:            }
120:
121:            /**
122:             * Verifies that the specified interaction is closed.
123:             * @param index the index of the <code>Interaction</code>
124:             * @throws VerifyFailedException if verification fails
125:             */
126:            public void verifyInteractionClosed(int index) {
127:                List interactions = getInteractionList();
128:                if (index >= interactions.size()) {
129:                    throw new VerifyFailedException("Interaction with index "
130:                            + index + " does not exist, only "
131:                            + interactions.size() + " interactions.");
132:                }
133:                MockInteraction interaction = (MockInteraction) interactions
134:                        .get(index);
135:                if (!interaction.isClosed()) {
136:                    throw new VerifyFailedException("Interaction with index "
137:                            + index + " is not closed.");
138:                }
139:            }
140:
141:            /**
142:             * Verifies that <code>expected</code> number of indexed records
143:             * have been created.
144:             * @param expected the expected number of indexed records
145:             * @throws VerifyFailedException if verification fails
146:             */
147:            public void verifyNumberCreatedIndexedRecords(int expected) {
148:                int actual = getMockRecordFactory()
149:                        .getNumberCreatedIndexedRecords();
150:                if (actual != expected) {
151:                    throw new VerifyFailedException("Expected " + expected
152:                            + " indexed records, actual " + actual
153:                            + " indexed records");
154:                }
155:            }
156:
157:            /**
158:             * Verifies that <code>expected</code> number of indexed records
159:             * with the specified name have been created.
160:             * @param recordName the name of the record
161:             * @param expected the expected number of indexed records
162:             * @throws VerifyFailedException if verification fails
163:             */
164:            public void verifyNumberCreatedIndexedRecords(String recordName,
165:                    int expected) {
166:                List list = getCreatedIndexedRecords(recordName);
167:                if (list.size() != expected) {
168:                    throw new VerifyFailedException("Expected " + expected
169:                            + " indexed records with the name " + recordName
170:                            + ", actual " + list.size() + " indexed records");
171:                }
172:            }
173:
174:            /**
175:             * Verifies that <code>expected</code> number of mapped records
176:             * have been created.
177:             * @param expected the expected number of mapped records
178:             * @throws VerifyFailedException if verification fails
179:             */
180:            public void verifyNumberCreatedMappedRecords(int expected) {
181:                int actual = getMockRecordFactory()
182:                        .getNumberCreatedMappedRecords();
183:                if (actual != expected) {
184:                    throw new VerifyFailedException("Expected " + expected
185:                            + " mapped records, actual " + actual
186:                            + " mapped records");
187:                }
188:            }
189:
190:            /**
191:             * Verifies that <code>expected</code> number of mapped records
192:             * with the specified name have been created.
193:             * @param recordName the name of the record
194:             * @param expected the expected number of mapped records
195:             * @throws VerifyFailedException if verification fails
196:             */
197:            public void verifyNumberCreatedMappedRecords(String recordName,
198:                    int expected) {
199:                List list = getCreatedMappedRecords(recordName);
200:                if (list.size() != expected) {
201:                    throw new VerifyFailedException("Expected " + expected
202:                            + " mapped records with the name " + recordName
203:                            + ", actual " + list.size() + " mapped records");
204:                }
205:            }
206:
207:            /**
208:             * Verifies that the current local transaction was committed.
209:             * @throws VerifyFailedException if verification fails
210:             */
211:            public void verifyLocalTransactionCommitted() {
212:                MockLocalTransaction transaction = mockFactory
213:                        .getMockConnection().getMockLocalTransaction();
214:                if (!transaction.wasCommitCalled()) {
215:                    throw new VerifyFailedException(
216:                            "Local transaction not committed");
217:                }
218:            }
219:
220:            /**
221:             * Verifies that the current local transaction was not committed.
222:             * @throws VerifyFailedException if verification fails
223:             */
224:            public void verifyLocalTransactionNotCommitted() {
225:                MockLocalTransaction transaction = mockFactory
226:                        .getMockConnection().getMockLocalTransaction();
227:                if (transaction.wasCommitCalled()) {
228:                    throw new VerifyFailedException(
229:                            "Local transaction was committed");
230:                }
231:            }
232:
233:            /**
234:             * Verifies that the current local transaction was rolled back.
235:             * @throws VerifyFailedException if verification fails
236:             */
237:            public void verifyLocalTransactionRolledBack() {
238:                MockLocalTransaction transaction = mockFactory
239:                        .getMockConnection().getMockLocalTransaction();
240:                if (!transaction.wasRollbackCalled()) {
241:                    throw new VerifyFailedException(
242:                            "Local transaction not rolled back");
243:                }
244:            }
245:
246:            /**
247:             * Verifies that the current local transaction was not rolled back.
248:             * @throws VerifyFailedException if verification fails
249:             */
250:            public void verifyLocalTransactionNotRolledBack() {
251:                MockLocalTransaction transaction = mockFactory
252:                        .getMockConnection().getMockLocalTransaction();
253:                if (transaction.wasRollbackCalled()) {
254:                    throw new VerifyFailedException(
255:                            "Local transaction was rolled back");
256:                }
257:            }
258:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.