|
Apache CXF example source code file (WSDLToCorbaBindingTypeTest.java)
The Apache CXF WSDLToCorbaBindingTypeTest.java source code/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package org.apache.cxf.tools.corba.processors; import java.io.File; import java.net.URI; import java.net.URL; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import javax.wsdl.Definition; import javax.wsdl.Port; import javax.wsdl.Service; import javax.wsdl.xml.WSDLWriter; import javax.xml.namespace.QName; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.apache.cxf.binding.corba.wsdl.AddressType; import org.apache.cxf.binding.corba.wsdl.Anonarray; import org.apache.cxf.binding.corba.wsdl.Anonfixed; import org.apache.cxf.binding.corba.wsdl.Anonsequence; import org.apache.cxf.binding.corba.wsdl.Anonstring; import org.apache.cxf.binding.corba.wsdl.Array; import org.apache.cxf.binding.corba.wsdl.CorbaTypeImpl; import org.apache.cxf.binding.corba.wsdl.Struct; import org.apache.cxf.binding.corba.wsdl.TypeMappingType; import org.apache.cxf.binding.corba.wsdl.Union; import org.apache.cxf.binding.corba.wsdl.Unionbranch; import org.apache.cxf.helpers.DOMUtils; import org.apache.cxf.tools.corba.common.WSDLCorbaFactory; import org.apache.cxf.tools.corba.processors.wsdl.WSDLToCorbaBinding; import org.apache.cxf.tools.corba.processors.wsdl.WSDLToIDLAction; import org.junit.Assert; import org.junit.Before; import org.junit.Test; public class WSDLToCorbaBindingTypeTest extends Assert { WSDLToCorbaBinding generator; WSDLWriter writer; @Before public void setUp() { generator = new WSDLToCorbaBinding(); try { WSDLCorbaFactory wsdlfactory = WSDLCorbaFactory .newInstance("org.apache.cxf.tools.corba.common.WSDLCorbaFactoryImpl"); writer = wsdlfactory.newWSDLWriter(); } catch (Exception ex) { ex.printStackTrace(); } } private Element getElementNode(Document document, String elName) { Element root = document.getDocumentElement(); for (Node nd = root.getFirstChild(); nd != null; nd = nd.getNextSibling()) { if (Node.ELEMENT_NODE == nd.getNodeType() && (elName.equals(nd.getNodeName()))) { return (Element)nd; } } return null; } @Test public void testWsAddressingAccountType() throws Exception { try { String fileName = getClass().getResource("/wsdl/wsaddressing_bank.wsdl").toString(); generator.setWsdlFile(fileName); generator.addInterfaceName("Bank"); Definition model = generator.generateCORBABinding(); Document document = writer.getDocument(model); Element typemap = getElementNode(document, "corba:typeMapping"); assertNotNull(typemap); assertEquals(1, DOMUtils.findAllElementsByTagNameNS(typemap, "http://cxf.apache.org/bindings/corba", "sequence").size()); assertEquals(2, DOMUtils.findAllElementsByTagNameNS(typemap, "http://cxf.apache.org/bindings/corba", "object").size()); WSDLToIDLAction idlgen = new WSDLToIDLAction(); idlgen.setBindingName("BankCORBABinding"); idlgen.setOutputFile("wsaddressing_bank.idl"); idlgen.generateIDL(model); File f = new File("wsaddressing_bank.idl"); assertTrue("wsaddressing_bank.idl should be generated", f.exists()); } finally { new File("wsaddressing_bank.idl").deleteOnExit(); } } @Test public void testWsAddressingBankType() throws Exception { try { String fileName = getClass().getResource("/wsdl/wsaddressing_account.wsdl").toString(); generator.setWsdlFile(fileName); generator.addInterfaceName("Account"); Definition model = generator.generateCORBABinding(); Document document = writer.getDocument(model); Element typemap = getElementNode(document, "corba:typeMapping"); assertNotNull(typemap); assertEquals(1, typemap.getElementsByTagName("corba:object").getLength()); WSDLToIDLAction idlgen = new WSDLToIDLAction(); idlgen.setBindingName("AccountCORBABinding"); idlgen.setOutputFile("wsaddressing_account.idl"); idlgen.generateIDL(model); File f = new File("wsaddressing_account.idl"); assertTrue("wsaddressing_account.idl should be generated", f.exists()); } finally { new File("wsaddressing_account.idl").deleteOnExit(); } } @Test public void testWsAddressingTypes() throws Exception { try { String fileName = getClass().getResource("/wsdl/wsaddressing_server.wsdl").toString(); generator.setWsdlFile(fileName); generator.addInterfaceName("TestServer"); Definition model = generator.generateCORBABinding(); Document document = writer.getDocument(model); Element typemap = getElementNode(document, "corba:typeMapping"); assertNotNull(typemap); assertEquals(1, typemap.getElementsByTagName("corba:object").getLength()); WSDLToIDLAction idlgen = new WSDLToIDLAction(); idlgen.setBindingName("TestServerCORBABinding"); idlgen.setOutputFile("wsaddressing_server.idl"); idlgen.generateIDL(model); File f = new File("wsaddressing_server.idl"); assertTrue("wsaddressing_server.idl should be generated", f.exists()); } finally { new File("wsaddressing_server.idl").deleteOnExit(); } } @Test public void testDateTimeTypes() throws Exception { try { String fileName = getClass().getResource("/wsdl/datetime.wsdl").toString(); generator.setWsdlFile(fileName); generator.addInterfaceName("BasePortType"); Definition model = generator.generateCORBABinding(); Document document = writer.getDocument(model); Element typemap = getElementNode(document, "corba:typeMapping"); assertNotNull(typemap); assertEquals(2, typemap.getElementsByTagName("corba:union").getLength()); assertEquals(2, typemap.getElementsByTagName("corba:struct").getLength()); WSDLToIDLAction idlgen = new WSDLToIDLAction(); idlgen.setBindingName("BaseCORBABinding"); idlgen.setOutputFile("datetime.idl"); idlgen.generateIDL(model); File f = new File("datetime.idl"); assertTrue("datetime.idl should be generated", f.exists()); } finally { new File("datetime.idl").deleteOnExit(); } } @Test public void testNestedInterfaceTypes() throws Exception { try { String fileName = getClass().getResource("/wsdl/nested_interfaces.wsdl").toString(); generator.setWsdlFile(fileName); generator.addInterfaceName("C.C1"); Definition model = generator.generateCORBABinding(); Document document = writer.getDocument(model); Element typemap = getElementNode(document, "corba:typeMapping"); assertNotNull(typemap); assertEquals(1, typemap.getElementsByTagName("corba:anonstring").getLength()); assertEquals(9, typemap.getElementsByTagName("corba:struct").getLength()); WSDLToIDLAction idlgen = new WSDLToIDLAction(); idlgen.setBindingName("C.C1CORBABinding"); idlgen.setOutputFile("nested_interfaces.idl"); idlgen.generateIDL(model); File f = new File("nested_interfaces.idl"); assertTrue("nested_interfaces.idl should be generated", f.exists()); } finally { new File("nested_interfaces.idl").deleteOnExit(); } } @Test public void testNestedComplexTypes() throws Exception { try { String fileName = getClass().getResource("/wsdl/nested_complex.wsdl").toString(); generator.setWsdlFile(fileName); generator.addInterfaceName("X"); Definition model = generator.generateCORBABinding(); Document document = writer.getDocument(model); Element typemap = getElementNode(document, "corba:typeMapping"); assertNotNull(typemap); assertEquals(6, typemap.getElementsByTagName("corba:union").getLength()); assertEquals(14, typemap.getElementsByTagName("corba:struct").getLength()); assertEquals(1, typemap.getElementsByTagName("corba:enum").getLength()); assertEquals(1, typemap.getElementsByTagName("corba:array").getLength()); WSDLToIDLAction idlgen = new WSDLToIDLAction(); idlgen.setBindingName("XCORBABinding"); idlgen.setOutputFile("nested_complex.idl"); idlgen.generateIDL(model); File f = new File("nested_complex.idl"); assertTrue("nested_complex.idl should be generated", f.exists()); } finally { new File("nested_complex.idl").deleteOnExit(); } } @Test public void testNestedDerivedTypes() throws Exception { try { String fileName = getClass().getResource("/wsdl/nested-derivedtypes.wsdl").toString(); generator.setWsdlFile(fileName); generator.addInterfaceName("DerivedTypesPortType"); Definition model = generator.generateCORBABinding(); Document document = writer.getDocument(model); Element typemap = getElementNode(document, "corba:typeMapping"); assertNotNull(typemap); assertEquals(6, typemap.getElementsByTagName("corba:union").getLength()); assertEquals(58, typemap.getElementsByTagName("corba:struct").getLength()); assertEquals(3, typemap.getElementsByTagName("corba:sequence").getLength()); WSDLToIDLAction idlgen = new WSDLToIDLAction(); idlgen.setBindingName("DerivedTypesCORBABinding"); idlgen.setOutputFile("nested-derivedtypes.idl"); idlgen.generateIDL(model); File f = new File("nested-derivedtypes.idl"); assertTrue("nested-derivedtypes.idl should be generated", f.exists()); } finally { new File("nested-derivedtypes.idl").deleteOnExit(); } } @Test public void testNestedType() throws Exception { try { String fileName = getClass().getResource("/wsdl/nested.wsdl").toString(); generator.setWsdlFile(fileName); generator.addInterfaceName("TypeInheritancePortType"); Definition model = generator.generateCORBABinding(); Document document = writer.getDocument(model); Element typemap = getElementNode(document, "corba:typeMapping"); assertNotNull(typemap); assertEquals(4, typemap.getElementsByTagName("corba:union").getLength()); assertEquals(23, typemap.getElementsByTagName("corba:struct").getLength()); assertEquals(1, typemap.getElementsByTagName("corba:anonstring").getLength()); WSDLToIDLAction idlgen = new WSDLToIDLAction(); idlgen.setBindingName("TypeInheritanceCORBABinding"); idlgen.setOutputFile("nested.idl"); idlgen.generateIDL(model); File f = new File("nested.idl"); assertTrue("nested.idl should be generated", f.exists()); } finally { new File("nested.idl").deleteOnExit(); } } @Test public void testNillableType() throws Exception { try { String fileName = getClass().getResource("/wsdl/nillable.wsdl").toString(); generator.setWsdlFile(fileName); generator.addInterfaceName("NillablePortType"); Definition model = generator.generateCORBABinding(); Document document = writer.getDocument(model); Element typemap = getElementNode(document, "corba:typeMapping"); assertNotNull(typemap); assertEquals(2, typemap.getElementsByTagName("corba:union").getLength()); assertEquals(1, typemap.getElementsByTagName("corba:struct").getLength()); TypeMappingType mapType = (TypeMappingType)model.getExtensibilityElements().get(0); WSDLToIDLAction idlgen = new WSDLToIDLAction(); idlgen.setBindingName("NillableCORBABinding"); idlgen.setOutputFile("nillable.idl"); idlgen.generateIDL(model); Union un = (Union)mapType.getStructOrExceptionOrUnion().get(2); assertEquals("Name is incorrect for Union Type", "long_nil", un.getName()); assertEquals("Type is incorrect for Union Type", "PEl", un.getType().getLocalPart()); Unionbranch unbranch = un.getUnionbranch().get(0); assertEquals("Name is incorrect for UnionBranch Type", "value", unbranch.getName()); assertEquals("Type is incorrect for UnionBranch Type", "long", unbranch.getIdltype().getLocalPart()); File f = new File("nillable.idl"); assertTrue("nillable.idl should be generated", f.exists()); } finally { new File("nillable.idl").deleteOnExit(); } } // tests Type Inheritance and attributes. @Test public void testTypeInheritance() throws Exception { try { String fileName = getClass().getResource("/wsdl/TypeInheritance.wsdl").toString(); generator.setWsdlFile(fileName); generator.addInterfaceName("TypeInheritancePortType"); Definition model = generator.generateCORBABinding(); Document document = writer.getDocument(model); Element typemap = getElementNode(document, "corba:typeMapping"); assertNotNull(typemap); assertEquals(3, typemap.getElementsByTagName("corba:union").getLength()); assertEquals(1, typemap.getElementsByTagName("corba:anonstring").getLength()); assertEquals(17, typemap.getElementsByTagName("corba:struct").getLength()); TypeMappingType mapType = (TypeMappingType)model.getExtensibilityElements().get(0); WSDLToIDLAction idlgen = new WSDLToIDLAction(); idlgen.setBindingName("TypeInheritanceCORBABinding"); idlgen.setOutputFile("typeInherit.idl"); idlgen.generateIDL(model); List<CorbaTypeImpl> types = mapType.getStructOrExceptionOrUnion(); for (int i = 0; i < types.size(); i++) { CorbaTypeImpl type = types.get(i); if ("Type5SequenceStruct".equals(type.getName())) { assertTrue("Name is incorrect for Type5SequenceStruct Type", type instanceof Struct); assertEquals("Type is incorrect for AnonSequence Type", "Type5", type.getType().getLocalPart()); } else if ("attrib2Type".equals(type.getName())) { assertTrue("Name is incorrect for attrib2Type Type", type instanceof Anonstring); assertEquals("Type is incorrect for AnonString Type", "string", type.getType().getLocalPart()); } else if ("attrib2Type_nil".equals(type.getName())) { assertTrue("Name is incorrect for Struct Type", type instanceof Union); assertEquals("Type is incorrect for AnonSequence Type", "attrib2", type.getType().getLocalPart()); } } File f = new File("typeInherit.idl"); assertTrue("typeInherit.idl should be generated", f.exists()); } finally { new File("typeInherit.idl").deleteOnExit(); } } // tests anonymous strings and fixed types. @Test public void testAnonFixedType() throws Exception { try { String fileName = getClass().getResource("/wsdl/anonfixed.wsdl").toString(); generator.setWsdlFile(fileName); generator.addInterfaceName("X"); Definition model = generator.generateCORBABinding(); Document document = writer.getDocument(model); Element typemap = getElementNode(document, "corba:typeMapping"); assertNotNull(typemap); assertEquals(1, typemap.getElementsByTagName("corba:anonfixed").getLength()); assertEquals(1, typemap.getElementsByTagName("corba:anonstring").getLength()); assertEquals(3, typemap.getElementsByTagName("corba:struct").getLength()); TypeMappingType mapType = (TypeMappingType)model.getExtensibilityElements().get(0); WSDLToIDLAction idlgen = new WSDLToIDLAction(); idlgen.setBindingName("XCORBABinding"); idlgen.setOutputFile("atype.idl"); idlgen.generateIDL(model); List<CorbaTypeImpl> types = mapType.getStructOrExceptionOrUnion(); for (int i = 0; i < types.size(); i++) { CorbaTypeImpl type = types.get(i); if (type instanceof Anonstring) { Anonstring str = (Anonstring)type; assertEquals("Name is incorrect for Array Type", "X._1_S", str.getName()); assertEquals("Type is incorrect for AnonString Type", "string", str.getType().getLocalPart()); } else if (type instanceof Anonfixed) { Anonfixed fx = (Anonfixed)type; assertEquals("Name is incorrect for Anon Array Type", "X._2_S", fx.getName()); assertEquals("Type is incorrect for AnonFixed Type", "decimal", fx.getType().getLocalPart()); } else if (type instanceof Struct) { Struct struct = (Struct)type; String[] testResult; if ("X.op_a".equals(struct.getName())) { testResult = new String[]{"X.op_a", "X.op_a", "p1", "X.S", "p2", "X.S"}; } else if ("X.op_aResult".equals(struct.getName())) { testResult = new String[]{"X.op_aResult", "X.op_aResult", "return", "X.S", "p2", "X.S"}; } else { testResult = new String[]{"X.S", "X.S", "str", "X._1_S", "fx", "X._2_S"}; } assertEquals("Name is incorrect for Anon Array Type", testResult[0], struct.getName()); assertEquals("Type is incorrect for Struct Type", testResult[1], struct.getType().getLocalPart()); assertEquals("Name for first Struct Member Type is incorrect", testResult[2], struct.getMember().get(0).getName()); assertEquals("Idltype for first Struct Member Type is incorrect", testResult[3], struct.getMember().get(0).getIdltype().getLocalPart()); assertEquals("Name for second Struct Member Type is incorrect", testResult[4], struct.getMember().get(1).getName()); assertEquals("Idltype for second Struct Member Type is incorrect", testResult[5], struct.getMember().get(1).getIdltype().getLocalPart()); } else { //System.err.println("Type: " + i + " " + type.getClass().getName()); } } File f = new File("atype.idl"); assertTrue("atype.idl should be generated", f.exists()); } finally { new File("atype.idl").deleteOnExit(); } } // tests anonymous arrays and sequences @Test public void testAnonType() throws Exception { try { String fileName = getClass().getResource("/wsdl/atype.wsdl").toString(); generator.setWsdlFile(fileName); generator.addInterfaceName("X"); Definition model = generator.generateCORBABinding(); Document document = writer.getDocument(model); Element typemap = getElementNode(document, "corba:typeMapping"); assertNotNull(typemap); assertEquals(3, typemap.getElementsByTagName("corba:anonsequence").getLength()); assertEquals(2, typemap.getElementsByTagName("corba:anonarray").getLength()); assertEquals(1, typemap.getElementsByTagName("corba:array").getLength()); assertEquals(2, typemap.getElementsByTagName("corba:struct").getLength()); TypeMappingType mapType = (TypeMappingType)model.getExtensibilityElements().get(0); Map<String, CorbaTypeImpl> tmap = new HashMap Other Apache CXF examples (source code examples)Here is a short list of links related to this Apache CXF WSDLToCorbaBindingTypeTest.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.