Search in sources :

Example 11 with DBBroker

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);
}
Also used : DBBroker(org.exist.storage.DBBroker) Database(org.exist.Database) Test(org.junit.Test)

Example 12 with DBBroker

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);
}
Also used : DBBroker(org.exist.storage.DBBroker) Test(org.junit.Test)

Example 13 with DBBroker

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);
}
Also used : DBBroker(org.exist.storage.DBBroker) Test(org.junit.Test)

Example 14 with DBBroker

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());
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) BrokerPool(org.exist.storage.BrokerPool)

Example 15 with DBBroker

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);
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) StringInputSource(org.exist.util.StringInputSource) TransactionManager(org.exist.storage.txn.TransactionManager) Txn(org.exist.storage.txn.Txn) BrokerPool(org.exist.storage.BrokerPool)

Aggregations

DBBroker (org.exist.storage.DBBroker)468 BrokerPool (org.exist.storage.BrokerPool)304 Txn (org.exist.storage.txn.Txn)219 Sequence (org.exist.xquery.value.Sequence)185 Test (org.junit.Test)170 XQuery (org.exist.xquery.XQuery)108 Collection (org.exist.collections.Collection)93 TransactionManager (org.exist.storage.txn.TransactionManager)70 EXistException (org.exist.EXistException)66 StringInputSource (org.exist.util.StringInputSource)66 PermissionDeniedException (org.exist.security.PermissionDeniedException)44 Source (org.exist.source.Source)42 StringSource (org.exist.source.StringSource)41 XmldbURI (org.exist.xmldb.XmldbURI)41 CompiledXQuery (org.exist.xquery.CompiledXQuery)39 IOException (java.io.IOException)38 QName (org.exist.dom.QName)37 LockedDocument (org.exist.dom.persistent.LockedDocument)36 Database (org.exist.Database)35 XPathException (org.exist.xquery.XPathException)30