01: package com.mockrunner.mock.connector.cci;
02:
03: import com.mockrunner.connector.InteractionHandler;
04:
05: /**
06: * Used to create all types of JCA mock objects.
07: * Maintains the necessary dependencies between the mock objects.
08: * If you use the mock objects returned by this
09: * factory in your tests you can be sure that they are all
10: * up to date. If you are using JNDI for obtaining the
11: * <code>MockConnectionFactory</code> you have to bind them to
12: * the mock JNDI context with {@link com.mockrunner.ejb.EJBTestModule#bindToContext}.
13: */
14: public class ConnectorMockObjectFactory {
15: private MockConnectionFactory connectionFactory;
16: private MockConnection connection;
17: private InteractionHandler interactionHandler;
18:
19: public ConnectorMockObjectFactory() {
20: connectionFactory = createMockConnectionFactory();
21: connection = createMockConnection();
22: connectionFactory.setConnection(connection);
23: interactionHandler = new InteractionHandler();
24: connection.setInteractionHandler(interactionHandler);
25: }
26:
27: /**
28: * Creates the {@link com.mockrunner.mock.connector.cci.MockConnection} using <code>new</code>.
29: * This method can be overridden to return a subclass of {@link com.mockrunner.mock.connector.cci.MockConnection}.
30: * @return the {@link com.mockrunner.mock.connector.cci.MockConnection}
31: */
32: public MockConnection createMockConnection() {
33: return new MockConnection();
34: }
35:
36: /**
37: * Creates the {@link com.mockrunner.mock.connector.cci.MockConnectionFactory} using <code>new</code>.
38: * This method can be overridden to return a subclass of {@link com.mockrunner.mock.connector.cci.MockConnectionFactory}.
39: * @return the {@link com.mockrunner.mock.connector.cci.MockConnectionFactory}
40: */
41: public MockConnectionFactory createMockConnectionFactory() {
42: return new MockConnectionFactory();
43: }
44:
45: /**
46: * Returns the {@link com.mockrunner.mock.connector.cci.MockConnection}.
47: * @return the {@link com.mockrunner.mock.connector.cci.MockConnection}
48: */
49: public MockConnection getMockConnection() {
50: return connection;
51: }
52:
53: /**
54: * Returns the {@link com.mockrunner.mock.connector.cci.MockConnectionFactory}.
55: * @return the {@link com.mockrunner.mock.connector.cci.MockConnectionFactory}
56: */
57: public MockConnectionFactory getMockConnectionFactory() {
58: return connectionFactory;
59: }
60:
61: /**
62: * Returns the {@link com.mockrunner.connector.InteractionHandler}.
63: * @return the {@link com.mockrunner.connector.InteractionHandler}
64: */
65: public InteractionHandler getInteractionHandler() {
66: return interactionHandler;
67: }
68: }
|