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.jaxb;
19:
20: import java.util.List;
21:
22: import javax.xml.stream.XMLInputFactory;
23: import javax.xml.stream.XMLStreamReader;
24:
25: import org.apache.cxf.interceptor.WrappedInInterceptor;
26: import org.apache.cxf.message.Message;
27: import org.apache.cxf.service.model.BindingOperationInfo;
28: import org.junit.Test;
29:
30: public class WrappedInInterceptorTest extends TestBase {
31:
32: @Test
33: public void testInterceptorInbound() throws Exception {
34: WrappedInInterceptor interceptor = new WrappedInInterceptor();
35:
36: message.setContent(XMLStreamReader.class, XMLInputFactory
37: .newInstance().createXMLStreamReader(
38: getTestStream(getClass(),
39: "resources/GreetMeDocLiteralReq.xml")));
40:
41: interceptor.handleMessage(message);
42:
43: assertNull(message.getContent(Exception.class));
44: BindingOperationInfo op = (BindingOperationInfo) message
45: .getExchange()
46: .get(BindingOperationInfo.class.getName());
47: assertNotNull(op);
48:
49: List<?> objs = message.getContent(List.class);
50: assertTrue(objs != null && objs.size() > 0);
51: Object obj = objs.get(0);
52: assertTrue(obj instanceof org.apache.hello_world_soap_http.types.GreetMe);
53: org.apache.hello_world_soap_http.types.GreetMe gm = (org.apache.hello_world_soap_http.types.GreetMe) obj;
54:
55: assertEquals("TestSOAPInputPMessage", gm.getRequestType());
56: }
57:
58: @Test
59: public void testInterceptorOutbound() throws Exception {
60: WrappedInInterceptor interceptor = new WrappedInInterceptor();
61:
62: message
63: .setContent(
64: XMLStreamReader.class,
65: XMLInputFactory
66: .newInstance()
67: .createXMLStreamReader(
68: getTestStream(getClass(),
69: "resources/GreetMeDocLiteralResp.xml")));
70: message.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
71:
72: interceptor.handleMessage(message);
73: assertNull(message.getContent(Exception.class));
74:
75: List<?> objs = message.getContent(List.class);
76: assertTrue(objs != null && objs.size() > 0);
77:
78: Object retValue = objs.get(0);
79: assertNotNull(retValue);
80:
81: assertTrue(retValue instanceof org.apache.hello_world_soap_http.types.GreetMeResponse);
82:
83: org.apache.hello_world_soap_http.types.GreetMeResponse gm = (org.apache.hello_world_soap_http.types.GreetMeResponse) retValue;
84: assertEquals("TestSOAPOutputPMessage", gm.getResponseType());
85: }
86: }
|