Search in sources :

Example 11 with XPathUtils

use of org.apache.cxf.helpers.XPathUtils in project cxf by apache.

the class JavaToWSTest method testXmlJavaTypeAdapter.

@Test
public void testXmlJavaTypeAdapter() throws Exception {
    String[] args = new String[] { "-o", output.getPath() + "/xmladapter.wsdl", "-verbose", "-wsdl", "org.apache.xmladapter.GreeterImpl" };
    CommandInterfaceUtils.commandCommonMain();
    JavaToWS j2w = new JavaToWS(args);
    j2w.run();
    File file = new File(output.getPath() + "/xmladapter.wsdl");
    Document doc = StaxUtils.read(file);
    Map<String, String> map = new HashMap<>();
    map.put("xsd", "http://www.w3.org/2001/XMLSchema");
    map.put("wsdl", "http://schemas.xmlsoap.org/wsdl/");
    map.put("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
    XPathUtils util = new XPathUtils(map);
    Element node = (Element) util.getValueNode("//xsd:element[@name='arg0']", doc);
    assertNotNull(node);
    assertEquals("0", node.getAttribute("minOccurs"));
    assertTrue(node.getAttribute("type").contains("string"));
}
Also used : HashMap(java.util.HashMap) XPathUtils(org.apache.cxf.helpers.XPathUtils) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) File(java.io.File) Test(org.junit.Test)

Example 12 with XPathUtils

use of org.apache.cxf.helpers.XPathUtils in project cxf by apache.

the class JavaToProcessorTest method testPropOrderInException2.

@Test
public void testPropOrderInException2() throws Exception {
    env.put(ToolConstants.CFG_OUTPUTFILE, output.getPath() + "/exception_prop_order2.wsdl");
    // env.put(ToolConstants.CFG_OUTPUTFILE, "/x1/tmp/exception_prop_order.wsdl");
    env.put(ToolConstants.CFG_CLASSNAME, "org.apache.cxf.tools.fortest.exception.Echo5Impl");
    env.put(ToolConstants.CFG_VERBOSE, ToolConstants.CFG_VERBOSE);
    processor.setEnvironment(env);
    processor.process();
    File wsdlFile = new File(output, "exception_prop_order2.wsdl");
    assertTrue(wsdlFile.exists());
    Document doc = StaxUtils.read(wsdlFile);
    Map<String, String> map = new HashMap<>();
    map.put("xsd", "http://www.w3.org/2001/XMLSchema");
    map.put("wsdl", "http://schemas.xmlsoap.org/wsdl/");
    map.put("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
    XPathUtils util = new XPathUtils(map);
    Element summary = (Element) util.getValueNode("//xsd:element[@name='summary']", doc);
    Element from = (Element) util.getValueNode("//xsd:element[@name='from']", doc);
    Element id = (Element) util.getValueNode("//xsd:element[@name='id']", doc);
    assertNotNull(summary);
    assertNotNull(from);
    assertNotNull(id);
    Node nd = summary.getNextSibling();
    while (nd != null) {
        if (nd == from) {
            from = null;
        } else if (nd == id) {
            if (from != null) {
                fail("id before from");
            }
            id = null;
        }
        nd = nd.getNextSibling();
    }
    assertNull(id);
    assertNull(from);
}
Also used : HashMap(java.util.HashMap) XPathUtils(org.apache.cxf.helpers.XPathUtils) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) File(java.io.File) Test(org.junit.Test)

Example 13 with XPathUtils

use of org.apache.cxf.helpers.XPathUtils in project cxf by apache.

the class JavaToProcessorTest method testException.

@Test
public void testException() throws Exception {
    env.put(ToolConstants.CFG_OUTPUTFILE, output.getPath() + "/exception.wsdl");
    env.put(ToolConstants.CFG_CLASSNAME, "org.apache.cxf.tools.fortest.simple.Caculator");
    env.put(ToolConstants.CFG_VERBOSE, ToolConstants.CFG_VERBOSE);
    processor.setEnvironment(env);
    processor.process();
    File wsdlFile = new File(output, "exception.wsdl");
    assertTrue(wsdlFile.exists());
    // schema element
    Document doc = StaxUtils.read(wsdlFile);
    Map<String, String> map = new HashMap<>();
    map.put("xsd", "http://www.w3.org/2001/XMLSchema");
    map.put("wsdl", "http://schemas.xmlsoap.org/wsdl/");
    map.put("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
    XPathUtils util = new XPathUtils(map);
    assertNotNull(util.getValueNode("//xsd:complexType[@name='Exception']", doc));
    Element nd = (Element) util.getValueNode("//xsd:element[@name='Exception']", doc);
    assertNotNull(nd);
    assertTrue(nd.getAttribute("type").contains("Exception"));
    nd = (Element) util.getValueNode("//xsd:element[@name='message']", doc);
    assertNotNull(nd);
    assertTrue(nd.getAttribute("type").contains("string"));
    assertTrue(nd.getAttribute("minOccurs").contains("0"));
    nd = (Element) util.getValueNode("//wsdl:part[@name='Exception']", doc);
    assertNotNull(nd);
    assertTrue(nd.getAttribute("element").contains(":Exception"));
    nd = (Element) util.getValueNode("//wsdl:fault[@name='Exception']", doc);
    assertNotNull(nd);
    assertTrue(nd.getAttribute("message").contains(":Exception"));
    nd = (Element) util.getValueNode("//soap:fault[@name='Exception']", doc);
    assertNotNull(nd);
    assertTrue(nd.getAttribute("use").contains("literal"));
}
Also used : HashMap(java.util.HashMap) XPathUtils(org.apache.cxf.helpers.XPathUtils) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) File(java.io.File) Test(org.junit.Test)

Example 14 with XPathUtils

use of org.apache.cxf.helpers.XPathUtils in project cxf by apache.

the class ClientServerRPCLitTest method testNoElementParts.

@Test
public void testNoElementParts() throws Exception {
    HttpURLConnection httpConnection = getHttpConnection("http://localhost:" + PORT + "/TestRPCWsdl?wsdl");
    httpConnection.connect();
    assertEquals(200, httpConnection.getResponseCode());
    assertEquals("OK", httpConnection.getResponseMessage());
    InputStream in = httpConnection.getInputStream();
    assertNotNull(in);
    Document doc = StaxUtils.read(in);
    assertNotNull(doc);
    Map<String, String> ns = new HashMap<>();
    ns.put("soap", Soap11.SOAP_NAMESPACE);
    ns.put("wsdl", "http://schemas.xmlsoap.org/wsdl/");
    ns.put("xs", "http://www.w3.org/2001/XMLSchema");
    XPathUtils xu = new XPathUtils(ns);
    // make sure the wrapper types are anonymous types
    NodeList ct = (NodeList) xu.getValue("//wsdl:definitions/wsdl:message/wsdl:part[@element != '']", doc, XPathConstants.NODESET);
    assertNotNull(ct);
    assertEquals(0, ct.getLength());
    ct = (NodeList) xu.getValue("//wsdl:definitions/wsdl:message/wsdl:part[@type != '']", doc, XPathConstants.NODESET);
    assertEquals(4, ct.getLength());
}
Also used : HttpURLConnection(java.net.HttpURLConnection) HashMap(java.util.HashMap) InputStream(java.io.InputStream) XPathUtils(org.apache.cxf.helpers.XPathUtils) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 15 with XPathUtils

use of org.apache.cxf.helpers.XPathUtils in project cxf by apache.

the class ClientServerGreeterNoWsdlTest method testWSDLImports.

@Test
public void testWSDLImports() throws Exception {
    URL url = new URL("http://localhost:" + PORT + "/SoapContext/GreeterPort?wsdl");
    Document doc = StaxUtils.read(url.openStream());
    Map<String, String> ns = new HashMap<>();
    ns.put("xsd", "http://www.w3.org/2001/XMLSchema");
    Node nd = new XPathUtils(ns).getValueNode("//xsd:import[@namespace='http://cxf.apache.org/greeter_control/types']", doc.getDocumentElement());
    assertNotNull(nd);
}
Also used : HashMap(java.util.HashMap) XPathUtils(org.apache.cxf.helpers.XPathUtils) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) URL(java.net.URL) Test(org.junit.Test)

Aggregations

XPathUtils (org.apache.cxf.helpers.XPathUtils)39 HashMap (java.util.HashMap)33 Document (org.w3c.dom.Document)26 Test (org.junit.Test)24 Element (org.w3c.dom.Element)22 Node (org.w3c.dom.Node)15 File (java.io.File)11 Bus (org.apache.cxf.Bus)9 Definition (javax.wsdl.Definition)7 QName (javax.xml.namespace.QName)7 StringReader (java.io.StringReader)6 WSDLWriter (javax.wsdl.xml.WSDLWriter)6 Server (org.apache.cxf.endpoint.Server)6 ServiceWSDLBuilder (org.apache.cxf.wsdl11.ServiceWSDLBuilder)6 URL (java.net.URL)5 InputStream (java.io.InputStream)4 Source (javax.xml.transform.Source)4 JaxWsServerFactoryBean (org.apache.cxf.jaxws.JaxWsServerFactoryBean)4 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)4 LocalTransportFactory (org.apache.cxf.transport.local.LocalTransportFactory)4