use of org.exist.storage.DBBroker in project exist by eXist-db.
the class NodeTest method tearDown.
@AfterClass
public static void tearDown() throws EXistException, PermissionDeniedException, IOException, TriggerException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
final TransactionManager transact = pool.getTransactionManager();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final Txn transaction = transact.beginTransaction()) {
root = broker.getOrCreateCollection(transaction, XmldbURI.create(XmldbURI.ROOT_COLLECTION + "/test"));
assertNotNull(root);
broker.removeCollection(transaction, root);
transact.commit(transaction);
}
}
use of org.exist.storage.DBBroker in project exist by eXist-db.
the class NodeTest method document.
@Test
public void document() throws EXistException, LockException, PermissionDeniedException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final LockedDocument lockedDoc = root.getDocumentWithLock(broker, XmldbURI.create("test.xml"), LockMode.READ_LOCK)) {
final NodeList children = lockedDoc.getDocument().getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
final IStoredNode node = (IStoredNode<?>) children.item(i);
node.getNodeId();
node.getNodeName();
}
}
}
use of org.exist.storage.DBBroker in project exist by eXist-db.
the class AuditTrailSessionListenerTest method sessionDestroyed.
/**
* Ensures that AuditTrailSessionListener releases any locks
* on the XQuery document when destroying a session
*/
@Test
public void sessionDestroyed() throws EXistException, PermissionDeniedException {
final HttpSessionEvent httpSessionEvent = createMock(HttpSessionEvent.class);
final HttpSession httpSession = createMock(HttpSession.class);
expect(httpSessionEvent.getSession()).andReturn(httpSession);
expect(httpSession.getId()).andReturn("mock-session");
replay(httpSessionEvent, httpSession);
final AuditTrailSessionListener listener = new AuditTrailSessionListener();
listener.sessionDestroyed(httpSessionEvent);
verify(httpSessionEvent, httpSession);
final XmldbURI docUri = XmldbURI.create(DESTROYED_SCRIPT_PATH);
try (final DBBroker broker = existEmbeddedServer.getBrokerPool().getBroker();
final LockedDocument lockedResource = broker.getXMLResource(docUri, Lock.LockMode.NO_LOCK)) {
// ensure that AuditTrailSessionListener released the lock
final LockManager lockManager = broker.getBrokerPool().getLockManager();
assertFalse(lockManager.isDocumentLockedForRead(docUri));
assertFalse(lockManager.isDocumentLockedForWrite(docUri));
}
}
use of org.exist.storage.DBBroker in project exist by eXist-db.
the class AuditTrailSessionListenerTest method sessionCreated.
/**
* Ensures that AuditTrailSessionListener releases any locks
* on the XQuery document when creating a session
*/
@Test
public void sessionCreated() throws EXistException, PermissionDeniedException {
final HttpSessionEvent httpSessionEvent = createMock(HttpSessionEvent.class);
final HttpSession httpSession = createMock(HttpSession.class);
expect(httpSessionEvent.getSession()).andReturn(httpSession);
expect(httpSession.getId()).andReturn("mock-session");
replay(httpSessionEvent, httpSession);
final AuditTrailSessionListener listener = new AuditTrailSessionListener();
listener.sessionCreated(httpSessionEvent);
verify(httpSessionEvent, httpSession);
final XmldbURI docUri = XmldbURI.create(CREATE_SCRIPT_PATH);
try (final DBBroker broker = existEmbeddedServer.getBrokerPool().getBroker();
final LockedDocument lockedResource = broker.getXMLResource(docUri, Lock.LockMode.NO_LOCK)) {
// ensure that AuditTrailSessionListener released the lock
final LockManager lockManager = broker.getBrokerPool().getLockManager();
assertFalse(lockManager.isDocumentLockedForRead(docUri));
assertFalse(lockManager.isDocumentLockedForWrite(docUri));
}
}
use of org.exist.storage.DBBroker in project exist by eXist-db.
the class AbstractRealmTest method updateGroup_calls_assertCanModifyGroup.
/*
@Test
public void updateAccount_calls_assertCanModifyAccount() throws PermissionDeniedException, EXistException {
SecurityManager mockSecurityManager = EasyMock.createMock(SecurityManager.class);
Configuration mockConfiguration = EasyMock.createMock(Configuration.class);
Database mockDatabase = EasyMock.createMock(Database.class);
Subject mockSubject = EasyMock.createMock(Subject.class);
Account mockAccount = EasyMock.createMockBuilder(AbstractAccount.class)
.addMockedMethod("getName", new Class[0])
.addMockedMethod("getGroups", new Class[0])
.addMockedMethod("assertCanModifyAccount", new Class[]{Account.class})
.addMockedMethod("getRealm", new Class[0])
.createNiceMock();
final String accountName = "someAccount";
AbstractRealm mockRealm = EasyMock
.createMockBuilder(AbstractRealm.class)
.withConstructor(SecurityManager.class, Configuration.class)
.withArgs(mockSecurityManager, mockConfiguration)
.addMockedMethod("getDatabase", new Class[0])
.addMockedMethod("getAccount", new Class[]{Subject.class, String.class})
.createNiceMock();
Account mockUpdatingAccount = EasyMock.createMock(Account.class);
//expectations
expect(mockRealm.getDatabase()).andReturn(mockDatabase);
expect(mockDatabase.getCurrentSubject()).andReturn(mockSubject);
mockAccount.assertCanModifyAccount(mockSubject);
expect(mockAccount.getName()).andReturn(accountName);
expect(mockRealm.getAccount(null, accountName)).andReturn(mockUpdatingAccount);
expect(mockAccount.getGroups()).andReturn(new String[0]);
expect(mockUpdatingAccount.getGroups()).andReturn(new String[0]);
replay(mockRealm, mockDatabase, mockSubject, mockUpdatingAccount, mockAccount);
mockRealm.updateAccount(null, mockAccount);
verify(mockRealm, mockDatabase, mockSubject, mockUpdatingAccount, mockAccount);
} */
@Test
public void updateGroup_calls_assertCanModifyGroup() throws PermissionDeniedException, EXistException {
SecurityManager mockSecurityManager = EasyMock.createMock(SecurityManager.class);
Configuration mockConfiguration = EasyMock.createMock(Configuration.class);
Database mockDatabase = EasyMock.createMock(Database.class);
DBBroker mockBroker = EasyMock.createMock(DBBroker.class);
Subject mockSubject = EasyMock.createMock(Subject.class);
Group mockGroup = EasyMock.createMockBuilder(AbstractGroup.class).addMockedMethod("getName", new Class[0]).addMockedMethod("getManagers", new Class[0]).addMockedMethod("assertCanModifyGroup", new Class[] { Account.class }).addMockedMethod("getMetadataKeys", new Class[0]).createNiceMock();
final String groupName = "someGroup";
AbstractRealm mockRealm = EasyMock.createMockBuilder(AbstractRealm.class).withConstructor(SecurityManager.class, Configuration.class).withArgs(mockSecurityManager, mockConfiguration).addMockedMethod("getDatabase", new Class[0]).addMockedMethod("getGroup", new Class[] { String.class }).createNiceMock();
Group mockUpdatingGroup = EasyMock.createNiceMock(Group.class);
// expectations
expect(mockRealm.getDatabase()).andReturn(mockDatabase);
expect(mockDatabase.getActiveBroker()).andReturn(mockBroker);
expect(mockBroker.getCurrentSubject()).andReturn(mockSubject);
mockGroup.assertCanModifyGroup(mockSubject);
expect(mockGroup.getName()).andReturn(groupName);
expect(mockRealm.getGroup(groupName)).andReturn(mockUpdatingGroup);
expect(mockGroup.getManagers()).andReturn(Collections.emptyList());
expect(mockUpdatingGroup.getManagers()).andReturn(Collections.emptyList());
expect(mockGroup.getMetadataKeys()).andReturn(Collections.emptySet());
mockGroup.save();
replay(mockRealm, mockDatabase, mockBroker, mockGroup, mockSubject, mockUpdatingGroup);
mockRealm.updateGroup(mockGroup);
verify(mockRealm, mockDatabase, mockBroker, mockGroup, mockSubject, mockUpdatingGroup);
}
Aggregations