Package core.apiCore.helpers
Class CsvReader
- java.lang.Object
-
- core.apiCore.helpers.CsvReader
-
public class CsvReader extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static StringACTION_KEYstatic StringOPTION_RUN_COUNTstatic intSERVICE_CSV_COLUMN_COUNTstatic StringSERVICE_CSV_DATAPROVIDER_COUNTstatic StringSERVICE_CSV_FILE_PREFIXstatic StringSERVICE_CSV_INCLUDE_SUB_DIRstatic StringSERVICE_CSV_SEPARATORstatic intSERVICE_CSV_VISIBLE_COLUMN_COUNTstatic StringSERVICE_EXCLUDE_LISTstatic StringSERVICE_INCLUDE_LISTstatic StringSERVICE_RUN_COUNTstatic StringSERVICE_RUN_CURRENT_COUNTstatic StringSERVICE_RUN_PREFIXstatic StringSERVICE_STEP_PREFIX
-
Constructor Summary
Constructors Constructor Description CsvReader()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static List<Object[]>addActionCsvTests(List<Object[]> csvList)update csv test list with tests from action csv files eg.static voiddetectDuplicateTests(List<Object[]> testCaseList)print out warning for duplicated test namesstatic voidevaluateOption(ServiceObject serviceObject)set run count for individual test casestatic ArrayList<File>filterTests()static voidgetAllKeywords()gets all keywords And stores them in apiMap in testObjectstatic voidgetAllTestCases(String testPath, String prefix)gets all test cases from testcase path based on prefixstatic intgetColumnIndexByName(String column, String[] row)gets column name by the column namestatic intgetCsvFileCount()static StringgetCsvFileFromIndex(int index)returns current csv test filestatic intgetCsvFileIndex(String fileName)returns the index of the file from the list of csv filesstatic intgetCsvFileIndex(String csvDir, String fileName)returns the index of the file from the list of csv filesstatic ArrayList<File>getCsvFileList(String csvTestPath)returns a list of all csv test filesstatic intgetCsvTestcount()get the number of tests in csv filestatic List<Object[]>getCsvTestList(File file)reads csv file and returns the list of rows include and exclude tests eg.static List<Object[]>getCsvTestListForTestRunner(String csvFile)gets csv tests list for service testsstatic List<Object[]>getCsvTestListForTestRunner(String csvDir, String csvInfo)gets csv tests list for service tests include and exclude tests eg.static intgetCurrentTestInvocation()gets csv file index does not increment When retrystatic intgetFileIndex(ArrayList<File> testCsvFileList, String csvFile)static List<Object[]>getMatchingTestId(String[] testIds, List<Object[]> testRows)matches testIds with csv data rows TestIdstatic String[]getTestCaseIds(String testFileInfo)gets a list of test case ids from testFile:testcaseId info Used for actions and test base testcase ids separated by "," format: testFile:testcaseId1,testcaseId2static List<Object>getTestCasesFromCsvFile()gets the tests from csv file based on the current test file indexstatic ArrayList<File>getTestDataCsvFileList()returns a list of all csv test filesstatic StringgetTestname(String fullTestname)get test name without test step identifierstatic Map<String,List<Object[]>>getTestStepMap(List<Object[]> csvList)get map of test cases with test steps removes test step prefix from test case idstatic booleanisRunningServiceTest()static booleanisValidTestFileType(String filename)returns if file is valid service test typestatic Map<String,ServiceObject>mapToApiObject(List<Object[]> testCases)maps list of test cases to service object mapstatic ServiceObjectmapToServiceObject(Object[] testData)test data array to service objectstatic com.opencsv.CSVReaderreadCsvFile(File file)static intsetTestRangeIndex()sets the index of the file specified in include and exclude testsstatic List<Object[]>setTestRerun(List<Object[]> testCaseList)set test cases based on run countstatic List<Object[]>setTestSteps(List<Object[]> csvList, Map<String,List<Object[]>> testStepMap)update test cases base on test steps (combining test steps with _step#number postfix.static List<Object[]>updateCsvFileFromFile(List<Object[]> csvList, String csvFileName, Map<String,List<Object[]>> testStepMap)update csv test list with additional meta data (csv file name, test index, service type, test count) if test case is set then single test is returned
-
-
-
Field Detail
-
SERVICE_CSV_COLUMN_COUNT
public static int SERVICE_CSV_COLUMN_COUNT
-
SERVICE_CSV_VISIBLE_COLUMN_COUNT
public static int SERVICE_CSV_VISIBLE_COLUMN_COUNT
-
SERVICE_CSV_FILE_PREFIX
public static String SERVICE_CSV_FILE_PREFIX
-
ACTION_KEY
public static final String ACTION_KEY
- See Also:
- Constant Field Values
-
SERVICE_CSV_SEPARATOR
public static final String SERVICE_CSV_SEPARATOR
- See Also:
- Constant Field Values
-
SERVICE_CSV_DATAPROVIDER_COUNT
public static final String SERVICE_CSV_DATAPROVIDER_COUNT
- See Also:
- Constant Field Values
-
SERVICE_CSV_INCLUDE_SUB_DIR
public static final String SERVICE_CSV_INCLUDE_SUB_DIR
- See Also:
- Constant Field Values
-
SERVICE_INCLUDE_LIST
public static final String SERVICE_INCLUDE_LIST
- See Also:
- Constant Field Values
-
SERVICE_EXCLUDE_LIST
public static final String SERVICE_EXCLUDE_LIST
- See Also:
- Constant Field Values
-
OPTION_RUN_COUNT
public static final String OPTION_RUN_COUNT
- See Also:
- Constant Field Values
-
SERVICE_RUN_COUNT
public static final String SERVICE_RUN_COUNT
- See Also:
- Constant Field Values
-
SERVICE_RUN_CURRENT_COUNT
public static final String SERVICE_RUN_CURRENT_COUNT
- See Also:
- Constant Field Values
-
SERVICE_RUN_PREFIX
public static final String SERVICE_RUN_PREFIX
- See Also:
- Constant Field Values
-
SERVICE_STEP_PREFIX
public static final String SERVICE_STEP_PREFIX
- See Also:
- Constant Field Values
-
-
Method Detail
-
getTestCasesFromCsvFile
public static List<Object> getTestCasesFromCsvFile()
gets the tests from csv file based on the current test file index- Returns:
-
setTestRangeIndex
public static int setTestRangeIndex()
sets the index of the file specified in include and exclude tests- Parameters:
index-- Returns:
-
detectDuplicateTests
public static void detectDuplicateTests(List<Object[]> testCaseList)
print out warning for duplicated test names- Parameters:
testCaseList-
-
setTestSteps
public static List<Object[]> setTestSteps(List<Object[]> csvList, Map<String,List<Object[]>> testStepMap)
update test cases base on test steps (combining test steps with _step#number postfix. eg. verifyUser_step1, verifyUser_step2- Parameters:
testCaseList-- Returns:
-
getTestname
public static String getTestname(String fullTestname)
get test name without test step identifier- Parameters:
csvRow-- Returns:
-
getTestStepMap
public static Map<String,List<Object[]>> getTestStepMap(List<Object[]> csvList)
get map of test cases with test steps removes test step prefix from test case id- Parameters:
csvList-- Returns:
-
setTestRerun
public static List<Object[]> setTestRerun(List<Object[]> testCaseList)
set test cases based on run count- Parameters:
testCaseList-- Returns:
-
updateCsvFileFromFile
public static List<Object[]> updateCsvFileFromFile(List<Object[]> csvList, String csvFileName, Map<String,List<Object[]>> testStepMap)
update csv test list with additional meta data (csv file name, test index, service type, test count) if test case is set then single test is returned- Parameters:
csvList-csvFileName-testCaseFile-- Returns:
-
addActionCsvTests
public static List<Object[]> addActionCsvTests(List<Object[]> csvList)
update csv test list with tests from action csv files eg. action:createUser.csv:createUser, updateUser or action:createUser.csv- Parameters:
testData-- Returns:
-
getTestCaseIds
public static String[] getTestCaseIds(String testFileInfo)
gets a list of test case ids from testFile:testcaseId info Used for actions and test base testcase ids separated by "," format: testFile:testcaseId1,testcaseId2- Parameters:
testFileInfo-- Returns:
-
getMatchingTestId
public static List<Object[]> getMatchingTestId(String[] testIds, List<Object[]> testRows)
matches testIds with csv data rows TestId- Parameters:
testIds-testRows-- Returns:
-
mapToApiObject
public static Map<String,ServiceObject> mapToApiObject(List<Object[]> testCases)
maps list of test cases to service object map- Parameters:
testCases-- Returns:
-
mapToServiceObject
public static ServiceObject mapToServiceObject(Object[] testData)
test data array to service object- Parameters:
testData-- Returns:
-
getAllTestCases
public static void getAllTestCases(String testPath, String prefix)
gets all test cases from testcase path based on prefix
-
getAllKeywords
public static void getAllKeywords()
gets all keywords And stores them in apiMap in testObject
-
getCurrentTestInvocation
public static int getCurrentTestInvocation()
gets csv file index does not increment When retry- Returns:
-
isRunningServiceTest
public static boolean isRunningServiceTest()
-
getCsvFileFromIndex
public static String getCsvFileFromIndex(int index)
returns current csv test file- Returns:
-
getCsvFileCount
public static int getCsvFileCount()
-
getTestDataCsvFileList
public static ArrayList<File> getTestDataCsvFileList()
returns a list of all csv test files- Returns:
-
getCsvFileList
public static ArrayList<File> getCsvFileList(String csvTestPath)
returns a list of all csv test files- Parameters:
csvTestPath- : full path to csv directory- Returns:
-
getCsvFileIndex
public static int getCsvFileIndex(String fileName)
returns the index of the file from the list of csv files- Parameters:
fileName-- Returns:
-
getCsvFileIndex
public static int getCsvFileIndex(String csvDir, String fileName)
returns the index of the file from the list of csv files- Parameters:
fileName-- Returns:
-
getCsvTestListForTestRunner
public static List<Object[]> getCsvTestListForTestRunner(String csvFile)
gets csv tests list for service tests- Parameters:
csvFile-- Returns:
-
getCsvTestListForTestRunner
public static List<Object[]> getCsvTestListForTestRunner(String csvDir, String csvInfo)
gets csv tests list for service tests include and exclude tests eg. include: TestCases_UserValidation.csv:createUser-createUserNoToken, createUserInvalidToken; eg. exclude: TestCases_UserValidation.csv:createUser-createUserNoToken, createUserInvalidToken;- Parameters:
csvInfo-- Returns:
-
getCsvTestList
public static List<Object[]> getCsvTestList(File file)
reads csv file and returns the list of rows include and exclude tests eg. include: TestCases_UserValidation.csv:createUser-createUserNoToken, createUserInvalidToken; eg. exclude: TestCases_UserValidation.csv:createUser-createUserNoToken, createUserInvalidToken;- Parameters:
file-- Returns:
-
readCsvFile
public static com.opencsv.CSVReader readCsvFile(File file)
-
getColumnIndexByName
public static int getColumnIndexByName(String column, String[] row)
gets column name by the column name- Parameters:
column- : column namerow- : header row- Returns:
-
getCsvTestcount
public static int getCsvTestcount()
get the number of tests in csv file- Returns:
-
isValidTestFileType
public static boolean isValidTestFileType(String filename)
returns if file is valid service test type- Parameters:
filename-- Returns:
-
evaluateOption
public static void evaluateOption(ServiceObject serviceObject)
set run count for individual test case- Parameters:
serviceObject-
-
-