cookercucumber_parser.fileGenerationFactory.GenMain 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.fileGenerationFactory;
import common.fileFactory.FileUtility;
import cookercucumber_parser.kitchenShelf.Ingredients;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import static cookercucumber_parser.fileGenerationFactory.FeatureFileGenerator.genFeatureFile;
import static cookercucumber_parser.fileGenerationFactory.TestRunnerGenerator.genTestRunner;
/**
* This Class is used to Generate Test Runners and Feature Files in the Specified Directory
* It Contains Static Methods
*/
public class GenMain {
////////////////////////////////////////////////////////////////////////////////
//GetAll Needed Values from Ingredients Class
private static String GenFeatureFilesFullPath = Ingredients.getFgFullGenPath();
private static String StepDefPackageName = Ingredients.getStepDefPackage();
private static Map CustomPlaceHolders = Ingredients.getCustomPlaceHolders();
private static String GenTestRunnersFullPath = Ingredients.getTrFullGenPath();
////////////////////////////////////////////////////////////////////////////////
/**
* This Method is used to generate TestRunner Files and Feature Files in Generated.TestRunners and Generated.FeatureFiles Directory
* Author : Manjunath Prabhakar ([email protected])
*
* @param pFileName //Feature Name Only
* @param pFeatureContent //Feature Content
*/
public static void genFiles(String pFileName, String pFeatureContent) {
//If Feature Name has any symbols, remove it
pFileName = pFileName.replaceAll("[^A-Za-z0-9\\s]", "");
//if the first letter of feature name is a number, then replace it with 'F'
char c = pFileName.charAt(0);
if (c >= '0' && c <= '9') {
pFileName = "F" + pFileName.substring(pFileName.length() - 1);
}
//Replace all Spaces with UnderScore
pFileName = pFileName.replace(" ", "_");
//Store Feature Name in another String
String feature = pFileName;
//Get a Random Number
String randNum = RandomNumberGenerator.genRandomNumber();
//Create a File Name with Feature underscore and Random number
String fileName = feature + "_" + randNum;
//Create a Full Feature File Path
String fullFeaturePath = GenFeatureFilesFullPath + fileName + ".feature";
//Initlize deafult placeholders for Test Runners
//Required : featureFilePath, StepDefs Package,
Map defaultPlaceholder = new HashMap();
defaultPlaceholder.put("featurefilepath", fullFeaturePath);
defaultPlaceholder.put("stepdefpackage", StepDefPackageName); //Step Defination Package Name
defaultPlaceholder.put("fileName", fileName); //fileName needed for creating Test Runner class name
//Get Custom Place Holders from Ingredeints(Maven Plugin) for Test Runners
Map customPlaceholder = CustomPlaceHolders;
//Call Generate Test Runner Method to Create Test Runners
genTestRunner(defaultPlaceholder, customPlaceholder, GenTestRunnersFullPath + fileName);
//Call Generate Feature Files Method to Create Feature Files
//Add 'Auto Generated Line'
pFeatureContent = pFeatureContent + "\n\n" + "# Auto Generated by Cooker Cucumber Maven Plugin";
genFeatureFile(pFeatureContent, GenFeatureFilesFullPath + fileName);
}
/**
* This Method is used to perfrom deletion and creation of Generated.TestRunners and Generated.FeatureFiles Directory
* It uses static methods from FileUtils Class
* Author : Manjunath Prabhakar ([email protected])
*/
public static void deleteAndCreateDir() {
//Delete Old Generated.FeatureFiles Directory
FileUtility.deleteRunnerandFeatureDir(new File(GenFeatureFilesFullPath));
//Delete Old Generated.TestRunners Directory
FileUtility.deleteRunnerandFeatureDir(new File(GenTestRunnersFullPath));
//Create New Generated.FeatureFiles Directory
FileUtility.createRunnerandFeatureDir(new File(GenFeatureFilesFullPath));
//Create New Generated.TestRunners Directory
FileUtility.createRunnerandFeatureDir(new File(GenTestRunnersFullPath));
}
}