use of com.evolvedbinary.j8fu.tuple.Tuple3 in project exist by eXist-db.
the class MoveOverwriteCollectionTest method store.
private Tuple3<Collection, Collection, Collection> store(final DBBroker broker) throws Exception {
try (final Txn transaction = broker.getBrokerPool().getTransactionManager().beginTransaction()) {
final Collection test1 = createCollection(transaction, broker, TEST_COLLECTION_URI);
final Collection test2 = createCollection(transaction, broker, SUB_TEST_COLLECTION_URI);
final Collection test3 = createCollection(transaction, broker, TEST3_COLLECTION_URI);
broker.storeDocument(transaction, doc1Name, new StringInputSource(XML1), MimeType.XML_TYPE, test1);
broker.storeDocument(transaction, doc2Name, new StringInputSource(XML2), MimeType.XML_TYPE, test2);
broker.storeDocument(transaction, doc3Name, new StringInputSource(XML3), MimeType.XML_TYPE, test3);
transaction.commit();
return new Tuple3<>(test1, test2, test3);
}
}
use of com.evolvedbinary.j8fu.tuple.Tuple3 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();
}
Aggregations