Search in sources :

Example 31 with XPathUtils

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

the class JavaToProcessorTest method testXmlAccessorOrderInException.

@Test
public void testXmlAccessorOrderInException() throws Exception {
    env.put(ToolConstants.CFG_OUTPUTFILE, output.getPath() + "/exception_order.wsdl");
    env.put(ToolConstants.CFG_CLASSNAME, "org.apache.cxf.tools.fortest.exception.OrderEchoImpl");
    env.put(ToolConstants.CFG_VERBOSE, ToolConstants.CFG_VERBOSE);
    processor.setEnvironment(env);
    processor.process();
    File wsdlFile = new File(output, "exception_order.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 = from.getNextSibling();
    while (nd != null) {
        if (nd == id) {
            from = null;
        } else if (nd == summary) {
            if (from != null) {
                fail("from before summary");
            }
            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 32 with XPathUtils

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

the class JavaToProcessorTest method testTransientMessage.

@Test
public void testTransientMessage() throws Exception {
    // CXF-5744
    env.put(ToolConstants.CFG_OUTPUTFILE, output.getPath() + "/transient_message.wsdl");
    env.put(ToolConstants.CFG_CLASSNAME, "org.apache.cxf.tools.fortest.exception.Echo4");
    env.put(ToolConstants.CFG_VERBOSE, ToolConstants.CFG_VERBOSE);
    processor.setEnvironment(env);
    processor.process();
    File wsdlFile = new File(output, "transient_message.wsdl");
    assertTrue(wsdlFile.exists());
    Document doc = StaxUtils.read(wsdlFile);
    // StaxUtils.print(doc);
    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/");
    map.put("tns", "http://cxf.apache.org/test/HelloService");
    XPathUtils util = new XPathUtils(map);
    String path = "//xsd:complexType[@name='TransientMessageException']//xsd:sequence/xsd:element[@name='message']";
    Element nd = (Element) util.getValueNode(path, doc);
    assertNull(nd);
    // ok, we didn't map it into the schema.  Make sure the runtime won't write it out.
    List<ServiceInfo> sl = CastUtils.cast((List<?>) env.get("serviceList"));
    FaultInfo mi = sl.get(0).getInterface().getOperation(new QName("http://cxf.apache.org/test/HelloService", "echo")).getFault(new QName("http://cxf.apache.org/test/HelloService", "TransientMessageException"));
    MessagePartInfo mpi = mi.getMessagePart(0);
    JAXBContext ctx = JAXBContext.newInstance(String.class, Integer.TYPE);
    StringWriter sw = new StringWriter();
    XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(sw);
    TransientMessageException tme = new TransientMessageException(12, "Exception Message");
    Marshaller ms = ctx.createMarshaller();
    ms.setProperty(Marshaller.JAXB_FRAGMENT, true);
    JAXBEncoderDecoder.marshallException(ms, tme, mpi, writer);
    writer.flush();
    writer.close();
    assertEquals(-1, sw.getBuffer().indexOf("Exception Message"));
}
Also used : FaultInfo(org.apache.cxf.service.model.FaultInfo) Marshaller(javax.xml.bind.Marshaller) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) JAXBContext(javax.xml.bind.JAXBContext) Document(org.w3c.dom.Document) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) TransientMessageException(org.apache.cxf.tools.fortest.exception.TransientMessageException) StringWriter(java.io.StringWriter) XPathUtils(org.apache.cxf.helpers.XPathUtils) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) File(java.io.File) Test(org.junit.Test)

Example 33 with XPathUtils

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

the class JavaToProcessorTest method testExceptionRefNillable.

@Test
public void testExceptionRefNillable() throws Exception {
    env.put(ToolConstants.CFG_OUTPUTFILE, output.getPath() + "/exception-ref-nillable.wsdl");
    env.put(ToolConstants.CFG_CLASSNAME, "org.apache.cxf.tools.fortest.exception.Echo3Impl");
    env.put(ToolConstants.CFG_VERBOSE, ToolConstants.CFG_VERBOSE);
    processor.setEnvironment(env);
    processor.process();
    File wsdlFile = new File(output, "exception-ref-nillable.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/");
    map.put("tns", "http://cxf.apache.org/test/HelloService");
    XPathUtils util = new XPathUtils(map);
    Element el = (Element) util.getValueNode("//xsd:element[@ref]", doc);
    assertNotNull(el);
    assertTrue(el.getAttribute("ref").contains("item"));
}
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 34 with XPathUtils

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

the class JavaToProcessorTest method testExceptionList.

@Test
public void testExceptionList() throws Exception {
    env.put(ToolConstants.CFG_OUTPUTFILE, output.getPath() + "/exception_list.wsdl");
    env.put(ToolConstants.CFG_CLASSNAME, "org.apache.cxf.tools.fortest.exception.Echo2Impl");
    env.put(ToolConstants.CFG_VERBOSE, ToolConstants.CFG_VERBOSE);
    processor.setEnvironment(env);
    processor.process();
    File wsdlFile = new File(output, "exception_list.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 nd = (Element) util.getValueNode("//xsd:element[@name='names']", doc);
    assertNotNull(nd);
    assertEquals("0", nd.getAttribute("minOccurs"));
    assertEquals("unbounded", nd.getAttribute("maxOccurs"));
    assertTrue(nd.getAttribute("type").endsWith(":myData"));
    nd = (Element) util.getValueNode("//xsd:complexType[@name='ListException2']" + "/xsd:sequence/xsd:element[@name='address']", doc);
    assertNotNull(nd);
    assertEquals("0", nd.getAttribute("minOccurs"));
    assertEquals("unbounded", nd.getAttribute("maxOccurs"));
    assertTrue(nd.getAttribute("type").endsWith(":myData"));
}
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 35 with XPathUtils

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

the class AegisTest method testAegisReconfigureDatabinding.

@Test
public void testAegisReconfigureDatabinding() throws Exception {
    final String sei = org.apache.cxf.tools.fortest.aegis2ws.TestAegisSEI.class.getName();
    File wsdlFile = new File(folder.getRoot(), "aegis.wsdl");
    String[] args = new String[] { "-wsdl", "-o", wsdlFile.toString(), "-beans", new File(getClass().getResource("/revisedAegisDefaultBeans.xml").toURI()).toString(), "-verbose", "-s", folder.getRoot().toString(), "-frontend", "jaxws", "-databinding", "aegis", "-client", "-server", sei };
    JavaToWS.main(args);
    assertTrue("wsdl is not generated " + getStdErr(), wsdlFile.exists());
    WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();
    reader.setFeature("javax.wsdl.verbose", false);
    Definition def = reader.readWSDL(wsdlFile.toURI().toURL().toString());
    Document wsdl = WSDLFactory.newInstance().newWSDLWriter().getDocument(def);
    assertValid("//xsd:element[@type='ns0:Something']", wsdl);
    XPathUtils xpu = new XPathUtils(getNSMap());
    String s = (String) xpu.getValue("//xsd:complexType[@name='takeSomething']/" + "xsd:sequence/xsd:element[@name='arg0']/@minOccurs", wsdl, XPathConstants.STRING);
    assertEquals("50", s);
    assertFalse(xpu.isExist("//xsd:complexType[@name='Something']/xsd:sequence/" + "xsd:element[@name='singular']/@minOccurs", wsdl, XPathConstants.NODE));
}
Also used : XPathUtils(org.apache.cxf.helpers.XPathUtils) Definition(javax.wsdl.Definition) Document(org.w3c.dom.Document) File(java.io.File) WSDLReader(javax.wsdl.xml.WSDLReader) 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