use of org.jaxrx.core.QueryParameter in project sirix by sirixdb.
the class DatabaseRepresentationTest method performQueryOnResource.
/**
* This method tests
* {@link DatabaseRepresentation#performQueryOnResource(String, String, Map)}
*
* @throws IOException
* @throws WebApplicationException
* @throws SAXException
* @throws ParserConfigurationException
*/
@Test
public void performQueryOnResource() throws WebApplicationException, IOException, ParserConfigurationException, SAXException {
final Map<QueryParameter, String> params = new HashMap<QueryParameter, String>();
params.put(QueryParameter.OUTPUT, LITERALTRUE);
params.put(QueryParameter.WRAP, LITERALTRUE);
final StreamingOutput sOutput = sirix.performQueryOnResource(RESOURCENAME, "//continent", params);
final ByteArrayOutputStream output = new ByteArrayOutputStream();
sOutput.write(output);
final Document doc = DOMHelper.buildDocument(output);
Node node = doc.getElementsByTagName("continent").item(0);
assertNotNull("check if continent exists", node);
node = doc.getElementsByTagName("country").item(0);
assertNull("check for null country object", node);
output.close();
}
use of org.jaxrx.core.QueryParameter in project sirix by sirixdb.
the class DatabaseRepresentationTest method addResource.
/**
* This method tests {@link DatabaseRepresentation#add(InputStream, String)}
*
* @throws IOException
* @throws WebApplicationException
* @throws SAXException
* @throws ParserConfigurationException
* @throws SirixException
*/
@Test
public void addResource() throws WebApplicationException, IOException, ParserConfigurationException, SAXException, SirixException {
final InputStream input = DatabaseRepresentationTest.class.getResourceAsStream("/books.xml");
sirix.deleteResource(RESOURCENAME);
assertTrue(sirix.add(input, RESOURCENAME));
final Map<QueryParameter, String> params = new HashMap<QueryParameter, String>();
params.put(QueryParameter.WRAP, LITERALTRUE);
final StreamingOutput sOutput = sirix.performQueryOnResource(RESOURCENAME, ".", params);
final ByteArrayOutputStream output = new ByteArrayOutputStream();
sOutput.write(output);
final Document doc = DOMHelper.buildDocument(output);
Node node = doc.getElementsByTagName("books").item(0);
assertNotNull("check if books has been added to factbook", node);
// node = doc.getElementsByTagName("mondial").item(0);
// assertNotNull("check if mondial still exists", node);
output.close();
}
use of org.jaxrx.core.QueryParameter in project sirix by sirixdb.
the class DatabaseRepresentationTest method getResource.
/**
* This method tests
* {@link DatabaseRepresentation#getResource(String, java.util.Map)}
*
* @throws SirixException
* @throws IOException
* @throws WebApplicationException
* @throws SAXException
* @throws ParserConfigurationException
*/
@Test
public void getResource() throws SirixException, WebApplicationException, IOException, ParserConfigurationException, SAXException {
final Map<QueryParameter, String> queryParams = new HashMap<QueryParameter, String>();
Document doc;
Node node;
Node resultNode;
Attr attribute;
StreamingOutput sOutput = sirix.getResource(RESOURCENAME, queryParams);
ByteArrayOutputStream output = new ByteArrayOutputStream();
sOutput.write(output);
doc = DOMHelper.buildDocument(output);
node = doc.getElementsByTagName("mondial").item(0);
attribute = (Attr) node.getAttributes().getNamedItem(IDNAME);
resultNode = doc.getElementsByTagName(RESULTNAME).item(0);
assertNotNull("mondial does exist", node);
assertNull("test if result node exists - null", resultNode);
assertNull("test if id element exists - null", attribute);
output.close();
queryParams.put(QueryParameter.WRAP, LITERALTRUE);
sOutput = sirix.getResource(RESOURCENAME, queryParams);
output = new ByteArrayOutputStream();
sOutput.write(output);
doc = DOMHelper.buildDocument(output);
node = doc.getElementsByTagName("country").item(0);
attribute = (Attr) node.getAttributes().getNamedItem(IDNAME);
resultNode = doc.getElementsByTagName(RESULTNAME).item(0);
assertNotNull("test if country exists", node);
assertNotNull("test if result node exists", resultNode);
assertNull("test if id element exists", attribute);
output.close();
queryParams.put(QueryParameter.OUTPUT, LITERALTRUE);
sOutput = sirix.getResource(RESOURCENAME, queryParams);
output = new ByteArrayOutputStream();
sOutput.write(output);
doc = DOMHelper.buildDocument(output);
node = doc.getElementsByTagName(NAME).item(0);
attribute = (Attr) node.getAttributes().getNamedItem(IDNAME);
resultNode = doc.getElementsByTagName(RESULTNAME).item(0);
assertNotNull("test if country exists2", node);
assertNotNull("test if result node exists2", resultNode);
assertNotNull("test if id element exists2", attribute);
output.close();
sOutput = sirix.getResource(RESOURCENAME, queryParams);
output = new ByteArrayOutputStream();
sOutput.write(output);
doc = DOMHelper.buildDocument(output);
node = doc.getElementsByTagName("city").item(0);
attribute = (Attr) node.getAttributes().getNamedItem(IDNAME);
resultNode = doc.getElementsByTagName(RESULTNAME).item(0);
assertNotNull("test if city exists2", node);
assertNotNull("test if result node exists2", resultNode);
assertNotNull("test if id element exists2", attribute);
output.close();
}
use of org.jaxrx.core.QueryParameter in project sirix by sirixdb.
the class NodeIdRepresentationTest method testGetResourceByAT.
/**
* Test method for
* {@link org.sirix.service.jaxrx.implementation.NodeIdRepresentation#getResourceByAT(java.lang.String, long, java.util.Map, org.sirix.service.jaxrx.enums.IDAccessType)}
* .
*
* @throws IOException
* @throws WebApplicationException
* @throws SAXException
* @throws ParserConfigurationException
*/
@Test
public final void testGetResourceByAT() throws WebApplicationException, IOException, ParserConfigurationException, SAXException {
final Map<QueryParameter, String> queryParams = new HashMap<QueryParameter, String>();
queryParams.put(QueryParameter.OUTPUT, LITERALSTRUE);
queryParams.put(QueryParameter.WRAP, LITERALSTRUE);
queryParams.put(QueryParameter.REVISION, "1");
ByteArrayOutputStream outputStream;
Document doc;
NodeList list;
String textContent = null;
Node node;
Attr attribute;
// Test for fist child
final StreamingOutput fChildOutput = ridWorker.getResourceByAT(RESOURCENAME, NODEIDGETRESOURCE, queryParams, IDAccessType.FIRSTCHILD);
outputStream = new ByteArrayOutputStream();
fChildOutput.write(outputStream);
doc = DOMHelper.buildDocument(outputStream);
list = doc.getElementsByTagName(NAME);
node = list.item(0);
textContent = node.getTextContent();
outputStream.close();
assertEquals("Test expected name ", "Albania", textContent);
// Test for last child final StreamingOutput lChildOutput =
final StreamingOutput lChildOutput = ridWorker.getResourceByAT(RESOURCENAME, NODEIDGETRESOURCE, queryParams, IDAccessType.LASTCHILD);
outputStream = new ByteArrayOutputStream();
lChildOutput.write(outputStream);
doc = DOMHelper.buildDocument(outputStream);
list = doc.getElementsByTagName("border");
node = list.item(0);
attribute = (Attr) node.getAttributes().getNamedItem("length");
outputStream.close();
assertEquals("Test expected border value ", "287", attribute.getValue());
// Test for rightSibling final StreamingOutput rSiblingOutput =
final StreamingOutput rSiblingOutput = ridWorker.getResourceByAT(RESOURCENAME, NODEIDGETRESOURCE, queryParams, IDAccessType.RIGHTSIBLING);
outputStream = new ByteArrayOutputStream();
rSiblingOutput.write(outputStream);
doc = DOMHelper.buildDocument(outputStream);
list = doc.getElementsByTagName("country");
node = list.item(0);
attribute = (Attr) node.getAttributes().getNamedItem(NAME);
outputStream.close();
assertEquals("Test expected right sibling name ", "Andorra", attribute.getValue());
// Test for leftSibling final StreamingOutput lSiblingOutput =
final StreamingOutput lSiblingOutput = ridWorker.getResourceByAT(RESOURCENAME, NODEIDGETRESOURCE, queryParams, IDAccessType.LEFTSIBLING);
outputStream = new ByteArrayOutputStream();
lSiblingOutput.write(outputStream);
doc = DOMHelper.buildDocument(outputStream);
list = doc.getElementsByTagName("continent");
node = list.item(0);
attribute = (Attr) node.getAttributes().getNamedItem(NAME);
outputStream.close();
assertEquals("Test expected right sibling name ", "Africa", attribute.getValue());
}
use of org.jaxrx.core.QueryParameter in project sirix by sirixdb.
the class NodeIdRepresentationTest method testAddSubResource.
/**
* Test method for
* {@link org.sirix.service.jaxrx.implementation.NodeIdRepresentation#addSubResource(java.lang.String, long, java.io.InputStream, org.sirix.service.jaxrx.enums.IDAccessType)}
* .
*
* @throws IOException
* @throws WebApplicationException
* @throws SAXException
* @throws ParserConfigurationException
*/
@Test
public final void testAddSubResource() throws WebApplicationException, IOException, ParserConfigurationException, SAXException {
final Map<QueryParameter, String> queryParams = new HashMap<QueryParameter, String>();
queryParams.put(QueryParameter.OUTPUT, LITERALSTRUE);
queryParams.put(QueryParameter.WRAP, LITERALSTRUE);
final Map<QueryParameter, String> queryParamsComp = new HashMap<QueryParameter, String>();
queryParams.put(QueryParameter.OUTPUT, LITERALSTRUE);
ByteArrayOutputStream outputStream;
StreamingOutput result;
Document doc;
NodeList list;
Node node;
final InputStream newNode = new ByteArrayInputStream("<myNode><test>hello</test></myNode>".getBytes());
// Test append first child
ridWorker.addSubResource(RESOURCENAME, NODEIDGETRESOURCE, newNode, IDAccessType.FIRSTCHILD);
result = ridWorker.getResourceByAT(RESOURCENAME, NODEIDGETRESOURCE, queryParamsComp, IDAccessType.FIRSTCHILD);
outputStream = new ByteArrayOutputStream();
result.write(outputStream);
doc = DOMHelper.buildDocument(outputStream);
list = doc.getElementsByTagName(NODENAME);
node = list.item(0);
outputStream.close();
assertNotNull("Test if first child exist after inserting", node);
// Test append last child
newNode.reset();
ridWorker.addSubResource(RESOURCENAME, NODEIDGETRESOURCE, newNode, IDAccessType.LASTCHILD);
result = ridWorker.getResourceByAT(RESOURCENAME, NODEIDGETRESOURCE, queryParamsComp, IDAccessType.LASTCHILD);
outputStream = new ByteArrayOutputStream();
result.write(outputStream);
doc = DOMHelper.buildDocument(outputStream);
list = doc.getElementsByTagName(NODENAME);
node = list.item(0);
outputStream.close();
assertNotNull("Test if last child exist after inserting", node);
// Test append left sibling
newNode.reset();
ridWorker.addSubResource(RESOURCENAME, NODEIDGETRESOURCE, newNode, IDAccessType.LEFTSIBLING);
result = ridWorker.getResourceByAT(RESOURCENAME, NODEIDGETRESOURCE, queryParamsComp, IDAccessType.LEFTSIBLING);
outputStream = new ByteArrayOutputStream();
result.write(outputStream);
doc = DOMHelper.buildDocument(outputStream);
list = doc.getElementsByTagName(NODENAME);
node = list.item(0);
outputStream.close();
assertNotNull("Test if left sibling exist after inserting", node);
// Test append right sibling
newNode.reset();
ridWorker.addSubResource(RESOURCENAME, NODEIDGETRESOURCE, newNode, IDAccessType.RIGHTSIBLING);
result = ridWorker.getResourceByAT(RESOURCENAME, NODEIDGETRESOURCE, queryParamsComp, IDAccessType.RIGHTSIBLING);
outputStream = new ByteArrayOutputStream();
result.write(outputStream);
doc = DOMHelper.buildDocument(outputStream);
list = doc.getElementsByTagName(NODENAME);
node = list.item(0);
outputStream.close();
assertNotNull("Test if right sibling exist after inserting", node);
}
Aggregations