Search in sources :

Example 1 with ClassBasedTestDescriptor

use of org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor in project graylog2-server by Graylog2.

the class ContainerMatrixClassSelectorResolver method resolve.

@Override
public Resolution resolve(UniqueIdSelector selector, Context context) {
    UniqueId uniqueId = selector.getUniqueId();
    UniqueId.Segment lastSegment = uniqueId.getLastSegment();
    if (ContainerMatrixTestClassDescriptor.SEGMENT_TYPE.equals(lastSegment.getType())) {
        String className = lastSegment.getValue();
        return ReflectionUtils.tryToLoadClass(className).toOptional().filter(isTestClassWithTests).map(testClass -> toResolution(context.addToParent(parent -> Optional.of(newClassTestDescriptor(parent, testClass))))).orElse(unresolved());
    }
    if (NestedClassTestDescriptor.SEGMENT_TYPE.equals(lastSegment.getType())) {
        String simpleClassName = lastSegment.getValue();
        return toResolution(context.addToParent(() -> selectUniqueId(uniqueId.removeLastSegment()), parent -> {
            if (parent instanceof ClassBasedTestDescriptor) {
                Class<?> parentTestClass = ((ClassBasedTestDescriptor) parent).getTestClass();
                return ReflectionUtils.findNestedClasses(parentTestClass, isNestedTestClass.and(where(Class::getSimpleName, isEqual(simpleClassName)))).stream().findFirst().flatMap(testClass -> Optional.of(newNestedClassTestDescriptor(parent, testClass)));
            }
            return Optional.empty();
        }));
    }
    return unresolved();
}
Also used : IsContainerMatrixTestClass(org.graylog.testing.containermatrix.discovery.IsContainerMatrixTestClass) IsTestClassWithTests(org.junit.jupiter.engine.discovery.predicates.IsTestClassWithTests) NestedClassTestDescriptor(org.junit.jupiter.engine.descriptor.NestedClassTestDescriptor) ReflectionUtils.findMethods(org.junit.platform.commons.util.ReflectionUtils.findMethods) ContainerMatrixTestsDescriptor(org.junit.jupiter.engine.descriptor.ContainerMatrixTestsDescriptor) UniqueIdSelector(org.junit.platform.engine.discovery.UniqueIdSelector) JupiterConfiguration(org.junit.jupiter.engine.config.JupiterConfiguration) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Collectors.toCollection(java.util.stream.Collectors.toCollection) IsContainerMatrixTestClass.isTestOrTestFactoryOrTestTemplateMethod(org.graylog.testing.containermatrix.discovery.IsContainerMatrixTestClass.isTestOrTestFactoryOrTestTemplateMethod) IsNestedTestClass(org.junit.jupiter.engine.discovery.predicates.IsNestedTestClass) MongodbServer(org.graylog.testing.containermatrix.MongodbServer) Resolution.unresolved(org.junit.platform.engine.support.discovery.SelectorResolver.Resolution.unresolved) DiscoverySelectors(org.junit.platform.engine.discovery.DiscoverySelectors) Method(java.lang.reflect.Method) LinkedHashSet(java.util.LinkedHashSet) Lifecycle(org.graylog.testing.completebackend.Lifecycle) DiscoverySelector(org.junit.platform.engine.DiscoverySelector) ContainerMatrixTestClassDescriptor(org.junit.jupiter.engine.descriptor.ContainerMatrixTestClassDescriptor) Predicate(java.util.function.Predicate) Set(java.util.Set) Predicate.isEqual(java.util.function.Predicate.isEqual) UniqueId(org.junit.platform.engine.UniqueId) ReflectionSupport.findNestedClasses(org.junit.platform.commons.support.ReflectionSupport.findNestedClasses) SearchVersion(org.graylog2.storage.SearchVersion) ReflectionUtils(org.junit.platform.commons.util.ReflectionUtils) ContainerMatrixTestEngine(org.graylog.testing.containermatrix.ContainerMatrixTestEngine) ClassBasedTestDescriptor(org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor) NestedClassSelector(org.junit.platform.engine.discovery.NestedClassSelector) List(java.util.List) Stream(java.util.stream.Stream) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) Optional(java.util.Optional) TestDescriptor(org.junit.platform.engine.TestDescriptor) SelectorResolver(org.junit.platform.engine.support.discovery.SelectorResolver) ClassSelector(org.junit.platform.engine.discovery.ClassSelector) FunctionUtils.where(org.junit.platform.commons.util.FunctionUtils.where) UniqueId(org.junit.platform.engine.UniqueId) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) ClassBasedTestDescriptor(org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor) IsContainerMatrixTestClass(org.graylog.testing.containermatrix.discovery.IsContainerMatrixTestClass) IsNestedTestClass(org.junit.jupiter.engine.discovery.predicates.IsNestedTestClass)

Aggregations

Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Predicate (java.util.function.Predicate)1 Predicate.isEqual (java.util.function.Predicate.isEqual)1 Supplier (java.util.function.Supplier)1 Collectors.toCollection (java.util.stream.Collectors.toCollection)1 Stream (java.util.stream.Stream)1 Lifecycle (org.graylog.testing.completebackend.Lifecycle)1 ContainerMatrixTestEngine (org.graylog.testing.containermatrix.ContainerMatrixTestEngine)1 MongodbServer (org.graylog.testing.containermatrix.MongodbServer)1 IsContainerMatrixTestClass (org.graylog.testing.containermatrix.discovery.IsContainerMatrixTestClass)1 IsContainerMatrixTestClass.isTestOrTestFactoryOrTestTemplateMethod (org.graylog.testing.containermatrix.discovery.IsContainerMatrixTestClass.isTestOrTestFactoryOrTestTemplateMethod)1 SearchVersion (org.graylog2.storage.SearchVersion)1 JupiterConfiguration (org.junit.jupiter.engine.config.JupiterConfiguration)1 ClassBasedTestDescriptor (org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor)1 ContainerMatrixTestClassDescriptor (org.junit.jupiter.engine.descriptor.ContainerMatrixTestClassDescriptor)1