Skip to content

Commit

Permalink
Small cleanup of version PR
Browse files Browse the repository at this point in the history
  • Loading branch information
rjrudin committed Oct 29, 2024
1 parent 588130d commit 38d95da
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* This class depends on a DatabaseClient, and how that is provided must be defined by the subclass.
* </p>
*/
public abstract class AbstractMarkLogicTest extends LoggingObject implements HasMarkLogicVersion {
public abstract class AbstractMarkLogicTest extends LoggingObject implements MarkLogicVersionSupplier {

/**
* Subclass must define how a connection is made to (presumably) the test database.
Expand All @@ -46,7 +46,8 @@ public abstract class AbstractMarkLogicTest extends LoggingObject implements Has
*/
@Override
public MarkLogicVersion getMarkLogicVersion() {
return MarkLogicVersion.getVersion(getDatabaseClient());
String version = getDatabaseClient().newServerEval().javascript("xdmp.version()").evalAs(String.class);
return new MarkLogicVersion(version);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
*/
package com.marklogic.junit5;

import com.marklogic.client.DatabaseClient;

/**
* Parses a MarkLogic version string - i.e. from xdmp.version() - into its major, minor, and patch values.
*/
Expand All @@ -14,21 +12,15 @@ public class MarkLogicVersion {
private final static String SEMVER_PATTERN = "^[0-9]+\\.[0-9]+\\.[0-9]+";
private final static String NIGHTLY_SEMVER_PATTERN = "^[0-9]+\\.[0-9]+\\.[0-9]{8}";

// For non-semver releases.
// For non-semver releases, such as MarkLogic 10 and earlier..
private final static String MAJOR_WITH_MINOR_PATTERN = "^.*-(.+)$";

private final static String VERSION_WITH_PATCH_PATTERN = "^.*-(.+)\\..*";
private final static String NIGHTLY_BUILD_PATTERN = "[^-]+-(\\d{4})(\\d{2})(\\d{2})";

private final int major;
private final Integer minor;
private final Integer patch;
private final boolean nightly;

public static MarkLogicVersion getVersion(DatabaseClient client) {
String version = client.newServerEval().javascript("xdmp.version()").evalAs(String.class);
return new MarkLogicVersion(version);
}

public MarkLogicVersion(String version) {
if (version.matches(NIGHTLY_SEMVER_PATTERN)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/**
* @since 1.5.0
*/
public interface HasMarkLogicVersion {
public interface MarkLogicVersionSupplier {

MarkLogicVersion getMarkLogicVersion();
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext con
if (!testInstance.isPresent()) {
throw new RuntimeException(getClass() + " can only be used when a test instance is present.");
}
if (!(testInstance.get() instanceof HasMarkLogicVersion)) {
throw new RuntimeException(testInstance.getClass() + " must implement " + HasMarkLogicVersion.class.getName());
if (!(testInstance.get() instanceof MarkLogicVersionSupplier)) {
throw new RuntimeException(testInstance.getClass() + " must implement " + MarkLogicVersionSupplier.class.getName());
}
markLogicVersion = ((HasMarkLogicVersion) context.getTestInstance().get()).getMarkLogicVersion();
markLogicVersion = ((MarkLogicVersionSupplier) context.getTestInstance().get()).getMarkLogicVersion();
}
return evaluateVersion(markLogicVersion);
}
Expand Down

0 comments on commit 38d95da

Please sign in to comment.