use of org.exist.xquery.value.Item in project exist by eXist-db.
the class IndexerTest method store_and_retrieve_ws_mixed_content_value.
private String store_and_retrieve_ws_mixed_content_value(final boolean preserve, final String typeXml, final String typeXquery) throws EXistException, IOException, LockException, AuthenticationException, PermissionDeniedException, SAXException, XPathException {
store_preserve_ws_mixed_content_value(preserve, typeXml);
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
final XQuery xquery = pool.getXQueryService();
final Sequence result = xquery.execute(broker, typeXquery, null);
try (final StringWriter out = new StringWriter()) {
final Properties props = new Properties();
props.setProperty(OutputKeys.INDENT, "yes");
final SAXSerializer serializer = new SAXSerializer(out, props);
serializer.startDocument();
for (final SequenceIterator i = result.iterate(); i.hasNext(); ) {
final Item next = i.nextItem();
next.toSAX(broker, serializer, props);
}
serializer.endDocument();
return out.toString();
}
}
}
use of org.exist.xquery.value.Item in project exist by eXist-db.
the class IndexerTest3 method store_and_retrieve_suppress_type.
private String store_and_retrieve_suppress_type(final String type, final String typeXml, final String typeXquery) throws EXistException, IOException, LockException, AuthenticationException, PermissionDeniedException, SAXException, XPathException {
store_suppress_type(type, typeXml);
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final StringWriter out = new StringWriter()) {
final XQuery xquery = pool.getXQueryService();
final Sequence result = xquery.execute(broker, typeXquery, null);
final Properties props = new Properties();
props.setProperty(OutputKeys.INDENT, "no");
final SAXSerializer serializer = new SAXSerializer(out, props);
serializer.startDocument();
for (final SequenceIterator i = result.iterate(); i.hasNext(); ) {
final Item next = i.nextItem();
next.toSAX(broker, serializer, props);
}
serializer.endDocument();
return out.toString();
}
}
use of org.exist.xquery.value.Item in project exist by eXist-db.
the class IntersectTest method memtree_intersect_memtree.
/**
* Tests the XQuery `intersect` operator against an
* in-memory node on both the left and right sides
*/
@Test
public void memtree_intersect_memtree() throws XPathException, NoSuchMethodException {
final XQueryContext mockContext = createMock(XQueryContext.class);
final PathExpr mockLeft = createMock(PathExpr.class);
final PathExpr mockRight = createMock(PathExpr.class);
final Sequence mockContextSequence = createMock(Sequence.class);
final Item mockContextItem = createMock(Item.class);
final Profiler mockProfiler = createMock(Profiler.class);
expect(mockContext.nextExpressionId()).andReturn(1);
expect(mockContext.getProfiler()).andReturn(mockProfiler);
final org.exist.dom.memtree.ElementImpl memElement = (org.exist.dom.memtree.ElementImpl) createInMemoryDocument().getDocumentElement();
// memtree node
expect(mockLeft.eval(mockContextSequence, mockContextItem)).andReturn(memElement);
// same memtree node
expect(mockRight.eval(mockContextSequence, mockContextItem)).andReturn(memElement);
expect(mockContext.getProfiler()).andReturn(mockProfiler);
replay(mockRight, mockLeft, mockContext);
// test
final Intersect intersect = new Intersect(mockContext, mockLeft, mockRight);
final Sequence result = intersect.eval(mockContextSequence, mockContextItem);
assertEquals(1, ((ValueSequence) result).size());
verify(mockRight, mockLeft, mockContext);
}
use of org.exist.xquery.value.Item in project exist by eXist-db.
the class IntersectTest method memtree_intersect_persistent.
/**
* Tests the XQuery `intersect` operator against an
* in-memory node on the left and a persistent node on the right
*/
@Test
public void memtree_intersect_persistent() throws XPathException, NoSuchMethodException {
final XQueryContext mockContext = createMock(XQueryContext.class);
final PathExpr mockLeft = createMock(PathExpr.class);
final PathExpr mockRight = createMock(PathExpr.class);
final Sequence mockContextSequence = createMock(Sequence.class);
final Item mockContextItem = createMock(Item.class);
final Profiler mockProfiler = createMock(Profiler.class);
final DocumentImpl mockPersistentDoc = createMock(DocumentImpl.class);
final NodeProxy mockPersistentNode = createMockBuilder(NodeProxy.class).withConstructor(DocumentImpl.class, NodeId.class).withArgs(mockPersistentDoc, new DLN(1)).addMockedMethods(NodeProxy.class.getMethod("isEmpty", new Class[] {}), NodeProxy.class.getMethod("getItemType", new Class[] {}), NodeProxy.class.getMethod("equals", new Class[] { Object.class })).createMock();
expect(mockContext.nextExpressionId()).andReturn(1);
expect(mockContext.getProfiler()).andReturn(mockProfiler);
// memtree node
expect(mockLeft.eval(mockContextSequence, mockContextItem)).andReturn((org.exist.dom.memtree.ElementImpl) createInMemoryDocument().getDocumentElement());
// persistent node
expect(mockRight.eval(mockContextSequence, mockContextItem)).andReturn(mockPersistentNode);
expect(mockPersistentNode.isEmpty()).andReturn(false);
expect(mockPersistentNode.getItemType()).andReturn(Type.NODE);
expect(mockContext.getProfiler()).andReturn(mockProfiler);
replay(mockPersistentDoc, mockPersistentNode, mockRight, mockLeft, mockContext);
// test
final Intersect intersect = new Intersect(mockContext, mockLeft, mockRight);
final Sequence result = intersect.eval(mockContextSequence, mockContextItem);
assertEquals(0, ((ValueSequence) result).size());
verify(mockPersistentDoc, mockPersistentNode, mockRight, mockLeft, mockContext);
}
use of org.exist.xquery.value.Item in project exist by eXist-db.
the class SerializeAttrMatchesTest method expandAttr.
@Test
public void expandAttr() throws CollectionConfigurationException, LockException, IOException, SAXException, PermissionDeniedException, EXistException, XPathException {
configureAndStore(COLLECTION_CONFIG, XML, "test1.xml");
// query and expand
final String query = "for $hit in collection(\"" + TestConstants.TEST_COLLECTION_URI.toString() + "\")//w[ft:query(@lemma, <query><regex>књиг.*</regex></query>)]\n" + "return util:expand($hit, \"highlight-matches=both\")";
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
final XQuery xquery = pool.getXQueryService();
final Sequence seq = xquery.execute(broker, query, null);
assertEquals(1, seq.getItemCount());
final Item item = seq.itemAt(0);
assertTrue(item instanceof ElementImpl);
assertEquals("lemma", ((ElementImpl) item).getAttribute("exist:matches"));
}
}
Aggregations