001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.binding.xml.interceptor;
019:
020: import java.io.InputStream;
021: import java.util.List;
022:
023: import javax.xml.namespace.QName;
024: import javax.xml.stream.XMLStreamReader;
025:
026: import org.apache.cxf.interceptor.DocLiteralInInterceptor;
027: import org.apache.cxf.service.model.OperationInfo;
028: import org.apache.cxf.staxutils.StaxUtils;
029: import org.apache.hello_world_xml_http.bare.types.MyComplexStructType;
030: import org.apache.hello_world_xml_http.wrapped.types.GreetMe;
031: import org.junit.Before;
032: import org.junit.Test;
033:
034: public class XMLMessageInInterceptorTest extends TestBase {
035:
036: XMLMessageInInterceptor in = new XMLMessageInInterceptor("phase1");
037: DocLiteralInInterceptor docLitIn = new DocLiteralInInterceptor();
038:
039: @Before
040: public void setUp() throws Exception {
041: super .setUp();
042: chain.add(in);
043: }
044:
045: @Test
046: public void testHandleMessageOnBareMultiParam() throws Exception {
047: String ns = "http://apache.org/hello_world_xml_http/bare";
048: prepareMessage("/message-bare-multi-param.xml");
049: common("/wsdl/hello_world_xml_bare.wsdl", new QName(ns,
050: "XMLPort"), MyComplexStructType.class);
051:
052: OperationInfo op = serviceInfo.getInterface().getOperation(
053: new QName(ns, "testMultiParamPart"));
054: op.getInput().getMessagePartByIndex(0).setTypeClass(
055: MyComplexStructType.class);
056: op.getInput().getMessagePartByIndex(1).setTypeClass(
057: String.class);
058:
059: in.handleMessage(xmlMessage);
060: docLitIn.handleMessage(xmlMessage);
061: List list = xmlMessage.getContent(List.class);
062: assertNotNull(list);
063: assertEquals("expect 2 param", 2, list.size());
064: assertEquals("method input in2 is MyComplexStructType", true,
065: list.get(0) instanceof MyComplexStructType);
066: assertEquals("method input in1 is String tli", true,
067: ((String) list.get(1)).indexOf("tli") >= 0);
068: }
069:
070: @Test
071: public void testHandleMessageOnBareSingleChild() throws Exception {
072: String ns = "http://apache.org/hello_world_xml_http/bare";
073: prepareMessage("/message-bare-single-param-element.xml");
074: common("/wsdl/hello_world_xml_bare.wsdl", new QName(ns,
075: "XMLPort"));
076:
077: OperationInfo op = serviceInfo.getInterface().getOperation(
078: new QName(ns, "greetMe"));
079: op.getInput().getMessagePartByIndex(0).setTypeClass(
080: String.class);
081:
082: in.handleMessage(xmlMessage);
083: docLitIn.handleMessage(xmlMessage);
084: List list = xmlMessage.getContent(List.class);
085: assertNotNull(list);
086: assertEquals("expect 1 param", 1, list.size());
087: assertEquals("method input me is String tli", true,
088: ((String) list.get(0)).indexOf("tli") >= 0);
089: }
090:
091: @Test
092: public void testHandleMessageWrapped() throws Exception {
093: String ns = "http://apache.org/hello_world_xml_http/wrapped";
094: prepareMessage("/message-wrap.xml");
095: common("/wsdl/hello_world_xml_wrapped.wsdl", new QName(ns,
096: "XMLPort"), GreetMe.class);
097:
098: OperationInfo op = serviceInfo.getInterface().getOperation(
099: new QName(ns, "greetMe"));
100: op.getInput().getMessagePartByIndex(0).setTypeClass(
101: GreetMe.class);
102:
103: in.handleMessage(xmlMessage);
104: docLitIn.handleMessage(xmlMessage);
105: List list = xmlMessage.getContent(List.class);
106: assertNotNull(list);
107: assertEquals("expect 1 param", 1, list.size());
108: assertEquals("method input me is String tli", true,
109: list.get(0) instanceof GreetMe);
110: }
111:
112: private void prepareMessage(String messageFileName)
113: throws Exception {
114: InputStream inputStream = this .getClass().getResourceAsStream(
115: messageFileName);
116: xmlMessage.setContent(InputStream.class, inputStream);
117: xmlMessage.setContent(XMLStreamReader.class, StaxUtils
118: .createXMLStreamReader(inputStream));
119: }
120: }
|