PayloadRootUtils { public static QName getPayloadRootQName(Source source, TransformerFactory transformerFactory) throws TransformerException { return getPayloadRootQName(source, new TransformerHelper(transformerFactory)); } private  PayloadRootUtils(); static QName getPayloadRootQName(Source source, TransformerFactory transformerFactory); static QName getPayloadRootQName(Source source, TransformerHelper transformerHelper);  }
@Test public void testGetQNameForDomSource() throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactoryUtils.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.newDocument(); Element element = document.createElementNS("namespace", "prefix:localname"); document.appendChild(element); Source source = new DOMSource(document); QName qName = PayloadRootUtils.getPayloadRootQName(source, TransformerFactoryUtils.newInstance()); Assert.assertNotNull("getQNameForNode returns null", qName); Assert.assertEquals("QName has invalid localname", "localname", qName.getLocalPart()); Assert.assertEquals("Qname has invalid namespace", "namespace", qName.getNamespaceURI()); Assert.assertEquals("Qname has invalid prefix", "prefix", qName.getPrefix()); }
@Test public void testGetQNameForStaxSourceStreamReader() throws Exception { String contents = "<prefix:localname xmlns:prefix='namespace'/>"; XMLInputFactory inputFactory = XMLInputFactoryUtils.newInstance(); XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(contents)); Source source = StaxUtils.createStaxSource(streamReader); QName qName = PayloadRootUtils.getPayloadRootQName(source, TransformerFactoryUtils.newInstance()); Assert.assertNotNull("getQNameForNode returns null", qName); Assert.assertEquals("QName has invalid localname", "localname", qName.getLocalPart()); Assert.assertEquals("Qname has invalid namespace", "namespace", qName.getNamespaceURI()); Assert.assertEquals("Qname has invalid prefix", "prefix", qName.getPrefix()); }
@Test public void testGetQNameForStaxSourceEventReader() throws Exception { String contents = "<prefix:localname xmlns:prefix='namespace'/>"; XMLInputFactory inputFactory = XMLInputFactoryUtils.newInstance(); XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(contents)); Source source = StaxUtils.createStaxSource(eventReader); QName qName = PayloadRootUtils.getPayloadRootQName(source, TransformerFactoryUtils.newInstance()); Assert.assertNotNull("getQNameForNode returns null", qName); Assert.assertEquals("QName has invalid localname", "localname", qName.getLocalPart()); Assert.assertEquals("Qname has invalid namespace", "namespace", qName.getNamespaceURI()); Assert.assertEquals("Qname has invalid prefix", "prefix", qName.getPrefix()); }
@Test public void testGetQNameForStreamSource() throws Exception { String contents = "<prefix:localname xmlns:prefix='namespace'/>"; Source source = new StreamSource(new StringReader(contents)); QName qName = PayloadRootUtils.getPayloadRootQName(source, TransformerFactoryUtils.newInstance()); Assert.assertNotNull("getQNameForNode returns null", qName); Assert.assertEquals("QName has invalid localname", "localname", qName.getLocalPart()); Assert.assertEquals("Qname has invalid namespace", "namespace", qName.getNamespaceURI()); Assert.assertEquals("Qname has invalid prefix", "prefix", qName.getPrefix()); }
@Test public void testGetQNameForSaxSource() throws Exception { String contents = "<prefix:localname xmlns:prefix='namespace'/>"; Source source = new SAXSource(new InputSource(new StringReader(contents))); QName qName = PayloadRootUtils.getPayloadRootQName(source, TransformerFactoryUtils.newInstance()); Assert.assertNotNull("getQNameForNode returns null", qName); Assert.assertEquals("QName has invalid localname", "localname", qName.getLocalPart()); Assert.assertEquals("Qname has invalid namespace", "namespace", qName.getNamespaceURI()); Assert.assertEquals("Qname has invalid prefix", "prefix", qName.getPrefix()); }
@Test public void testGetQNameForNullSource() throws Exception { QName qName = PayloadRootUtils.getPayloadRootQName(null, TransformerFactoryUtils.newInstance()); Assert.assertNull("Qname returned", qName); }