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.soap;
019:
020: import javax.wsdl.Definition;
021: import javax.wsdl.Service;
022: import javax.wsdl.factory.WSDLFactory;
023: import javax.wsdl.xml.WSDLReader;
024: import javax.xml.namespace.QName;
025:
026: import org.apache.cxf.Bus;
027: import org.apache.cxf.binding.BindingFactoryManager;
028: import org.apache.cxf.helpers.CastUtils;
029: import org.apache.cxf.service.model.BindingInfo;
030: import org.apache.cxf.service.model.BindingMessageInfo;
031: import org.apache.cxf.service.model.BindingOperationInfo;
032: import org.apache.cxf.service.model.MessagePartInfo;
033: import org.apache.cxf.service.model.SchemaInfo;
034: import org.apache.cxf.service.model.ServiceInfo;
035: import org.apache.cxf.service.model.ServiceModelUtil;
036: import org.apache.cxf.transport.DestinationFactoryManager;
037: import org.apache.cxf.wsdl11.WSDLServiceBuilder;
038: import org.easymock.classextension.EasyMock;
039: import org.easymock.classextension.IMocksControl;
040: import org.junit.After;
041: import org.junit.Assert;
042: import org.junit.Before;
043: import org.junit.Test;
044:
045: import static org.easymock.EasyMock.expect;
046:
047: public class ServiceModelUtilTest extends Assert {
048: private static final String WSDL_PATH = "test-soap-header.wsdl";
049: private Definition def;
050: private Service service;
051: private ServiceInfo serviceInfo;
052:
053: private IMocksControl control;
054: private Bus bus;
055: private BindingFactoryManager bindingFactoryManager;
056:
057: @Before
058: public void setUp() throws Exception {
059: String wsdlUrl = getClass().getResource(WSDL_PATH).toString();
060: WSDLFactory wsdlFactory = WSDLFactory.newInstance();
061: WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
062: wsdlReader.setFeature("javax.wsdl.verbose", false);
063: def = wsdlReader.readWSDL(wsdlUrl);
064:
065: WSDLServiceBuilder wsdlServiceBuilder = new WSDLServiceBuilder(
066: bus);
067: for (Service serv : CastUtils.cast(def.getServices().values(),
068: Service.class)) {
069: if (serv != null) {
070: service = serv;
071: break;
072: }
073: }
074:
075: control = EasyMock.createNiceControl();
076: bus = control.createMock(Bus.class);
077: bindingFactoryManager = control
078: .createMock(BindingFactoryManager.class);
079: wsdlServiceBuilder = new WSDLServiceBuilder(bus);
080:
081: EasyMock.expect(bus.getExtension(BindingFactoryManager.class))
082: .andReturn(bindingFactoryManager);
083:
084: DestinationFactoryManager dfm = control
085: .createMock(DestinationFactoryManager.class);
086: expect(bus.getExtension(DestinationFactoryManager.class))
087: .andStubReturn(dfm);
088:
089: control.replay();
090: serviceInfo = wsdlServiceBuilder.buildServices(def, service)
091: .get(0);
092: }
093:
094: @After
095: public void tearDown() throws Exception {
096:
097: }
098:
099: @Test
100: public void testGetSchema() throws Exception {
101: BindingInfo bindingInfo = null;
102: bindingInfo = serviceInfo.getBindings().iterator().next();
103: QName name = new QName(serviceInfo.getName().getNamespaceURI(),
104: "inHeader");
105: BindingOperationInfo inHeader = bindingInfo.getOperation(name);
106: BindingMessageInfo input = inHeader.getInput();
107: assertNotNull(input);
108: assertEquals(input.getMessageInfo().getName().getLocalPart(),
109: "inHeaderRequest");
110: assertEquals(
111: input.getMessageInfo().getName().getNamespaceURI(),
112: "http://org.apache.cxf/headers");
113: assertEquals(input.getMessageInfo().getMessageParts().size(), 2);
114: assertTrue(input.getMessageInfo().getMessageParts().get(0)
115: .isElement());
116: assertEquals(input.getMessageInfo().getMessageParts().get(0)
117: .getElementQName().getLocalPart(), "inHeader");
118: assertEquals(input.getMessageInfo().getMessageParts().get(0)
119: .getElementQName().getNamespaceURI(),
120: "http://org.apache.cxf/headers");
121:
122: assertTrue(input.getMessageInfo().getMessageParts().get(0)
123: .isElement());
124: assertEquals(input.getMessageInfo().getMessageParts().get(1)
125: .getElementQName().getLocalPart(), "passenger");
126: assertEquals(input.getMessageInfo().getMessageParts().get(1)
127: .getElementQName().getNamespaceURI(),
128: "http://mycompany.example.com/employees");
129: assertTrue(input.getMessageInfo().getMessageParts().get(1)
130: .isElement());
131:
132: MessagePartInfo messagePartInfo = input.getMessageInfo()
133: .getMessageParts().get(0);
134: SchemaInfo schemaInfo = ServiceModelUtil.getSchema(serviceInfo,
135: messagePartInfo);
136: assertEquals(schemaInfo.getNamespaceURI(),
137: "http://org.apache.cxf/headers");
138:
139: messagePartInfo = input.getMessageInfo().getMessageParts().get(
140: 1);
141: schemaInfo = ServiceModelUtil.getSchema(serviceInfo,
142: messagePartInfo);
143: assertEquals(schemaInfo.getNamespaceURI(),
144: "http://mycompany.example.com/employees");
145: }
146: }
|