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.jaxws.context;
19:
20: import javax.xml.ws.handler.MessageContext;
21:
22: import org.apache.cxf.message.MessageImpl;
23: import org.junit.After;
24: import org.junit.Assert;
25: import org.junit.Test;
26:
27: public class WebServiceContextImplTest extends Assert {
28:
29: @After
30: public void tearDown() {
31: WebServiceContextImpl.clear();
32: }
33:
34: @Test
35: public void testConstructor() {
36: MessageImpl msg = new MessageImpl();
37: WrappedMessageContext msgCtx = new WrappedMessageContext(msg);
38: WebServiceContextImpl ctx = new WebServiceContextImpl(msgCtx);
39: assertSame(msgCtx, ctx.getMessageContext());
40: }
41:
42: @Test
43: public void testGetSetMessageContext() {
44: WebServiceContextImpl wsci = new WebServiceContextImpl();
45: assertNull(wsci.getMessageContext());
46:
47: MessageImpl msg = new MessageImpl();
48: final MessageContext ctx = new WrappedMessageContext(msg);
49: WebServiceContextImpl.setMessageContext(ctx);
50:
51: assertSame(ctx, wsci.getMessageContext());
52:
53: Thread t = new Thread() {
54: public void run() {
55: WebServiceContextImpl threadLocalWSCI = new WebServiceContextImpl();
56:
57: assertNull(threadLocalWSCI.getMessageContext());
58:
59: MessageImpl msg1 = new MessageImpl();
60: MessageContext threadLocalCtx = new WrappedMessageContext(
61: msg1);
62: WebServiceContextImpl.setMessageContext(threadLocalCtx);
63:
64: assertSame(threadLocalCtx, threadLocalWSCI
65: .getMessageContext());
66: assertTrue(ctx != threadLocalWSCI.getMessageContext());
67:
68: }
69: };
70:
71: t.start();
72:
73: try {
74: t.join();
75: } catch (InterruptedException e) {
76: e.printStackTrace();
77: }
78: }
79: }
|