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

com.intuit.karate.core.Scenario Maven / Gradle / Ivy

There is a newer version: 1.4.1
Show newest version
/*
 * The MIT License
 *
 * Copyright 2018 Intuit Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package com.intuit.karate.core;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 *
 * @author pthomas3
 */
public class Scenario {

    public static final String TYPE = "scenario";
    public static final String KEYWORD = "Scenario";

    private final Feature feature;
    private final FeatureSection section;
    private final int index;

    private List tags;
    private int line;
    private String name;
    private String description;
    private List steps;
    private boolean outline;

    public Scenario(Feature feature, FeatureSection section, int index) {
        this.feature = feature;
        this.section = section;
        this.index = index;
    }
    
    public String getDisplayMeta() {
        int num = section.getIndex() + 1;
        String meta = "[#" + num;
        if (index != -1) {
            meta = meta + " eg " + (index + 1);
        }
        return meta + " line " + line + "]";
    }    

    public List getStepsIncludingBackground() { 
        List background = feature.isBackgroundPresent() ? feature.getBackground().getSteps() : null;
        int count = background == null ? steps.size() : steps.size() + background.size();
        List temp = new ArrayList(count);
        if (background != null) {
            temp.addAll(background);
        }
        temp.addAll(steps);
        return temp;
    }
    
    public String getKeyword() {
        return outline ? ScenarioOutline.KEYWORD : KEYWORD;
    }
    
    private Collection tagsEffective; // cache

    public Collection getTagsEffective() {
        if (tagsEffective == null) {
            tagsEffective = Tags.merge(feature.getTags(), tags);
        }
        return tagsEffective;
    }    

    public FeatureSection getSection() {
        return section;
    }

    public Feature getFeature() {
        return feature;
    }
   
    public int getIndex() {
        return index;
    }

    public int getLine() {
        return line;
    }

    public void setLine(int line) {
        this.line = line;
    }

    public List getTags() {
        return tags;
    }

    public void setTags(List tags) {
        this.tags = tags;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public List getSteps() {
        return steps;
    }

    public void setSteps(List steps) {
        this.steps = steps;
    }

    public boolean isOutline() {
        return outline;
    }

    public void setOutline(boolean outline) {
        this.outline = outline;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy