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.codehaus.xfire.aegis.inheritance;
019:
020: import java.util.ArrayList;
021: import java.util.HashMap;
022: import java.util.List;
023: import java.util.Map;
024:
025: import javax.xml.namespace.QName;
026:
027: import org.w3c.dom.Document;
028: import org.w3c.dom.Node;
029:
030: import org.apache.cxf.aegis.AbstractAegisTest;
031: import org.apache.cxf.aegis.databinding.AegisDatabinding;
032: import org.apache.cxf.aegis.util.XmlConstants;
033: import org.apache.cxf.frontend.ServerFactoryBean;
034: import org.junit.Before;
035: import org.junit.Test;
036:
037: /**
038: * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
039: */
040: public class InheritancePOJOTest extends AbstractAegisTest {
041:
042: @Before
043: public void setUp() throws Exception {
044: super .setUp();
045:
046: ServerFactoryBean sf = createServiceFactory(
047: InheritanceService.class,
048: "InheritanceService",
049: new QName("urn:xfire:inheritance", "InheritanceService"));
050:
051: Map<String, Object> props = new HashMap<String, Object>();
052: props.put(AegisDatabinding.WRITE_XSI_TYPE_KEY, "true");
053:
054: List<String> l = new ArrayList<String>();
055: l.add(Employee.class.getName());
056:
057: props.put(AegisDatabinding.OVERRIDE_TYPES_KEY, l);
058:
059: sf.getServiceFactory().setProperties(props);
060: sf.create();
061: }
062:
063: @Test
064: public void testGenerateWsdl() throws Exception {
065: Document d = getWSDLDocument("InheritanceService");
066:
067: String types = "//wsdl:types/xsd:schema/";
068:
069: // check for Employee as extension
070: String employeeType = types
071: + "xsd:complexType[@name='Employee']";
072: assertValid(employeeType, d);
073: String extension = "/xsd:complexContent/xsd:extension[@base='ns1:AbstractUser']";
074: assertValid(employeeType + extension, d);
075: assertValid(employeeType + extension
076: + "/xsd:sequence/xsd:element[@name='division']", d);
077: // assertValid("count(" + employeeType + extension +
078: // "/xsd:sequence/*)=1", d);
079:
080: // check for BaseUser as abstract
081: String baseUserType = types
082: + "xsd:complexType[(@name='AbstractUser') and (@abstract='true')]";
083: assertValid(baseUserType, d);
084: assertValid(baseUserType
085: + "/xsd:sequence/xsd:element[@name='name']", d);
086: // assertValid("count(" + baseUserType + "/xsd:sequence/*)=1", d);
087: }
088:
089: @Test
090: public void testLocalReceiveEmployee() throws Exception {
091: Node response = invoke("InheritanceService",
092: "ReceiveEmployee.xml");
093: addNamespace("w", "urn:xfire:inheritance");
094: assertValid("//s:Body/w:receiveUserResponse", response);
095: }
096:
097: @Test
098: public void testLocalGetEmployee() throws Exception {
099: Node response = invoke("InheritanceService", "GetEmployee.xml");
100: addNamespace("xsi", XmlConstants.XSI_NS);
101: addNamespace("w", "urn:xfire:inheritance");
102: addNamespace("p", "http://inheritance.aegis.xfire.codehaus.org");
103: assertValid(
104: "//s:Body/w:getEmployeeResponse/w:return/p:division",
105: response);
106: assertValid(
107: "//s:Body/w:getEmployeeResponse/w:return[@xsi:type]",
108: response);
109: }
110: }
|