use of org.exist.storage.DBBroker in project exist by eXist-db.
the class TransformTest method xslDocument.
@Ignore("https://github.com/eXist-db/exist/issues/2096")
@Test
public void xslDocument() throws EXistException, PermissionDeniedException, XPathException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
final XQuery xquery = pool.getXQueryService();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
final Sequence sequence = xquery.execute(broker, DOCUMENT_XSLT_QUERY, null);
assertNotNull(sequence);
assertTrue(sequence.hasOne());
final Item item = sequence.itemAt(0);
assertEquals(Type.DOCUMENT, item.getType());
final Source expected = Input.fromString("<elem1/>").build();
final Source actual = Input.fromDocument(sequence.itemAt(0).toJavaObject(Document.class)).build();
final Diff diff = DiffBuilder.compare(actual).withTest(expected).checkForSimilar().build();
assertFalse(diff.toString(), diff.hasDifferences());
}
}
use of org.exist.storage.DBBroker in project exist by eXist-db.
the class GroupMembershipFunctionRemoveGroupMemberTest method setup.
@Before
public void setup() throws EXistException, PermissionDeniedException, XPathException {
final BrokerPool pool = existWebServer.getBrokerPool();
final SecurityManager sm = pool.getSecurityManager();
// create user with personal group as primary group
try (final DBBroker broker = pool.get(Optional.of(sm.getSystemSubject()));
final Txn transaction = pool.getTransactionManager().beginTransaction()) {
final Account user1 = createUser(broker, sm, USER1_NAME, USER1_PWD);
final Group otherGroup1 = createGroup(broker, sm, OTHER_GROUP1_NAME);
addUserToGroup(sm, user1, otherGroup1);
addUserAsGroupManager(USER1_NAME, OTHER_GROUP1_NAME);
final Group otherGroup2 = createGroup(broker, sm, OTHER_GROUP2_NAME);
addUserToGroup(sm, user1, otherGroup2);
addUserAsGroupManager(USER1_NAME, OTHER_GROUP2_NAME);
transaction.commit();
}
// check that the user is as we expect
try (final DBBroker broker = pool.get(Optional.of(sm.getSystemSubject()));
final Txn transaction = pool.getTransactionManager().beginTransaction()) {
final Account user1 = sm.getAccount(USER1_NAME);
assertEquals(USER1_NAME, user1.getPrimaryGroup());
final String[] user1Groups = user1.getGroups();
assertArrayEquals(new String[] { USER1_NAME, OTHER_GROUP1_NAME, OTHER_GROUP2_NAME }, user1Groups);
for (final String user1Group : user1Groups) {
assertNotNull(sm.getGroup(user1Group));
}
transaction.commit();
}
}
use of org.exist.storage.DBBroker in project exist by eXist-db.
the class PermissionsFunctionChmodTest method cleanupDb.
@AfterClass
public static void cleanupDb() throws EXistException, PermissionDeniedException, IOException, TriggerException {
final BrokerPool pool = existWebServer.getBrokerPool();
final SecurityManager sm = pool.getSecurityManager();
try (final DBBroker broker = pool.get(Optional.of(sm.getSystemSubject()));
final Txn transaction = pool.getTransactionManager().beginTransaction()) {
removeUser(sm, USER2_NAME);
removeUser(sm, USER1_NAME);
removeCollection(broker, transaction, TestConstants.TEST_COLLECTION_URI);
transaction.commit();
}
}
use of org.exist.storage.DBBroker in project exist by eXist-db.
the class AccountManagementFunctionRemoveAccountTest method xqueryRemoveAccount.
private Sequence xqueryRemoveAccount(final String username, final Optional<Subject> asUser) throws EXistException, PermissionDeniedException, XPathException {
final BrokerPool pool = existWebServer.getBrokerPool();
final String query = "import module namespace sm = 'http://exist-db.org/xquery/securitymanager';\n" + "sm:remove-account('" + username + "')";
try (final DBBroker broker = pool.get(asUser)) {
final XQuery xquery = existWebServer.getBrokerPool().getXQueryService();
final Sequence result = xquery.execute(broker, query, null);
return result;
}
}
use of org.exist.storage.DBBroker in project exist by eXist-db.
the class ParseHtmlTest method parseHtml.
@Test
public void parseHtml() throws EXistException, PermissionDeniedException, XPathException {
final String query = "util:parse-html(\"<p>hello <img src='1.jpg'></p>\")";
final XQuery xquery = server.getBrokerPool().getXQueryService();
try (final DBBroker broker = server.getBrokerPool().getBroker()) {
final Sequence result = xquery.execute(broker, query, null);
assertEquals(1, result.getItemCount());
assertTrue(result.itemAt(0) instanceof DocumentImpl);
final Source expected = Input.fromString("<?xml version=\"1.0\" encoding=\"UTF-8\"?><HTML><head xmlns=\"http://www.w3.org/1999/xhtml\"/><BODY><p>hello <img src=\"1.jpg\"/></p></BODY></HTML>").build();
final Source actual = Input.fromDocument((DocumentImpl) result.itemAt(0)).build();
final Diff diff = DiffBuilder.compare(expected).withTest(actual).checkForIdentical().build();
assertFalse(diff.toString(), diff.hasDifferences());
}
}
Aggregations