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.binding.soap;
19:
20: import java.util.List;
21: import java.util.Map;
22:
23: import javax.xml.namespace.QName;
24:
25: import org.apache.cxf.binding.soap.interceptor.SoapActionOutInterceptor;
26: import org.apache.cxf.binding.soap.model.SoapOperationInfo;
27: import org.apache.cxf.helpers.CastUtils;
28: import org.apache.cxf.message.ExchangeImpl;
29: import org.apache.cxf.message.Message;
30: import org.apache.cxf.message.MessageImpl;
31: import org.apache.cxf.service.model.BindingInfo;
32: import org.apache.cxf.service.model.BindingOperationInfo;
33: import org.apache.cxf.service.model.InterfaceInfo;
34: import org.apache.cxf.service.model.ServiceInfo;
35: import org.junit.Assert;
36: import org.junit.Test;
37:
38: public class SoapActionInterceptorTest extends Assert {
39:
40: @Test
41: public void testSoapAction() throws Exception {
42: SoapActionOutInterceptor i = new SoapActionOutInterceptor();
43:
44: Message message = new MessageImpl();
45: message.setExchange(new ExchangeImpl());
46: message.getExchange().setOutMessage(message);
47: SoapBinding sb = new SoapBinding(null);
48: message = sb.createMessage(message);
49: assertNotNull(message);
50: assertTrue(message instanceof SoapMessage);
51: SoapMessage soapMessage = (SoapMessage) message;
52: assertEquals(Soap11.getInstance(), soapMessage.getVersion());
53: (new SoapActionOutInterceptor()).handleMessage(soapMessage);
54: Map<String, List<String>> reqHeaders = CastUtils
55: .cast((Map) soapMessage.get(Message.PROTOCOL_HEADERS));
56: assertNotNull(reqHeaders);
57: assertEquals("\"\"", reqHeaders.get("SOAPAction").get(0));
58:
59: sb.setSoapVersion(Soap12.getInstance());
60: soapMessage.clear();
61: soapMessage = (SoapMessage) sb.createMessage(soapMessage);
62: i.handleMessage(soapMessage);
63: String ct = (String) message.get(Message.CONTENT_TYPE);
64: assertEquals("application/soap+xml", ct);
65:
66: BindingOperationInfo bop = createBindingOperation();
67:
68: message.getExchange().put(BindingOperationInfo.class, bop);
69: SoapOperationInfo soapInfo = new SoapOperationInfo();
70: soapInfo.setAction("foo");
71: bop.addExtensor(soapInfo);
72:
73: i.handleMessage(soapMessage);
74: ct = (String) message.get(Message.CONTENT_TYPE);
75: assertEquals("application/soap+xml; action=\"foo\"", ct);
76: }
77:
78: private BindingOperationInfo createBindingOperation() {
79: ServiceInfo s = new ServiceInfo();
80: InterfaceInfo ii = s.createInterface(new QName("FooInterface"));
81: s.setInterface(ii);
82: ii.addOperation(new QName("fooOp"));
83:
84: BindingInfo b = new BindingInfo(s, "foo");
85: return b.buildOperation(new QName("fooOp"), null, null);
86: }
87:
88: }
|