use of org.exist.storage.DBBroker in project exist by eXist-db.
the class AbstractGroupTest method addManagerWithString_calls_assertCanModifyGroup.
@Test
public void addManagerWithString_calls_assertCanModifyGroup() throws PermissionDeniedException, NoSuchMethodException {
DBBroker mockBroker = EasyMock.createMock(DBBroker.class);
AbstractRealm mockRealm = EasyMock.createNiceMock(AbstractRealm.class);
Subject mockSubject = EasyMock.createMock(Subject.class);
Database mockDatabase = EasyMock.createMock(Database.class);
AbstractGroup partialMockGroup = EasyMock.createMockBuilder(AbstractGroup.class).withConstructor(DBBroker.class, AbstractRealm.class, int.class, String.class, List.class).withArgs(mockBroker, mockRealm, 1, "testGroup", null).addMockedMethod("assertCanModifyGroup", Account.class).addMockedMethod(AbstractGroup.class.getDeclaredMethod("_addManager", Account.class)).createNiceMock();
// expectations
expect(mockRealm.getDatabase()).andReturn(mockDatabase);
expect(mockDatabase.getActiveBroker()).andReturn(mockBroker);
expect(mockBroker.getCurrentSubject()).andReturn(mockSubject);
partialMockGroup.assertCanModifyGroup(mockSubject);
replay(mockRealm, mockDatabase, mockBroker, partialMockGroup);
// test
partialMockGroup.addManager((String) null);
verify(mockRealm, mockDatabase, mockBroker, partialMockGroup);
}
use of org.exist.storage.DBBroker in project exist by eXist-db.
the class AbstractAccountTest method assertCanModifyAccount_fails_when_user_is_null.
@Test(expected = PermissionDeniedException.class)
public void assertCanModifyAccount_fails_when_user_is_null() throws PermissionDeniedException, ConfigurationException {
DBBroker mockBroker = EasyMock.createMock(DBBroker.class);
AbstractRealm mockRealm = EasyMock.createMock(AbstractRealm.class);
TestableAbstractAccount account = new TestableAbstractAccount(mockBroker, mockRealm, 1, "testAccount");
account.assertCanModifyAccount(null);
}
use of org.exist.storage.DBBroker in project exist by eXist-db.
the class AbstractAccountTest method assertCanModifyAccount_fails_when_user_is_not_same.
@Test(expected = PermissionDeniedException.class)
public void assertCanModifyAccount_fails_when_user_is_not_same() throws PermissionDeniedException, ConfigurationException {
DBBroker mockBroker = EasyMock.createMock(DBBroker.class);
AbstractRealm mockRealm = EasyMock.createMock(AbstractRealm.class);
Account mockAccount = EasyMock.createMock(Account.class);
TestableAbstractAccount account = new TestableAbstractAccount(mockBroker, mockRealm, 1, "testAccount");
// expectations
expect(mockAccount.hasDbaRole()).andReturn(Boolean.FALSE);
expect(mockAccount.getName()).andReturn("otherAccount").times(2);
replay(mockAccount);
// test
account.assertCanModifyAccount(mockAccount);
verify(mockAccount);
}
use of org.exist.storage.DBBroker in project exist by eXist-db.
the class NodeTest method attributeAxis.
@Test
public void attributeAxis() 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)) {
Element docElement = lockedDoc.getDocument().getDocumentElement();
Element first = (Element) docElement.getFirstChild();
assertEquals("a", first.getNodeName());
assertEquals("1", first.getAttribute("ns:a"));
assertEquals("1", first.getAttributeNS("http://foo.org", "a"));
Attr attr = first.getAttributeNode("ns:a");
assertNotNull(attr);
assertEquals("a", attr.getLocalName());
assertEquals("http://foo.org", attr.getNamespaceURI());
assertEquals("1", attr.getValue());
Node parent = attr.getOwnerElement();
assertNotNull(parent);
assertEquals("a", parent.getNodeName());
parent = attr.getParentNode();
assertNull(parent);
attr = first.getAttributeNodeNS("http://foo.org", "a");
assertNotNull(attr);
assertEquals("a", attr.getLocalName());
assertEquals("http://foo.org", attr.getNamespaceURI());
assertEquals("1", attr.getValue());
NamedNodeMap map = first.getAttributes();
assertEquals(2, map.getLength());
attr = (Attr) map.getNamedItemNS("http://foo.org", "b");
assertNotNull(attr);
assertEquals("b", attr.getLocalName());
assertEquals("http://foo.org", attr.getNamespaceURI());
assertEquals("m", attr.getValue());
}
}
use of org.exist.storage.DBBroker in project exist by eXist-db.
the class NodeTest method setUp.
@BeforeClass
public static void setUp() throws Exception {
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.saveCollection(transaction, root);
broker.storeDocument(transaction, XmldbURI.create("test.xml"), new StringInputSource(XML), MimeType.XML_TYPE, root);
transact.commit(transaction);
}
}
Aggregations