org.junit.jupiter.engine.descriptor.PdslTestParameter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pdsl Show documentation
Show all versions of pdsl Show documentation
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 org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.Parser;
import org.antlr.v4.runtime.tree.ParseTreeListener;
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;
import static com.pdsl.runners.PdslTest.DEFAULT_ALL_RULE;
/**
* A Data Transfer Object provided to either a {@link
* org.junit.jupiter.engine.descriptor.PdslGeneralInvocationContextProvider
* PdslGeneralInvocationContextProvider}
* or a {@link org.junit.jupiter.engine.descriptor.PdslGherkinInvocationContextProvider
* PdslGherkinInvocationContextProvider}.
*
* This is ultimately to integrate a JUnit5 @TestTemplate with PDSL.
*/
public class PdslTestParameter {
private final Optional> recognizedByParser;
private final Optional> recognizedByLexer;
private final Class extends Parser> parser;
private final Class extends Lexer> lexer;
private final Optional> listener;
private final Optional>> visitor;
private final Optional> interpreterParams;
private final String tagExpression;
private final String[] includesResources;
private final String[] excludesResources;
private final String startRule;
private final Optional recognizerRule;
private PdslTestParameter(Builder builder) {
Preconditions.checkArgument((builder.listener.isPresent()
^ builder.visitor.isPresent() ^ builder.interpreterParams.isPresent()),
"You can only have one of a visitor, listener or list of interpreterDtos!");
this.parser = builder.parser;
this.lexer = builder.lexer;
this.listener = builder.listener;
this.visitor = builder.visitor;
this.tagExpression = builder.tagExpression;
this.includesResources = builder.includesResources;
this.excludesResources = builder.excludesResources;
this.startRule = builder.startRule;
this.recognizerRule = builder.recognizerRule;
this.recognizedByLexer = builder.recognizedByLexer;
this.recognizedByParser = builder.recognizedByParser;
this.interpreterParams = builder.interpreterParams;
}
public Optional> getInterpreters() { return interpreterParams; }
public Optional> getRecognizedByParser() {
return recognizedByParser;
}
public Optional> getRecognizedByLexer() {
return recognizedByLexer;
}
public Class extends Parser> getParser() {
return parser;
}
public Class extends Lexer> getLexer() {
return lexer;
}
public Optional> getListener() {
return listener;
}
public Optional>> getVisitor() {
return visitor;
}
public String getTagExpression() {
return tagExpression;
}
public String[] getIncludesResources() {
return includesResources;
}
public String[] getExcludesResources() {
return excludesResources;
}
public String getStartRule() {
return startRule;
}
public Optional getRecognizerRule() {
return recognizerRule;
}
public static class Builder {
private Class extends Parser> parser;
private Class extends Lexer> lexer;
private Optional> recognizedByParser = Optional.empty();
private Optional> recognizedByLexer = Optional.empty();
private Optional> listener = Optional.empty();
private Optional>> visitor = Optional.empty();
private String tagExpression = "";
private String[] includesResources = {"*.feature"};
private String[] excludesResources = {};
private String startRule = DEFAULT_ALL_RULE;
private Optional recognizerRule = Optional.empty();
private Optional> interpreterParams = Optional.empty();
public Builder(
Class extends Lexer> lexer,
Class extends Parser> parser,
Supplier extends ParseTreeVisitor>> visitor
) {
Preconditions.checkNotNull(parser, "Parser cannot be null!");
Preconditions.checkNotNull(lexer, "Lexer cannot be null!");
Preconditions.checkNotNull(visitor, "Visitor cannot be null!");
this.parser = parser;
this.lexer = lexer;
this.visitor = Optional.of(visitor);
}
public Builder(List interpreters) {
withInterpreters(interpreters);
}
public Builder(
Supplier extends ParseTreeListener> listener,
Class extends Lexer> lexer,
Class extends Parser> parser
) {
Preconditions.checkNotNull(parser, "Parser cannot be null!");
Preconditions.checkNotNull(lexer, "Lexer cannot be null!");
Preconditions.checkNotNull(listener, "Visitor cannot be null!");
this.parser = parser;
this.lexer = lexer;
this.listener = Optional.of(listener);
}
public Builder withRecognizer(Class extends Lexer> recognizedByLexer, Class extends Parser> recognizedByParser) {
if (recognizedByLexer == null ^ recognizedByParser == null) {
throw new IllegalArgumentException("If a null lexer or parser is specified then both must be null!");
}
this.recognizedByLexer = Optional.ofNullable(recognizedByLexer);
this.recognizedByParser = Optional.ofNullable(recognizedByParser);
return this;
}
public Builder withParser(Class extends Parser> parser) {
Preconditions.checkNotNull(parser, "Parser cannot be null!");
this.parser = parser;
this.interpreterParams = Optional.empty();
return this;
}
public Builder withLexer( Class extends Lexer> lexer) {
Preconditions.checkNotNull(lexer, "Lexer cannot be null!");
this.lexer = lexer;
this.interpreterParams = Optional.empty();
return this;
}
public Builder withInterpreters(List interpreters) {
Preconditions.checkNotNull(interpreters, "InterpreterParams cannot be null!");
Preconditions.checkArgument(!interpreters.isEmpty(), "Interpreter params cannot be empty!");
interpreters.forEach(i -> Preconditions.checkNotNull(i, "InterpreterDto cannot be null!"));
interpreters.forEach(i -> Preconditions.checkNotNull(i.interpreterObj(), "InterpreterObj cannot be null!"));
this.interpreterParams = Optional.of(interpreters);
return this;
}
public Builder withListener( Supplier extends ParseTreeListener> listener) {
this.listener = Optional.of(listener);
return this;
}
public Builder withVisitor(Supplier extends ParseTreeVisitor>> visitor) {
this.visitor = Optional.of(visitor);
return this;
}
public Builder withTagExpression(String str) {
Preconditions.checkNotNull(str, "Tag expression cannot be null!");
this.tagExpression = str;
return this;
}
public Builder withIncludedResources(String[] resources) {
this.includesResources = resources;
return this;
}
public Builder withExcludedResources(String[] excludes) {
this.excludesResources = excludes;
return this;
}
public Builder withStartRule(String startRule) {
Preconditions.checkNotNull(startRule, "start rule cannot be null!");
this.startRule = startRule;
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 = Optional.of(recognizerRule);
return this;
}
public PdslTestParameter build() {
return new PdslTestParameter(this);
}
}
}