All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.junit.jupiter.engine.descriptor.PdslConfigParameter Maven / Gradle / Ivy

Go to download

The Polymorphic DSL test framework was designed to solve the challenges with testing large, complex systems. Modern architecture requires software to run as distrubited systems or on multiple platforms. The conventional cost of testing these systems is quite high. PDSL allows a user to describe the system under test using a DSL of some kind: a picture, sentences in natural languages, graphs, etc. Using a common DSL allows someone to make deeply scalable tests. A simple change to the DSL could generate dozens of tests providing coverage through many layers of the test pyramid or even multiple applications.

The newest version!
package org.junit.jupiter.engine.descriptor;

import com.google.common.base.Preconditions;
import com.pdsl.executors.TraceableTestRunExecutor;
import com.pdsl.gherkin.DefaultGherkinTestSpecificationFactory;
import com.pdsl.runners.*;
import com.pdsl.specifications.LineDelimitedTestSpecificationFactory;
import com.pdsl.specifications.TestResourceFinderGenerator;
import com.pdsl.specifications.TestSpecificationFactory;
import com.pdsl.testcases.PreorderTestCaseFactory;
import com.pdsl.testcases.TestCaseFactory;

import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.Parser;

import java.net.URI;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.Optional;
import java.util.function.Supplier;

/**
 * A Data Transfer Object used to integrate the PDSL framework with JUnit5.
 */
public class PdslConfigParameter {

    private String context = "Unspecified";
    private String applicationName = "Polymorphic DSL System Under Test";
    private URI resourceRoot = Paths.get("./").toUri();
    private Optional> dslRecognizerParser = Optional.empty();
    private Optional> dslRecognizerLexer = Optional.empty();
    private Optional> testRunExecutor = Optional.empty();
    private Optional> resourceFinder = Optional.empty();
    private String recognizerRule = RecognizedBy.DEFAULT_RECOGNIZER_RULE_NAME;
    private final Supplier specificationFactoryProvider;
    private final Supplier testCaseFactoryProvider;
    private final Collection pdslTestParameters;

    private PdslConfigParameter(Builder builder) {
        this.context = builder.context;
        this.applicationName = builder.applicationName;
        this.resourceRoot = builder.resourceRoot;
        this.dslRecognizerParser = builder.dslRecognizerParser;
        this.dslRecognizerLexer = builder.dslRecognizerLexer;
        this.testRunExecutor = builder.testRunExecutor;
        this.resourceFinder = builder.resourceFinder;
        this.recognizerRule = builder.recognizerRule;
        this.specificationFactoryProvider = builder.specificationFactoryProvider;
        this.testCaseFactoryProvider = builder.testCaseFactoryProvider;
        this.pdslTestParameters = builder.pdslTestParameters;
    }

    public String getContext() {
        return context;
    }

    public String getApplicationName() {
        return applicationName;
    }

    public URI getResourceRoot() {
        return resourceRoot;
    }

    public Optional> getDslRecognizerParser() {
        return dslRecognizerParser;
    }

    public Optional> getDslRecognizerLexer() {
        return dslRecognizerLexer;
    }

    public Optional> getTestRunExecutor() {
        return testRunExecutor;
    }

    public Optional> getResourceFinder() {
        return resourceFinder;
    }

    public String getRecognizerRule() {
        return recognizerRule;
    }

    public Supplier getSpecificationFactoryProvider() {
        return specificationFactoryProvider;
    }

    public Supplier getTestCaseFactoryProvider() {
        return testCaseFactoryProvider;
    }

    public  Collection getPdslTestParameters() {
        return pdslTestParameters;
    }

    public static Builder createGeneralPdslConfig(Supplier testCaseFactoryProvider,
                                                  Supplier specificationFactoryProvider,
                                                  Collection pdslTestParameters) {
        return new Builder(testCaseFactoryProvider, specificationFactoryProvider, pdslTestParameters);
    }

    private static final TestCaseFactory GHERKIN_TEST_SPECIFICATION_FACTORY_SINGLETON = new PreorderTestCaseFactory();
    public static Builder createGherkinPdslConfig(Collection pdslTestParameters) {
        return new Builder(() -> GHERKIN_TEST_SPECIFICATION_FACTORY_SINGLETON,
                () -> filter -> new DefaultGherkinTestSpecificationFactory.Builder(filter).build(),
                pdslTestParameters);
    }

    /**
     * A builder for creating a PdslConfigParameter.
     */
    public static class Builder {
        private String context = "Unspecified";
        private String applicationName = "Polymorphic DSL System Under Test";
        private URI resourceRoot = Paths.get("./").toUri();
        private Optional> dslRecognizerParser = Optional.empty();
        private Optional> dslRecognizerLexer = Optional.empty();
        private Optional> testRunExecutor = Optional.empty();
        private Optional> resourceFinder = Optional.empty();
        private String recognizerRule = RecognizedBy.DEFAULT_RECOGNIZER_RULE_NAME;
        private Supplier specificationFactoryProvider;
        private Supplier testCaseFactoryProvider;
        private Collection pdslTestParameters;

        Builder(Supplier testCaseFactoryProvider,
                       Supplier specificationFactoryProvider,
                       Collection pdslTestParameters) {
            Preconditions.checkNotNull(pdslTestParameters, "PDSL test parameters cannot be null!");
            Preconditions.checkArgument(!pdslTestParameters.isEmpty(), "PDSL test parameters cannot be empty!");
            this.testCaseFactoryProvider = testCaseFactoryProvider;
            this.specificationFactoryProvider = specificationFactoryProvider;
            this.pdslTestParameters = pdslTestParameters;
        }

        Builder(Supplier testCaseFactoryProvider,
                Supplier specificationFactoryProvider) {
            Preconditions.checkNotNull(pdslTestParameters, "PDSL test parameters cannot be null!");
            Preconditions.checkArgument(!pdslTestParameters.isEmpty(), "PDSL test parameters cannot be empty!");
            this.testCaseFactoryProvider = testCaseFactoryProvider;
            this.specificationFactoryProvider = specificationFactoryProvider;
        }

        public Builder withContext(String context) {
            this.context = context;
            return this;
        }

        public Builder withApplicationName(String applicationName) {
            this.applicationName = applicationName;
            return this;
        }

        public Builder withResourceRoot(URI resourceRoot) {
            this.resourceRoot = resourceRoot;
            return this;
        }

        public Builder withDslRecognizerParser(Class dslRecognizerParser) {
            this.dslRecognizerParser = Optional.ofNullable(dslRecognizerParser);
            return this;
        }

        public Builder withDslRecognizerLexer(Class dslRecognizerLexer) {
            this.dslRecognizerLexer = Optional.ofNullable(dslRecognizerLexer);
            return this;
        }

        public Builder withTestRunExecutor(Supplier executor) {
            this.testRunExecutor = Optional.of(executor);
            return this;
        }

        public Builder withTestResourceFinderGenerator(Supplier resourceFinderGenerator) {
            this.resourceFinder = Optional.of(resourceFinderGenerator);
            return this;
        }

        public Builder withTestSpecificationFactoryGenerator(Supplier testSpecificationFactoryGenerator) {
            Preconditions.checkNotNull(testSpecificationFactoryGenerator, "Test specifcation factory generator cannot be null!");
            this.specificationFactoryProvider = testSpecificationFactoryGenerator;
            return this;
        }

        public Builder withTestCaseFactory(Supplier testCaseFactoryProvider) {
            this.testCaseFactoryProvider = testCaseFactoryProvider;
            return this;
        }

        public Builder withPdslTestParameter(Collection pdslTestParameters) {
            Preconditions.checkNotNull(pdslTestParameters, "Pdsl test parameters cannot be null!");
            Preconditions.checkArgument(pdslTestParameters.isEmpty(), "PDSL test parameters cannot be empty!");
            this.pdslTestParameters = pdslTestParameters;
            return this;
        }

        public Builder withRecognizerRule(String recognizerRule) {
            Preconditions.checkNotNull(recognizerRule, "recognizer rule cannot be null!");
            Preconditions.checkArgument(!recognizerRule.isEmpty(), "Recognizer rule cannot be empty!");
            this.recognizerRule = recognizerRule;
            return this;
        }

        public Builder withPdslTestParameters(Collection pdslTestParameters) {
            Preconditions.checkNotNull(pdslTestParameters, "PDSL test parameters cannot be null!");
            Preconditions.checkArgument(!pdslTestParameters.isEmpty(), "PDSL test parameters cannot be empty!");
            this.pdslTestParameters = pdslTestParameters;
            return this;
        }

        /**
         * Creates a PdslConfigParameter.
         *
         * A non-empty list of PdslTestParameters must have been provided
         * otherwise a runtime exception will be thrown.
         */
        public PdslConfigParameter build() {
            if (pdslTestParameters.isEmpty()) {
                throw new IllegalStateException("PDSL test parameters cannot be empty!");
            }
            return new PdslConfigParameter(this);
        }

    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy