use of org.exist.dom.persistent.LockedDocument in project exist by eXist-db.
the class FluentBrokerAPITest method all.
@Test
public void all() throws PermissionDeniedException, EXistException, LockException {
final XmldbURI docUri = uri("all-test.xml");
final long collectionCreated = 1234;
final long docLastModified = 5678;
final IMocksControl ctrl = createStrictControl();
ctrl.checkOrder(true);
final BrokerPool mockBrokerPool = ctrl.createMock(BrokerPool.class);
final DBBroker mockBroker = ctrl.createMock(DBBroker.class);
final Collection mockCollection = ctrl.createMock(Collection.class);
final LockedDocument mockLockedDocument = ctrl.createMock(LockedDocument.class);
final DocumentImpl mockDocument = ctrl.createMock(DocumentImpl.class);
expect(mockBrokerPool.getBroker()).andReturn(mockBroker);
expect(mockBroker.openCollection(TEST_COLLECTION_URI, READ_LOCK)).andReturn(mockCollection);
expect(mockCollection.getCreated()).andReturn(collectionCreated);
expect(mockCollection.getDocumentWithLock(mockBroker, docUri, READ_LOCK)).andReturn(mockLockedDocument);
expect(mockLockedDocument.getDocument()).andReturn(mockDocument);
expect(mockCollection.getURI()).andReturn(TEST_COLLECTION_URI);
expect(mockDocument.getFileURI()).andReturn(docUri);
// NOTE: checks that Collection lock is release before Document lock
mockCollection.close();
expect(mockDocument.getLastModified()).andReturn(docLastModified);
mockLockedDocument.close();
mockBroker.close();
ctrl.replay();
final Function<Collection, Long> collectionOp = collection -> collection.getCreated();
final BiFunction<Collection, DocumentImpl, String> collectionDocOp = (collection, doc) -> collection.getURI().append(doc.getFileURI()).toString();
final Function<DocumentImpl, Long> documentOp = document -> document.getLastModified();
final Tuple3<Long, String, Long> result = FluentBrokerAPI.builder(mockBrokerPool).withCollection(TEST_COLLECTION_URI, READ_LOCK).execute(collectionOp).withDocument(collection -> new Tuple2<>(docUri, READ_LOCK)).execute(collectionDocOp).withoutCollection().execute(documentOp).doAll();
assertEquals(collectionCreated, result._1.longValue());
assertEquals(TEST_COLLECTION_URI.append(docUri), result._2);
assertEquals(docLastModified, result._3.longValue());
ctrl.verify();
}
use of org.exist.dom.persistent.LockedDocument in project exist by eXist-db.
the class FluentBrokerAPITest method collectionAndDocThenDoc.
@Test
public void collectionAndDocThenDoc() throws PermissionDeniedException, EXistException, LockException {
final XmldbURI docUri = uri("all-test.xml");
final long docLastModified = 5678;
final IMocksControl ctrl = createStrictControl();
ctrl.checkOrder(true);
final BrokerPool mockBrokerPool = ctrl.createMock(BrokerPool.class);
final DBBroker mockBroker = ctrl.createMock(DBBroker.class);
final Collection mockCollection = ctrl.createMock(Collection.class);
final LockedDocument mockLockedDocument = ctrl.createMock(LockedDocument.class);
final DocumentImpl mockDocument = ctrl.createMock(DocumentImpl.class);
expect(mockBrokerPool.getBroker()).andReturn(mockBroker);
expect(mockBroker.openCollection(TEST_COLLECTION_URI, READ_LOCK)).andReturn(mockCollection);
expect(mockCollection.getDocumentWithLock(mockBroker, docUri, READ_LOCK)).andReturn(mockLockedDocument);
expect(mockLockedDocument.getDocument()).andReturn(mockDocument);
expect(mockCollection.getURI()).andReturn(TEST_COLLECTION_URI);
expect(mockDocument.getFileURI()).andReturn(docUri);
// NOTE: checks that Collection lock is release before Document lock
mockCollection.close();
expect(mockDocument.getLastModified()).andReturn(docLastModified);
mockLockedDocument.close();
mockBroker.close();
ctrl.replay();
final BiFunction<Collection, DocumentImpl, String> collectionDocOp = (collection, doc) -> collection.getURI().append(doc.getFileURI()).toString();
final Function<DocumentImpl, Long> documentOp = document -> document.getLastModified();
final Tuple2<String, Long> result = FluentBrokerAPI.builder(mockBrokerPool).withCollection(TEST_COLLECTION_URI, READ_LOCK).withDocument(collection -> new Tuple2<>(docUri, READ_LOCK)).execute(collectionDocOp).withoutCollection().execute(documentOp).doAll();
assertEquals(TEST_COLLECTION_URI.append(docUri), result._1);
assertEquals(docLastModified, result._2.longValue());
ctrl.verify();
}
use of org.exist.dom.persistent.LockedDocument in project exist by eXist-db.
the class FluentBrokerAPITest method collectionAndDocOnly.
@Test
public void collectionAndDocOnly() throws PermissionDeniedException, EXistException, LockException {
final XmldbURI docUri = uri("all-test.xml");
final IMocksControl ctrl = createStrictControl();
ctrl.checkOrder(true);
final BrokerPool mockBrokerPool = ctrl.createMock(BrokerPool.class);
final DBBroker mockBroker = ctrl.createMock(DBBroker.class);
final Collection mockCollection = ctrl.createMock(Collection.class);
final LockedDocument mockLockedDocument = ctrl.createMock(LockedDocument.class);
final DocumentImpl mockDocument = ctrl.createMock(DocumentImpl.class);
final Lock mockDocumentLock = ctrl.createMock(Lock.class);
expect(mockBrokerPool.getBroker()).andReturn(mockBroker);
expect(mockBroker.openCollection(TEST_COLLECTION_URI, READ_LOCK)).andReturn(mockCollection);
expect(mockCollection.getDocumentWithLock(mockBroker, docUri, READ_LOCK)).andReturn(mockLockedDocument);
expect(mockLockedDocument.getDocument()).andReturn(mockDocument);
expect(mockCollection.getURI()).andReturn(TEST_COLLECTION_URI);
expect(mockDocument.getFileURI()).andReturn(docUri);
// NOTE: checks that Collection lock is release before Document lock
mockCollection.close();
mockLockedDocument.close();
mockBroker.close();
ctrl.replay();
final BiFunction<Collection, DocumentImpl, String> collectionDocOp = (collection, doc) -> collection.getURI().append(doc.getFileURI()).toString();
final String result = FluentBrokerAPI.builder(mockBrokerPool).withCollection(TEST_COLLECTION_URI, READ_LOCK).withDocument(collection -> new Tuple2<>(docUri, READ_LOCK)).execute(collectionDocOp).doAll();
assertEquals(TEST_COLLECTION_URI.append(docUri), result);
ctrl.verify();
}
use of org.exist.dom.persistent.LockedDocument in project exist by eXist-db.
the class FluentBrokerAPITest method docOnly.
@Test
public void docOnly() throws PermissionDeniedException, EXistException, LockException {
final XmldbURI docUri = uri("all-test.xml");
final long docLastModified = 5678;
final IMocksControl ctrl = createStrictControl();
ctrl.checkOrder(true);
final BrokerPool mockBrokerPool = ctrl.createMock(BrokerPool.class);
final DBBroker mockBroker = ctrl.createMock(DBBroker.class);
final Collection mockCollection = ctrl.createMock(Collection.class);
final LockedDocument mockLockedDocument = ctrl.createMock(LockedDocument.class);
final DocumentImpl mockDocument = ctrl.createMock(DocumentImpl.class);
expect(mockBrokerPool.getBroker()).andReturn(mockBroker);
expect(mockBroker.openCollection(TEST_COLLECTION_URI, READ_LOCK)).andReturn(mockCollection);
expect(mockCollection.getDocumentWithLock(mockBroker, docUri, READ_LOCK)).andReturn(mockLockedDocument);
expect(mockLockedDocument.getDocument()).andReturn(mockDocument);
// NOTE: checks that Collection lock is release before Document lock
mockCollection.close();
expect(mockDocument.getLastModified()).andReturn(docLastModified);
mockLockedDocument.close();
mockBroker.close();
ctrl.replay();
final Function<DocumentImpl, Long> documentOp = document -> document.getLastModified();
final long result = FluentBrokerAPI.builder(mockBrokerPool).withCollection(TEST_COLLECTION_URI, READ_LOCK).withDocument(collection -> new Tuple2<>(docUri, READ_LOCK)).withoutCollection().execute(documentOp).doAll();
assertEquals(docLastModified, result);
ctrl.verify();
}
use of org.exist.dom.persistent.LockedDocument in project exist by eXist-db.
the class FluentBrokerAPITest method collectionThenDoc.
@Test
public void collectionThenDoc() throws PermissionDeniedException, EXistException, LockException {
final XmldbURI docUri = uri("all-test.xml");
final long collectionCreated = 1234;
final long docLastModified = 5678;
final IMocksControl ctrl = createStrictControl();
ctrl.checkOrder(true);
final BrokerPool mockBrokerPool = ctrl.createMock(BrokerPool.class);
final DBBroker mockBroker = ctrl.createMock(DBBroker.class);
final Collection mockCollection = ctrl.createMock(Collection.class);
final LockedDocument mockLockedDocument = ctrl.createMock(LockedDocument.class);
final DocumentImpl mockDocument = ctrl.createMock(DocumentImpl.class);
expect(mockBrokerPool.getBroker()).andReturn(mockBroker);
expect(mockBroker.openCollection(TEST_COLLECTION_URI, READ_LOCK)).andReturn(mockCollection);
expect(mockCollection.getCreated()).andReturn(collectionCreated);
expect(mockCollection.getDocumentWithLock(mockBroker, docUri, READ_LOCK)).andReturn(mockLockedDocument);
expect(mockLockedDocument.getDocument()).andReturn(mockDocument);
// NOTE: checks that Collection lock is release before Document lock
mockCollection.close();
expect(mockDocument.getLastModified()).andReturn(docLastModified);
mockLockedDocument.close();
mockBroker.close();
ctrl.replay();
final Function<Collection, Long> collectionOp = collection -> collection.getCreated();
final Function<DocumentImpl, Long> documentOp = document -> document.getLastModified();
final Tuple2<Long, Long> result = FluentBrokerAPI.builder(mockBrokerPool).withCollection(TEST_COLLECTION_URI, READ_LOCK).execute(collectionOp).withDocument(collection -> new Tuple2<>(docUri, READ_LOCK)).withoutCollection().execute(documentOp).doAll();
assertEquals(collectionCreated, result._1.longValue());
assertEquals(docLastModified, result._2.longValue());
ctrl.verify();
}
Aggregations