1
2
3
4
5
6
7
8 package it.imolinfo.jbi4ejb.test.wsdlgeneration;
9
10 import it.imolinfo.jbi4ejb.jbi.wsdl.Jbi4EjbAddress;
11 import it.imolinfo.jbi4ejb.jbi.wsdl.Jbi4EjbBinding;
12 import it.imolinfo.jbi4ejb.jbi.wsdl.Jbi4EjbExtension;
13 import it.imolinfo.jbi4ejb.jbi.wsdl.Jbi4EjbTypes;
14 import it.imolinfo.jbi4ejb.test.TestUtils;
15
16 import java.io.File;
17 import java.io.FileWriter;
18 import java.io.StringWriter;
19 import java.util.Properties;
20
21 import javax.wsdl.Binding;
22 import javax.wsdl.BindingOperation;
23 import javax.wsdl.Definition;
24 import javax.wsdl.Operation;
25 import javax.wsdl.Port;
26 import javax.wsdl.PortType;
27 import javax.wsdl.Service;
28 import javax.xml.namespace.QName;
29
30 import junit.framework.TestCase;
31
32
33
34
35
36 public class WSDLExtensionsTest extends TestCase {
37
38
39 private static final String ECHO_SERVICE_NO_EXTENSIONS_WSDL = "EchoService_Abstract_No_extensions.wsdl";
40
41 private static final String WSDL_DIR = "src/test/etc/wsdl";
42
43 private String tns = "test-namespace";
44
45 public WSDLExtensionsTest() {}
46
47 private File tempDir = null;
48
49
50 public void setUp() {
51 tempDir = TestUtils.createTempDir();
52 }
53
54
55
56
57 public void testWSDLSerializer() {
58
59 try {
60 Definition def = TestUtils.getExtendedWSDLReader().readWSDL(WSDL_DIR,ECHO_SERVICE_NO_EXTENSIONS_WSDL);
61
62
63 def.addNamespace(Jbi4EjbExtension.DEFAULT_PREFIX, Jbi4EjbExtension.NS_URI_JBI4EJB);
64
65
66 Service myService = def.createService();
67 myService.setQName(new QName(tns, "MyService"));
68 def.addService(myService);
69
70
71 Port myPort = def.createPort();
72 myPort.setName("myPort");
73 myService.addPort(myPort);
74
75
76 Jbi4EjbTypes ejbTypes = new Jbi4EjbTypes();
77 ejbTypes.setElementType(Jbi4EjbExtension.Q_ELEM_JBI4EJB_TYPES);
78 Properties types = new Properties();
79 types.put("myclass", "-12");
80 types.put("myclass2", "-14");
81 ejbTypes.setTypesSerialVersionUIDs(types);
82 def.addExtensibilityElement(ejbTypes);
83
84
85 Jbi4EjbAddress ejbAddress = new Jbi4EjbAddress();
86 ejbAddress.setElementType(Jbi4EjbExtension.Q_ELEM_JBI4EJB_ADDRESS);
87 ejbAddress.setName("name");
88 ejbAddress.setLocalizationType("corbaname");
89 myPort.addExtensibilityElement(ejbAddress);
90
91
92 PortType portType = def.getPortType(new QName(tns,"EchoServicePortType"));
93 Binding myBinding = def.createBinding();
94 myBinding.setUndefined(false);
95 myBinding.setQName(new QName(tns, "MyBinding"));
96 myBinding.setPortType(portType);
97 myPort.setBinding(myBinding);
98 def.addBinding(myBinding);
99 BindingOperation myOp = def.createBindingOperation();
100 myOp.setName("myOp");
101 myOp.setOperation((Operation)portType.getOperations().get(0));
102 myBinding.addBindingOperation(myOp);
103
104
105 Jbi4EjbBinding ejbBinding = new Jbi4EjbBinding();
106 ejbBinding.setElementType(Jbi4EjbExtension.Q_ELEM_JBI4EJB_BINDING);
107
108
109 Properties orbProperties = new Properties();
110 orbProperties.setProperty("org.omg.CORBA.ORBInitialPort", "1050");
111 orbProperties.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
112 ejbBinding.setOrbProperties(orbProperties);
113
114 myBinding.addExtensibilityElement(ejbBinding);
115
116
117 String wsdlFileName = tempDir + File.separator + "TestWSDLwriter.wsdl";
118 File wsdlFile = new File(wsdlFileName);
119 FileWriter fileWriter = new FileWriter(wsdlFile);
120
121 TestUtils.getExtendedWSDLWriter().writeWSDL(def, fileWriter);
122
123
124 Definition def2 = TestUtils.getExtendedWSDLReader().readWSDL(tempDir.getAbsolutePath(),"TestWSDLwriter.wsdl");
125 StringWriter strWriter = new StringWriter();
126 TestUtils.getExtendedWSDLWriter().writeWSDL(def2, strWriter);
127 System.out.println(strWriter);
128 wsdlFile.delete();
129
130
131 Binding extBinding = def2.getBinding(new QName(tns, "MyBinding"));
132 Jbi4EjbBinding readenJbi4EjbBinding = (Jbi4EjbBinding) extBinding.getExtensibilityElements().get(0);
133 Service extService = def2.getService(new QName(tns, "MyService"));
134 Port extPort = (Port)extService.getPort("myPort");
135 Jbi4EjbAddress readenJbi4EjbAddress = (Jbi4EjbAddress) extPort.getExtensibilityElements().get(0);
136 Jbi4EjbTypes readenJbi4EjbTypes = (Jbi4EjbTypes) def2.getExtensibilityElements().get(0);
137
138
139 assertTrue(readenJbi4EjbBinding.equals(ejbBinding));
140 assertTrue(readenJbi4EjbAddress.equals(ejbAddress));
141 assertTrue(readenJbi4EjbTypes.equals(ejbTypes));
142
143 } catch (Exception e) {
144
145 System.out.print(e.getMessage());
146 e.printStackTrace();
147 fail(e.getMessage());
148 }
149 }
150
151
152 public void tearDown() {
153
154 tempDir.delete();
155 }
156
157
158 }