use of org.exist.dom.persistent.LockedDocument in project exist by eXist-db.
the class SourceFactoryTest method getSourceFromXmldb_noContext.
@Test
public void getSourceFromXmldb_noContext() throws IOException, PermissionDeniedException {
final String contextPath = null;
final String location = "xmldb:exist:///db/library.xqm";
final DBBroker mockBroker = createMock(DBBroker.class);
final LockedDocument mockLockedDoc = createMock(LockedDocument.class);
final BinaryDocument mockBinDoc = createMock(BinaryDocument.class);
expect(mockBroker.getXMLResource(anyObject(), anyObject())).andReturn(mockLockedDoc);
expect(mockLockedDoc.getDocument()).andReturn(mockBinDoc);
expect(mockBinDoc.getResourceType()).andReturn(BinaryDocument.BINARY_FILE);
expect(mockBinDoc.getURI()).andReturn(XmldbURI.create(location)).times(2);
expect(mockBinDoc.getLastModified()).andReturn(123456789l);
/*expect*/
mockLockedDoc.close();
replay(mockBroker, mockLockedDoc, mockBinDoc);
final Source libSource = SourceFactory.getSource(mockBroker, contextPath, location, false);
assertTrue(libSource instanceof DBSource);
assertEquals(XmldbURI.create(location), ((DBSource) libSource).getDocumentPath());
verify(mockBroker, mockLockedDoc, mockBinDoc);
}
use of org.exist.dom.persistent.LockedDocument in project exist by eXist-db.
the class AbstractUpdateTest method read.
private void read(final BrokerPool pool) throws EXistException, PermissionDeniedException, SAXException, XPathException {
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
final Serializer serializer = broker.borrowSerializer();
try (final LockedDocument lockedDoc = broker.getXMLResource(TEST_COLLECTION_URI.append("test2/test.xml"), LockMode.READ_LOCK)) {
assertNotNull("Document '" + TEST_COLLECTION_URI.append("test2/test.xml") + "' should not be null", lockedDoc);
final String data = serializer.serialize(lockedDoc.getDocument());
} finally {
broker.returnSerializer(serializer);
}
final XQuery xquery = pool.getXQueryService();
final Sequence seq = xquery.execute(broker, "/products/product[last()]", null);
for (final SequenceIterator i = seq.iterate(); i.hasNext(); ) {
Item next = i.nextItem();
}
}
}
use of org.exist.dom.persistent.LockedDocument in project exist by eXist-db.
the class SourceFactoryTest method getSourceFromXmldbEmbedded_noContext.
@Test
public void getSourceFromXmldbEmbedded_noContext() throws IOException, PermissionDeniedException {
final String contextPath = null;
final String location = "xmldb:exist://embedded-eXist-server/db/library.xqm";
final DBBroker mockBroker = createMock(DBBroker.class);
final LockedDocument mockLockedDoc = createMock(LockedDocument.class);
final BinaryDocument mockBinDoc = createMock(BinaryDocument.class);
expect(mockBroker.getXMLResource(anyObject(), anyObject())).andReturn(mockLockedDoc);
expect(mockLockedDoc.getDocument()).andReturn(mockBinDoc);
expect(mockBinDoc.getResourceType()).andReturn(BinaryDocument.BINARY_FILE);
expect(mockBinDoc.getURI()).andReturn(XmldbURI.create(location)).times(2);
expect(mockBinDoc.getLastModified()).andReturn(123456789l);
/*expect*/
mockLockedDoc.close();
replay(mockBroker, mockLockedDoc, mockBinDoc);
final Source libSource = SourceFactory.getSource(mockBroker, contextPath, location, false);
assertTrue(libSource instanceof DBSource);
assertEquals(XmldbURI.create(location), ((DBSource) libSource).getDocumentPath());
verify(mockBroker, mockLockedDoc, mockBinDoc);
}
use of org.exist.dom.persistent.LockedDocument in project exist by eXist-db.
the class SourceFactoryTest method getSourceFromDb.
@Test
public void getSourceFromDb() throws IOException, PermissionDeniedException {
final String contextPath = "/db";
final String location = "library.xqm";
final DBBroker mockBroker = createMock(DBBroker.class);
final LockedDocument mockLockedDoc = createMock(LockedDocument.class);
final BinaryDocument mockBinDoc = createMock(BinaryDocument.class);
expect(mockBroker.getXMLResource(anyObject(), anyObject())).andReturn(mockLockedDoc);
expect(mockLockedDoc.getDocument()).andReturn(mockBinDoc);
expect(mockBinDoc.getResourceType()).andReturn(BinaryDocument.BINARY_FILE);
expect(mockBinDoc.getURI()).andReturn(XmldbURI.create(contextPath).append(location)).times(2);
expect(mockBinDoc.getLastModified()).andReturn(123456789l);
/*expect*/
mockLockedDoc.close();
replay(mockBroker, mockLockedDoc, mockBinDoc);
final Source libSource = SourceFactory.getSource(mockBroker, contextPath, location, false);
assertTrue(libSource instanceof DBSource);
assertEquals(XmldbURI.create(contextPath).append(location), ((DBSource) libSource).getDocumentPath());
verify(mockBroker, mockLockedDoc, mockBinDoc);
}
use of org.exist.dom.persistent.LockedDocument in project exist by eXist-db.
the class SourceFactoryTest method getSourceFromXmldbEmbedded.
@Test
public void getSourceFromXmldbEmbedded() throws IOException, PermissionDeniedException {
final String contextPath = "xmldb:exist://embedded-eXist-server/db";
final String location = "library.xqm";
final DBBroker mockBroker = createMock(DBBroker.class);
final LockedDocument mockLockedDoc = createMock(LockedDocument.class);
final BinaryDocument mockBinDoc = createMock(BinaryDocument.class);
expect(mockBroker.getXMLResource(anyObject(), anyObject())).andReturn(mockLockedDoc);
expect(mockLockedDoc.getDocument()).andReturn(mockBinDoc);
expect(mockBinDoc.getResourceType()).andReturn(BinaryDocument.BINARY_FILE);
expect(mockBinDoc.getURI()).andReturn(XmldbURI.create(contextPath).append(location)).times(2);
expect(mockBinDoc.getLastModified()).andReturn(123456789l);
/*expect*/
mockLockedDoc.close();
replay(mockBroker, mockLockedDoc, mockBinDoc);
final Source libSource = SourceFactory.getSource(mockBroker, contextPath, location, false);
assertTrue(libSource instanceof DBSource);
assertEquals(XmldbURI.create(contextPath).append(location), ((DBSource) libSource).getDocumentPath());
verify(mockBroker, mockLockedDoc, mockBinDoc);
}
Aggregations