001    package com.mockrunner.mock.connector.cci;
002    
003    import com.mockrunner.connector.InteractionHandler;
004    
005    /**
006     * Used to create all types of JCA mock objects. 
007     * Maintains the necessary dependencies between the mock objects.
008     * If you use the mock objects returned by this
009     * factory in your tests you can be sure that they are all
010     * up to date. If you are using JNDI for obtaining the
011     * <code>MockConnectionFactory</code> you have to bind them to 
012     * the mock JNDI context with {@link com.mockrunner.ejb.EJBTestModule#bindToContext}.
013     */
014    public class ConnectorMockObjectFactory
015    {
016        private MockConnectionFactory connectionFactory;
017        private MockConnection connection;
018        private InteractionHandler interactionHandler;
019        
020        public ConnectorMockObjectFactory()
021        {
022            connectionFactory = createMockConnectionFactory();
023            connection = createMockConnection();
024            connectionFactory.setConnection(connection);
025            interactionHandler = new InteractionHandler();
026            connection.setInteractionHandler(interactionHandler);
027        }
028    
029        /**
030         * Creates the {@link com.mockrunner.mock.connector.cci.MockConnection} using <code>new</code>.
031         * This method can be overridden to return a subclass of {@link com.mockrunner.mock.connector.cci.MockConnection}.
032         * @return the {@link com.mockrunner.mock.connector.cci.MockConnection}
033         */
034        public MockConnection createMockConnection()
035        {
036            return new MockConnection();
037        }
038    
039        /**
040         * Creates the {@link com.mockrunner.mock.connector.cci.MockConnectionFactory} using <code>new</code>.
041         * This method can be overridden to return a subclass of {@link com.mockrunner.mock.connector.cci.MockConnectionFactory}.
042         * @return the {@link com.mockrunner.mock.connector.cci.MockConnectionFactory}
043         */
044        public MockConnectionFactory createMockConnectionFactory()
045        {
046            return new MockConnectionFactory();
047        }
048    
049        /**
050         * Returns the {@link com.mockrunner.mock.connector.cci.MockConnection}.
051         * @return the {@link com.mockrunner.mock.connector.cci.MockConnection}
052         */
053        public MockConnection getMockConnection()
054        {
055            return connection;
056        }
057    
058        /**
059         * Returns the {@link com.mockrunner.mock.connector.cci.MockConnectionFactory}.
060         * @return the {@link com.mockrunner.mock.connector.cci.MockConnectionFactory}
061         */
062        public MockConnectionFactory getMockConnectionFactory()
063        {
064            return connectionFactory;
065        }
066    
067        /**
068         * Returns the {@link com.mockrunner.connector.InteractionHandler}.
069         * @return the {@link com.mockrunner.connector.InteractionHandler}
070         */
071        public InteractionHandler getInteractionHandler()
072        {
073            return interactionHandler;
074        }
075    }