KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exolab > jms > net > tcp > connector > TCPSRequestInfoTest


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 info@exolab.org.
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 2005 (C) Exoffice Technologies Inc. All Rights Reserved.
42  *
43  * $Id: TCPSRequestInfoTest.java,v 1.1 2005/05/03 13:46:02 tanderson Exp $
44  */

45 package org.exolab.jms.net.tcp.connector;
46
47 import junit.framework.TestCase;
48
49 import org.exolab.jms.net.tcp.TCPSRequestInfo;
50 import org.exolab.jms.net.uri.URI;
51 import org.exolab.jms.net.util.Properties;
52 import org.exolab.jms.net.util.SSLProperties;
53 import org.exolab.jms.net.socket.SocketRequestInfo;
54 import org.exolab.jms.net.socket.SocketRequestInfoTest;
55
56
57 /**
58  * Tests the {@link TCPSRequestInfo} class.
59  *
60  * @author <a HREF="mailto:tma@netspace.net.au">Tim Anderson</a>
61  * @version $Revision: 1.1 $ $Date: 2005/05/03 13:46:02 $
62  */

63 public class TCPSRequestInfoTest extends TestCase {
64
65     /**
66      * Construct a new <code>TCPSRequestInfoTest</code>.
67      *
68      * @param name the name of the test to run
69      */

70     public TCPSRequestInfoTest(String JavaDoc name) {
71         super(name);
72     }
73
74     /**
75      * Tests accessors.
76      * <p/>
77      * NOTE: accessors provided by {@link SocketRequestInfo} are tested in
78      * {@link SocketRequestInfoTest}.
79      *
80      * @throws Exception for any error
81      */

82     public void testAccessors() throws Exception JavaDoc {
83         final String JavaDoc uri = "tcps://localhost:8050";
84         final SSLProperties ssl = new SSLProperties();
85         final boolean clientAuthReqd = true;
86         final boolean clientAuthNotReqd = false;
87
88         TCPSRequestInfo info = populate(uri, null, true, 10, ssl,
89                                         clientAuthReqd);
90
91         assertEquals(ssl, info.getSSLProperties());
92         assertEquals(clientAuthReqd, info.getNeedClientAuth());
93
94         info.setNeedClientAuth(clientAuthNotReqd);
95         assertEquals(clientAuthNotReqd, info.getNeedClientAuth());
96     }
97
98     /**
99      * Tests {@link TCPSRequestInfo#equals}.
100      *
101      * @throws Exception for any error
102      */

103     public void testEquals() throws Exception JavaDoc {
104         final String JavaDoc uri = "tcp://localhost:8050";
105         final String JavaDoc alternativeURI = "tcp://foo.org:9090";
106         final boolean bindAll = true;
107         final int maxThreads = 23;
108         final SSLProperties ssl = new SSLProperties();
109         final boolean clientAuthReqd = true;
110         final boolean clientAuthNotReqd = false;
111
112         TCPSRequestInfo info1 = populate(uri, alternativeURI, bindAll,
113                                          maxThreads, ssl, clientAuthReqd);
114         TCPSRequestInfo info2 = populate(uri, alternativeURI, bindAll,
115                                          maxThreads, ssl, clientAuthReqd);
116         assertEquals(info1, info2);
117
118         TCPSRequestInfo info3 = populate(uri, alternativeURI, bindAll,
119                                          maxThreads, null, clientAuthReqd);
120         assertFalse(info1.equals(info3));
121
122         TCPSRequestInfo info4 = populate(uri, alternativeURI, bindAll,
123                                          maxThreads, ssl, clientAuthNotReqd);
124         assertFalse(info1.equals(info4));
125     }
126
127     /**
128      * Tests properties.
129      *
130      * @throws Exception for any error
131      */

132     public void testProperties() throws Exception JavaDoc {
133         final String JavaDoc prefix = "org.exolab.jms.net.tcps.";
134         final String JavaDoc uri = "tcps://exolab.org:4040/";
135         final String JavaDoc alternativeURI = "tcps://localhost:4040/";
136         final boolean bindAll = false;
137         final int maxThreads = 24;
138         final SSLProperties ssl = new SSLProperties();
139         final boolean clientAuthReqd = true;
140
141         ssl.setKeyStore("keyStore");
142         ssl.setKeyStorePassword("keyStorePassword");
143         ssl.setKeyStoreType("JKS");
144         ssl.setTrustStore("trustStore");
145         ssl.setTrustStorePassword("trustStorePassword");
146         ssl.setTrustStoreType("PCKS12");
147
148         Properties properties = new Properties(prefix);
149         TCPSRequestInfo info1 = populate(uri, alternativeURI, bindAll,
150                                          maxThreads, ssl, clientAuthReqd);
151         info1.export(properties);
152
153         TCPSRequestInfo info2 = new TCPSRequestInfo(new URI(uri),
154                                                     properties);
155         assertEquals(info1, info2);
156
157         assertEquals(ssl, info2.getSSLProperties());
158         assertEquals(clientAuthReqd, info2.getNeedClientAuth());
159     }
160
161     /**
162      * Helper to populate an {@link TCPSRequestInfo}.
163      *
164      * @param uri the URI
165      * @param alternativeURI the alternative URI
166      * @param bindAll indicates how socket connections should be
167      * accepted, on a multi-homed host
168      * @param maxThreads the maximum no. of threads to handle concurrent
169      * invocations
170      * @param ssl SSL properties
171      * @param needClientAuth if <code>true</code>, the clients must authenticate
172      * themselves.
173      * @return a new <code>TCPSRequestInfo</code>
174      * @throws Exception for any error
175      */

176     private TCPSRequestInfo populate(String JavaDoc uri, String JavaDoc alternativeURI,
177                                      boolean bindAll, int maxThreads,
178                                      SSLProperties ssl, boolean needClientAuth)
179             throws Exception JavaDoc {
180         TCPSRequestInfo info = new TCPSRequestInfo(new URI(uri));
181         if (alternativeURI != null) {
182             info.setAlternativeURI(new URI(alternativeURI));
183         }
184         info.setBindAll(bindAll);
185         info.setMaxThreads(maxThreads);
186         info.setSSLProperties(ssl);
187         info.setNeedClientAuth(needClientAuth);
188         return info;
189     }
190
191 }
192
Popular Tags