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.jaxws;
019:
020: import java.net.URL;
021: import java.util.HashSet;
022: import java.util.Set;
023:
024: import javax.xml.namespace.QName;
025: import javax.xml.ws.BindingProvider;
026: import javax.xml.ws.WebServiceException;
027: import javax.xml.ws.soap.SOAPBinding;
028:
029: import org.apache.cxf.binding.soap.Soap12;
030: import org.apache.cxf.calculator.CalculatorPortType;
031: import org.junit.Test;
032:
033: public class SOAPBindingTest extends AbstractJaxWsTest {
034:
035: private static final QName SERVICE_1 = new QName(
036: "http://apache.org/cxf/calculator", "CalculatorService");
037:
038: private static final QName PORT_1 = new QName(
039: "http://apache.org/cxf/calculator", "CalculatorPort");
040:
041: @Test
042: public void testRoles() throws Exception {
043: URL wsdl1 = getClass().getResource("/wsdl/calculator.wsdl");
044: assertNotNull(wsdl1);
045:
046: ServiceImpl service = new ServiceImpl(getBus(), wsdl1,
047: SERVICE_1, ServiceImpl.class);
048:
049: CalculatorPortType cal = (CalculatorPortType) service.getPort(
050: PORT_1, CalculatorPortType.class);
051:
052: BindingProvider bindingProvider = (BindingProvider) cal;
053:
054: assertTrue(bindingProvider.getBinding() instanceof SOAPBinding);
055: SOAPBinding binding = (SOAPBinding) bindingProvider
056: .getBinding();
057:
058: assertNotNull(binding.getRoles());
059: assertEquals(2, binding.getRoles().size());
060: assertTrue(binding.getRoles().contains(
061: Soap12.getInstance().getNextRole()));
062: assertTrue(binding.getRoles().contains(
063: Soap12.getInstance().getUltimateReceiverRole()));
064:
065: String myrole = "http://myrole";
066: Set<String> roles = new HashSet<String>();
067: roles.add(myrole);
068:
069: binding.setRoles(roles);
070:
071: assertNotNull(binding.getRoles());
072: assertEquals(3, binding.getRoles().size());
073: assertTrue(binding.getRoles().contains(myrole));
074: assertTrue(binding.getRoles().contains(
075: Soap12.getInstance().getNextRole()));
076: assertTrue(binding.getRoles().contains(
077: Soap12.getInstance().getUltimateReceiverRole()));
078:
079: roles.add(Soap12.getInstance().getNoneRole());
080:
081: try {
082: binding.setRoles(roles);
083: fail("did not throw exception");
084: } catch (WebServiceException e) {
085: // that's expected with none role
086: }
087: }
088:
089: @Test
090: public void testSAAJ() throws Exception {
091: URL wsdl1 = getClass().getResource("/wsdl/calculator.wsdl");
092: assertNotNull(wsdl1);
093:
094: ServiceImpl service = new ServiceImpl(getBus(), wsdl1,
095: SERVICE_1, ServiceImpl.class);
096:
097: CalculatorPortType cal = (CalculatorPortType) service.getPort(
098: PORT_1, CalculatorPortType.class);
099:
100: BindingProvider bindingProvider = (BindingProvider) cal;
101:
102: assertTrue(bindingProvider.getBinding() instanceof SOAPBinding);
103: SOAPBinding binding = (SOAPBinding) bindingProvider
104: .getBinding();
105:
106: assertNotNull(binding.getMessageFactory());
107:
108: assertNotNull(binding.getSOAPFactory());
109: }
110:
111: }
|