use of org.apache.commons.io.input.UnsynchronizedByteArrayInputStream in project exist by eXist-db.
the class MemtreeTest method getLastNode.
@Test
public void getLastNode() throws IOException, ParserConfigurationException, SAXException {
final DocumentImpl doc;
try (final InputStream is = new UnsynchronizedByteArrayInputStream(XML.getBytes(UTF_8))) {
doc = parse(is);
}
assertEquals(26, doc.getLastNode());
}
use of org.apache.commons.io.input.UnsynchronizedByteArrayInputStream in project exist by eXist-db.
the class MemtreeTest method getAttributesCountFor.
@Test
public void getAttributesCountFor() throws IOException, ParserConfigurationException, SAXException {
final DocumentImpl doc;
try (final InputStream is = new UnsynchronizedByteArrayInputStream(XML.getBytes(UTF_8))) {
doc = parse(is);
}
// attributes count of the document node
assertEquals(0, doc.getAttributesCountFor(0));
// attributes count of <!-- comment before doc 1 -->
assertEquals(0, doc.getAttributesCountFor(1));
// attributes count of <?pi-before-doc-1?>
assertEquals(0, doc.getAttributesCountFor(2));
// attributes count of <!-- comment before doc 2 -->
assertEquals(0, doc.getAttributesCountFor(3));
// attributes count of <?pi-before-doc-2?>
assertEquals(0, doc.getAttributesCountFor(4));
// attributes count of doc-element
assertEquals(0, doc.getAttributesCountFor(5));
// attributes count of doc-element/text()[1]
assertEquals(0, doc.getAttributesCountFor(6));
// attributes count of <!-- comment before e1 -->
assertEquals(0, doc.getAttributesCountFor(7));
// attributes count of doc-element/text()[2]
assertEquals(0, doc.getAttributesCountFor(8));
// attributes count of e1
assertEquals(1, doc.getAttributesCountFor(9));
// attributes count of e1/text()[1]
assertEquals(0, doc.getAttributesCountFor(10));
// attributes count of <?pi-before-e1_1?>
assertEquals(0, doc.getAttributesCountFor(11));
// attributes count of e1/text()[2]
assertEquals(0, doc.getAttributesCountFor(12));
// attributes count of e1_1
assertEquals(1, doc.getAttributesCountFor(13));
// attributes count of e1_1/text()[1]
assertEquals(0, doc.getAttributesCountFor(14));
// attributes count of e1/text()[3]
assertEquals(0, doc.getAttributesCountFor(15));
// attributes count of e1_2
assertEquals(2, doc.getAttributesCountFor(16));
// attributes count of e1_2/text()[1]
assertEquals(0, doc.getAttributesCountFor(17));
// attributes count of e1/text()[4]
assertEquals(0, doc.getAttributesCountFor(18));
// attributes count of doc-element/text()[3]
assertEquals(0, doc.getAttributesCountFor(19));
// attributes count of <!-- comment after e1 -->
assertEquals(0, doc.getAttributesCountFor(20));
// attributes count of doc-element/text()[4]
assertEquals(0, doc.getAttributesCountFor(21));
// attributes count of <?pi-after-doc-1?>
assertEquals(0, doc.getAttributesCountFor(22));
// attributes count of <!-- comment after doc 1 -->
assertEquals(0, doc.getAttributesCountFor(23));
// attributes count of <?pi-after-doc-2?>
assertEquals(0, doc.getAttributesCountFor(24));
// attributes count of <!-- comment after doc 2 -->
assertEquals(0, doc.getAttributesCountFor(25));
// attributes count of <?pi-after-doc-3?>
assertEquals(0, doc.getAttributesCountFor(26));
}
use of org.apache.commons.io.input.UnsynchronizedByteArrayInputStream in project exist by eXist-db.
the class DocumentImplTest method checkNamespaces_xerces.
@Test
public void checkNamespaces_xerces() throws IOException, ParserConfigurationException, SAXException {
final Document doc;
try (final InputStream is = new UnsynchronizedByteArrayInputStream(DOC_WITH_NAMESPACES.getBytes(UTF_8))) {
doc = parseXerces(is);
}
final Element elem = doc.getDocumentElement();
final NamedNodeMap attrs = elem.getAttributes();
assertEquals(2, attrs.getLength());
int index = 0;
final Attr attr1 = (Attr) attrs.item(index++);
assertEquals(Node.ATTRIBUTE_NODE, attr1.getNodeType());
assertTrue(attr1 instanceof AttrNSImpl);
assertEquals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, attr1.getNamespaceURI());
assertEquals(null, attr1.getPrefix());
assertEquals(XMLConstants.XMLNS_ATTRIBUTE, attr1.getLocalName());
assertEquals(XMLConstants.XMLNS_ATTRIBUTE, attr1.getNodeName());
assertEquals("http://exist-db.org/xquery/repo", attr1.getValue());
final Attr attr2 = (Attr) attrs.item(index++);
assertEquals(Node.ATTRIBUTE_NODE, attr2.getNodeType());
assertTrue(attr2 instanceof AttrNSImpl);
assertEquals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, attr2.getNamespaceURI());
assertEquals(XMLConstants.XMLNS_ATTRIBUTE, attr2.getPrefix());
assertEquals("repo", attr2.getLocalName());
assertEquals(XMLConstants.XMLNS_ATTRIBUTE + ":repo", attr2.getNodeName());
assertEquals("http://exist-db.org/xquery/repo", attr2.getValue());
}
use of org.apache.commons.io.input.UnsynchronizedByteArrayInputStream in project exist by eXist-db.
the class DocumentImplTest method checkNamespaces_saxon.
@Test
public void checkNamespaces_saxon() throws IOException, ParserConfigurationException, SAXException, IllegalAccessException, InstantiationException, ClassNotFoundException {
final Document doc;
try (final InputStream is = new UnsynchronizedByteArrayInputStream(DOC_WITH_NAMESPACES.getBytes(UTF_8))) {
doc = parseSaxon(is);
}
final Element elem = doc.getDocumentElement();
final NamedNodeMap attrs = elem.getAttributes();
assertEquals(3, attrs.getLength());
int index = 0;
final Attr attr1 = (Attr) attrs.item(index++);
assertEquals(Node.ATTRIBUTE_NODE, attr1.getNodeType());
assertEquals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, attr1.getNamespaceURI());
assertEquals(XMLConstants.XMLNS_ATTRIBUTE, attr1.getPrefix());
assertEquals(XMLConstants.XML_NS_PREFIX, attr1.getLocalName());
assertEquals(XMLConstants.XMLNS_ATTRIBUTE + ":" + XMLConstants.XML_NS_PREFIX, attr1.getNodeName());
assertEquals(XMLConstants.XML_NS_URI, attr1.getValue());
final Attr attr2 = (Attr) attrs.item(index++);
assertEquals(Node.ATTRIBUTE_NODE, attr2.getNodeType());
assertEquals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, attr2.getNamespaceURI());
assertEquals(null, attr2.getPrefix());
assertEquals(XMLConstants.XMLNS_ATTRIBUTE, attr2.getLocalName());
assertEquals(XMLConstants.XMLNS_ATTRIBUTE, attr2.getNodeName());
assertEquals("http://exist-db.org/xquery/repo", attr2.getValue());
final Attr attr3 = (Attr) attrs.item(index++);
assertEquals(Node.ATTRIBUTE_NODE, attr3.getNodeType());
assertEquals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, attr3.getNamespaceURI());
assertEquals(XMLConstants.XMLNS_ATTRIBUTE, attr3.getPrefix());
assertEquals("repo", attr3.getLocalName());
assertEquals(XMLConstants.XMLNS_ATTRIBUTE + ":repo", attr3.getNodeName());
assertEquals("http://exist-db.org/xquery/repo", attr3.getValue());
}
use of org.apache.commons.io.input.UnsynchronizedByteArrayInputStream in project exist by eXist-db.
the class ConfigurableTest method notSimple.
@Test
public void notSimple() throws Exception {
InputStream is = new UnsynchronizedByteArrayInputStream(config3.getBytes(UTF_8));
Configuration config = Configurator.parse(is);
ConfigurableObject2 object = new ConfigurableObject2(config);
assertEquals("a", object.some);
assertEquals(Integer.valueOf(5), object.someInteger);
assertTrue(object.simpleInteger == 5);
assertTrue(object.defaultInteger == 3);
assertTrue(object.someboolean);
assertFalse(object.someBoolean);
assertEquals("cool", object.sp.name);
}
Aggregations