Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions exist-core/src/main/java/org/exist/test/DiffMatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private DiffMatcher(final Source expectedSource, final boolean identical) {

/**
* Compares that the XML sources are similar.
*
* <p>
* In this context "similar" is defined by {@link DiffBuilder#checkForSimilar()}.
*
* @param expectedSource the expected XML
Expand All @@ -79,7 +79,7 @@ public static DiffMatcher hasSimilarXml(final Source expectedSource) {

/**
* Compares that the XML sources are identical.
*
* <p>
* In this context "similar" is defined by {@link DiffBuilder#checkForIdentical()} ()}.
*
* @param expectedSource the expected XML
Expand All @@ -101,7 +101,7 @@ public boolean matches(final Object item, final Description mismatch) {
if (item instanceof NodeValue) {
actualItem = (NodeValue) item;

} else if (item instanceof Sequence actual) {
} else if (item instanceof final Sequence actual) {

if (actual.getItemCount() != 1) {
mismatch.appendText("Sequence does not contain 1 item");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public void startDb() throws DatabaseConfigurationException, EXistException, IOE
});

if (useTemporaryStorage) {
if (!temporaryStorage.isPresent()) {
if (temporaryStorage.isEmpty()) {
this.temporaryStorage = Optional.of(Files.createTempDirectory("org.exist.test.ExistEmbeddedServer"));
}
config.setProperty(BrokerPool.PROPERTY_DATA_DIR, temporaryStorage.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
import javax.annotation.Nullable;
import javax.xml.transform.OutputKeys;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Path;
import java.util.Map;
import java.util.Properties;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
Expand Down Expand Up @@ -105,7 +105,8 @@ protected void before() throws Throwable {
super.before();
}

private void startDb() throws ClassNotFoundException, IllegalAccessException, InstantiationException, XMLDBException {
private void startDb() throws ClassNotFoundException, IllegalAccessException, InstantiationException,
XMLDBException, NoSuchMethodException, InvocationTargetException {
try {
existEmbeddedServer.startDb();
} catch (final DatabaseConfigurationException | EXistException | IOException e) {
Expand All @@ -114,11 +115,12 @@ private void startDb() throws ClassNotFoundException, IllegalAccessException, In
startXmldb();
}

private void startXmldb() throws ClassNotFoundException, IllegalAccessException, InstantiationException, XMLDBException {
private void startXmldb() throws ClassNotFoundException, IllegalAccessException, InstantiationException,
XMLDBException, NoSuchMethodException, InvocationTargetException {
if (database == null) {
// initialize driver
final Class<?> cl = Class.forName("org.exist.xmldb.DatabaseImpl");
database = (Database) cl.newInstance();
database = (Database) cl.getDeclaredConstructor().newInstance();
database.setProperty("create-database", "true");
DatabaseManager.registerDatabase(database);
if (asGuest) {
Expand All @@ -132,11 +134,13 @@ private void startXmldb() throws ClassNotFoundException, IllegalAccessException,
}
}

public void restart() throws ClassNotFoundException, InstantiationException, XMLDBException, IllegalAccessException {
public void restart() throws ClassNotFoundException, InstantiationException, XMLDBException, IllegalAccessException,
InvocationTargetException, NoSuchMethodException {
restart(false);
}

public void restart(final boolean clearTemporaryStorage) throws ClassNotFoundException, InstantiationException, XMLDBException, IllegalAccessException {
public void restart(final boolean clearTemporaryStorage) throws ClassNotFoundException, InstantiationException,
XMLDBException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
stopDb(clearTemporaryStorage);
startDb();
}
Expand Down
26 changes: 13 additions & 13 deletions exist-core/src/main/java/org/exist/test/TransactionTestDSL.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@
/**
* A DSL for describing a schedule of
* transaction operations upon the database.
*
* <p>
* A type-safe builder pattern is provided
* for constructing the schedule. Once
* the schedule is build a scheduler
* can execute it upon the database
* and return the results.
*
* <p>
* The DSL uses recursive types
* in a similar way to a typed heterogeneous
* list (such as Shapeless's HList) to ensure
Expand All @@ -74,10 +74,10 @@
* At the cost of complexity in implementing
* the DSL, the recursive typing makes use of
* the DSL by the user much simpler and safer.
*
* <p>
* The recursive type implementation was
* inspired by <a href="https://apocalisp.wordpress.com/2008/10/23/heterogeneous-lists-and-the-limits-of-the-java-type-system/">https://apocalisp.wordpress.com/2008/10/23/heterogeneous-lists-and-the-limits-of-the-java-type-system/</a>.
*
* <p>
* Example usage for creating a schedule of
* two transactions, where each will execute in
* its own thread but operationally linear
Expand Down Expand Up @@ -116,7 +116,7 @@ public interface TransactionTestDSL {

/**
* A Transaction Schedule builder.
*
* <p>
* Enables us to build a schedule of operations to be executed
* within one or more transactions.
*
Expand Down Expand Up @@ -146,7 +146,7 @@ static BiTransactionScheduleBuilderFactory biSchedule() {

/**
* A schedule builder factory for two transactions T1 and T2.
*
* <p>
* Responsible for creating a Schedule Builder which is initialized
* to the first transaction state.
*/
Expand Down Expand Up @@ -462,7 +462,7 @@ U execute(final BrokerPool brokerPool, final ExecutionListener executionListener

/**
* A schedule of two transactions T1 and T2.
*
* <p>
* Which are executed concurrently, each in their
* own thread, but linearly according to the schedule.
*
Expand Down Expand Up @@ -551,7 +551,7 @@ public Tuple2<U1, U2> execute(final BrokerPool brokerPool, final ExecutionListen

/**
* A function which describes an operation on the database with a Transaction.
*
* <p>
* You can think of this as a function <pre>f(T) -&gt; U</pre>
* where the database and transaction are available to the
* function <pre>f</pre>.
Expand Down Expand Up @@ -691,7 +691,7 @@ static <T> TransactionOperation<T, T> abort() {
* Executes this, and then the other Transaction Operation
* on the input type {@code <T>} and returns
* the results as a tuple.
*
* <p>
* e.g. <pre>Tuple2(f(T) -&gt; U, other(T) -&gt; U2)</pre>
*
* @param <U2> thr result of the other operation.
Expand All @@ -707,7 +707,7 @@ default <U2> TransactionOperation<T, Tuple2<U, U2>> with(final TransactionOperat
/**
* Returns a composed function that first applies this function to
* its input, and then applies the {@code after} function to the result.
*
* <p>
* See {@link Function#andThen(Function)}
*
* @param <V> the result of the after operation.
Expand All @@ -723,7 +723,7 @@ default <V> TransactionOperation<T, V> andThen(final TransactionOperation<? supe
/**
* Returns a composed function that first applies the {@code before}
* function to its input, and then applies this function to the result.
*
* <p>
* See {@link Function#compose(Function)}
*
* @param <V> the input type of the before operation.
Expand All @@ -739,7 +739,7 @@ default <V> TransactionOperation<V, U> compose(final TransactionOperation<? supe

/**
* Returns a function that always returns its input argument.
*
* <p>
* See {@link Function#identity()}
*
* @param <T> the result of the identity operation.
Expand All @@ -754,7 +754,7 @@ static <T> TransactionOperation<T, T> identity() {
/**
* A simple extension of {@link CountDownLatch}
* which also provides a name for the latch.
*
* <p>
* Useful for debugging latching ordering in
* transaction schedules.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ protected static Sequence executeQuery(final BrokerPool brokerPool, final Source
}
}

protected static String checkDescription(Object source, String description) {
protected static String checkDescription(final Object source, final String description) {
if (description == null) {
throw new IllegalArgumentException(source + " description is null");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private XPathException errorMapAsXPathException(final MapType errorMap) throws X
final String methodName = matcherAt.group(2);
final String fileName = matcherAt.group(3);
final String lineNumber = matcherAt.group(4);
return new StackTraceElement(declaringClass, methodName, fileName, Integer.valueOf(lineNumber));
return new StackTraceElement(declaringClass, methodName, fileName, Integer.parseInt(lineNumber));
} else {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,14 @@ private static XMLTestInfo extractTestInfo(final Path path, final Document doc)
}

private String getSuiteName() {
return "xmlts." + info.getName();
return "xmlts." + info.name();
}

@Override
public Description getDescription() {
final String suiteName = checkDescription(info, getSuiteName());
final Description description = Description.createSuiteDescription(suiteName);
for (final String childName : info.getChildNames()) {
for (final String childName : info.childNames()) {
description.addChild(Description.createTestDescription(suiteName, checkDescription(info, childName)));
}
return description;
Expand Down Expand Up @@ -225,29 +225,6 @@ private static Document parse(final Path path) throws ParserConfigurationExcepti
return adapter.getDocument();
}

private static class XMLTestInfo {
@Nullable private final String name;
@Nullable private final String description;
private final List<String> childNames;

private XMLTestInfo(@Nullable final String name, @Nullable final String description, final List<String> childNames) {
this.name = name;
this.description = description;
this.childNames = childNames;
}

@Nullable
public String getName() {
return name;
}

@Nullable
public String getDescription() {
return description;
}

public List<String> getChildNames() {
return childNames;
}
private record XMLTestInfo(@Nullable String name, @Nullable String description, List<String> childNames) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ private static XQueryTestInfo extractTestInfo(final Path path) throws Initializa
}

private String getSuiteName() {
if (info.getNamespace() == null) {
if (info.namespace() == null) {
return path.getFileName().toString();
}

return namespaceToPackageName(info.getNamespace());
return namespaceToPackageName(info.namespace());
}

private String namespaceToPackageName(final String namespace) {
Expand Down Expand Up @@ -220,8 +220,8 @@ private void pathToPackageName(String path, final StringBuilder buffer) {
public Description getDescription() {
final String suiteName = checkDescription(this, getSuiteName());
final Description description = Description.createSuiteDescription(suiteName);
for (final XQueryTestInfo.TestFunctionDef testFunctionDef : info.getTestFunctions()) {
description.addChild(Description.createTestDescription(suiteName, checkDescription(testFunctionDef, testFunctionDef.getLocalName())));
for (final XQueryTestInfo.TestFunctionDef testFunctionDef : info.testFunctions()) {
description.addChild(Description.createTestDescription(suiteName, checkDescription(testFunctionDef, testFunctionDef.localName())));
}
return description;
}
Expand Down Expand Up @@ -257,45 +257,9 @@ public void run(final RunNotifier notifier) {
}
}

private static class XQueryTestInfo {
private final String prefix;
private final String namespace;
private final List<TestFunctionDef> testFunctions;
private record XQueryTestInfo(String prefix, String namespace, List<TestFunctionDef> testFunctions) {

private XQueryTestInfo(final String prefix, final String namespace, final List<TestFunctionDef> testFunctions) {
this.prefix = prefix;
this.namespace = namespace;
this.testFunctions = testFunctions;
}

public String getPrefix() {
return prefix;
}

public String getNamespace() {
return namespace;
}

public List<TestFunctionDef> getTestFunctions() {
return testFunctions;
}

private static class TestFunctionDef {
private final String localName;
private final int arity;

private TestFunctionDef(final String localName, final int arity) {
this.localName = localName;
this.arity = arity;
}

public String getLocalName() {
return localName;
}

public int getArity() {
return arity;
private record TestFunctionDef(String localName, int arity) {
}
}
}
}
9 changes: 4 additions & 5 deletions exist-core/src/main/java/org/exist/test/runner/XSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,15 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* Using <code>XSuite</code> as a runner allows you to manually
* build a suite containing tests from both:
*
* <p>
* 1. XQSuite - as defined in $EXIST_HOME/src/org/exist/xquery/lib/xqsuite/xqsuite.xql
* 2. XML Test - as defined in $EXIST_HOME/src/org/exist/xquery/lib/test.xq
*
* <p>
* To use it, annotate a class
* with <code>@RunWith(XSuite.class)</code> and <code>@XSuiteClasses({"extensions/my-extension/src/test/xquery", ...})</code>.
* When you run this class, it will run all the tests in all the suite classes.
Expand All @@ -67,7 +66,7 @@ public class XSuite extends ParentRunner<Runner> {
public static Runner emptySuite() {
try {
return new XSuite((Class<?>) null, new String[0]);
} catch (InitializationError e) {
} catch (final InitializationError e) {
throw new RuntimeException("This shouldn't be possible");
}
}
Expand Down Expand Up @@ -204,7 +203,7 @@ private static List<Runner> getRunners(final String[] suites, final boolean para
if (Files.isDirectory(path)) {
// directory of files of test(s)
try (final Stream<Path> children = Files.list(path)) {
for(final Path child : children.collect(Collectors.toList())) {
for(final Path child : children.toList()) {
if(!Files.isDirectory(child)) {
final Runner runner = getRunner(child, parallel);
if(runner != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.xmldb.api.base.XMLDBException;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

/**
* Security Manager round trip tests against the XML:DB Local API
Expand All @@ -49,7 +50,8 @@ protected Collection getRoot() {
protected void restartServer() throws XMLDBException, IOException {
try {
existXmldbEmbeddedServer.restart();
} catch (final ClassNotFoundException | InstantiationException | IllegalAccessException e) {
} catch (final ClassNotFoundException | InstantiationException | IllegalAccessException |
InvocationTargetException | NoSuchMethodException e) {
Comment on lines +53 to +54
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One could use the parent ReflectiveOperationException instead those existing ones

throw new XMLDBException(ErrorCodes.UNKNOWN_ERROR, e);
}
}
Expand Down
Loading