1 /***
2 * Redistribution and use of this software and associated documentation
3 * ("Software"), with or without modification, are permitted provided
4 * that the following conditions are met:
5 *
6 * 1. Redistributions of source code must retain copyright
7 * statements and notices. Redistributions must also contain a
8 * copy of this document.
9 *
10 * 2. Redistributions in binary form must reproduce the
11 * above copyright notice, this list of conditions and the
12 * following disclaimer in the documentation and/or other
13 * materials provided with the distribution.
14 *
15 * 3. The name "Exolab" must not be used to endorse or promote
16 * products derived from this Software without prior written
17 * permission of Exoffice Technologies. For written permission,
18 * please contact tma@netspace.net.au.
19 *
20 * 4. Products derived from this Software may not be called "Exolab"
21 * nor may "Exolab" appear in their names without prior written
22 * permission of Exoffice Technologies. Exolab is a registered
23 * trademark of Exoffice Technologies.
24 *
25 * 5. Due credit should be given to the Exolab Project
26 * (http://www.exolab.org/).
27 *
28 * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32 * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39 * OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * Copyright 2003-2004 (C) Exoffice Technologies Inc. All Rights Reserved.
42 *
43 * $Id: AuthTest.java,v 1.2 2004/02/03 07:32:07 tanderson Exp $
44 */
45 package org.exolab.jmscts.test.connection;
46
47 import javax.jms.JMSException;
48 import javax.jms.JMSSecurityException;
49 import javax.jms.QueueConnection;
50 import javax.jms.QueueConnectionFactory;
51 import javax.jms.TopicConnection;
52 import javax.jms.TopicConnectionFactory;
53
54 import junit.framework.Test;
55
56 import org.exolab.jmscts.core.AbstractConnectionFactoryTestCase;
57 import org.exolab.jmscts.core.TestContext;
58 import org.exolab.jmscts.core.TestCreator;
59 import org.exolab.jmscts.core.TestProperties;
60
61
62 /***
63 * This class tests connection authorisation
64 *
65 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a>
66 * @version $Revision: 1.2 $
67 */
68 public class AuthTest extends AbstractConnectionFactoryTestCase {
69
70
71 /***
72 * Create a new <code>AuthTest</code>.
73 *
74 * @param name the name of test case
75 */
76 public AuthTest(String name) {
77 super(name);
78 }
79
80 /***
81 * Sets up the test suite
82 *
83 * @return an instance of this class that may be run by
84 * {@link org.exolab.jmscts.core.JMSTestRunner}
85 */
86 public static Test suite() {
87 return TestCreator.createConnectionFactoryTest(AuthTest.class);
88 }
89
90 /***
91 * Verifies that a QueueConnection can be created, using a valid
92 * username and password
93 *
94 * @jmscts.requirement connection.authentication
95 * @jmscts.factory QueueConnectionFactory
96 * @throws Exception for any error
97 */
98 public void testQueueAuth() throws Exception {
99 TestContext context = getContext();
100 QueueConnectionFactory factory =
101 (QueueConnectionFactory) context.getConnectionFactory();
102 QueueConnection connection = null;
103 String user = TestProperties.getString("valid.username", "CHANGE_ME");
104 String password = TestProperties.getString("valid.password",
105 "CHANGE_ME");
106
107 try {
108 connection = factory.createQueueConnection(user, password);
109 assertNotNull("QueueConnection is null", connection);
110 } catch (JMSException exception) {
111 fail("Expected creation of QueueConnection to succeed with "
112 + "username=" + user + ", password=" + password);
113 } finally {
114 if (connection != null) {
115 connection.close();
116 }
117 }
118 }
119
120 /***
121 * Verifies that a QueueConnection cannot be created, when using an invalid
122 * username and password
123 *
124 * @jmscts.requirement connection.authentication
125 * @jmscts.factory QueueConnectionFactory
126 * @throws Exception for any error
127 */
128 public void testInvalidQueueAuth() throws Exception {
129 TestContext context = getContext();
130 QueueConnectionFactory factory =
131 (QueueConnectionFactory) context.getConnectionFactory();
132 QueueConnection connection = null;
133 String user = TestProperties.getString("invalid.username",
134 "CHANGE_ME");
135 String password = TestProperties.getString("invalid.password",
136 "CHANGE_ME");
137
138 try {
139 connection = factory.createQueueConnection(user, password);
140 fail("Expected creation of QueueConnection to fail with "
141 + "username=" + user + ", password=" + password);
142 } catch (JMSSecurityException ignore) {
143 // expected behaviour
144 } catch (JMSException exception) {
145 fail("Expected JMSSecurityException to be thrown, but got "
146 + "exception type=" + exception.getClass().getName() + ": "
147 + exception);
148 } finally {
149 if (connection != null) {
150 connection.close();
151 }
152 }
153 }
154
155 /***
156 * Verifies that a TopicConnection can be created, using a valid
157 * username and password
158 *
159 * @jmscts.requirement connection.authentication
160 * @jmscts.factory TopicConnectionFactory
161 * @throws Exception for any error
162 */
163 public void testTopicAuth() throws Exception {
164 TestContext context = getContext();
165 TopicConnectionFactory factory =
166 (TopicConnectionFactory) context.getConnectionFactory();
167 TopicConnection connection = null;
168 String user = TestProperties.getString("valid.username", "CHANGE_ME");
169 String password = TestProperties.getString("valid.password",
170 "CHANGE_ME");
171
172 try {
173 connection = factory.createTopicConnection(user, password);
174 assertNotNull("TopicConnection is null", connection);
175 } catch (JMSException exception) {
176 fail("Expected creation of TopicConnection to succeed with user="
177 + user + ", password=" + password);
178 } finally {
179 if (connection != null) {
180 connection.close();
181 }
182 }
183 }
184
185 /***
186 * Verifies that a TopicConnection cannot be created, when using an invalid
187 * username and password
188 *
189 * @jmscts.requirement connection.authentication
190 * @jmscts.factory TopicConnectionFactory
191 * @throws Exception for any error
192 */
193 public void testInvalidTopicAuth() throws Exception {
194 TestContext context = getContext();
195 TopicConnectionFactory factory =
196 (TopicConnectionFactory) context.getConnectionFactory();
197 TopicConnection connection = null;
198 String user = TestProperties.getString("invalid.username",
199 "CHANGE_ME");
200 String password = TestProperties.getString("invalid.password",
201 "CHANGE_ME");
202
203 try {
204 connection = factory.createTopicConnection(user, password);
205 fail("Expected creation of TopicConnection to fail with user="
206 + user + ", password=" + password);
207 } catch (JMSSecurityException ignore) {
208 // expected behaviour
209 } catch (JMSException exception) {
210 fail("Expected JMSSecurityException to be thrown, but got "
211 + "exception type=" + exception.getClass().getName() + ": "
212 + exception);
213 } finally {
214 if (connection != null) {
215 connection.close();
216 }
217 }
218 }
219
220 }
This page was automatically generated by Maven