001: package org.objectweb.celtix.systest.securebasic;
002:
003: import java.lang.reflect.UndeclaredThrowableException;
004: import java.net.URL;
005:
006: import javax.xml.namespace.QName;
007:
008: import junit.framework.Test;
009: import junit.framework.TestSuite;
010:
011: import org.objectweb.celtix.systest.common.ClientServerSetupBase;
012: import org.objectweb.celtix.systest.common.ClientServerTestBase;
013: import org.objectweb.hello_world_soap_http_secure.Greeter;
014: import org.objectweb.hello_world_soap_http_secure.SecureSOAPService;
015: import org.objectweb.hello_world_soap_http_secure.types.Result;
016:
017: public class ClientPropertiesReadFromConfigSetServerTest extends
018: ClientServerTestBase {
019:
020: private static final int REPEAT_NUM_TIMES = 1;
021:
022: private static ClientServerSetupBase cssb;
023:
024: public static Test suite() throws Exception {
025:
026: TestSuite suite = new TestSuite(
027: ClientPropertiesReadFromConfigSetServerTest.class);
028:
029: cssb = new ClientServerSetupBase(suite) {
030: public void startServers() throws Exception {
031: SecureBasicUtils
032: .startServer(
033: getClass().getResource(".")
034: + "WantAndNeedClientAuthServer.xml",
035: "celtix.security.configurer.http-listener.9001",
036: null, cssb,
037: WantAndNeedClientAuthServer.class);
038: SecureBasicUtils
039: .startServer(
040: getClass().getResource(".")
041: + "WantNotNeedClientAuthServer.xml",
042: "celtix.security.configurer.http-listener.9002",
043: null, cssb,
044: WantNotNeedClientAuthServer.class);
045: SecureBasicUtils
046: .startServer(
047: getClass().getResource(".")
048: + "WantAndNeedClientAuthInterServer.xml",
049: "celtix.security.configurer.http-listener.9003",
050: null, cssb,
051: WantAndNeedClientAuthInterServer.class);
052: SecureBasicUtils
053: .startServer(
054: getClass().getResource(".")
055: + "WantNotNeedClientAuthInterServer.xml",
056: "celtix.security.configurer.http-listener.9004",
057: null, cssb,
058: WantNotNeedClientAuthInterServer.class);
059: SecureBasicUtils
060: .startServer(
061: getClass().getResource(".")
062: + "WantAndNeedClientAuthServerSetGoodDataProvider.xml",
063: "celtix.security.configurer.celtix.http-listener.9005",
064: "org.objectweb.celtix.systest.securebasic."
065: + "SetAllDataSecurityDataProvider",
066: cssb,
067: WantAndNeedClientAuthServerSetGoodDataProvider.class);
068: SecureBasicUtils
069: .startServer(
070: getClass().getResource(".")
071: + "WantAndNeedClientAuthServerSetBadDataProvider.xml",
072: "celtix.security.configurer.celtix.http-listener.9006",
073: "org.objectweb.celtix.systest.securebasic."
074: + "SetBadDataSecurityDataProvider",
075: cssb,
076: WantAndNeedClientAuthServerSetBadDataProvider.class);
077: SecureBasicUtils
078: .startServer(
079: getClass().getResource(".")
080: + "WantAndNeedClientAuthServerPKCS12.xml",
081: "celtix.security.configurer.celtix.http-listener.9007",
082: null, cssb,
083: WantAndNeedClientAuthServerPKCS12.class);
084:
085: }
086: };
087: return cssb;
088: }
089:
090: public void testTwoTiers() throws Exception {
091: String configFile = getClass().getResource(".") + "client.xml";
092: System.setProperty("celtix.config.file", configFile);
093:
094: for (int index = 0; index < Matrix.TWO_TIER_TESTS.length; index++) {
095: URL wsdl = getClass()
096: .getResource(
097: "/wsdl/"
098: + Matrix.TWO_TIER_TESTS[index].clientData.clientWsdl);
099: assertNotNull(wsdl);
100: QName serviceName = new QName(
101: "http://objectweb.org/hello_world_soap_http_secure",
102: Matrix.TWO_TIER_TESTS[index].clientData.clientServiceName);
103: SecureSOAPService service = new SecureSOAPService(wsdl,
104: serviceName);
105: assertNotNull(service);
106:
107: QName portName = new QName(
108: "http://objectweb.org/hello_world_soap_http_secure",
109: Matrix.TWO_TIER_TESTS[index].clientData.clientPortName);
110: Greeter greeter = service.getPort(portName, Greeter.class);
111: String propStr = "celtix.security.configurer"
112: + ".celtix.{http://objectweb.org/hello_world_soap_http_secure}"
113: + Matrix.TWO_TIER_TESTS[index].clientData.clientServiceName
114: + "/"
115: + Matrix.TWO_TIER_TESTS[index].clientData.clientPortName
116: + ".http-client";
117: if (Matrix.TWO_TIER_TESTS[index].clientData.securityConfigurer != null) {
118: System
119: .setProperty(
120: propStr,
121: Matrix.TWO_TIER_TESTS[index].clientData.securityConfigurer);
122:
123: }
124: invokeTwoTier(greeter, index);
125: if (System.getProperty("propStr") != null) {
126: System.getProperties().remove(propStr);
127: }
128: }
129: }
130:
131: private void invokeTwoTier(Greeter greeter, int index)
132: throws Exception {
133: String response1 = new String("Hello Milestone-");
134: try {
135: for (int idx = 0; idx < REPEAT_NUM_TIMES; idx++) {
136: Result ret = greeter.greetMeTwoTier("Milestone-" + idx,
137: index);
138: if (!Matrix.TWO_TIER_TESTS[index].clientData.clientExpectSuccess) {
139: fail("Expected to FAIL but didn't, index = "
140: + index);
141: }
142: assertNotNull("no response received from service", ret
143: .getReturnString());
144: String exResponse = response1 + idx;
145: assertEquals(exResponse, ret.getReturnString());
146:
147: }
148: } catch (UndeclaredThrowableException ex) {
149: if (Matrix.TWO_TIER_TESTS[index].clientData.clientExpectSuccess) {
150: fail("Caught unexpected ex = " + ex
151: + ", ex message is " + ex.getMessage()
152: + ", index = " + index);
153: throw (Exception) ex.getCause();
154: }
155:
156: }
157:
158: }
159:
160: public void testThreeTiers() throws Exception {
161: String configFile = getClass().getResource(".") + "client.xml";
162: System.setProperty("celtix.config.file", configFile);
163:
164: for (int index = 0; index < Matrix.THREE_TIER_TESTS.length; index++) {
165: URL wsdl = getClass()
166: .getResource(
167: "/wsdl/"
168: + Matrix.THREE_TIER_TESTS[index].clientData.clientWsdl);
169: assertNotNull(wsdl);
170: QName serviceName = new QName(
171: "http://objectweb.org/hello_world_soap_http_secure",
172: Matrix.THREE_TIER_TESTS[index].clientData.clientServiceName);
173: SecureSOAPService service = new SecureSOAPService(wsdl,
174: serviceName);
175: assertNotNull(service);
176:
177: QName portName = new QName(
178: "http://objectweb.org/hello_world_soap_http_secure",
179: Matrix.THREE_TIER_TESTS[index].clientData.clientPortName);
180: Greeter greeter = service.getPort(portName, Greeter.class);
181:
182: invokeThreeTier(greeter, index);
183: }
184: }
185:
186: private void invokeThreeTier(Greeter greeter, int index)
187: throws Exception {
188: String response1 = new String("Hello Milestone-");
189: try {
190: for (int idx = 0; idx < REPEAT_NUM_TIMES; idx++) {
191: Result ret = greeter.greetMeThreeTier("Milestone-"
192: + idx, index);
193: if (!Matrix.THREE_TIER_TESTS[index].clientData.clientExpectSuccess) {
194: fail("Expected to FAIL but didn't");
195: } else if (!ret.isDidPass()) {
196: fail("The inter server reported the following error : "
197: + ret.getFailureReason());
198: }
199: assertNotNull("no response received from service", ret
200: .getReturnString());
201: String exResponse = response1 + idx;
202: assertEquals(exResponse, ret.getReturnString());
203:
204: }
205: } catch (UndeclaredThrowableException ex) {
206: if (Matrix.THREE_TIER_TESTS[index].clientData.clientExpectSuccess) {
207: fail("Caught unexpected exception for test index, "
208: + index + ",ex = " + ex);
209: throw (Exception) ex.getCause();
210: }
211:
212: }
213:
214: }
215:
216: public static void main(String[] args) {
217: junit.textui.TestRunner
218: .run(ClientPropertiesReadFromConfigSetServerTest.class);
219: }
220:
221: }
|