Search in sources :

Example 6 with Version

use of org.projectnessie.tools.compatibility.api.Version in project nessie by projectnessie.

the class AbstractMultiVersionExtension method evaluateExecutionCondition.

@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
    Optional<Version> version = nessieVersionFromContext(context);
    if (!version.isPresent()) {
        if (isNessieMultiVersionTest(context)) {
            return disabled("(not running via multi-nessie-version engine)");
        }
        return enabled("(not running via multi-nessie-versions engine)");
    }
    ConditionEvaluationResult classResult = context.getTestClass().map(c -> conditionCheck(version.get(), c)).orElse(PASS);
    if (classResult.isDisabled()) {
        return classResult;
    }
    ConditionEvaluationResult methodResult = context.getTestMethod().map(m -> conditionCheck(version.get(), m)).orElse(PASS);
    if (methodResult.isDisabled()) {
        return methodResult;
    }
    return PASS;
}
Also used : AnnotatedFields.populateAnnotatedFields(org.projectnessie.tools.compatibility.internal.AnnotatedFields.populateAnnotatedFields) Arrays(java.util.Arrays) NessieVersion(org.projectnessie.tools.compatibility.api.NessieVersion) ConditionEvaluationResult.disabled(org.junit.jupiter.api.extension.ConditionEvaluationResult.disabled) Version.parseVersion(org.projectnessie.tools.compatibility.api.Version.parseVersion) UniqueId(org.junit.platform.engine.UniqueId) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) VersionCondition(org.projectnessie.tools.compatibility.api.VersionCondition) Objects(java.util.Objects) Stream(java.util.stream.Stream) ConditionEvaluationResult(org.junit.jupiter.api.extension.ConditionEvaluationResult) BeforeAllCallback(org.junit.jupiter.api.extension.BeforeAllCallback) ExecutionCondition(org.junit.jupiter.api.extension.ExecutionCondition) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) AnnotationSupport.findAnnotation(org.junit.platform.commons.support.AnnotationSupport.findAnnotation) Segment(org.junit.platform.engine.UniqueId.Segment) BeforeEachCallback(org.junit.jupiter.api.extension.BeforeEachCallback) Optional(java.util.Optional) AnnotationUtils(org.junit.platform.commons.util.AnnotationUtils) ConditionEvaluationResult.enabled(org.junit.jupiter.api.extension.ConditionEvaluationResult.enabled) AnnotatedElement(java.lang.reflect.AnnotatedElement) Version(org.projectnessie.tools.compatibility.api.Version) ConditionEvaluationResult(org.junit.jupiter.api.extension.ConditionEvaluationResult) NessieVersion(org.projectnessie.tools.compatibility.api.NessieVersion) Version.parseVersion(org.projectnessie.tools.compatibility.api.Version.parseVersion) Version(org.projectnessie.tools.compatibility.api.Version)

Example 7 with Version

use of org.projectnessie.tools.compatibility.api.Version in project nessie by projectnessie.

the class MultiNessieVersionsTestEngine method discover.

@Override
public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
    try {
        // JupiterEngineDescriptor must be the root, that's what the JUnit Jupiter engine
        // implementation expects.
        JupiterConfiguration configuration = new CachingJupiterConfiguration(new DefaultJupiterConfiguration(discoveryRequest.getConfigurationParameters()));
        JupiterEngineDescriptor engineDescriptor = new JupiterEngineDescriptor(uniqueId, configuration);
        SortedSet<Version> versionsToTest;
        try {
            versionsToTest = VersionsToExercise.versionsForEngine(discoveryRequest);
        } catch (IllegalStateException e) {
            // No versions to test found - return early
            return engineDescriptor;
        }
        for (Version version : versionsToTest) {
            UniqueId perVersionId = uniqueId.append("nessie-version", version.toString());
            NessieVersionTestDescriptor perVersionTestDescriptor = new NessieVersionTestDescriptor(perVersionId, version);
            engineDescriptor.addChild(perVersionTestDescriptor);
            TestDescriptor discoverResult = delegate.discover(discoveryRequest, perVersionId);
            List<? extends TestDescriptor> children = new ArrayList<>(discoverResult.getChildren());
            for (TestDescriptor child : children) {
                discoverResult.removeChild(child);
                perVersionTestDescriptor.addChild(child);
            }
        }
        return engineDescriptor;
    } catch (Exception e) {
        LOGGER.error("Failed to discover tests", e);
        throw new RuntimeException(e);
    }
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) CachingJupiterConfiguration(org.junit.jupiter.engine.config.CachingJupiterConfiguration) ArrayList(java.util.ArrayList) JupiterEngineDescriptor(org.junit.jupiter.engine.descriptor.JupiterEngineDescriptor) Version(org.projectnessie.tools.compatibility.api.Version) DefaultJupiterConfiguration(org.junit.jupiter.engine.config.DefaultJupiterConfiguration) JupiterConfiguration(org.junit.jupiter.engine.config.JupiterConfiguration) CachingJupiterConfiguration(org.junit.jupiter.engine.config.CachingJupiterConfiguration) DefaultJupiterConfiguration(org.junit.jupiter.engine.config.DefaultJupiterConfiguration) AbstractTestDescriptor(org.junit.platform.engine.support.descriptor.AbstractTestDescriptor) TestDescriptor(org.junit.platform.engine.TestDescriptor)

Example 8 with Version

use of org.projectnessie.tools.compatibility.api.Version in project nessie by projectnessie.

the class NessieUpgradesExtension method beforeAll.

@Override
public void beforeAll(ExtensionContext context) {
    Version version = populateNessieVersionAnnotatedFields(context, null);
    if (version == null) {
        return;
    }
    ServerKey serverKey = buildServerKey(version, context);
    NessieServer nessieServer = nessieServer(context, serverKey, initializeRepositorySupplier(context, serverKey));
    populateFields(context, null, version, ctx -> nessieServer);
}
Also used : Version(org.projectnessie.tools.compatibility.api.Version)

Example 9 with Version

use of org.projectnessie.tools.compatibility.api.Version in project nessie by projectnessie.

the class NessieUpgradesExtension method beforeEach.

@Override
public void beforeEach(ExtensionContext context) {
    Object testInstance = context.getRequiredTestInstance();
    Version version = populateNessieVersionAnnotatedFields(context, testInstance);
    if (version == null) {
        return;
    }
    ServerKey serverKey = buildServerKey(version, context);
    NessieServer nessieServer = nessieServerExisting(context, serverKey);
    populateFields(context, testInstance, version, ctx -> nessieServer);
}
Also used : Version(org.projectnessie.tools.compatibility.api.Version)

Aggregations

Version (org.projectnessie.tools.compatibility.api.Version)9 ExtensionContext (org.junit.jupiter.api.extension.ExtensionContext)5 Collections (java.util.Collections)3 BooleanSupplier (java.util.function.BooleanSupplier)3 Function (java.util.function.Function)3 AbstractNessieApiHolder.apiInstanceForField (org.projectnessie.tools.compatibility.internal.AbstractNessieApiHolder.apiInstanceForField)3 AnnotatedFields.populateNessieAnnotatedFields (org.projectnessie.tools.compatibility.internal.AnnotatedFields.populateNessieAnnotatedFields)3 NessieServer.nessieServer (org.projectnessie.tools.compatibility.internal.NessieServer.nessieServer)3 Field (java.lang.reflect.Field)2 Map (java.util.Map)2 UniqueId (org.junit.platform.engine.UniqueId)2 NessieVersion (org.projectnessie.tools.compatibility.api.NessieVersion)2 Version.parseVersion (org.projectnessie.tools.compatibility.api.Version.parseVersion)2 Util.classContext (org.projectnessie.tools.compatibility.internal.Util.classContext)2 AnnotatedElement (java.lang.reflect.AnnotatedElement)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 URI (java.net.URI)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1