本文整理汇总了Java中gherkin.ast.ScenarioDefinition类的典型用法代码示例。如果您正苦于以下问题:Java ScenarioDefinition类的具体用法?Java ScenarioDefinition怎么用?Java ScenarioDefinition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ScenarioDefinition类属于gherkin.ast包,在下文中一共展示了ScenarioDefinition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseGherkinSource
import gherkin.ast.ScenarioDefinition; //导入依赖的package包/类
private void parseGherkinSource(final String path) {
if (!pathToReadEventMap.containsKey(path)) {
return;
}
final Parser<GherkinDocument> parser = new Parser<>(new AstBuilder());
final TokenMatcher matcher = new TokenMatcher();
try {
final GherkinDocument gherkinDocument = parser.parse(pathToReadEventMap.get(path).source, matcher);
pathToAstMap.put(path, gherkinDocument);
final Map<Integer, AstNode> nodeMap = new HashMap<>();
final AstNode currentParent = new AstNode(gherkinDocument.getFeature(), null);
for (ScenarioDefinition child : gherkinDocument.getFeature().getChildren()) {
processScenarioDefinition(nodeMap, child, currentParent);
}
pathToNodeMap.put(path, nodeMap);
} catch (ParserException e) {
LOGGER.trace(e.getMessage(), e);
}
}
示例2: getRecipes
import gherkin.ast.ScenarioDefinition; //导入依赖的package包/类
protected List<Recipe> getRecipes(FeatureWrapper feature, Collection<Pickle> pickles) {
int pickleCount = pickles.size();
ArrayList<Recipe> recipes = Lists.newArrayListWithExpectedSize(pickleCount);
Set<Integer> pickleLines = Sets.newHashSetWithExpectedSize(pickleCount);
RangeMap<Integer, ScenarioDefinition> rangeMap = getRangeMap(feature);
for (Pickle pickle : pickles) {
List<PickleLocation> locations = pickle.getLocations();
for (PickleLocation location : locations) {
int line = location.getLine();
if (!pickleLines.contains(line)) {
pickleLines.add(line);
Range<Integer> range = Range.singleton(line);
RangeMap<Integer, ScenarioDefinition> subRangeMap = rangeMap.subRangeMap(range);
Map<Range<Integer>, ScenarioDefinition> asMap = subRangeMap.asMapOfRanges();
checkState(1 == asMap.size(), "no single range found encompassing PickleLocation %s", location);
ScenarioDefinition definition = Iterables.getOnlyElement(asMap.values());
Recipe recipe = new Recipe(feature, pickle, location, definition);
recipes.add(recipe);
}
}
}
return recipes;
}
示例3: getRangeMap
import gherkin.ast.ScenarioDefinition; //导入依赖的package包/类
protected RangeMap<Integer, ScenarioDefinition> getRangeMap(FeatureWrapper feature) {
List<ScenarioDefinition> children = Lists.newArrayList(feature.getChildren());
ImmutableRangeMap.Builder<Integer, ScenarioDefinition> builder = ImmutableRangeMap.builder();
while (!children.isEmpty()) {
ScenarioDefinition child = children.remove(0);
Location location = child.getLocation();
Integer childStart = location.getLine();
ScenarioDefinition sibling = children.isEmpty() ? null : children.get(0);
Location siblingLocation = null == sibling ? null : sibling.getLocation();
Integer siblingStart = null == siblingLocation ? null : siblingLocation.getLine();
Range<Integer> range = null == siblingStart ? Range.atLeast(childStart) : Range.closedOpen(childStart, siblingStart);
builder.put(range, child);
}
return builder.build();
}
示例4: createTestCases
import gherkin.ast.ScenarioDefinition; //导入依赖的package包/类
private void createTestCases(Scenario scenario, Feature feature) {
for (ScenarioDefinition scenarioDef : feature.getChildren()) {
String scenDefName = scenarioDef.getName();
TestCase testCase = updateInfo(createTestCase(scenario, scenDefName), scenarioDef);
testCase.clearSteps();
for (Step step : scenarioDef.getSteps()) {
String reusableName = convert(step.getText());
TestCase reusable = updateInfo(createReusable(create("StepDefinitions"), reusableName), step);
if (reusable != null) {
reusable.addNewStep()
.setInput(getInputField(testCase.getName(), step.getText()))
.setDescription(getDescription(step));
}
testCase.addNewStep()
.asReusableStep("StepDefinitions", reusableName)
.setDescription(getDescription(step));
}
if (scenarioDef instanceof ScenarioOutline) {
ScenarioOutline scOutline = (ScenarioOutline) scenarioDef;
createTestData(testCase, scOutline.getExamples());
}
}
}
示例5: updateInfo
import gherkin.ast.ScenarioDefinition; //导入依赖的package包/类
private TestCase updateInfo(TestCase tc, ScenarioDefinition sdef) {
if (tc != null) {
DataItem tcInfo = pModel().getData().find(tc.getName(), tc.getScenario().getName())
.orElseGet(() -> {
DataItem di = DataItem.createTestCase(tc.getName(), tc.getScenario().getName());
pModel().addData(di);
return di;
});
List<gherkin.ast.Tag> tags = getTags(sdef);
if (tags != null) {
tcInfo.setTags(toTag(tags));
}
tcInfo.getAttributes().update(Attribute.create("feature.children.line", sdef.getLocation().getLine()));
tcInfo.getAttributes().update(Attribute.create("feature.children.name", sdef.getName()));
tcInfo.getAttributes().update(Attribute.create("description", sdef.getDescription()));
tcInfo.getAttributes().update(Attribute.create("feature.children.keyword", sdef.getKeyword()));
pModel().addData(tcInfo);
}
return tc;
}
示例6: compile
import gherkin.ast.ScenarioDefinition; //导入依赖的package包/类
public List<Pickle> compile(GherkinDocument gherkinDocument, String path) {
List<Pickle> pickles = new ArrayList<>();
Feature feature = gherkinDocument.getFeature();
if (feature == null) {
return pickles;
}
List<Tag> featureTags = feature.getTags();
List<PickleStep> backgroundSteps = new ArrayList<>();
for (ScenarioDefinition scenarioDefinition : feature.getChildren()) {
if (scenarioDefinition instanceof Background) {
backgroundSteps = pickleSteps(scenarioDefinition, path);
} else if (scenarioDefinition instanceof Scenario) {
compileScenario(pickles, backgroundSteps, (Scenario) scenarioDefinition, featureTags, path);
} else {
compileScenarioOutline(pickles, backgroundSteps, (ScenarioOutline) scenarioDefinition, featureTags, path);
}
}
return pickles;
}
示例7: scenarios
import gherkin.ast.ScenarioDefinition; //导入依赖的package包/类
private List<ScenarioDefinition> scenarios(Feature feature)
{
List<ScenarioDefinition> result = new ArrayList<>();
for (ScenarioDefinition scenario : feature.getChildren())
{
if (isScenarioNormal(scenario))
{
result.add(scenario);
}
else if (isScenarioOutline(scenario))
{
ScenarioOutline scenarioOutline = (ScenarioOutline) scenario;
for (Examples examples : scenarioOutline.getExamples())
{
for (TableRow row : examples.getTableBody())
{
result.add(concreteScenario(scenarioOutline, parametersMap(examples.getTableHeader(), row)));
}
}
}
}
return result;
}
示例8: concreteScenario
import gherkin.ast.ScenarioDefinition; //导入依赖的package包/类
private ScenarioDefinition concreteScenario(ScenarioOutline abstractScenario, Map<String, String> parameters)
{
List<Step> steps = new ArrayList<>();
for (Step step : abstractScenario.getSteps())
{
steps.add(concreteStep(step, parameters));
}
return new gherkin.ast.Scenario(
abstractScenario.getTags(),
abstractScenario.getLocation(),
abstractScenario.getKeyword(),
abstractScenario.getName(),
abstractScenario.getDescription(),
steps);
}
示例9: compile
import gherkin.ast.ScenarioDefinition; //导入依赖的package包/类
public List<Pickle> compile(GherkinDocument gherkinDocument) {
List<Pickle> pickles = new ArrayList<>();
Feature feature = gherkinDocument.getFeature();
if (feature == null) {
return pickles;
}
List<Tag> featureTags = feature.getTags();
List<PickleStep> backgroundSteps = new ArrayList<>();
for (ScenarioDefinition scenarioDefinition : feature.getChildren()) {
if (scenarioDefinition instanceof Background) {
backgroundSteps = pickleSteps(scenarioDefinition);
} else if (scenarioDefinition instanceof Scenario) {
compileScenario(pickles, backgroundSteps, (Scenario) scenarioDefinition, featureTags);
} else {
compileScenarioOutline(pickles, backgroundSteps, (ScenarioOutline) scenarioDefinition, featureTags);
}
}
return pickles;
}
示例10: compile
import gherkin.ast.ScenarioDefinition; //导入依赖的package包/类
public List<Pickle> compile(GherkinDocument gherkinDocument) {
List<Pickle> pickles = new ArrayList<>();
Feature feature = gherkinDocument.getFeature();
if (feature == null) {
return pickles;
}
String language = feature.getLanguage();
List<Tag> featureTags = feature.getTags();
List<PickleStep> backgroundSteps = new ArrayList<>();
for (ScenarioDefinition scenarioDefinition : feature.getChildren()) {
if (scenarioDefinition instanceof Background) {
backgroundSteps = pickleSteps(scenarioDefinition);
} else if (scenarioDefinition instanceof Scenario) {
compileScenario(pickles, backgroundSteps, (Scenario) scenarioDefinition, featureTags, language);
} else {
compileScenarioOutline(pickles, backgroundSteps, (ScenarioOutline) scenarioDefinition, featureTags, language);
}
}
return pickles;
}
示例11: handleTestCaseStarted
import gherkin.ast.ScenarioDefinition; //导入依赖的package包/类
private void handleTestCaseStarted(final TestCaseStarted event) {
currentFeatureFile = event.testCase.getUri();
currentFeature = cucumberSourceUtils.getFeature(currentFeatureFile);
currentTestCase = event.testCase;
final Deque<PickleTag> tags = new LinkedList<>();
tags.addAll(event.testCase.getTags());
final LabelBuilder labelBuilder = new LabelBuilder(currentFeature, event.testCase, tags);
final TestResult result = new TestResult()
.withUuid(getTestCaseUuid(event.testCase))
.withHistoryId(getHistoryId(event.testCase))
.withName(event.testCase.getName())
.withLabels(labelBuilder.getScenarioLabels())
.withLinks(labelBuilder.getScenarioLinks());
final ScenarioDefinition scenarioDefinition =
cucumberSourceUtils.getScenarioDefinition(currentFeatureFile, currentTestCase.getLine());
if (scenarioDefinition instanceof ScenarioOutline) {
result.withParameters(
getExamplesAsParameters((ScenarioOutline) scenarioDefinition)
);
}
if (currentFeature.getDescription() != null && !currentFeature.getDescription().isEmpty()) {
result.withDescription(currentFeature.getDescription());
}
lifecycle.scheduleTestCase(result);
lifecycle.startTestCase(getTestCaseUuid(event.testCase));
}
示例12: processScenarioDefinition
import gherkin.ast.ScenarioDefinition; //导入依赖的package包/类
private void processScenarioDefinition(
final Map<Integer, AstNode> nodeMap, final ScenarioDefinition child, final AstNode currentParent
) {
final AstNode childNode = new AstNode(child, currentParent);
nodeMap.put(child.getLocation().getLine(), childNode);
child.getSteps().forEach(
step -> nodeMap.put(step.getLocation().getLine(), new AstNode(step, childNode))
);
if (child instanceof ScenarioOutline) {
processScenarioOutlineExamples(nodeMap, (ScenarioOutline) child, childNode);
}
}
示例13: translate
import gherkin.ast.ScenarioDefinition; //导入依赖的package包/类
@Override
public SpecflowFileContents translate(List<ScenarioDefinition> scenarios, List<Tag> tags, ITestFrameworkConstants constants) {
String featureContent = scenarios.stream()
.map( scenario -> {
String stepsString = scenario.getSteps().stream()
.map( step -> String.format(StepBody, step.getKeyword(), step.getText()) )
.collect( Collectors.joining( System.getProperty("line.separator")) );
String tagsString = tags.stream()
.map(tg -> String.format("\"%1$s\"", tg.getName()))
.collect(Collectors.joining(","));
return String.format(ScenarioBody,
constants.getTestScenarioMethodHeader(scenario.getName()),
scenario.getName().replaceAll("[^A-Za-z0-9]", ""),
scenario.getName(),
tagsString,
stepsString);
})
.collect( Collectors.joining( System.getProperty("line.separator")) );
List<Step> stepsDone= new ArrayList<>();
String stepString = scenarios.stream()
.map(ScenarioDefinition::getSteps)
.flatMap(List::stream)
.filter(step -> !stepsDone.stream().anyMatch(stepDone -> step.getText() == stepDone.getText() && step.getKeyword() == stepDone.getKeyword()))
.peek(step -> stepsDone.add(step))
.map(step -> String.format(StepsStepsBody,
step.getKeyword(),
step.getText(),
step.getText().replaceAll("[^A-Za-z0-9]", "")))
.collect( Collectors.joining( System.getProperty("line.separator")) );
return new SpecflowFileContents(featureContent, stepString);
}
示例14: analizeCallsCorrectProcess
import gherkin.ast.ScenarioDefinition; //导入依赖的package包/类
@Test
public void analizeCallsCorrectProcess() throws Exception {
Parser<GherkinDocument> parser = (Parser<GherkinDocument>) mock(Parser.class);
ISpecflowTranslator translator = mock(ISpecflowTranslator.class);
ITestFrameworkConstants constants = mock(ITestFrameworkConstants.class);
String document = Faker.getRandomString();
GherkinDocument gherkinDocument = mock(GherkinDocument.class);
when(parser.parse(document)).thenReturn(gherkinDocument);
Feature feature = mock(Feature.class);
List<ScenarioDefinition> scenarios = new ArrayList<>();
List<Tag> tags = new ArrayList<>();
when(feature.getChildren()).thenReturn(scenarios);
when(feature.getTags()).thenReturn(tags);
when(gherkinDocument.getFeature()).thenReturn(feature);
SpecflowFileContents translatedScenarios =new SpecflowFileContents(Faker.getRandomString(), Faker.getRandomString());
SpecflowFileContents translatedFeature =new SpecflowFileContents(Faker.getRandomString(), Faker.getRandomString());
SpecflowFileContents translatedFile =new SpecflowFileContents(Faker.getRandomString(), Faker.getRandomString());
String namespace = Faker.getRandomString();
when(translator.translate(scenarios, tags, constants)).thenReturn(translatedScenarios);
when(translator.translate(feature, translatedScenarios,constants)).thenReturn(translatedFeature);
when(translator.translate(namespace,translatedFeature, constants)).thenReturn(translatedFile);
SpecflowAnalyzer analyzer = new SpecflowAnalyzer(parser, translator, constants);
SpecflowFileContents contents = analyzer.analyze(document, namespace);
verify(parser).parse(document);
assertEquals(translatedFile.feature, contents.feature);
assertEquals(translatedFile.steps, contents.steps);
}
示例15: getMartinis
import gherkin.ast.ScenarioDefinition; //导入依赖的package包/类
@Override
public ImmutableList<Martini> getMartinis() {
synchronized (martinisReference) {
ImmutableList<Martini> martinis = martinisReference.get();
if (null == martinis) {
Map<String, StepImplementation> index = context.getBeansOfType(StepImplementation.class);
Collection<StepImplementation> implementations = index.values();
ImmutableList.Builder<Martini> builder = ImmutableList.builder();
for (Recipe recipe : recipes) {
DefaultMartini.Builder martiniBuilder = DefaultMartini.builder().setRecipe(recipe);
Pickle pickle = recipe.getPickle();
Background background = recipe.getBackground();
ScenarioDefinition scenarioDefinition = recipe.getScenarioDefinition();
List<PickleStep> steps = pickle.getSteps();
for (PickleStep step : steps) {
Step gherkinStep = getGherkinStep(background, scenarioDefinition, step);
StepImplementation implementation = getImplementation(gherkinStep, implementations);
martiniBuilder.add(gherkinStep, implementation);
}
Martini martini = martiniBuilder.build();
builder.add(martini);
}
martinis = builder.build();
martinisReference.set(martinis);
}
return martinis;
}
}