Search in sources :

Example 1 with XMLFormatBinding

use of org.apache.cxf.bindings.xformat.XMLFormatBinding in project cxf by apache.

the class WSDLToXMLProcessorTest method testAllDefault.

@Test
public void testAllDefault() throws Exception {
    String[] args = new String[] { "-i", "Greeter", "-d", output.getCanonicalPath(), getLocation("/misctools_wsdl/hello_world.wsdl") };
    WSDLToXML.main(args);
    File outputFile = new File(output, "hello_world-xmlbinding.wsdl");
    assertTrue("New wsdl file is not generated", outputFile.exists());
    WSDLToXMLProcessor processor = new WSDLToXMLProcessor();
    processor.setEnvironment(env);
    processor.parseWSDL(outputFile.getAbsolutePath());
    Binding binding = processor.getWSDLDefinition().getBinding(new QName(processor.getWSDLDefinition().getTargetNamespace(), "Greeter_XMLBinding"));
    if (binding == null) {
        fail("Element wsdl:binding Greeter_XMLBinding Missed!");
    }
    boolean found = false;
    for (Object obj : binding.getExtensibilityElements()) {
        if (obj instanceof XMLFormatBinding) {
            found = true;
            break;
        }
    }
    if (!found) {
        fail("Element <xformat:binding/> Missed!");
    }
    BindingOperation bo = binding.getBindingOperation("sayHi", null, null);
    if (bo == null) {
        fail("Element <wsdl:operation name=\"sayHi\"> Missed!");
    }
    found = false;
    for (Object obj : bo.getBindingInput().getExtensibilityElements()) {
        if (obj instanceof XMLBindingMessageFormat && ((XMLBindingMessageFormat) obj).getRootNode().getLocalPart().equals("sayHi")) {
            found = true;
            break;
        }
    }
    if (!found) {
        fail("Element <xformat:body rootNode=\"tns:sayHi\" /> Missed!");
    }
    Service service = processor.getWSDLDefinition().getService(new QName(processor.getWSDLDefinition().getTargetNamespace(), "Greeter_XMLService"));
    if (service == null) {
        fail("Element wsdl:service Greeter_XMLService Missed!");
    }
    found = false;
    for (Object obj : service.getPort("Greeter_XMLPort").getExtensibilityElements()) {
        if (obj instanceof HTTPAddress) {
            HTTPAddress xmlHttpAddress = (HTTPAddress) obj;
            if (xmlHttpAddress.getLocationURI() != null) {
                found = true;
                break;
            }
        }
    }
    if (!found) {
        fail("Element http:address of service port Missed!");
    }
}
Also used : XMLFormatBinding(org.apache.cxf.bindings.xformat.XMLFormatBinding) Binding(javax.wsdl.Binding) HTTPAddress(javax.wsdl.extensions.http.HTTPAddress) QName(javax.xml.namespace.QName) Service(javax.wsdl.Service) BindingOperation(javax.wsdl.BindingOperation) XMLBindingMessageFormat(org.apache.cxf.bindings.xformat.XMLBindingMessageFormat) XMLFormatBinding(org.apache.cxf.bindings.xformat.XMLFormatBinding) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)1 Binding (javax.wsdl.Binding)1 BindingOperation (javax.wsdl.BindingOperation)1 Service (javax.wsdl.Service)1 HTTPAddress (javax.wsdl.extensions.http.HTTPAddress)1 QName (javax.xml.namespace.QName)1 XMLBindingMessageFormat (org.apache.cxf.bindings.xformat.XMLBindingMessageFormat)1 XMLFormatBinding (org.apache.cxf.bindings.xformat.XMLFormatBinding)1 Test (org.junit.Test)1