01: package org.objectweb.celtix.bus.bindings.xml;
02:
03: import java.net.*;
04: import java.util.*;
05: import javax.wsdl.Binding;
06: import javax.wsdl.BindingInput;
07: import javax.wsdl.BindingOperation;
08: import javax.wsdl.BindingOutput;
09: import javax.wsdl.Definition;
10: import javax.wsdl.extensions.ExtensionRegistry;
11: import javax.xml.namespace.QName;
12:
13: import junit.framework.TestCase;
14:
15: import org.objectweb.celtix.Bus;
16: import org.objectweb.celtix.bindings.xmlformat.TBody;
17:
18: public class XMLBindingExtensionTest extends TestCase {
19:
20: public void testExtensionRegister() throws Exception {
21: Bus bus = Bus.init();
22: int inCount = 0;
23: int outCount = 0;
24: ExtensionRegistry registry = bus.getWSDLManager()
25: .getExtenstionRegistry();
26: assertNotNull(registry);
27:
28: if (registry.getAllowableExtensions(BindingInput.class) != null) {
29: inCount = registry.getAllowableExtensions(
30: BindingInput.class).size();
31: }
32:
33: if (registry.getAllowableExtensions(BindingOutput.class) != null) {
34: outCount = registry.getAllowableExtensions(
35: BindingOutput.class).size();
36: }
37:
38: Set inputSet = registry
39: .getAllowableExtensions(BindingInput.class);
40: Set outputSet = registry
41: .getAllowableExtensions(BindingOutput.class);
42:
43: assertNotNull(inputSet);
44: assertNotNull(outputSet);
45:
46: assertEquals(inputSet.size() - inCount, outputSet.size()
47: - outCount);
48: // Since during the bus init, the xml binding factory already register the extensor
49: // So, there should have no difference.
50: assertTrue(inputSet.size() == inCount);
51: assertTrue(outputSet.size() == outCount);
52: }
53:
54: public void testXMLBindingExtensor() throws Exception {
55: Bus bus = Bus.init();
56: ExtensionRegistry registry = bus.getWSDLManager()
57: .getExtenstionRegistry();
58: assertNotNull(registry);
59:
60: URL wsdlUrl = getClass().getResource(
61: "/wsdl/hello_world_xml_bare.wsdl");
62: Definition definition = bus.getWSDLManager().getDefinition(
63: wsdlUrl);
64: assertNotNull(definition);
65: QName wsdlName = new QName(
66: "http://objectweb.org/hello_world_xml_http/bare",
67: "HelloWorld");
68: assertEquals(definition.getQName(), wsdlName);
69:
70: QName bindingName = new QName(
71: "http://objectweb.org/hello_world_xml_http/bare",
72: "Greeter_XMLBinding");
73: Binding binding = definition.getBinding(bindingName);
74: assertNotNull(binding);
75:
76: BindingOperation operation = binding.getBindingOperation(
77: "sayHi", "sayHiRequest", "sayHiResponse");
78: assertNotNull(operation);
79: BindingInput input = operation.getBindingInput();
80: assertNotNull(input);
81:
82: TBody xmlBinding = null;
83: Iterator ite = input.getExtensibilityElements().iterator();
84: while (ite.hasNext()) {
85: Object obj = ite.next();
86: if (obj instanceof TBody) {
87: xmlBinding = (TBody) obj;
88: }
89: }
90: assertNotNull(xmlBinding);
91: assertEquals(new QName(
92: "http://objectweb.org/hello_world_xml_http/bare",
93: "sayHi"), xmlBinding.getRootNode());
94: }
95: }
|