001 package com.mockrunner.mock.jms; 002 003 import com.mockrunner.jms.ConfigurationManager; 004 import com.mockrunner.jms.DestinationManager; 005 006 /** 007 * Used to create all types of JMS mock objects. 008 * Maintains the necessary dependencies between the mock objects. 009 * If you use the mock objects returned by this 010 * factory in your tests you can be sure that they are all 011 * up to date. If you are using JNDI for obtaining the 012 * connection factories you have to bind them to the mock JNDI context 013 * with {@link com.mockrunner.ejb.EJBTestModule#bindToContext}. 014 */ 015 public class JMSMockObjectFactory 016 { 017 private DestinationManager destinationManager; 018 private ConfigurationManager configurationManager; 019 private MockQueueConnectionFactory queueConnectionFactory; 020 private MockTopicConnectionFactory topicConnectionFactory; 021 private MockConnectionFactory connectionFactory; 022 023 /** 024 * Creates a new set of mock objects. 025 */ 026 public JMSMockObjectFactory() 027 { 028 destinationManager = new DestinationManager(); 029 configurationManager = new ConfigurationManager(); 030 queueConnectionFactory = createMockQueueConnectionFactory(); 031 topicConnectionFactory = createMockTopicConnectionFactory(); 032 connectionFactory = createMockConnectionFactory(); 033 } 034 035 /** 036 * Creates the {@link com.mockrunner.mock.jms.MockConnectionFactory} using <code>new</code>. 037 * This method can be overridden to return a subclass of {@link com.mockrunner.mock.jms.MockConnectionFactory}. 038 * @return the {@link com.mockrunner.mock.jms.MockConnectionFactory} 039 */ 040 public MockConnectionFactory createMockConnectionFactory() 041 { 042 return new MockConnectionFactory(destinationManager, configurationManager); 043 } 044 045 /** 046 * Creates the {@link com.mockrunner.mock.jms.MockTopicConnectionFactory} using <code>new</code>. 047 * This method can be overridden to return a subclass of {@link com.mockrunner.mock.jms.MockTopicConnectionFactory}. 048 * @return the {@link com.mockrunner.mock.jms.MockTopicConnectionFactory} 049 */ 050 public MockTopicConnectionFactory createMockTopicConnectionFactory() 051 { 052 return new MockTopicConnectionFactory(destinationManager, configurationManager); 053 } 054 055 /** 056 * Creates the {@link com.mockrunner.mock.jms.MockQueueConnectionFactory} using <code>new</code>. 057 * This method can be overridden to return a subclass of {@link com.mockrunner.mock.jms.MockQueueConnectionFactory}. 058 * @return the {@link com.mockrunner.mock.jms.MockQueueConnectionFactory} 059 */ 060 public MockQueueConnectionFactory createMockQueueConnectionFactory() 061 { 062 return new MockQueueConnectionFactory(destinationManager, configurationManager); 063 } 064 065 /** 066 * Returns the {@link com.mockrunner.jms.ConfigurationManager}. 067 * @return the {@link com.mockrunner.jms.ConfigurationManager} 068 */ 069 public ConfigurationManager getConfigurationManager() 070 { 071 return configurationManager; 072 } 073 074 /** 075 * Returns the {@link com.mockrunner.jms.DestinationManager}. 076 * @return the {@link com.mockrunner.jms.DestinationManager} 077 */ 078 public DestinationManager getDestinationManager() 079 { 080 return destinationManager; 081 } 082 083 /** 084 * Returns the {@link com.mockrunner.mock.jms.MockQueueConnectionFactory}. 085 * @return the {@link com.mockrunner.mock.jms.MockQueueConnectionFactory} 086 */ 087 public MockQueueConnectionFactory getMockQueueConnectionFactory() 088 { 089 return queueConnectionFactory; 090 } 091 092 /** 093 * Returns the {@link com.mockrunner.mock.jms.MockTopicConnectionFactory}. 094 * @return the {@link com.mockrunner.mock.jms.MockTopicConnectionFactory} 095 */ 096 public MockTopicConnectionFactory getMockTopicConnectionFactory() 097 { 098 return topicConnectionFactory; 099 } 100 101 /** 102 * Returns the {@link com.mockrunner.mock.jms.MockConnectionFactory}. 103 * @return the {@link com.mockrunner.mock.jms.MockConnectionFactory} 104 */ 105 public MockConnectionFactory getMockConnectionFactory() 106 { 107 return connectionFactory; 108 } 109 }