BAEL-3038 Add integration tests (#7495)
* Adds first tutorial examples * Add README * Add packages for XML- and JSON-stuff * Update CreateJsonVersionedResource.java * Update CreateJsonVersionedResource.java * Update CreateXmlDatabase.java * Update CreateJsonVersionedResource.java * Add class and minor changes * Add versioned XML resource example * Add output when done * Add exmaple * Add example * Add example * Change to integration tests * Move to persistence-modules / change class names / BDD test names * Remove core-api-tutorial folder * Add test and modify a test * Add integration test * Minor cleanup
This commit is contained in:
parent
f918e37fa6
commit
1f104924c7
24
persistence-modules/sirix/.gitignore
vendored
Normal file
24
persistence-modules/sirix/.gitignore
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
nbproject/private/
|
||||
build/
|
||||
nbbuild/
|
||||
dist/
|
||||
nbdist/
|
||||
.nb-gradle/
|
3
persistence-modules/sirix/README.md
Normal file
3
persistence-modules/sirix/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
## Relevant articles:
|
||||
|
||||
- [Introduction to Sirix](https://www.baeldung.com/introduction-to-sirix)
|
52
persistence-modules/sirix/pom.xml
Normal file
52
persistence-modules/sirix/pom.xml
Normal file
@ -0,0 +1,52 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>io.sirix</groupId>
|
||||
<artifactId>core-api-tutorial</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>core-api-tutorial</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-java</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-java</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.sirix</groupId>
|
||||
<artifactId>sirix-core</artifactId>
|
||||
<version>0.9.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
<configuration>
|
||||
<release>${maven.release.version}</release>
|
||||
<encoding>${project.build.sourceEncoding}</encoding>
|
||||
</configuration>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.ow2.asm</groupId>
|
||||
<artifactId>asm</artifactId>
|
||||
<version>6.1</version> <!-- Use newer version of ASM -->
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.release.version>11</maven.release.version>
|
||||
</properties>
|
||||
</project>
|
@ -0,0 +1,13 @@
|
||||
package io.sirix.tutorial;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public final class Constants {
|
||||
private Constants() {
|
||||
}
|
||||
|
||||
public static final String USER_HOME = System.getProperty("user.home");
|
||||
|
||||
public static final Path SIRIX_DATA_LOCATION = Paths.get(USER_HOME, "sirix-data");
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
package io.sirix.tutorial.json;
|
||||
|
||||
import org.sirix.access.trx.node.json.objectvalue.ArrayValue;
|
||||
import org.sirix.access.trx.node.json.objectvalue.BooleanValue;
|
||||
import org.sirix.access.trx.node.json.objectvalue.ObjectValue;
|
||||
import org.sirix.access.trx.node.json.objectvalue.StringValue;
|
||||
import org.sirix.api.json.JsonNodeTrx;
|
||||
import org.sirix.exception.SirixException;
|
||||
|
||||
/**
|
||||
* <h1>JSON-Document</h1>
|
||||
*
|
||||
* <p>
|
||||
* This class creates a JSON document.
|
||||
* </p>
|
||||
*
|
||||
* <code><pre>
|
||||
* {
|
||||
* "foo": ["bar", null, 2.33],
|
||||
* "bar": { "hello": "world", "helloo": true },
|
||||
* "baz": "hello",
|
||||
* "tada": [{"foo":"bar"},{"baz":false},"boo",{},[]]
|
||||
* }
|
||||
* </pre></code>
|
||||
*/
|
||||
public final class JsonDocumentCreator {
|
||||
|
||||
public static final String JSON = "{\"foo\":[\"bar\",null,2.33],\"bar\":{\"hello\":\"world\",\"helloo\":true},\"baz\":\"hello\",\"tada\":[{\"foo\":\"bar\"},{\"baz\":false},\"boo\",{},[]]}";
|
||||
|
||||
/**
|
||||
* Private Constructor, not used.
|
||||
*/
|
||||
private JsonDocumentCreator() {
|
||||
throw new AssertionError("Not permitted to call constructor!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create simple test document containing all supported node kinds.
|
||||
*
|
||||
* @param wtx {@link JsonNodeWriteTrx} to write to
|
||||
* @throws SirixException if anything weird happens
|
||||
*/
|
||||
public static void create(final JsonNodeTrx wtx) {
|
||||
wtx.insertObjectAsFirstChild();
|
||||
|
||||
wtx.insertObjectRecordAsFirstChild("foo", new ArrayValue())
|
||||
.insertStringValueAsFirstChild("bar")
|
||||
.insertNullValueAsRightSibling()
|
||||
.insertNumberValueAsRightSibling(2.33);
|
||||
|
||||
wtx.moveToParent().trx().moveToParent();
|
||||
|
||||
wtx.insertObjectRecordAsRightSibling("bar", new ObjectValue())
|
||||
.insertObjectRecordAsFirstChild("hello", new StringValue("world"))
|
||||
.moveToParent();
|
||||
wtx.insertObjectRecordAsRightSibling("helloo", new BooleanValue(true))
|
||||
.moveToParent().trx().moveToParent().trx().moveToParent();
|
||||
|
||||
wtx.insertObjectRecordAsRightSibling("baz", new StringValue("hello"))
|
||||
.moveToParent();
|
||||
|
||||
wtx.insertObjectRecordAsRightSibling("tada", new ArrayValue())
|
||||
.insertObjectAsFirstChild()
|
||||
.insertObjectRecordAsFirstChild("foo", new StringValue("bar"))
|
||||
.moveToParent().trx().moveToParent();
|
||||
|
||||
wtx.insertObjectAsRightSibling()
|
||||
.insertObjectRecordAsFirstChild("baz", new BooleanValue(false))
|
||||
.moveToParent().trx().moveToParent();
|
||||
|
||||
wtx.insertStringValueAsRightSibling("boo")
|
||||
.insertObjectAsRightSibling()
|
||||
.insertArrayAsRightSibling();
|
||||
|
||||
wtx.moveToDocumentRoot();
|
||||
}
|
||||
|
||||
public static void createVersioned(final JsonNodeTrx wtx) {
|
||||
// Create sample document.
|
||||
JsonDocumentCreator.create(wtx);
|
||||
wtx.commit();
|
||||
|
||||
// Add changes and commit a second revision.
|
||||
wtx.moveToDocumentRoot().trx().moveToFirstChild();
|
||||
wtx.insertObjectRecordAsFirstChild("revision2", new StringValue("yes"));
|
||||
wtx.commit();
|
||||
|
||||
// Add changes and commit a third revision.
|
||||
wtx.moveToDocumentRoot().trx().moveToFirstChild().trx().moveToFirstChild();
|
||||
wtx.insertObjectRecordAsRightSibling("revision3", new StringValue("yes"));
|
||||
wtx.commit();
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package io.sirix.tutorial.json;
|
||||
|
||||
import org.sirix.access.ResourceConfiguration;
|
||||
import org.sirix.api.Database;
|
||||
import org.sirix.api.json.JsonResourceManager;
|
||||
|
||||
public final class VersionedJsonDocumentCreator {
|
||||
|
||||
/**
|
||||
* Private Constructor, not used.
|
||||
*/
|
||||
private VersionedJsonDocumentCreator() {
|
||||
throw new AssertionError("Not permitted to call constructor!");
|
||||
}
|
||||
|
||||
public static void create(final Database<JsonResourceManager> database) {
|
||||
final var resource = "resource";
|
||||
database.createResource(ResourceConfiguration.newBuilder(resource)
|
||||
.useTextCompression(false)
|
||||
.useDeweyIDs(true)
|
||||
.build());
|
||||
try (final var manager = database.openResourceManager(resource);
|
||||
final var wtx = manager.beginNodeTrx()) {
|
||||
// Create sample document.
|
||||
JsonDocumentCreator.createVersioned(wtx);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package io.sirix.tutorial.xml;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.sirix.diff.DiffDepth;
|
||||
import org.sirix.diff.DiffFactory.DiffType;
|
||||
import org.sirix.diff.DiffObserver;
|
||||
import org.sirix.diff.DiffTuple;
|
||||
|
||||
public class MyXmlDiffObserver implements DiffObserver {
|
||||
|
||||
private final List<DiffTuple> diffTuples;
|
||||
|
||||
MyXmlDiffObserver() {
|
||||
diffTuples = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void diffListener(DiffType diffType, long newNodeKey, long oldNodeKey, DiffDepth depth) {
|
||||
if (diffType == DiffType.INSERTED || diffType == DiffType.DELETED || diffType == DiffType.UPDATED)
|
||||
diffTuples.add(new DiffTuple(diffType, newNodeKey, oldNodeKey, depth));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void diffDone() {
|
||||
}
|
||||
|
||||
public List<DiffTuple> getDiffTuples() {
|
||||
return Collections.unmodifiableList(diffTuples);
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package io.sirix.tutorial.xml;
|
||||
|
||||
import org.sirix.access.ResourceConfiguration;
|
||||
import org.sirix.api.Database;
|
||||
import org.sirix.api.xml.XmlResourceManager;
|
||||
|
||||
public final class VersionedXmlDocumentCreator {
|
||||
|
||||
/**
|
||||
* Private Constructor, not used.
|
||||
*/
|
||||
private VersionedXmlDocumentCreator() {
|
||||
throw new AssertionError("Not permitted to call constructor!");
|
||||
}
|
||||
|
||||
public static void create(final Database<XmlResourceManager> database) {
|
||||
final var resource = "resource";
|
||||
database.createResource(ResourceConfiguration.newBuilder(resource)
|
||||
.useTextCompression(false)
|
||||
.useDeweyIDs(true)
|
||||
.build());
|
||||
try (final var manager = database.openResourceManager(resource);
|
||||
final var wtx = manager.beginNodeTrx()) {
|
||||
XmlDocumentCreator.createVersioned(wtx);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,385 @@
|
||||
/**
|
||||
* Copyright (c) 2011, University of Konstanz, Distributed Systems Group All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted
|
||||
* provided that the following conditions are met: * Redistributions of source code must retain the
|
||||
* above copyright notice, this list of conditions and the following disclaimer. * Redistributions
|
||||
* in binary form must reproduce the above copyright notice, this list of conditions and the
|
||||
* following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the University of Konstanz nor the names of its contributors may be used to
|
||||
* endorse or promote products derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package io.sirix.tutorial.xml;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
|
||||
import org.brackit.xquery.atomic.QNm;
|
||||
import org.sirix.api.Database;
|
||||
import org.sirix.api.xml.XmlNodeTrx;
|
||||
import org.sirix.api.xml.XmlResourceManager;
|
||||
import org.sirix.exception.SirixException;
|
||||
import org.sirix.service.xml.shredder.InsertPosition;
|
||||
import org.sirix.service.xml.shredder.XmlShredder;
|
||||
|
||||
/**
|
||||
* <h1>XmlDocumentCreator</h1>
|
||||
*
|
||||
* <p>
|
||||
* This class creates an XML document that contains all features seen in the Extensible Markup
|
||||
* Language (XML) 1.1 (Second Edition) as well as the Namespaces in XML 1.1 (Second Edition).
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* The following figure describes the created test document (see <code>xml/test.xml</code>). The
|
||||
* nodes are described as follows:
|
||||
*
|
||||
* <ul>
|
||||
* <li><code>Kind.ROOT: doc()</code></li>
|
||||
* <li><code>Kind.ELEMENT : <prefix:localPart></code></li>
|
||||
* <li><code>Kind.NAMESPACE: §prefix:namespaceURI</code></li>
|
||||
* <li><code>Kind.ATTRIBUTE: @prefix:localPart='value'</code></li>
|
||||
* <li><code>Kind.TEXT: #value</code></li>
|
||||
* <li><code>Kind.COMMENT: %comment</code></li>
|
||||
* <li><code>Kind.PI: &content:target</code></li>
|
||||
* </ul>
|
||||
*
|
||||
* without processing instruction and comment:
|
||||
*
|
||||
* <pre>
|
||||
* 0 doc()
|
||||
* |- 1 <p:a §p:ns @i='j'>
|
||||
* |- 4 #oops1
|
||||
* |- 5 <b>
|
||||
* | |- 6 #foo
|
||||
* | |- 7 <c/>
|
||||
* |- 8 #oops2
|
||||
* |- 9 <b @p:x='y'>
|
||||
* | |- 11 <c/>
|
||||
* | |- 12 #bar
|
||||
* |- 13 #oops3
|
||||
* </pre>
|
||||
*
|
||||
* with processing instruction and comment:
|
||||
*
|
||||
* <pre>
|
||||
* 0 doc()
|
||||
* |- 1 <p:a §p:ns @i='j'>
|
||||
* |- 4 %foo
|
||||
* |- 5 #oops1
|
||||
* |- 6 <b>
|
||||
* | |- 7 #foo
|
||||
* | |- 8 <c/>
|
||||
* |- 9 &bar:baz=\"foo\"
|
||||
* |- 10 #oops2
|
||||
* |- 11 <b @p:x='y'>
|
||||
* | |- 13 <c/>
|
||||
* | |- 14 #bar
|
||||
* |- 15 #oops3
|
||||
* </pre>
|
||||
*
|
||||
* </p>
|
||||
*/
|
||||
public final class XmlDocumentCreator {
|
||||
|
||||
/** String representation of revisioned xml file. */
|
||||
public static final String REVXML =
|
||||
"<article><title>A Test Document</title><para>This is para 1.</para><para>This is para 2<emphasis>"
|
||||
+ "with emphasis</emphasis>in it.</para><para>This is para 3.</para><para id=\"p4\">This is "
|
||||
+ "para 4.</para><para id=\"p5\">This is para 5.</para><para>This is para 6."
|
||||
+ "</para><para>This is para 7.</para><para>This is para 8.</para><para>This is para 9."
|
||||
+ "</para></article>";
|
||||
|
||||
/** String representation of ID. */
|
||||
public static final String ID = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><p:a xmlns:p=\"ns\" "
|
||||
+ "id=\"1\" i=\"j\">oops1<b id=\"5\">foo<c id=\"7\"/></b>oops2<b id=\"9\" p:x=\"y\">"
|
||||
+ "<c id=\"11\"/>bar</b>oops3</p:a>";
|
||||
|
||||
/** String representation of rest. */
|
||||
public static final String REST = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
|
||||
+ "<rest:sequence xmlns:rest=\"https://sirix.io/rest\"><rest:item>"
|
||||
+ "<p:a xmlns:p=\"ns\" rest:id=\"1\" i=\"j\">oops1<b rest:id=\"5\">foo<c rest:id=\"7\"/></b>oops2<b rest:id=\"9\" p:x=\"y\">"
|
||||
+ "<c rest:id=\"11\"/>bar</b>oops3</p:a></rest:item></rest:sequence>";
|
||||
|
||||
/** String representation of test document. */
|
||||
public static final String XML = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
|
||||
+ "<p:a xmlns:p=\"ns\" i=\"j\">oops1<b>foo<c/></b>oops2<b p:x=\"y\"><c/>bar</b>oops3</p:a>";
|
||||
|
||||
/** String representation of test document. */
|
||||
public static final String COMMENTPIXML = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
|
||||
+ "<p:a xmlns:p=\"ns\" i=\"j\"><!-- foo -->oops1<b>foo<c/></b><?bar baz=\"foo\"?>oops2<b p:x=\"y\">"
|
||||
+ "<c/>bar</b>oops3</p:a>";
|
||||
|
||||
/** String representation of test document without xml declaration. */
|
||||
public static final String XML_WITHOUT_XMLDECL =
|
||||
"<p:a xmlns:p=\"ns\" i=\"j\">oops1<b>foo<c/></b>oops2<b p:x=\"y\"><c/>bar</b>oops3</p:a>";
|
||||
|
||||
/** String representation of versioned test document. */
|
||||
public static final String VERSIONEDXML = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
|
||||
+ "<sdb:sirix xmlns:sdb=\"https://sirix.io/rest\"><sdb:sirix-item sdb:revision=\"1\"><p:a xmlns:p=\"ns\" i=\"j\">oops1<b>foo<c/></b>oops2<b p:x=\"y\"><c/>bar</b>oops3</p:a></sdb:sirix-item>"
|
||||
+ "<sdb:sirix-item sdb:revision=\"2\"><p:a xmlns:p=\"ns\" i=\"j\"><p:a>OOPS4!</p:a>oops1<b>foo<c/></b>oops2<b p:x=\"y\"><c/>bar</b>oops3</p:a></sdb:sirix-item>"
|
||||
+ "<sdb:sirix-item sdb:revision=\"3\"><p:a xmlns:p=\"ns\" i=\"j\"><p:a>OOPS4!</p:a><p:a>OOPS4!</p:a>oops1<b>foo<c/></b>oops2<b p:x=\"y\"><c/>bar</b>oops3</p:a></sdb:sirix-item></sdb:sirix>";
|
||||
|
||||
/** String representation of test document without attributes. */
|
||||
public static final String XMLWITHOUTATTRIBUTES = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
|
||||
+ "<p:a>oops1<b>foo<c></c></b>oops2<b>" + "<c></c>bar</b>oops3</p:a>";
|
||||
|
||||
/** XML for the index structure. */
|
||||
public static final String XML_INDEX = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
|
||||
+ "<t:o><t:oo><t:oop><t:oops><d:DOCUMENT_ROOT_KIND nodeID=\"0\"><d:p:a nodeID=\"1\">"
|
||||
+ "<d:TEXT_KIND nodeID=\"4\"/></d:p:a></d:DOCUMENT_ROOT_KIND></t:oops></t:oop></t:oo>"
|
||||
+ "</t:o><t:f><t:fo><t:foo><d:DOCUMENT_ROOT_KIND nodeID=\"0\"><d:p:a nodeID=\"1\">"
|
||||
+ "<d:b nodeID=\"5\"><d:TEXT_KIND nodeID=\"6\"/></d:b></d:p:a></d:DOCUMENT_ROOT_KIND></t:foo>"
|
||||
+ "</t:fo></t:f><t:b><t:ba><t:bar><d:DOCUMENT_ROOT_KIND nodeID=\"0\"><d:p:a nodeID=\"1\">"
|
||||
+ "<d:b nodeID=\"9\"><d:TEXT_KIND nodeID=\"12\"/></d:b></d:p:a></d:DOCUMENT_ROOT_KIND></t:bar>" + "</t:ba></t:b>";
|
||||
|
||||
/**
|
||||
* Private Constructor, not used.
|
||||
*/
|
||||
private XmlDocumentCreator() {
|
||||
throw new AssertionError("Not permitted to call constructor!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create simple test document containing all supported node kinds.
|
||||
*
|
||||
* @param wtx {@link XmlNodeTrx} to write to
|
||||
* @throws SirixException if anything weird happens
|
||||
*/
|
||||
public static void createCommentPI(final XmlNodeTrx wtx) throws SirixException {
|
||||
wtx.moveToDocumentRoot();
|
||||
|
||||
wtx.insertElementAsFirstChild(new QNm("ns", "p", "a"));
|
||||
wtx.insertNamespace(new QNm("ns", "p", "xmlns"));
|
||||
wtx.moveToParent();
|
||||
wtx.insertAttribute(new QNm("i"), "j");
|
||||
wtx.moveToParent();
|
||||
|
||||
wtx.insertCommentAsFirstChild("foo");
|
||||
wtx.insertTextAsRightSibling("oops1");
|
||||
|
||||
wtx.insertElementAsRightSibling(new QNm("b"));
|
||||
|
||||
wtx.insertTextAsFirstChild("foo");
|
||||
wtx.insertElementAsRightSibling(new QNm("c"));
|
||||
wtx.moveToParent();
|
||||
|
||||
wtx.insertPIAsRightSibling("bar", "baz=\"foo\"");
|
||||
wtx.insertTextAsRightSibling("oops2");
|
||||
|
||||
wtx.insertElementAsRightSibling(new QNm("b"));
|
||||
wtx.insertAttribute(new QNm("ns", "p", "x"), "y");
|
||||
wtx.moveToParent();
|
||||
|
||||
wtx.insertElementAsFirstChild(new QNm("c"));
|
||||
wtx.insertTextAsRightSibling("bar");
|
||||
wtx.moveToParent();
|
||||
|
||||
wtx.insertTextAsRightSibling("oops3");
|
||||
|
||||
wtx.moveToDocumentRoot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create simple test document containing all supported node kinds except comment- and processing
|
||||
* instructions.
|
||||
*
|
||||
* @param wtx {@link XmlNodeTrx} to write to
|
||||
* @throws SirixException if anything weird happens
|
||||
*/
|
||||
public static void create(final XmlNodeTrx wtx) throws SirixException {
|
||||
wtx.moveToDocumentRoot();
|
||||
|
||||
wtx.insertElementAsFirstChild(new QNm("ns", "p", "a"));
|
||||
wtx.insertNamespace(new QNm("ns", "p", ""));
|
||||
wtx.moveToParent();
|
||||
wtx.insertAttribute(new QNm("i"), "j");
|
||||
wtx.moveToParent();
|
||||
|
||||
wtx.insertTextAsFirstChild("oops1");
|
||||
|
||||
wtx.insertElementAsRightSibling(new QNm("b"));
|
||||
|
||||
wtx.insertTextAsFirstChild("foo");
|
||||
wtx.insertElementAsRightSibling(new QNm("c"));
|
||||
wtx.moveToParent();
|
||||
|
||||
wtx.insertTextAsRightSibling("oops2");
|
||||
|
||||
wtx.insertElementAsRightSibling(new QNm("b"));
|
||||
wtx.insertAttribute(new QNm("ns", "p", "x"), "y");
|
||||
wtx.moveToParent();
|
||||
|
||||
wtx.insertElementAsFirstChild(new QNm("c"));
|
||||
wtx.insertTextAsRightSibling("bar");
|
||||
wtx.moveToParent().hasMoved();
|
||||
|
||||
wtx.insertTextAsRightSibling("oops3");
|
||||
|
||||
wtx.moveToDocumentRoot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create simple revision test in current database.
|
||||
*
|
||||
* @param wtx {@link XmlNodeTrx} to write to
|
||||
* @throws SirixException if anything went wrong
|
||||
*/
|
||||
public static void createVersioned(final XmlNodeTrx wtx) {
|
||||
create(wtx);
|
||||
wtx.commit();
|
||||
for (int i = 0; i <= 1; i++) {
|
||||
wtx.moveToDocumentRoot();
|
||||
wtx.moveToFirstChild();
|
||||
wtx.insertElementAsFirstChild(new QNm("ns", "p", "a"));
|
||||
wtx.insertTextAsFirstChild("OOPS4!");
|
||||
wtx.commit();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create simple revision test in current database.
|
||||
*
|
||||
* @param wtx {@link XmlNodeTrx} to write to
|
||||
* @throws SirixException if anything went wrong
|
||||
*/
|
||||
public static void createVersionedWithUpdatesAndDeletes(final XmlNodeTrx wtx) {
|
||||
create(wtx);
|
||||
wtx.commit();
|
||||
for (int i = 0; i <= 1; i++) {
|
||||
wtx.moveToDocumentRoot();
|
||||
wtx.moveToFirstChild();
|
||||
wtx.insertElementAsFirstChild(new QNm("a"));
|
||||
wtx.insertAttribute(new QNm("att"), "attval").moveToParent();
|
||||
wtx.insertTextAsFirstChild("OOPS4!");
|
||||
wtx.commit();
|
||||
}
|
||||
|
||||
wtx.moveToDocumentRoot().trx().moveToFirstChild().trx().moveToLastChild().trx();
|
||||
wtx.remove();
|
||||
wtx.commit();
|
||||
|
||||
wtx.moveTo(4);
|
||||
wtx.setValue("fooooooo");
|
||||
wtx.commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create simple test document containing all supported node kinds except the attributes.
|
||||
*
|
||||
* @param paramWtx {@link XmlNodeTrx} to write to
|
||||
* @throws SirixException if anything went wrong
|
||||
*/
|
||||
public static void createWithoutAttributes(final XmlNodeTrx wtx) {
|
||||
wtx.moveToDocumentRoot();
|
||||
wtx.insertElementAsFirstChild(new QNm("ns", "p", "a"));
|
||||
wtx.insertTextAsFirstChild("oops1");
|
||||
wtx.insertElementAsRightSibling(new QNm("b"));
|
||||
wtx.insertTextAsFirstChild("foo");
|
||||
wtx.insertElementAsRightSibling(new QNm("c"));
|
||||
wtx.moveToParent();
|
||||
wtx.insertTextAsRightSibling("oops2");
|
||||
wtx.insertElementAsRightSibling(new QNm("b"));
|
||||
wtx.insertElementAsFirstChild(new QNm("c"));
|
||||
wtx.insertTextAsRightSibling("bar");
|
||||
wtx.moveToParent();
|
||||
wtx.insertTextAsRightSibling("oops3");
|
||||
wtx.moveToDocumentRoot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create simple test document containing all supported node kinds, but ignoring their namespace
|
||||
* prefixes.
|
||||
*
|
||||
* @param wtx {@link XmlNodeTrx} to write to
|
||||
* @throws SirixException if anything went wrong
|
||||
*/
|
||||
public static void createWithoutNamespace(final XmlNodeTrx wtx) throws SirixException {
|
||||
wtx.moveToDocumentRoot();
|
||||
wtx.insertElementAsFirstChild(new QNm("a"));
|
||||
wtx.insertAttribute(new QNm("i"), "j");
|
||||
wtx.moveToParent();
|
||||
wtx.insertTextAsFirstChild("oops1");
|
||||
wtx.insertElementAsRightSibling(new QNm("b"));
|
||||
wtx.insertTextAsFirstChild("foo");
|
||||
wtx.insertElementAsRightSibling(new QNm("c"));
|
||||
wtx.moveToParent();
|
||||
wtx.insertTextAsRightSibling("oops2");
|
||||
wtx.insertElementAsRightSibling(new QNm("b"));
|
||||
wtx.insertAttribute(new QNm("x"), "y");
|
||||
wtx.moveToParent();
|
||||
wtx.insertElementAsFirstChild(new QNm("c"));
|
||||
wtx.insertTextAsRightSibling("bar");
|
||||
wtx.moveToParent();
|
||||
wtx.insertTextAsRightSibling("oops3");
|
||||
wtx.moveToDocumentRoot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create revisioned document.
|
||||
*
|
||||
* @throws SirixException if shredding fails
|
||||
* @throws XMLStreamException if StAX reader couldn't be created
|
||||
* @throws IOException if reading XML string fails
|
||||
*/
|
||||
public static void createRevisioned(final Database<XmlResourceManager> database) {
|
||||
|
||||
try (final XmlResourceManager resMgr = database.openResourceManager("resource")) {
|
||||
try (final XmlNodeTrx firstWtx = resMgr.beginNodeTrx()) {
|
||||
final XmlShredder shredder = new XmlShredder.Builder(firstWtx, XmlShredder.createStringReader(REVXML),
|
||||
InsertPosition.AS_FIRST_CHILD).commitAfterwards().build();
|
||||
shredder.call();
|
||||
}
|
||||
|
||||
try (final XmlNodeTrx secondWtx = resMgr.beginNodeTrx()) {
|
||||
secondWtx.moveToFirstChild();
|
||||
secondWtx.moveToFirstChild();
|
||||
secondWtx.moveToFirstChild();
|
||||
secondWtx.setValue("A Contrived Test Document");
|
||||
secondWtx.moveToParent();
|
||||
secondWtx.moveToRightSibling();
|
||||
secondWtx.moveToRightSibling();
|
||||
secondWtx.moveToFirstChild();
|
||||
secondWtx.moveToRightSibling();
|
||||
final long key = secondWtx.getNodeKey();
|
||||
secondWtx.insertAttribute(new QNm("role"), "bold");
|
||||
secondWtx.moveTo(key);
|
||||
secondWtx.moveToRightSibling();
|
||||
secondWtx.setValue("changed in it.");
|
||||
secondWtx.moveToParent();
|
||||
secondWtx.insertElementAsRightSibling(new QNm("para"));
|
||||
secondWtx.insertTextAsFirstChild("This is a new para 2b.");
|
||||
secondWtx.moveToParent();
|
||||
secondWtx.moveToRightSibling();
|
||||
secondWtx.moveToRightSibling();
|
||||
secondWtx.moveToFirstChild();
|
||||
secondWtx.setValue("This is a different para 4.");
|
||||
secondWtx.moveToParent();
|
||||
secondWtx.insertElementAsRightSibling(new QNm("para"));
|
||||
secondWtx.insertTextAsFirstChild("This is a new para 4b.");
|
||||
secondWtx.moveToParent();
|
||||
secondWtx.moveToRightSibling();
|
||||
secondWtx.moveToRightSibling();
|
||||
secondWtx.remove();
|
||||
secondWtx.remove();
|
||||
secondWtx.commit();
|
||||
secondWtx.moveToDocumentRoot();
|
||||
secondWtx.moveToFirstChild();
|
||||
secondWtx.moveToFirstChild();
|
||||
secondWtx.remove();
|
||||
secondWtx.commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package io.sirix.tutorial.json;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.sirix.access.DatabaseConfiguration;
|
||||
import org.sirix.access.Databases;
|
||||
import org.sirix.access.ResourceConfiguration;
|
||||
import org.sirix.service.json.serialize.JsonSerializer;
|
||||
import org.sirix.service.json.shredder.JsonShredder;
|
||||
import org.sirix.settings.VersioningType;
|
||||
|
||||
public final class CreateJsonDatabaseIntegrationTest {
|
||||
|
||||
private static final Path JSON_DIRECTORY = Paths.get("src", "test", "resources", "json");
|
||||
|
||||
private static final String TMP_DIRECTORY = System.getProperty("java.io.tmpdir");
|
||||
|
||||
private static final Path DATABASE_PATH = Paths.get(TMP_DIRECTORY, "sirix", "json-database");
|
||||
|
||||
private static final String COMPLEX_JSON =
|
||||
"{\"problems\":[{\"Diabetes\":[{\"medications\":[{\"medicationsClasses\":[{\"className\":[{\"associatedDrug\":[{\"name\":\"asprin\",\"dose\":\"\",\"strength\":\"500 mg\"}],\"associatedDrug#2\":[{\"name\":\"somethingElse\",\"dose\":\"\",\"strength\":\"500 mg\"}]}],\"className2\":[{\"associatedDrug\":[{\"name\":\"asprin\",\"dose\":\"\",\"strength\":\"500 mg\"}],\"associatedDrug#2\":[{\"name\":\"somethingElse\",\"dose\":\"\",\"strength\":\"500 mg\"}]}]}]}],\"labs\":[{\"missing_field\":\"missing_value\"}]}],\"Asthma\":[{}]}]}";
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
if (Files.exists(DATABASE_PATH))
|
||||
Databases.removeDatabase(DATABASE_PATH);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
if (Files.exists(DATABASE_PATH))
|
||||
Databases.removeDatabase(DATABASE_PATH);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createDatabaseResourceAndCheckWithSerialization() throws IOException {
|
||||
final var pathToJsonFile = JSON_DIRECTORY.resolve("complex1.json");
|
||||
|
||||
// Create an empty JSON database.
|
||||
Databases.createJsonDatabase(new DatabaseConfiguration(DATABASE_PATH));
|
||||
|
||||
// Open the database.
|
||||
try (final var database = Databases.openJsonDatabase(DATABASE_PATH)) {
|
||||
// Create a resource to store a JSON-document.
|
||||
database.createResource(ResourceConfiguration.newBuilder("resource")
|
||||
.useTextCompression(false)
|
||||
.useDeweyIDs(true)
|
||||
.versioningApproach(VersioningType.DIFFERENTIAL)
|
||||
.revisionsToRestore(3)
|
||||
.buildPathSummary(true)
|
||||
.build());
|
||||
|
||||
// Import JSON.
|
||||
try (final var manager = database.openResourceManager("resource");
|
||||
final var wtx = manager.beginNodeTrx()) {
|
||||
wtx.insertSubtreeAsFirstChild(JsonShredder.createFileReader(pathToJsonFile));
|
||||
wtx.commit();
|
||||
}
|
||||
|
||||
// Serialize JSON again and compare.
|
||||
try (final var manager = database.openResourceManager("resource");
|
||||
final Writer writer = new StringWriter()) {
|
||||
final var serializer = JsonSerializer.newBuilder(manager, writer).build();
|
||||
serializer.call();
|
||||
assertEquals(COMPLEX_JSON, writer.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
package io.sirix.tutorial.json;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.sirix.access.DatabaseConfiguration;
|
||||
import org.sirix.access.Databases;
|
||||
import org.sirix.api.ResourceManager;
|
||||
import org.sirix.api.json.JsonNodeReadOnlyTrx;
|
||||
import org.sirix.api.json.JsonNodeTrx;
|
||||
import org.sirix.api.visitor.JsonNodeVisitor;
|
||||
import org.sirix.api.visitor.VisitResult;
|
||||
import org.sirix.api.visitor.VisitResultType;
|
||||
import org.sirix.axis.temporal.PastAxis;
|
||||
import org.sirix.axis.visitor.VisitorDescendantAxis;
|
||||
import org.sirix.node.immutable.json.ImmutableObjectKeyNode;
|
||||
|
||||
public final class CreateVersionedJsonResourceAndQueryIntegrationTest {
|
||||
private static final String TMP_DIRECTORY = System.getProperty("java.io.tmpdir");
|
||||
|
||||
private static final Path DATABASE_PATH = Paths.get(TMP_DIRECTORY, "sirix", "json-database");
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
if (Files.exists(DATABASE_PATH))
|
||||
Databases.removeDatabase(DATABASE_PATH);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
if (Files.exists(DATABASE_PATH))
|
||||
Databases.removeDatabase(DATABASE_PATH);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createVersionedResourceAndQueryWithTheVisitoDescendantAxis() throws IOException {
|
||||
Databases.createJsonDatabase(new DatabaseConfiguration(DATABASE_PATH));
|
||||
|
||||
try (final var database = Databases.openJsonDatabase(DATABASE_PATH)) {
|
||||
VersionedJsonDocumentCreator.create(database);
|
||||
|
||||
try (final var manager = database.openResourceManager("resource");
|
||||
// Starts a read only transaction on the most recent revision.
|
||||
final var rtx = manager.beginNodeReadOnlyTrx()) {
|
||||
|
||||
final var axis = VisitorDescendantAxis.newBuilder(rtx)
|
||||
.includeSelf()
|
||||
.visitor(new MyJsonNodeVisitor(manager, rtx))
|
||||
.build();
|
||||
|
||||
axis.forEach((unused) -> {});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final class MyJsonNodeVisitor implements JsonNodeVisitor {
|
||||
|
||||
private final ResourceManager<JsonNodeReadOnlyTrx, JsonNodeTrx> manager;
|
||||
|
||||
private final JsonNodeReadOnlyTrx trx;
|
||||
|
||||
public MyJsonNodeVisitor(final ResourceManager<JsonNodeReadOnlyTrx, JsonNodeTrx> manager, final JsonNodeReadOnlyTrx rtx) {
|
||||
this.manager = manager;
|
||||
this.trx = rtx;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisitResult visit(ImmutableObjectKeyNode node) {
|
||||
System.out.println("Object key node (most recent revision " + trx.getRevisionNumber() + "): " + node.getName());
|
||||
|
||||
if (node.getNodeKey() == 24L) {
|
||||
final var pastAxis = new PastAxis<>(manager, trx);
|
||||
|
||||
assertTrue(pastAxis.hasNext());
|
||||
pastAxis.next();
|
||||
|
||||
assertFalse(pastAxis.hasNext());
|
||||
} else if (node.getNodeKey() == 25L) {
|
||||
final var pastAxis = new PastAxis<>(manager, trx);
|
||||
|
||||
assertFalse(pastAxis.hasNext());
|
||||
}
|
||||
|
||||
// Axis to iterate over the node in past revisions (if the node existed back then).
|
||||
final var pastAxis = new PastAxis<>(manager, trx);
|
||||
pastAxis.forEachRemaining((trx) ->
|
||||
System.out.println("Object key node in the past (revision " + trx.getRevisionNumber() + "): " + trx.getName()));
|
||||
|
||||
return VisitResultType.CONTINUE;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
package io.sirix.tutorial.json;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.brackit.xquery.atomic.QNm;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.sirix.access.DatabaseConfiguration;
|
||||
import org.sirix.access.Databases;
|
||||
|
||||
public final class CreateVersionedJsonResourceIntegrationTest {
|
||||
|
||||
private static final String TMP_DIRECTORY = System.getProperty("java.io.tmpdir");
|
||||
|
||||
private static final Path DATABASE_PATH = Paths.get(TMP_DIRECTORY, "sirix", "json-database");
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
if (Files.exists(DATABASE_PATH))
|
||||
Databases.removeDatabase(DATABASE_PATH);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
if (Files.exists(DATABASE_PATH))
|
||||
Databases.removeDatabase(DATABASE_PATH);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createVersionedDatabaseAndCheckAllRevisions() {
|
||||
Databases.createJsonDatabase(new DatabaseConfiguration(DATABASE_PATH));
|
||||
|
||||
try (final var database = Databases.openJsonDatabase(DATABASE_PATH)) {
|
||||
VersionedJsonDocumentCreator.create(database);
|
||||
|
||||
// Check first revision.
|
||||
try (final var manager = database.openResourceManager("resource");
|
||||
final var rtx = manager.beginNodeReadOnlyTrx(1)) {
|
||||
rtx.moveToDocumentRoot().trx().moveToFirstChild().trx().moveToFirstChild();
|
||||
|
||||
assertEquals(new QNm("foo"), rtx.getName());
|
||||
|
||||
rtx.moveToFirstChild();
|
||||
|
||||
assertTrue(rtx.isArray());
|
||||
}
|
||||
|
||||
// Check second revision.
|
||||
try (final var manager = database.openResourceManager("resource");
|
||||
final var rtx = manager.beginNodeReadOnlyTrx(2)) {
|
||||
rtx.moveToDocumentRoot().trx().moveToFirstChild().trx().moveToFirstChild();
|
||||
|
||||
assertEquals(new QNm("revision2"), rtx.getName());
|
||||
|
||||
rtx.moveToFirstChild();
|
||||
|
||||
assertEquals("yes", rtx.getValue());
|
||||
|
||||
rtx.moveToParent().trx().moveToRightSibling();
|
||||
|
||||
assertEquals(new QNm("foo"), rtx.getName());
|
||||
|
||||
rtx.moveToFirstChild();
|
||||
|
||||
assertTrue(rtx.isArray());
|
||||
}
|
||||
|
||||
|
||||
// Check final revision.
|
||||
try (final var manager = database.openResourceManager("resource");
|
||||
final var rtx = manager.beginNodeReadOnlyTrx()) {
|
||||
rtx.moveToDocumentRoot().trx().moveToFirstChild().trx().moveToFirstChild();
|
||||
|
||||
assertEquals(new QNm("revision2"), rtx.getName());
|
||||
|
||||
rtx.moveToFirstChild();
|
||||
|
||||
assertEquals("yes", rtx.getValue());
|
||||
|
||||
rtx.moveToParent().trx().moveToRightSibling();
|
||||
|
||||
assertEquals(new QNm("revision3"), rtx.getName());
|
||||
|
||||
rtx.moveToFirstChild();
|
||||
|
||||
assertEquals("yes", rtx.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package io.sirix.tutorial.json;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.sirix.access.DatabaseConfiguration;
|
||||
import org.sirix.access.Databases;
|
||||
import org.sirix.access.ResourceConfiguration;
|
||||
import org.sirix.api.json.JsonNodeReadOnlyTrx;
|
||||
import org.sirix.axis.DescendantAxis;
|
||||
import org.sirix.axis.IncludeSelf;
|
||||
import org.sirix.axis.filter.FilterAxis;
|
||||
import org.sirix.axis.filter.json.JsonNameFilter;
|
||||
import org.sirix.service.json.shredder.JsonShredder;
|
||||
import org.sirix.settings.VersioningType;
|
||||
|
||||
public final class JsonFilterIntegrationTest {
|
||||
|
||||
private static final Path JSON_DIRECTORY = Paths.get("src", "test", "resources", "json");
|
||||
|
||||
private static final String TMP_DIRECTORY = System.getProperty("java.io.tmpdir");
|
||||
|
||||
private static final Path DATABASE_PATH = Paths.get(TMP_DIRECTORY, "sirix", "json-database");
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
if (Files.exists(DATABASE_PATH))
|
||||
Databases.removeDatabase(DATABASE_PATH);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
if (Files.exists(DATABASE_PATH))
|
||||
Databases.removeDatabase(DATABASE_PATH);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFilter() {
|
||||
final var pathToJsonFile = JSON_DIRECTORY.resolve("complex1.json");
|
||||
|
||||
// Create an empty JSON database.
|
||||
Databases.createJsonDatabase(new DatabaseConfiguration(DATABASE_PATH));
|
||||
|
||||
// Open the database.
|
||||
try (final var database = Databases.openJsonDatabase(DATABASE_PATH)) {
|
||||
// Create a resource to store a JSON-document.
|
||||
database.createResource(ResourceConfiguration.newBuilder("resource")
|
||||
.useTextCompression(false)
|
||||
.useDeweyIDs(true)
|
||||
.versioningApproach(VersioningType.DIFFERENTIAL)
|
||||
.revisionsToRestore(3)
|
||||
.buildPathSummary(true)
|
||||
.build());
|
||||
|
||||
// Import JSON.
|
||||
try (final var manager = database.openResourceManager("resource");
|
||||
final var wtx = manager.beginNodeTrx()) {
|
||||
wtx.insertSubtreeAsFirstChild(JsonShredder.createFileReader(pathToJsonFile));
|
||||
wtx.commit();
|
||||
wtx.moveToDocumentRoot();
|
||||
|
||||
int foundTimes = 0;
|
||||
|
||||
final var axis = new DescendantAxis(wtx, IncludeSelf.YES);
|
||||
final var filter = new JsonNameFilter(wtx, "associatedDrug");
|
||||
|
||||
for (var filterAxis = new FilterAxis<JsonNodeReadOnlyTrx>(axis, filter); filterAxis.hasNext();) {
|
||||
filterAxis.next();
|
||||
foundTimes++;
|
||||
}
|
||||
assertEquals(2, foundTimes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
package io.sirix.tutorial.json;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.sirix.access.DatabaseConfiguration;
|
||||
import org.sirix.access.Databases;
|
||||
import org.sirix.api.json.JsonResourceManager;
|
||||
import org.sirix.service.json.serialize.JsonSerializer;
|
||||
|
||||
public class SerializeVersionedJsonResourceIntegrationTest {
|
||||
|
||||
private static final Path JSON_TEST_RESULT_DIRECTORY = Paths.get("src", "test", "resources", "json-test-result-strings");
|
||||
|
||||
private static final String TMP_DIRECTORY = System.getProperty("java.io.tmpdir");
|
||||
|
||||
private static final Path DATABASE_PATH = Paths.get(TMP_DIRECTORY, "sirix", "json-database");
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
if (Files.exists(DATABASE_PATH))
|
||||
Databases.removeDatabase(DATABASE_PATH);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
if (Files.exists(DATABASE_PATH))
|
||||
Databases.removeDatabase(DATABASE_PATH);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createVersionedResourceAndTestSerializations() throws IOException {
|
||||
Databases.createJsonDatabase(new DatabaseConfiguration(DATABASE_PATH));
|
||||
|
||||
try (final var database = Databases.openJsonDatabase(DATABASE_PATH)) {
|
||||
VersionedJsonDocumentCreator.create(database);
|
||||
|
||||
try (final var manager = database.openResourceManager("resource")) {
|
||||
serializeRevisionOneAndTwo(manager);
|
||||
serializeMostRecentRevision(manager);
|
||||
serializeAllRevisions(manager);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void serializeRevisionOneAndTwo(final JsonResourceManager manager) throws IOException {
|
||||
final var writer = new StringWriter();
|
||||
final var serializer = JsonSerializer.newBuilder(manager, writer, 1, 2).build();
|
||||
serializer.call();
|
||||
final var expectedJson = Files.readAllLines(JSON_TEST_RESULT_DIRECTORY.resolve("revision1And2.json"),
|
||||
StandardCharsets.UTF_8)
|
||||
.stream()
|
||||
.collect(Collectors.joining());
|
||||
assertEquals(expectedJson, writer.toString());
|
||||
}
|
||||
|
||||
private static void serializeMostRecentRevision(final JsonResourceManager manager) throws IOException {
|
||||
final var writer = new StringWriter();
|
||||
final var serializer = JsonSerializer.newBuilder(manager, writer).build();
|
||||
serializer.call();
|
||||
final var expectedJson = Files.readAllLines(JSON_TEST_RESULT_DIRECTORY.resolve("mostRecentRevision.json"),
|
||||
StandardCharsets.UTF_8)
|
||||
.stream()
|
||||
.collect(Collectors.joining());
|
||||
assertEquals(expectedJson, writer.toString());
|
||||
}
|
||||
|
||||
private static void serializeAllRevisions(final JsonResourceManager manager) throws IOException {
|
||||
final var writer = new StringWriter();
|
||||
final var serializer = JsonSerializer.newBuilder(manager, writer, -1).build();
|
||||
serializer.call();
|
||||
final var expectedJson = Files.readAllLines(JSON_TEST_RESULT_DIRECTORY.resolve("allRevisions.json"),
|
||||
StandardCharsets.UTF_8)
|
||||
.stream()
|
||||
.collect(Collectors.joining());
|
||||
assertEquals(expectedJson, writer.toString());
|
||||
}
|
||||
}
|
@ -0,0 +1,130 @@
|
||||
package io.sirix.tutorial.xml;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.sirix.access.DatabaseConfiguration;
|
||||
import org.sirix.access.Databases;
|
||||
import org.sirix.api.ResourceManager;
|
||||
import org.sirix.api.visitor.VisitResult;
|
||||
import org.sirix.api.visitor.VisitResultType;
|
||||
import org.sirix.api.visitor.XmlNodeVisitor;
|
||||
import org.sirix.api.xml.XmlNodeReadOnlyTrx;
|
||||
import org.sirix.api.xml.XmlNodeTrx;
|
||||
import org.sirix.axis.NonStructuralWrapperAxis;
|
||||
import org.sirix.axis.temporal.PastAxis;
|
||||
import org.sirix.axis.visitor.VisitorDescendantAxis;
|
||||
import org.sirix.node.immutable.xdm.ImmutableElement;
|
||||
import org.sirix.node.immutable.xdm.ImmutableText;
|
||||
|
||||
public final class CreateVersionedXmlResourceAndQueryIntegrationTest {
|
||||
private static final String TMP_DIRECTORY = System.getProperty("java.io.tmpdir");
|
||||
|
||||
private static final Path DATABASE_PATH = Paths.get(TMP_DIRECTORY, "sirix", "xml-database");
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
if (Files.exists(DATABASE_PATH))
|
||||
Databases.removeDatabase(DATABASE_PATH);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
if (Files.exists(DATABASE_PATH))
|
||||
Databases.removeDatabase(DATABASE_PATH);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createVersionedResourceAndQueryWithTheVisitoDescendantAxis() throws IOException {
|
||||
Databases.createXmlDatabase(new DatabaseConfiguration(DATABASE_PATH));
|
||||
|
||||
try (final var database = Databases.openXmlDatabase(DATABASE_PATH)) {
|
||||
VersionedXmlDocumentCreator.create(database);
|
||||
|
||||
try (final var manager = database.openResourceManager("resource");
|
||||
// Starts a read only transaction on the most recent revision.
|
||||
final var rtx = manager.beginNodeReadOnlyTrx()) {
|
||||
|
||||
final var axis = new NonStructuralWrapperAxis(
|
||||
VisitorDescendantAxis.newBuilder(rtx)
|
||||
.includeSelf()
|
||||
.visitor(new MyXmlNodeVisitor(manager, rtx))
|
||||
.build());
|
||||
|
||||
axis.forEach((unused) -> {});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final class MyXmlNodeVisitor implements XmlNodeVisitor {
|
||||
|
||||
private final ResourceManager<XmlNodeReadOnlyTrx, XmlNodeTrx> manager;
|
||||
|
||||
private final XmlNodeReadOnlyTrx trx;
|
||||
|
||||
public MyXmlNodeVisitor(final ResourceManager<XmlNodeReadOnlyTrx, XmlNodeTrx> manager, final XmlNodeReadOnlyTrx rtx) {
|
||||
this.manager = manager;
|
||||
this.trx = rtx;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisitResult visit(ImmutableElement node) {
|
||||
System.out.println("Element (most recent revision " + trx.getRevisionNumber() + "): " + node.getName());
|
||||
|
||||
if (node.getNodeKey() == 14L) {
|
||||
final var pastAxis = new PastAxis<>(manager, trx);
|
||||
|
||||
assertTrue(pastAxis.hasNext());
|
||||
pastAxis.next();
|
||||
|
||||
assertFalse(pastAxis.hasNext());
|
||||
} else if (node.getNodeKey() == 16L) {
|
||||
final var pastAxis = new PastAxis<>(manager, trx);
|
||||
|
||||
assertFalse(pastAxis.hasNext());
|
||||
}
|
||||
|
||||
// Axis to iterate over the node in past revisions (if the node existed back then).
|
||||
final var pastAxis = new PastAxis<>(manager, trx);
|
||||
pastAxis.forEachRemaining((trx) ->
|
||||
System.out.println("Element in the past (revision " + trx.getRevisionNumber() + "): " + trx.getName()));
|
||||
|
||||
for (int i = 0, attributes = trx.getAttributeCount(); i < attributes; i++) {
|
||||
trx.moveToAttribute(i);
|
||||
|
||||
System.out.println("Attribute (most recent revision " + trx.getRevisionNumber() + "):"
|
||||
+ trx.getName() + " ='" + trx.getValue() + "'");
|
||||
|
||||
// Axis to iterate over the node in past revisions (if the node existed back then).
|
||||
final var pastAttributeAxis = new PastAxis<>(manager, trx);
|
||||
pastAttributeAxis.forEachRemaining((trx) ->
|
||||
System.out.println("Attribute in the past (revision " + trx.getRevisionNumber() + "): "
|
||||
+ trx.getName() + " ='" + trx.getValue() + "'"));
|
||||
|
||||
trx.moveToParent();
|
||||
}
|
||||
|
||||
return VisitResultType.CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisitResult visit(ImmutableText node) {
|
||||
System.out.println("Text (most recent revision " + trx.getRevisionNumber() + "): " + node.getValue());
|
||||
|
||||
// Axis to iterate over the node in past revisions (if the node existed back then).
|
||||
final var pastAxis = new PastAxis<>(manager, trx);
|
||||
pastAxis.forEachRemaining((trx) ->
|
||||
System.out.println("Text in the past (revision " + trx.getRevisionNumber() + "): " + trx.getValue()));
|
||||
|
||||
return VisitResultType.CONTINUE;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
package io.sirix.tutorial.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.brackit.xquery.atomic.QNm;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.sirix.access.DatabaseConfiguration;
|
||||
import org.sirix.access.Databases;
|
||||
|
||||
public final class CreateVersionedXmlResourceIntegrationTest {
|
||||
|
||||
private static final String TMP_DIRECTORY = System.getProperty("java.io.tmpdir");
|
||||
|
||||
private static final Path DATABASE_PATH = Paths.get(TMP_DIRECTORY, "sirix", "json-database");
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
if (Files.exists(DATABASE_PATH))
|
||||
Databases.removeDatabase(DATABASE_PATH);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
if (Files.exists(DATABASE_PATH))
|
||||
Databases.removeDatabase(DATABASE_PATH);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createVersionedResourceAndCheck() {
|
||||
Databases.createXmlDatabase(new DatabaseConfiguration(DATABASE_PATH));
|
||||
|
||||
try (final var database = Databases.openXmlDatabase(DATABASE_PATH)) {
|
||||
VersionedXmlDocumentCreator.create(database);
|
||||
|
||||
// Check first revision.
|
||||
try (final var manager = database.openResourceManager("resource");
|
||||
final var rtx = manager.beginNodeReadOnlyTrx(1)) {
|
||||
rtx.moveToDocumentRoot().trx().moveToFirstChild().trx().moveToFirstChild();
|
||||
|
||||
assertEquals("oops1", rtx.getValue());
|
||||
}
|
||||
|
||||
// Check second revision.
|
||||
try (final var manager = database.openResourceManager("resource");
|
||||
final var rtx = manager.beginNodeReadOnlyTrx(2)) {
|
||||
rtx.moveToDocumentRoot().trx().moveToFirstChild().trx().moveToFirstChild();
|
||||
|
||||
assertEquals(new QNm("ns", "p", "a"), rtx.getName());
|
||||
assertEquals(14L, rtx.getNodeKey());
|
||||
|
||||
rtx.moveToFirstChild();
|
||||
|
||||
assertEquals("OOPS4!", rtx.getValue());
|
||||
assertEquals(15L, rtx.getNodeKey());
|
||||
|
||||
rtx.moveToParent().trx().moveToRightSibling();
|
||||
|
||||
assertEquals("oops1", rtx.getValue());
|
||||
}
|
||||
|
||||
// Check second revision.
|
||||
try (final var manager = database.openResourceManager("resource");
|
||||
final var rtx = manager.beginNodeReadOnlyTrx()) {
|
||||
rtx.moveToDocumentRoot().trx().moveToFirstChild().trx().moveToFirstChild();
|
||||
|
||||
assertEquals(new QNm("ns", "p", "a"), rtx.getName());
|
||||
assertEquals(16L, rtx.getNodeKey());
|
||||
|
||||
rtx.moveToFirstChild();
|
||||
|
||||
assertEquals("OOPS4!", rtx.getValue());
|
||||
assertEquals(17L, rtx.getNodeKey());
|
||||
|
||||
rtx.moveToParent().trx().moveToRightSibling();
|
||||
|
||||
assertEquals(new QNm("ns", "p", "a"), rtx.getName());
|
||||
assertEquals(14L, rtx.getNodeKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
package io.sirix.tutorial.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.sirix.access.DatabaseConfiguration;
|
||||
import org.sirix.access.Databases;
|
||||
import org.sirix.access.ResourceConfiguration;
|
||||
import org.sirix.service.xml.serialize.XmlSerializer;
|
||||
import org.sirix.service.xml.shredder.XmlShredder;
|
||||
|
||||
public final class CreateXmlDatabaseIntegrationTest {
|
||||
|
||||
private static final Path XML_TEST_RESULT_DIRECTORY = Paths.get("src", "test", "resources", "xml-test-result-strings");
|
||||
|
||||
private static final Path XML_DIRECTORY = Paths.get("src", "test", "resources", "xml");
|
||||
|
||||
private static final String TMP_DIRECTORY = System.getProperty("java.io.tmpdir");
|
||||
|
||||
private static final Path DATABASE_PATH = Paths.get(TMP_DIRECTORY, "sirix", "xml-database");
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
if (Files.exists(DATABASE_PATH))
|
||||
Databases.removeDatabase(DATABASE_PATH);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
if (Files.exists(DATABASE_PATH))
|
||||
Databases.removeDatabase(DATABASE_PATH);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createDatabaseResourceAndCheckWithSerialization() throws IOException {
|
||||
final var pathToXmlFile = XML_DIRECTORY.resolve("orga.xml");
|
||||
|
||||
// Create an empty XML database.
|
||||
Databases.createXmlDatabase(new DatabaseConfiguration(DATABASE_PATH));
|
||||
|
||||
// Open the database.
|
||||
try (final var database = Databases.openXmlDatabase(DATABASE_PATH)) {
|
||||
// Create a resource to store an XML-document.
|
||||
database.createResource(ResourceConfiguration.newBuilder("resource")
|
||||
.useTextCompression(false)
|
||||
.useDeweyIDs(true)
|
||||
.build());
|
||||
|
||||
// Import XML.
|
||||
try (final var manager = database.openResourceManager("resource");
|
||||
final var wtx = manager.beginNodeTrx();
|
||||
final var fileInputStream = new FileInputStream(pathToXmlFile.toFile())) {
|
||||
wtx.insertSubtreeAsFirstChild(XmlShredder.createFileReader(fileInputStream));
|
||||
wtx.commit();
|
||||
}
|
||||
|
||||
// Serialize XML again and compare.
|
||||
try (final var manager = database.openResourceManager("resource");
|
||||
final var outputStream = new ByteArrayOutputStream()) {
|
||||
final var serializer = XmlSerializer.newBuilder(manager, outputStream)
|
||||
.emitXMLDeclaration()
|
||||
.build();
|
||||
serializer.call();
|
||||
|
||||
final var expectedXml = Files.readAllLines(XML_TEST_RESULT_DIRECTORY.resolve("orga.xml"),
|
||||
StandardCharsets.UTF_8)
|
||||
.stream()
|
||||
.collect(Collectors.joining());
|
||||
assertEquals(expectedXml, outputStream.toString(StandardCharsets.UTF_8));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,70 @@
|
||||
package io.sirix.tutorial.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.sirix.access.DatabaseConfiguration;
|
||||
import org.sirix.access.Databases;
|
||||
import org.sirix.access.trx.node.HashType;
|
||||
import org.sirix.diff.DiffFactory;
|
||||
import org.sirix.diff.DiffFactory.DiffOptimized;
|
||||
import org.sirix.diff.DiffFactory.DiffType;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
public class DiffXmlResourceIntegrationTest {
|
||||
private static final String TMP_DIRECTORY = System.getProperty("java.io.tmpdir");
|
||||
|
||||
private static final Path DATABASE_PATH = Paths.get(TMP_DIRECTORY, "sirix", "xml-database");
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
if (Files.exists(DATABASE_PATH))
|
||||
Databases.removeDatabase(DATABASE_PATH);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
if (Files.exists(DATABASE_PATH))
|
||||
Databases.removeDatabase(DATABASE_PATH);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createVersionedResourceAndCheckDiffingOfRevisionOneAndThree() throws IOException {
|
||||
Databases.createXmlDatabase(new DatabaseConfiguration(DATABASE_PATH));
|
||||
|
||||
try (final var database = Databases.openXmlDatabase(DATABASE_PATH)) {
|
||||
VersionedXmlDocumentCreator.create(database);
|
||||
|
||||
try (final var manager = database.openResourceManager("resource");
|
||||
final var rtxOnFirstRevision = manager.beginNodeReadOnlyTrx(1);
|
||||
final var rtxOnThirdRevision = manager.beginNodeReadOnlyTrx(3)) {
|
||||
final var observer = new MyXmlDiffObserver();
|
||||
DiffFactory.invokeFullXmlDiff(
|
||||
new DiffFactory.Builder<>(manager, 3, 1, manager.getResourceConfig().hashType == HashType.NONE
|
||||
? DiffOptimized.NO
|
||||
: DiffOptimized.HASHED,
|
||||
ImmutableSet.of(observer)).skipSubtrees(true));
|
||||
|
||||
final var diffs = observer.getDiffTuples();
|
||||
|
||||
assertEquals(2, diffs.size());
|
||||
|
||||
final var firstDiffTuple = diffs.get(0);
|
||||
|
||||
assertEquals(DiffType.INSERTED, firstDiffTuple.getDiff());
|
||||
|
||||
final var secondDiffTuple = diffs.get(1);
|
||||
|
||||
assertEquals(DiffType.INSERTED, secondDiffTuple.getDiff());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
package io.sirix.tutorial.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.sirix.access.DatabaseConfiguration;
|
||||
import org.sirix.access.Databases;
|
||||
import org.sirix.access.ResourceConfiguration;
|
||||
import org.sirix.api.Axis;
|
||||
import org.sirix.axis.ChildAxis;
|
||||
import org.sirix.axis.DescendantAxis;
|
||||
import org.sirix.axis.IncludeSelf;
|
||||
import org.sirix.axis.NestedAxis;
|
||||
import org.sirix.axis.concurrent.ConcurrentAxis;
|
||||
import org.sirix.axis.filter.FilterAxis;
|
||||
import org.sirix.axis.filter.xml.XdmNameFilter;
|
||||
import org.sirix.service.xml.shredder.XmlShredder;
|
||||
|
||||
/**
|
||||
* Note that this simple test shows, that the higher level XQuery-API is much more user-friendly, when chaining
|
||||
* axis is required.
|
||||
*/
|
||||
public class QueryXmlResourceWithConcurrentAxisIntegrationTest {
|
||||
|
||||
private static final Path XML_DIRECTORY = Paths.get("src", "test", "resources", "xml");
|
||||
|
||||
private static final String TMP_DIRECTORY = System.getProperty("java.io.tmpdir");
|
||||
|
||||
private static final Path DATABASE_PATH = Paths.get(TMP_DIRECTORY, "sirix", "xml-database");
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
if (Files.exists(DATABASE_PATH))
|
||||
Databases.removeDatabase(DATABASE_PATH);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
if (Files.exists(DATABASE_PATH))
|
||||
Databases.removeDatabase(DATABASE_PATH);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createDatabaseAndXMarkResourceAndCheckQuery() throws IOException {
|
||||
final var pathToXmlFile = XML_DIRECTORY.resolve("10mb.xml");
|
||||
|
||||
// Create an empty XML database.
|
||||
Databases.createXmlDatabase(new DatabaseConfiguration(DATABASE_PATH));
|
||||
|
||||
// Open the database.
|
||||
try (final var database = Databases.openXmlDatabase(DATABASE_PATH)) {
|
||||
// Create a resource to store an XML-document.
|
||||
database.createResource(ResourceConfiguration.newBuilder("resource")
|
||||
.useTextCompression(false)
|
||||
.useDeweyIDs(true)
|
||||
.build());
|
||||
|
||||
// Import XML.
|
||||
try (final var manager = database.openResourceManager("resource");
|
||||
final var wtx = manager.beginNodeTrx();
|
||||
final var fileInputStream = new FileInputStream(pathToXmlFile.toFile())) {
|
||||
wtx.insertSubtreeAsFirstChild(XmlShredder.createFileReader(fileInputStream));
|
||||
wtx.commit();
|
||||
}
|
||||
|
||||
try (final var manager = database.openResourceManager("resource");
|
||||
final var firstConcurrRtx = manager.beginNodeReadOnlyTrx();
|
||||
final var secondConcurrRtx = manager.beginNodeReadOnlyTrx();
|
||||
final var thirdConcurrRtx = manager.beginNodeReadOnlyTrx();
|
||||
final var firstRtx = manager.beginNodeReadOnlyTrx();
|
||||
final var secondRtx = manager.beginNodeReadOnlyTrx();
|
||||
final var thirdRtx = manager.beginNodeReadOnlyTrx()) {
|
||||
|
||||
/* query: //regions/africa//location */
|
||||
final Axis axis =
|
||||
new NestedAxis(
|
||||
new NestedAxis(
|
||||
new ConcurrentAxis<>(firstConcurrRtx,
|
||||
new FilterAxis<>(new DescendantAxis(firstRtx, IncludeSelf.YES),
|
||||
new XdmNameFilter(firstRtx, "regions"))),
|
||||
new ConcurrentAxis<>(secondConcurrRtx,
|
||||
new FilterAxis<>(new ChildAxis(secondRtx),
|
||||
new XdmNameFilter(secondRtx, "africa")))),
|
||||
new ConcurrentAxis<>(thirdConcurrRtx,
|
||||
new FilterAxis<>(new DescendantAxis(thirdRtx, IncludeSelf.YES),
|
||||
new XdmNameFilter(thirdRtx, "location"))));
|
||||
|
||||
final var resultNumber = 55;
|
||||
|
||||
for (int i = 0; i < resultNumber; i++) {
|
||||
assertEquals(true, axis.hasNext());
|
||||
axis.next();
|
||||
}
|
||||
assertEquals(false, axis.hasNext());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
package io.sirix.tutorial.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.sirix.access.DatabaseConfiguration;
|
||||
import org.sirix.access.Databases;
|
||||
import org.sirix.api.xml.XmlResourceManager;
|
||||
import org.sirix.service.xml.serialize.XmlSerializer;
|
||||
|
||||
public class SerializeVersionedXmlResourceIntegrationTest {
|
||||
|
||||
private static final Path XML_TEST_RESULT_DIRECTORY = Paths.get("src", "test", "resources", "xml-test-result-strings");
|
||||
|
||||
private static final String TMP_DIRECTORY = System.getProperty("java.io.tmpdir");
|
||||
|
||||
private static final Path DATABASE_PATH = Paths.get(TMP_DIRECTORY, "sirix", "xml-database");
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
if (Files.exists(DATABASE_PATH))
|
||||
Databases.removeDatabase(DATABASE_PATH);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
if (Files.exists(DATABASE_PATH))
|
||||
Databases.removeDatabase(DATABASE_PATH);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createVersionedResourceAndTestSerializations() throws IOException {
|
||||
Databases.createXmlDatabase(new DatabaseConfiguration(DATABASE_PATH));
|
||||
|
||||
try (final var database = Databases.openXmlDatabase(DATABASE_PATH)) {
|
||||
VersionedXmlDocumentCreator.create(database);
|
||||
|
||||
try (final var manager = database.openResourceManager("resource")) {
|
||||
serializeRevisionOneAndTwo(manager);
|
||||
serializeMostRecentRevision(manager);
|
||||
serializeAllRevisions(manager);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void serializeRevisionOneAndTwo(final XmlResourceManager manager) throws IOException {
|
||||
final var outputStream = new ByteArrayOutputStream();
|
||||
final var serializerForRevisionOneAndTwo =
|
||||
XmlSerializer.newBuilder(manager, outputStream, 1, 2).emitIDs()
|
||||
.prettyPrint()
|
||||
.build();
|
||||
serializerForRevisionOneAndTwo.call();
|
||||
final var expectedXml = Files.readAllLines(XML_TEST_RESULT_DIRECTORY.resolve("revision1And2.xml"),
|
||||
StandardCharsets.UTF_8)
|
||||
.stream()
|
||||
.collect(Collectors.joining(System.lineSeparator()));
|
||||
assertEquals(expectedXml, outputStream.toString(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
private static void serializeMostRecentRevision(final XmlResourceManager manager) throws IOException {
|
||||
final var outputStream = new ByteArrayOutputStream();
|
||||
final var serializerForMostRecentRevision =
|
||||
XmlSerializer.newBuilder(manager, outputStream).emitIDs()
|
||||
.prettyPrint()
|
||||
.build();
|
||||
serializerForMostRecentRevision.call();
|
||||
final var expectedXml = Files.readAllLines(XML_TEST_RESULT_DIRECTORY.resolve("mostRecentRevision.xml"),
|
||||
StandardCharsets.UTF_8)
|
||||
.stream()
|
||||
.collect(Collectors.joining(System.lineSeparator()));
|
||||
assertEquals(expectedXml, outputStream.toString(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
private static void serializeAllRevisions(final XmlResourceManager manager) throws IOException {
|
||||
final var outputStream = new ByteArrayOutputStream();
|
||||
final var serializerForAllRevisions =
|
||||
XmlSerializer.newBuilder(manager, outputStream, -1).emitIDs()
|
||||
.prettyPrint()
|
||||
.build();
|
||||
serializerForAllRevisions.call();
|
||||
final var expectedXml = Files.readAllLines(XML_TEST_RESULT_DIRECTORY.resolve("allRevisions.xml"),
|
||||
StandardCharsets.UTF_8)
|
||||
.stream()
|
||||
.collect(Collectors.joining(System.lineSeparator()));
|
||||
assertEquals(expectedXml, outputStream.toString(StandardCharsets.UTF_8));
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
{"sirix":[{"revisionNumber":1,"revision":{"foo":["bar",null,2.33],"bar":{"hello":"world","helloo":true},"baz":"hello","tada":[{"foo":"bar"},{"baz":false},"boo",{},[]]}},{"revisionNumber":2,"revision":{"revision2":"yes","foo":["bar",null,2.33],"bar":{"hello":"world","helloo":true},"baz":"hello","tada":[{"foo":"bar"},{"baz":false},"boo",{},[]]}},{"revisionNumber":3,"revision":{"revision2":"yes","revision3":"yes","foo":["bar",null,2.33],"bar":{"hello":"world","helloo":true},"baz":"hello","tada":[{"foo":"bar"},{"baz":false},"boo",{},[]]}}]}
|
@ -0,0 +1 @@
|
||||
{"revision2":"yes","revision3":"yes","foo":["bar",null,2.33],"bar":{"hello":"world","helloo":true},"baz":"hello","tada":[{"foo":"bar"},{"baz":false},"boo",{},[]]}
|
@ -0,0 +1 @@
|
||||
{"sirix":[{"revisionNumber":1,"revision":{"foo":["bar",null,2.33],"bar":{"hello":"world","helloo":true},"baz":"hello","tada":[{"foo":"bar"},{"baz":false},"boo",{},[]]}},{"revisionNumber":2,"revision":{"revision2":"yes","foo":["bar",null,2.33],"bar":{"hello":"world","helloo":true},"baz":"hello","tada":[{"foo":"bar"},{"baz":false},"boo",{},[]]}}]}
|
@ -0,0 +1,37 @@
|
||||
{
|
||||
"problems": [{
|
||||
"Diabetes":[{
|
||||
"medications":[{
|
||||
"medicationsClasses":[{
|
||||
"className":[{
|
||||
"associatedDrug":[{
|
||||
"name":"asprin",
|
||||
"dose":"",
|
||||
"strength":"500 mg"
|
||||
}],
|
||||
"associatedDrug#2":[{
|
||||
"name":"somethingElse",
|
||||
"dose":"",
|
||||
"strength":"500 mg"
|
||||
}]
|
||||
}],
|
||||
"className2":[{
|
||||
"associatedDrug":[{
|
||||
"name":"asprin",
|
||||
"dose":"",
|
||||
"strength":"500 mg"
|
||||
}],
|
||||
"associatedDrug#2":[{
|
||||
"name":"somethingElse",
|
||||
"dose":"",
|
||||
"strength":"500 mg"
|
||||
}]
|
||||
}]
|
||||
}]
|
||||
}],
|
||||
"labs":[{
|
||||
"missing_field": "missing_value"
|
||||
}]
|
||||
}],
|
||||
"Asthma":[{}]
|
||||
}]}
|
151
persistence-modules/sirix/src/test/resources/json/complex2.json
Normal file
151
persistence-modules/sirix/src/test/resources/json/complex2.json
Normal file
@ -0,0 +1,151 @@
|
||||
{
|
||||
"medications": [
|
||||
{
|
||||
"aceInhibitors": [
|
||||
{
|
||||
"name": "lisinopril",
|
||||
"strength": "10 mg Tab",
|
||||
"dose": "1 tab",
|
||||
"route": "PO",
|
||||
"sig": "daily",
|
||||
"pillCount": "#90",
|
||||
"refills": "Refill 3"
|
||||
}
|
||||
],
|
||||
"antianginal": [
|
||||
{
|
||||
"name": "nitroglycerin",
|
||||
"strength": "0.4 mg Sublingual Tab",
|
||||
"dose": "1 tab",
|
||||
"route": "SL",
|
||||
"sig": "q15min PRN",
|
||||
"pillCount": "#30",
|
||||
"refills": "Refill 1"
|
||||
}
|
||||
],
|
||||
"anticoagulants": [
|
||||
{
|
||||
"name": "warfarin sodium",
|
||||
"strength": "3 mg Tab",
|
||||
"dose": "1 tab",
|
||||
"route": "PO",
|
||||
"sig": "daily",
|
||||
"pillCount": "#90",
|
||||
"refills": "Refill 3"
|
||||
}
|
||||
],
|
||||
"betaBlocker": [
|
||||
{
|
||||
"name": "metoprolol tartrate",
|
||||
"strength": "25 mg Tab",
|
||||
"dose": "1 tab",
|
||||
"route": "PO",
|
||||
"sig": "daily",
|
||||
"pillCount": "#90",
|
||||
"refills": "Refill 3"
|
||||
}
|
||||
],
|
||||
"diuretic": [
|
||||
{
|
||||
"name": "furosemide",
|
||||
"strength": "40 mg Tab",
|
||||
"dose": "1 tab",
|
||||
"route": "PO",
|
||||
"sig": "daily",
|
||||
"pillCount": "#90",
|
||||
"refills": "Refill 3"
|
||||
}
|
||||
],
|
||||
"mineral": [
|
||||
{
|
||||
"name": "potassium chloride ER",
|
||||
"strength": "10 mEq Tab",
|
||||
"dose": "1 tab",
|
||||
"route": "PO",
|
||||
"sig": "daily",
|
||||
"pillCount": "#90",
|
||||
"refills": "Refill 3"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"labs": [
|
||||
{
|
||||
"name": "Arterial Blood Gas",
|
||||
"time": "Today",
|
||||
"location": "Main Hospital Lab"
|
||||
},
|
||||
{
|
||||
"name": "BMP",
|
||||
"time": "Today",
|
||||
"location": "Primary Care Clinic"
|
||||
},
|
||||
{
|
||||
"name": "BNP",
|
||||
"time": "3 Weeks",
|
||||
"location": "Primary Care Clinic"
|
||||
},
|
||||
{
|
||||
"name": "BUN",
|
||||
"time": "1 Year",
|
||||
"location": "Primary Care Clinic"
|
||||
},
|
||||
{
|
||||
"name": "Cardiac Enzymes",
|
||||
"time": "Today",
|
||||
"location": "Primary Care Clinic"
|
||||
},
|
||||
{
|
||||
"name": "CBC",
|
||||
"time": "1 Year",
|
||||
"location": "Primary Care Clinic"
|
||||
},
|
||||
{
|
||||
"name": "Creatinine",
|
||||
"time": "1 Year",
|
||||
"location": "Main Hospital Lab"
|
||||
},
|
||||
{
|
||||
"name": "Electrolyte Panel",
|
||||
"time": "1 Year",
|
||||
"location": "Primary Care Clinic"
|
||||
},
|
||||
{
|
||||
"name": "Glucose",
|
||||
"time": "1 Year",
|
||||
"location": "Main Hospital Lab"
|
||||
},
|
||||
{
|
||||
"name": "PT/INR",
|
||||
"time": "3 Weeks",
|
||||
"location": "Primary Care Clinic"
|
||||
},
|
||||
{
|
||||
"name": "PTT",
|
||||
"time": "3 Weeks",
|
||||
"location": "Coumadin Clinic"
|
||||
},
|
||||
{
|
||||
"name": "TSH",
|
||||
"time": "1 Year",
|
||||
"location": "Primary Care Clinic"
|
||||
}
|
||||
],
|
||||
"imaging": [
|
||||
{
|
||||
"name": "Chest X-Ray",
|
||||
"time": "Today",
|
||||
"location": "Main Hospital Radiology"
|
||||
},
|
||||
{
|
||||
"name": "Chest X-Ray",
|
||||
"time": "Today",
|
||||
"location": "Main Hospital Radiology"
|
||||
},
|
||||
{
|
||||
"name": "Chest X-Ray",
|
||||
"time": "Today",
|
||||
"location": "Main Hospital Radiology"
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1 @@
|
||||
{"foo":["bar",null,2.33],"bar":{"hello":"world","helloo":true},"baz":"hello","tada":[{"foo":"bar"},{"baz":false},"boo",{},[]]}
|
547
persistence-modules/sirix/src/test/resources/json/twitter.json
Normal file
547
persistence-modules/sirix/src/test/resources/json/twitter.json
Normal file
@ -0,0 +1,547 @@
|
||||
{
|
||||
"statuses": [
|
||||
{
|
||||
"created_at": "Sun Feb 25 18:11:01 +0000 2018",
|
||||
"id": 967824267948773377,
|
||||
"id_str": "967824267948773377",
|
||||
"text": "From pilot to astronaut, Robert H. Lawrence was the first African-American to be selected as an astronaut by any na… https://t.co/FjPEWnh804",
|
||||
"truncated": true,
|
||||
"entities": {
|
||||
"hashtags": [],
|
||||
"symbols": [],
|
||||
"user_mentions": [],
|
||||
"urls": [
|
||||
{
|
||||
"url": "https://t.co/FjPEWnh804",
|
||||
"expanded_url": "https://twitter.com/i/web/status/967824267948773377",
|
||||
"display_url": "twitter.com/i/web/status/9…",
|
||||
"indices": [
|
||||
117,
|
||||
140
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"metadata": {
|
||||
"result_type": "popular",
|
||||
"iso_language_code": "en"
|
||||
},
|
||||
"source": "<a href='https://www.sprinklr.com' rel='nofollow'>Sprinklr</a>",
|
||||
"in_reply_to_status_id": null,
|
||||
"in_reply_to_status_id_str": null,
|
||||
"in_reply_to_user_id": null,
|
||||
"in_reply_to_user_id_str": null,
|
||||
"in_reply_to_screen_name": null,
|
||||
"user": {
|
||||
"id": 11348282,
|
||||
"id_str": "11348282",
|
||||
"name": "NASA",
|
||||
"screen_name": "NASA",
|
||||
"location": "",
|
||||
"description": "Explore the universe and discover our home planet with @NASA. We usually post in EST (UTC-5)",
|
||||
"url": "https://t.co/TcEE6NS8nD",
|
||||
"entities": {
|
||||
"url": {
|
||||
"urls": [
|
||||
{
|
||||
"url": "https://t.co/TcEE6NS8nD",
|
||||
"expanded_url": "http://www.nasa.gov",
|
||||
"display_url": "nasa.gov",
|
||||
"indices": [
|
||||
0,
|
||||
23
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"description": {
|
||||
"urls": []
|
||||
}
|
||||
},
|
||||
"protected": false,
|
||||
"followers_count": 28605561,
|
||||
"friends_count": 270,
|
||||
"listed_count": 90405,
|
||||
"created_at": "Wed Dec 19 20:20:32 +0000 2007",
|
||||
"favourites_count": 2960,
|
||||
"utc_offset": -18000,
|
||||
"time_zone": "Eastern Time (US & Canada)",
|
||||
"geo_enabled": false,
|
||||
"verified": true,
|
||||
"statuses_count": 50713,
|
||||
"lang": "en",
|
||||
"contributors_enabled": false,
|
||||
"is_translator": false,
|
||||
"is_translation_enabled": false,
|
||||
"profile_background_color": "000000",
|
||||
"profile_background_image_url": "http://pbs.twimg.com/profile_background_images/590922434682880000/3byPYvqe.jpg",
|
||||
"profile_background_image_url_https": "https://pbs.twimg.com/profile_background_images/590922434682880000/3byPYvqe.jpg",
|
||||
"profile_background_tile": false,
|
||||
"profile_image_url": "http://pbs.twimg.com/profile_images/188302352/nasalogo_twitter_normal.jpg",
|
||||
"profile_image_url_https": "https://pbs.twimg.com/profile_images/188302352/nasalogo_twitter_normal.jpg",
|
||||
"profile_banner_url": "https://pbs.twimg.com/profile_banners/11348282/1518798395",
|
||||
"profile_link_color": "205BA7",
|
||||
"profile_sidebar_border_color": "000000",
|
||||
"profile_sidebar_fill_color": "F3F2F2",
|
||||
"profile_text_color": "000000",
|
||||
"profile_use_background_image": true,
|
||||
"has_extended_profile": true,
|
||||
"default_profile": false,
|
||||
"default_profile_image": false,
|
||||
"following": null,
|
||||
"follow_request_sent": null,
|
||||
"notifications": null,
|
||||
"translator_type": "regular"
|
||||
},
|
||||
"geo": null,
|
||||
"coordinates": null,
|
||||
"place": null,
|
||||
"contributors": null,
|
||||
"is_quote_status": false,
|
||||
"retweet_count": 988,
|
||||
"favorite_count": 3875,
|
||||
"favorited": false,
|
||||
"retweeted": false,
|
||||
"possibly_sensitive": false,
|
||||
"lang": "en"
|
||||
},
|
||||
{
|
||||
"created_at": "Sun Feb 25 19:31:07 +0000 2018",
|
||||
"id": 967844427480911872,
|
||||
"id_str": "967844427480911872",
|
||||
"text": "A magnetic power struggle of galactic proportions - new research highlights the role of the Sun's magnetic landscap… https://t.co/29dZgga54m",
|
||||
"truncated": true,
|
||||
"entities": {
|
||||
"hashtags": [],
|
||||
"symbols": [],
|
||||
"user_mentions": [],
|
||||
"urls": [
|
||||
{
|
||||
"url": "https://t.co/29dZgga54m",
|
||||
"expanded_url": "https://twitter.com/i/web/status/967844427480911872",
|
||||
"display_url": "twitter.com/i/web/status/9…",
|
||||
"indices": [
|
||||
117,
|
||||
140
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"metadata": {
|
||||
"result_type": "popular",
|
||||
"iso_language_code": "en"
|
||||
},
|
||||
"source": "<a href='https://www.sprinklr.com' rel='nofollow'>Sprinklr</a>",
|
||||
"in_reply_to_status_id": null,
|
||||
"in_reply_to_status_id_str": null,
|
||||
"in_reply_to_user_id": null,
|
||||
"in_reply_to_user_id_str": null,
|
||||
"in_reply_to_screen_name": null,
|
||||
"user": {
|
||||
"id": 11348282,
|
||||
"id_str": "11348282",
|
||||
"name": "NASA",
|
||||
"screen_name": "NASA",
|
||||
"location": "",
|
||||
"description": "Explore the universe and discover our home planet with @NASA. We usually post in EST (UTC-5)",
|
||||
"url": "https://t.co/TcEE6NS8nD",
|
||||
"entities": {
|
||||
"url": {
|
||||
"urls": [
|
||||
{
|
||||
"url": "https://t.co/TcEE6NS8nD",
|
||||
"expanded_url": "http://www.nasa.gov",
|
||||
"display_url": "nasa.gov",
|
||||
"indices": [
|
||||
0,
|
||||
23
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"description": {
|
||||
"urls": []
|
||||
}
|
||||
},
|
||||
"protected": false,
|
||||
"followers_count": 28605561,
|
||||
"friends_count": 270,
|
||||
"listed_count": 90405,
|
||||
"created_at": "Wed Dec 19 20:20:32 +0000 2007",
|
||||
"favourites_count": 2960,
|
||||
"utc_offset": -18000,
|
||||
"time_zone": "Eastern Time (US & Canada)",
|
||||
"geo_enabled": false,
|
||||
"verified": true,
|
||||
"statuses_count": 50713,
|
||||
"lang": "en",
|
||||
"contributors_enabled": false,
|
||||
"is_translator": false,
|
||||
"is_translation_enabled": false,
|
||||
"profile_background_color": "000000",
|
||||
"profile_background_image_url": "http://pbs.twimg.com/profile_background_images/590922434682880000/3byPYvqe.jpg",
|
||||
"profile_background_image_url_https": "https://pbs.twimg.com/profile_background_images/590922434682880000/3byPYvqe.jpg",
|
||||
"profile_background_tile": false,
|
||||
"profile_image_url": "http://pbs.twimg.com/profile_images/188302352/nasalogo_twitter_normal.jpg",
|
||||
"profile_image_url_https": "https://pbs.twimg.com/profile_images/188302352/nasalogo_twitter_normal.jpg",
|
||||
"profile_banner_url": "https://pbs.twimg.com/profile_banners/11348282/1518798395",
|
||||
"profile_link_color": "205BA7",
|
||||
"profile_sidebar_border_color": "000000",
|
||||
"profile_sidebar_fill_color": "F3F2F2",
|
||||
"profile_text_color": "000000",
|
||||
"profile_use_background_image": true,
|
||||
"has_extended_profile": true,
|
||||
"default_profile": false,
|
||||
"default_profile_image": false,
|
||||
"following": null,
|
||||
"follow_request_sent": null,
|
||||
"notifications": null,
|
||||
"translator_type": "regular"
|
||||
},
|
||||
"geo": null,
|
||||
"coordinates": null,
|
||||
"place": null,
|
||||
"contributors": null,
|
||||
"is_quote_status": false,
|
||||
"retweet_count": 2654,
|
||||
"favorite_count": 7962,
|
||||
"favorited": false,
|
||||
"retweeted": false,
|
||||
"possibly_sensitive": false,
|
||||
"lang": "en"
|
||||
},
|
||||
{
|
||||
"created_at": "Mon Feb 26 19:21:43 +0000 2018",
|
||||
"id": 968204446625869827,
|
||||
"id_str": "968204446625869827",
|
||||
"text": "Someone's got to be first. In space, the first explorers beyond Mars were Pioneers 10 and 11, twin robots who chart… https://t.co/SUX30Y45mr",
|
||||
"truncated": true,
|
||||
"entities": {
|
||||
"hashtags": [],
|
||||
"symbols": [],
|
||||
"user_mentions": [],
|
||||
"urls": [
|
||||
{
|
||||
"url": "https://t.co/SUX30Y45mr",
|
||||
"expanded_url": "https://twitter.com/i/web/status/968204446625869827",
|
||||
"display_url": "twitter.com/i/web/status/9…",
|
||||
"indices": [
|
||||
117,
|
||||
140
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"metadata": {
|
||||
"result_type": "popular",
|
||||
"iso_language_code": "en"
|
||||
},
|
||||
"source": "<a href='https://www.sprinklr.com' rel='nofollow'>Sprinklr</a>",
|
||||
"in_reply_to_status_id": null,
|
||||
"in_reply_to_status_id_str": null,
|
||||
"in_reply_to_user_id": null,
|
||||
"in_reply_to_user_id_str": null,
|
||||
"in_reply_to_screen_name": null,
|
||||
"user": {
|
||||
"id": 11348282,
|
||||
"id_str": "11348282",
|
||||
"name": "NASA",
|
||||
"screen_name": "NASA",
|
||||
"location": "",
|
||||
"description": "Explore the universe and discover our home planet with @NASA. We usually post in EST (UTC-5)",
|
||||
"url": "https://t.co/TcEE6NS8nD",
|
||||
"entities": {
|
||||
"url": {
|
||||
"urls": [
|
||||
{
|
||||
"url": "https://t.co/TcEE6NS8nD",
|
||||
"expanded_url": "http://www.nasa.gov",
|
||||
"display_url": "nasa.gov",
|
||||
"indices": [
|
||||
0,
|
||||
23
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"description": {
|
||||
"urls": []
|
||||
}
|
||||
},
|
||||
"protected": false,
|
||||
"followers_count": 28605561,
|
||||
"friends_count": 270,
|
||||
"listed_count": 90405,
|
||||
"created_at": "Wed Dec 19 20:20:32 +0000 2007",
|
||||
"favourites_count": 2960,
|
||||
"utc_offset": -18000,
|
||||
"time_zone": "Eastern Time (US & Canada)",
|
||||
"geo_enabled": false,
|
||||
"verified": true,
|
||||
"statuses_count": 50713,
|
||||
"lang": "en",
|
||||
"contributors_enabled": false,
|
||||
"is_translator": false,
|
||||
"is_translation_enabled": false,
|
||||
"profile_background_color": "000000",
|
||||
"profile_background_image_url": "http://pbs.twimg.com/profile_background_images/590922434682880000/3byPYvqe.jpg",
|
||||
"profile_background_image_url_https": "https://pbs.twimg.com/profile_background_images/590922434682880000/3byPYvqe.jpg",
|
||||
"profile_background_tile": false,
|
||||
"profile_image_url": "http://pbs.twimg.com/profile_images/188302352/nasalogo_twitter_normal.jpg",
|
||||
"profile_image_url_https": "https://pbs.twimg.com/profile_images/188302352/nasalogo_twitter_normal.jpg",
|
||||
"profile_banner_url": "https://pbs.twimg.com/profile_banners/11348282/1518798395",
|
||||
"profile_link_color": "205BA7",
|
||||
"profile_sidebar_border_color": "000000",
|
||||
"profile_sidebar_fill_color": "F3F2F2",
|
||||
"profile_text_color": "000000",
|
||||
"profile_use_background_image": true,
|
||||
"has_extended_profile": true,
|
||||
"default_profile": false,
|
||||
"default_profile_image": false,
|
||||
"following": null,
|
||||
"follow_request_sent": null,
|
||||
"notifications": null,
|
||||
"translator_type": "regular"
|
||||
},
|
||||
"geo": null,
|
||||
"coordinates": null,
|
||||
"place": null,
|
||||
"contributors": null,
|
||||
"is_quote_status": false,
|
||||
"retweet_count": 729,
|
||||
"favorite_count": 2777,
|
||||
"favorited": false,
|
||||
"retweeted": false,
|
||||
"possibly_sensitive": false,
|
||||
"lang": "en"
|
||||
},
|
||||
{
|
||||
"created_at": "Mon Feb 26 06:42:50 +0000 2018",
|
||||
"id": 968013469743288321,
|
||||
"id_str": "968013469743288321",
|
||||
"text": "宇宙ステーションでも、日本と9時間の時差で月曜日が始まりました。n今週は6人から3人にクルーのサイズダウンがありますが、しっかりと任されているタスクをこなしたいと思います。nn写真は、NASAの実験施設「ディスティニー」のグローブ… https://t.co/2CYoPV6Aqx",
|
||||
"truncated": true,
|
||||
"entities": {
|
||||
"hashtags": [],
|
||||
"symbols": [],
|
||||
"user_mentions": [],
|
||||
"urls": [
|
||||
{
|
||||
"url": "https://t.co/2CYoPV6Aqx",
|
||||
"expanded_url": "https://twitter.com/i/web/status/968013469743288321",
|
||||
"display_url": "twitter.com/i/web/status/9…",
|
||||
"indices": [
|
||||
117,
|
||||
140
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"metadata": {
|
||||
"result_type": "popular",
|
||||
"iso_language_code": "ja"
|
||||
},
|
||||
"source": "<a href='http://twitter.com' rel='nofollow'>Twitter Web Client</a>",
|
||||
"in_reply_to_status_id": null,
|
||||
"in_reply_to_status_id_str": null,
|
||||
"in_reply_to_user_id": null,
|
||||
"in_reply_to_user_id_str": null,
|
||||
"in_reply_to_screen_name": null,
|
||||
"user": {
|
||||
"id": 842625693733203968,
|
||||
"id_str": "842625693733203968",
|
||||
"name": "金井 宣茂",
|
||||
"screen_name": "Astro_Kanai",
|
||||
"location": "",
|
||||
"description": "宇宙飛行士。2017年12月19日から国際宇宙ステーションに長期滞在中。 応援いただいているフォロワーのみなさまと一緒に、宇宙滞在を楽しみたいと思います!",
|
||||
"url": "https://t.co/rWU6cxY9iL",
|
||||
"entities": {
|
||||
"url": {
|
||||
"urls": [
|
||||
{
|
||||
"url": "https://t.co/rWU6cxY9iL",
|
||||
"expanded_url": "https://ameblo.jp/astro-kanai/",
|
||||
"display_url": "ameblo.jp/astro-kanai/",
|
||||
"indices": [
|
||||
0,
|
||||
23
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"description": {
|
||||
"urls": []
|
||||
}
|
||||
},
|
||||
"protected": false,
|
||||
"followers_count": 51512,
|
||||
"friends_count": 59,
|
||||
"listed_count": 655,
|
||||
"created_at": "Fri Mar 17 06:36:35 +0000 2017",
|
||||
"favourites_count": 7075,
|
||||
"utc_offset": 32400,
|
||||
"time_zone": "Tokyo",
|
||||
"geo_enabled": false,
|
||||
"verified": true,
|
||||
"statuses_count": 1035,
|
||||
"lang": "ja",
|
||||
"contributors_enabled": false,
|
||||
"is_translator": false,
|
||||
"is_translation_enabled": false,
|
||||
"profile_background_color": "000000",
|
||||
"profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png",
|
||||
"profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png",
|
||||
"profile_background_tile": false,
|
||||
"profile_image_url": "http://pbs.twimg.com/profile_images/879071738625232901/u0nlrr4Y_normal.jpg",
|
||||
"profile_image_url_https": "https://pbs.twimg.com/profile_images/879071738625232901/u0nlrr4Y_normal.jpg",
|
||||
"profile_banner_url": "https://pbs.twimg.com/profile_banners/842625693733203968/1492509582",
|
||||
"profile_link_color": "E81C4F",
|
||||
"profile_sidebar_border_color": "000000",
|
||||
"profile_sidebar_fill_color": "000000",
|
||||
"profile_text_color": "000000",
|
||||
"profile_use_background_image": false,
|
||||
"has_extended_profile": true,
|
||||
"default_profile": false,
|
||||
"default_profile_image": false,
|
||||
"following": null,
|
||||
"follow_request_sent": null,
|
||||
"notifications": null,
|
||||
"translator_type": "none"
|
||||
},
|
||||
"geo": null,
|
||||
"coordinates": null,
|
||||
"place": null,
|
||||
"contributors": null,
|
||||
"is_quote_status": false,
|
||||
"retweet_count": 226,
|
||||
"favorite_count": 1356,
|
||||
"favorited": false,
|
||||
"retweeted": false,
|
||||
"possibly_sensitive": false,
|
||||
"lang": "ja"
|
||||
},
|
||||
{
|
||||
"created_at": "Mon Feb 26 01:07:05 +0000 2018",
|
||||
"id": 967928974960545793,
|
||||
"id_str": "967928974960545793",
|
||||
"text": "Congratulations to #Olympics athletes who won gold! Neutron stars like the one at the heart of the Crab Nebula may… https://t.co/vz4SnPupe2",
|
||||
"truncated": true,
|
||||
"entities": {
|
||||
"hashtags": [
|
||||
{
|
||||
"text": "Olympics",
|
||||
"indices": [
|
||||
19,
|
||||
28
|
||||
]
|
||||
}
|
||||
],
|
||||
"symbols": [],
|
||||
"user_mentions": [],
|
||||
"urls": [
|
||||
{
|
||||
"url": "https://t.co/vz4SnPupe2",
|
||||
"expanded_url": "https://twitter.com/i/web/status/967928974960545793",
|
||||
"display_url": "twitter.com/i/web/status/9…",
|
||||
"indices": [
|
||||
116,
|
||||
139
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"metadata": {
|
||||
"result_type": "popular",
|
||||
"iso_language_code": "en"
|
||||
},
|
||||
"source": "<a href='https://studio.twitter.com' rel='nofollow'>Media Studio</a>",
|
||||
"in_reply_to_status_id": null,
|
||||
"in_reply_to_status_id_str": null,
|
||||
"in_reply_to_user_id": null,
|
||||
"in_reply_to_user_id_str": null,
|
||||
"in_reply_to_screen_name": null,
|
||||
"user": {
|
||||
"id": 19802879,
|
||||
"id_str": "19802879",
|
||||
"name": "NASA JPL",
|
||||
"screen_name": "NASAJPL",
|
||||
"location": "Pasadena, Calif.",
|
||||
"description": "NASA Jet Propulsion Laboratory manages many of NASA's robotic missions exploring Earth, the solar system and our universe. Tweets from JPL's News Office.",
|
||||
"url": "http://t.co/gcM9d1YLUB",
|
||||
"entities": {
|
||||
"url": {
|
||||
"urls": [
|
||||
{
|
||||
"url": "http://t.co/gcM9d1YLUB",
|
||||
"expanded_url": "http://www.jpl.nasa.gov",
|
||||
"display_url": "jpl.nasa.gov",
|
||||
"indices": [
|
||||
0,
|
||||
22
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"description": {
|
||||
"urls": []
|
||||
}
|
||||
},
|
||||
"protected": false,
|
||||
"followers_count": 2566921,
|
||||
"friends_count": 379,
|
||||
"listed_count": 15065,
|
||||
"created_at": "Sat Jan 31 03:19:43 +0000 2009",
|
||||
"favourites_count": 1281,
|
||||
"utc_offset": -32400,
|
||||
"time_zone": "Alaska",
|
||||
"geo_enabled": false,
|
||||
"verified": true,
|
||||
"statuses_count": 6328,
|
||||
"lang": "en",
|
||||
"contributors_enabled": false,
|
||||
"is_translator": false,
|
||||
"is_translation_enabled": false,
|
||||
"profile_background_color": "0B090B",
|
||||
"profile_background_image_url": "http://pbs.twimg.com/profile_background_images/8479565/twitter_jpl_bkg.009.jpg",
|
||||
"profile_background_image_url_https": "https://pbs.twimg.com/profile_background_images/8479565/twitter_jpl_bkg.009.jpg",
|
||||
"profile_background_tile": false,
|
||||
"profile_image_url": "http://pbs.twimg.com/profile_images/2305452633/lg0hov3l8g4msxbdwv48_normal.jpeg",
|
||||
"profile_image_url_https": "https://pbs.twimg.com/profile_images/2305452633/lg0hov3l8g4msxbdwv48_normal.jpeg",
|
||||
"profile_banner_url": "https://pbs.twimg.com/profile_banners/19802879/1398298134",
|
||||
"profile_link_color": "0D1787",
|
||||
"profile_sidebar_border_color": "100F0E",
|
||||
"profile_sidebar_fill_color": "74A6CD",
|
||||
"profile_text_color": "0C0C0D",
|
||||
"profile_use_background_image": true,
|
||||
"has_extended_profile": false,
|
||||
"default_profile": false,
|
||||
"default_profile_image": false,
|
||||
"following": null,
|
||||
"follow_request_sent": null,
|
||||
"notifications": null,
|
||||
"translator_type": "none"
|
||||
},
|
||||
"geo": null,
|
||||
"coordinates": null,
|
||||
"place": null,
|
||||
"contributors": null,
|
||||
"is_quote_status": false,
|
||||
"retweet_count": 325,
|
||||
"favorite_count": 1280,
|
||||
"favorited": false,
|
||||
"retweeted": false,
|
||||
"possibly_sensitive": false,
|
||||
"lang": "en"
|
||||
}
|
||||
],
|
||||
"search_metadata": {
|
||||
"completed_in": 0.057,
|
||||
"max_id": 0,
|
||||
"max_id_str": "0",
|
||||
"next_results": "?max_id=967574182522482687&q=nasa&include_entities=1&result_type=popular",
|
||||
"query": "nasa",
|
||||
"count": 3,
|
||||
"since_id": 0,
|
||||
"since_id_str": "0"
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
<sdb:sirix xmlns:sdb="https://sirix.io/rest">
|
||||
<sdb:sirix-item sdb:revision="1">
|
||||
<p:a xmlns:p="ns" sdb:id="1" i="j">
|
||||
oops1
|
||||
<b sdb:id="5">
|
||||
foo
|
||||
<c sdb:id="7"/>
|
||||
</b>
|
||||
oops2
|
||||
<b sdb:id="9" p:x="y">
|
||||
<c sdb:id="11"/>
|
||||
bar
|
||||
</b>
|
||||
oops3
|
||||
</p:a>
|
||||
</sdb:sirix-item>
|
||||
<sdb:sirix-item sdb:revision="2">
|
||||
<p:a xmlns:p="ns" sdb:id="1" i="j">
|
||||
<p:a sdb:id="14">OOPS4!</p:a>
|
||||
oops1
|
||||
<b sdb:id="5">
|
||||
foo
|
||||
<c sdb:id="7"/>
|
||||
</b>
|
||||
oops2
|
||||
<b sdb:id="9" p:x="y">
|
||||
<c sdb:id="11"/>
|
||||
bar
|
||||
</b>
|
||||
oops3
|
||||
</p:a>
|
||||
</sdb:sirix-item>
|
||||
<sdb:sirix-item sdb:revision="3">
|
||||
<p:a xmlns:p="ns" sdb:id="1" i="j">
|
||||
<p:a sdb:id="16">OOPS4!</p:a>
|
||||
<p:a sdb:id="14">OOPS4!</p:a>
|
||||
oops1
|
||||
<b sdb:id="5">
|
||||
foo
|
||||
<c sdb:id="7"/>
|
||||
</b>
|
||||
oops2
|
||||
<b sdb:id="9" p:x="y">
|
||||
<c sdb:id="11"/>
|
||||
bar
|
||||
</b>
|
||||
oops3
|
||||
</p:a>
|
||||
</sdb:sirix-item>
|
||||
</sdb:sirix>
|
@ -0,0 +1,17 @@
|
||||
<p:a xmlns:p="ns" id="1" i="j">
|
||||
<p:a id="16">OOPS4!</p:a>
|
||||
<p:a id="14">OOPS4!</p:a>
|
||||
oops1
|
||||
<b id="5">
|
||||
foo
|
||||
<c id="7"/>
|
||||
</b>
|
||||
oops2
|
||||
<b id="9" p:x="y">
|
||||
<c id="11"/>
|
||||
bar
|
||||
</b>
|
||||
oops3
|
||||
</p:a>
|
||||
|
||||
|
@ -0,0 +1 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Organization><Department><Member employee="true" key="12"><Firstname>Kurt</Firstname><Lastname>Mayer</Lastname><DateOfBirth>1.4.1963</DateOfBirth><Title>Dr.-Ing.</Title></Member><Member employe="false" key="40"><Firstname>Hans</Firstname><Lastname>Mettmann</Lastname><DateOfBirth>12.9.1974</DateOfBirth><Title>Dipl.-Inf</Title></Member><Member/><Member/></Department><Project id="4711" priority="high"><Title>XML-DB</Title><Budget>10000</Budget></Project><Project id="666" priority="evenhigher"><Title>DISS</Title><Budget>7000</Budget><Abstract>Native<b>XML</b>-Databases</Abstract></Project></Organization>
|
@ -0,0 +1,33 @@
|
||||
<sdb:sirix xmlns:sdb="https://sirix.io/rest">
|
||||
<sdb:sirix-item sdb:revision="1">
|
||||
<p:a xmlns:p="ns" sdb:id="1" i="j">
|
||||
oops1
|
||||
<b sdb:id="5">
|
||||
foo
|
||||
<c sdb:id="7"/>
|
||||
</b>
|
||||
oops2
|
||||
<b sdb:id="9" p:x="y">
|
||||
<c sdb:id="11"/>
|
||||
bar
|
||||
</b>
|
||||
oops3
|
||||
</p:a>
|
||||
</sdb:sirix-item>
|
||||
<sdb:sirix-item sdb:revision="2">
|
||||
<p:a xmlns:p="ns" sdb:id="1" i="j">
|
||||
<p:a sdb:id="14">OOPS4!</p:a>
|
||||
oops1
|
||||
<b sdb:id="5">
|
||||
foo
|
||||
<c sdb:id="7"/>
|
||||
</b>
|
||||
oops2
|
||||
<b sdb:id="9" p:x="y">
|
||||
<c sdb:id="11"/>
|
||||
bar
|
||||
</b>
|
||||
oops3
|
||||
</p:a>
|
||||
</sdb:sirix-item>
|
||||
</sdb:sirix>
|
205334
persistence-modules/sirix/src/test/resources/xml/10mb.xml
Normal file
205334
persistence-modules/sirix/src/test/resources/xml/10mb.xml
Normal file
File diff suppressed because one or more lines are too long
@ -0,0 +1 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Organization><Department><Member key="12" employee="true"><Firstname>Kurt</Firstname><Lastname>Mayer</Lastname><DateOfBirth>1.4.1963</DateOfBirth><Title>Dr.-Ing.</Title></Member><Member key="40" employe="false"><Firstname>Hans</Firstname><Lastname>Mettmann</Lastname><DateOfBirth>12.9.1974</DateOfBirth><Title>Dipl.-Inf</Title></Member><Member/><Member/></Department><Project id="4711" priority="high"><Title>XML-DB</Title><Budget>10000</Budget></Project><Project id="666" priority="evenhigher"><Title>DISS</Title><Budget>7000</Budget><Abstract>Native<b>XML</b>-Databases</Abstract></Project></Organization>
|
41
persistence-modules/sirix/src/test/resources/xml/test.xml
Normal file
41
persistence-modules/sirix/src/test/resources/xml/test.xml
Normal file
@ -0,0 +1,41 @@
|
||||
<nachrichten>
|
||||
<nachricht>
|
||||
<sender>...</sender>
|
||||
<empfaenger>...</empfaenger>
|
||||
<betreff>...</betreff>
|
||||
<text>baz</text>
|
||||
</nachricht>
|
||||
<nachricht>
|
||||
<sender>...</sender>
|
||||
<empfaenger>...</empfaenger>
|
||||
<betreff>sommer</betreff>
|
||||
<text>strand</text>
|
||||
</nachricht>
|
||||
<nachricht>
|
||||
<sender>...</sender>
|
||||
<empfaenger>...</empfaenger>
|
||||
<betreff>...</betreff>
|
||||
<text>strand</text>
|
||||
</nachricht>
|
||||
<nachricht>
|
||||
<sender>...</sender>
|
||||
<empfaenger>...</empfaenger>
|
||||
<betreff>foo</betreff>
|
||||
<text>bar</text>
|
||||
</nachricht>
|
||||
<nachricht>
|
||||
<sender>...</sender>
|
||||
<empfaenger>...</empfaenger>
|
||||
<betreff>sommer</betreff>
|
||||
<text>...</text>
|
||||
</nachricht>
|
||||
<nachricht>...</nachricht>
|
||||
<nachricht>
|
||||
<sender>...</sender>
|
||||
<empfaenger>...</empfaenger>
|
||||
<betreff>foo</betreff>
|
||||
<text>...</text>
|
||||
</nachricht>
|
||||
</nachrichten>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user