1
2
3
4
5
6
7
8
9
10
11 package org.mule.providers.jms;
12
13 import org.mule.MuleManager;
14 import org.mule.tck.AbstractMuleTestCase;
15
16 import java.util.HashMap;
17 import java.util.Map;
18
19 import javax.jms.Connection;
20 import javax.jms.ConnectionFactory;
21 import javax.jms.JMSException;
22 import javax.jms.QueueConnection;
23 import javax.jms.QueueConnectionFactory;
24
25 public class JmsConnectionFactoryTestCase extends AbstractMuleTestCase
26 {
27
28
29
30
31
32 public void testProviderPropertiesNotPassed() throws Exception
33 {
34
35
36
37 ((MuleManager)MuleManager.getInstance()).initialise();
38
39 JmsConnector connector = new JmsConnector();
40 Map providerProperties = new HashMap(1);
41 final String testProviderProperty = "providerProperty";
42 final String testValue = "TEST_VALUE";
43 providerProperties.put(testProviderProperty, testValue);
44 connector.setJndiProviderProperties(providerProperties);
45
46 ConnectionFactory cf = new TestConnectionFactory();
47 connector.setConnectionFactory(cf);
48
49 connector.initialise();
50
51 assertEquals("Provider properties should not be passed to the ConnectionFactory.", "NOT_SET",
52 ((TestConnectionFactory)cf).getProviderProperty());
53 }
54
55
56
57
58
59 public void testConnectionFactoryPropertiesPassed() throws Exception
60 {
61
62
63
64 ((MuleManager)MuleManager.getInstance()).initialise();
65
66 JmsConnector connector = new JmsConnector();
67 Map connectionFactoryProperties = new HashMap(1);
68 final String testConnectionFactoryProperty = "connectionFactoryProperty";
69 final String testValue = "TEST_VALUE";
70 connectionFactoryProperties.put(testConnectionFactoryProperty, testValue);
71 connector.setConnectionFactoryProperties(connectionFactoryProperties);
72
73 ConnectionFactory cf = new TestConnectionFactory();
74 connector.setConnectionFactory(cf);
75
76 connector.initialise();
77 connector.startConnector();
78
79 assertEquals("ConnectionFactory properties should be passed to the ConnectionFactory.", "TEST_VALUE",
80 ((TestConnectionFactory)cf).getConnectionFactoryProperty());
81 }
82
83 public static final class TestConnectionFactory implements QueueConnectionFactory
84 {
85 private String providerProperty = "NOT_SET";
86 private String connectionFactoryProperty = "NOT_SET";
87
88 public Connection createConnection() throws JMSException
89 {
90 return null;
91 }
92
93 public Connection createConnection(String string, String string1) throws JMSException
94 {
95 return null;
96 }
97
98 public String getProviderProperty()
99 {
100 return providerProperty;
101 }
102
103
104
105
106 public void setProviderProperty(final String providerProperty)
107 {
108 throw new IllegalStateException("Should never be called.");
109 }
110
111 public String getConnectionFactoryProperty()
112 {
113 return connectionFactoryProperty;
114 }
115
116
117
118
119 public void setConnectionFactoryProperty(final String connectionFactoryProperty)
120 {
121 this.connectionFactoryProperty = connectionFactoryProperty;
122 }
123
124 public QueueConnection createQueueConnection() throws JMSException
125 {
126 return null;
127 }
128
129 public QueueConnection createQueueConnection(String string, String string1) throws JMSException
130 {
131 return null;
132 }
133 }
134
135 }