Search in sources :

Example 6 with DefaultJupiterConfiguration

use of org.junit.jupiter.engine.config.DefaultJupiterConfiguration in project junit5 by junit-team.

the class TestInstanceLifecycleUtilsTests method getTestInstanceLifecycleWithNoConfigParamSet.

@Test
void getTestInstanceLifecycleWithNoConfigParamSet() {
    Lifecycle lifecycle = getTestInstanceLifecycle(getClass(), new DefaultJupiterConfiguration(mock(ConfigurationParameters.class)));
    assertThat(lifecycle).isEqualTo(PER_METHOD);
}
Also used : Lifecycle(org.junit.jupiter.api.TestInstance.Lifecycle) TestInstanceLifecycleUtils.getTestInstanceLifecycle(org.junit.jupiter.engine.descriptor.TestInstanceLifecycleUtils.getTestInstanceLifecycle) DefaultJupiterConfiguration(org.junit.jupiter.engine.config.DefaultJupiterConfiguration) Test(org.junit.jupiter.api.Test)

Example 7 with DefaultJupiterConfiguration

use of org.junit.jupiter.engine.config.DefaultJupiterConfiguration in project graylog2-server by Graylog2.

the class ContainerMatrixTestEngine method discover.

@Override
public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
    JupiterConfiguration configuration = new CachingJupiterConfiguration(new DefaultJupiterConfiguration(discoveryRequest.getConfigurationParameters()));
    final ContainerMatrixEngineDescriptor engineDescriptor = new ContainerMatrixEngineDescriptor(uniqueId, "Graylog Container Matrix Tests", configuration);
    Reflections reflections = new Reflections("org.graylog", "org.graylog2");
    final Set<Class<?>> annotated = reflections.getTypesAnnotatedWith(ContainerMatrixTestsConfiguration.class);
    final Set<Integer> extraPorts = getExtraPorts(annotated);
    final List<URL> mongoDBFixtures = getMongoDBFixtures(annotated);
    if (testAgainstRunningESMongoDB()) {
        // if you test from inside an IDE against running containers
        ContainerMatrixTestsDescriptor testsDescriptor = new ContainerMatrixTestWithRunningESMongoTestsDescriptor(engineDescriptor, extraPorts, mongoDBFixtures);
        new ContainerMatrixTestsDiscoverySelectorResolver(engineDescriptor).resolveSelectors(discoveryRequest, testsDescriptor);
        engineDescriptor.addChild(testsDescriptor);
    } else {
        // for full tests, create all combinations of tests. First differentiate for maven builds.
        getMavenProjectDirProvider(annotated).forEach(mavenProjectDirProvider -> getPluginJarsProvider(annotated).forEach(pluginJarsProvider -> {
            MavenProjectDirProvider mpdp = instantiateFactory(mavenProjectDirProvider);
            PluginJarsProvider pjp = instantiateFactory(pluginJarsProvider);
            // now add all grouped tests for Lifecycle.VM
            getSearchServerVersions(annotated).stream().map(SearchServer::getSearchVersion).forEach(searchVersion -> getMongoVersions(annotated).forEach(mongoVersion -> {
                ContainerMatrixTestsDescriptor testsDescriptor = new ContainerMatrixTestsDescriptor(engineDescriptor, Lifecycle.VM, mavenProjectDirProvider, mpdp.getUniqueId(), pluginJarsProvider, pjp.getUniqueId(), searchVersion, mongoVersion, extraPorts, mongoDBFixtures);
                new ContainerMatrixTestsDiscoverySelectorResolver(engineDescriptor).resolveSelectors(discoveryRequest, testsDescriptor);
                engineDescriptor.addChild(testsDescriptor);
            }));
            // add separate test classes (Lifecycle.CLASS)
            getSearchServerVersions(annotated).stream().map(SearchServer::getSearchVersion).forEach(esVersion -> getMongoVersions(annotated).forEach(mongoVersion -> {
                ContainerMatrixTestsDescriptor testsDescriptor = new ContainerMatrixTestsDescriptor(engineDescriptor, Lifecycle.CLASS, mavenProjectDirProvider, mpdp.getUniqueId(), pluginJarsProvider, pjp.getUniqueId(), esVersion, mongoVersion, extraPorts, new ArrayList<>());
                new ContainerMatrixTestsDiscoverySelectorResolver(engineDescriptor).resolveSelectors(discoveryRequest, testsDescriptor);
                engineDescriptor.addChild(testsDescriptor);
            }));
        }));
    }
    return engineDescriptor;
}
Also used : Arrays(java.util.Arrays) ThrowableCollector(org.junit.platform.engine.support.hierarchical.ThrowableCollector) URL(java.net.URL) ContainerMatrixTestsDescriptor(org.junit.jupiter.engine.descriptor.ContainerMatrixTestsDescriptor) JupiterConfiguration(org.junit.jupiter.engine.config.JupiterConfiguration) Reflections(org.reflections.Reflections) ContainerMatrixTestWithRunningESMongoTestsDescriptor(org.junit.jupiter.engine.descriptor.ContainerMatrixTestWithRunningESMongoTestsDescriptor) Function(java.util.function.Function) ArrayList(java.util.ArrayList) JupiterEngineExecutionContext(org.junit.jupiter.engine.execution.JupiterEngineExecutionContext) ContainerMatrixTestsConfiguration(org.graylog.testing.containermatrix.annotations.ContainerMatrixTestsConfiguration) ContainerMatrixTestsDiscoverySelectorResolver(org.junit.jupiter.engine.discovery.ContainerMatrixTestsDiscoverySelectorResolver) LinkedList(java.util.LinkedList) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) Lifecycle(org.graylog.testing.completebackend.Lifecycle) DefaultJupiterConfiguration(org.junit.jupiter.engine.config.DefaultJupiterConfiguration) Resources(com.google.common.io.Resources) MavenProjectDirProvider(org.graylog.testing.completebackend.MavenProjectDirProvider) ContainerMatrixEngineDescriptor(org.junit.jupiter.engine.descriptor.ContainerMatrixEngineDescriptor) Set(java.util.Set) HierarchicalTestExecutorService(org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutorService) UniqueId(org.junit.platform.engine.UniqueId) Collectors(java.util.stream.Collectors) CachingJupiterConfiguration(org.junit.jupiter.engine.config.CachingJupiterConfiguration) PluginJarsProvider(org.graylog.testing.completebackend.PluginJarsProvider) JupiterThrowableCollectorFactory(org.junit.jupiter.engine.support.JupiterThrowableCollectorFactory) AnnotationSupport(org.junit.platform.commons.support.AnnotationSupport) List(java.util.List) Stream(java.util.stream.Stream) ContainerMatrixHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.ContainerMatrixHierarchicalTestEngine) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) Paths(java.nio.file.Paths) Optional(java.util.Optional) ExecutionRequest(org.junit.platform.engine.ExecutionRequest) TestDescriptor(org.junit.platform.engine.TestDescriptor) ContainerMatrixTestsDescriptor(org.junit.jupiter.engine.descriptor.ContainerMatrixTestsDescriptor) ContainerMatrixEngineDescriptor(org.junit.jupiter.engine.descriptor.ContainerMatrixEngineDescriptor) CachingJupiterConfiguration(org.junit.jupiter.engine.config.CachingJupiterConfiguration) MavenProjectDirProvider(org.graylog.testing.completebackend.MavenProjectDirProvider) URL(java.net.URL) ContainerMatrixTestsDiscoverySelectorResolver(org.junit.jupiter.engine.discovery.ContainerMatrixTestsDiscoverySelectorResolver) PluginJarsProvider(org.graylog.testing.completebackend.PluginJarsProvider) JupiterConfiguration(org.junit.jupiter.engine.config.JupiterConfiguration) DefaultJupiterConfiguration(org.junit.jupiter.engine.config.DefaultJupiterConfiguration) CachingJupiterConfiguration(org.junit.jupiter.engine.config.CachingJupiterConfiguration) DefaultJupiterConfiguration(org.junit.jupiter.engine.config.DefaultJupiterConfiguration) Reflections(org.reflections.Reflections) ContainerMatrixTestWithRunningESMongoTestsDescriptor(org.junit.jupiter.engine.descriptor.ContainerMatrixTestWithRunningESMongoTestsDescriptor)

Example 8 with DefaultJupiterConfiguration

use of org.junit.jupiter.engine.config.DefaultJupiterConfiguration in project junit5 by junit-team.

the class TestInstanceLifecycleUtilsTests method getTestInstanceLifecycleFromSpecializedClassWithNoConfigParamSet.

@Test
void getTestInstanceLifecycleFromSpecializedClassWithNoConfigParamSet() {
    Class<?> testClass = SpecializedTestCase.class;
    Lifecycle lifecycle = getTestInstanceLifecycle(testClass, new DefaultJupiterConfiguration(mock(ConfigurationParameters.class)));
    assertThat(lifecycle).isEqualTo(PER_CLASS);
}
Also used : Lifecycle(org.junit.jupiter.api.TestInstance.Lifecycle) TestInstanceLifecycleUtils.getTestInstanceLifecycle(org.junit.jupiter.engine.descriptor.TestInstanceLifecycleUtils.getTestInstanceLifecycle) DefaultJupiterConfiguration(org.junit.jupiter.engine.config.DefaultJupiterConfiguration) Test(org.junit.jupiter.api.Test)

Example 9 with DefaultJupiterConfiguration

use of org.junit.jupiter.engine.config.DefaultJupiterConfiguration in project junit5 by junit-team.

the class TestInstanceLifecycleUtilsTests method getTestInstanceLifecycleWithLocalConfigThatOverridesCustomDefaultSetViaConfigParam.

@Test
void getTestInstanceLifecycleWithLocalConfigThatOverridesCustomDefaultSetViaConfigParam() {
    ConfigurationParameters configParams = mock(ConfigurationParameters.class);
    when(configParams.get(KEY)).thenReturn(Optional.of(PER_CLASS.name().toLowerCase()));
    Lifecycle lifecycle = getTestInstanceLifecycle(TestCase.class, new DefaultJupiterConfiguration(configParams));
    assertThat(lifecycle).isEqualTo(PER_METHOD);
}
Also used : Lifecycle(org.junit.jupiter.api.TestInstance.Lifecycle) TestInstanceLifecycleUtils.getTestInstanceLifecycle(org.junit.jupiter.engine.descriptor.TestInstanceLifecycleUtils.getTestInstanceLifecycle) ConfigurationParameters(org.junit.platform.engine.ConfigurationParameters) DefaultJupiterConfiguration(org.junit.jupiter.engine.config.DefaultJupiterConfiguration) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultJupiterConfiguration (org.junit.jupiter.engine.config.DefaultJupiterConfiguration)9 Test (org.junit.jupiter.api.Test)6 Lifecycle (org.junit.jupiter.api.TestInstance.Lifecycle)5 TestInstanceLifecycleUtils.getTestInstanceLifecycle (org.junit.jupiter.engine.descriptor.TestInstanceLifecycleUtils.getTestInstanceLifecycle)5 JupiterConfiguration (org.junit.jupiter.engine.config.JupiterConfiguration)3 ConfigurationParameters (org.junit.platform.engine.ConfigurationParameters)3 CachingJupiterConfiguration (org.junit.jupiter.engine.config.CachingJupiterConfiguration)2 UniqueId (org.junit.platform.engine.UniqueId)2 Resources (com.google.common.io.Resources)1 Method (java.lang.reflect.Method)1 URL (java.net.URL)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1