Skip to content

Commit

Permalink
chore: resolve test issues
Browse files Browse the repository at this point in the history
  • Loading branch information
marmoure committed May 4, 2023
1 parent b54a1a5 commit 0da7071
Showing 1 changed file with 31 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.exist.indexing;

import org.exist.EXistException;
import org.exist.TestUtils;
import org.exist.collections.Collection;
import org.exist.collections.CollectionConfigurationException;
import org.exist.collections.CollectionConfigurationManager;
Expand All @@ -23,7 +22,6 @@
import org.exist.xquery.XPathException;
import org.exist.xquery.XQuery;
import org.exist.xquery.XQueryContext;
import org.exist.xquery.value.Item;
import org.exist.xquery.value.Sequence;
import org.junit.*;
import org.xml.sax.SAXException;
Expand Down Expand Up @@ -65,14 +63,8 @@ public class EnforceIndexUseTest {
" <foo bar=\"baz\"/>\n" +
"</root>";

private Collection test = null;

@Test
public void matchesWithDiffrentIndexStyles() throws CollectionConfigurationException, LockException, IOException, SAXException, PermissionDeniedException, EXistException, XPathException {
// store the xml data and configure it
configureAndStore(NEW_RANGE_COLLECTION_CONFIG, XML, "test.xml", "/new-range-index");
configureAndStore(OLD_RANGE_COLLECTION_CONFIG, XML, "test.xml", "/old-range-index");
configureAndStore(null, XML, "test.xml", "/no-range-index");

//query and expand
final String query = "for $hit in collection(\"" + TestConstants.TEST_COLLECTION_URI.toString() + "\")//foo[matches(@bar, \"^b\")]\n" +
Expand Down Expand Up @@ -101,7 +93,7 @@ private DocumentSet configureAndStore(final String configuration, final String d
broker.storeDocument(transaction, XmldbURI.create(docName), new StringInputSource(data), MimeType.XML_TYPE, collection);

docs.add(collection.getDocument(broker, XmldbURI.create(docName)));
transact.commit(transaction);
transaction.commit();
} catch (URISyntaxException e) {
throw new RuntimeException(e);

Check warning on line 98 in extensions/indexes/indexes-integration-tests/src/test/java/org/exist/indexing/EnforceIndexUseTest.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

extensions/indexes/indexes-integration-tests/src/test/java/org/exist/indexing/EnforceIndexUseTest.java#L98

Avoid throwing raw exception types.
}
Expand All @@ -110,23 +102,36 @@ private DocumentSet configureAndStore(final String configuration, final String d
}

@Before
public void setup() throws EXistException, PermissionDeniedException, IOException, TriggerException {
public void setup() throws PermissionDeniedException, IOException, SAXException{
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()) {

test = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
Collection newRange = broker.getOrCreateCollection(transaction, XmldbURI.xmldbUriFor(TestConstants.TEST_COLLECTION_URI + "new-range-index"));
Collection oldRange = broker.getOrCreateCollection(transaction, XmldbURI.xmldbUriFor(TestConstants.TEST_COLLECTION_URI + "old-range-index"));
Collection noRange = broker.getOrCreateCollection(transaction, XmldbURI.xmldbUriFor(TestConstants.TEST_COLLECTION_URI + "no-range-index"));
broker.saveCollection(transaction, test);
broker.saveCollection(transaction, newRange);
broker.saveCollection(transaction, oldRange);
broker.saveCollection(transaction, noRange);
try(Collection test = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
Collection newRange = broker.getOrCreateCollection(transaction, XmldbURI.xmldbUriFor(TestConstants.TEST_COLLECTION_URI + "new-range-index"));
Collection oldRange = broker.getOrCreateCollection(transaction, XmldbURI.xmldbUriFor(TestConstants.TEST_COLLECTION_URI + "old-range-index"));
Collection noRange = broker.getOrCreateCollection(transaction, XmldbURI.xmldbUriFor(TestConstants.TEST_COLLECTION_URI + "no-range-index"))){

broker.saveCollection(transaction, newRange);
broker.saveCollection(transaction, test);
broker.saveCollection(transaction, oldRange);
broker.saveCollection(transaction, noRange);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}

transact.commit(transaction);
} catch (URISyntaxException e) {
transaction.commit();
} catch (EXistException e) {
throw new RuntimeException(e);
}

// store the xml data and configure it
try {
configureAndStore(NEW_RANGE_COLLECTION_CONFIG, XML, "test.xml", "/new-range-index");
configureAndStore(OLD_RANGE_COLLECTION_CONFIG, XML, "test.xml", "/old-range-index");
configureAndStore(null, XML, "test.xml", "/no-range-index");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Expand All @@ -141,16 +146,13 @@ public void cleanup() throws EXistException, PermissionDeniedException, IOExcept
final Collection collConfig = broker.getOrCreateCollection(transaction,
XmldbURI.create(XmldbURI.CONFIG_COLLECTION + "/db"));
broker.removeCollection(transaction, collConfig);

if (test != null) {
broker.removeCollection(transaction, test);
try(Collection test = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI)) {
if (test != null) {
broker.removeCollection(transaction, test);
}
}
transact.commit(transaction);
}
}

@AfterClass
public static void cleanupDb() throws LockException, TriggerException, PermissionDeniedException, EXistException, IOException {
TestUtils.cleanupDB();
transaction.commit();
}
}
}

0 comments on commit 0da7071

Please sign in to comment.