cookercucumber_parser.featureParserFactory.FeatureUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cooker-maven-plugin Show documentation
Show all versions of cooker-maven-plugin Show documentation
Derives smallest Feature File, Allows Data from Excel(xls and xlsx) and Also provides a clear and
concise reporting
package cookercucumber_parser.featureParserFactory;
import gherkin.ast.*;
import java.util.ArrayList;
import java.util.List;
public class FeatureUtils implements FeatureDocument {
private Feature feature = null;
private StringBuilder result = new StringBuilder();
private String sFeatureKeyword;
private String sFeatureName;
private String sfeatureLanguage;
private String sfeatureDescription;
private List sfeatureLevelTags;
private List sfeaturescenarios;
public FeatureUtils(Feature pFeature) {
this.feature = pFeature;
sFeatureKeyword = this.feature.getKeyword();
sFeatureName = this.feature.getName();
sfeatureLanguage = this.feature.getLanguage();
sfeatureDescription = this.feature.getDescription() == null ? "" : this.feature.getDescription();
sfeatureLevelTags = this.feature.getTags();
sfeaturescenarios = this.feature.getChildren();
}
public String getsFeatureKeyword() {
return sFeatureKeyword;
}
public String getsFeatureName() {
return sFeatureName;
}
public String getSfeatureLanguage() {
return sfeatureLanguage;
}
public String getSfeatureDescription() {
return sfeatureDescription;
}
/**
* Read the Feature Object and Parse it and get it's Content in as String
* Author : Manjunath Prabhakar ([email protected])
*
* @return String Content of Feature Object
*/
public String getFeatureData() {
try {
if (feature == null) {
System.out.println("empty");
/**
* THROW ERROR AS ITS EMPTY FILE
*/
}
String fTagData = getFeatureTags();
this.result.append(fTagData);
this.result.append(System.getProperty("line.separator"));
this.result.append(sFeatureKeyword).append(": ").append(sFeatureName);
this.result.append(sfeatureDescription);
this.result.append(System.getProperty("line.separator"));
this.result.append("#Language : ").append(sfeatureLanguage);
this.result.append(System.getProperty("line.separator"));
for (ScenarioDefinition scenarioDefinition : sfeaturescenarios) {
if (scenarioDefinition instanceof Background) {
Background background = (Background) scenarioDefinition;
BackgroundUtils backgroundUtils = new BackgroundUtils(background);
String fBackgroundData = backgroundUtils.getBackgroundData();
this.result.append(fBackgroundData);
}
if (scenarioDefinition instanceof Scenario) {
Scenario scenario = (Scenario) scenarioDefinition;
ScenarioUtils scenarioUtils = new ScenarioUtils(scenario);
String fScenarioData = scenarioUtils.getScenarioData();
this.result.append(fScenarioData);
}
if (scenarioDefinition instanceof ScenarioOutline) {
ScenarioOutline scenarioOutline = (ScenarioOutline) scenarioDefinition;
ScenarioOutlineUtils scenarioOutlineUtils = new ScenarioOutlineUtils(scenarioOutline);
String fScenarioOutlineData = scenarioOutlineUtils.getScenarioOutlineData();
this.result.append(fScenarioOutlineData);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return String.valueOf(this.result);
}
public String getFeatureTags() {
StringBuilder FeatureTags = new StringBuilder();
try {
for (Tag tag : sfeatureLevelTags) {
TagUtils tagUtils = new TagUtils(tag);
FeatureTags.append(tagUtils.getTagsData());
}
} catch (Exception e) {
e.printStackTrace();
}
return String.valueOf(FeatureTags);
}
public List getFeatureTagsList() {
List res = new ArrayList();
try {
for (Tag tag : sfeatureLevelTags) {
TagUtils tagUtils = new TagUtils(tag);
res.add(tagUtils.getTagsData().trim());
}
} catch (Exception e) {
e.printStackTrace();
}
return res;
}
}