Skip to content

Commit cff6e20

Browse files
committed
[bugfix] Allow XSuite to use an EXPath Repo when examining XQSuite tests in XQueryTestRunner#extractTestInfo
1 parent d228a37 commit cff6e20

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

exist-core/src/main/java/org/exist/repo/ExistRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public void configure(final Configuration configuration) throws BrokerPoolServic
8787

8888
@Override
8989
public void prepare(final BrokerPool brokerPool) throws BrokerPoolServiceException {
90-
if(!Files.exists(expathDir)) {
90+
if (!Files.exists(expathDir) && brokerPool != null) {
9191
moveOldRepo(brokerPool.getConfiguration().getExistHome(), expathDir);
9292
}
9393
try {

exist-core/src/main/java/org/exist/storage/BrokerPool.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ private void _initialize() throws EXistException, DatabaseConfigurationException
506506

507507
this.symbols = servicesManager.register(new SymbolTable());
508508

509-
this.expathRepo = Optional.ofNullable(new ExistRepository());
509+
this.expathRepo = Optional.of(new ExistRepository());
510510
expathRepo.ifPresent(servicesManager::register);
511511
servicesManager.register(new ClasspathHelper());
512512

exist-core/src/main/java/org/exist/test/runner/XQueryTestRunner.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@
2525
import com.evolvedbinary.j8fu.tuple.Tuple2;
2626
import org.exist.EXistException;
2727
import org.exist.dom.QName;
28+
import org.exist.repo.ExistRepository;
2829
import org.exist.security.PermissionDeniedException;
2930
import org.exist.source.ClassLoaderSource;
3031
import org.exist.source.FileSource;
3132
import org.exist.source.Source;
3233
import org.exist.storage.BrokerPool;
34+
import org.exist.storage.BrokerPoolServiceException;
3335
import org.exist.util.Configuration;
3436
import org.exist.util.ConfigurationHelper;
3537
import org.exist.util.DatabaseConfigurationException;
@@ -88,7 +90,17 @@ private static Configuration getConfiguration() throws DatabaseConfigurationExce
8890
private static XQueryTestInfo extractTestInfo(final Path path) throws InitializationError {
8991
try {
9092
final Configuration config = getConfiguration();
93+
94+
final ExistRepository expathRepo = new ExistRepository();
95+
try {
96+
expathRepo.configure(config);
97+
expathRepo.prepare(null);
98+
} catch (final BrokerPoolServiceException e) {
99+
throw new InitializationError(e);
100+
}
101+
91102
final XQueryContext xqueryContext = new XQueryContext(config);
103+
xqueryContext.setTestRepository(Optional.of(expathRepo));
92104

93105
final Source xquerySource = new FileSource(path, UTF_8, false);
94106
final XQuery xquery = new XQuery();

exist-core/src/main/java/org/exist/xquery/XQueryContext.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
import org.exist.xquery.value.*;
9898
import org.w3c.dom.Node;
9999

100+
import static com.evolvedbinary.j8fu.OptionalUtil.or;
100101
import static com.evolvedbinary.j8fu.tuple.Tuple.Tuple;
101102
import static javax.xml.XMLConstants.XMLNS_ATTRIBUTE;
102103
import static javax.xml.XMLConstants.XML_NS_PREFIX;
@@ -425,6 +426,8 @@ public class XQueryContext implements BinaryValueManager, Context {
425426
private final Map<QName, DecimalFormat> staticDecimalFormats = HashMap(Tuple(UNNAMED_DECIMAL_FORMAT, DecimalFormat.UNNAMED));
426427

427428
// Only used for testing, e.g. {@link org.exist.test.runner.XQueryTestRunner}.
429+
private Optional<ExistRepository> testRepository = Optional.empty();
430+
428431
public XQueryContext() {
429432
this(null, null, null);
430433
}
@@ -512,13 +515,26 @@ public void setHttpContext(final HttpContext httpContext) {
512515
this.httpContext = httpContext;
513516
}
514517

518+
/**
519+
* Set the EXPath repository used for testing,
520+
* only should be called from {@link org.exist.test.runner.XQueryTestRunner}.
521+
*
522+
* @param testRepository the EXPath repository to use for test execution.
523+
*/
524+
public void setTestRepository(final Optional<ExistRepository> testRepository) {
525+
this.testRepository = testRepository;
526+
}
527+
515528
/**
516529
* Get the EXPath repository configured for the BrokerPool, if present.
517530
*
518-
* @return the EXPath respository if present.
531+
* @return the EXPath repository if present.
519532
*/
520533
public Optional<ExistRepository> getRepository() {
521-
return Optional.ofNullable(getBroker()).map(DBBroker::getBrokerPool).flatMap(BrokerPool::getExpathRepo);
534+
return or(
535+
testRepository,
536+
() -> Optional.ofNullable(getBroker()).map(DBBroker::getBrokerPool).flatMap(BrokerPool::getExpathRepo)
537+
);
522538
}
523539

524540
/**

0 commit comments

Comments
 (0)