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.handler;
19:
20: import java.util.ArrayList;
21: import java.util.List;
22:
23: import javax.xml.bind.JAXBContext;
24: import javax.xml.bind.JAXBElement;
25:
26: import org.apache.cxf.jaxws.handler.logical.LogicalMessageContextImpl;
27: import org.apache.cxf.jaxws.handler.logical.LogicalMessageImpl;
28: import org.apache.cxf.message.Exchange;
29: import org.apache.cxf.message.ExchangeImpl;
30: import org.apache.cxf.message.Message;
31: import org.apache.cxf.message.MessageImpl;
32: import org.apache.handlers.types.AddNumbers;
33: import org.apache.handlers.types.ObjectFactory;
34: import org.junit.Assert;
35: import org.junit.Before;
36: import org.junit.Test;
37:
38: public class LogicalMessageImplTest extends Assert {
39: AddNumbers req;
40: List<Object> args;
41:
42: @Before
43: public void setUp() {
44: req = new AddNumbers();
45: req.setArg0(10);
46: req.setArg1(20);
47: args = new ArrayList<Object>();
48: args.add(req);
49: }
50:
51: @Test
52: public void testGetPayloadOfJAXB() throws Exception {
53: //using Dispatch
54: JAXBContext ctx = JAXBContext.newInstance(ObjectFactory.class);
55: Message message = new MessageImpl();
56: Exchange e = new ExchangeImpl();
57: message.setExchange(e);
58: LogicalMessageContextImpl lmci = new LogicalMessageContextImpl(
59: message);
60:
61: JAXBElement<AddNumbers> el = new ObjectFactory()
62: .createAddNumbers(req);
63:
64: LogicalMessageImpl lmi = new LogicalMessageImpl(lmci);
65: lmi.setPayload(el, ctx);
66:
67: Object obj = lmi.getPayload(ctx);
68: assertTrue(obj instanceof JAXBElement);
69: JAXBElement<?> el2 = (JAXBElement) obj;
70: assertTrue(el2.getValue() instanceof AddNumbers);
71: AddNumbers resp = (AddNumbers) el2.getValue();
72: assertEquals(req.getArg0(), resp.getArg0());
73: assertEquals(req.getArg1(), resp.getArg1());
74: }
75: }
|