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);
}
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"));
}
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"));
}
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"));
}
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));
}
Aggregations