4646package org .exist .test .runner ;
4747
4848import org .exist .test .ExistEmbeddedServer ;
49+ import org .exist .util .StringUtil ;
4950import org .exist .util .XMLFilenameFilter ;
5051import org .exist .util .XQueryFilenameFilter ;
5152import org .junit .AfterClass ;
6566import java .util .ArrayList ;
6667import java .util .Collections ;
6768import java .util .List ;
69+ import java .util .Properties ;
6870import java .util .stream .Collectors ;
6971import java .util .stream .Stream ;
7072
8385 */
8486public class XSuite extends ParentRunner <Runner > {
8587
88+ private static boolean DEFAULT_DISABLE_EXPATH_AUTO_DEPLOY = true ;
89+ private static boolean DEFAULT_DATABASE_USE_TEMPORARY_STORAGE = true ;
90+
8691 /**
8792 * Returns an empty suite.
8893 *
@@ -120,6 +125,18 @@ public static Runner emptySuite() {
120125 public @interface XSuiteParallel {
121126 }
122127
128+ /**
129+ * The <code>XSuiteConfig</code> annotation specifies any config for XSuite.
130+ */
131+ @ Retention (RetentionPolicy .RUNTIME )
132+ @ Target (ElementType .TYPE )
133+ @ Inherited
134+ public @interface XSuiteConfig {
135+ boolean disableExpathAutoDeploy () default true ;
136+ boolean databaseUseTemporaryStorage () default true ;
137+ String databaseDataDirPath () default "" ;
138+ }
139+
123140 private static String [] getAnnotatedDirectories (final Class <?> klass ) throws InitializationError {
124141 final XSuite .XSuiteFiles annotation = klass .getAnnotation (XSuite .XSuiteFiles .class );
125142 if (annotation == null ) {
@@ -136,6 +153,24 @@ private static boolean hasParallelAnnotation(@Nullable final Class<?> klass) {
136153 return annotation != null ;
137154 }
138155
156+ private static Config getConfig (final Class <?> klass ) throws InitializationError {
157+ final XSuite .XSuiteConfig annotation = klass .getAnnotation (XSuite .XSuiteConfig .class );
158+ final boolean disableExpathAutoDeploy ;
159+ final boolean databaseUseTemporaryStorage ;
160+ final String databaseDataDirPath ;
161+ if (annotation != null ) {
162+ disableExpathAutoDeploy = annotation .disableExpathAutoDeploy ();
163+ databaseUseTemporaryStorage = annotation .databaseUseTemporaryStorage ();
164+ databaseDataDirPath = annotation .databaseDataDirPath ();
165+ } else {
166+ disableExpathAutoDeploy = DEFAULT_DISABLE_EXPATH_AUTO_DEPLOY ;
167+ databaseUseTemporaryStorage = DEFAULT_DATABASE_USE_TEMPORARY_STORAGE ;
168+ databaseDataDirPath = null ;
169+ }
170+ return new Config (disableExpathAutoDeploy , databaseUseTemporaryStorage , databaseDataDirPath );
171+ }
172+
173+ private final Config config ;
139174 private final List <Runner > runners ;
140175
141176 /**
@@ -198,6 +233,7 @@ protected XSuite(final RunnerBuilder builder, final Class<?> klass, final String
198233 */
199234 protected XSuite (final Class <?> klass , final List <Runner > runners ) throws InitializationError {
200235 super (klass );
236+ this .config = getConfig (klass );
201237 this .runners = Collections .unmodifiableList (runners );
202238 }
203239
@@ -280,7 +316,7 @@ protected Statement withBeforeClasses(final Statement statement) {
280316 final List <FrameworkMethod > befores = getTestClass ().getAnnotatedMethods (BeforeClass .class );
281317
282318 // inject a Server startup as though it were an @BeforeClass
283- final Statement startExistDb = new StartExistDbStatement ();
319+ final Statement startExistDb = new StartExistDbStatement (config );
284320
285321 return new RunXSuiteBefores (statement , startExistDb , befores , null );
286322 }
@@ -296,6 +332,26 @@ protected Statement withAfterClasses(final Statement statement) {
296332 return new RunXSuiteAfters (statement , stopExist , afters , null );
297333 }
298334
335+ private static class Config {
336+ final boolean disableExpathAutoDeploy ;
337+ final boolean databaseUseTemporaryStorage ;
338+ final String databaseDataDirPath ;
339+
340+
341+ private Config (final boolean disableExpathAutoDeploy , final boolean databaseUseTemporaryStorage , final String databaseDataDirPath ) {
342+ if (databaseUseTemporaryStorage && databaseDataDirPath != null ) {
343+ throw new IllegalArgumentException ("You cannot specify databaseUseTemporaryStorage=true and a databaseDataDirPath" );
344+ }
345+ this .disableExpathAutoDeploy = disableExpathAutoDeploy ;
346+ this .databaseUseTemporaryStorage = databaseUseTemporaryStorage ;
347+ if (StringUtil .notNullOrEmpty (databaseDataDirPath )) {
348+ this .databaseDataDirPath = databaseDataDirPath ;
349+ } else {
350+ this .databaseDataDirPath = null ;
351+ }
352+ }
353+ }
354+
299355 private static class RunXSuiteBefores extends Statement {
300356 private final Statement next ;
301357 private final Object target ;
@@ -358,12 +414,18 @@ public void evaluate() throws Throwable {
358414 }
359415
360416 private static class StartExistDbStatement extends Statement {
417+ final Config config ;
418+
419+ public StartExistDbStatement (final Config config ) {
420+ this .config = config ;
421+ }
422+
361423 @ Override
362424 public void evaluate () throws Throwable {
363425 if (EXIST_EMBEDDED_SERVER_CLASS_INSTANCE != null ) {
364426 throw new IllegalStateException ("EXIST_EMBEDDED_SERVER_CLASS_INSTANCE already instantiated" );
365427 }
366- EXIST_EMBEDDED_SERVER_CLASS_INSTANCE = newExistDbServer ();
428+ EXIST_EMBEDDED_SERVER_CLASS_INSTANCE = newExistDbServer (config );
367429 EXIST_EMBEDDED_SERVER_CLASS_INSTANCE .startDb ();
368430 }
369431 }
@@ -381,7 +443,15 @@ public void evaluate() {
381443
382444 static ExistEmbeddedServer EXIST_EMBEDDED_SERVER_CLASS_INSTANCE = null ;
383445
384- static ExistEmbeddedServer newExistDbServer () {
385- return new ExistEmbeddedServer (true , true );
446+ static ExistEmbeddedServer newExistDbServer (final Config config ) {
447+ if (config .databaseDataDirPath == null ) {
448+ return new ExistEmbeddedServer (config .disableExpathAutoDeploy , config .databaseUseTemporaryStorage );
449+
450+ } else {
451+ final Properties properties = new Properties ();
452+ properties .setProperty ("org.exist.db-connection.files" , config .databaseDataDirPath );
453+ properties .setProperty ("org.exist.db-connection.recovery.journal-dir" , config .databaseDataDirPath );
454+ return new ExistEmbeddedServer (properties , config .disableExpathAutoDeploy , false );
455+ }
386456 }
387457}
0 commit comments