KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > systest > securebasic > ClientPropertiesReadFromConfigSetServerTest


1 package org.objectweb.celtix.systest.securebasic;
2
3 import java.lang.reflect.UndeclaredThrowableException JavaDoc;
4 import java.net.URL JavaDoc;
5
6 import javax.xml.namespace.QName JavaDoc;
7
8 import junit.framework.Test;
9 import junit.framework.TestSuite;
10
11 import org.objectweb.celtix.systest.common.ClientServerSetupBase;
12 import org.objectweb.celtix.systest.common.ClientServerTestBase;
13 import org.objectweb.hello_world_soap_http_secure.Greeter;
14 import org.objectweb.hello_world_soap_http_secure.SecureSOAPService;
15 import org.objectweb.hello_world_soap_http_secure.types.Result;
16
17 public class ClientPropertiesReadFromConfigSetServerTest extends ClientServerTestBase {
18   
19     private static final int REPEAT_NUM_TIMES = 1;
20     
21     private static ClientServerSetupBase cssb;
22     
23    
24
25     public static Test suite() throws Exception JavaDoc {
26
27         TestSuite suite = new TestSuite(ClientPropertiesReadFromConfigSetServerTest.class);
28         
29         cssb = new ClientServerSetupBase(suite) {
30             public void startServers() throws Exception JavaDoc {
31                 SecureBasicUtils.startServer(getClass().getResource(".")
32                                              + "WantAndNeedClientAuthServer.xml",
33                                              "celtix.security.configurer.http-listener.9001",
34                                              null, cssb, WantAndNeedClientAuthServer.class);
35                 SecureBasicUtils.startServer(getClass().getResource(".")
36                                              + "WantNotNeedClientAuthServer.xml",
37                                              "celtix.security.configurer.http-listener.9002",
38                                              null, cssb, WantNotNeedClientAuthServer.class);
39                 SecureBasicUtils.startServer(getClass().getResource(".")
40                                              + "WantAndNeedClientAuthInterServer.xml",
41                                              "celtix.security.configurer.http-listener.9003",
42                                              null, cssb, WantAndNeedClientAuthInterServer.class);
43                 SecureBasicUtils.startServer(getClass().getResource(".")
44                                              + "WantNotNeedClientAuthInterServer.xml",
45                                              "celtix.security.configurer.http-listener.9004",
46                                              null, cssb, WantNotNeedClientAuthInterServer.class);
47                 SecureBasicUtils.startServer(getClass().getResource(".")
48                                              + "WantAndNeedClientAuthServerSetGoodDataProvider.xml",
49                                              "celtix.security.configurer.celtix.http-listener.9005",
50                                                "org.objectweb.celtix.systest.securebasic."
51                                              + "SetAllDataSecurityDataProvider",
52                                              cssb, WantAndNeedClientAuthServerSetGoodDataProvider.class);
53                 SecureBasicUtils.startServer(getClass().getResource(".")
54                                              + "WantAndNeedClientAuthServerSetBadDataProvider.xml",
55                                              "celtix.security.configurer.celtix.http-listener.9006",
56                                              "org.objectweb.celtix.systest.securebasic."
57                                                  + "SetBadDataSecurityDataProvider",
58                                              cssb, WantAndNeedClientAuthServerSetBadDataProvider.class);
59                 SecureBasicUtils.startServer(getClass().getResource(".")
60                                              + "WantAndNeedClientAuthServerPKCS12.xml",
61                                              "celtix.security.configurer.celtix.http-listener.9007",
62                                              null, cssb, WantAndNeedClientAuthServerPKCS12.class);
63                                             
64             }
65         };
66         return cssb;
67     }
68     
69   
70     public void testTwoTiers() throws Exception JavaDoc {
71         String JavaDoc configFile = getClass().getResource(".") + "client.xml";
72         System.setProperty("celtix.config.file", configFile);
73         
74         for (int index = 0; index < Matrix.TWO_TIER_TESTS.length; index++) {
75             URL JavaDoc wsdl = getClass().getResource("/wsdl/" + Matrix.TWO_TIER_TESTS[index].clientData.clientWsdl);
76             assertNotNull(wsdl);
77             QName JavaDoc serviceName =
78                 new QName JavaDoc("http://objectweb.org/hello_world_soap_http_secure",
79                           Matrix.TWO_TIER_TESTS[index].clientData.clientServiceName);
80             SecureSOAPService service = new SecureSOAPService(wsdl, serviceName);
81             assertNotNull(service);
82             
83             QName JavaDoc portName = new QName JavaDoc("http://objectweb.org/hello_world_soap_http_secure",
84                                        Matrix.TWO_TIER_TESTS[index].clientData.clientPortName);
85             Greeter greeter = service.getPort(portName, Greeter.class);
86             String JavaDoc propStr = "celtix.security.configurer"
87                 + ".celtix.{http://objectweb.org/hello_world_soap_http_secure}"
88                 + Matrix.TWO_TIER_TESTS[index].clientData.clientServiceName + "/"
89                 + Matrix.TWO_TIER_TESTS[index].clientData.clientPortName + ".http-client";
90             if (Matrix.TWO_TIER_TESTS[index].clientData.securityConfigurer != null) {
91                 System.setProperty(propStr,
92                                    Matrix.TWO_TIER_TESTS[index].clientData.securityConfigurer);
93                 
94             }
95             invokeTwoTier(greeter, index);
96             if (System.getProperty("propStr") != null) {
97                 System.getProperties().remove(propStr);
98             }
99         }
100     }
101     
102  
103      
104     private void invokeTwoTier(Greeter greeter, int index) throws Exception JavaDoc {
105         String JavaDoc response1 = new String JavaDoc("Hello Milestone-");
106         try {
107             for (int idx = 0; idx < REPEAT_NUM_TIMES; idx++) {
108                 Result ret = greeter.greetMeTwoTier("Milestone-" + idx, index);
109                 if (!Matrix.TWO_TIER_TESTS[index].clientData.clientExpectSuccess) {
110                     fail("Expected to FAIL but didn't, index = " + index);
111                 }
112                 assertNotNull("no response received from service", ret.getReturnString());
113                 String JavaDoc exResponse = response1 + idx;
114                 assertEquals(exResponse, ret.getReturnString());
115                 
116             }
117         } catch (UndeclaredThrowableException JavaDoc ex) {
118             if (Matrix.TWO_TIER_TESTS[index].clientData.clientExpectSuccess) {
119                 fail("Caught unexpected ex = " + ex
120                      + ", ex message is " + ex.getMessage()
121                      + ", index = " + index);
122                 throw (Exception JavaDoc)ex.getCause();
123             }
124
125         }
126
127     }
128     
129     public void testThreeTiers() throws Exception JavaDoc {
130         String JavaDoc configFile = getClass().getResource(".") + "client.xml";
131         System.setProperty("celtix.config.file", configFile);
132         
133         for (int index = 0; index < Matrix.THREE_TIER_TESTS.length; index++) {
134             URL JavaDoc wsdl = getClass().getResource("/wsdl/"
135                                               + Matrix.THREE_TIER_TESTS[index].clientData.clientWsdl);
136             assertNotNull(wsdl);
137             QName JavaDoc serviceName =
138                 new QName JavaDoc("http://objectweb.org/hello_world_soap_http_secure",
139                           Matrix.THREE_TIER_TESTS[index].clientData.clientServiceName);
140             SecureSOAPService service = new SecureSOAPService(wsdl, serviceName);
141             assertNotNull(service);
142             
143             QName JavaDoc portName = new QName JavaDoc("http://objectweb.org/hello_world_soap_http_secure",
144                                        Matrix.THREE_TIER_TESTS[index].clientData.clientPortName);
145             Greeter greeter = service.getPort(portName, Greeter.class);
146             
147             invokeThreeTier(greeter, index);
148         }
149     }
150
151      
152     private void invokeThreeTier(Greeter greeter, int index) throws Exception JavaDoc {
153         String JavaDoc response1 = new String JavaDoc("Hello Milestone-");
154         try {
155             for (int idx = 0; idx < REPEAT_NUM_TIMES; idx++) {
156                 Result ret = greeter.greetMeThreeTier("Milestone-" + idx, index);
157                 if (!Matrix.THREE_TIER_TESTS[index].clientData.clientExpectSuccess) {
158                     fail("Expected to FAIL but didn't");
159                 } else if (!ret.isDidPass()) {
160                     fail("The inter server reported the following error : " + ret.getFailureReason());
161                 }
162                 assertNotNull("no response received from service", ret.getReturnString());
163                 String JavaDoc exResponse = response1 + idx;
164                 assertEquals(exResponse, ret.getReturnString());
165                 
166             }
167         } catch (UndeclaredThrowableException JavaDoc ex) {
168             if (Matrix.THREE_TIER_TESTS[index].clientData.clientExpectSuccess) {
169                 fail("Caught unexpected exception for test index, " + index + ",ex = " + ex);
170                 throw (Exception JavaDoc)ex.getCause();
171             }
172             
173         }
174
175     }
176     
177  
178     
179     public static void main(String JavaDoc[] args) {
180         junit.textui.TestRunner.run(ClientPropertiesReadFromConfigSetServerTest.class);
181     }
182           
183     
184 }
185
Popular Tags