use of org.exist.storage.txn.Txn in project exist by eXist-db.
the class TransformTest method cleanupResources.
@AfterClass
public static void cleanupResources() throws EXistException, PermissionDeniedException, IOException, TriggerException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final Txn transaction = pool.getTransactionManager().beginTransaction()) {
deleteCollection(broker, transaction, TEST_IDS_COLLECTION);
deleteCollection(broker, transaction, TEST_DOCUMENT_XSLT_COLLECTION);
deleteCollection(broker, transaction, TEST_SIMPLE_XML_COLLECTION);
deleteCollection(broker, transaction, TEST_SIMPLE_XML_WITH_COMMENT_COLLECTION);
deleteCollection(broker, transaction, TEST_SIMPLE_XML_WITH_TWO_COMMENTS_COLLECTION);
deleteCollection(broker, transaction, TEST_TWO_NODES_COLLECTION);
transaction.commit();
}
}
use of org.exist.storage.txn.Txn in project exist by eXist-db.
the class TransformTest method storeResources.
@BeforeClass
public static void storeResources() throws EXistException, PermissionDeniedException, IOException, SAXException, LockException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final Txn transaction = pool.getTransactionManager().beginTransaction()) {
createCollection(broker, transaction, TEST_IDS_COLLECTION, Tuple(LIST_OPS_XSLT_NAME, LIST_OPS_XSLT), Tuple(INPUT_LIST_XML_NAME, INPUT_XML), Tuple(DICTIONARY_XML_NAME, DICTIONARY_XML));
createCollection(broker, transaction, TEST_DOCUMENT_XSLT_COLLECTION, Tuple(DOCUMENT_XSLT_NAME, DOCUMENT_XSLT));
createCollection(broker, transaction, TEST_SIMPLE_XML_COLLECTION, Tuple(SIMPLE_XML_NAME, SIMPLE_XML), Tuple(COUNT_DESCENDANTS_XSLT_NAME, getCountDescendantsXslt(TEST_SIMPLE_XML_COLLECTION)));
createCollection(broker, transaction, TEST_SIMPLE_XML_WITH_COMMENT_COLLECTION, Tuple(SIMPLE_XML_NAME, SIMPLE_XML_WITH_COMMENT), Tuple(COUNT_DESCENDANTS_XSLT_NAME, getCountDescendantsXslt(TEST_SIMPLE_XML_WITH_COMMENT_COLLECTION)));
createCollection(broker, transaction, TEST_SIMPLE_XML_WITH_TWO_COMMENTS_COLLECTION, Tuple(SIMPLE_XML_NAME, SIMPLE_XML_WITH_TWO_COMMENTS), Tuple(COUNT_DESCENDANTS_XSLT_NAME, getCountDescendantsXslt(TEST_SIMPLE_XML_WITH_TWO_COMMENTS_COLLECTION)));
createCollection(broker, transaction, TEST_TWO_NODES_COLLECTION, Tuple(TWO_NODES_XML_NAME, TWO_NODES_XML), Tuple(COUNT_DESCENDANTS_TWO_NODES_XSLT_NAME, COUNT_DESCENDANTS_TWO_NODES_XSLT));
transaction.commit();
}
}
use of org.exist.storage.txn.Txn 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.txn.Txn 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.txn.Txn in project exist by eXist-db.
the class SendEmailIT method sendEmailJavaMail.
@Test
public void sendEmailJavaMail() throws EXistException, XPathException, PermissionDeniedException, IOException, MessagingException {
final String from = "sender@place1.com";
final String to = "recipient@place2.com";
final String subject = "some email subject";
final String messageText = UUIDGenerator.getUUIDversion4();
final String query = "import module namespace mail = \"http://exist-db.org/xquery/mail\";\n" + "let $session := mail:get-mail-session(\n" + " <properties>\n" + " <property name=\"mail.transport.protocol\" value=\"smtp\"/>\n" + " <property name=\"mail.smtp.port\" value=\"" + smtpPort + "\"/>\n" + " <property name=\"mail.smtp.host\" value=\"127.0.0.1\"/>\n" + " </properties>\n" + ")\n" + "return\n" + " mail:send-email(\n" + " $session,\n" + " <mail><from>" + from + "</from><to>" + to + "</to><subject>" + subject + "</subject><message><text>" + messageText + "</text></message></mail>\n" + " )";
// send the email from XQuery via SMTP
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
final Source source = new StringSource(query);
try (final DBBroker broker = pool.getBroker();
final Txn transaction = pool.getTransactionManager().beginTransaction()) {
// execute query
final Boolean sendResult = withCompiledQuery(broker, source, compiledXQuery -> {
executeQuery(broker, compiledXQuery);
return true;
});
transaction.commit();
assertTrue(sendResult.booleanValue());
}
// check the SMTP server received the email
final MimeMessage[] receivedMessages = greenMail.getReceivedMessages();
assertEquals(1, receivedMessages.length);
final MimeMessage receivedMessage = receivedMessages[0];
// final Address sender = receivedMessage.getSender();
// assertEquals(from, sender.toString());
final Address[] recipients = receivedMessage.getRecipients(Message.RecipientType.TO);
assertEquals(1, recipients.length);
assertEquals(to, recipients[0].toString());
assertEquals(subject, receivedMessage.getSubject());
assertEquals(messageText, GreenMailUtil.getBody(receivedMessage));
}
Aggregations