KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > orb > AlternateIIOPAddressTest


1 package org.jacorb.test.orb;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1997-2005 Gerald Brose.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
21  * MA 02110-1301, USA.
22  */

23
24 import java.util.Properties JavaDoc;
25
26 import junit.framework.*;
27
28 import org.jacorb.test.*;
29 import org.jacorb.test.common.*;
30
31 /**
32  * Tests components of type TAG_ALTERNATE_IIOP_ADDRESS within IORs.
33  *
34  * @jacorb-since 2.2
35  * @author Andre Spiegel
36  * @version $Id: AlternateIIOPAddressTest.java,v 1.5 2005/05/13 13:40:48 andre.spiegel Exp $
37  */

38 public class AlternateIIOPAddressTest extends ClientServerTestCase
39 {
40     protected IIOPAddressServer server = null;
41     
42     private static final String JavaDoc CORRECT_HOST = "127.0.0.1";
43     private static final String JavaDoc WRONG_HOST = "10.0.1.222";
44     private static final String JavaDoc WRONG_HOST_2 = "10.0.1.223";
45     
46     private static final int CORRECT_PORT = 45000;
47     private static final int WRONG_PORT = 45001;
48
49     public AlternateIIOPAddressTest(String JavaDoc name, ClientServerSetup setup)
50     {
51         super(name, setup);
52     }
53
54     protected void setUp() throws Exception JavaDoc
55     {
56         server = IIOPAddressServerHelper.narrow(setup.getServerObject());
57     }
58
59     protected void tearDown() throws Exception JavaDoc
60     {
61         // server.clearSocketAddress();
62
server.setIORAddress (CORRECT_HOST, CORRECT_PORT);
63         server.clearAlternateAddresses();
64     }
65
66     public static Test suite()
67     {
68         TestSuite suite = new JacORBTestSuite("Test TAG_ALTERNATE_IIOP_ADDRESS",
69                                               AlternateIIOPAddressTest.class);
70
71         Properties JavaDoc client_props = new Properties JavaDoc();
72         client_props.setProperty ("jacorb.retries", "0");
73         client_props.setProperty ("jacorb.retry_interval", "50");
74
75         Properties JavaDoc server_props = new Properties JavaDoc();
76         server_props.setProperty
77             ("org.omg.PortableInterceptor.ORBInitializerClass."
78            + "org.jacorb.test.orb.IIOPAddressORBInitializer", "");
79         server_props.setProperty ("OAPort", Integer.toString(CORRECT_PORT));
80
81         ClientServerSetup setup =
82             new ClientServerSetup (suite,
83                                    "org.jacorb.test.orb.IIOPAddressServerImpl",
84                                    client_props,
85                                    server_props);
86
87         suite.addTest (new AlternateIIOPAddressTest("test_ping", setup));
88         suite.addTest (new AlternateIIOPAddressTest("test_primary_ok", setup));
89         suite.addTest (new AlternateIIOPAddressTest("test_primary_wrong_host", setup));
90         suite.addTest (new AlternateIIOPAddressTest("test_primary_wrong_port", setup));
91         suite.addTest (new AlternateIIOPAddressTest("test_alternate_ok", setup));
92         suite.addTest (new AlternateIIOPAddressTest("test_alternate_ok_2", setup));
93         suite.addTest (new AlternateIIOPAddressTest("test_alternate_wrong", setup));
94
95         return setup;
96     }
97     
98     public void test_ping()
99     {
100         Sample s = server.getObject();
101         int result = s.ping (17);
102         assertEquals (18, result);
103     }
104
105     public void test_primary_ok()
106     {
107         server.setIORAddress( CORRECT_HOST, CORRECT_PORT );
108         Sample s = server.getObject();
109         int result = s.ping (77);
110         assertEquals (78, result);
111     }
112     
113     public void test_primary_wrong_host()
114     {
115         server.setIORAddress( WRONG_HOST, CORRECT_PORT );
116         Sample s = server.getObject();
117         try
118         {
119             int result = s.ping (123);
120             fail ("TRANSIENT exception expected");
121         }
122         catch (org.omg.CORBA.TRANSIENT JavaDoc ex)
123         {
124             // ok
125
}
126     }
127     
128     public void test_primary_wrong_port()
129     {
130         server.setIORAddress( CORRECT_HOST, WRONG_PORT );
131         Sample s = server.getObject();
132         try
133         {
134             int result = s.ping (4);
135             fail ("TRANSIENT exception expected");
136         }
137         catch (org.omg.CORBA.TRANSIENT JavaDoc ex)
138         {
139             // ok
140
}
141     }
142     
143     public void test_alternate_ok()
144     {
145         server.setIORAddress( WRONG_HOST, CORRECT_PORT );
146         server.addAlternateAddress( CORRECT_HOST, CORRECT_PORT );
147         Sample s = server.getObject();
148         int result = s.ping (99);
149         assertEquals (100, result);
150     }
151
152     public void test_alternate_ok_2()
153     {
154         server.setIORAddress( WRONG_HOST, CORRECT_PORT );
155         server.addAlternateAddress( WRONG_HOST_2, CORRECT_PORT );
156         server.addAlternateAddress( CORRECT_HOST, CORRECT_PORT );
157         Sample s = server.getObject();
158         int result = s.ping (187);
159         assertEquals (188, result);
160     }
161
162     public void test_alternate_wrong()
163     {
164         server.setIORAddress( CORRECT_HOST, WRONG_PORT );
165         server.addAlternateAddress( WRONG_HOST, CORRECT_PORT );
166         server.addAlternateAddress( WRONG_HOST_2, WRONG_PORT );
167         server.addAlternateAddress( WRONG_HOST_2, WRONG_PORT );
168         Sample s = server.getObject();
169         try
170         {
171             int result = s.ping (33);
172             fail ("TRANSIENT exception expected");
173         }
174         catch (org.omg.CORBA.TRANSIENT JavaDoc ex)
175         {
176             // ok
177
}
178
179     }
180
181 }
182
Popular Tags