Search in sources :

Example 91 with UniqueId

use of org.junit.platform.engine.UniqueId in project cucumber-jvm by cucumber.

the class FeatureResolver method resolveUniqueId.

void resolveUniqueId(UniqueIdSelector uniqueIdSelector) {
    UniqueId uniqueId = uniqueIdSelector.getUniqueId();
    // Ignore any ids not from our own engine
    if (!uniqueId.hasPrefix(engineDescriptor.getUniqueId())) {
        return;
    }
    Predicate<TestDescriptor> keepTestWithSelectedId = testDescriptor -> uniqueId.equals(testDescriptor.getUniqueId());
    uniqueId.getSegments().stream().filter(FeatureOrigin::isFeatureSegment).map(UniqueId.Segment::getValue).map(URI::create).flatMap(this::resolveUri).forEach(featureDescriptor -> {
        featureDescriptor.prune(keepTestWithSelectedId);
        engineDescriptor.mergeFeature(featureDescriptor);
    });
}
Also used : Pickle(io.cucumber.core.gherkin.Pickle) ConfigurationParameters(org.junit.platform.engine.ConfigurationParameters) UniqueIdSelector(org.junit.platform.engine.discovery.UniqueIdSelector) FeatureParser(io.cucumber.core.feature.FeatureParser) LoggerFactory(io.cucumber.core.logging.LoggerFactory) FeatureIdentifier(io.cucumber.core.feature.FeatureIdentifier) ClasspathRootSelector(org.junit.platform.engine.discovery.ClasspathRootSelector) FileSelector(org.junit.platform.engine.discovery.FileSelector) DirectorySelector(org.junit.platform.engine.discovery.DirectorySelector) URI(java.net.URI) Comparator.comparing(java.util.Comparator.comparing) UriSelector(org.junit.platform.engine.discovery.UriSelector) ClassLoaders(io.cucumber.core.resource.ClassLoaders) Logger(io.cucumber.core.logging.Logger) ResourceScanner(io.cucumber.core.resource.ResourceScanner) Predicate(java.util.function.Predicate) Node(io.cucumber.plugin.event.Node) UniqueId(org.junit.platform.engine.UniqueId) UUID(java.util.UUID) List(java.util.List) Stream(java.util.stream.Stream) Feature(io.cucumber.core.gherkin.Feature) ClasspathResourceSelector(org.junit.platform.engine.discovery.ClasspathResourceSelector) TestDescriptor(org.junit.platform.engine.TestDescriptor) PackageSelector(org.junit.platform.engine.discovery.PackageSelector) ClassSelector(org.junit.platform.engine.discovery.ClassSelector) UniqueId(org.junit.platform.engine.UniqueId) TestDescriptor(org.junit.platform.engine.TestDescriptor) URI(java.net.URI)

Example 92 with UniqueId

use of org.junit.platform.engine.UniqueId in project cucumber-jvm by cucumber.

the class DiscoverySelectorResolverTest method resolveRequestWithMultipleUniqueIdSelector.

@Test
void resolveRequestWithMultipleUniqueIdSelector() {
    Set<UniqueId> selectors = new HashSet<>();
    DiscoverySelector resource = selectDirectory("src/test/resources/io/cucumber/junit/platform/engine/feature-with-outline.feature");
    selectSomePickle(resource).ifPresent(selectors::add);
    DiscoverySelector resource2 = selectDirectory("src/test/resources/io/cucumber/junit/platform/engine/single.feature");
    selectSomePickle(resource2).ifPresent(selectors::add);
    EngineDiscoveryRequest discoveryRequest = new SelectorRequest(selectors.stream().map(DiscoverySelectors::selectUniqueId).collect(Collectors.toList()));
    resolver.resolveSelectors(discoveryRequest, testDescriptor);
    assertEquals(selectors, testDescriptor.getDescendants().stream().filter(PickleDescriptor.class::isInstance).map(TestDescriptor::getUniqueId).collect(toSet()));
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) DiscoverySelector(org.junit.platform.engine.DiscoverySelector) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) TestDescriptor(org.junit.platform.engine.TestDescriptor) HashSet(java.util.HashSet) DiscoverySelectors(org.junit.platform.engine.discovery.DiscoverySelectors) Test(org.junit.jupiter.api.Test)

Example 93 with UniqueId

use of org.junit.platform.engine.UniqueId 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 94 with UniqueId

use of org.junit.platform.engine.UniqueId in project junit5 by junit-team.

the class TestTemplateTestDescriptorTests method inheritsTagsFromParent.

@Test
void inheritsTagsFromParent() throws Exception {
    UniqueId rootUniqueId = UniqueId.root("segment", "template");
    UniqueId parentUniqueId = rootUniqueId.append("class", "myClass");
    AbstractTestDescriptor parent = containerTestDescriptorWithTags(parentUniqueId, singleton(TestTag.create("foo")));
    when(jupiterConfiguration.getDefaultDisplayNameGenerator()).thenReturn(new DisplayNameGenerator.Standard());
    TestTemplateTestDescriptor testDescriptor = new TestTemplateTestDescriptor(parentUniqueId.append("tmp", "testTemplate()"), MyTestCase.class, MyTestCase.class.getDeclaredMethod("testTemplate"), jupiterConfiguration);
    parent.addChild(testDescriptor);
    assertThat(testDescriptor.getTags()).containsExactlyInAnyOrder(TestTag.create("foo"), TestTag.create("bar"), TestTag.create("baz"));
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) DisplayNameGenerator(org.junit.jupiter.api.DisplayNameGenerator) AbstractTestDescriptor(org.junit.platform.engine.support.descriptor.AbstractTestDescriptor) Test(org.junit.jupiter.api.Test)

Example 95 with UniqueId

use of org.junit.platform.engine.UniqueId in project junit5 by junit-team.

the class OtherClass method resolvingUniqueIdWithUnknownSegmentTypeResolvesNothing.

@Test
void resolvingUniqueIdWithUnknownSegmentTypeResolvesNothing() {
    UniqueId uniqueId = engineId().append("bogus", "enigma");
    UniqueIdSelector selector = selectUniqueId(uniqueId);
    resolve(request().selectors(selector));
    assertTrue(engineDescriptor.getDescendants().isEmpty());
    assertUnresolved(selector);
}
Also used : UniqueIdSelector(org.junit.platform.engine.discovery.UniqueIdSelector) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) UniqueId(org.junit.platform.engine.UniqueId) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

Aggregations

UniqueId (org.junit.platform.engine.UniqueId)131 Test (org.junit.jupiter.api.Test)95 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)83 DynamicTest (org.junit.jupiter.api.DynamicTest)64 TestDescriptor (org.junit.platform.engine.TestDescriptor)29 UniqueIdSelector (org.junit.platform.engine.discovery.UniqueIdSelector)25 ClassSelector (org.junit.platform.engine.discovery.ClassSelector)15 EngineDiscoveryRequest (org.junit.platform.engine.EngineDiscoveryRequest)14 List (java.util.List)9 JupiterTestDescriptor (org.junit.jupiter.engine.descriptor.JupiterTestDescriptor)8 TestTemplateInvocationTestDescriptor (org.junit.jupiter.engine.descriptor.TestTemplateInvocationTestDescriptor)8 TestPlan (org.junit.platform.launcher.TestPlan)8 JUnitException (org.junit.platform.commons.JUnitException)7 Method (java.lang.reflect.Method)6 ArrayList (java.util.ArrayList)6 Optional (java.util.Optional)6 DynamicDescendantFilter (org.junit.jupiter.engine.descriptor.DynamicDescendantFilter)6 TestEngine (org.junit.platform.engine.TestEngine)6 TrackLogRecords (org.junit.jupiter.engine.TrackLogRecords)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5