01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.systest.http;
19:
20: import java.lang.reflect.UndeclaredThrowableException;
21:
22: import javax.xml.ws.BindingProvider;
23:
24: import org.apache.cxf.greeter_control.Greeter;
25: import org.apache.cxf.greeter_control.GreeterService;
26: import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
27: import org.junit.BeforeClass;
28: import org.junit.Test;
29:
30: public class ClientServerSessionTest extends
31: AbstractBusClientServerTestBase {
32: @BeforeClass
33: public static void startServers() throws Exception {
34: assertTrue("server did not launch correctly",
35: launchServer(SessionServer.class));
36: }
37:
38: @Test
39: public void testInvocationWithSession() throws Exception {
40:
41: GreeterService service = new GreeterService();
42: assertNotNull(service);
43:
44: try {
45: Greeter greeter = service.getGreeterPort();
46: ((BindingProvider) greeter).getRequestContext().put(
47: BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
48: String greeting = greeter.greetMe("Bonjour");
49:
50: assertNotNull("no response received from service", greeting);
51: assertEquals("Hello Bonjour", greeting);
52:
53: greeting = greeter.greetMe("Hello");
54: assertNotNull("no response received from service", greeting);
55: assertEquals("Hello Bonjour", greeting);
56:
57: greeting = greeter.greetMe("NiHao");
58: assertNotNull("no response received from service", greeting);
59: assertEquals("Hello Hello", greeting);
60:
61: } catch (UndeclaredThrowableException ex) {
62: throw (Exception) ex.getCause();
63: }
64: }
65:
66: @Test
67: public void testInvocationWithoutSession() throws Exception {
68:
69: GreeterService service = new GreeterService();
70: assertNotNull(service);
71:
72: try {
73: Greeter greeter = service.getGreeterPort();
74:
75: String greeting = greeter.greetMe("Bonjour");
76:
77: assertNotNull("no response received from service", greeting);
78: assertEquals("Hello Bonjour", greeting);
79:
80: greeting = greeter.greetMe("Hello");
81: assertNotNull("no response received from service", greeting);
82: assertEquals("Hello Hello", greeting);
83:
84: greeting = greeter.greetMe("NiHao");
85: assertNotNull("no response received from service", greeting);
86: assertEquals("Hello NiHao", greeting);
87:
88: } catch (UndeclaredThrowableException ex) {
89: throw (Exception) ex.getCause();
90: }
91: }
92:
93: }
|