From 25d7e377dd58a0c8e256647960b484a9a7cfcb84 Mon Sep 17 00:00:00 2001 From: Dima Grinevich Date: Tue, 7 Mar 2023 15:31:42 +0300 Subject: [PATCH 01/52] refactor(carina-dataprovider): reduced duplicated code --- .../carina/core/foundation/IAbstractTest.java | 3 +- .../listeners/AbstractTestListener.java | 17 -- .../annotations/CsvDataSourceParameters.java | 27 +-- .../annotations/DataSourceParameters.java | 34 +++ .../annotations/XlsDataSourceParameters.java | 36 +--- .../core/DataProviderFactory.java | 102 +++++---- .../core/groupping/GroupByMapper.java | 3 +- .../core/impl/BaseDataProvider.java | 15 +- .../core/impl/CsvDataProvider.java | 41 ++-- .../core/impl/XlsDataProvider.java | 44 ++-- .../dataprovider/parser/DSBean.java | 199 +++++++----------- 11 files changed, 213 insertions(+), 308 deletions(-) create mode 100644 carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/DataSourceParameters.java diff --git a/carina-core/src/main/java/com/qaprosoft/carina/core/foundation/IAbstractTest.java b/carina-core/src/main/java/com/qaprosoft/carina/core/foundation/IAbstractTest.java index 74242d87c6..fb0d7337f4 100644 --- a/carina-core/src/main/java/com/qaprosoft/carina/core/foundation/IAbstractTest.java +++ b/carina-core/src/main/java/com/qaprosoft/carina/core/foundation/IAbstractTest.java @@ -74,8 +74,7 @@ default Object[][] createData(final ITestNGMethod testMethod, ITestContext conte } @DataProvider(name = "SingleDataProvider") - default Object[][] createDataSingleThread(final ITestNGMethod testMethod, - ITestContext context) { + default Object[][] createDataSingleThread(final ITestNGMethod testMethod, ITestContext context) { Annotation[] annotations = testMethod.getConstructorOrMethod().getMethod().getDeclaredAnnotations(); Object[][] objects = DataProviderFactory.getDataProvider(annotations, context, testMethod); return objects; diff --git a/carina-core/src/main/java/com/qaprosoft/carina/core/foundation/listeners/AbstractTestListener.java b/carina-core/src/main/java/com/qaprosoft/carina/core/foundation/listeners/AbstractTestListener.java index 328998d194..60839879f1 100644 --- a/carina-core/src/main/java/com/qaprosoft/carina/core/foundation/listeners/AbstractTestListener.java +++ b/carina-core/src/main/java/com/qaprosoft/carina/core/foundation/listeners/AbstractTestListener.java @@ -154,23 +154,6 @@ public void onTestStart(ITestResult result) { generateParameters(result); - if (!result.getTestContext().getCurrentXmlTest().getAllParameters() - .containsKey(SpecialKeywords.EXCEL_DS_CUSTOM_PROVIDER) && - result.getParameters().length > 0) // set parameters from XLS only if test contains any parameter at - // all) - { - if (result.getTestContext().getCurrentXmlTest().getAllParameters() - .containsKey(SpecialKeywords.EXCEL_DS_ARGS)) { - DSBean dsBean = new DSBean(result.getTestContext()); - int index = 0; - for (String arg : dsBean.getArgs()) { - dsBean.getTestParams().put(arg, (String) result.getParameters()[index++]); - } - result.getTestContext().getCurrentXmlTest().setParameters(dsBean.getTestParams()); - - } - } - //TODO: do not write STARTED at message for retry! or move it into the DEBUG level! startItem(result, Messager.TEST_STARTED); diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/CsvDataSourceParameters.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/CsvDataSourceParameters.java index 5770a7c4d9..c2fb7df6ad 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/CsvDataSourceParameters.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/CsvDataSourceParameters.java @@ -25,34 +25,9 @@ public @interface CsvDataSourceParameters { String className() default "com.qaprosoft.carina.core.foundation.dataprovider.core.impl.CsvDataProvider"; - String path(); - char separator() default ','; char quote() default '"'; - String dsArgs() default ""; - - String dsUid() default ""; - - String executeColumn() default ""; - - String executeValue() default ""; - - String staticArgs() default ""; - - String groupColumn() default ""; - - String testRailColumn() default ""; - - String qTestColumn() default ""; - - String testMethodColumn() default ""; - - String testMethodOwnerColumn() default ""; - - String bugColumn() default ""; - - String[] doNotRunTestNames() default {}; - + DataSourceParameters data(); } \ No newline at end of file diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/DataSourceParameters.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/DataSourceParameters.java new file mode 100644 index 0000000000..c50c236afa --- /dev/null +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/DataSourceParameters.java @@ -0,0 +1,34 @@ +package com.qaprosoft.carina.core.foundation.dataprovider.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.ANNOTATION_TYPE) +@Retention(RetentionPolicy.RUNTIME) +public @interface DataSourceParameters { + String path() default ""; + + String dsArgs() default ""; + + String dsUid() default ""; + + String executeColumn() default "Execute"; + + String executeValue() default "y"; + + String staticArgs() default ""; + + String groupColumn() default ""; + + String testRailColumn() default ""; + + String qTestColumn() default ""; + + String testMethodColumn() default ""; + + String testMethodOwnerColumn() default ""; + + String bugColumn() default ""; +} diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/XlsDataSourceParameters.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/XlsDataSourceParameters.java index cd53ecbeb2..67438d6238 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/XlsDataSourceParameters.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/XlsDataSourceParameters.java @@ -25,43 +25,9 @@ public @interface XlsDataSourceParameters { String className() default "com.qaprosoft.carina.core.foundation.dataprovider.core.impl.XlsDataProvider"; - /** - * Is mutually exclusive with spreadsheetId - * - * @return String - */ - String path() default ""; - - /** - * Is mutually exclusive with path - * - * @return String - */ String spreadsheetId() default ""; String sheet() default ""; - String dsArgs() default ""; - - String dsUid() default ""; - - String executeColumn() default ""; - - String executeValue() default ""; - - String staticArgs() default ""; - - String groupColumn() default ""; - - String testRailColumn() default ""; - - String qTestColumn() default ""; - - String testMethodColumn() default ""; - - String testMethodOwnerColumn() default ""; - - String bugColumn() default ""; - - String[] doNotRunTestNames() default {}; + DataSourceParameters data(); } diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java index 2e408b49db..93c60d9327 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java @@ -19,12 +19,12 @@ import java.lang.invoke.MethodHandles; import java.lang.reflect.Constructor; import java.lang.reflect.Method; -import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; -import java.util.List; import java.util.Map; +import com.qaprosoft.carina.core.foundation.dataprovider.annotations.CsvDataSourceParameters; +import com.qaprosoft.carina.core.foundation.dataprovider.annotations.XlsDataSourceParameters; import org.apache.commons.lang3.ArrayUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -48,52 +48,21 @@ private DataProviderFactory() { } public static Object[][] getDataProvider(Annotation[] annotations, ITestContext context, ITestNGMethod m) { - Map testNameArgsMap = Collections.synchronizedMap(new HashMap<>()); - Map testMethodOwnerArgsMap = Collections.synchronizedMap(new HashMap<>()); - Map testRailsArgsMap = Collections.synchronizedMap(new HashMap<>()); - List doNotRunTests = Collections.synchronizedList(new ArrayList<>()); - - Object[][] provider = new Object[][] {}; + Object[][] provider = new Object[][]{}; for (Annotation annotation : annotations) { - try { - Class type = annotation.annotationType(); - - String providerClass = ""; - - for (Method method : type.getDeclaredMethods()) { - if (method.getName().equalsIgnoreCase("classname")) { - providerClass = (String) method.invoke(annotation); - break; - } - } - - if (providerClass.isEmpty()) - continue; - - Class clazz; - Object object = null; - try { - clazz = Class.forName(providerClass); - Constructor ctor = clazz.getConstructor(); - object = ctor.newInstance(); - } catch (Exception e) { - LOGGER.error("DataProvider failure", e); - } + String providerClass; + if (annotation instanceof CsvDataSourceParameters || annotation instanceof XlsDataSourceParameters) { + providerClass = findProviderClass(annotation); + } else { + continue; + } - if (object instanceof com.qaprosoft.carina.core.foundation.dataprovider.core.impl.BaseDataProvider) { - BaseDataProvider activeProvider = (BaseDataProvider) object; - provider = ArrayUtils.addAll(provider, activeProvider.getDataProvider(annotation, context, m)); - testNameArgsMap.putAll(activeProvider.getTestNameArgsMap()); - testMethodOwnerArgsMap.putAll(activeProvider.getTestMethodOwnerArgsMap()); - testRailsArgsMap.putAll(activeProvider.getTestRailsArgsMap()); - doNotRunTests.addAll(activeProvider.getDoNotRunRowsIDs()); - } + BaseDataProvider dataProvider = initDataProvider(providerClass); - } catch (Exception e) { - LOGGER.error("DataProvider failure", e); - } + provider = ArrayUtils.addAll(provider, dataProvider.getDataProvider(annotation, context, m)); + testNameArgsMap.putAll(dataProvider.getTestNameArgsMap()); } if (!GroupByMapper.getInstanceInt().isEmpty() || !GroupByMapper.getInstanceStrings().isEmpty()) { @@ -109,6 +78,53 @@ public static Object[][] getDataProvider(Annotation[] annotations, ITestContext return provider; } + /** + * Finds class name for data provider implementation. + * + * @param annotation test method annotation. + * + * @return class name of data provider if it was found in annotation classname() method. + * Empty string if not. + */ + private static String findProviderClass(Annotation annotation) { + Class type = annotation.annotationType(); + String providerClass = ""; + + try { + for (Method method : type.getDeclaredMethods()) { + if (method.getName().equalsIgnoreCase("classname")) { + providerClass = (String) method.invoke(annotation); + break; + } + } + } catch (ReflectiveOperationException e){ + LOGGER.error("Failure on finding DataProvider class instance", e); + } + + return providerClass; + } + + /** + * Initialize DataProvider based on className parameter. + * + * @param providerClass String full className. + * + * @return DataProvider Instance. + */ + private static BaseDataProvider initDataProvider(String providerClass){ + Class clazz; + BaseDataProvider dataProvider = null; + try { + clazz = Class.forName(providerClass); + Constructor ctor = clazz.getConstructor(); + dataProvider = (BaseDataProvider) ctor.newInstance(); + } catch (Exception e) { + LOGGER.error("DataProvider initialization failure", e); + } + + return dataProvider; + } + private static Object[][] getGroupedList(Object[][] provider) { Object[][] finalProvider; if (GroupByMapper.isHashMapped()) { diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/groupping/GroupByMapper.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/groupping/GroupByMapper.java index 1cd0095518..d500d2a660 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/groupping/GroupByMapper.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/groupping/GroupByMapper.java @@ -23,7 +23,6 @@ * Created by Yauheni_Patotski on 1/7/2015. */ public class GroupByMapper { - private static Set instanceInt; private static Set instanceString; @@ -38,6 +37,8 @@ public static void setIsHashMapped(boolean isHashMapped) { GroupByMapper.hashMapped = isHashMapped; } + private GroupByMapper() {} + public static Set getInstanceInt() { if (instanceInt == null) { instanceInt = Collections.synchronizedSet(new HashSet()); diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java index 897aee7924..653ec54355 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java @@ -42,8 +42,6 @@ public abstract class BaseDataProvider { protected List argsList; protected List staticArgsList; - protected List doNotRunTestNames; - public abstract Object[][] getDataProvider(Annotation annotation, ITestContext context, ITestNGMethod testMethod); protected static Object getStaticParam(String name, ITestContext context, DSBean dsBean) { @@ -63,8 +61,17 @@ public Map getTestRailsArgsMap() { return testRailsArgsMap; } - public List getDoNotRunRowsIDs() { - return doNotRunTestNames; + protected void addValueToSpecialMap(Map map, String column, String hashCode, Map row) { + if (column != null) { + if (!column.isEmpty()) { + if (row.get(column) != null) { + if (!row.get(column).isEmpty()) { + // put into the args only non empty jira tickets + map.put(hashCode, row.get(column)); + } + } + } + } } } diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java index 926e6924dc..cf3f335c6f 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java @@ -26,6 +26,7 @@ import java.util.List; import java.util.Map; +import com.qaprosoft.carina.core.foundation.dataprovider.annotations.DataSourceParameters; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testng.ITestContext; @@ -57,37 +58,35 @@ public class CsvDataProvider extends BaseDataProvider { @Override public Object[][] getDataProvider(Annotation annotation, ITestContext context, ITestNGMethod testMethod) { CsvDataSourceParameters parameters = (CsvDataSourceParameters) annotation; - doNotRunTestNames = Arrays.asList(parameters.doNotRunTestNames()); - DSBean dsBean = new DSBean(parameters, context.getCurrentXmlTest().getAllParameters()); char separator, quote; + separator = parameters.separator(); + quote = parameters.quote(); executeColumn = dsBean.getExecuteColumn(); executeValue = dsBean.getExecuteValue(); - separator = parameters.separator(); - quote = parameters.quote(); - - testRailColumn = parameters.testRailColumn(); + DataSourceParameters data = parameters.data(); + testRailColumn = data.testRailColumn(); - if (!parameters.qTestColumn().isEmpty() && testRailColumn.isEmpty()) - testRailColumn = parameters.qTestColumn(); + if (!data.qTestColumn().isEmpty() && testRailColumn.isEmpty()) + testRailColumn = data.qTestColumn(); - testMethodColumn = parameters.testMethodColumn(); - testMethodOwnerColumn = parameters.testMethodOwnerColumn(); - bugColumn = parameters.bugColumn(); + testMethodColumn = data.testMethodColumn(); + testMethodOwnerColumn = data.testMethodOwnerColumn(); + bugColumn = data.bugColumn(); List argsList = dsBean.getArgs(); List staticArgsList = dsBean.getStaticArgs(); - String groupByParameter = parameters.groupColumn(); + String groupByParameter = data.groupColumn(); if (!groupByParameter.isEmpty()) { GroupByMapper.getInstanceInt().add(argsList.indexOf(groupByParameter)); GroupByMapper.getInstanceStrings().add(groupByParameter); } - if (parameters.dsArgs().isEmpty()) { + if (data.dsArgs().isEmpty()) { GroupByMapper.setIsHashMapped(true); } CSVReader reader; @@ -234,18 +233,4 @@ private Integer getIndex(String arg, List headers) { } return index; } - - private void addValueToSpecialMap(Map map, String column, String hashCode, Map csvRow) { - if (column != null) { - if (!column.isEmpty()) { - if (csvRow.get(column) != null) { - if (!csvRow.get(column).isEmpty()) { - // put into the args only non empty jira tickets - map.put(hashCode, csvRow.get(column)); - } - } - } - } - } - -} \ No newline at end of file +} diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java index f562a1843f..65feddb26e 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java @@ -38,44 +38,42 @@ public class XlsDataProvider extends BaseDataProvider { public Object[][] getDataProvider(Annotation annotation, ITestContext context, ITestNGMethod testMethod) { XlsDataSourceParameters parameters = (XlsDataSourceParameters) annotation; - doNotRunTestNames = Arrays.asList(parameters.doNotRunTestNames()); - DSBean dsBean = new DSBean(parameters, context - .getCurrentXmlTest().getAllParameters()); + DSBean dsBean = new DSBean(parameters, context.getCurrentXmlTest().getAllParameters()); XLSTable dsData = XLSParser.parseSpreadSheet(dsBean.getDsFile(), dsBean.getXlsSheet(), dsBean.getExecuteColumn(), dsBean.getExecuteValue()); argsList = dsBean.getArgs(); staticArgsList = dsBean.getStaticArgs(); - if (parameters.dsArgs().isEmpty()) { + if (parameters.data().dsArgs().isEmpty()) { GroupByMapper.setIsHashMapped(true); } - String groupByParameter = parameters.groupColumn(); + String groupByParameter = parameters.data().groupColumn(); if (!groupByParameter.isEmpty()) { GroupByMapper.getInstanceInt().add(argsList.indexOf(groupByParameter)); GroupByMapper.getInstanceStrings().add(groupByParameter); } String testRailColumn = ""; - if (!parameters.testRailColumn().isEmpty()) - testRailColumn = parameters.testRailColumn(); + if (!parameters.data().testRailColumn().isEmpty()) + testRailColumn = parameters.data().testRailColumn(); - if (!parameters.qTestColumn().isEmpty() && testRailColumn.isEmpty()) - testRailColumn = parameters.qTestColumn(); + if (!parameters.data().qTestColumn().isEmpty() && testRailColumn.isEmpty()) + testRailColumn = parameters.data().qTestColumn(); String testMethodColumn = ""; - if (!parameters.testMethodColumn().isEmpty()) - testMethodColumn = parameters.testMethodColumn(); + if (!parameters.data().testMethodColumn().isEmpty()) + testMethodColumn = parameters.data().testMethodColumn(); String testMethodOwnerColumn = ""; - if (!parameters.testMethodOwnerColumn().isEmpty()) - testMethodOwnerColumn = parameters.testMethodOwnerColumn(); + if (!parameters.data().testMethodOwnerColumn().isEmpty()) + testMethodOwnerColumn = parameters.data().testMethodOwnerColumn(); String bugColumn = ""; - if (!parameters.bugColumn().isEmpty()) - bugColumn = parameters.bugColumn(); + if (!parameters.data().bugColumn().isEmpty()) + bugColumn = parameters.data().bugColumn(); int width = 0; if (argsList.size() == 0) { @@ -143,18 +141,4 @@ public Object[][] getDataProvider(Annotation annotation, ITestContext context, I return args; } - - private void addValueToSpecialMap(Map map, String column, String hashCode, Map xlsRow) { - if (column != null) { - if (!column.isEmpty()) { - if (xlsRow.get(column) != null) { - if (!xlsRow.get(column).isEmpty()) { - // put into the args only non empty jira tickets - map.put(hashCode, xlsRow.get(column)); - } - } - } - } - } - -} \ No newline at end of file +} diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/DSBean.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/DSBean.java index 099f99edda..a82e9fbbd5 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/DSBean.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/DSBean.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.Map; +import com.qaprosoft.carina.core.foundation.dataprovider.annotations.DataSourceParameters; import org.apache.commons.lang3.StringUtils; import org.testng.ITestContext; @@ -30,9 +31,9 @@ public class DSBean { Map testParams; - private List args; - private List uidArgs; - private List staticArgs; + private List args = new ArrayList<>(); + private List uidArgs = new ArrayList<>(); + private List staticArgs = new ArrayList<>(); private String dsFile; private String xlsSheet; @@ -48,149 +49,103 @@ public DSBean(ITestContext context) { public DSBean(Map testParams) { this.testParams = testParams; - this.dsFile = testParams.get(SpecialKeywords.EXCEL_DS_FILE); this.xlsSheet = testParams.get(SpecialKeywords.EXCEL_DS_SHEET); - this.args = new ArrayList(); - this.uidArgs = new ArrayList(); - - if (testParams.get(SpecialKeywords.EXCEL_DS_ARGS) != null) { - args = Arrays.asList(testParams.get(SpecialKeywords.EXCEL_DS_ARGS).replace(",", ";").replace(" ", "").split(";")); - } - if (testParams.get(SpecialKeywords.EXCEL_DS_UID) != null) { - uidArgs = Arrays.asList(testParams.get(SpecialKeywords.EXCEL_DS_UID).replace(",", ";").replace(" ", "").split(";")); - } + initParamsFromSuite(testParams, "excel"); } - public DSBean(String xlsFile, String xlsSheet, String dsArgs, String dsUids) { - this.dsFile = xlsFile; - this.xlsSheet = xlsSheet; - this.args = new ArrayList(); - this.uidArgs = new ArrayList(); - - if (dsArgs != null && !dsArgs.isEmpty()) { - args = Arrays.asList(dsArgs.replace(",", ";").replace(" ", "").split(";")); - } - if (dsUids != null && !dsUids.isEmpty()) { - uidArgs = Arrays.asList(dsUids.replace(",", ";").replace(" ", "").split(";")); + public DSBean(XlsDataSourceParameters xlsDataSourceParameters, Map suiteParams) { + // params init order: 1) from test annotation 2) from suite + if (xlsDataSourceParameters != null) { + this.initParamsFromAnnotation(xlsDataSourceParameters.data()); + if (!xlsDataSourceParameters.sheet().isEmpty()) { + xlsSheet = xlsDataSourceParameters.sheet(); + } } - } + if (!suiteParams.isEmpty()) { + initParamsFromSuite(suiteParams, "excel"); + if (suiteParams.get(SpecialKeywords.EXCEL_DS_SHEET) != null) { + this.xlsSheet = suiteParams.get(SpecialKeywords.EXCEL_DS_SHEET); + } + } - public DSBean(XlsDataSourceParameters parameters, Map testParams) { - // initialize default Xls data source parameters from suite xml file - String xlsFile = testParams.get(SpecialKeywords.EXCEL_DS_FILE); - String xlsSheet = testParams.get(SpecialKeywords.EXCEL_DS_SHEET); - String dsArgs = testParams.get(SpecialKeywords.EXCEL_DS_ARGS); - String dsUid = testParams.get(SpecialKeywords.EXCEL_DS_UID); - String dsStaticArgs = ""; - - if (parameters != null) { - // reinitialize parameters from annotation if any - if (!parameters.path().isEmpty() && !parameters.spreadsheetId().isEmpty()) + if (xlsDataSourceParameters != null && !xlsDataSourceParameters.spreadsheetId().isEmpty()) { + if (!this.dsFile.isEmpty()) { throw new InvalidArgsException("Spreadsheet id and path parameters are mutually exclusive"); - if (!parameters.path().isEmpty()) - xlsFile = parameters.path(); - if (!parameters.spreadsheetId().isEmpty()) { - xlsFile = parameters.spreadsheetId(); + } else { + this.dsFile = xlsDataSourceParameters.spreadsheetId(); this.spreadsheet = true; } - - if (!parameters.sheet().isEmpty()) - xlsSheet = parameters.sheet(); - - if (!parameters.dsArgs().isEmpty()) - dsArgs = parameters.dsArgs(); - - if (!parameters.dsUid().isEmpty()) - dsUid = parameters.dsUid(); - - if (!parameters.staticArgs().isEmpty()) - dsStaticArgs = parameters.staticArgs(); } - this.testParams = testParams; - this.dsFile = xlsFile; - this.xlsSheet = xlsSheet; - this.args = new ArrayList(); - this.uidArgs = new ArrayList(); - this.staticArgs = new ArrayList(); + this.testParams = suiteParams; + } - if (dsArgs != null && !dsArgs.isEmpty()) { - args = Arrays.asList(dsArgs.replace(",", ";").replace(" ", "").split(";")); - } - if (dsUid != null && !dsUid.isEmpty()) { - uidArgs = Arrays.asList(dsUid.replace(",", ";").replace(" ", "").split(";")); + public DSBean(CsvDataSourceParameters csvDataSourceParameters, Map suiteParams) { + // initialize default Xls data source parameters from suite xml file + if (csvDataSourceParameters != null) { + this.initParamsFromAnnotation(csvDataSourceParameters.data()); } - if (dsStaticArgs != null && !dsStaticArgs.isEmpty()) { - staticArgs = Arrays.asList(dsStaticArgs.replace(",", ";").replace(" ", "").split(";")); + if (!suiteParams.isEmpty()) { + initParamsFromSuite(suiteParams, ""); } - this.executeColumn = "Execute"; - this.executeValue = "y"; - if (testParams.get(SpecialKeywords.DS_EXECUTE_COLUMN) != null) - this.executeColumn = testParams.get(SpecialKeywords.DS_EXECUTE_COLUMN); - if (testParams.get(SpecialKeywords.DS_EXECUTE_VALUE) != null) - this.executeValue = testParams.get(SpecialKeywords.DS_EXECUTE_VALUE); - - if (!parameters.executeColumn().isEmpty()) - this.executeColumn = parameters.executeColumn(); - if (!parameters.executeValue().isEmpty()) - this.executeValue = parameters.executeValue(); + this.testParams = suiteParams; + this.xlsSheet = null; } - // TODO: Analyze DSBean for XLS and CSV DataProviders and remove code duplicates - public DSBean(CsvDataSourceParameters parameters, Map testParams) { - // initialize default Xls data source parameters from suite xml file - String dsFile = testParams.get(SpecialKeywords.DS_FILE); - String dsArgs = testParams.get(SpecialKeywords.DS_ARGS); - String dsUid = testParams.get(SpecialKeywords.DS_UID); - String dsStaticArgs = ""; - - if (parameters != null) { - // reinitialize parameters from annotation if any - if (!parameters.path().isEmpty()) - dsFile = parameters.path(); - - if (!parameters.dsArgs().isEmpty()) - dsArgs = parameters.dsArgs(); - - if (!parameters.dsUid().isEmpty()) - dsUid = parameters.dsUid(); - - if (!parameters.staticArgs().isEmpty()) - dsStaticArgs = parameters.staticArgs(); + private void initParamsFromAnnotation(DataSourceParameters data) { + if (data != null) { + if (!data.path().isEmpty()) { + this.dsFile = data.path(); + } + if (!data.executeColumn().isEmpty()) { + this.executeColumn = data.executeColumn(); + } + if (!data.executeValue().isEmpty()) { + this.executeValue = data.executeValue(); + } + if (!data.dsArgs().isEmpty()) { + this.args = Arrays.asList(data.dsArgs().replace(" ", "").split(",")); + } + if (!data.dsUid().isEmpty()) { + this.uidArgs = Arrays.asList(data.dsUid().replace(" ", "").split(",")); + } + if (!data.staticArgs().isEmpty()) { + this.staticArgs = Arrays.asList(data.staticArgs().replace(" ", "").split(",")); + } } + } - this.testParams = testParams; - this.dsFile = dsFile; - this.xlsSheet = null; - this.args = new ArrayList(); - this.uidArgs = new ArrayList(); - this.staticArgs = new ArrayList(); - - if (dsArgs != null && !dsArgs.isEmpty()) { - args = Arrays.asList(dsArgs.replace(",", ";").replace(" ", "").split(";")); + private void initParamsFromSuite(Map suiteParams, String specialKeyPrefix) { + if (suiteParams.get(insert(SpecialKeywords.DS_FILE, specialKeyPrefix)) != null) { + this.dsFile = suiteParams.get(insert(SpecialKeywords.DS_FILE, specialKeyPrefix)); } - if (dsUid != null && !dsUid.isEmpty()) { - uidArgs = Arrays.asList(dsUid.replace(",", ";").replace(" ", "").split(";")); + if (suiteParams.get(SpecialKeywords.DS_EXECUTE_COLUMN) != null) { + this.executeColumn = suiteParams.get(SpecialKeywords.DS_EXECUTE_COLUMN); } - - if (dsStaticArgs != null && !dsStaticArgs.isEmpty()) { - staticArgs = Arrays.asList(dsStaticArgs.replace(",", ";").replace(" ", "").split(";")); + if (suiteParams.get(SpecialKeywords.DS_EXECUTE_VALUE) != null) { + this.executeValue = suiteParams.get(SpecialKeywords.DS_EXECUTE_VALUE); + } + if (suiteParams.get(insert(SpecialKeywords.DS_ARGS, specialKeyPrefix)) != null) { + this.args = Arrays.asList(suiteParams.get(insert(SpecialKeywords.DS_ARGS, specialKeyPrefix)) + .replace(" ", "").split(",")); } + if (suiteParams.get(insert(SpecialKeywords.DS_UID, specialKeyPrefix)) != null) { + this.uidArgs = Arrays.asList(suiteParams.get(insert(SpecialKeywords.DS_UID, specialKeyPrefix)) + .replace(" ", "").split(",")); + } +// TODO: Add staticArgs to SpecialKeywords +// if (testParams.get(SpecialKeywords.DS_STATIC_ARGS) != null) { +// dsStaticArgs = testParams.get(SpecialKeywords.DS_STATIC_ARGS); +// } + } - this.executeColumn = "Execute"; - this.executeValue = "y"; - if (testParams.get(SpecialKeywords.DS_EXECUTE_COLUMN) != null) - this.executeColumn = testParams.get(SpecialKeywords.DS_EXECUTE_COLUMN); - if (testParams.get(SpecialKeywords.DS_EXECUTE_VALUE) != null) - this.executeValue = testParams.get(SpecialKeywords.DS_EXECUTE_VALUE); - - if (!parameters.executeColumn().isEmpty()) - this.executeColumn = parameters.executeColumn(); - if (!parameters.executeValue().isEmpty()) - this.executeValue = parameters.executeValue(); + private String insert(String into, String insertion) { + StringBuilder newString = new StringBuilder(into); + newString.insert(1, insertion); + return newString.toString(); } public String getDsFile() { From 01dbefdac9d596b7cf707a409c53036e95c5183e Mon Sep 17 00:00:00 2001 From: Dima Grinevich Date: Thu, 9 Mar 2023 09:34:53 +0300 Subject: [PATCH 02/52] refactor(DataSourceParameters.java): deleted new annotation --- .../annotations/CsvDataSourceParameters.java | 24 +++++++- .../annotations/DataSourceParameters.java | 34 ----------- .../annotations/XlsDataSourceParameters.java | 24 +++++++- .../core/DataProviderFactory.java | 6 +- .../core/impl/CsvDataProvider.java | 18 +++--- .../core/impl/XlsDataProvider.java | 24 ++++---- .../dataprovider/parser/DSBean.java | 57 +++++++++++++------ 7 files changed, 108 insertions(+), 79 deletions(-) delete mode 100644 carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/DataSourceParameters.java diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/CsvDataSourceParameters.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/CsvDataSourceParameters.java index c2fb7df6ad..0255d0665f 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/CsvDataSourceParameters.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/CsvDataSourceParameters.java @@ -29,5 +29,27 @@ char quote() default '"'; - DataSourceParameters data(); + String path() default ""; + + String dsArgs() default ""; + + String dsUid() default ""; + + String executeColumn() default "Execute"; + + String executeValue() default "y"; + + String staticArgs() default ""; + + String groupColumn() default ""; + + String testRailColumn() default ""; + + String qTestColumn() default ""; + + String testMethodColumn() default ""; + + String testMethodOwnerColumn() default ""; + + String bugColumn() default ""; } \ No newline at end of file diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/DataSourceParameters.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/DataSourceParameters.java deleted file mode 100644 index c50c236afa..0000000000 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/DataSourceParameters.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.qaprosoft.carina.core.foundation.dataprovider.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Target(ElementType.ANNOTATION_TYPE) -@Retention(RetentionPolicy.RUNTIME) -public @interface DataSourceParameters { - String path() default ""; - - String dsArgs() default ""; - - String dsUid() default ""; - - String executeColumn() default "Execute"; - - String executeValue() default "y"; - - String staticArgs() default ""; - - String groupColumn() default ""; - - String testRailColumn() default ""; - - String qTestColumn() default ""; - - String testMethodColumn() default ""; - - String testMethodOwnerColumn() default ""; - - String bugColumn() default ""; -} diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/XlsDataSourceParameters.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/XlsDataSourceParameters.java index 67438d6238..661a9e8a6f 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/XlsDataSourceParameters.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/XlsDataSourceParameters.java @@ -29,5 +29,27 @@ String sheet() default ""; - DataSourceParameters data(); + String path() default ""; + + String dsArgs() default ""; + + String dsUid() default ""; + + String executeColumn() default "Execute"; + + String executeValue() default "y"; + + String staticArgs() default ""; + + String groupColumn() default ""; + + String testRailColumn() default ""; + + String qTestColumn() default ""; + + String testMethodColumn() default ""; + + String testMethodOwnerColumn() default ""; + + String bugColumn() default ""; } diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java index 93c60d9327..a050252852 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java @@ -52,10 +52,8 @@ public static Object[][] getDataProvider(Annotation[] annotations, ITestContext Object[][] provider = new Object[][]{}; for (Annotation annotation : annotations) { - String providerClass; - if (annotation instanceof CsvDataSourceParameters || annotation instanceof XlsDataSourceParameters) { - providerClass = findProviderClass(annotation); - } else { + String providerClass = findProviderClass(annotation); + if (providerClass.isEmpty()){ continue; } diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java index cf3f335c6f..784912b19c 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java @@ -26,7 +26,6 @@ import java.util.List; import java.util.Map; -import com.qaprosoft.carina.core.foundation.dataprovider.annotations.DataSourceParameters; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testng.ITestContext; @@ -67,26 +66,25 @@ public Object[][] getDataProvider(Annotation annotation, ITestContext context, I executeColumn = dsBean.getExecuteColumn(); executeValue = dsBean.getExecuteValue(); - DataSourceParameters data = parameters.data(); - testRailColumn = data.testRailColumn(); + testRailColumn = parameters.testRailColumn(); - if (!data.qTestColumn().isEmpty() && testRailColumn.isEmpty()) - testRailColumn = data.qTestColumn(); + if (!parameters.qTestColumn().isEmpty() && testRailColumn.isEmpty()) + testRailColumn = parameters.qTestColumn(); - testMethodColumn = data.testMethodColumn(); - testMethodOwnerColumn = data.testMethodOwnerColumn(); - bugColumn = data.bugColumn(); + testMethodColumn = parameters.testMethodColumn(); + testMethodOwnerColumn = parameters.testMethodOwnerColumn(); + bugColumn = parameters.bugColumn(); List argsList = dsBean.getArgs(); List staticArgsList = dsBean.getStaticArgs(); - String groupByParameter = data.groupColumn(); + String groupByParameter = parameters.groupColumn(); if (!groupByParameter.isEmpty()) { GroupByMapper.getInstanceInt().add(argsList.indexOf(groupByParameter)); GroupByMapper.getInstanceStrings().add(groupByParameter); } - if (data.dsArgs().isEmpty()) { + if (parameters.dsArgs().isEmpty()) { GroupByMapper.setIsHashMapped(true); } CSVReader reader; diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java index 65feddb26e..43466e4edc 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java @@ -46,34 +46,34 @@ public Object[][] getDataProvider(Annotation annotation, ITestContext context, I argsList = dsBean.getArgs(); staticArgsList = dsBean.getStaticArgs(); - if (parameters.data().dsArgs().isEmpty()) { + if (parameters.dsArgs().isEmpty()) { GroupByMapper.setIsHashMapped(true); } - String groupByParameter = parameters.data().groupColumn(); + String groupByParameter = parameters.groupColumn(); if (!groupByParameter.isEmpty()) { GroupByMapper.getInstanceInt().add(argsList.indexOf(groupByParameter)); GroupByMapper.getInstanceStrings().add(groupByParameter); } String testRailColumn = ""; - if (!parameters.data().testRailColumn().isEmpty()) - testRailColumn = parameters.data().testRailColumn(); + if (!parameters.testRailColumn().isEmpty()) + testRailColumn = parameters.testRailColumn(); - if (!parameters.data().qTestColumn().isEmpty() && testRailColumn.isEmpty()) - testRailColumn = parameters.data().qTestColumn(); + if (!parameters.qTestColumn().isEmpty() && testRailColumn.isEmpty()) + testRailColumn = parameters.qTestColumn(); String testMethodColumn = ""; - if (!parameters.data().testMethodColumn().isEmpty()) - testMethodColumn = parameters.data().testMethodColumn(); + if (!parameters.testMethodColumn().isEmpty()) + testMethodColumn = parameters.testMethodColumn(); String testMethodOwnerColumn = ""; - if (!parameters.data().testMethodOwnerColumn().isEmpty()) - testMethodOwnerColumn = parameters.data().testMethodOwnerColumn(); + if (!parameters.testMethodOwnerColumn().isEmpty()) + testMethodOwnerColumn = parameters.testMethodOwnerColumn(); String bugColumn = ""; - if (!parameters.data().bugColumn().isEmpty()) - bugColumn = parameters.data().bugColumn(); + if (!parameters.bugColumn().isEmpty()) + bugColumn = parameters.bugColumn(); int width = 0; if (argsList.size() == 0) { diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/DSBean.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/DSBean.java index a82e9fbbd5..6658a18d4e 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/DSBean.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/DSBean.java @@ -15,12 +15,12 @@ *******************************************************************************/ package com.qaprosoft.carina.core.foundation.dataprovider.parser; +import java.lang.annotation.Annotation; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; -import com.qaprosoft.carina.core.foundation.dataprovider.annotations.DataSourceParameters; import org.apache.commons.lang3.StringUtils; import org.testng.ITestContext; @@ -56,7 +56,7 @@ public DSBean(Map testParams) { public DSBean(XlsDataSourceParameters xlsDataSourceParameters, Map suiteParams) { // params init order: 1) from test annotation 2) from suite if (xlsDataSourceParameters != null) { - this.initParamsFromAnnotation(xlsDataSourceParameters.data()); + this.initParamsFromAnnotation(xlsDataSourceParameters); if (!xlsDataSourceParameters.sheet().isEmpty()) { xlsSheet = xlsDataSourceParameters.sheet(); } @@ -84,7 +84,7 @@ public DSBean(XlsDataSourceParameters xlsDataSourceParameters, Map suiteParams) { // initialize default Xls data source parameters from suite xml file if (csvDataSourceParameters != null) { - this.initParamsFromAnnotation(csvDataSourceParameters.data()); + this.initParamsFromAnnotation(csvDataSourceParameters); } if (!suiteParams.isEmpty()) { @@ -95,25 +95,48 @@ public DSBean(CsvDataSourceParameters csvDataSourceParameters, Map Date: Thu, 9 Mar 2023 09:42:51 +0300 Subject: [PATCH 03/52] refactor(DataProviderFactory.java): returned provider init logic --- .../dataprovider/core/DataProviderFactory.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java index a050252852..3e35f0b6ab 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java @@ -57,10 +57,13 @@ public static Object[][] getDataProvider(Annotation[] annotations, ITestContext continue; } - BaseDataProvider dataProvider = initDataProvider(providerClass); + Object providerObject = initDataProvider(providerClass); - provider = ArrayUtils.addAll(provider, dataProvider.getDataProvider(annotation, context, m)); - testNameArgsMap.putAll(dataProvider.getTestNameArgsMap()); + if (providerObject instanceof BaseDataProvider) { + BaseDataProvider dataProvider = (BaseDataProvider) providerObject; + provider = ArrayUtils.addAll(provider, dataProvider.getDataProvider(annotation, context, m)); + testNameArgsMap.putAll(dataProvider.getTestNameArgsMap()); + } } if (!GroupByMapper.getInstanceInt().isEmpty() || !GroupByMapper.getInstanceStrings().isEmpty()) { @@ -109,13 +112,13 @@ private static String findProviderClass(Annotation annotation) { * * @return DataProvider Instance. */ - private static BaseDataProvider initDataProvider(String providerClass){ + private static Object initDataProvider(String providerClass){ Class clazz; - BaseDataProvider dataProvider = null; + Object dataProvider = null; try { clazz = Class.forName(providerClass); Constructor ctor = clazz.getConstructor(); - dataProvider = (BaseDataProvider) ctor.newInstance(); + dataProvider = ctor.newInstance(); } catch (Exception e) { LOGGER.error("DataProvider initialization failure", e); } From 81867d4122e1834fd3379106bea79dbc40e59def Mon Sep 17 00:00:00 2001 From: Dima Grinevich Date: Fri, 10 Mar 2023 11:32:27 +0300 Subject: [PATCH 04/52] fix(DataProviderFactory.java): adding value to existing attribute in context, so we dont override old data --- .../carina/core/testng/TestNamingService.java | 25 +++++++---- .../core/DataProviderFactory.java | 41 ++++++++++++++----- .../core/impl/BaseDataProvider.java | 26 ++++++++---- .../core/impl/XlsDataProvider.java | 35 +++++++++++++--- .../src/main/resources/config.properties | 2 +- 5 files changed, 96 insertions(+), 33 deletions(-) diff --git a/carina-core/src/main/java/com/zebrunner/carina/core/testng/TestNamingService.java b/carina-core/src/main/java/com/zebrunner/carina/core/testng/TestNamingService.java index 8deb0c1efd..562bf917f0 100644 --- a/carina-core/src/main/java/com/zebrunner/carina/core/testng/TestNamingService.java +++ b/carina-core/src/main/java/com/zebrunner/carina/core/testng/TestNamingService.java @@ -22,6 +22,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; +import com.qaprosoft.carina.core.foundation.dataprovider.core.impl.BaseDataProvider; import com.zebrunner.agent.testng.listener.RunContextService; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; @@ -94,10 +95,7 @@ private static String setTestName(ITestResult result) { ITestNGMethod method = result.getMethod(); name = Configuration.get(Configuration.Parameter.TEST_NAMING_PATTERN); - String testNameMapName = getTestNameMapName(result); - name = name.replace(SpecialKeywords.TEST_NAME_MAP, testNameMapName) - .replace(SpecialKeywords.TEST_NAME, - testNameMapName.isEmpty() ? result.getTestContext().getCurrentXmlTest().getName() : "") + name = name.replace(SpecialKeywords.TEST_NAME, getTestNameMapName(result)) .replace(SpecialKeywords.TEST_NAME_TUID, getMethodUID(result)) .replace(SpecialKeywords.METHOD_NAME, method.getMethodName()) .replace(SpecialKeywords.METHOD_PRIORITY, String.valueOf(method.getPriority())) @@ -121,12 +119,14 @@ private static String setTestName(ITestResult result) { private static String getTestNameMapName(ITestResult result) { String testNameMapName = StringUtils.EMPTY; @SuppressWarnings("unchecked") - Map testNameMap = (Map) result.getTestContext().getAttribute(SpecialKeywords.TEST_NAME_ARGS_MAP); + Map testNameMap = (Map) result.getTestContext().getAttribute(SpecialKeywords.TEST_NAME); if (testNameMap != null) { - String testHash = String.valueOf(Arrays.hashCode(result.getParameters())); + String testHash = BaseDataProvider.hash(result.getParameters(), result.getMethod()); if (testNameMap.containsKey(testHash)) { testNameMapName = testNameMap.get(testHash); + } else { + testNameMapName = result.getTestContext().getCurrentXmlTest().getName(); } } return testNameMapName; @@ -161,9 +161,20 @@ private static String getMethodUID(ITestResult result) { } catch (NoSuchMethodException e) { LOGGER.error("For some reason test method not found using reflection: {}", result.getMethod().getMethodName()); } + + @SuppressWarnings("unchecked") + Map tuidMap = (Map) result.getTestContext().getAttribute(SpecialKeywords.TUID); + + if (tuidMap != null) { + String testHash = BaseDataProvider.hash(result.getParameters(), result.getMethod()); + if (tuidMap.containsKey(testHash)) { + methodUID = tuidMap.get(testHash); + } + } + return methodUID; } - + /** * get Test Method name * diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java index 3e35f0b6ab..e56e4fd576 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java @@ -48,12 +48,13 @@ private DataProviderFactory() { } public static Object[][] getDataProvider(Annotation[] annotations, ITestContext context, ITestNGMethod m) { - Map testNameArgsMap = Collections.synchronizedMap(new HashMap<>()); + Map tuidMap = Collections.synchronizedMap(new HashMap<>()); + Map testNameFromColumn = Collections.synchronizedMap(new HashMap<>()); Object[][] provider = new Object[][]{}; for (Annotation annotation : annotations) { String providerClass = findProviderClass(annotation); - if (providerClass.isEmpty()){ + if (providerClass.isEmpty()) { continue; } @@ -62,15 +63,15 @@ public static Object[][] getDataProvider(Annotation[] annotations, ITestContext if (providerObject instanceof BaseDataProvider) { BaseDataProvider dataProvider = (BaseDataProvider) providerObject; provider = ArrayUtils.addAll(provider, dataProvider.getDataProvider(annotation, context, m)); - testNameArgsMap.putAll(dataProvider.getTestNameArgsMap()); + tuidMap.putAll(dataProvider.getTuidMap()); + testNameFromColumn.putAll(dataProvider.getTestColumnNamesMap()); } } if (!GroupByMapper.getInstanceInt().isEmpty() || !GroupByMapper.getInstanceStrings().isEmpty()) { provider = getGroupedList(provider); } - - context.setAttribute(SpecialKeywords.TEST_NAME_ARGS_MAP, testNameArgsMap); + putValuesToContext(context, tuidMap, testNameFromColumn); // clear group by settings GroupByMapper.getInstanceInt().clear(); @@ -79,13 +80,32 @@ public static Object[][] getDataProvider(Annotation[] annotations, ITestContext return provider; } + private static void putValuesToContext(ITestContext context, + Map tuidMap, + Map testNameFromColumn) { + @SuppressWarnings("unchecked") + Map contextTUID = (Map) context.getAttribute(SpecialKeywords.TUID); + if (contextTUID != null) { + contextTUID.putAll(tuidMap); + } else { + context.setAttribute(SpecialKeywords.TUID, tuidMap); + } + + @SuppressWarnings("unchecked") + Map contextTestName = (Map) context.getAttribute(SpecialKeywords.TEST_NAME); + if (contextTestName != null) { + contextTUID.putAll(tuidMap); + } else { + context.setAttribute(SpecialKeywords.TEST_NAME, testNameFromColumn); + } + } + /** * Finds class name for data provider implementation. * * @param annotation test method annotation. - * * @return class name of data provider if it was found in annotation classname() method. - * Empty string if not. + * Empty string if not. */ private static String findProviderClass(Annotation annotation) { Class type = annotation.annotationType(); @@ -98,7 +118,7 @@ private static String findProviderClass(Annotation annotation) { break; } } - } catch (ReflectiveOperationException e){ + } catch (ReflectiveOperationException e) { LOGGER.error("Failure on finding DataProvider class instance", e); } @@ -109,16 +129,15 @@ private static String findProviderClass(Annotation annotation) { * Initialize DataProvider based on className parameter. * * @param providerClass String full className. - * * @return DataProvider Instance. */ - private static Object initDataProvider(String providerClass){ + private static Object initDataProvider(String providerClass) { Class clazz; Object dataProvider = null; try { clazz = Class.forName(providerClass); Constructor ctor = clazz.getConstructor(); - dataProvider = ctor.newInstance(); + dataProvider = ctor.newInstance(); } catch (Exception e) { LOGGER.error("DataProvider initialization failure", e); } diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java index 653ec54355..b6e56ad6f0 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java @@ -16,10 +16,7 @@ package com.qaprosoft.carina.core.foundation.dataprovider.core.impl; import java.lang.annotation.Annotation; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import org.testng.ITestContext; import org.testng.ITestNGMethod; @@ -32,12 +29,11 @@ */ public abstract class BaseDataProvider { - + protected Map tuidMap = Collections.synchronizedMap(new HashMap<>()); protected Map testNameArgsMap = Collections.synchronizedMap(new HashMap<>()); - protected Map testMethodOwnerArgsMap = Collections.synchronizedMap(new HashMap<>()); - protected Map testRailsArgsMap = Collections.synchronizedMap(new HashMap<>()); + protected Map testColumnNamesMap = Collections.synchronizedMap(new HashMap<>()); protected List argsList; protected List staticArgsList; @@ -49,8 +45,12 @@ protected static Object getStaticParam(String name, ITestContext context, DSBean .getTestParams().get(name)); } - public Map getTestNameArgsMap() { - return testNameArgsMap; + public Map getTestColumnNamesMap() { + return testColumnNamesMap; + } + + public Map getTuidMap() { + return tuidMap; } public Map getTestMethodOwnerArgsMap() { @@ -74,4 +74,12 @@ protected void addValueToSpecialMap(Map map, String column, Stri } } + public static String hash(Object[] args, ITestNGMethod method) { + String toHash = ""; + toHash += Arrays.hashCode(args); + toHash += method.getMethodName(); + toHash += (method.getRealClass()); + return String.valueOf(toHash.hashCode()); + } + } diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java index 43466e4edc..1ab2e89c83 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java @@ -17,6 +17,7 @@ import java.lang.annotation.Annotation; import java.util.Arrays; +import java.util.List; import java.util.Map; import org.testng.ITestContext; @@ -121,13 +122,14 @@ public Object[][] getDataProvider(Annotation annotation, ITestContext context, I args[rowIndex][i + j] = getStaticParam(staticArgsList.get(j), context, dsBean); } } - // update testName adding UID values from DataSource arguments if any - testName = dsBean.setDataSorceUUID(testName, xlsRow); - testNameArgsMap.put(String.valueOf(Arrays.hashCode(args[rowIndex])), testName); + tuidMap.put(hash(args[rowIndex], testMethod), getValueFromRow(xlsRow, dsBean.getUidArgs())); + if (!testMethodColumn.isEmpty()) { - // override testName value from xls datasource to special hashMap - addValueToSpecialMap(testNameArgsMap, testMethodColumn, String.valueOf(Arrays.hashCode(args[rowIndex])), xlsRow); + String testNameOverride = getValueFromRow(xlsRow, List.of(testMethodColumn)); + if (!testNameOverride.isEmpty()) { + testColumnNamesMap.put(hash(args[rowIndex], testMethod), getValueFromRow(xlsRow, testMethodColumn)); + } } // add testMethoOwner from xls datasource to special hashMap @@ -141,4 +143,27 @@ public Object[][] getDataProvider(Annotation annotation, ITestContext context, I return args; } + + private String getValueFromRow(Map xlsRow, String key) { + return getValueFromRow(xlsRow, List.of(key)); + } + + private String getValueFromRow(Map xlsRow, List keys) { + StringBuilder valueRes = new StringBuilder(); + + for (String key : keys) { + if (xlsRow.containsKey(key)) { + String value = xlsRow.get(key); + if (value != null && !value.isEmpty()) { + valueRes.append(value); + valueRes.append(", "); + } + } + } + + if (valueRes.indexOf(",") != -1) { + valueRes.replace(valueRes.length() - 2, valueRes.length() - 1, ""); + } + return valueRes.toString(); + } } diff --git a/carina-reporting/src/main/resources/config.properties b/carina-reporting/src/main/resources/config.properties index bf3b67aab3..70c96140d3 100644 --- a/carina-reporting/src/main/resources/config.properties +++ b/carina-reporting/src/main/resources/config.properties @@ -3,7 +3,7 @@ max_log_file_size=150 max_screen_history=NULL suite_name=NULL -test_naming_pattern={tuid} {map}{test_name} - {method_name} +test_naming_pattern={tuid}{test_name} - {method_name} report_url=NULL custom_artifacts_folder=NULL project_report_directory=NULL From f99f2ed4453d2ce6365d9fe9759e96472624c312 Mon Sep 17 00:00:00 2001 From: Dima Grinevich Date: Fri, 10 Mar 2023 12:04:53 +0300 Subject: [PATCH 05/52] refactor(CsvDataProvider.java): implemented new naming logic --- .../core/DataProviderFactory.java | 2 +- .../core/impl/BaseDataProvider.java | 23 +++++++++++++++++++ .../core/impl/CsvDataProvider.java | 8 ++++++- .../core/impl/XlsDataProvider.java | 23 ------------------- 4 files changed, 31 insertions(+), 25 deletions(-) diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java index e56e4fd576..4b41d8bbfc 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java @@ -94,7 +94,7 @@ private static void putValuesToContext(ITestContext context, @SuppressWarnings("unchecked") Map contextTestName = (Map) context.getAttribute(SpecialKeywords.TEST_NAME); if (contextTestName != null) { - contextTUID.putAll(tuidMap); + contextTestName.putAll(testNameFromColumn); } else { context.setAttribute(SpecialKeywords.TEST_NAME, testNameFromColumn); } diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java index b6e56ad6f0..72377b6baf 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java @@ -82,4 +82,27 @@ public static String hash(Object[] args, ITestNGMethod method) { return String.valueOf(toHash.hashCode()); } + protected String getValueFromRow(Map xlsRow, String key) { + return getValueFromRow(xlsRow, List.of(key)); + } + + protected String getValueFromRow(Map xlsRow, List keys) { + StringBuilder valueRes = new StringBuilder(); + + for (String key : keys) { + if (xlsRow.containsKey(key)) { + String value = xlsRow.get(key); + if (value != null && !value.isEmpty()) { + valueRes.append(value); + valueRes.append(", "); + } + } + } + + if (valueRes.indexOf(",") != -1) { + valueRes.replace(valueRes.length() - 2, valueRes.length() - 1, ""); + } + return valueRes.toString(); + } + } diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java index 784912b19c..183e2b759b 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java @@ -170,7 +170,13 @@ public Object[][] getDataProvider(Annotation annotation, ITestContext context, I testName = dsBean.setDataSorceUUID(testName, strings, mapper); // provide whole line from data provider for UUID generation HashMap csvRow = (HashMap) args[rowIndex][0]; - + tuidMap.put(hash(args[rowIndex], testMethod), getValueFromRow(csvRow, dsBean.getUidArgs())); + if (!testMethodColumn.isEmpty()) { + String testNameOverride = getValueFromRow(csvRow, List.of(testMethodColumn)); + if (!testNameOverride.isEmpty()) { + testColumnNamesMap.put(hash(args[rowIndex], testMethod), getValueFromRow(csvRow, testMethodColumn)); + } + } testNameArgsMap.put(String.valueOf(Arrays.hashCode(args[rowIndex])), testName); if (!testMethodColumn.isEmpty()) { // override testName value from xls datasource to special hashMap diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java index 1ab2e89c83..35205cb04f 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java @@ -143,27 +143,4 @@ public Object[][] getDataProvider(Annotation annotation, ITestContext context, I return args; } - - private String getValueFromRow(Map xlsRow, String key) { - return getValueFromRow(xlsRow, List.of(key)); - } - - private String getValueFromRow(Map xlsRow, List keys) { - StringBuilder valueRes = new StringBuilder(); - - for (String key : keys) { - if (xlsRow.containsKey(key)) { - String value = xlsRow.get(key); - if (value != null && !value.isEmpty()) { - valueRes.append(value); - valueRes.append(", "); - } - } - } - - if (valueRes.indexOf(",") != -1) { - valueRes.replace(valueRes.length() - 2, valueRes.length() - 1, ""); - } - return valueRes.toString(); - } } From 53901979803a08f36f25a2aa5423ed581396aee4 Mon Sep 17 00:00:00 2001 From: Dima Grinevich Date: Fri, 10 Mar 2023 14:35:07 +0300 Subject: [PATCH 06/52] fix(dataprovider): code cleanup --- .../dataprovider/core/impl/BaseDataProvider.java | 1 - .../dataprovider/core/impl/CsvDataProvider.java | 15 +++------------ .../dataprovider/core/impl/XlsDataProvider.java | 1 - 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java index 72377b6baf..5b9eb84144 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java @@ -30,7 +30,6 @@ public abstract class BaseDataProvider { protected Map tuidMap = Collections.synchronizedMap(new HashMap<>()); - protected Map testNameArgsMap = Collections.synchronizedMap(new HashMap<>()); protected Map testMethodOwnerArgsMap = Collections.synchronizedMap(new HashMap<>()); protected Map testRailsArgsMap = Collections.synchronizedMap(new HashMap<>()); protected Map testColumnNamesMap = Collections.synchronizedMap(new HashMap<>()); diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java index 183e2b759b..e362104a79 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java @@ -131,8 +131,6 @@ public Object[][] getDataProvider(Annotation annotation, ITestContext context, I Object[][] args = new Object[listSize][width]; int rowIndex = 0; for (String[] strings : list) { - String testName = context.getName(); - int i = 0; if (argsList.size() == 0) { // read all csv data into the single HashMap object @@ -145,10 +143,9 @@ public Object[][] getDataProvider(Annotation annotation, ITestContext context, I } else { dynamicAttrs.put(header, null); } - - args[rowIndex][0] = dynamicAttrs; } + args[rowIndex][0] = dynamicAttrs; i++; } else { for (String arg : argsList) { @@ -166,22 +163,16 @@ public Object[][] getDataProvider(Annotation annotation, ITestContext context, I args[rowIndex][i + j] = getStaticParam(staticArgsList.get(j), context, dsBean); } - // update testName adding UID values from DataSource arguments if any - testName = dsBean.setDataSorceUUID(testName, strings, mapper); // provide whole line from data provider for UUID generation - HashMap csvRow = (HashMap) args[rowIndex][0]; tuidMap.put(hash(args[rowIndex], testMethod), getValueFromRow(csvRow, dsBean.getUidArgs())); + if (!testMethodColumn.isEmpty()) { String testNameOverride = getValueFromRow(csvRow, List.of(testMethodColumn)); if (!testNameOverride.isEmpty()) { testColumnNamesMap.put(hash(args[rowIndex], testMethod), getValueFromRow(csvRow, testMethodColumn)); } } - testNameArgsMap.put(String.valueOf(Arrays.hashCode(args[rowIndex])), testName); - if (!testMethodColumn.isEmpty()) { - // override testName value from xls datasource to special hashMap - addValueToSpecialMap(testNameArgsMap, testMethodColumn, String.valueOf(Arrays.hashCode(args[rowIndex])), csvRow); - } + // add testMethoOwner from xls datasource to special hashMap addValueToSpecialMap(testMethodOwnerArgsMap, testMethodOwnerColumn, String.valueOf(Arrays.hashCode(args[rowIndex])), csvRow); diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java index 35205cb04f..50dfcdf694 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java @@ -86,7 +86,6 @@ public Object[][] getDataProvider(Annotation annotation, ITestContext context, I int rowIndex = 0; for (Map xlsRow : dsData.getDataRows()) { - String testName = context.getName(); if (argsList.size() == 0) { // process each column in xlsRow data obligatory replacing special keywords like UUID etc From 460670b558c7ae675406197942d97fcccf019fce Mon Sep 17 00:00:00 2001 From: Dima Grinevich Date: Fri, 10 Mar 2023 15:47:53 +0300 Subject: [PATCH 07/52] fix(CsvDataProvider.java): implemented xsl alike method to parse csv --- .../core/impl/CsvDataProvider.java | 132 +++++++----------- .../core/impl/XlsDataProvider.java | 2 +- 2 files changed, 51 insertions(+), 83 deletions(-) diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java index e362104a79..e83887afa7 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java @@ -75,8 +75,8 @@ public Object[][] getDataProvider(Annotation annotation, ITestContext context, I testMethodOwnerColumn = parameters.testMethodOwnerColumn(); bugColumn = parameters.bugColumn(); - List argsList = dsBean.getArgs(); - List staticArgsList = dsBean.getStaticArgs(); + argsList = dsBean.getArgs(); + staticArgsList = dsBean.getStaticArgs(); String groupByParameter = parameters.groupColumn(); if (!groupByParameter.isEmpty()) { @@ -101,20 +101,16 @@ public Object[][] getDataProvider(Annotation annotation, ITestContext context, I if (list.size() == 0) { throw new RuntimeException("Unable to retrieve data from CSV DataProvider! Verify separator and quote settings."); } - List headers = Arrays.asList((String[]) list.get(0)); - - // handle empty argsList inside initMapper - mapper = initMapper(argsList, headers); + List headers = Arrays.asList(list.get(0)); list.remove(0); + List> dsData = initData(headers, list); // exclude those lines which don't satisfy executeColumn/executeValue filter - Iterator iter = list.iterator(); - while (iter.hasNext()) { - int index = mapper.get(executeColumn); - - String[] line = iter.next(); - if (!line[index].equalsIgnoreCase(executeValue)) { - iter.remove(); + for (int i = 0; i < dsData.size(); i++) { + Map row = dsData.get(i); + if (!row.get(dsBean.getExecuteColumn()).equalsIgnoreCase(executeValue)) { + dsData.remove(i); + i--; } } @@ -130,55 +126,56 @@ public Object[][] getDataProvider(Annotation annotation, ITestContext context, I Object[][] args = new Object[listSize][width]; int rowIndex = 0; - for (String[] strings : list) { - int i = 0; + for (Map row : dsData) { + if (argsList.size() == 0) { - // read all csv data into the single HashMap object - HashMap dynamicAttrs = new HashMap(); - - for (String header : headers) { - int index = mapper.get(header); - if (ParameterGenerator.process(strings[index]) != null) { - dynamicAttrs.put(header, ParameterGenerator.process(strings[index]).toString()); - } else { - dynamicAttrs.put(header, null); + for (Map.Entry entry : row.entrySet()) { + if (entry == null) + continue; + + String value = entry.getValue(); + if (value == null) + continue; + + Object param = ParameterGenerator.process(value); + if (param == null) + continue; + + String newValue = param.toString(); + if (!value.equals(newValue)) { + entry.setValue(newValue); } } - - args[rowIndex][0] = dynamicAttrs; - i++; + args[rowIndex][0] = row; + for (int i = 0; i < staticArgsList.size(); i++) { + args[rowIndex][i + 1] = getStaticParam(staticArgsList.get(i), context, dsBean); + } } else { - for (String arg : argsList) { - int index = mapper.get(arg); - if (ParameterGenerator.process(strings[index]) != null) { - args[rowIndex][i] = ParameterGenerator.process(strings[index]).toString(); - } else { - args[rowIndex][i] = null; - } - i++; + int i; + for (i = 0; i < argsList.size(); i++) { + args[rowIndex][i] = ParameterGenerator + .process(row.get(argsList.get(i))); } - } - for (int j = 0; j < staticArgsList.size(); j++) { - args[rowIndex][i + j] = getStaticParam(staticArgsList.get(j), context, dsBean); + for (int j = 0; j < staticArgsList.size(); j++) { + args[rowIndex][i + j] = getStaticParam(staticArgsList.get(j), context, dsBean); + } } - HashMap csvRow = (HashMap) args[rowIndex][0]; - tuidMap.put(hash(args[rowIndex], testMethod), getValueFromRow(csvRow, dsBean.getUidArgs())); + tuidMap.put(hash(args[rowIndex], testMethod), getValueFromRow(row, dsBean.getUidArgs())); if (!testMethodColumn.isEmpty()) { - String testNameOverride = getValueFromRow(csvRow, List.of(testMethodColumn)); + String testNameOverride = getValueFromRow(row, List.of(testMethodColumn)); if (!testNameOverride.isEmpty()) { - testColumnNamesMap.put(hash(args[rowIndex], testMethod), getValueFromRow(csvRow, testMethodColumn)); + testColumnNamesMap.put(hash(args[rowIndex], testMethod), getValueFromRow(row, testMethodColumn)); } } - // add testMethoOwner from xls datasource to special hashMap - addValueToSpecialMap(testMethodOwnerArgsMap, testMethodOwnerColumn, String.valueOf(Arrays.hashCode(args[rowIndex])), csvRow); + addValueToSpecialMap(testMethodOwnerArgsMap, testMethodOwnerColumn, String.valueOf(Arrays.hashCode(args[rowIndex])), row); // add testrails cases from xls datasource to special hashMap - addValueToSpecialMap(testRailsArgsMap, testRailColumn, String.valueOf(Arrays.hashCode(args[rowIndex])), csvRow); + addValueToSpecialMap(testRailsArgsMap, testRailColumn, String.valueOf(Arrays.hashCode(args[rowIndex])), row); rowIndex++; } @@ -186,46 +183,17 @@ public Object[][] getDataProvider(Annotation annotation, ITestContext context, I return args; } - /* - * obligatory add to mapper all columns for DataProvider artifacts like: - * executeColumn - filter column - * testRailColumn - * testMethodColumn - * testMethodOwnerColumn - */ - private Map initMapper(List argsList, List headers) { - Map mapper = new HashMap(); + private List> initData(List headers, List values) { + List> list = new ArrayList<>(); - if (argsList.size() == 0) { - // read all columns and put their name into the mapper - for (String arg : headers) { - mapper.put(arg, getIndex(arg, headers)); + for (int i = 0; i < values.size(); i++) { + Map map = new HashMap<>(); + list.add(map); + for (int j = 0; j < headers.size(); j++) { + map.put(headers.get(j), values.get(i)[j]); } - } else { - for (String arg : argsList) { - mapper.put(arg, getIndex(arg, headers)); - } - } - - mapper.put(executeColumn, getIndex(executeColumn, headers)); - mapper.put(testRailColumn, getIndex(testRailColumn, headers)); - mapper.put(testMethodColumn, getIndex(testMethodColumn, headers)); - mapper.put(testMethodOwnerColumn, getIndex(testMethodOwnerColumn, headers)); - mapper.put(bugColumn, getIndex(bugColumn, headers)); - - return mapper; - } - - private Integer getIndex(String arg, List headers) { - if (arg.isEmpty()) { - return -1; } - int index = headers.indexOf(arg); - if (index == -1) { - throw new RuntimeException( - "Unable to find column '" + arg + "' in DataProvider among '" + headers + "'! Verify separator and quote settings."); - } - return index; + return list; } } diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java index 50dfcdf694..af7a285455 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java @@ -97,7 +97,7 @@ public Object[][] getDataProvider(Annotation annotation, ITestContext context, I if (value == null) continue; - Object param = ParameterGenerator.process(entry.getValue().toString()); + Object param = ParameterGenerator.process(value); if (param == null) continue; From f2d38f71c2530b2bec12de1b33f5c620fad32287 Mon Sep 17 00:00:00 2001 From: Dima Grinevich Date: Fri, 10 Mar 2023 19:08:29 +0300 Subject: [PATCH 08/52] refactor(dataprovider): reduced duplicate code --- .../core/impl/BaseDataProvider.java | 8 +- .../core/impl/CsvDataProvider.java | 69 ++---- .../core/impl/XlsDataProvider.java | 58 ++--- .../dataprovider/parser/DSBean.java | 217 ++++++------------ 4 files changed, 119 insertions(+), 233 deletions(-) diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java index 5b9eb84144..db76241064 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java @@ -34,14 +34,10 @@ public abstract class BaseDataProvider { protected Map testRailsArgsMap = Collections.synchronizedMap(new HashMap<>()); protected Map testColumnNamesMap = Collections.synchronizedMap(new HashMap<>()); - protected List argsList; - protected List staticArgsList; - public abstract Object[][] getDataProvider(Annotation annotation, ITestContext context, ITestNGMethod testMethod); - protected static Object getStaticParam(String name, ITestContext context, DSBean dsBean) { - return ParameterGenerator.process(dsBean - .getTestParams().get(name)); + protected static Object getStaticParam(String name, DSBean dsBean) { + return ParameterGenerator.process(dsBean.getTestParams().get(name)); } public Map getTestColumnNamesMap() { diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java index e83887afa7..ea54252abf 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java @@ -22,7 +22,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; @@ -42,16 +41,7 @@ * Created by Patotsky on 16.12.2014. */ public class CsvDataProvider extends BaseDataProvider { - private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - private Map mapper = new HashMap(); - - private String executeColumn; - private String executeValue; - private String testRailColumn; - private String testMethodColumn; - private String testMethodOwnerColumn; - private String bugColumn; @SuppressWarnings("unchecked") @Override @@ -63,32 +53,21 @@ public Object[][] getDataProvider(Annotation annotation, ITestContext context, I separator = parameters.separator(); quote = parameters.quote(); - executeColumn = dsBean.getExecuteColumn(); - executeValue = dsBean.getExecuteValue(); - - testRailColumn = parameters.testRailColumn(); - - if (!parameters.qTestColumn().isEmpty() && testRailColumn.isEmpty()) - testRailColumn = parameters.qTestColumn(); - - testMethodColumn = parameters.testMethodColumn(); - testMethodOwnerColumn = parameters.testMethodOwnerColumn(); - bugColumn = parameters.bugColumn(); - - argsList = dsBean.getArgs(); - staticArgsList = dsBean.getStaticArgs(); + String testRailColumn = dsBean.getTestRailColumn(); + if (testRailColumn.isEmpty()) + testRailColumn = dsBean.getQTestColumn(); - String groupByParameter = parameters.groupColumn(); + String groupByParameter = dsBean.getGroupColumn(); if (!groupByParameter.isEmpty()) { - GroupByMapper.getInstanceInt().add(argsList.indexOf(groupByParameter)); + GroupByMapper.getInstanceInt().add(dsBean.getArgs().indexOf(groupByParameter)); GroupByMapper.getInstanceStrings().add(groupByParameter); } - if (parameters.dsArgs().isEmpty()) { + if (dsBean.getArgs().isEmpty()) { GroupByMapper.setIsHashMapped(true); } CSVReader reader; - List list = new ArrayList(); + List list = new ArrayList<>(); try { String csvFile = ClassLoader.getSystemResource(dsBean.getDsFile()).getFile(); @@ -108,7 +87,7 @@ public Object[][] getDataProvider(Annotation annotation, ITestContext context, I // exclude those lines which don't satisfy executeColumn/executeValue filter for (int i = 0; i < dsData.size(); i++) { Map row = dsData.get(i); - if (!row.get(dsBean.getExecuteColumn()).equalsIgnoreCase(executeValue)) { + if (!row.get(dsBean.getExecuteColumn()).equalsIgnoreCase(dsBean.getExecuteValue())) { dsData.remove(i); i--; } @@ -117,18 +96,18 @@ public Object[][] getDataProvider(Annotation annotation, ITestContext context, I int listSize = list.size(); int width = 0; - if (argsList.size() == 0) { + if (dsBean.getArgs().size() == 0) { // first element is dynamic HashMap - width = staticArgsList.size() + 1; + width = dsBean.getStaticArgs().size() + 1; } else { - width = argsList.size() + staticArgsList.size(); + width = dsBean.getArgs().size() + dsBean.getStaticArgs().size(); } Object[][] args = new Object[listSize][width]; int rowIndex = 0; for (Map row : dsData) { - if (argsList.size() == 0) { + if (dsBean.getArgs().size() == 0) { for (Map.Entry entry : row.entrySet()) { if (entry == null) continue; @@ -147,32 +126,32 @@ public Object[][] getDataProvider(Annotation annotation, ITestContext context, I } } args[rowIndex][0] = row; - for (int i = 0; i < staticArgsList.size(); i++) { - args[rowIndex][i + 1] = getStaticParam(staticArgsList.get(i), context, dsBean); + for (int i = 0; i < dsBean.getStaticArgs().size(); i++) { + args[rowIndex][i + 1] = getStaticParam(dsBean.getStaticArgs().get(i), dsBean); } } else { int i; - for (i = 0; i < argsList.size(); i++) { + for (i = 0; i < dsBean.getArgs().size(); i++) { args[rowIndex][i] = ParameterGenerator - .process(row.get(argsList.get(i))); + .process(row.get(dsBean.getArgs().get(i))); } - for (int j = 0; j < staticArgsList.size(); j++) { - args[rowIndex][i + j] = getStaticParam(staticArgsList.get(j), context, dsBean); + for (int j = 0; j < dsBean.getStaticArgs().size(); j++) { + args[rowIndex][i + j] = getStaticParam(dsBean.getStaticArgs().get(j), dsBean); } } tuidMap.put(hash(args[rowIndex], testMethod), getValueFromRow(row, dsBean.getUidArgs())); - if (!testMethodColumn.isEmpty()) { - String testNameOverride = getValueFromRow(row, List.of(testMethodColumn)); + if (!dsBean.getTestMethodColumn().isEmpty()) { + String testNameOverride = getValueFromRow(row, dsBean.getTestMethodColumn()); if (!testNameOverride.isEmpty()) { - testColumnNamesMap.put(hash(args[rowIndex], testMethod), getValueFromRow(row, testMethodColumn)); + testColumnNamesMap.put(hash(args[rowIndex], testMethod), testNameOverride); } } // add testMethoOwner from xls datasource to special hashMap - addValueToSpecialMap(testMethodOwnerArgsMap, testMethodOwnerColumn, String.valueOf(Arrays.hashCode(args[rowIndex])), row); + addValueToSpecialMap(testMethodOwnerArgsMap, dsBean.getTestMethodOwnerColumn(), String.valueOf(Arrays.hashCode(args[rowIndex])), row); // add testrails cases from xls datasource to special hashMap addValueToSpecialMap(testRailsArgsMap, testRailColumn, String.valueOf(Arrays.hashCode(args[rowIndex])), row); @@ -186,11 +165,11 @@ public Object[][] getDataProvider(Annotation annotation, ITestContext context, I private List> initData(List headers, List values) { List> list = new ArrayList<>(); - for (int i = 0; i < values.size(); i++) { + for (String[] value : values) { Map map = new HashMap<>(); list.add(map); for (int j = 0; j < headers.size(); j++) { - map.put(headers.get(j), values.get(i)[j]); + map.put(headers.get(j), value[j]); } } diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java index af7a285455..0d6f584aae 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java @@ -44,50 +44,33 @@ public Object[][] getDataProvider(Annotation annotation, ITestContext context, I XLSTable dsData = XLSParser.parseSpreadSheet(dsBean.getDsFile(), dsBean.getXlsSheet(), dsBean.getExecuteColumn(), dsBean.getExecuteValue()); - argsList = dsBean.getArgs(); - staticArgsList = dsBean.getStaticArgs(); - if (parameters.dsArgs().isEmpty()) { + if (dsBean.getArgs().isEmpty()) { GroupByMapper.setIsHashMapped(true); } - String groupByParameter = parameters.groupColumn(); + String groupByParameter = dsBean.getGroupColumn(); if (!groupByParameter.isEmpty()) { - GroupByMapper.getInstanceInt().add(argsList.indexOf(groupByParameter)); + GroupByMapper.getInstanceInt().add(dsBean.getArgs().indexOf(groupByParameter)); GroupByMapper.getInstanceStrings().add(groupByParameter); } - String testRailColumn = ""; - if (!parameters.testRailColumn().isEmpty()) - testRailColumn = parameters.testRailColumn(); - - if (!parameters.qTestColumn().isEmpty() && testRailColumn.isEmpty()) - testRailColumn = parameters.qTestColumn(); - - String testMethodColumn = ""; - if (!parameters.testMethodColumn().isEmpty()) - testMethodColumn = parameters.testMethodColumn(); - - String testMethodOwnerColumn = ""; - if (!parameters.testMethodOwnerColumn().isEmpty()) - testMethodOwnerColumn = parameters.testMethodOwnerColumn(); - - String bugColumn = ""; - if (!parameters.bugColumn().isEmpty()) - bugColumn = parameters.bugColumn(); + String testRailColumn = dsBean.getTestRailColumn(); + if (testRailColumn.isEmpty()) + testRailColumn = dsBean.getQTestColumn(); int width = 0; - if (argsList.size() == 0) { - width = staticArgsList.size() + 1; + if (dsBean.getArgs().size() == 0) { + width = dsBean.getStaticArgs().size() + 1; } else { - width = argsList.size() + staticArgsList.size(); + width = dsBean.getArgs().size() + dsBean.getStaticArgs().size(); } Object[][] args = new Object[dsData.getDataRows().size()][width]; int rowIndex = 0; for (Map xlsRow : dsData.getDataRows()) { - if (argsList.size() == 0) { + if (dsBean.getArgs().size() == 0) { // process each column in xlsRow data obligatory replacing special keywords like UUID etc for (Map.Entry entry : xlsRow.entrySet()) { if (entry == null) @@ -107,32 +90,31 @@ public Object[][] getDataProvider(Annotation annotation, ITestContext context, I } } args[rowIndex][0] = xlsRow; - for (int i = 0; i < staticArgsList.size(); i++) { - args[rowIndex][i + 1] = getStaticParam(staticArgsList.get(i), context, dsBean); + for (int i = 0; i < dsBean.getStaticArgs().size(); i++) { + args[rowIndex][i + 1] = getStaticParam(dsBean.getStaticArgs().get(i), dsBean); } } else { int i; - for (i = 0; i < argsList.size(); i++) { - args[rowIndex][i] = ParameterGenerator.process(xlsRow - .get(argsList.get(i))); + for (i = 0; i < dsBean.getArgs().size(); i++) { + args[rowIndex][i] = ParameterGenerator.process(xlsRow.get(dsBean.getArgs().get(i))); } // populate the rest of items by static parameters from testParams - for (int j = 0; j < staticArgsList.size(); j++) { - args[rowIndex][i + j] = getStaticParam(staticArgsList.get(j), context, dsBean); + for (int j = 0; j < dsBean.getStaticArgs().size(); j++) { + args[rowIndex][i + j] = getStaticParam(dsBean.getStaticArgs().get(j), dsBean); } } tuidMap.put(hash(args[rowIndex], testMethod), getValueFromRow(xlsRow, dsBean.getUidArgs())); - if (!testMethodColumn.isEmpty()) { - String testNameOverride = getValueFromRow(xlsRow, List.of(testMethodColumn)); + if (!dsBean.getTestMethodColumn().isEmpty()) { + String testNameOverride = getValueFromRow(xlsRow, dsBean.getTestMethodColumn()); if (!testNameOverride.isEmpty()) { - testColumnNamesMap.put(hash(args[rowIndex], testMethod), getValueFromRow(xlsRow, testMethodColumn)); + testColumnNamesMap.put(hash(args[rowIndex], testMethod), testNameOverride); } } // add testMethoOwner from xls datasource to special hashMap - addValueToSpecialMap(testMethodOwnerArgsMap, testMethodOwnerColumn, String.valueOf(Arrays.hashCode(args[rowIndex])), xlsRow); + addValueToSpecialMap(testMethodOwnerArgsMap, dsBean.getTestMethodOwnerColumn(), String.valueOf(Arrays.hashCode(args[rowIndex])), xlsRow); // add testrails cases from xls datasource to special hashMap addValueToSpecialMap(testRailsArgsMap, testRailColumn, String.valueOf(Arrays.hashCode(args[rowIndex])), xlsRow); diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/DSBean.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/DSBean.java index 6658a18d4e..92310b3d7c 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/DSBean.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/DSBean.java @@ -15,43 +15,33 @@ *******************************************************************************/ package com.qaprosoft.carina.core.foundation.dataprovider.parser; -import java.lang.annotation.Annotation; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; -import org.apache.commons.lang3.StringUtils; -import org.testng.ITestContext; - import com.zebrunner.carina.utils.commons.SpecialKeywords; import com.qaprosoft.carina.core.foundation.dataprovider.annotations.CsvDataSourceParameters; import com.qaprosoft.carina.core.foundation.dataprovider.annotations.XlsDataSourceParameters; import com.zebrunner.carina.utils.exception.InvalidArgsException; public class DSBean { - Map testParams; + private Map testParams; private List args = new ArrayList<>(); private List uidArgs = new ArrayList<>(); private List staticArgs = new ArrayList<>(); private String dsFile; private String xlsSheet; - private String executeColumn; private String executeValue; - private boolean spreadsheet; - - public DSBean(ITestContext context) { - this(context.getCurrentXmlTest().getAllParameters()); - } - - public DSBean(Map testParams) { - this.testParams = testParams; - this.xlsSheet = testParams.get(SpecialKeywords.EXCEL_DS_SHEET); - initParamsFromSuite(testParams, "excel"); - } + private String groupColumn; + private String testRailColumn; + private String qTestColumn; + private String testMethodColumn; + private String testMethodOwnerColumn; + private String bugColumn; public DSBean(XlsDataSourceParameters xlsDataSourceParameters, Map suiteParams) { // params init order: 1) from test annotation 2) from suite @@ -96,48 +86,45 @@ public DSBean(CsvDataSourceParameters csvDataSourceParameters, Map suiteParams, String special if (suiteParams.get(SpecialKeywords.DS_EXECUTE_VALUE) != null) { this.executeValue = suiteParams.get(SpecialKeywords.DS_EXECUTE_VALUE); } - if (suiteParams.get(insert(SpecialKeywords.DS_ARGS, specialKeyPrefix)) != null) { - this.args = Arrays.asList(suiteParams.get(insert(SpecialKeywords.DS_ARGS, specialKeyPrefix)) - .replace(" ", "").split(",")); + + String dsArgs = suiteParams.get(insert(SpecialKeywords.DS_ARGS, specialKeyPrefix)); + if (dsArgs != null && !dsArgs.isEmpty()) { + this.args = Arrays.asList(dsArgs.replace(" ", "").split(",")); } - if (suiteParams.get(insert(SpecialKeywords.DS_UID, specialKeyPrefix)) != null) { - this.uidArgs = Arrays.asList(suiteParams.get(insert(SpecialKeywords.DS_UID, specialKeyPrefix)) - .replace(" ", "").split(",")); + String dsUid = suiteParams.get(insert(SpecialKeywords.DS_UID, specialKeyPrefix)); + if (dsUid != null && !dsUid.isEmpty()) { + this.uidArgs = Arrays.asList(dsUid.replace(" ", "").split(",")); } -// TODO: Add staticArgs to SpecialKeywords -// if (testParams.get(SpecialKeywords.DS_STATIC_ARGS) != null) { -// dsStaticArgs = testParams.get(SpecialKeywords.DS_STATIC_ARGS); -// } } private String insert(String into, String insertion) { @@ -171,107 +155,56 @@ private String insert(String into, String insertion) { return newString.toString(); } - public String getDsFile() { - return dsFile; - } - - public void setDsFile(String xlsFile) { - this.dsFile = xlsFile; - } - - public String getXlsSheet() { - return xlsSheet; - } - - public void setXlsSheet(String xlsSheet) { - this.xlsSheet = xlsSheet; - } - - public List getUidArgs() { - return uidArgs; + public Map getTestParams() { + return testParams; } public List getArgs() { return args; } - public void setArgs(List args) { - this.args = args; + public List getUidArgs() { + return uidArgs; } public List getStaticArgs() { return staticArgs; } - public void setStaticArgs(List staticArgs) { - this.staticArgs = staticArgs; + public String getDsFile() { + return dsFile; } - public Map getTestParams() { - return testParams; + public String getXlsSheet() { + return xlsSheet; } - public void setTestParams(Map testParams) { - this.testParams = testParams; + public String getGroupColumn() { + return groupColumn; } - public String argsToString(List args, Map params) { - if (args.size() == 0) { - return ""; - } - StringBuilder sb = new StringBuilder(); - for (String arg : args) { - if (SpecialKeywords.TUID.equals(arg)) - continue; - sb.append(String.format("%s=%s; ", arg, params.get(arg))); - } - return StringUtils.removeEnd(sb.toString(), "; "); + public String getTestRailColumn() { + return testRailColumn; } - public String setDataSorceUUID(String testName, Map params) { - - if (!params.isEmpty()) { - if (params.containsKey(SpecialKeywords.TUID)) { - testName = params.get(SpecialKeywords.TUID) + " - " + testName; - } - } - if (!uidArgs.isEmpty()) { - if (!argsToString(uidArgs, params).isEmpty()) { - testName = testName + " [" + argsToString(uidArgs, params) + "]"; - } - } + public String getQTestColumn() { + return qTestColumn; + } - return testName; + public String getTestMethodColumn() { + return testMethodColumn; } - public String setDataSorceUUID(String testName, Object[] params, Map mapper) { - // looks through the parameters for TUID or get column value by uidArgs parameter - Integer indexTUID = mapper.get(SpecialKeywords.TUID); - if (indexTUID != null) { - testName = params[indexTUID] + " - " + testName; - } + public String getTestMethodOwnerColumn() { + return testMethodOwnerColumn; + } - if (!uidArgs.isEmpty()) { - String uidString = argsToString(uidArgs, params, mapper); - if (!uidString.isEmpty()) { - testName = testName + " [" + uidString + "]"; - } - } - return testName; + public String getBugColumn() { + return bugColumn; } - public String argsToString(List args, Object[] params, Map mapper) { - if (args.size() == 0) { - return ""; - } - StringBuilder sb = new StringBuilder(); - for (String arg : args) { - Integer index = mapper.get(arg); - if (index != null) { - sb.append(String.format("%s=%s; ", arg, params[index].toString())); - } - } - return StringUtils.removeEnd(sb.toString(), "; "); + public boolean isSpreadsheet() { + return spreadsheet; } public String getExecuteColumn() { @@ -281,8 +214,4 @@ public String getExecuteColumn() { public String getExecuteValue() { return executeValue; } - - public boolean isSpreadsheet() { - return spreadsheet; - } } From 2bb7184f47d6161c855448d1ae7196f1eb9c481a Mon Sep 17 00:00:00 2001 From: Dima Grinevich Date: Mon, 13 Mar 2023 12:02:59 +0300 Subject: [PATCH 09/52] refactor(dataProvider): added temp documentation --- .../annotations/CsvDataSourceParameters.java | 54 +++++++++++++++++++ .../core/DataProviderFactory.java | 34 ++++++++---- .../core/impl/BaseDataProvider.java | 31 +++++++++-- .../core/impl/CsvDataProvider.java | 9 ++++ .../core/impl/XlsDataProvider.java | 9 ++++ 5 files changed, 122 insertions(+), 15 deletions(-) diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/CsvDataSourceParameters.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/CsvDataSourceParameters.java index 0255d0665f..9db7902f94 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/CsvDataSourceParameters.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/CsvDataSourceParameters.java @@ -23,22 +23,71 @@ @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface CsvDataSourceParameters { + /** + * Define data provider instance + * + * @return String + */ String className() default "com.qaprosoft.carina.core.foundation.dataprovider.core.impl.CsvDataProvider"; + /** + * Define column separator for parsing + * + * @return char + */ char separator() default ','; + /** + * The character to use for quoted elements + * + * @return char + */ char quote() default '"'; + /** + * Path to source data file + * + * @return String + */ String path() default ""; + /** + * Column names with data that need to be inserted into test. + * If empty, all columns as keys and data as values will be put into hashMap + * and can be accessed by column names in test + * + * @return String + */ String dsArgs() default ""; + /** + * Column name with unique test identifiers + * + * @return String + */ String dsUid() default ""; + /** + * Column name that determines whether to execute test or not + * + * @return String + */ String executeColumn() default "Execute"; + /** + * executeColumn value from record which defines to execute test or not + * (if executeValue equalsIgnoreCase to value from executeColumn -> add test to run) + * + * @return String + */ String executeValue() default "y"; + /** + * Static arguments names, which values will be present in every test. + * Gets value from testNG suite by defined static arguments name + * + * @return String + */ String staticArgs() default ""; String groupColumn() default ""; @@ -47,6 +96,11 @@ String qTestColumn() default ""; + /** + * Column name, which contains values for test name overriding + * + * @return String + */ String testMethodColumn() default ""; String testMethodOwnerColumn() default ""; diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java index 4b41d8bbfc..2bc5eaa003 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java @@ -23,8 +23,6 @@ import java.util.HashMap; import java.util.Map; -import com.qaprosoft.carina.core.foundation.dataprovider.annotations.CsvDataSourceParameters; -import com.qaprosoft.carina.core.foundation.dataprovider.annotations.XlsDataSourceParameters; import org.apache.commons.lang3.ArrayUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,12 +39,22 @@ * Created by Patotsky on 16.12.2014. */ public class DataProviderFactory { - private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - private DataProviderFactory() { - } + private DataProviderFactory() {} + /** + * Creates data provider from specified source in annotations. + * + * @param annotations test method annotations. For using carina's custom data provider + * test should be annotated with @CsvDataSourceParameters or @XlsDataSourceParameters + * + * @param context test context + * @param m current test method + * @return Object[][] provider from specified source, + * where provider.length shows number of test to be invoked + * and provider[i][] contains test invocation args for each i test + */ public static Object[][] getDataProvider(Annotation[] annotations, ITestContext context, ITestNGMethod m) { Map tuidMap = Collections.synchronizedMap(new HashMap<>()); Map testNameFromColumn = Collections.synchronizedMap(new HashMap<>()); @@ -80,6 +88,13 @@ public static Object[][] getDataProvider(Annotation[] annotations, ITestContext return provider; } + /** + * Put data from test parameters to test's context. Necessary for correct test naming. + * + * @param context ITestContext. + * @param tuidMap Map contains tuid values for each test (if present) + * @param testNameFromColumn Map contains values for overriding test names from specified column + */ private static void putValuesToContext(ITestContext context, Map tuidMap, Map testNameFromColumn) { @@ -103,9 +118,8 @@ private static void putValuesToContext(ITestContext context, /** * Finds class name for data provider implementation. * - * @param annotation test method annotation. - * @return class name of data provider if it was found in annotation classname() method. - * Empty string if not. + * @param annotation test method annotation + * @return String class name of data provider if it was found in annotation classname() method. Empty if not */ private static String findProviderClass(Annotation annotation) { Class type = annotation.annotationType(); @@ -128,8 +142,8 @@ private static String findProviderClass(Annotation annotation) { /** * Initialize DataProvider based on className parameter. * - * @param providerClass String full className. - * @return DataProvider Instance. + * @param providerClass String full className + * @return Object DataProvider Instance */ private static Object initDataProvider(String providerClass) { Class clazz; diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java index db76241064..c5ddcf5b59 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java @@ -69,6 +69,13 @@ protected void addValueToSpecialMap(Map map, String column, Stri } } + /** + * Generates hash by class name, method name and arg values. + * + * @param args Object[] test method arguments + * @param method ITestNGMethod + * @return String hash + */ public static String hash(Object[] args, ITestNGMethod method) { String toHash = ""; toHash += Arrays.hashCode(args); @@ -77,16 +84,30 @@ public static String hash(Object[] args, ITestNGMethod method) { return String.valueOf(toHash.hashCode()); } - protected String getValueFromRow(Map xlsRow, String key) { - return getValueFromRow(xlsRow, List.of(key)); + /** + * Get value from data source in specified row. + * + * @param dataRow Map test method arguments/ record from source table + * @param key String argument name/ column name from source table + * @return String "value " from record + */ + protected String getValueFromRow(Map dataRow, String key) { + return getValueFromRow(dataRow, List.of(key)); } - protected String getValueFromRow(Map xlsRow, List keys) { + /** + * Get value from data source in specified row from several columns. + * + * @param dataRow Map test method arguments/ record from source table + * @param keys List argument names/ column names from source table + * @return String "value1, value2, ..., valueN " from record + */ + protected String getValueFromRow(Map dataRow, List keys) { StringBuilder valueRes = new StringBuilder(); for (String key : keys) { - if (xlsRow.containsKey(key)) { - String value = xlsRow.get(key); + if (dataRow.containsKey(key)) { + String value = dataRow.get(key); if (value != null && !value.isEmpty()) { valueRes.append(value); valueRes.append(", "); diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java index ea54252abf..e5ada6a875 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java @@ -43,6 +43,15 @@ public class CsvDataProvider extends BaseDataProvider { private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + /** + * Create data for tests from csv data source by annotation and context parameters + * + * @param annotation Annotation csv data source parameters + * @param context ITestContext + * @param testMethod ITestNGMethod + * + * @return Object[][] dataProvider + */ @SuppressWarnings("unchecked") @Override public Object[][] getDataProvider(Annotation annotation, ITestContext context, ITestNGMethod testMethod) { diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java index 0d6f584aae..d569137cc8 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java @@ -35,6 +35,15 @@ */ public class XlsDataProvider extends BaseDataProvider { + /** + * Create data for tests from xls data source by annotation and context parameters + * + * @param annotation Annotation xls data source parameters + * @param context ITestContext + * @param testMethod ITestNGMethod + * + * @return Object[][] dataProvider + */ @Override public Object[][] getDataProvider(Annotation annotation, ITestContext context, ITestNGMethod testMethod) { From 3b8856eba03e69b86d5a53abdbbca439927ebe3f Mon Sep 17 00:00:00 2001 From: Dima Grinevich Date: Mon, 13 Mar 2023 15:54:24 +0300 Subject: [PATCH 10/52] refactor(dataProvider): added comments for annotations, deprecated unused ones --- .../listeners/AbstractTestListener.java | 17 +++++ .../annotations/CsvDataSourceParameters.java | 51 ++++++++++---- .../annotations/XlsDataSourceParameters.java | 69 ++++++++++++++++++- .../core/DataProviderFactory.java | 12 ++-- .../core/impl/BaseDataProvider.java | 35 +++------- .../core/impl/CsvDataProvider.java | 27 ++------ .../core/impl/XlsDataProvider.java | 23 +------ .../dataprovider/parser/DSBean.java | 31 ++------- .../src/main/resources/config.properties | 2 +- 9 files changed, 151 insertions(+), 116 deletions(-) diff --git a/carina-core/src/main/java/com/qaprosoft/carina/core/foundation/listeners/AbstractTestListener.java b/carina-core/src/main/java/com/qaprosoft/carina/core/foundation/listeners/AbstractTestListener.java index 60839879f1..572f328fb8 100644 --- a/carina-core/src/main/java/com/qaprosoft/carina/core/foundation/listeners/AbstractTestListener.java +++ b/carina-core/src/main/java/com/qaprosoft/carina/core/foundation/listeners/AbstractTestListener.java @@ -154,6 +154,23 @@ public void onTestStart(ITestResult result) { generateParameters(result); + if (!result.getTestContext().getCurrentXmlTest().getAllParameters() + .containsKey(SpecialKeywords.EXCEL_DS_CUSTOM_PROVIDER) && + result.getParameters().length > 0) // set parameters from XLS only if test contains any parameter at + // all) + { + if (result.getTestContext().getCurrentXmlTest().getAllParameters() + .containsKey(SpecialKeywords.EXCEL_DS_ARGS)) { + DSBean dsBean = new DSBean(result.getTestContext()); + int index = 0; + for (String arg : dsBean.getArgs()) { + dsBean.getTestParams().put(arg, (String) result.getParameters()[index++]); + } + result.getTestContext().getCurrentXmlTest().setParameters(dsBean.getTestParams()); + + } + } + //TODO: do not write STARTED at message for retry! or move it into the DEBUG level! startItem(result, Messager.TEST_STARTED); diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/CsvDataSourceParameters.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/CsvDataSourceParameters.java index 9db7902f94..78190e940d 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/CsvDataSourceParameters.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/CsvDataSourceParameters.java @@ -38,53 +38,52 @@ char separator() default ','; /** - * The character to use for quoted elements + * The character to use for quoted elements when parsing * * @return char */ char quote() default '"'; /** - * Path to source data file + * Path to data source file * * @return String */ String path() default ""; /** - * Column names with data that need to be inserted into test. - * If empty, all columns as keys and data as values will be put into hashMap - * and can be accessed by column names in test + * Column names that need to be inserted into test from row. Several arguments should be split by ",". + * If empty, per row will be created hashMap with all data source columns as keys and row data as values. * * @return String */ String dsArgs() default ""; /** - * Column name with unique test identifiers + * Column name with unique test identifiers. Several name arguments should be split by ",". * * @return String */ String dsUid() default ""; /** - * Column name that determines whether to execute test or not + * Column name which rows determines whether to execute test or not * * @return String */ String executeColumn() default "Execute"; /** - * executeColumn value from record which defines to execute test or not - * (if executeValue equalsIgnoreCase to value from executeColumn -> add test to run) + * Defines to execute test or not. + * If executeValue equalsIgnoreCase to value from executeColumn -> add test row to run. * * @return String */ String executeValue() default "y"; /** - * Static arguments names, which values will be present in every test. - * Gets value from testNG suite by defined static arguments name + * Gets value from testNG suite by defined static arguments name. + * The same argument will present in every test * * @return String */ @@ -92,10 +91,6 @@ String groupColumn() default ""; - String testRailColumn() default ""; - - String qTestColumn() default ""; - /** * Column name, which contains values for test name overriding * @@ -103,7 +98,33 @@ */ String testMethodColumn() default ""; + /** + * Reason: not implemented + */ + @Deprecated(forRemoval = true, since = "1.0.0") + String testRailColumn() default ""; + + /** + * Reason: not implemented + */ + @Deprecated(forRemoval = true, since = "1.0.0") + String qTestColumn() default ""; + + /** + * Reason: not implemented + */ + @Deprecated(forRemoval = true, since = "1.0.0") String testMethodOwnerColumn() default ""; + /** + * Reason: not implemented + */ + @Deprecated(forRemoval = true, since = "1.0.0") String bugColumn() default ""; + + /** + * Reason: not implemented + */ + @Deprecated(forRemoval = true, since = "1.0.0") + String[] doNotRunTestNames() default {}; } \ No newline at end of file diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/XlsDataSourceParameters.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/XlsDataSourceParameters.java index 661a9e8a6f..09a7c79a00 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/XlsDataSourceParameters.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/XlsDataSourceParameters.java @@ -23,33 +23,98 @@ @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface XlsDataSourceParameters { + /** + * Define data provider instance + * + * @return String + */ String className() default "com.qaprosoft.carina.core.foundation.dataprovider.core.impl.XlsDataProvider"; String spreadsheetId() default ""; String sheet() default ""; + /** + * Path to data source file + * + * @return String + */ String path() default ""; + /** + * Column names that need to be inserted into test from row. Several arguments should be split by ",". + * If empty, per row will be created hashMap with all data source columns as keys and row data as values. + * + * @return String + */ String dsArgs() default ""; + /** + * Column name with unique test identifiers. Several name arguments should be split by ",". + * + * @return String + */ String dsUid() default ""; + /** + * Column name which rows determines whether to execute test or not + * + * @return String + */ String executeColumn() default "Execute"; + /** + * Defines to execute test or not. + * If executeValue equalsIgnoreCase to value from executeColumn -> add test row to run. + * + * @return String + */ String executeValue() default "y"; + /** + * Gets value from testNG suite by defined static arguments name. + * The same argument will present in every test + * + * @return String + */ String staticArgs() default ""; String groupColumn() default ""; + /** + * Column name, which contains values for test name overriding + * + * @return String + */ + String testMethodColumn() default ""; + + /** + * Reason: not implemented + */ + @Deprecated(forRemoval = true, since = "1.0.0") String testRailColumn() default ""; + /** + * Reason: not implemented + */ + @Deprecated(forRemoval = true, since = "1.0.0") String qTestColumn() default ""; - String testMethodColumn() default ""; - + /** + * Reason: not implemented + */ + @Deprecated(forRemoval = true, since = "1.0.0") String testMethodOwnerColumn() default ""; + /** + * Reason: not implemented + */ + @Deprecated(forRemoval = true, since = "1.0.0") String bugColumn() default ""; + + /** + * Reason: not implemented + */ + @Deprecated(forRemoval = true, since = "1.0.0") + String[] doNotRunTestNames() default {}; } diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java index 2bc5eaa003..1f1be85417 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java @@ -57,7 +57,8 @@ private DataProviderFactory() {} */ public static Object[][] getDataProvider(Annotation[] annotations, ITestContext context, ITestNGMethod m) { Map tuidMap = Collections.synchronizedMap(new HashMap<>()); - Map testNameFromColumn = Collections.synchronizedMap(new HashMap<>()); + Map testNameMap = Collections.synchronizedMap(new HashMap<>()); + Map testRailMap = Collections.synchronizedMap(new HashMap<>()); Object[][] provider = new Object[][]{}; for (Annotation annotation : annotations) { @@ -71,15 +72,17 @@ public static Object[][] getDataProvider(Annotation[] annotations, ITestContext if (providerObject instanceof BaseDataProvider) { BaseDataProvider dataProvider = (BaseDataProvider) providerObject; provider = ArrayUtils.addAll(provider, dataProvider.getDataProvider(annotation, context, m)); + tuidMap.putAll(dataProvider.getTuidMap()); - testNameFromColumn.putAll(dataProvider.getTestColumnNamesMap()); + testNameMap.putAll(dataProvider.getTestColumnNamesMap()); + testRailMap.putAll(dataProvider.getTestRailsArgsMap()); } } if (!GroupByMapper.getInstanceInt().isEmpty() || !GroupByMapper.getInstanceStrings().isEmpty()) { provider = getGroupedList(provider); } - putValuesToContext(context, tuidMap, testNameFromColumn); + putValuesToContext(context, tuidMap, testNameMap, testRailMap); // clear group by settings GroupByMapper.getInstanceInt().clear(); @@ -97,7 +100,8 @@ public static Object[][] getDataProvider(Annotation[] annotations, ITestContext */ private static void putValuesToContext(ITestContext context, Map tuidMap, - Map testNameFromColumn) { + Map testNameFromColumn, + Map testRailMap) { @SuppressWarnings("unchecked") Map contextTUID = (Map) context.getAttribute(SpecialKeywords.TUID); if (contextTUID != null) { diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java index c5ddcf5b59..b369f7eb41 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java @@ -30,8 +30,6 @@ public abstract class BaseDataProvider { protected Map tuidMap = Collections.synchronizedMap(new HashMap<>()); - protected Map testMethodOwnerArgsMap = Collections.synchronizedMap(new HashMap<>()); - protected Map testRailsArgsMap = Collections.synchronizedMap(new HashMap<>()); protected Map testColumnNamesMap = Collections.synchronizedMap(new HashMap<>()); public abstract Object[][] getDataProvider(Annotation annotation, ITestContext context, ITestNGMethod testMethod); @@ -48,31 +46,16 @@ public Map getTuidMap() { return tuidMap; } - public Map getTestMethodOwnerArgsMap() { - return testMethodOwnerArgsMap; - } - - public Map getTestRailsArgsMap() { - return testRailsArgsMap; - } - - protected void addValueToSpecialMap(Map map, String column, String hashCode, Map row) { - if (column != null) { - if (!column.isEmpty()) { - if (row.get(column) != null) { - if (!row.get(column).isEmpty()) { - // put into the args only non empty jira tickets - map.put(hashCode, row.get(column)); - } - } - } + protected void addValueToMap(Map map, String hashCode, String value) { + if (!value.isEmpty()) { + map.put(hashCode, value); } } /** * Generates hash by class name, method name and arg values. * - * @param args Object[] test method arguments + * @param args Object[] test method arguments * @param method ITestNGMethod * @return String hash */ @@ -88,7 +71,7 @@ public static String hash(Object[] args, ITestNGMethod method) { * Get value from data source in specified row. * * @param dataRow Map test method arguments/ record from source table - * @param key String argument name/ column name from source table + * @param key String argument name/ column name from source table * @return String "value " from record */ protected String getValueFromRow(Map dataRow, String key) { @@ -99,24 +82,24 @@ protected String getValueFromRow(Map dataRow, String key) { * Get value from data source in specified row from several columns. * * @param dataRow Map test method arguments/ record from source table - * @param keys List argument names/ column names from source table + * @param keys List argument names/ column names from source table * @return String "value1, value2, ..., valueN " from record */ protected String getValueFromRow(Map dataRow, List keys) { StringBuilder valueRes = new StringBuilder(); for (String key : keys) { - if (dataRow.containsKey(key)) { + if (!key.isEmpty() && dataRow.containsKey(key)) { String value = dataRow.get(key); if (value != null && !value.isEmpty()) { valueRes.append(value); - valueRes.append(", "); + valueRes.append(","); } } } if (valueRes.indexOf(",") != -1) { - valueRes.replace(valueRes.length() - 2, valueRes.length() - 1, ""); + valueRes.replace(valueRes.length() - 1, valueRes.length(), ""); } return valueRes.toString(); } diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java index e5ada6a875..07c5b23b5d 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java @@ -47,9 +47,8 @@ public class CsvDataProvider extends BaseDataProvider { * Create data for tests from csv data source by annotation and context parameters * * @param annotation Annotation csv data source parameters - * @param context ITestContext + * @param context ITestContext * @param testMethod ITestNGMethod - * * @return Object[][] dataProvider */ @SuppressWarnings("unchecked") @@ -62,10 +61,6 @@ public Object[][] getDataProvider(Annotation annotation, ITestContext context, I separator = parameters.separator(); quote = parameters.quote(); - String testRailColumn = dsBean.getTestRailColumn(); - if (testRailColumn.isEmpty()) - testRailColumn = dsBean.getQTestColumn(); - String groupByParameter = dsBean.getGroupColumn(); if (!groupByParameter.isEmpty()) { GroupByMapper.getInstanceInt().add(dsBean.getArgs().indexOf(groupByParameter)); @@ -141,8 +136,7 @@ public Object[][] getDataProvider(Annotation annotation, ITestContext context, I } else { int i; for (i = 0; i < dsBean.getArgs().size(); i++) { - args[rowIndex][i] = ParameterGenerator - .process(row.get(dsBean.getArgs().get(i))); + args[rowIndex][i] = ParameterGenerator.process(row.get(dsBean.getArgs().get(i))); } for (int j = 0; j < dsBean.getStaticArgs().size(); j++) { @@ -150,20 +144,9 @@ public Object[][] getDataProvider(Annotation annotation, ITestContext context, I } } - tuidMap.put(hash(args[rowIndex], testMethod), getValueFromRow(row, dsBean.getUidArgs())); - - if (!dsBean.getTestMethodColumn().isEmpty()) { - String testNameOverride = getValueFromRow(row, dsBean.getTestMethodColumn()); - if (!testNameOverride.isEmpty()) { - testColumnNamesMap.put(hash(args[rowIndex], testMethod), testNameOverride); - } - } - - // add testMethoOwner from xls datasource to special hashMap - addValueToSpecialMap(testMethodOwnerArgsMap, dsBean.getTestMethodOwnerColumn(), String.valueOf(Arrays.hashCode(args[rowIndex])), row); - - // add testrails cases from xls datasource to special hashMap - addValueToSpecialMap(testRailsArgsMap, testRailColumn, String.valueOf(Arrays.hashCode(args[rowIndex])), row); + String recordHash = hash(args[rowIndex], testMethod); + addValueToMap(tuidMap, recordHash, getValueFromRow(row, dsBean.getUidArgs())); + addValueToMap(testColumnNamesMap, recordHash, getValueFromRow(row, dsBean.getTestMethodColumn())); rowIndex++; } diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java index d569137cc8..216af1389d 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java @@ -17,7 +17,6 @@ import java.lang.annotation.Annotation; import java.util.Arrays; -import java.util.List; import java.util.Map; import org.testng.ITestContext; @@ -64,10 +63,6 @@ public Object[][] getDataProvider(Annotation annotation, ITestContext context, I GroupByMapper.getInstanceStrings().add(groupByParameter); } - String testRailColumn = dsBean.getTestRailColumn(); - if (testRailColumn.isEmpty()) - testRailColumn = dsBean.getQTestColumn(); - int width = 0; if (dsBean.getArgs().size() == 0) { width = dsBean.getStaticArgs().size() + 1; @@ -112,21 +107,9 @@ public Object[][] getDataProvider(Annotation annotation, ITestContext context, I args[rowIndex][i + j] = getStaticParam(dsBean.getStaticArgs().get(j), dsBean); } } - - tuidMap.put(hash(args[rowIndex], testMethod), getValueFromRow(xlsRow, dsBean.getUidArgs())); - - if (!dsBean.getTestMethodColumn().isEmpty()) { - String testNameOverride = getValueFromRow(xlsRow, dsBean.getTestMethodColumn()); - if (!testNameOverride.isEmpty()) { - testColumnNamesMap.put(hash(args[rowIndex], testMethod), testNameOverride); - } - } - - // add testMethoOwner from xls datasource to special hashMap - addValueToSpecialMap(testMethodOwnerArgsMap, dsBean.getTestMethodOwnerColumn(), String.valueOf(Arrays.hashCode(args[rowIndex])), xlsRow); - - // add testrails cases from xls datasource to special hashMap - addValueToSpecialMap(testRailsArgsMap, testRailColumn, String.valueOf(Arrays.hashCode(args[rowIndex])), xlsRow); + String recordHash = hash(args[rowIndex], testMethod); + addValueToMap(tuidMap, recordHash, getValueFromRow(xlsRow, dsBean.getUidArgs())); + addValueToMap(testColumnNamesMap, recordHash, getValueFromRow(xlsRow, dsBean.getTestMethodColumn())); rowIndex++; } diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/DSBean.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/DSBean.java index 92310b3d7c..3dba0afbe2 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/DSBean.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/DSBean.java @@ -24,6 +24,7 @@ import com.qaprosoft.carina.core.foundation.dataprovider.annotations.CsvDataSourceParameters; import com.qaprosoft.carina.core.foundation.dataprovider.annotations.XlsDataSourceParameters; import com.zebrunner.carina.utils.exception.InvalidArgsException; +import org.testng.ITestContext; public class DSBean { private Map testParams; @@ -37,11 +38,11 @@ public class DSBean { private String executeValue; private boolean spreadsheet; private String groupColumn; - private String testRailColumn; - private String qTestColumn; private String testMethodColumn; - private String testMethodOwnerColumn; - private String bugColumn; + + public DSBean(ITestContext context){ + initParamsFromSuite(context.getCurrentXmlTest().getAllParameters(), "excel"); + } public DSBean(XlsDataSourceParameters xlsDataSourceParameters, Map suiteParams) { // params init order: 1) from test annotation 2) from suite @@ -90,10 +91,7 @@ private void initParamsFromAnnotation(XlsDataSourceParameters parameters) { this.executeColumn = parameters.executeColumn(); this.executeValue = parameters.executeValue(); this.groupColumn = parameters.groupColumn(); - this.testRailColumn = parameters.testRailColumn(); - this.qTestColumn = parameters.qTestColumn(); this.testMethodColumn = parameters.testMethodColumn(); - this.testMethodOwnerColumn = parameters.testMethodOwnerColumn(); if (!parameters.dsArgs().isEmpty()) { this.args = Arrays.asList(parameters.dsArgs().replace(" ", "").split(",")); @@ -112,10 +110,7 @@ private void initParamsFromAnnotation(CsvDataSourceParameters parameters) { this.executeColumn = parameters.executeColumn(); this.executeValue = parameters.executeValue(); this.groupColumn = parameters.groupColumn(); - this.testRailColumn = parameters.testRailColumn(); - this.qTestColumn = parameters.qTestColumn(); this.testMethodColumn = parameters.testMethodColumn(); - this.testMethodOwnerColumn = parameters.testMethodOwnerColumn(); if (!parameters.dsArgs().isEmpty()) { this.args = Arrays.asList(parameters.dsArgs().replace(" ", "").split(",")); @@ -183,26 +178,10 @@ public String getGroupColumn() { return groupColumn; } - public String getTestRailColumn() { - return testRailColumn; - } - - public String getQTestColumn() { - return qTestColumn; - } - public String getTestMethodColumn() { return testMethodColumn; } - public String getTestMethodOwnerColumn() { - return testMethodOwnerColumn; - } - - public String getBugColumn() { - return bugColumn; - } - public boolean isSpreadsheet() { return spreadsheet; } diff --git a/carina-reporting/src/main/resources/config.properties b/carina-reporting/src/main/resources/config.properties index 70c96140d3..f5570a025b 100644 --- a/carina-reporting/src/main/resources/config.properties +++ b/carina-reporting/src/main/resources/config.properties @@ -3,7 +3,7 @@ max_log_file_size=150 max_screen_history=NULL suite_name=NULL -test_naming_pattern={tuid}{test_name} - {method_name} +test_naming_pattern={tuid} - {test_name} - {method_name} report_url=NULL custom_artifacts_folder=NULL project_report_directory=NULL From 6f6f1f01bf8ff6b335327e8e078bbf6a3a6c9c2b Mon Sep 17 00:00:00 2001 From: Dima Grinevich Date: Mon, 13 Mar 2023 15:58:36 +0300 Subject: [PATCH 11/52] refactor(DataProviderFactory.java): deleted testRail map --- .../foundation/dataprovider/core/DataProviderFactory.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java index 1f1be85417..0396ab3b9d 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java @@ -58,7 +58,7 @@ private DataProviderFactory() {} public static Object[][] getDataProvider(Annotation[] annotations, ITestContext context, ITestNGMethod m) { Map tuidMap = Collections.synchronizedMap(new HashMap<>()); Map testNameMap = Collections.synchronizedMap(new HashMap<>()); - Map testRailMap = Collections.synchronizedMap(new HashMap<>()); + Object[][] provider = new Object[][]{}; for (Annotation annotation : annotations) { @@ -75,14 +75,13 @@ public static Object[][] getDataProvider(Annotation[] annotations, ITestContext tuidMap.putAll(dataProvider.getTuidMap()); testNameMap.putAll(dataProvider.getTestColumnNamesMap()); - testRailMap.putAll(dataProvider.getTestRailsArgsMap()); } } if (!GroupByMapper.getInstanceInt().isEmpty() || !GroupByMapper.getInstanceStrings().isEmpty()) { provider = getGroupedList(provider); } - putValuesToContext(context, tuidMap, testNameMap, testRailMap); + putValuesToContext(context, tuidMap, testNameMap); // clear group by settings GroupByMapper.getInstanceInt().clear(); @@ -100,8 +99,7 @@ public static Object[][] getDataProvider(Annotation[] annotations, ITestContext */ private static void putValuesToContext(ITestContext context, Map tuidMap, - Map testNameFromColumn, - Map testRailMap) { + Map testNameFromColumn) { @SuppressWarnings("unchecked") Map contextTUID = (Map) context.getAttribute(SpecialKeywords.TUID); if (contextTUID != null) { From 33cb2ad637b2abcdd454a9db6d5e1c9ee416b14b Mon Sep 17 00:00:00 2001 From: Dima Grinevich Date: Tue, 14 Mar 2023 12:09:23 +0300 Subject: [PATCH 12/52] refactor(dataprovider): removed code duplication, splitted methods by functionality into several --- .../carina/core/testng/TestNamingService.java | 2 +- .../core/DataProviderFactory.java | 23 ++- .../core/impl/BaseDataProvider.java | 112 ++++++++++++--- .../core/impl/CsvDataProvider.java | 135 +++--------------- .../core/impl/XlsDataProvider.java | 79 ++-------- .../dataprovider/parser/AbstractTable.java | 52 +++++++ .../parser/AbstractXLSParser.java | 23 --- .../dataprovider/parser/DSBean.java | 23 +-- .../dataprovider/parser/csv/CSVParser.java | 57 ++++++++ .../dataprovider/parser/csv/CSVTable.java | 48 +++++++ .../parser/{ => xls}/XLSCache.java | 8 +- .../parser/{ => xls}/XLSChildTable.java | 6 +- .../parser/{ => xls}/XLSParser.java | 8 +- .../parser/{ => xls}/XLSTable.java | 60 ++------ .../carina/utils/ParameterGenerator.java | 23 ++- .../parser/CellLinksIntegrationTest.java | 4 +- .../src/main/resources/config.properties | 2 +- 17 files changed, 353 insertions(+), 312 deletions(-) create mode 100644 carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/AbstractTable.java delete mode 100644 carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/AbstractXLSParser.java create mode 100644 carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/csv/CSVParser.java create mode 100644 carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/csv/CSVTable.java rename carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/{ => xls}/XLSCache.java (99%) rename carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/{ => xls}/XLSChildTable.java (99%) rename carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/{ => xls}/XLSParser.java (97%) rename carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/{ => xls}/XLSTable.java (79%) diff --git a/carina-core/src/main/java/com/zebrunner/carina/core/testng/TestNamingService.java b/carina-core/src/main/java/com/zebrunner/carina/core/testng/TestNamingService.java index 562bf917f0..6246e3fc39 100644 --- a/carina-core/src/main/java/com/zebrunner/carina/core/testng/TestNamingService.java +++ b/carina-core/src/main/java/com/zebrunner/carina/core/testng/TestNamingService.java @@ -168,7 +168,7 @@ private static String getMethodUID(ITestResult result) { if (tuidMap != null) { String testHash = BaseDataProvider.hash(result.getParameters(), result.getMethod()); if (tuidMap.containsKey(testHash)) { - methodUID = tuidMap.get(testHash); + methodUID = tuidMap.get(testHash) + " - "; } } diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java index 0396ab3b9d..1876a29fe2 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java @@ -15,6 +15,17 @@ *******************************************************************************/ package com.qaprosoft.carina.core.foundation.dataprovider.core; +import com.qaprosoft.carina.core.foundation.dataprovider.core.groupping.GroupByImpl; +import com.qaprosoft.carina.core.foundation.dataprovider.core.groupping.GroupByMapper; +import com.qaprosoft.carina.core.foundation.dataprovider.core.groupping.exceptions.GroupByException; +import com.qaprosoft.carina.core.foundation.dataprovider.core.impl.BaseDataProvider; +import com.zebrunner.carina.utils.commons.SpecialKeywords; +import org.apache.commons.lang3.ArrayUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.ITestContext; +import org.testng.ITestNGMethod; + import java.lang.annotation.Annotation; import java.lang.invoke.MethodHandles; import java.lang.reflect.Constructor; @@ -23,18 +34,6 @@ import java.util.HashMap; import java.util.Map; -import org.apache.commons.lang3.ArrayUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.ITestContext; -import org.testng.ITestNGMethod; - -import com.zebrunner.carina.utils.commons.SpecialKeywords; -import com.qaprosoft.carina.core.foundation.dataprovider.core.groupping.GroupByImpl; -import com.qaprosoft.carina.core.foundation.dataprovider.core.groupping.GroupByMapper; -import com.qaprosoft.carina.core.foundation.dataprovider.core.groupping.exceptions.GroupByException; -import com.qaprosoft.carina.core.foundation.dataprovider.core.impl.BaseDataProvider; - /** * Created by Patotsky on 16.12.2014. */ diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java index b369f7eb41..3b30e93251 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java @@ -15,14 +15,14 @@ *******************************************************************************/ package com.qaprosoft.carina.core.foundation.dataprovider.core.impl; -import java.lang.annotation.Annotation; -import java.util.*; - +import com.qaprosoft.carina.core.foundation.dataprovider.parser.AbstractTable; +import com.qaprosoft.carina.core.foundation.dataprovider.parser.DSBean; +import com.zebrunner.carina.utils.ParameterGenerator; import org.testng.ITestContext; import org.testng.ITestNGMethod; -import com.qaprosoft.carina.core.foundation.dataprovider.parser.DSBean; -import com.zebrunner.carina.utils.ParameterGenerator; +import java.lang.annotation.Annotation; +import java.util.*; /** * Created by Patotsky on 19.12.2014. @@ -34,18 +34,6 @@ public abstract class BaseDataProvider { public abstract Object[][] getDataProvider(Annotation annotation, ITestContext context, ITestNGMethod testMethod); - protected static Object getStaticParam(String name, DSBean dsBean) { - return ParameterGenerator.process(dsBean.getTestParams().get(name)); - } - - public Map getTestColumnNamesMap() { - return testColumnNamesMap; - } - - public Map getTuidMap() { - return tuidMap; - } - protected void addValueToMap(Map map, String hashCode, String value) { if (!value.isEmpty()) { map.put(hashCode, value); @@ -104,4 +92,94 @@ protected String getValueFromRow(Map dataRow, List keys) return valueRes.toString(); } + protected Object[][] fillDataProviderWithData(AbstractTable table, DSBean dsBean, ITestNGMethod testMethod) { + processTable(table); + + Object[][] dataProvider = declareDataProviderArray(table, dsBean); + + if (dsBean.isArgsToHashMap()) { + fillArgsAsHashMap(dataProvider, table, dsBean); + } else { + fillArgsAsArray(dataProvider, table, dsBean); + } + + configureTestNamingVars(dataProvider, dsBean, table, testMethod); + + return dataProvider; + } + + private void processTable(AbstractTable table) { + for (Map row : table.getDataRows()) { + ParameterGenerator.processMap(row); + } + } + + private void fillArgsAsHashMap(Object[][] dataProvider, AbstractTable table, DSBean dsBean) { + for (int rowIndex = 0; rowIndex < dataProvider.length; rowIndex++) { + Map row = table.getDataRows().get(rowIndex); + + // populate arguments by parameters from data source + dataProvider[rowIndex][0] = row; + + // populate the rest of arguments by static parameters from testParams + for (int staticArgsColumn = 0; staticArgsColumn < dsBean.getStaticArgs().size(); staticArgsColumn++) { + String staticArgName = dsBean.getStaticArgs().get(staticArgsColumn); + dataProvider[rowIndex][staticArgsColumn + 1] = getStaticParam(staticArgName, dsBean); + } + } + } + + private void fillArgsAsArray(Object[][] dataProvider, AbstractTable table, DSBean dsBean) { + for (int rowIndex = 0; rowIndex < dataProvider.length; rowIndex++) { + Map row = table.getDataRows().get(rowIndex); + + // populate arguments by parameters from data source + for (int argsColumn = 0; argsColumn < dsBean.getArgs().size(); argsColumn++) { + dataProvider[rowIndex][argsColumn] = row.get(dsBean.getArgs().get(argsColumn)); + } + + // populate the rest of arguments by static parameters from testParams + for (int staticArgsColumn = 0; staticArgsColumn < dsBean.getStaticArgs().size(); staticArgsColumn++) { + String staticArgName = dsBean.getStaticArgs().get(staticArgsColumn); + dataProvider[rowIndex][staticArgsColumn + row.entrySet().size()] = getStaticParam(staticArgName, dsBean); + } + } + } + + private Object[][] declareDataProviderArray(AbstractTable table, DSBean dsBean) { + int numberOfRowsToExecute = table.getDataRows().size(); + + int numberOfArgsInTest; + if (dsBean.isArgsToHashMap()) { + // first element is dynamic HashMap + numberOfArgsInTest = 1 + dsBean.getStaticArgs().size(); + } else { + numberOfArgsInTest = dsBean.getArgs().size() + dsBean.getStaticArgs().size(); + } + + return new Object[numberOfRowsToExecute][numberOfArgsInTest]; + } + + private void configureTestNamingVars(Object[][] dataProvider, DSBean dsBean, AbstractTable table, ITestNGMethod testNGMethod) { + for (int rowIndex = 0; rowIndex < dataProvider.length; rowIndex++) { + Map row = table.getDataRows().get(rowIndex); + + String rowHash = hash(dataProvider[rowIndex], testNGMethod); + addValueToMap(tuidMap, rowHash, getValueFromRow(row, dsBean.getUidArgs())); + addValueToMap(testColumnNamesMap, rowHash, getValueFromRow(row, dsBean.getTestMethodColumn())); + } + } + + protected static Object getStaticParam(String name, DSBean dsBean) { + return ParameterGenerator.process(dsBean.getTestParams().get(name)); + } + + public Map getTestColumnNamesMap() { + return testColumnNamesMap; + } + + public Map getTuidMap() { + return tuidMap; + } + } diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java index 07c5b23b5d..1245b919f9 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java @@ -15,27 +15,23 @@ *******************************************************************************/ package com.qaprosoft.carina.core.foundation.dataprovider.core.impl; -import java.io.FileReader; -import java.io.IOException; -import java.lang.annotation.Annotation; -import java.lang.invoke.MethodHandles; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.ITestContext; -import org.testng.ITestNGMethod; - +import au.com.bytecode.opencsv.CSVReader; import com.qaprosoft.carina.core.foundation.dataprovider.annotations.CsvDataSourceParameters; import com.qaprosoft.carina.core.foundation.dataprovider.core.groupping.GroupByMapper; import com.qaprosoft.carina.core.foundation.dataprovider.parser.DSBean; +import com.qaprosoft.carina.core.foundation.dataprovider.parser.csv.CSVParser; +import com.qaprosoft.carina.core.foundation.dataprovider.parser.csv.CSVTable; import com.zebrunner.carina.utils.ParameterGenerator; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.ITestContext; +import org.testng.ITestNGMethod; -import au.com.bytecode.opencsv.CSVReader; +import java.io.FileReader; +import java.io.IOException; +import java.lang.annotation.Annotation; +import java.lang.invoke.MethodHandles; +import java.util.*; /** * Created by Patotsky on 16.12.2014. @@ -49,6 +45,7 @@ public class CsvDataProvider extends BaseDataProvider { * @param annotation Annotation csv data source parameters * @param context ITestContext * @param testMethod ITestNGMethod + * * @return Object[][] dataProvider */ @SuppressWarnings("unchecked") @@ -57,114 +54,16 @@ public Object[][] getDataProvider(Annotation annotation, ITestContext context, I CsvDataSourceParameters parameters = (CsvDataSourceParameters) annotation; DSBean dsBean = new DSBean(parameters, context.getCurrentXmlTest().getAllParameters()); - char separator, quote; - separator = parameters.separator(); - quote = parameters.quote(); + CSVTable csvTable = CSVParser.parseCsvFile(dsBean, parameters.separator(), parameters.quote()); + csvTable.excludeEntriesForNonExecution(); String groupByParameter = dsBean.getGroupColumn(); if (!groupByParameter.isEmpty()) { GroupByMapper.getInstanceInt().add(dsBean.getArgs().indexOf(groupByParameter)); GroupByMapper.getInstanceStrings().add(groupByParameter); } + GroupByMapper.setIsHashMapped(dsBean.isArgsToHashMap()); - if (dsBean.getArgs().isEmpty()) { - GroupByMapper.setIsHashMapped(true); - } - CSVReader reader; - List list = new ArrayList<>(); - - try { - String csvFile = ClassLoader.getSystemResource(dsBean.getDsFile()).getFile(); - reader = new CSVReader(new FileReader(csvFile), separator, quote); - list = reader.readAll(); - } catch (IOException e) { - LOGGER.error("Unable to read data from CSV DataProvider", e); - } - - if (list.size() == 0) { - throw new RuntimeException("Unable to retrieve data from CSV DataProvider! Verify separator and quote settings."); - } - List headers = Arrays.asList(list.get(0)); - list.remove(0); - - List> dsData = initData(headers, list); - // exclude those lines which don't satisfy executeColumn/executeValue filter - for (int i = 0; i < dsData.size(); i++) { - Map row = dsData.get(i); - if (!row.get(dsBean.getExecuteColumn()).equalsIgnoreCase(dsBean.getExecuteValue())) { - dsData.remove(i); - i--; - } - } - - int listSize = list.size(); - - int width = 0; - if (dsBean.getArgs().size() == 0) { - // first element is dynamic HashMap - width = dsBean.getStaticArgs().size() + 1; - } else { - width = dsBean.getArgs().size() + dsBean.getStaticArgs().size(); - } - - Object[][] args = new Object[listSize][width]; - int rowIndex = 0; - for (Map row : dsData) { - - if (dsBean.getArgs().size() == 0) { - for (Map.Entry entry : row.entrySet()) { - if (entry == null) - continue; - - String value = entry.getValue(); - if (value == null) - continue; - - Object param = ParameterGenerator.process(value); - if (param == null) - continue; - - String newValue = param.toString(); - if (!value.equals(newValue)) { - entry.setValue(newValue); - } - } - args[rowIndex][0] = row; - for (int i = 0; i < dsBean.getStaticArgs().size(); i++) { - args[rowIndex][i + 1] = getStaticParam(dsBean.getStaticArgs().get(i), dsBean); - } - } else { - int i; - for (i = 0; i < dsBean.getArgs().size(); i++) { - args[rowIndex][i] = ParameterGenerator.process(row.get(dsBean.getArgs().get(i))); - } - - for (int j = 0; j < dsBean.getStaticArgs().size(); j++) { - args[rowIndex][i + j] = getStaticParam(dsBean.getStaticArgs().get(j), dsBean); - } - } - - String recordHash = hash(args[rowIndex], testMethod); - addValueToMap(tuidMap, recordHash, getValueFromRow(row, dsBean.getUidArgs())); - addValueToMap(testColumnNamesMap, recordHash, getValueFromRow(row, dsBean.getTestMethodColumn())); - - rowIndex++; - } - - return args; - } - - private List> initData(List headers, List values) { - List> list = new ArrayList<>(); - - for (String[] value : values) { - Map map = new HashMap<>(); - list.add(map); - for (int j = 0; j < headers.size(); j++) { - map.put(headers.get(j), value[j]); - } - } - - return list; + return fillDataProviderWithData(csvTable, dsBean, testMethod); } } diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java index 216af1389d..92d88ffa7b 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java @@ -15,19 +15,15 @@ *******************************************************************************/ package com.qaprosoft.carina.core.foundation.dataprovider.core.impl; -import java.lang.annotation.Annotation; -import java.util.Arrays; -import java.util.Map; - -import org.testng.ITestContext; -import org.testng.ITestNGMethod; - import com.qaprosoft.carina.core.foundation.dataprovider.annotations.XlsDataSourceParameters; import com.qaprosoft.carina.core.foundation.dataprovider.core.groupping.GroupByMapper; import com.qaprosoft.carina.core.foundation.dataprovider.parser.DSBean; -import com.qaprosoft.carina.core.foundation.dataprovider.parser.XLSParser; -import com.qaprosoft.carina.core.foundation.dataprovider.parser.XLSTable; -import com.zebrunner.carina.utils.ParameterGenerator; +import com.qaprosoft.carina.core.foundation.dataprovider.parser.xls.XLSParser; +import com.qaprosoft.carina.core.foundation.dataprovider.parser.xls.XLSTable; +import org.testng.ITestContext; +import org.testng.ITestNGMethod; + +import java.lang.annotation.Annotation; /** * Created by Patotsky on 16.12.2014. @@ -45,75 +41,18 @@ public class XlsDataProvider extends BaseDataProvider { */ @Override public Object[][] getDataProvider(Annotation annotation, ITestContext context, ITestNGMethod testMethod) { - XlsDataSourceParameters parameters = (XlsDataSourceParameters) annotation; - DSBean dsBean = new DSBean(parameters, context.getCurrentXmlTest().getAllParameters()); - XLSTable dsData = XLSParser.parseSpreadSheet(dsBean.getDsFile(), dsBean.getXlsSheet(), dsBean.getExecuteColumn(), dsBean.getExecuteValue()); - - - if (dsBean.getArgs().isEmpty()) { - GroupByMapper.setIsHashMapped(true); - } + XLSTable xlsTable = XLSParser.parseSpreadSheet(dsBean.getDsFile(), dsBean.getXlsSheet(), dsBean.getExecuteColumn(), dsBean.getExecuteValue()); String groupByParameter = dsBean.getGroupColumn(); if (!groupByParameter.isEmpty()) { GroupByMapper.getInstanceInt().add(dsBean.getArgs().indexOf(groupByParameter)); GroupByMapper.getInstanceStrings().add(groupByParameter); } + GroupByMapper.setIsHashMapped(dsBean.isArgsToHashMap()); - int width = 0; - if (dsBean.getArgs().size() == 0) { - width = dsBean.getStaticArgs().size() + 1; - } else { - width = dsBean.getArgs().size() + dsBean.getStaticArgs().size(); - } - Object[][] args = new Object[dsData.getDataRows().size()][width]; - - int rowIndex = 0; - for (Map xlsRow : dsData.getDataRows()) { - - if (dsBean.getArgs().size() == 0) { - // process each column in xlsRow data obligatory replacing special keywords like UUID etc - for (Map.Entry entry : xlsRow.entrySet()) { - if (entry == null) - continue; - - String value = entry.getValue(); - if (value == null) - continue; - - Object param = ParameterGenerator.process(value); - if (param == null) - continue; - - String newValue = param.toString(); - if (!value.equals(newValue)) { - entry.setValue(newValue); - } - } - args[rowIndex][0] = xlsRow; - for (int i = 0; i < dsBean.getStaticArgs().size(); i++) { - args[rowIndex][i + 1] = getStaticParam(dsBean.getStaticArgs().get(i), dsBean); - } - } else { - int i; - for (i = 0; i < dsBean.getArgs().size(); i++) { - args[rowIndex][i] = ParameterGenerator.process(xlsRow.get(dsBean.getArgs().get(i))); - } - // populate the rest of items by static parameters from testParams - for (int j = 0; j < dsBean.getStaticArgs().size(); j++) { - args[rowIndex][i + j] = getStaticParam(dsBean.getStaticArgs().get(j), dsBean); - } - } - String recordHash = hash(args[rowIndex], testMethod); - addValueToMap(tuidMap, recordHash, getValueFromRow(xlsRow, dsBean.getUidArgs())); - addValueToMap(testColumnNamesMap, recordHash, getValueFromRow(xlsRow, dsBean.getTestMethodColumn())); - - rowIndex++; - } - - return args; + return fillDataProviderWithData(xlsTable, dsBean, testMethod); } } diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/AbstractTable.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/AbstractTable.java new file mode 100644 index 0000000000..42ae18e025 --- /dev/null +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/AbstractTable.java @@ -0,0 +1,52 @@ +package com.qaprosoft.carina.core.foundation.dataprovider.parser; + +import java.util.*; + +public abstract class AbstractTable { + protected List headers; + protected List> dataRows; + protected String executeColumn; + protected String executeValue; + + public AbstractTable() { + headers = Collections.synchronizedList(new LinkedList()); + dataRows = Collections.synchronizedList(new LinkedList>()); + } + + public AbstractTable(String executeColumn, String executeValue) { + this(); + this.executeColumn = executeColumn; + this.executeValue = executeValue; + } + + public List getHeaders() { + return headers; + } + + public List> getDataRows() { + return dataRows; + } + + public String getExecuteColumn() { + return executeColumn; + } + + public void setExecuteColumn(String executeColumn) { + this.executeColumn = executeColumn; + } + + public String getExecuteValue() { + return executeValue; + } + + public void setExecuteValue(String executeValue) { + this.executeValue = executeValue; + } + + public void setHeaders(Collection row) { + headers.clear(); + headers.addAll(row); + } + + public abstract void addDataRow(List row); +} diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/AbstractXLSParser.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/AbstractXLSParser.java deleted file mode 100644 index 3918872c5b..0000000000 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/AbstractXLSParser.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright 2020-2022 Zebrunner Inc (https://www.zebrunner.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *******************************************************************************/ -package com.qaprosoft.carina.core.foundation.dataprovider.parser; - -abstract class AbstractXLSParser { - - protected static XLSTable prepareDataTable(String executeColumn, String executeValue) { - return executeColumn != null && executeValue != null ? new XLSTable(executeColumn, executeValue) : new XLSTable(); - } -} diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/DSBean.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/DSBean.java index 3dba0afbe2..8370cfa0bc 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/DSBean.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/DSBean.java @@ -15,17 +15,17 @@ *******************************************************************************/ package com.qaprosoft.carina.core.foundation.dataprovider.parser; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -import com.zebrunner.carina.utils.commons.SpecialKeywords; import com.qaprosoft.carina.core.foundation.dataprovider.annotations.CsvDataSourceParameters; import com.qaprosoft.carina.core.foundation.dataprovider.annotations.XlsDataSourceParameters; +import com.zebrunner.carina.utils.commons.SpecialKeywords; import com.zebrunner.carina.utils.exception.InvalidArgsException; import org.testng.ITestContext; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + public class DSBean { private Map testParams; private List args = new ArrayList<>(); @@ -40,7 +40,7 @@ public class DSBean { private String groupColumn; private String testMethodColumn; - public DSBean(ITestContext context){ + public DSBean(ITestContext context) { initParamsFromSuite(context.getCurrentXmlTest().getAllParameters(), "excel"); } @@ -81,7 +81,6 @@ public DSBean(CsvDataSourceParameters csvDataSourceParameters, Map data = readData(dsBean, separator, quote); + if (data.size() == 0) { + throw new RuntimeException("Unable to retrieve data from CSV DataProvider! Verify separator and quote settings."); + } + + csvTable.setHeaders(Arrays.asList(data.get(0))); + + mapData(csvTable, data); + + return csvTable; + } + + @SuppressWarnings("unchecked") + private static List readData(DSBean dsBean, char separator, char quote) { + CSVReader reader = null; + List list = new ArrayList<>(); + try { + String csvFile = ClassLoader.getSystemResource(dsBean.getDsFile()).getFile(); + reader = new CSVReader(new FileReader(csvFile), separator, quote); + list = reader.readAll(); + } catch (IOException e) { + LOGGER.error("Unable to read data from CSV DataProvider", e); + } finally { + try { + assert reader != null; + reader.close(); + } catch (IOException e) { + LOGGER.error("Unable to close CSV Reader", e); + } + } + return list; + } + + private static void mapData(CSVTable table, List data) { + for (int i = 1; i < data.size(); i ++) { + table.addDataRow(List.of(data.get(i))); + } + } +} diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/csv/CSVTable.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/csv/CSVTable.java new file mode 100644 index 0000000000..57f622dedf --- /dev/null +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/csv/CSVTable.java @@ -0,0 +1,48 @@ +package com.qaprosoft.carina.core.foundation.dataprovider.parser.csv; + +import com.qaprosoft.carina.core.foundation.dataprovider.parser.AbstractTable; +import com.qaprosoft.carina.core.foundation.dataprovider.parser.DSBean; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.lang.invoke.MethodHandles; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class CSVTable extends AbstractTable { + private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + + public CSVTable() { + super(); + } + + public CSVTable(String executeColumn, String executeValue) { + super(executeColumn, executeValue); + } + + @Override + public void addDataRow(List row) { + if (row.size() == headers.size()) { + Map rowMap = new HashMap<>(); + for (int i = 0; i < headers.size(); i++) { + rowMap.put(headers.get(i), row.get(i)); + } + if (!rowMap.isEmpty()) { + dataRows.add(rowMap); + } + } else { + LOGGER.error("Headers size and row size didn't match, can't add data to table"); + } + } + + public void excludeEntriesForNonExecution() { + for (int i = 0; i < dataRows.size(); i++) { + Map row = dataRows.get(i); + if (!row.get(executeColumn).equalsIgnoreCase(executeValue)) { + dataRows.remove(i); + i--; + } + } + } +} diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/XLSCache.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/xls/XLSCache.java similarity index 99% rename from carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/XLSCache.java rename to carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/xls/XLSCache.java index 7ed5b5b92b..14265a6e13 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/XLSCache.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/xls/XLSCache.java @@ -13,16 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ -package com.qaprosoft.carina.core.foundation.dataprovider.parser; +package com.qaprosoft.carina.core.foundation.dataprovider.parser.xls; + +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.ss.usermodel.WorkbookFactory; import java.io.InputStream; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; -import org.apache.poi.ss.usermodel.Workbook; -import org.apache.poi.ss.usermodel.WorkbookFactory; - public class XLSCache { private static Map xlsCache = new HashMap(); diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/XLSChildTable.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/xls/XLSChildTable.java similarity index 99% rename from carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/XLSChildTable.java rename to carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/xls/XLSChildTable.java index 9e2036224e..4fe8d4e015 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/XLSChildTable.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/xls/XLSChildTable.java @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ -package com.qaprosoft.carina.core.foundation.dataprovider.parser; +package com.qaprosoft.carina.core.foundation.dataprovider.parser.xls; + +import org.apache.poi.ss.usermodel.Row; import java.util.HashMap; import java.util.Map; -import org.apache.poi.ss.usermodel.Row; - public class XLSChildTable extends XLSTable { public void addDataRow(Row row) { Map dataMap = new HashMap(); diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/XLSParser.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/xls/XLSParser.java similarity index 97% rename from carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/XLSParser.java rename to carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/xls/XLSParser.java index a0d1b0da17..28f5262321 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/XLSParser.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/xls/XLSParser.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ -package com.qaprosoft.carina.core.foundation.dataprovider.parser; +package com.qaprosoft.carina.core.foundation.dataprovider.parser.xls; import java.io.File; import java.lang.invoke.MethodHandles; @@ -38,7 +38,7 @@ import com.zebrunner.carina.utils.exception.DataLoadingException; import com.zebrunner.carina.utils.exception.InvalidArgsException; -public class XLSParser extends AbstractXLSParser { +public class XLSParser { private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private static DataFormatter df; private static FormulaEvaluator evaluator; @@ -261,4 +261,8 @@ private static XLSChildTable createChildTable(Sheet sheet, int rowNumber) { childTable.addDataRow(sheet.getRow(rowNumber)); return childTable; } + + private static XLSTable prepareDataTable(String executeColumn, String executeValue) { + return executeColumn != null && executeValue != null ? new XLSTable(executeColumn, executeValue) : new XLSTable(); + } } diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/XLSTable.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/xls/XLSTable.java similarity index 79% rename from carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/XLSTable.java rename to carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/xls/XLSTable.java index 9f0210d9f5..9cdf54fc40 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/XLSTable.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/xls/XLSTable.java @@ -13,17 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ -package com.qaprosoft.carina.core.foundation.dataprovider.parser; - -import java.lang.invoke.MethodHandles; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.function.Function; +package com.qaprosoft.carina.core.foundation.dataprovider.parser.xls; +import com.qaprosoft.carina.core.foundation.dataprovider.parser.AbstractTable; import org.apache.commons.lang3.StringUtils; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; @@ -31,24 +23,20 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class XLSTable { +import java.lang.invoke.MethodHandles; +import java.util.*; +import java.util.function.Function; + +public class XLSTable extends AbstractTable { private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private final static String FK_PREFIX = "FK_LINK_"; - private List headers; - private List> dataRows; - private String executeColumn; - private String executeValue; - public XLSTable() { - headers = new LinkedList(); - dataRows = Collections.synchronizedList(new LinkedList>()); + super(); } public XLSTable(String executeColumn, String executeValue) { - this(); - this.executeColumn = executeColumn; - this.executeValue = executeValue; + super(executeColumn, executeValue); } public void setHeaders(Row row) { @@ -58,11 +46,6 @@ public void setHeaders(Row row) { } } - public void setHeaders(Collection row) { - headers.clear(); - headers.addAll(row); - } - public void addDataRow(Row row, Workbook wb, Sheet sheet) { if (row == null) { // don't add any data row if it is null. It seems like there is empty row in xls file @@ -71,6 +54,7 @@ public void addDataRow(Row row, Workbook wb, Sheet sheet) { addDataRow(rowIndex -> XLSParser.getCellValue(row.getCell(rowIndex)), row, wb, sheet); } + @Override public void addDataRow(List row) { if (row == null) { return; @@ -137,28 +121,4 @@ private void merge(XLSChildTable childRow, Map dataMap) { } } } - - public List getHeaders() { - return headers; - } - - public List> getDataRows() { - return dataRows; - } - - public String getExecuteColumn() { - return executeColumn; - } - - public void setExecuteColumn(String executeColumn) { - this.executeColumn = executeColumn; - } - - public String getExecuteValue() { - return executeValue; - } - - public void setExecuteValue(String executeValue) { - this.executeValue = executeValue; - } } diff --git a/carina-dataprovider/src/main/java/com/zebrunner/carina/utils/ParameterGenerator.java b/carina-dataprovider/src/main/java/com/zebrunner/carina/utils/ParameterGenerator.java index 596a820ab8..d5e5c0bd43 100644 --- a/carina-dataprovider/src/main/java/com/zebrunner/carina/utils/ParameterGenerator.java +++ b/carina-dataprovider/src/main/java/com/zebrunner/carina/utils/ParameterGenerator.java @@ -16,6 +16,7 @@ package com.zebrunner.carina.utils; import java.lang.invoke.MethodHandles; +import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -24,7 +25,7 @@ import org.slf4j.LoggerFactory; import com.zebrunner.carina.utils.commons.SpecialKeywords; -import com.qaprosoft.carina.core.foundation.dataprovider.parser.XLSParser; +import com.qaprosoft.carina.core.foundation.dataprovider.parser.xls.XLSParser; import com.zebrunner.carina.utils.exception.InvalidArgsException; import com.zebrunner.carina.utils.resources.L10N; @@ -121,6 +122,26 @@ public static Object process(String param) { return param; } + public static void processMap(Map paramsMap) { + for (Map.Entry entry : paramsMap.entrySet()) { + if (entry == null) + continue; + + String value = entry.getValue(); + if (value == null) + continue; + + Object param = process(value); + if (param == null) + continue; + + String newValue = param.toString(); + if (!value.equals(newValue)) { + entry.setValue(newValue); + } + } + } + private static String getValueFromXLS(String xlsSheetKey) { if (StringUtils.isEmpty(xlsSheetKey)) { throw new InvalidArgsException("Invalid excel key, should be 'xls_file#sheet#key'."); diff --git a/carina-dataprovider/src/test/java/com/qaprosoft/carina/core/foundation/parser/CellLinksIntegrationTest.java b/carina-dataprovider/src/test/java/com/qaprosoft/carina/core/foundation/parser/CellLinksIntegrationTest.java index e69fa1a258..55365d7258 100644 --- a/carina-dataprovider/src/test/java/com/qaprosoft/carina/core/foundation/parser/CellLinksIntegrationTest.java +++ b/carina-dataprovider/src/test/java/com/qaprosoft/carina/core/foundation/parser/CellLinksIntegrationTest.java @@ -19,12 +19,12 @@ import java.util.List; import java.util.Map; +import com.qaprosoft.carina.core.foundation.dataprovider.parser.xls.XLSParser; import org.testng.Assert; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; -import com.qaprosoft.carina.core.foundation.dataprovider.parser.XLSParser; -import com.qaprosoft.carina.core.foundation.dataprovider.parser.XLSTable; +import com.qaprosoft.carina.core.foundation.dataprovider.parser.xls.XLSTable; public class CellLinksIntegrationTest { private List headers; diff --git a/carina-reporting/src/main/resources/config.properties b/carina-reporting/src/main/resources/config.properties index f5570a025b..70c96140d3 100644 --- a/carina-reporting/src/main/resources/config.properties +++ b/carina-reporting/src/main/resources/config.properties @@ -3,7 +3,7 @@ max_log_file_size=150 max_screen_history=NULL suite_name=NULL -test_naming_pattern={tuid} - {test_name} - {method_name} +test_naming_pattern={tuid}{test_name} - {method_name} report_url=NULL custom_artifacts_folder=NULL project_report_directory=NULL From cfff7c2753dc93b92fb8764ed77a667291ebeaec Mon Sep 17 00:00:00 2001 From: Dima Grinevich Date: Tue, 14 Mar 2023 12:20:36 +0300 Subject: [PATCH 13/52] fix(TestNamingService.java): getTestNameMap() refactor fix --- .../zebrunner/carina/core/testng/TestNamingService.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/carina-core/src/main/java/com/zebrunner/carina/core/testng/TestNamingService.java b/carina-core/src/main/java/com/zebrunner/carina/core/testng/TestNamingService.java index 6246e3fc39..6c6a988cd2 100644 --- a/carina-core/src/main/java/com/zebrunner/carina/core/testng/TestNamingService.java +++ b/carina-core/src/main/java/com/zebrunner/carina/core/testng/TestNamingService.java @@ -95,7 +95,7 @@ private static String setTestName(ITestResult result) { ITestNGMethod method = result.getMethod(); name = Configuration.get(Configuration.Parameter.TEST_NAMING_PATTERN); - name = name.replace(SpecialKeywords.TEST_NAME, getTestNameMapName(result)) + name = name.replace(SpecialKeywords.TEST_NAME, getTestNameMap(result)) .replace(SpecialKeywords.TEST_NAME_TUID, getMethodUID(result)) .replace(SpecialKeywords.METHOD_NAME, method.getMethodName()) .replace(SpecialKeywords.METHOD_PRIORITY, String.valueOf(method.getPriority())) @@ -116,7 +116,7 @@ private static String setTestName(ITestResult result) { return testName.get(); } - private static String getTestNameMapName(ITestResult result) { + private static String getTestNameMap(ITestResult result) { String testNameMapName = StringUtils.EMPTY; @SuppressWarnings("unchecked") Map testNameMap = (Map) result.getTestContext().getAttribute(SpecialKeywords.TEST_NAME); @@ -125,9 +125,9 @@ private static String getTestNameMapName(ITestResult result) { String testHash = BaseDataProvider.hash(result.getParameters(), result.getMethod()); if (testNameMap.containsKey(testHash)) { testNameMapName = testNameMap.get(testHash); - } else { - testNameMapName = result.getTestContext().getCurrentXmlTest().getName(); } + } else { + testNameMapName = result.getTestContext().getCurrentXmlTest().getName(); } return testNameMapName; } From e83c958c85837e8af24989675cf9e9bedc46e28a Mon Sep 17 00:00:00 2001 From: Dima Grinevich Date: Tue, 14 Mar 2023 12:37:02 +0300 Subject: [PATCH 14/52] fix(TestNamingService.java): getTestNameMap() refactor fix --- .../com/zebrunner/carina/core/testng/TestNamingService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/carina-core/src/main/java/com/zebrunner/carina/core/testng/TestNamingService.java b/carina-core/src/main/java/com/zebrunner/carina/core/testng/TestNamingService.java index 6c6a988cd2..a4c9b57133 100644 --- a/carina-core/src/main/java/com/zebrunner/carina/core/testng/TestNamingService.java +++ b/carina-core/src/main/java/com/zebrunner/carina/core/testng/TestNamingService.java @@ -121,7 +121,7 @@ private static String getTestNameMap(ITestResult result) { @SuppressWarnings("unchecked") Map testNameMap = (Map) result.getTestContext().getAttribute(SpecialKeywords.TEST_NAME); - if (testNameMap != null) { + if (testNameMap != null && !testNameMap.isEmpty()) { String testHash = BaseDataProvider.hash(result.getParameters(), result.getMethod()); if (testNameMap.containsKey(testHash)) { testNameMapName = testNameMap.get(testHash); From 62da3c4c8093d65a148f98e8c9a67e3da0586cfb Mon Sep 17 00:00:00 2001 From: Dima Grinevich Date: Tue, 14 Mar 2023 14:17:57 +0300 Subject: [PATCH 15/52] refactor(dataprovider): refactored comments according to javadoc --- .../listeners/AbstractTestListener.java | 2 +- .../annotations/CsvDataSourceParameters.java | 12 ++++++++- .../annotations/XlsDataSourceParameters.java | 25 +++++++++++++++++-- .../core/impl/BaseDataProvider.java | 6 ++--- .../core/impl/CsvDataProvider.java | 5 ---- .../dataprovider/parser/csv/CSVTable.java | 1 - 6 files changed, 38 insertions(+), 13 deletions(-) diff --git a/carina-core/src/main/java/com/qaprosoft/carina/core/foundation/listeners/AbstractTestListener.java b/carina-core/src/main/java/com/qaprosoft/carina/core/foundation/listeners/AbstractTestListener.java index 572f328fb8..328998d194 100644 --- a/carina-core/src/main/java/com/qaprosoft/carina/core/foundation/listeners/AbstractTestListener.java +++ b/carina-core/src/main/java/com/qaprosoft/carina/core/foundation/listeners/AbstractTestListener.java @@ -157,7 +157,7 @@ public void onTestStart(ITestResult result) { if (!result.getTestContext().getCurrentXmlTest().getAllParameters() .containsKey(SpecialKeywords.EXCEL_DS_CUSTOM_PROVIDER) && result.getParameters().length > 0) // set parameters from XLS only if test contains any parameter at - // all) + // all) { if (result.getTestContext().getCurrentXmlTest().getAllParameters() .containsKey(SpecialKeywords.EXCEL_DS_ARGS)) { diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/CsvDataSourceParameters.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/CsvDataSourceParameters.java index 78190e940d..f087f5bf2a 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/CsvDataSourceParameters.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/CsvDataSourceParameters.java @@ -75,7 +75,7 @@ /** * Defines to execute test or not. - * If executeValue equalsIgnoreCase to value from executeColumn -> add test row to run. + * If executeValue equalsIgnoreCase to value from executeColumn test will be added to run. * * @return String */ @@ -100,30 +100,40 @@ /** * Reason: not implemented + * + * @return String */ @Deprecated(forRemoval = true, since = "1.0.0") String testRailColumn() default ""; /** * Reason: not implemented + * + * @return String */ @Deprecated(forRemoval = true, since = "1.0.0") String qTestColumn() default ""; /** * Reason: not implemented + * + * @return String */ @Deprecated(forRemoval = true, since = "1.0.0") String testMethodOwnerColumn() default ""; /** * Reason: not implemented + * + * @return String */ @Deprecated(forRemoval = true, since = "1.0.0") String bugColumn() default ""; /** * Reason: not implemented + * + * @return String[] */ @Deprecated(forRemoval = true, since = "1.0.0") String[] doNotRunTestNames() default {}; diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/XlsDataSourceParameters.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/XlsDataSourceParameters.java index 09a7c79a00..208caa5733 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/XlsDataSourceParameters.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/XlsDataSourceParameters.java @@ -30,12 +30,23 @@ */ String className() default "com.qaprosoft.carina.core.foundation.dataprovider.core.impl.XlsDataProvider"; + /** + * Is mutually exclusive with path + * + * @return String + */ String spreadsheetId() default ""; + /** + * Define data provider instance + * + * @return String + */ String sheet() default ""; /** - * Path to data source file + * Path to data source file. + * Is mutually exclusive with spreadsheetId * * @return String */ @@ -65,7 +76,7 @@ /** * Defines to execute test or not. - * If executeValue equalsIgnoreCase to value from executeColumn -> add test row to run. + * If executeValue equalsIgnoreCase to value from executeColumn test will be added to run. * * @return String */ @@ -90,30 +101,40 @@ /** * Reason: not implemented + * + * @return String */ @Deprecated(forRemoval = true, since = "1.0.0") String testRailColumn() default ""; /** * Reason: not implemented + * + * @return String */ @Deprecated(forRemoval = true, since = "1.0.0") String qTestColumn() default ""; /** * Reason: not implemented + * + * @return String */ @Deprecated(forRemoval = true, since = "1.0.0") String testMethodOwnerColumn() default ""; /** * Reason: not implemented + * + * @return String */ @Deprecated(forRemoval = true, since = "1.0.0") String bugColumn() default ""; /** * Reason: not implemented + * + * @return String */ @Deprecated(forRemoval = true, since = "1.0.0") String[] doNotRunTestNames() default {}; diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java index 3b30e93251..4e7d33fd72 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java @@ -58,7 +58,7 @@ public static String hash(Object[] args, ITestNGMethod method) { /** * Get value from data source in specified row. * - * @param dataRow Map test method arguments/ record from source table + * @param dataRow @literal{Map} test method arguments/ record from source table * @param key String argument name/ column name from source table * @return String "value " from record */ @@ -69,8 +69,8 @@ protected String getValueFromRow(Map dataRow, String key) { /** * Get value from data source in specified row from several columns. * - * @param dataRow Map test method arguments/ record from source table - * @param keys List argument names/ column names from source table + * @param dataRow @literal{Map} test method arguments/ record from source table + * @param keys @literal{List} argument names/ column names from source table * @return String "value1, value2, ..., valueN " from record */ protected String getValueFromRow(Map dataRow, List keys) { diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java index 1245b919f9..f0d80acde9 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java @@ -15,23 +15,18 @@ *******************************************************************************/ package com.qaprosoft.carina.core.foundation.dataprovider.core.impl; -import au.com.bytecode.opencsv.CSVReader; import com.qaprosoft.carina.core.foundation.dataprovider.annotations.CsvDataSourceParameters; import com.qaprosoft.carina.core.foundation.dataprovider.core.groupping.GroupByMapper; import com.qaprosoft.carina.core.foundation.dataprovider.parser.DSBean; import com.qaprosoft.carina.core.foundation.dataprovider.parser.csv.CSVParser; import com.qaprosoft.carina.core.foundation.dataprovider.parser.csv.CSVTable; -import com.zebrunner.carina.utils.ParameterGenerator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testng.ITestContext; import org.testng.ITestNGMethod; -import java.io.FileReader; -import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.invoke.MethodHandles; -import java.util.*; /** * Created by Patotsky on 16.12.2014. diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/csv/CSVTable.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/csv/CSVTable.java index 57f622dedf..82d9134285 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/csv/CSVTable.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/csv/CSVTable.java @@ -1,7 +1,6 @@ package com.qaprosoft.carina.core.foundation.dataprovider.parser.csv; import com.qaprosoft.carina.core.foundation.dataprovider.parser.AbstractTable; -import com.qaprosoft.carina.core.foundation.dataprovider.parser.DSBean; import org.slf4j.Logger; import org.slf4j.LoggerFactory; From 69665118ff542a6cc1c2d02f07f772dfcda03b57 Mon Sep 17 00:00:00 2001 From: Dima Grinevich Date: Tue, 14 Mar 2023 14:41:56 +0300 Subject: [PATCH 16/52] fix(GroupByImpl.java): correct declaration of grouped array for dataProvider --- .../foundation/dataprovider/core/groupping/GroupByImpl.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/groupping/GroupByImpl.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/groupping/GroupByImpl.java index 2960bcd719..d2d0146f38 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/groupping/GroupByImpl.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/groupping/GroupByImpl.java @@ -51,8 +51,7 @@ public static Object[][] getGroupedDataProviderArgs(Object[][] objects, int fiel ordered.add(tempList); } - int arraySize = listOfObjects.get(0).length; - Object[][] finalObject = new Object[ordered.size()][arraySize]; + Object[][] finalObject = new Object[ordered.size()][ordered.get(0).size()]; int i = 0; for (List list : ordered) { From 26c054c46cb168e55d991fc48e7ae17395460cfd Mon Sep 17 00:00:00 2001 From: Dima Grinevich Date: Wed, 15 Mar 2023 16:43:47 +0300 Subject: [PATCH 17/52] refactor(dataprovider): refactored columnGroup parameter work logic --- .../carina/core/testng/TestNamingService.java | 6 +- .../core/DataProviderFactory.java | 33 +--- .../core/groupping/GroupByImpl.java | 144 +++++------------- .../core/groupping/GroupByMapper.java | 55 ------- .../exceptions/GroupByException.java | 1 + .../core/impl/BaseDataProvider.java | 136 +++++++++++------ .../core/impl/CsvDataProvider.java | 19 +-- .../core/impl/XlsDataProvider.java | 18 ++- .../dataprovider/parser/AbstractTable.java | 32 ++++ .../dataprovider/parser/DSBean.java | 16 +- 10 files changed, 191 insertions(+), 269 deletions(-) delete mode 100644 carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/groupping/GroupByMapper.java diff --git a/carina-core/src/main/java/com/zebrunner/carina/core/testng/TestNamingService.java b/carina-core/src/main/java/com/zebrunner/carina/core/testng/TestNamingService.java index a4c9b57133..665faebe17 100644 --- a/carina-core/src/main/java/com/zebrunner/carina/core/testng/TestNamingService.java +++ b/carina-core/src/main/java/com/zebrunner/carina/core/testng/TestNamingService.java @@ -117,17 +117,15 @@ private static String setTestName(ITestResult result) { } private static String getTestNameMap(ITestResult result) { - String testNameMapName = StringUtils.EMPTY; + String testNameMapName = result.getTestContext().getCurrentXmlTest().getName(); + @SuppressWarnings("unchecked") Map testNameMap = (Map) result.getTestContext().getAttribute(SpecialKeywords.TEST_NAME); - if (testNameMap != null && !testNameMap.isEmpty()) { String testHash = BaseDataProvider.hash(result.getParameters(), result.getMethod()); if (testNameMap.containsKey(testHash)) { testNameMapName = testNameMap.get(testHash); } - } else { - testNameMapName = result.getTestContext().getCurrentXmlTest().getName(); } return testNameMapName; } diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java index 1876a29fe2..e4320db4f2 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java @@ -15,9 +15,6 @@ *******************************************************************************/ package com.qaprosoft.carina.core.foundation.dataprovider.core; -import com.qaprosoft.carina.core.foundation.dataprovider.core.groupping.GroupByImpl; -import com.qaprosoft.carina.core.foundation.dataprovider.core.groupping.GroupByMapper; -import com.qaprosoft.carina.core.foundation.dataprovider.core.groupping.exceptions.GroupByException; import com.qaprosoft.carina.core.foundation.dataprovider.core.impl.BaseDataProvider; import com.zebrunner.carina.utils.commons.SpecialKeywords; import org.apache.commons.lang3.ArrayUtils; @@ -77,15 +74,8 @@ public static Object[][] getDataProvider(Annotation[] annotations, ITestContext } } - if (!GroupByMapper.getInstanceInt().isEmpty() || !GroupByMapper.getInstanceStrings().isEmpty()) { - provider = getGroupedList(provider); - } putValuesToContext(context, tuidMap, testNameMap); - // clear group by settings - GroupByMapper.getInstanceInt().clear(); - GroupByMapper.getInstanceStrings().clear(); - return provider; } @@ -96,7 +86,7 @@ public static Object[][] getDataProvider(Annotation[] annotations, ITestContext * @param tuidMap Map contains tuid values for each test (if present) * @param testNameFromColumn Map contains values for overriding test names from specified column */ - private static void putValuesToContext(ITestContext context, + private static synchronized void putValuesToContext(ITestContext context, Map tuidMap, Map testNameFromColumn) { @SuppressWarnings("unchecked") @@ -159,25 +149,4 @@ private static Object initDataProvider(String providerClass) { return dataProvider; } - - private static Object[][] getGroupedList(Object[][] provider) { - Object[][] finalProvider; - if (GroupByMapper.isHashMapped()) { - if (GroupByMapper.getInstanceStrings().size() == 1) { - finalProvider = GroupByImpl.getGroupedDataProviderMap(provider, GroupByMapper.getInstanceStrings().iterator().next()); - } else { - throw new GroupByException("Incorrect groupColumn annotation parameter!"); - } - } else { - if (GroupByMapper.getInstanceInt().size() == 1 && !GroupByMapper.getInstanceInt().contains(-1)) { - - finalProvider = GroupByImpl.getGroupedDataProviderArgs(provider, GroupByMapper.getInstanceInt().iterator().next()); - } else { - throw new GroupByException("Incorrect groupColumn annotation parameter!"); - } - } - - return finalProvider; - } - } diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/groupping/GroupByImpl.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/groupping/GroupByImpl.java index d2d0146f38..8ee6b2fde0 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/groupping/GroupByImpl.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/groupping/GroupByImpl.java @@ -21,132 +21,66 @@ * Created by Patotsky on 29.12.2014. */ +@Deprecated(forRemoval = true, since = "1.0.0") public class GroupByImpl { public static Object[][] getGroupedDataProviderArgs(Object[][] objects, int fieldNumber) { + //add unique group values + Set groupValues = new LinkedHashSet<>(); + for (Object[] item : objects) { + String value = (String) item[fieldNumber]; + groupValues.add(value); + } - List listOfObjects = sortDefaultObject(objects, fieldNumber); - @SuppressWarnings("rawtypes") - Iterator iterator = listOfObjects.iterator(); - Object[] temp = (Object[]) iterator.next(); - List> ordered = new ArrayList>(); - List tempList = new ArrayList(); - tempList.add(temp); - while (iterator.hasNext()) { - Object[] current = (Object[]) iterator.next(); - if (temp[fieldNumber].equals(current[fieldNumber])) { - tempList.add(current); - } else { - temp = current; - ordered.add(tempList); - tempList = new ArrayList(); - tempList.add(temp); - if (!iterator.hasNext()) { - ordered.add(tempList); + //group maps into lists, that has the same unique group value + List> groupedList = new ArrayList<>(); + for (String groupBy: groupValues) { + List groupOfRows = new ArrayList<>(); + for (Object[] object : objects) { + String value = (String) object[fieldNumber]; + if (value.equals(groupBy)) { + groupOfRows.add(object); } } + groupedList.add(groupOfRows); } - if (tempList.size() > 0) { - // add last grouped rows - ordered.add(tempList); - } - - Object[][] finalObject = new Object[ordered.size()][ordered.get(0).size()]; - int i = 0; - for (List list : ordered) { - finalObject[i][0] = list; - i++; + //cast List> to Object[][] + Object[][] finalObject = new Object[groupedList.size()][1]; + for (int i = 0; i < groupedList.size(); i++) { + finalObject[i][0] = groupedList.get(i); } return finalObject; - } - @SuppressWarnings("rawtypes") public static Object[][] getGroupedDataProviderMap(Object[][] objects, String fieldName) { - - List listOfObjects = sortMapObject(objects, fieldName); - Iterator iterator = listOfObjects.iterator(); - Object[] temp = (Object[]) iterator.next(); - List> ordered = new ArrayList>(); - List tempList = new ArrayList(); - tempList.add(temp); - while (iterator.hasNext()) { - Object[] current = (Object[]) iterator.next(); - if (((HashMap) (temp[0])).get(fieldName).equals(((HashMap) (current[0])).get(fieldName))) { - tempList.add(current); - } else { - temp = current; - ordered.add(tempList); - tempList = new ArrayList(); - tempList.add(temp); - if (!iterator.hasNext()) { - ordered.add(tempList); - } - } - } - - if (tempList.size() > 0) { - // add last grouped rows - ordered.add(tempList); + //add unique group values + Set groupValues = new LinkedHashSet<>(); + for (Object[] item : objects) { + String value = ((Map) item[0]).get(fieldName); + groupValues.add(value); } - int arraySize = listOfObjects.get(0).length; - - Object[][] finalObject = new Object[ordered.size()][arraySize]; - int i = 0; - for (List list : ordered) { - finalObject[i][0] = getHashMaps(list); - - if (arraySize > 1) { - for (int j = 1; j < arraySize; j++) { - finalObject[i][j] = list.get(0)[j]; - j++; + //group maps into lists, that has the same unique group value + List>> groupedList = new ArrayList<>(); + for (String groupBy: groupValues) { + List> groupOfRows = new ArrayList<>(); + for (Object[] item : objects) { + String value = ((Map) item[0]).get(fieldName); + if (value.equals(groupBy)) { + groupOfRows.add((Map) item[0]); } - } - i++; + groupedList.add(groupOfRows); } - return finalObject; - - } - - @SuppressWarnings("rawtypes") - private static List getHashMaps(List list) { - List hashMaps = new ArrayList(); - for (Object[] objects : list) { - hashMaps.add((HashMap) objects[0]); + //cast List> to Object[][] + Object[][] finalObject = new Object[groupedList.size()][1]; + for (int i = 0; i < groupedList.size(); i++) { + finalObject[i][0] = groupedList.get(i); } - return hashMaps; - } - private static List sortDefaultObject(Object[][] objects, final int fieldNumber) { - List listOfObjects = Arrays.asList(objects); - Collections.sort(listOfObjects, new Comparator() { - @Override - public int compare(final Object[] object1, final Object[] object2) { - String firstField = (String) object1[fieldNumber]; - String secondField = (String) object2[fieldNumber]; - return firstField.compareTo(secondField); - } - }); - return listOfObjects; - } - - private static List sortMapObject(Object[][] objects, final String keyName) { - List listOfObjects = Arrays.asList(objects); - Collections.sort(listOfObjects, new Comparator() { - @SuppressWarnings("unchecked") - @Override - public int compare(final Object[] object1, final Object[] object2) { - String firstField = ((HashMap) object1[0]).get(keyName); - String secondField = ((HashMap) object2[0]).get(keyName); - return firstField.compareTo(secondField); - } - }); - return listOfObjects; + return finalObject; } - } diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/groupping/GroupByMapper.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/groupping/GroupByMapper.java deleted file mode 100644 index d500d2a660..0000000000 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/groupping/GroupByMapper.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * Copyright 2020-2022 Zebrunner Inc (https://www.zebrunner.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *******************************************************************************/ -package com.qaprosoft.carina.core.foundation.dataprovider.core.groupping; - -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -/** - * Created by Yauheni_Patotski on 1/7/2015. - */ -public class GroupByMapper { - private static Set instanceInt; - - private static Set instanceString; - - private static boolean hashMapped = false; - - public static boolean isHashMapped() { - return hashMapped; - } - - public static void setIsHashMapped(boolean isHashMapped) { - GroupByMapper.hashMapped = isHashMapped; - } - - private GroupByMapper() {} - - public static Set getInstanceInt() { - if (instanceInt == null) { - instanceInt = Collections.synchronizedSet(new HashSet()); - } - return instanceInt; - } - - public static Set getInstanceStrings() { - if (instanceString == null) { - instanceString = Collections.synchronizedSet(new HashSet()); - } - return instanceString; - } -} \ No newline at end of file diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/groupping/exceptions/GroupByException.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/groupping/exceptions/GroupByException.java index 297b6d8431..f923d31cab 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/groupping/exceptions/GroupByException.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/groupping/exceptions/GroupByException.java @@ -19,6 +19,7 @@ * Created by Patotsky on 08.01.2015. */ +@Deprecated(forRemoval = true, since = "1.0.0") @SuppressWarnings("serial") public class GroupByException extends RuntimeException { diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java index 4e7d33fd72..955a5653f9 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java @@ -15,6 +15,7 @@ *******************************************************************************/ package com.qaprosoft.carina.core.foundation.dataprovider.core.impl; +import com.qaprosoft.carina.core.foundation.dataprovider.core.groupping.GroupByImpl; import com.qaprosoft.carina.core.foundation.dataprovider.parser.AbstractTable; import com.qaprosoft.carina.core.foundation.dataprovider.parser.DSBean; import com.zebrunner.carina.utils.ParameterGenerator; @@ -55,50 +56,24 @@ public static String hash(Object[] args, ITestNGMethod method) { return String.valueOf(toHash.hashCode()); } - /** - * Get value from data source in specified row. - * - * @param dataRow @literal{Map} test method arguments/ record from source table - * @param key String argument name/ column name from source table - * @return String "value " from record - */ - protected String getValueFromRow(Map dataRow, String key) { - return getValueFromRow(dataRow, List.of(key)); - } - - /** - * Get value from data source in specified row from several columns. - * - * @param dataRow @literal{Map} test method arguments/ record from source table - * @param keys @literal{List} argument names/ column names from source table - * @return String "value1, value2, ..., valueN " from record - */ - protected String getValueFromRow(Map dataRow, List keys) { - StringBuilder valueRes = new StringBuilder(); + public Object[][] createGroupedDataProvider(List>> groupedList, DSBean dsBean, ITestNGMethod testMethod) { + Object[][] dataProvider = declareDataProviderArray(groupedList, dsBean); - for (String key : keys) { - if (!key.isEmpty() && dataRow.containsKey(key)) { - String value = dataRow.get(key); - if (value != null && !value.isEmpty()) { - valueRes.append(value); - valueRes.append(","); - } - } + if (dsBean.getArgs().isEmpty()) { + fillArgsAsMap(dataProvider, groupedList, dsBean); + } else { + fillArgsAsGropedMap(dataProvider, groupedList, dsBean); } - if (valueRes.indexOf(",") != -1) { - valueRes.replace(valueRes.length() - 1, valueRes.length(), ""); - } - return valueRes.toString(); + configureTestNamingVarsForGroupedProvider(dataProvider, dsBean, groupedList, testMethod); + return dataProvider; } - protected Object[][] fillDataProviderWithData(AbstractTable table, DSBean dsBean, ITestNGMethod testMethod) { - processTable(table); + public Object[][] createDataProvider(AbstractTable table, DSBean dsBean, ITestNGMethod testMethod) { + Object[][] dataProvider = declareDataProviderArray(table.getDataRows(), dsBean); - Object[][] dataProvider = declareDataProviderArray(table, dsBean); - - if (dsBean.isArgsToHashMap()) { - fillArgsAsHashMap(dataProvider, table, dsBean); + if (dsBean.isArgsToMap()) { + fillArgsAsMap(dataProvider, table.getDataRows(), dsBean); } else { fillArgsAsArray(dataProvider, table, dsBean); } @@ -108,18 +83,30 @@ protected Object[][] fillDataProviderWithData(AbstractTable table, DSBean dsBean return dataProvider; } - private void processTable(AbstractTable table) { - for (Map row : table.getDataRows()) { - ParameterGenerator.processMap(row); + private void fillArgsAsGropedMap(Object[][] dataProvider, List>> gropedList, DSBean dsBean) { + List argsToPass = dsBean.getArgs(); + for (int rowIndex = 0; rowIndex < gropedList.size(); rowIndex++) { + List> listToPass = new ArrayList<>(); + for (Map groupedMap : gropedList.get(rowIndex)) { + Map mapToPass = new HashMap<>(); + for (String argName : argsToPass) { + mapToPass.put(argName, groupedMap.get(argName)); + } + listToPass.add(mapToPass); + } + dataProvider[rowIndex][0] = listToPass; + + for (int staticArgsColumn = 0; staticArgsColumn < dsBean.getStaticArgs().size(); staticArgsColumn++) { + String staticArgName = dsBean.getStaticArgs().get(staticArgsColumn); + dataProvider[rowIndex][staticArgsColumn + 1] = getStaticParam(staticArgName, dsBean); + } } } - private void fillArgsAsHashMap(Object[][] dataProvider, AbstractTable table, DSBean dsBean) { + private void fillArgsAsMap(Object[][] dataProvider, List dataRows, DSBean dsBean) { for (int rowIndex = 0; rowIndex < dataProvider.length; rowIndex++) { - Map row = table.getDataRows().get(rowIndex); - // populate arguments by parameters from data source - dataProvider[rowIndex][0] = row; + dataProvider[rowIndex][0] = dataRows.get(rowIndex); // populate the rest of arguments by static parameters from testParams for (int staticArgsColumn = 0; staticArgsColumn < dsBean.getStaticArgs().size(); staticArgsColumn++) { @@ -146,11 +133,11 @@ private void fillArgsAsArray(Object[][] dataProvider, AbstractTable table, DSBea } } - private Object[][] declareDataProviderArray(AbstractTable table, DSBean dsBean) { - int numberOfRowsToExecute = table.getDataRows().size(); + private Object[][] declareDataProviderArray(List dataRows, DSBean dsBean) { + int numberOfRowsToExecute = dataRows.size(); int numberOfArgsInTest; - if (dsBean.isArgsToHashMap()) { + if (dsBean.isArgsToMap()) { // first element is dynamic HashMap numberOfArgsInTest = 1 + dsBean.getStaticArgs().size(); } else { @@ -166,10 +153,60 @@ private void configureTestNamingVars(Object[][] dataProvider, DSBean dsBean, Abs String rowHash = hash(dataProvider[rowIndex], testNGMethod); addValueToMap(tuidMap, rowHash, getValueFromRow(row, dsBean.getUidArgs())); - addValueToMap(testColumnNamesMap, rowHash, getValueFromRow(row, dsBean.getTestMethodColumn())); + addValueToMap(testColumnNamesMap, rowHash, getValueFromRow(row, List.of(dsBean.getTestMethodColumn()))); } } + private void configureTestNamingVarsForGroupedProvider(Object[][] dataProvider, + DSBean dsBean, + List>> groupedList, + ITestNGMethod testNGMethod) { + for (int rowIndex = 0; rowIndex < dataProvider.length; rowIndex++) { + + String rowHash = hash(dataProvider[rowIndex], testNGMethod); + + String testUid = getValueFromGroupList(rowIndex, groupedList, dsBean.getUidArgs()); + addValueToMap(tuidMap, rowHash, testUid); + + String testName = getValueFromGroupList(rowIndex, groupedList, List.of(dsBean.getTestMethodColumn())); + addValueToMap(testColumnNamesMap, rowHash, testName.split(",")[0]); + } + } + + private String getValueFromGroupList(int rowIndex, List>> groupedList, List columnNames) { + Set values = new LinkedHashSet<>(); + List> dataRowList = groupedList.get(rowIndex); + + for (Map dataMap : dataRowList) { + values.add(getValueFromRow(dataMap, columnNames)); + } + + StringBuilder valueRes = new StringBuilder(String.join(",", values)); + if (valueRes.indexOf(",") != -1) { + valueRes.replace(valueRes.length() - 1, valueRes.length(), ""); + } + return valueRes.toString(); + } + + public String getValueFromRow(Map row, List columnNames) { + StringBuilder valueRes = new StringBuilder(); + + for (String key : columnNames) { + if (!key.isEmpty() && row.containsKey(key)) { + String value = row.get(key); + if (value != null && !value.isEmpty()) { + valueRes.append(value); + valueRes.append(","); + } + } + } + + if (valueRes.indexOf(",") != -1) { + valueRes.replace(valueRes.length() - 1, valueRes.length(), ""); + } + return valueRes.toString(); + } + protected static Object getStaticParam(String name, DSBean dsBean) { return ParameterGenerator.process(dsBean.getTestParams().get(name)); } @@ -181,5 +218,4 @@ public Map getTestColumnNamesMap() { public Map getTuidMap() { return tuidMap; } - } diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java index f0d80acde9..216d4a209b 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java @@ -16,7 +16,6 @@ package com.qaprosoft.carina.core.foundation.dataprovider.core.impl; import com.qaprosoft.carina.core.foundation.dataprovider.annotations.CsvDataSourceParameters; -import com.qaprosoft.carina.core.foundation.dataprovider.core.groupping.GroupByMapper; import com.qaprosoft.carina.core.foundation.dataprovider.parser.DSBean; import com.qaprosoft.carina.core.foundation.dataprovider.parser.csv.CSVParser; import com.qaprosoft.carina.core.foundation.dataprovider.parser.csv.CSVTable; @@ -27,6 +26,8 @@ import java.lang.annotation.Annotation; import java.lang.invoke.MethodHandles; +import java.util.List; +import java.util.Map; /** * Created by Patotsky on 16.12.2014. @@ -40,7 +41,6 @@ public class CsvDataProvider extends BaseDataProvider { * @param annotation Annotation csv data source parameters * @param context ITestContext * @param testMethod ITestNGMethod - * * @return Object[][] dataProvider */ @SuppressWarnings("unchecked") @@ -51,14 +51,15 @@ public Object[][] getDataProvider(Annotation annotation, ITestContext context, I CSVTable csvTable = CSVParser.parseCsvFile(dsBean, parameters.separator(), parameters.quote()); csvTable.excludeEntriesForNonExecution(); + csvTable.processTable(); - String groupByParameter = dsBean.getGroupColumn(); - if (!groupByParameter.isEmpty()) { - GroupByMapper.getInstanceInt().add(dsBean.getArgs().indexOf(groupByParameter)); - GroupByMapper.getInstanceStrings().add(groupByParameter); + String groupColumn = dsBean.getGroupColumn(); + if (groupColumn.isEmpty()) { + return createDataProvider(csvTable, dsBean, testMethod); + } else { + List>> groupedList = csvTable.getGroupedDataProviderMap(groupColumn); + dsBean.setArgsToMap(true); + return createGroupedDataProvider(groupedList, dsBean, testMethod); } - GroupByMapper.setIsHashMapped(dsBean.isArgsToHashMap()); - - return fillDataProviderWithData(csvTable, dsBean, testMethod); } } diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java index 92d88ffa7b..233dba9464 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java @@ -16,7 +16,6 @@ package com.qaprosoft.carina.core.foundation.dataprovider.core.impl; import com.qaprosoft.carina.core.foundation.dataprovider.annotations.XlsDataSourceParameters; -import com.qaprosoft.carina.core.foundation.dataprovider.core.groupping.GroupByMapper; import com.qaprosoft.carina.core.foundation.dataprovider.parser.DSBean; import com.qaprosoft.carina.core.foundation.dataprovider.parser.xls.XLSParser; import com.qaprosoft.carina.core.foundation.dataprovider.parser.xls.XLSTable; @@ -24,6 +23,8 @@ import org.testng.ITestNGMethod; import java.lang.annotation.Annotation; +import java.util.List; +import java.util.Map; /** * Created by Patotsky on 16.12.2014. @@ -45,14 +46,15 @@ public Object[][] getDataProvider(Annotation annotation, ITestContext context, I DSBean dsBean = new DSBean(parameters, context.getCurrentXmlTest().getAllParameters()); XLSTable xlsTable = XLSParser.parseSpreadSheet(dsBean.getDsFile(), dsBean.getXlsSheet(), dsBean.getExecuteColumn(), dsBean.getExecuteValue()); + xlsTable.processTable(); - String groupByParameter = dsBean.getGroupColumn(); - if (!groupByParameter.isEmpty()) { - GroupByMapper.getInstanceInt().add(dsBean.getArgs().indexOf(groupByParameter)); - GroupByMapper.getInstanceStrings().add(groupByParameter); + String groupColumn = dsBean.getGroupColumn(); + if (groupColumn.isEmpty()) { + return createDataProvider(xlsTable, dsBean, testMethod); + } else { + List>> groupedList = xlsTable.getGroupedDataProviderMap(groupColumn); + dsBean.setArgsToMap(true); + return createGroupedDataProvider(groupedList, dsBean, testMethod); } - GroupByMapper.setIsHashMapped(dsBean.isArgsToHashMap()); - - return fillDataProviderWithData(xlsTable, dsBean, testMethod); } } diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/AbstractTable.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/AbstractTable.java index 42ae18e025..c6171daeda 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/AbstractTable.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/AbstractTable.java @@ -1,5 +1,7 @@ package com.qaprosoft.carina.core.foundation.dataprovider.parser; +import com.zebrunner.carina.utils.ParameterGenerator; + import java.util.*; public abstract class AbstractTable { @@ -49,4 +51,34 @@ public void setHeaders(Collection row) { } public abstract void addDataRow(List row); + + public void processTable() { + for (Map row : dataRows) { + ParameterGenerator.processMap(row); + } + } + + public List>> getGroupedDataProviderMap(String fieldName) { + //add unique group values + Set groupValues = new LinkedHashSet<>(); + for (Map item : dataRows) { + String value = item.get(fieldName); + groupValues.add(value); + } + + //group maps into lists, that has the same unique group value + List>> groupedList = new ArrayList<>(); + for (String groupBy: groupValues) { + List> groupOfRows = new ArrayList<>(); + for (Map item : dataRows) { + String value = item.get(fieldName); + if (value.equals(groupBy)) { + groupOfRows.add(item); + } + } + groupedList.add(groupOfRows); + } + + return groupedList; + } } diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/DSBean.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/DSBean.java index 8370cfa0bc..6b022edf97 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/DSBean.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/DSBean.java @@ -39,9 +39,11 @@ public class DSBean { private boolean spreadsheet; private String groupColumn; private String testMethodColumn; + private boolean argsToMap; public DSBean(ITestContext context) { initParamsFromSuite(context.getCurrentXmlTest().getAllParameters(), "excel"); + this.argsToMap = this.args.size() == 0; } public DSBean(XlsDataSourceParameters xlsDataSourceParameters, Map suiteParams) { @@ -70,6 +72,7 @@ public DSBean(XlsDataSourceParameters xlsDataSourceParameters, Map suiteParams) { @@ -83,6 +86,7 @@ public DSBean(CsvDataSourceParameters csvDataSourceParameters, Map Date: Wed, 15 Mar 2023 18:35:05 +0300 Subject: [PATCH 18/52] refactor(dataprovider): added comments to code --- .../annotations/CsvDataSourceParameters.java | 8 ++++ .../annotations/XlsDataSourceParameters.java | 8 ++++ .../core/DataProviderFactory.java | 21 +++++----- .../core/impl/BaseDataProvider.java | 38 +++++++++++++++---- .../core/impl/CsvDataProvider.java | 8 ++-- .../core/impl/XlsDataProvider.java | 9 ++--- .../dataprovider/parser/DSBean.java | 7 +++- 7 files changed, 69 insertions(+), 30 deletions(-) diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/CsvDataSourceParameters.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/CsvDataSourceParameters.java index f087f5bf2a..f7db783629 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/CsvDataSourceParameters.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/CsvDataSourceParameters.java @@ -89,10 +89,18 @@ */ String staticArgs() default ""; + /** + * Name of the column, by which will be performed grouping. + * If used, test will receive @literal{ArrayList} argument, + * where data grouped by lists depending on groupColumn values. + * + * @return String + */ String groupColumn() default ""; /** * Column name, which contains values for test name overriding + * If used with groupColumn parameter, test will be overridden by first occurrence in group * * @return String */ diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/XlsDataSourceParameters.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/XlsDataSourceParameters.java index 208caa5733..7e3143bc5e 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/XlsDataSourceParameters.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/XlsDataSourceParameters.java @@ -90,10 +90,18 @@ */ String staticArgs() default ""; + /** + * Name of the column, by which will be performed grouping. + * If used, test will receive @literal{ArrayList} argument, + * where data grouped by lists depending on groupColumn values. + * + * @return String + */ String groupColumn() default ""; /** * Column name, which contains values for test name overriding + * If used with groupColumn parameter, test will be overridden by first occurrence in group * * @return String */ diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java index e4320db4f2..58670c1034 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java @@ -43,13 +43,12 @@ private DataProviderFactory() {} * Creates data provider from specified source in annotations. * * @param annotations test method annotations. For using carina's custom data provider - * test should be annotated with @CsvDataSourceParameters or @XlsDataSourceParameters - * - * @param context test context - * @param m current test method + * test should be annotated with @CsvDataSourceParameters or @XlsDataSourceParameters + * @param context test context + * @param m current test method * @return Object[][] provider from specified source, - * where provider.length shows number of test to be invoked - * and provider[i][] contains test invocation args for each i test + * where provider.length shows number of test to be invoked + * and provider[i][] contains test invocation args for each i test */ public static Object[][] getDataProvider(Annotation[] annotations, ITestContext context, ITestNGMethod m) { Map tuidMap = Collections.synchronizedMap(new HashMap<>()); @@ -82,13 +81,13 @@ public static Object[][] getDataProvider(Annotation[] annotations, ITestContext /** * Put data from test parameters to test's context. Necessary for correct test naming. * - * @param context ITestContext. - * @param tuidMap Map contains tuid values for each test (if present) - * @param testNameFromColumn Map contains values for overriding test names from specified column + * @param context ITestContext. + * @param tuidMap @literal{Map} contains tuid values for each test (if present) + * @param testNameFromColumn @literal{Map} contains values for overriding test names from specified column */ private static synchronized void putValuesToContext(ITestContext context, - Map tuidMap, - Map testNameFromColumn) { + Map tuidMap, + Map testNameFromColumn) { @SuppressWarnings("unchecked") Map contextTUID = (Map) context.getAttribute(SpecialKeywords.TUID); if (contextTUID != null) { diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java index 955a5653f9..5abe9e6ab4 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java @@ -15,7 +15,6 @@ *******************************************************************************/ package com.qaprosoft.carina.core.foundation.dataprovider.core.impl; -import com.qaprosoft.carina.core.foundation.dataprovider.core.groupping.GroupByImpl; import com.qaprosoft.carina.core.foundation.dataprovider.parser.AbstractTable; import com.qaprosoft.carina.core.foundation.dataprovider.parser.DSBean; import com.zebrunner.carina.utils.ParameterGenerator; @@ -42,7 +41,7 @@ protected void addValueToMap(Map map, String hashCode, String va } /** - * Generates hash by class name, method name and arg values. + * Generate hash by class name, method name and arg values. * * @param args Object[] test method arguments * @param method ITestNGMethod @@ -56,19 +55,35 @@ public static String hash(Object[] args, ITestNGMethod method) { return String.valueOf(toHash.hashCode()); } + /** + * Generate dataProvider based on grouped data rows + * + * @param groupedList @literal{List>>} grouped data rows + * @param dsBean DSBean test parameters bean + * @param testMethod ITestNGMethod current test method + * @return Object[][] grouped data provider, where object[i][0] contains @literal{ArrayList>} + */ public Object[][] createGroupedDataProvider(List>> groupedList, DSBean dsBean, ITestNGMethod testMethod) { Object[][] dataProvider = declareDataProviderArray(groupedList, dsBean); if (dsBean.getArgs().isEmpty()) { fillArgsAsMap(dataProvider, groupedList, dsBean); } else { - fillArgsAsGropedMap(dataProvider, groupedList, dsBean); + fillArgsAsGroupedMap(dataProvider, groupedList, dsBean); } configureTestNamingVarsForGroupedProvider(dataProvider, dsBean, groupedList, testMethod); return dataProvider; } + /** + * Generate dataProvider based on data source rows + * + * @param table AbstractTable contains parsed from data source data rows + * @param dsBean DSBean test parameters bean + * @param testMethod ITestNGMethod current test method + * @return Object[][] grouped data provider + */ public Object[][] createDataProvider(AbstractTable table, DSBean dsBean, ITestNGMethod testMethod) { Object[][] dataProvider = declareDataProviderArray(table.getDataRows(), dsBean); @@ -83,17 +98,20 @@ public Object[][] createDataProvider(AbstractTable table, DSBean dsBean, ITestNG return dataProvider; } - private void fillArgsAsGropedMap(Object[][] dataProvider, List>> gropedList, DSBean dsBean) { + private void fillArgsAsGroupedMap(Object[][] dataProvider, List>> groupedList, DSBean dsBean) { + //selecting only specified in test parameters args from whole dataRow into new grouped list List argsToPass = dsBean.getArgs(); - for (int rowIndex = 0; rowIndex < gropedList.size(); rowIndex++) { + for (int rowIndex = 0; rowIndex < groupedList.size(); rowIndex++) { List> listToPass = new ArrayList<>(); - for (Map groupedMap : gropedList.get(rowIndex)) { + for (Map groupedMap : groupedList.get(rowIndex)) { Map mapToPass = new HashMap<>(); for (String argName : argsToPass) { mapToPass.put(argName, groupedMap.get(argName)); } listToPass.add(mapToPass); } + + //creating grouped data provider with specified args dataProvider[rowIndex][0] = listToPass; for (int staticArgsColumn = 0; staticArgsColumn < dsBean.getStaticArgs().size(); staticArgsColumn++) { @@ -165,11 +183,14 @@ private void configureTestNamingVarsForGroupedProvider(Object[][] dataProvider, String rowHash = hash(dataProvider[rowIndex], testNGMethod); + //get all unique tuid values from certain group String testUid = getValueFromGroupList(rowIndex, groupedList, dsBean.getUidArgs()); addValueToMap(tuidMap, rowHash, testUid); + //get only first test name occurrence in group String testName = getValueFromGroupList(rowIndex, groupedList, List.of(dsBean.getTestMethodColumn())); - addValueToMap(testColumnNamesMap, rowHash, testName.split(",")[0]); + testName = testName.split(",")[0]; + addValueToMap(testColumnNamesMap, rowHash, testName); } } @@ -188,7 +209,7 @@ private String getValueFromGroupList(int rowIndex, List return valueRes.toString(); } - public String getValueFromRow(Map row, List columnNames) { + private String getValueFromRow(Map row, List columnNames) { StringBuilder valueRes = new StringBuilder(); for (String key : columnNames) { @@ -208,6 +229,7 @@ public String getValueFromRow(Map row, List columnNames) } protected static Object getStaticParam(String name, DSBean dsBean) { + //get value from suite by name return ParameterGenerator.process(dsBean.getTestParams().get(name)); } diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java index 216d4a209b..7895a2a3cf 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java @@ -36,11 +36,11 @@ public class CsvDataProvider extends BaseDataProvider { private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); /** - * Create data for tests from csv data source by annotation and context parameters + * Create data provider for test based on csv data source, suite and annotation parameters * * @param annotation Annotation csv data source parameters - * @param context ITestContext - * @param testMethod ITestNGMethod + * @param context ITestContext suite data source parameters + * @param testMethod ITestNGMethod current test method * @return Object[][] dataProvider */ @SuppressWarnings("unchecked") @@ -57,7 +57,7 @@ public Object[][] getDataProvider(Annotation annotation, ITestContext context, I if (groupColumn.isEmpty()) { return createDataProvider(csvTable, dsBean, testMethod); } else { - List>> groupedList = csvTable.getGroupedDataProviderMap(groupColumn); + List>> groupedList = csvTable.getGroupedDataProviderMap(groupColumn); dsBean.setArgsToMap(true); return createGroupedDataProvider(groupedList, dsBean, testMethod); } diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java index 233dba9464..07240f450d 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java @@ -32,12 +32,11 @@ public class XlsDataProvider extends BaseDataProvider { /** - * Create data for tests from xls data source by annotation and context parameters + * Create data provider for test based on xls data source, suite and annotation parameters * * @param annotation Annotation xls data source parameters - * @param context ITestContext - * @param testMethod ITestNGMethod - * + * @param context ITestContext suite data source parameters + * @param testMethod ITestNGMethod current test method * @return Object[][] dataProvider */ @Override @@ -52,7 +51,7 @@ public Object[][] getDataProvider(Annotation annotation, ITestContext context, I if (groupColumn.isEmpty()) { return createDataProvider(xlsTable, dsBean, testMethod); } else { - List>> groupedList = xlsTable.getGroupedDataProviderMap(groupColumn); + List>> groupedList = xlsTable.getGroupedDataProviderMap(groupColumn); dsBean.setArgsToMap(true); return createGroupedDataProvider(groupedList, dsBean, testMethod); } diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/DSBean.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/DSBean.java index 6b022edf97..c73c17cb5d 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/DSBean.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/DSBean.java @@ -47,7 +47,7 @@ public DSBean(ITestContext context) { } public DSBean(XlsDataSourceParameters xlsDataSourceParameters, Map suiteParams) { - // params init order: 1) from test annotation 2) from suite + // params initialize order: 1) from test annotation 2) from suite if (xlsDataSourceParameters != null) { this.initParamsFromAnnotation(xlsDataSourceParameters); if (!xlsDataSourceParameters.sheet().isEmpty()) { @@ -76,7 +76,7 @@ public DSBean(XlsDataSourceParameters xlsDataSourceParameters, Map suiteParams) { - // initialize default Xls data source parameters from suite xml file + // params initialize order: 1) from test annotation 2) from suite if (csvDataSourceParameters != null) { this.initParamsFromAnnotation(csvDataSourceParameters); } @@ -90,6 +90,7 @@ public DSBean(CsvDataSourceParameters csvDataSourceParameters, Map suiteParams, String specialKeyPrefix) { + // initialize data source parameters from suite xml file if (suiteParams.get(insert(SpecialKeywords.DS_FILE, specialKeyPrefix)) != null) { this.dsFile = suiteParams.get(insert(SpecialKeywords.DS_FILE, specialKeyPrefix)); } From 22be9ab2cb4c71756cefa8727ae75fe536b6a0c3 Mon Sep 17 00:00:00 2001 From: Dima Grinevich Date: Fri, 17 Mar 2023 16:39:25 +0300 Subject: [PATCH 19/52] refactor(IAbstractTest.java): moved to dataProvider init from IAbstractTest to new file --- .../carina/core/foundation/IAbstractTest.java | 14 ----------- .../dataprovider/core/CustomProvider.java | 24 +++++++++++++++++++ 2 files changed, 24 insertions(+), 14 deletions(-) create mode 100644 carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/CustomProvider.java diff --git a/carina-core/src/main/java/com/qaprosoft/carina/core/foundation/IAbstractTest.java b/carina-core/src/main/java/com/qaprosoft/carina/core/foundation/IAbstractTest.java index fb0d7337f4..14ad198eb8 100644 --- a/carina-core/src/main/java/com/qaprosoft/carina/core/foundation/IAbstractTest.java +++ b/carina-core/src/main/java/com/qaprosoft/carina/core/foundation/IAbstractTest.java @@ -66,20 +66,6 @@ private void onCarinaBeforeMethod() { // do nothing } - @DataProvider(name = "DataProvider", parallel = true) - default Object[][] createData(final ITestNGMethod testMethod, ITestContext context) { - Annotation[] annotations = testMethod.getConstructorOrMethod().getMethod().getDeclaredAnnotations(); - Object[][] objects = DataProviderFactory.getDataProvider(annotations, context, testMethod); - return objects; - } - - @DataProvider(name = "SingleDataProvider") - default Object[][] createDataSingleThread(final ITestNGMethod testMethod, ITestContext context) { - Annotation[] annotations = testMethod.getConstructorOrMethod().getMethod().getDeclaredAnnotations(); - Object[][] objects = DataProviderFactory.getDataProvider(annotations, context, testMethod); - return objects; - } - /** * Pause for specified timeout. * diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/CustomProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/CustomProvider.java new file mode 100644 index 0000000000..559e9e0071 --- /dev/null +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/CustomProvider.java @@ -0,0 +1,24 @@ +package com.qaprosoft.carina.core.foundation.dataprovider.core; + +import org.testng.ITestContext; +import org.testng.ITestNGMethod; +import org.testng.annotations.DataProvider; + +import java.lang.annotation.Annotation; + +public interface CustomProvider { + + @DataProvider(name = "DataProvider", parallel = true) + default Object[][] createData(final ITestNGMethod testMethod, ITestContext context) { + Annotation[] annotations = testMethod.getConstructorOrMethod().getMethod().getDeclaredAnnotations(); + Object[][] objects = DataProviderFactory.getDataProvider(annotations, context, testMethod); + return objects; + } + + @DataProvider(name = "SingleDataProvider") + default Object[][] createDataSingleThread(final ITestNGMethod testMethod, ITestContext context) { + Annotation[] annotations = testMethod.getConstructorOrMethod().getMethod().getDeclaredAnnotations(); + Object[][] objects = DataProviderFactory.getDataProvider(annotations, context, testMethod); + return objects; + } +} From a75cc1fa70cb40df091a6ced49ab69e1326acef0 Mon Sep 17 00:00:00 2001 From: Dima Grinevich Date: Wed, 22 Mar 2023 11:17:03 +0300 Subject: [PATCH 20/52] refactor(IAbstractDataProvider.java): renaming --- .../core/{CustomProvider.java => IAbstractDataProvider.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/{CustomProvider.java => IAbstractDataProvider.java} (96%) diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/CustomProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/IAbstractDataProvider.java similarity index 96% rename from carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/CustomProvider.java rename to carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/IAbstractDataProvider.java index 559e9e0071..45d2b9b4a9 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/CustomProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/IAbstractDataProvider.java @@ -6,7 +6,7 @@ import java.lang.annotation.Annotation; -public interface CustomProvider { +public interface IAbstractDataProvider { @DataProvider(name = "DataProvider", parallel = true) default Object[][] createData(final ITestNGMethod testMethod, ITestContext context) { From ceb59a0c101cfb8e8303d548e61d02750b11321a Mon Sep 17 00:00:00 2001 From: Dima Grinevich Date: Wed, 22 Mar 2023 11:22:20 +0300 Subject: [PATCH 21/52] refactor(config.properties): changed test_naming_pattern --- carina-core/src/main/resources/config.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/carina-core/src/main/resources/config.properties b/carina-core/src/main/resources/config.properties index 130fdfc0fe..fcc3c16fa7 100644 --- a/carina-core/src/main/resources/config.properties +++ b/carina-core/src/main/resources/config.properties @@ -18,7 +18,7 @@ test_run_rules=NULL max_log_file_size=150 max_screen_history=NULL suite_name=NULL -test_naming_pattern={tuid} {map}{test_name} - {method_name} +test_naming_pattern={tuid}{test_name} - {method_name} report_url=NULL custom_artifacts_folder=NULL project_report_directory=NULL From 97abeb2310f4b4b9b7437940022488513d658008 Mon Sep 17 00:00:00 2001 From: Andrei Kamarouski Date: Wed, 22 Mar 2023 11:59:02 +0300 Subject: [PATCH 22/52] refactor(carina-dataprovider): refactor usage of @literal doc --- .../annotations/CsvDataSourceParameters.java | 2 +- .../annotations/XlsDataSourceParameters.java | 2 +- .../core/DataProviderFactory.java | 23 ++++++++-------- .../core/impl/BaseDataProvider.java | 26 ++++++++++++------- 4 files changed, 31 insertions(+), 22 deletions(-) diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/CsvDataSourceParameters.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/CsvDataSourceParameters.java index f7db783629..eecc71d971 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/CsvDataSourceParameters.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/CsvDataSourceParameters.java @@ -91,7 +91,7 @@ /** * Name of the column, by which will be performed grouping. - * If used, test will receive @literal{ArrayList} argument, + * If used, test will receive {@code ArrayList} argument, * where data grouped by lists depending on groupColumn values. * * @return String diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/XlsDataSourceParameters.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/XlsDataSourceParameters.java index 7e3143bc5e..b547500e3e 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/XlsDataSourceParameters.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/XlsDataSourceParameters.java @@ -92,7 +92,7 @@ /** * Name of the column, by which will be performed grouping. - * If used, test will receive @literal{ArrayList} argument, + * If used, test will receive {@literal ArrayList>} argument, * where data grouped by lists depending on groupColumn values. * * @return String diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java index 58670c1034..0727ca7643 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java @@ -15,14 +15,6 @@ *******************************************************************************/ package com.qaprosoft.carina.core.foundation.dataprovider.core; -import com.qaprosoft.carina.core.foundation.dataprovider.core.impl.BaseDataProvider; -import com.zebrunner.carina.utils.commons.SpecialKeywords; -import org.apache.commons.lang3.ArrayUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.ITestContext; -import org.testng.ITestNGMethod; - import java.lang.annotation.Annotation; import java.lang.invoke.MethodHandles; import java.lang.reflect.Constructor; @@ -31,6 +23,15 @@ import java.util.HashMap; import java.util.Map; +import org.apache.commons.lang3.ArrayUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.ITestContext; +import org.testng.ITestNGMethod; + +import com.qaprosoft.carina.core.foundation.dataprovider.core.impl.BaseDataProvider; +import com.zebrunner.carina.utils.commons.SpecialKeywords; + /** * Created by Patotsky on 16.12.2014. */ @@ -81,9 +82,9 @@ public static Object[][] getDataProvider(Annotation[] annotations, ITestContext /** * Put data from test parameters to test's context. Necessary for correct test naming. * - * @param context ITestContext. - * @param tuidMap @literal{Map} contains tuid values for each test (if present) - * @param testNameFromColumn @literal{Map} contains values for overriding test names from specified column + * @param context ITestContext. + * @param tuidMap contains tuid values for each test (if present) + * @param testNameFromColumn contains values for overriding test names from specified column */ private static synchronized void putValuesToContext(ITestContext context, Map tuidMap, diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java index 5abe9e6ab4..0e35173129 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java @@ -15,14 +15,22 @@ *******************************************************************************/ package com.qaprosoft.carina.core.foundation.dataprovider.core.impl; -import com.qaprosoft.carina.core.foundation.dataprovider.parser.AbstractTable; -import com.qaprosoft.carina.core.foundation.dataprovider.parser.DSBean; -import com.zebrunner.carina.utils.ParameterGenerator; +import java.lang.annotation.Annotation; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + import org.testng.ITestContext; import org.testng.ITestNGMethod; -import java.lang.annotation.Annotation; -import java.util.*; +import com.qaprosoft.carina.core.foundation.dataprovider.parser.AbstractTable; +import com.qaprosoft.carina.core.foundation.dataprovider.parser.DSBean; +import com.zebrunner.carina.utils.ParameterGenerator; /** * Created by Patotsky on 19.12.2014. @@ -58,10 +66,10 @@ public static String hash(Object[] args, ITestNGMethod method) { /** * Generate dataProvider based on grouped data rows * - * @param groupedList @literal{List>>} grouped data rows - * @param dsBean DSBean test parameters bean - * @param testMethod ITestNGMethod current test method - * @return Object[][] grouped data provider, where object[i][0] contains @literal{ArrayList>} + * @param groupedList grouped data rows + * @param dsBean DSBean test parameters bean + * @param testMethod ITestNGMethod current test method + * @return Object[][] grouped data provider, where object[i][0] contains {@code ArrayList>} */ public Object[][] createGroupedDataProvider(List>> groupedList, DSBean dsBean, ITestNGMethod testMethod) { Object[][] dataProvider = declareDataProviderArray(groupedList, dsBean); From 13250fc536ed6fc236be064d8ae398cf963d8ab0 Mon Sep 17 00:00:00 2001 From: Andrei Kamarouski Date: Wed, 22 Mar 2023 14:49:50 +0300 Subject: [PATCH 23/52] refactor: remove logic with EXCEL_DS_CUSTOM_PROVIDER and EXCEL_DS_ARGS, separate carina-dataprovider --- carina-core/pom.xml | 10 +- .../carina/core/foundation/IAbstractTest.java | 10 +- .../listeners/AbstractTestListener.java | 38 +-- .../carina/core/testng/TestNamingService.java | 8 +- carina-dataprovider/pom.xml | 16 +- .../{core => }/IAbstractDataProvider.java | 3 +- .../core/impl/BaseDataProvider.java | 22 +- .../core/impl/XlsDataProvider.java | 15 +- .../dataprovider/parser/AbstractTable.java | 84 ------ .../dataprovider/parser/csv/CSVTable.java | 9 +- .../dataprovider/parser/xls/XLSCache.java | 58 ---- .../parser/xls/XLSChildTable.java | 33 --- .../dataprovider/parser/xls/XLSParser.java | 268 ------------------ .../dataprovider/parser/xls/XLSTable.java | 124 -------- .../carina/utils/ParameterGenerator.java | 164 ----------- .../parser/CellLinksIntegrationTest.java | 4 +- pom.xml | 5 - 17 files changed, 54 insertions(+), 817 deletions(-) rename carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/{core => }/IAbstractDataProvider.java (87%) delete mode 100644 carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/AbstractTable.java delete mode 100644 carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/xls/XLSCache.java delete mode 100644 carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/xls/XLSChildTable.java delete mode 100644 carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/xls/XLSParser.java delete mode 100644 carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/xls/XLSTable.java delete mode 100644 carina-dataprovider/src/main/java/com/zebrunner/carina/utils/ParameterGenerator.java diff --git a/carina-core/pom.xml b/carina-core/pom.xml index b350217824..92e8742978 100644 --- a/carina-core/pom.xml +++ b/carina-core/pom.xml @@ -20,10 +20,10 @@ UTF-8 1.0.0 - 1.0.2 + 1.0.3.P1-SNAPSHOT - + @@ -44,10 +44,6 @@ ${carina-webdriver.version} - - com.qaprosoft - carina-dataprovider - com.zebrunner carina-utils diff --git a/carina-core/src/main/java/com/qaprosoft/carina/core/foundation/IAbstractTest.java b/carina-core/src/main/java/com/qaprosoft/carina/core/foundation/IAbstractTest.java index 14ad198eb8..e1c0d38bb8 100644 --- a/carina-core/src/main/java/com/qaprosoft/carina/core/foundation/IAbstractTest.java +++ b/carina-core/src/main/java/com/qaprosoft/carina/core/foundation/IAbstractTest.java @@ -15,27 +15,21 @@ *******************************************************************************/ package com.qaprosoft.carina.core.foundation; -import java.lang.annotation.Annotation; - -import org.testng.ITestContext; -import org.testng.ITestNGMethod; import org.testng.SkipException; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeSuite; -import org.testng.annotations.DataProvider; import com.nordstrom.automation.testng.LinkedListeners; -import com.qaprosoft.carina.core.foundation.dataprovider.core.DataProviderFactory; import com.qaprosoft.carina.core.foundation.listeners.CarinaListener; import com.qaprosoft.carina.core.foundation.listeners.FilterTestsListener; import com.qaprosoft.carina.core.foundation.report.testrail.ITestCases; +import com.zebrunner.agent.core.registrar.CurrentTest; +import com.zebrunner.agent.testng.listener.TestRunListener; import com.zebrunner.carina.utils.Configuration; import com.zebrunner.carina.utils.Configuration.Parameter; import com.zebrunner.carina.utils.common.CommonUtils; import com.zebrunner.carina.utils.factory.ICustomTypePageFactory; -import com.zebrunner.agent.core.registrar.CurrentTest; -import com.zebrunner.agent.testng.listener.TestRunListener; /* * IAbstractTest - base test for UI and API tests. diff --git a/carina-core/src/main/java/com/qaprosoft/carina/core/foundation/listeners/AbstractTestListener.java b/carina-core/src/main/java/com/qaprosoft/carina/core/foundation/listeners/AbstractTestListener.java index dacfe21613..9b2ec0a90e 100644 --- a/carina-core/src/main/java/com/qaprosoft/carina/core/foundation/listeners/AbstractTestListener.java +++ b/carina-core/src/main/java/com/qaprosoft/carina/core/foundation/listeners/AbstractTestListener.java @@ -19,7 +19,6 @@ import java.util.Collection; import java.util.Map; -import com.zebrunner.carina.core.testng.TestNamingService; import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; @@ -30,22 +29,22 @@ import org.testng.TestListenerAdapter; import org.testng.internal.annotations.DisabledRetryAnalyzer; -import com.zebrunner.carina.utils.commons.SpecialKeywords; -import com.qaprosoft.carina.core.foundation.dataprovider.parser.DSBean; -import com.zebrunner.carina.utils.report.ReportContext; -import com.zebrunner.carina.utils.report.TestResultItem; -import com.zebrunner.carina.utils.report.TestResultType; import com.qaprosoft.carina.core.foundation.report.email.EmailReportItemCollector; -import com.zebrunner.carina.utils.retry.RetryAnalyzer; +import com.zebrunner.agent.testng.core.retry.RetryAnalyzerInterceptor; +import com.zebrunner.agent.testng.core.testname.TestNameResolverRegistry; +import com.zebrunner.agent.testng.listener.RetryService; +import com.zebrunner.carina.core.testng.TestNamingService; import com.zebrunner.carina.utils.DateUtils; -import com.zebrunner.carina.utils.messager.Messager; import com.zebrunner.carina.utils.ParameterGenerator; import com.zebrunner.carina.utils.R; import com.zebrunner.carina.utils.StringGenerator; +import com.zebrunner.carina.utils.commons.SpecialKeywords; +import com.zebrunner.carina.utils.messager.Messager; +import com.zebrunner.carina.utils.report.ReportContext; +import com.zebrunner.carina.utils.report.TestResultItem; +import com.zebrunner.carina.utils.report.TestResultType; +import com.zebrunner.carina.utils.retry.RetryAnalyzer; import com.zebrunner.carina.webdriver.IDriverPool; -import com.zebrunner.agent.testng.core.retry.RetryAnalyzerInterceptor; -import com.zebrunner.agent.testng.core.testname.TestNameResolverRegistry; -import com.zebrunner.agent.testng.listener.RetryService; public class AbstractTestListener extends TestListenerAdapter implements IDriverPool { private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); @@ -154,23 +153,6 @@ public void onTestStart(ITestResult result) { generateParameters(result); - if (!result.getTestContext().getCurrentXmlTest().getAllParameters() - .containsKey(SpecialKeywords.EXCEL_DS_CUSTOM_PROVIDER) && - result.getParameters().length > 0) // set parameters from XLS only if test contains any parameter at - // all) - { - if (result.getTestContext().getCurrentXmlTest().getAllParameters() - .containsKey(SpecialKeywords.EXCEL_DS_ARGS)) { - DSBean dsBean = new DSBean(result.getTestContext()); - int index = 0; - for (String arg : dsBean.getArgs()) { - dsBean.getTestParams().put(arg, (String) result.getParameters()[index++]); - } - result.getTestContext().getCurrentXmlTest().setParameters(dsBean.getTestParams()); - - } - } - //TODO: do not write STARTED at message for retry! or move it into the DEBUG level! startItem(result, Messager.TEST_STARTED); diff --git a/carina-core/src/main/java/com/zebrunner/carina/core/testng/TestNamingService.java b/carina-core/src/main/java/com/zebrunner/carina/core/testng/TestNamingService.java index 665faebe17..355b667cff 100644 --- a/carina-core/src/main/java/com/zebrunner/carina/core/testng/TestNamingService.java +++ b/carina-core/src/main/java/com/zebrunner/carina/core/testng/TestNamingService.java @@ -22,8 +22,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; -import com.qaprosoft.carina.core.foundation.dataprovider.core.impl.BaseDataProvider; -import com.zebrunner.agent.testng.listener.RunContextService; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -31,7 +29,9 @@ import org.testng.ITestNGMethod; import org.testng.ITestResult; +import com.zebrunner.agent.testng.listener.RunContextService; import com.zebrunner.carina.utils.Configuration; +import com.zebrunner.carina.utils.ParameterGenerator; import com.zebrunner.carina.utils.commons.SpecialKeywords; public class TestNamingService { @@ -122,7 +122,7 @@ private static String getTestNameMap(ITestResult result) { @SuppressWarnings("unchecked") Map testNameMap = (Map) result.getTestContext().getAttribute(SpecialKeywords.TEST_NAME); if (testNameMap != null && !testNameMap.isEmpty()) { - String testHash = BaseDataProvider.hash(result.getParameters(), result.getMethod()); + String testHash = ParameterGenerator.hash(result.getParameters(), result.getMethod()); if (testNameMap.containsKey(testHash)) { testNameMapName = testNameMap.get(testHash); } @@ -164,7 +164,7 @@ private static String getMethodUID(ITestResult result) { Map tuidMap = (Map) result.getTestContext().getAttribute(SpecialKeywords.TUID); if (tuidMap != null) { - String testHash = BaseDataProvider.hash(result.getParameters(), result.getMethod()); + String testHash = ParameterGenerator.hash(result.getParameters(), result.getMethod()); if (tuidMap.containsKey(testHash)) { methodUID = tuidMap.get(testHash) + " - "; } diff --git a/carina-dataprovider/pom.xml b/carina-dataprovider/pom.xml index 48a7bcda4e..26a1b0b75d 100644 --- a/carina-dataprovider/pom.xml +++ b/carina-dataprovider/pom.xml @@ -20,10 +20,24 @@ UTF-8 - 1.0.2 + 1.0.3.P1-SNAPSHOT 1.7 + + + zebrunner_snapshots + zebrunner Snapshots + https://nexus.zebrunner.dev/repository/ce-snapshots/ + + false + + + true + + + + diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/IAbstractDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/IAbstractDataProvider.java similarity index 87% rename from carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/IAbstractDataProvider.java rename to carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/IAbstractDataProvider.java index 45d2b9b4a9..b1e55a22de 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/IAbstractDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/IAbstractDataProvider.java @@ -1,5 +1,6 @@ -package com.qaprosoft.carina.core.foundation.dataprovider.core; +package com.qaprosoft.carina.core.foundation.dataprovider; +import com.qaprosoft.carina.core.foundation.dataprovider.core.DataProviderFactory; import org.testng.ITestContext; import org.testng.ITestNGMethod; import org.testng.annotations.DataProvider; diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java index 0e35173129..64a8cd0aa5 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java @@ -17,7 +17,6 @@ import java.lang.annotation.Annotation; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashSet; @@ -28,9 +27,9 @@ import org.testng.ITestContext; import org.testng.ITestNGMethod; -import com.qaprosoft.carina.core.foundation.dataprovider.parser.AbstractTable; import com.qaprosoft.carina.core.foundation.dataprovider.parser.DSBean; import com.zebrunner.carina.utils.ParameterGenerator; +import com.zebrunner.carina.utils.parser.xls.AbstractTable; /** * Created by Patotsky on 19.12.2014. @@ -48,21 +47,6 @@ protected void addValueToMap(Map map, String hashCode, String va } } - /** - * Generate hash by class name, method name and arg values. - * - * @param args Object[] test method arguments - * @param method ITestNGMethod - * @return String hash - */ - public static String hash(Object[] args, ITestNGMethod method) { - String toHash = ""; - toHash += Arrays.hashCode(args); - toHash += method.getMethodName(); - toHash += (method.getRealClass()); - return String.valueOf(toHash.hashCode()); - } - /** * Generate dataProvider based on grouped data rows * @@ -177,7 +161,7 @@ private void configureTestNamingVars(Object[][] dataProvider, DSBean dsBean, Abs for (int rowIndex = 0; rowIndex < dataProvider.length; rowIndex++) { Map row = table.getDataRows().get(rowIndex); - String rowHash = hash(dataProvider[rowIndex], testNGMethod); + String rowHash = ParameterGenerator.hash(dataProvider[rowIndex], testNGMethod); addValueToMap(tuidMap, rowHash, getValueFromRow(row, dsBean.getUidArgs())); addValueToMap(testColumnNamesMap, rowHash, getValueFromRow(row, List.of(dsBean.getTestMethodColumn()))); } @@ -189,7 +173,7 @@ private void configureTestNamingVarsForGroupedProvider(Object[][] dataProvider, ITestNGMethod testNGMethod) { for (int rowIndex = 0; rowIndex < dataProvider.length; rowIndex++) { - String rowHash = hash(dataProvider[rowIndex], testNGMethod); + String rowHash = ParameterGenerator.hash(dataProvider[rowIndex], testNGMethod); //get all unique tuid values from certain group String testUid = getValueFromGroupList(rowIndex, groupedList, dsBean.getUidArgs()); diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java index 07240f450d..5ecbfb4247 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java @@ -15,17 +15,18 @@ *******************************************************************************/ package com.qaprosoft.carina.core.foundation.dataprovider.core.impl; -import com.qaprosoft.carina.core.foundation.dataprovider.annotations.XlsDataSourceParameters; -import com.qaprosoft.carina.core.foundation.dataprovider.parser.DSBean; -import com.qaprosoft.carina.core.foundation.dataprovider.parser.xls.XLSParser; -import com.qaprosoft.carina.core.foundation.dataprovider.parser.xls.XLSTable; -import org.testng.ITestContext; -import org.testng.ITestNGMethod; - import java.lang.annotation.Annotation; import java.util.List; import java.util.Map; +import org.testng.ITestContext; +import org.testng.ITestNGMethod; + +import com.qaprosoft.carina.core.foundation.dataprovider.annotations.XlsDataSourceParameters; +import com.qaprosoft.carina.core.foundation.dataprovider.parser.DSBean; +import com.zebrunner.carina.utils.parser.xls.XLSParser; +import com.zebrunner.carina.utils.parser.xls.XLSTable; + /** * Created by Patotsky on 16.12.2014. */ diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/AbstractTable.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/AbstractTable.java deleted file mode 100644 index c6171daeda..0000000000 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/AbstractTable.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.qaprosoft.carina.core.foundation.dataprovider.parser; - -import com.zebrunner.carina.utils.ParameterGenerator; - -import java.util.*; - -public abstract class AbstractTable { - protected List headers; - protected List> dataRows; - protected String executeColumn; - protected String executeValue; - - public AbstractTable() { - headers = Collections.synchronizedList(new LinkedList()); - dataRows = Collections.synchronizedList(new LinkedList>()); - } - - public AbstractTable(String executeColumn, String executeValue) { - this(); - this.executeColumn = executeColumn; - this.executeValue = executeValue; - } - - public List getHeaders() { - return headers; - } - - public List> getDataRows() { - return dataRows; - } - - public String getExecuteColumn() { - return executeColumn; - } - - public void setExecuteColumn(String executeColumn) { - this.executeColumn = executeColumn; - } - - public String getExecuteValue() { - return executeValue; - } - - public void setExecuteValue(String executeValue) { - this.executeValue = executeValue; - } - - public void setHeaders(Collection row) { - headers.clear(); - headers.addAll(row); - } - - public abstract void addDataRow(List row); - - public void processTable() { - for (Map row : dataRows) { - ParameterGenerator.processMap(row); - } - } - - public List>> getGroupedDataProviderMap(String fieldName) { - //add unique group values - Set groupValues = new LinkedHashSet<>(); - for (Map item : dataRows) { - String value = item.get(fieldName); - groupValues.add(value); - } - - //group maps into lists, that has the same unique group value - List>> groupedList = new ArrayList<>(); - for (String groupBy: groupValues) { - List> groupOfRows = new ArrayList<>(); - for (Map item : dataRows) { - String value = item.get(fieldName); - if (value.equals(groupBy)) { - groupOfRows.add(item); - } - } - groupedList.add(groupOfRows); - } - - return groupedList; - } -} diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/csv/CSVTable.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/csv/CSVTable.java index 82d9134285..bab708f486 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/csv/CSVTable.java +++ b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/csv/CSVTable.java @@ -1,14 +1,15 @@ package com.qaprosoft.carina.core.foundation.dataprovider.parser.csv; -import com.qaprosoft.carina.core.foundation.dataprovider.parser.AbstractTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.lang.invoke.MethodHandles; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.zebrunner.carina.utils.parser.xls.AbstractTable; + public class CSVTable extends AbstractTable { private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/xls/XLSCache.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/xls/XLSCache.java deleted file mode 100644 index 14265a6e13..0000000000 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/xls/XLSCache.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright 2020-2022 Zebrunner Inc (https://www.zebrunner.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *******************************************************************************/ -package com.qaprosoft.carina.core.foundation.dataprovider.parser.xls; - -import org.apache.poi.ss.usermodel.Workbook; -import org.apache.poi.ss.usermodel.WorkbookFactory; - -import java.io.InputStream; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; - -public class XLSCache { - private static Map xlsCache = new HashMap(); - - public static synchronized Workbook getWorkbook(String xlsPath) { - if (!xlsCache.keySet().contains(xlsPath)) { - Workbook wb; - try { - InputStream is = ClassLoader.getSystemResourceAsStream(xlsPath); - try { - wb = WorkbookFactory.create(is); - } finally { - // [VD] code cleanup based on Sonar - is.close(); - // if (is != null) { - // is.close(); - // } - } - } catch (Exception e) { - throw new RuntimeException("Can't read xls: " + xlsPath); - } - xlsCache.put(xlsPath, wb); - } - return xlsCache.get(xlsPath); - } - - public static synchronized String getWorkbookPath(Workbook book) { - for (Entry entry : xlsCache.entrySet()) { - if (entry.getValue() == book) - return entry.getKey(); - } - return null; - } -} diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/xls/XLSChildTable.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/xls/XLSChildTable.java deleted file mode 100644 index 4fe8d4e015..0000000000 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/xls/XLSChildTable.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright 2020-2022 Zebrunner Inc (https://www.zebrunner.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *******************************************************************************/ -package com.qaprosoft.carina.core.foundation.dataprovider.parser.xls; - -import org.apache.poi.ss.usermodel.Row; - -import java.util.HashMap; -import java.util.Map; - -public class XLSChildTable extends XLSTable { - public void addDataRow(Row row) { - Map dataMap = new HashMap(); - for (int i = 0; i < super.getHeaders().size(); i++) { - synchronized (dataMap) { - dataMap.put(super.getHeaders().get(i), XLSParser.getCellValue(row.getCell(i))); - } - } - super.getDataRows().add(dataMap); - } -} diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/xls/XLSParser.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/xls/XLSParser.java deleted file mode 100644 index 28f5262321..0000000000 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/xls/XLSParser.java +++ /dev/null @@ -1,268 +0,0 @@ -/******************************************************************************* - * Copyright 2020-2022 Zebrunner Inc (https://www.zebrunner.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *******************************************************************************/ -package com.qaprosoft.carina.core.foundation.dataprovider.parser.xls; - -import java.io.File; -import java.lang.invoke.MethodHandles; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Locale; - -import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.ss.usermodel.CellType; -import org.apache.poi.ss.usermodel.DataFormatter; -import org.apache.poi.ss.usermodel.FormulaEvaluator; -import org.apache.poi.ss.usermodel.Sheet; -import org.apache.poi.ss.usermodel.Workbook; -import org.apache.poi.xssf.model.ExternalLinksTable; -import org.apache.poi.xssf.usermodel.XSSFSheet; -import org.apache.poi.xssf.usermodel.XSSFTable; -import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.zebrunner.carina.utils.exception.DataLoadingException; -import com.zebrunner.carina.utils.exception.InvalidArgsException; - -public class XLSParser { - private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - private static DataFormatter df; - private static FormulaEvaluator evaluator; - - static { - df = new DataFormatter(); - } - - public static String parseValue(String locatorKey, String xlsPath, Locale locale) { - String value; - - Workbook wb = XLSCache.getWorkbook(xlsPath); - Sheet sheet = wb.getSheetAt(0); - - List locales = getLocales(sheet); - if (!locales.contains(locale.getCountry())) { - throw new RuntimeException("Can't find locale '" + locale.getCountry() + "' in xls '" + xlsPath + "'!"); - } - int cellN = locales.indexOf(locale.getCountry()) + 1; - - List locatorKeys = getLocatorKeys(sheet); - if (!locatorKeys.contains(locatorKey)) { - throw new RuntimeException("Can't find locatorKey '" + locatorKey + "' in xls '" + xlsPath + "'!"); - } - int rowN = locatorKeys.indexOf(locatorKey) + 1; - - try { - value = getCellValue(sheet.getRow(rowN).getCell(cellN)); - } catch (Exception e) { - throw new RuntimeException("Can't find value for locatorKey '" + locatorKey + "' with locale '" + locale.getCountry() - + "' in xls '" + xlsPath + "'!"); - } - - return value; - } - - private static List getLocales(Sheet sheet) { - List locales = new ArrayList(); - int lastCell = sheet.getRow(0).getLastCellNum(); - for (int i = 1; i < lastCell; i++) { - locales.add(getCellValue(sheet.getRow(0).getCell(i))); - } - return locales; - } - - private static List getLocatorKeys(Sheet sheet) { - List locatorKeys = new ArrayList(); - int lastRow = sheet.getLastRowNum(); - for (int i = 1; i <= lastRow; i++) { - locatorKeys.add(getCellValue(sheet.getRow(i).getCell(0))); - } - return locatorKeys; - } - - public static String parseValue(String xls, String sheetName, String key) { - String value = null; - - Workbook wb = XLSCache.getWorkbook(xls); - - Sheet sheet = wb.getSheet(sheetName); - if (sheet == null) { - throw new InvalidArgsException(String.format("No sheet: '%s' in excel file: '%s'!", sheetName, xls)); - } - - boolean isKeyFound = false; - for (int i = 1; i <= sheet.getLastRowNum(); i++) { - if (key.equals(getCellValue(sheet.getRow(i).getCell(0)))) { - value = getCellValue(sheet.getRow(i).getCell(1)); - isKeyFound = true; - break; - } - } - - if (!isKeyFound) { - throw new InvalidArgsException(String.format("No key: '%s' on sheet '%s' in excel file: '%s'!", key, sheetName, xls)); - } - - return value; - } - - public static XLSTable parseSpreadSheet(String xls, String sheetName) { - return parseSpreadSheet(xls, sheetName, null, null); - } - - public static XLSTable parseSpreadSheet(String xls, String sheetName, String executeColumn, String executeValue) { - XLSTable dataTable = prepareDataTable(executeColumn, executeValue); - - Workbook wb = XLSCache.getWorkbook(xls); - evaluator = wb.getCreationHelper().createFormulaEvaluator(); - - Sheet sheet = wb.getSheet(sheetName); - if (sheet == null) { - throw new InvalidArgsException(String.format("No sheet: '%s' in excel file: '%s'!", sheetName, xls)); - } - - try { - for (int i = 0; i <= sheet.getLastRowNum(); i++) { - if (i == 0) { - dataTable.setHeaders(sheet.getRow(i)); - } else { - dataTable.addDataRow(sheet.getRow(i), wb, sheet); - } - } - } catch (Exception e) { - LOGGER.error("Error while parsing spreadsheet!", e); - } - return dataTable; - } - - public static String getCellValue(Cell cell) { - if (cell == null) - return ""; - - switch (cell.getCellType()) { - case STRING: - return df.formatCellValue(cell).trim(); - case NUMERIC: - return df.formatCellValue(cell).trim(); - case BOOLEAN: - return df.formatCellValue(cell).trim(); - case FORMULA: - return (cell.getCellFormula().contains("[") && cell.getCellFormula().contains("]")) ? null : df.formatCellValue(cell, evaluator).trim(); - case BLANK: - return ""; - default: - return null; - } - } - - public static XLSChildTable parseCellLinks(Cell cell, Workbook wb, Sheet sheet) { - if (cell == null) - return null; - - if (cell.getCellType() == CellType.FORMULA) { - if (cell.getCellFormula().contains("#This Row")) { - if (cell.getCellFormula().contains("!")) { - // Parse link to the cell with table name in the external doc([2]!Table1[[#This Row],[Header6]]) - List paths = Arrays.asList(cell.getCellFormula().split("!")); - int externalLinkNumber = Integer.valueOf(paths.get(0).replaceAll("\\D+", "")) - 1; - String tableName = paths.get(1).split("\\[")[0]; - if (wb instanceof XSSFWorkbook) { - ExternalLinksTable link = ((XSSFWorkbook) wb).getExternalLinksTable().get(externalLinkNumber); - File file = new File(XLSCache.getWorkbookPath(wb)); - XSSFWorkbook childWb = (XSSFWorkbook) XLSCache.getWorkbook(file.getParent() + "/" + link.getLinkedFileName()); - if (childWb == null) - throw new DataLoadingException(String.format("WorkBook '%s' doesn't exist!", link.getLinkedFileName())); - for (int i = 0; i < childWb.getNumberOfSheets(); i++) { - XSSFSheet childSheet = childWb.getSheetAt(i); - for (XSSFTable table : childSheet.getTables()) { - if (table.getName().equals(tableName)) { - return createChildTable(childSheet, cell.getRowIndex()); - } - } - } - } else { - throw new DataLoadingException("Unsupported format. External links supports only for .xlsx documents."); - } - } else { - // Parse link to the cell with table name in the same doc(=Table1[[#This Row],[Header6]]) - List paths = Arrays.asList(cell.getCellFormula().replace("=", "").split("\\[")); - if (wb instanceof XSSFWorkbook) { - for (int i = 0; i < wb.getNumberOfSheets(); i++) { - XSSFSheet childSheet = (XSSFSheet) wb.getSheetAt(i); - for (XSSFTable table : childSheet.getTables()) { - if (table.getName().equals(paths.get(0))) { - return createChildTable(childSheet, cell.getRowIndex()); - } - } - } - } else { - throw new DataLoadingException("Unsupported format. Links with table name supports only for .xlsx documents."); - } - } - } else { - String cellValue = cell.getCellFormula().replace("=", "").replace("[", "").replace("]", "!").replace("'", ""); - List paths = Arrays.asList(cellValue.split("!")); - int rowNumber = 0; - Sheet childSheet = null; - - switch (paths.size()) { - // Parse link to the cell in the same sheet(=A4) - case 1: - rowNumber = Integer.valueOf(paths.get(0).replaceAll("\\D+", "")) - 1; - return createChildTable(sheet, rowNumber); - // Parse link to the cell in another sheet in the same doc(=SheetName!A4) - case 2: - childSheet = wb.getSheet(paths.get(0)); - if (childSheet == null) - throw new DataLoadingException(String.format("Sheet '%s' doesn't exist!", paths.get(0))); - rowNumber = Integer.valueOf(paths.get(1).replaceAll("\\D+", "")) - 1; - return createChildTable(childSheet, rowNumber); - // Parse link to the cell in another doc(=[2]SheetName!A4) - case 3: - if (wb instanceof XSSFWorkbook) { - ExternalLinksTable link = ((XSSFWorkbook) wb).getExternalLinksTable().get(Integer.valueOf(paths.get(0)) - 1); - File file = new File(XLSCache.getWorkbookPath(wb)); - XSSFWorkbook childWb = (XSSFWorkbook) XLSCache.getWorkbook(file.getParent() + "/" + link.getLinkedFileName()); - - if (childWb == null) - throw new DataLoadingException(String.format("WorkBook '%s' doesn't exist!", paths.get(0))); - childSheet = childWb.getSheet(paths.get(1)); - if (childSheet == null) - throw new DataLoadingException(String.format("Sheet '%s' doesn't exist!", paths.get(0))); - rowNumber = Integer.valueOf(paths.get(2).replaceAll("\\D+", "")) - 1; - return createChildTable(childSheet, rowNumber); - } else { - throw new DataLoadingException("Unsupported format. External links supports only for .xlsx documents."); - } - default: - return null; - } - } - } - return null; - } - - private static XLSChildTable createChildTable(Sheet sheet, int rowNumber) { - XLSChildTable childTable = new XLSChildTable(); - childTable.setHeaders(sheet.getRow(0)); - childTable.addDataRow(sheet.getRow(rowNumber)); - return childTable; - } - - private static XLSTable prepareDataTable(String executeColumn, String executeValue) { - return executeColumn != null && executeValue != null ? new XLSTable(executeColumn, executeValue) : new XLSTable(); - } -} diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/xls/XLSTable.java b/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/xls/XLSTable.java deleted file mode 100644 index 9cdf54fc40..0000000000 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/xls/XLSTable.java +++ /dev/null @@ -1,124 +0,0 @@ -/******************************************************************************* - * Copyright 2020-2022 Zebrunner Inc (https://www.zebrunner.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *******************************************************************************/ -package com.qaprosoft.carina.core.foundation.dataprovider.parser.xls; - -import com.qaprosoft.carina.core.foundation.dataprovider.parser.AbstractTable; -import org.apache.commons.lang3.StringUtils; -import org.apache.poi.ss.usermodel.Row; -import org.apache.poi.ss.usermodel.Sheet; -import org.apache.poi.ss.usermodel.Workbook; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.lang.invoke.MethodHandles; -import java.util.*; -import java.util.function.Function; - -public class XLSTable extends AbstractTable { - private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - private final static String FK_PREFIX = "FK_LINK_"; - - public XLSTable() { - super(); - } - - public XLSTable(String executeColumn, String executeValue) { - super(executeColumn, executeValue); - } - - public void setHeaders(Row row) { - headers.clear(); - for (int i = 0; i < row.getLastCellNum(); i++) { - headers.add(XLSParser.getCellValue(row.getCell(i))); - } - } - - public void addDataRow(Row row, Workbook wb, Sheet sheet) { - if (row == null) { - // don't add any data row if it is null. It seems like there is empty row in xls file - return; - } - addDataRow(rowIndex -> XLSParser.getCellValue(row.getCell(rowIndex)), row, wb, sheet); - } - - @Override - public void addDataRow(List row) { - if (row == null) { - return; - } - addDataRow(index -> row.size() > index ? row.get(index) : null, null, null, null); - } - - private void addDataRow(Function cellValueGetter, Row row, Workbook wb, Sheet sheet) { - if (executeColumn != null && executeValue != null && headers.contains(executeColumn)) { - if (!executeValue.equalsIgnoreCase(cellValueGetter.apply(headers.indexOf(executeColumn)))) { - return; - } - } - - XLSChildTable childRow = null; - - Map dataMap = new HashMap(); - LOGGER.debug("Loading data from row: "); - for (int i = 0; i < headers.size(); i++) { - String header = headers.get(i); - if (header.startsWith(FK_PREFIX)) { - if(row != null && wb != null && sheet != null) { - childRow = XLSParser.parseCellLinks(row.getCell(i), wb, sheet); - } else { - // TODO: 2019-03-20 implement logic to use fk prefix for spreadsheets - LOGGER.warn("FK_LINK_ prefix is not currently supported for spreadsheets"); - } - } - - synchronized (dataMap) { - dataMap.put(header, cellValueGetter.apply(i)); - } - LOGGER.debug(header + ": " + dataMap.get(header)); - } - - // If row has foreign key than merge headers and data - merge(childRow, dataMap); - - LOGGER.debug("Merged row: "); - for (int i = 0; i < headers.size(); i++) { - LOGGER.debug(headers.get(i) + ": " + dataMap.get(headers.get(i))); - } - - dataRows.add(dataMap); - } - - private void merge(XLSChildTable childRow, Map dataMap) { - if (childRow != null) { - LOGGER.debug("Loading data from child row: "); - for (int i = 0; i < childRow.getHeaders().size(); i++) { - String currentHeader = childRow.getHeaders().get(i); - - if (StringUtils.isBlank(dataMap.get(currentHeader))) { - // Merge headers - if (!this.headers.contains(currentHeader)) - this.headers.add(currentHeader); - - // Merge data - synchronized (dataMap) { - dataMap.put(currentHeader, childRow.getDataRows().get(0).get(currentHeader)); - } - } - LOGGER.debug(currentHeader + ": " + childRow.getDataRows().get(0).get(currentHeader)); - } - } - } -} diff --git a/carina-dataprovider/src/main/java/com/zebrunner/carina/utils/ParameterGenerator.java b/carina-dataprovider/src/main/java/com/zebrunner/carina/utils/ParameterGenerator.java deleted file mode 100644 index d5e5c0bd43..0000000000 --- a/carina-dataprovider/src/main/java/com/zebrunner/carina/utils/ParameterGenerator.java +++ /dev/null @@ -1,164 +0,0 @@ -/******************************************************************************* - * Copyright 2020-2022 Zebrunner Inc (https://www.zebrunner.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *******************************************************************************/ -package com.zebrunner.carina.utils; - -import java.lang.invoke.MethodHandles; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.zebrunner.carina.utils.commons.SpecialKeywords; -import com.qaprosoft.carina.core.foundation.dataprovider.parser.xls.XLSParser; -import com.zebrunner.carina.utils.exception.InvalidArgsException; -import com.zebrunner.carina.utils.resources.L10N; - -public class ParameterGenerator { - - private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - - private static Pattern GENERATE_UUID_PATTERN = Pattern.compile(SpecialKeywords.GENERATE_UUID); - private static Pattern GENERATE_PATTERN = Pattern.compile(SpecialKeywords.GENERATE); - private static Pattern GENERATEAN_PATTERN = Pattern.compile(SpecialKeywords.GENERATEAN); - private static Pattern GENERATEN_PATTERN = Pattern.compile(SpecialKeywords.GENERATEN); - private static Pattern TESTDATA_PATTERN = Pattern.compile(SpecialKeywords.TESTDATA); - private static Pattern ENV_PATTERN = Pattern.compile(SpecialKeywords.ENV); - private static Pattern L10N_PATTERN = Pattern.compile(SpecialKeywords.L10N_PATTERN); - private static Pattern EXCEL_PATTERN = Pattern.compile(SpecialKeywords.EXCEL); - - private static Matcher matcher; - - private static String UUID; - - public static Object process(String param) { - try { - if (param == null || param.toLowerCase().equals("nil")) { - return null; - } - - matcher = GENERATE_UUID_PATTERN.matcher(param); - if (matcher.find()) { - return StringUtils.replace(param, matcher.group(), UUID); - } - matcher = GENERATE_PATTERN.matcher(param); - if (matcher.find()) { - int start = param.indexOf(":") + 1; - int end = param.indexOf("}"); - int size = Integer.valueOf(param.substring(start, end)); - return StringUtils.replace(param, matcher.group(), StringGenerator.generateWord(size)); - } - - matcher = GENERATEAN_PATTERN.matcher(param); - if (matcher.find()) { - int start = param.indexOf(":") + 1; - int end = param.indexOf("}"); - int size = Integer.valueOf(param.substring(start, end)); - return StringUtils.replace(param, matcher.group(), StringGenerator.generateWordAN(size)); - } - - matcher = GENERATEN_PATTERN.matcher(param); - if (matcher.find()) { - int start = param.indexOf(":") + 1; - int end = param.indexOf("}"); - int size = Integer.valueOf(param.substring(start, end)); - return StringUtils.replace(param, matcher.group(), StringGenerator.generateNumeric(size)); - } - - matcher = ENV_PATTERN.matcher(param); - if (matcher.find()) { - int start = param.indexOf(":") + 1; - int end = param.indexOf("}"); - String key = param.substring(start, end); - return StringUtils.replace(param, matcher.group(), Configuration.getEnvArg(key)); - } - - matcher = TESTDATA_PATTERN.matcher(param); - if (matcher.find()) { - int start = param.indexOf(":") + 1; - int end = param.indexOf("}"); - String key = param.substring(start, end); - return StringUtils.replace(param, matcher.group(), R.TESTDATA.get(key)); - } - - matcher = EXCEL_PATTERN.matcher(param); - if (matcher.find()) { - int start = param.indexOf(":") + 1; - int end = param.indexOf("}"); - String key = param.substring(start, end); - return StringUtils.replace(param, matcher.group(), getValueFromXLS(key)); - } - - matcher = L10N_PATTERN.matcher(param); - String initStrL10N = param; - while (matcher.find()) { - int start = param.indexOf(SpecialKeywords.L10N + ":") + 5; - int end = param.indexOf("}"); - String key = param.substring(start, end); - param = StringUtils.replace(param, matcher.group(), L10N.getText(key)); - } - // in case if L10N pattern was applied - if (!initStrL10N.equalsIgnoreCase(param)) { - return param; - } - } catch (Exception e) { - LOGGER.error(e.getMessage()); - } - return param; - } - - public static void processMap(Map paramsMap) { - for (Map.Entry entry : paramsMap.entrySet()) { - if (entry == null) - continue; - - String value = entry.getValue(); - if (value == null) - continue; - - Object param = process(value); - if (param == null) - continue; - - String newValue = param.toString(); - if (!value.equals(newValue)) { - entry.setValue(newValue); - } - } - } - - private static String getValueFromXLS(String xlsSheetKey) { - if (StringUtils.isEmpty(xlsSheetKey)) { - throw new InvalidArgsException("Invalid excel key, should be 'xls_file#sheet#key'."); - } - - String xls = xlsSheetKey.split("#")[0]; - String sheet = xlsSheetKey.split("#")[1]; - String key = xlsSheetKey.split("#")[2]; - - return XLSParser.parseValue(xls, sheet, key); - } - - public static String getUUID() { - return UUID; - } - - public static void setUUID(String uUID) { - UUID = uUID; - } -} diff --git a/carina-dataprovider/src/test/java/com/qaprosoft/carina/core/foundation/parser/CellLinksIntegrationTest.java b/carina-dataprovider/src/test/java/com/qaprosoft/carina/core/foundation/parser/CellLinksIntegrationTest.java index 55365d7258..b12daf1222 100644 --- a/carina-dataprovider/src/test/java/com/qaprosoft/carina/core/foundation/parser/CellLinksIntegrationTest.java +++ b/carina-dataprovider/src/test/java/com/qaprosoft/carina/core/foundation/parser/CellLinksIntegrationTest.java @@ -19,12 +19,12 @@ import java.util.List; import java.util.Map; -import com.qaprosoft.carina.core.foundation.dataprovider.parser.xls.XLSParser; import org.testng.Assert; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; -import com.qaprosoft.carina.core.foundation.dataprovider.parser.xls.XLSTable; +import com.zebrunner.carina.utils.parser.xls.XLSParser; +import com.zebrunner.carina.utils.parser.xls.XLSTable; public class CellLinksIntegrationTest { private List headers; diff --git a/pom.xml b/pom.xml index f30448a5a2..e222b923f6 100644 --- a/pom.xml +++ b/pom.xml @@ -296,11 +296,6 @@ - - com.qaprosoft - carina-dataprovider - 1.0-SNAPSHOT - com.qaprosoft From 025feae861c91d2e083d72fded11056265a9f39e Mon Sep 17 00:00:00 2001 From: Andrei Kamarouski Date: Wed, 22 Mar 2023 15:27:47 +0300 Subject: [PATCH 24/52] refactor(carina-dataprovider): rename package to com.zebrunner --- carina-dataprovider/pom.xml | 6 ------ .../carina}/dataprovider/IAbstractDataProvider.java | 4 ++-- .../annotations/CsvDataSourceParameters.java | 2 +- .../annotations/XlsDataSourceParameters.java | 2 +- .../carina}/dataprovider/core/DataProviderFactory.java | 4 ++-- .../dataprovider/core/groupping/GroupByImpl.java | 2 +- .../core/groupping/exceptions/GroupByException.java | 2 +- .../dataprovider/core/impl/BaseDataProvider.java | 4 ++-- .../dataprovider/core/impl/CsvDataProvider.java | 10 +++++----- .../dataprovider/core/impl/XlsDataProvider.java | 6 +++--- .../carina}/dataprovider/parser/DSBean.java | 6 +++--- .../carina}/dataprovider/parser/csv/CSVParser.java | 4 ++-- .../carina}/dataprovider/parser/csv/CSVTable.java | 2 +- .../carina/utils}/parser/CellLinksIntegrationTest.java | 2 +- pom.xml | 6 ------ 15 files changed, 25 insertions(+), 37 deletions(-) rename carina-dataprovider/src/main/java/com/{qaprosoft/carina/core/foundation => zebrunner/carina}/dataprovider/IAbstractDataProvider.java (87%) rename carina-dataprovider/src/main/java/com/{qaprosoft/carina/core/foundation => zebrunner/carina}/dataprovider/annotations/CsvDataSourceParameters.java (98%) rename carina-dataprovider/src/main/java/com/{qaprosoft/carina/core/foundation => zebrunner/carina}/dataprovider/annotations/XlsDataSourceParameters.java (98%) rename carina-dataprovider/src/main/java/com/{qaprosoft/carina/core/foundation => zebrunner/carina}/dataprovider/core/DataProviderFactory.java (97%) rename carina-dataprovider/src/main/java/com/{qaprosoft/carina/core/foundation => zebrunner/carina}/dataprovider/core/groupping/GroupByImpl.java (97%) rename carina-dataprovider/src/main/java/com/{qaprosoft/carina/core/foundation => zebrunner/carina}/dataprovider/core/groupping/exceptions/GroupByException.java (94%) rename carina-dataprovider/src/main/java/com/{qaprosoft/carina/core/foundation => zebrunner/carina}/dataprovider/core/impl/BaseDataProvider.java (98%) rename carina-dataprovider/src/main/java/com/{qaprosoft/carina/core/foundation => zebrunner/carina}/dataprovider/core/impl/CsvDataProvider.java (86%) rename carina-dataprovider/src/main/java/com/{qaprosoft/carina/core/foundation => zebrunner/carina}/dataprovider/core/impl/XlsDataProvider.java (91%) rename carina-dataprovider/src/main/java/com/{qaprosoft/carina/core/foundation => zebrunner/carina}/dataprovider/parser/DSBean.java (96%) rename carina-dataprovider/src/main/java/com/{qaprosoft/carina/core/foundation => zebrunner/carina}/dataprovider/parser/csv/CSVParser.java (92%) rename carina-dataprovider/src/main/java/com/{qaprosoft/carina/core/foundation => zebrunner/carina}/dataprovider/parser/csv/CSVTable.java (95%) rename carina-dataprovider/src/test/java/com/{qaprosoft/carina/core/foundation => zebrunner/carina/utils}/parser/CellLinksIntegrationTest.java (98%) diff --git a/carina-dataprovider/pom.xml b/carina-dataprovider/pom.xml index 26a1b0b75d..807fa41f74 100644 --- a/carina-dataprovider/pom.xml +++ b/carina-dataprovider/pom.xml @@ -57,12 +57,6 @@ ${opencsv.version} - - - org.apache.poi - poi-ooxml - - org.apache.commons commons-lang3 diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/IAbstractDataProvider.java b/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/IAbstractDataProvider.java similarity index 87% rename from carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/IAbstractDataProvider.java rename to carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/IAbstractDataProvider.java index b1e55a22de..18b820220f 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/IAbstractDataProvider.java +++ b/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/IAbstractDataProvider.java @@ -1,6 +1,6 @@ -package com.qaprosoft.carina.core.foundation.dataprovider; +package com.zebrunner.carina.dataprovider; -import com.qaprosoft.carina.core.foundation.dataprovider.core.DataProviderFactory; +import com.zebrunner.carina.dataprovider.core.DataProviderFactory; import org.testng.ITestContext; import org.testng.ITestNGMethod; import org.testng.annotations.DataProvider; diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/CsvDataSourceParameters.java b/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/annotations/CsvDataSourceParameters.java similarity index 98% rename from carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/CsvDataSourceParameters.java rename to carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/annotations/CsvDataSourceParameters.java index eecc71d971..ae703df082 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/CsvDataSourceParameters.java +++ b/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/annotations/CsvDataSourceParameters.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ -package com.qaprosoft.carina.core.foundation.dataprovider.annotations; +package com.zebrunner.carina.dataprovider.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/XlsDataSourceParameters.java b/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/annotations/XlsDataSourceParameters.java similarity index 98% rename from carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/XlsDataSourceParameters.java rename to carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/annotations/XlsDataSourceParameters.java index b547500e3e..f9b8e4a7c2 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/annotations/XlsDataSourceParameters.java +++ b/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/annotations/XlsDataSourceParameters.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ -package com.qaprosoft.carina.core.foundation.dataprovider.annotations; +package com.zebrunner.carina.dataprovider.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java b/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/DataProviderFactory.java similarity index 97% rename from carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java rename to carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/DataProviderFactory.java index 0727ca7643..9cb90e35f2 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/DataProviderFactory.java +++ b/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/DataProviderFactory.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ -package com.qaprosoft.carina.core.foundation.dataprovider.core; +package com.zebrunner.carina.dataprovider.core; import java.lang.annotation.Annotation; import java.lang.invoke.MethodHandles; @@ -29,7 +29,7 @@ import org.testng.ITestContext; import org.testng.ITestNGMethod; -import com.qaprosoft.carina.core.foundation.dataprovider.core.impl.BaseDataProvider; +import com.zebrunner.carina.dataprovider.core.impl.BaseDataProvider; import com.zebrunner.carina.utils.commons.SpecialKeywords; /** diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/groupping/GroupByImpl.java b/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/groupping/GroupByImpl.java similarity index 97% rename from carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/groupping/GroupByImpl.java rename to carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/groupping/GroupByImpl.java index 8ee6b2fde0..91967b16a1 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/groupping/GroupByImpl.java +++ b/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/groupping/GroupByImpl.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ -package com.qaprosoft.carina.core.foundation.dataprovider.core.groupping; +package com.zebrunner.carina.dataprovider.core.groupping; import java.util.*; diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/groupping/exceptions/GroupByException.java b/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/groupping/exceptions/GroupByException.java similarity index 94% rename from carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/groupping/exceptions/GroupByException.java rename to carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/groupping/exceptions/GroupByException.java index f923d31cab..3c3c90eaec 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/groupping/exceptions/GroupByException.java +++ b/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/groupping/exceptions/GroupByException.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ -package com.qaprosoft.carina.core.foundation.dataprovider.core.groupping.exceptions; +package com.zebrunner.carina.dataprovider.core.groupping.exceptions; /** * Created by Patotsky on 08.01.2015. diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java b/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/impl/BaseDataProvider.java similarity index 98% rename from carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java rename to carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/impl/BaseDataProvider.java index 64a8cd0aa5..fd539642ab 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/BaseDataProvider.java +++ b/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/impl/BaseDataProvider.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ -package com.qaprosoft.carina.core.foundation.dataprovider.core.impl; +package com.zebrunner.carina.dataprovider.core.impl; import java.lang.annotation.Annotation; import java.util.ArrayList; @@ -24,10 +24,10 @@ import java.util.Map; import java.util.Set; +import com.zebrunner.carina.dataprovider.parser.DSBean; import org.testng.ITestContext; import org.testng.ITestNGMethod; -import com.qaprosoft.carina.core.foundation.dataprovider.parser.DSBean; import com.zebrunner.carina.utils.ParameterGenerator; import com.zebrunner.carina.utils.parser.xls.AbstractTable; diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java b/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/impl/CsvDataProvider.java similarity index 86% rename from carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java rename to carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/impl/CsvDataProvider.java index 7895a2a3cf..6b3903941e 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/CsvDataProvider.java +++ b/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/impl/CsvDataProvider.java @@ -13,12 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ -package com.qaprosoft.carina.core.foundation.dataprovider.core.impl; +package com.zebrunner.carina.dataprovider.core.impl; -import com.qaprosoft.carina.core.foundation.dataprovider.annotations.CsvDataSourceParameters; -import com.qaprosoft.carina.core.foundation.dataprovider.parser.DSBean; -import com.qaprosoft.carina.core.foundation.dataprovider.parser.csv.CSVParser; -import com.qaprosoft.carina.core.foundation.dataprovider.parser.csv.CSVTable; +import com.zebrunner.carina.dataprovider.annotations.CsvDataSourceParameters; +import com.zebrunner.carina.dataprovider.parser.DSBean; +import com.zebrunner.carina.dataprovider.parser.csv.CSVParser; +import com.zebrunner.carina.dataprovider.parser.csv.CSVTable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testng.ITestContext; diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java b/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/impl/XlsDataProvider.java similarity index 91% rename from carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java rename to carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/impl/XlsDataProvider.java index 5ecbfb4247..3f6b3ffe94 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/core/impl/XlsDataProvider.java +++ b/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/impl/XlsDataProvider.java @@ -13,17 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ -package com.qaprosoft.carina.core.foundation.dataprovider.core.impl; +package com.zebrunner.carina.dataprovider.core.impl; import java.lang.annotation.Annotation; import java.util.List; import java.util.Map; +import com.zebrunner.carina.dataprovider.annotations.XlsDataSourceParameters; +import com.zebrunner.carina.dataprovider.parser.DSBean; import org.testng.ITestContext; import org.testng.ITestNGMethod; -import com.qaprosoft.carina.core.foundation.dataprovider.annotations.XlsDataSourceParameters; -import com.qaprosoft.carina.core.foundation.dataprovider.parser.DSBean; import com.zebrunner.carina.utils.parser.xls.XLSParser; import com.zebrunner.carina.utils.parser.xls.XLSTable; diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/DSBean.java b/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/parser/DSBean.java similarity index 96% rename from carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/DSBean.java rename to carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/parser/DSBean.java index c73c17cb5d..db0dad4162 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/DSBean.java +++ b/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/parser/DSBean.java @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ -package com.qaprosoft.carina.core.foundation.dataprovider.parser; +package com.zebrunner.carina.dataprovider.parser; -import com.qaprosoft.carina.core.foundation.dataprovider.annotations.CsvDataSourceParameters; -import com.qaprosoft.carina.core.foundation.dataprovider.annotations.XlsDataSourceParameters; +import com.zebrunner.carina.dataprovider.annotations.CsvDataSourceParameters; +import com.zebrunner.carina.dataprovider.annotations.XlsDataSourceParameters; import com.zebrunner.carina.utils.commons.SpecialKeywords; import com.zebrunner.carina.utils.exception.InvalidArgsException; import org.testng.ITestContext; diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/csv/CSVParser.java b/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/parser/csv/CSVParser.java similarity index 92% rename from carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/csv/CSVParser.java rename to carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/parser/csv/CSVParser.java index 7f322858fe..a35c892444 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/csv/CSVParser.java +++ b/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/parser/csv/CSVParser.java @@ -1,7 +1,7 @@ -package com.qaprosoft.carina.core.foundation.dataprovider.parser.csv; +package com.zebrunner.carina.dataprovider.parser.csv; import au.com.bytecode.opencsv.CSVReader; -import com.qaprosoft.carina.core.foundation.dataprovider.parser.DSBean; +import com.zebrunner.carina.dataprovider.parser.DSBean; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/csv/CSVTable.java b/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/parser/csv/CSVTable.java similarity index 95% rename from carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/csv/CSVTable.java rename to carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/parser/csv/CSVTable.java index bab708f486..92f30236e9 100644 --- a/carina-dataprovider/src/main/java/com/qaprosoft/carina/core/foundation/dataprovider/parser/csv/CSVTable.java +++ b/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/parser/csv/CSVTable.java @@ -1,4 +1,4 @@ -package com.qaprosoft.carina.core.foundation.dataprovider.parser.csv; +package com.zebrunner.carina.dataprovider.parser.csv; import java.lang.invoke.MethodHandles; import java.util.HashMap; diff --git a/carina-dataprovider/src/test/java/com/qaprosoft/carina/core/foundation/parser/CellLinksIntegrationTest.java b/carina-dataprovider/src/test/java/com/zebrunner/carina/utils/parser/CellLinksIntegrationTest.java similarity index 98% rename from carina-dataprovider/src/test/java/com/qaprosoft/carina/core/foundation/parser/CellLinksIntegrationTest.java rename to carina-dataprovider/src/test/java/com/zebrunner/carina/utils/parser/CellLinksIntegrationTest.java index b12daf1222..ba49557b41 100644 --- a/carina-dataprovider/src/test/java/com/qaprosoft/carina/core/foundation/parser/CellLinksIntegrationTest.java +++ b/carina-dataprovider/src/test/java/com/zebrunner/carina/utils/parser/CellLinksIntegrationTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ -package com.qaprosoft.carina.core.foundation.parser; +package com.zebrunner.carina.utils.parser; import java.util.ArrayList; import java.util.List; diff --git a/pom.xml b/pom.xml index e222b923f6..6dfe46eb8a 100644 --- a/pom.xml +++ b/pom.xml @@ -48,7 +48,6 @@ 1.9.3 - 4.1.2 @@ -338,11 +337,6 @@ commons-lang3 ${commons-lang3.version} - - org.apache.poi - poi-ooxml - ${apache-poi.version} - From 00ac5bc2650ee1490d86ff3aaba01b2ce297d4b6 Mon Sep 17 00:00:00 2001 From: Andrei Kamarouski Date: Thu, 23 Mar 2023 10:38:35 +0300 Subject: [PATCH 25/52] refactor: remove carina-dataprovider module --- carina-dataprovider/pom.xml | 108 -------- .../dataprovider/IAbstractDataProvider.java | 25 -- .../annotations/CsvDataSourceParameters.java | 148 ----------- .../annotations/XlsDataSourceParameters.java | 149 ----------- .../core/DataProviderFactory.java | 152 ----------- .../core/groupping/GroupByImpl.java | 86 ------- .../exceptions/GroupByException.java | 44 ---- .../core/impl/BaseDataProvider.java | 235 ------------------ .../core/impl/CsvDataProvider.java | 65 ----- .../core/impl/XlsDataProvider.java | 60 ----- .../carina/dataprovider/parser/DSBean.java | 210 ---------------- .../dataprovider/parser/csv/CSVParser.java | 57 ----- .../dataprovider/parser/csv/CSVTable.java | 48 ---- .../java/CarinaDataproviderLoggerTest.java | 14 -- .../parser/CellLinksIntegrationTest.java | 141 ----------- .../src/test/resources/_config.properties | 2 - .../test/resources/xlsx_data/ChildTest.xlsx | Bin 9200 -> 0 bytes .../test/resources/xlsx_data/ParentTest.xlsx | Bin 11360 -> 0 bytes pom.xml | 1 - 19 files changed, 1545 deletions(-) delete mode 100644 carina-dataprovider/pom.xml delete mode 100644 carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/IAbstractDataProvider.java delete mode 100644 carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/annotations/CsvDataSourceParameters.java delete mode 100644 carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/annotations/XlsDataSourceParameters.java delete mode 100644 carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/DataProviderFactory.java delete mode 100644 carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/groupping/GroupByImpl.java delete mode 100644 carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/groupping/exceptions/GroupByException.java delete mode 100644 carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/impl/BaseDataProvider.java delete mode 100644 carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/impl/CsvDataProvider.java delete mode 100644 carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/impl/XlsDataProvider.java delete mode 100644 carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/parser/DSBean.java delete mode 100644 carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/parser/csv/CSVParser.java delete mode 100644 carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/parser/csv/CSVTable.java delete mode 100644 carina-dataprovider/src/test/java/CarinaDataproviderLoggerTest.java delete mode 100644 carina-dataprovider/src/test/java/com/zebrunner/carina/utils/parser/CellLinksIntegrationTest.java delete mode 100644 carina-dataprovider/src/test/resources/_config.properties delete mode 100644 carina-dataprovider/src/test/resources/xlsx_data/ChildTest.xlsx delete mode 100644 carina-dataprovider/src/test/resources/xlsx_data/ParentTest.xlsx diff --git a/carina-dataprovider/pom.xml b/carina-dataprovider/pom.xml deleted file mode 100644 index 807fa41f74..0000000000 --- a/carina-dataprovider/pom.xml +++ /dev/null @@ -1,108 +0,0 @@ - - - - 4.0.0 - carina-dataprovider - jar - - Carina DataProvider - Set of dataprovider carina utilities. - - - com.qaprosoft - carina - 1.0-SNAPSHOT - .. - - - - - UTF-8 - 1.0.3.P1-SNAPSHOT - 1.7 - - - - - zebrunner_snapshots - zebrunner Snapshots - https://nexus.zebrunner.dev/repository/ce-snapshots/ - - false - - - true - - - - - - - - com.zebrunner - carina-utils - ${carina-utils.version} - - - - org.slf4j - slf4j-api - - - - net.sf.opencsv - opencsv - ${opencsv.version} - - - - org.apache.commons - commons-lang3 - - - - - org.testng - testng - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${java.version} - - - - maven-assembly-plugin - - - jar-with-dependencies - - - - - org.apache.maven.plugins - maven-source-plugin - - - attach-sources - - jar - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - - - - - diff --git a/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/IAbstractDataProvider.java b/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/IAbstractDataProvider.java deleted file mode 100644 index 18b820220f..0000000000 --- a/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/IAbstractDataProvider.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.zebrunner.carina.dataprovider; - -import com.zebrunner.carina.dataprovider.core.DataProviderFactory; -import org.testng.ITestContext; -import org.testng.ITestNGMethod; -import org.testng.annotations.DataProvider; - -import java.lang.annotation.Annotation; - -public interface IAbstractDataProvider { - - @DataProvider(name = "DataProvider", parallel = true) - default Object[][] createData(final ITestNGMethod testMethod, ITestContext context) { - Annotation[] annotations = testMethod.getConstructorOrMethod().getMethod().getDeclaredAnnotations(); - Object[][] objects = DataProviderFactory.getDataProvider(annotations, context, testMethod); - return objects; - } - - @DataProvider(name = "SingleDataProvider") - default Object[][] createDataSingleThread(final ITestNGMethod testMethod, ITestContext context) { - Annotation[] annotations = testMethod.getConstructorOrMethod().getMethod().getDeclaredAnnotations(); - Object[][] objects = DataProviderFactory.getDataProvider(annotations, context, testMethod); - return objects; - } -} diff --git a/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/annotations/CsvDataSourceParameters.java b/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/annotations/CsvDataSourceParameters.java deleted file mode 100644 index ae703df082..0000000000 --- a/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/annotations/CsvDataSourceParameters.java +++ /dev/null @@ -1,148 +0,0 @@ -/******************************************************************************* - * Copyright 2020-2022 Zebrunner Inc (https://www.zebrunner.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *******************************************************************************/ -package com.zebrunner.carina.dataprovider.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -public @interface CsvDataSourceParameters { - /** - * Define data provider instance - * - * @return String - */ - String className() default "com.qaprosoft.carina.core.foundation.dataprovider.core.impl.CsvDataProvider"; - - /** - * Define column separator for parsing - * - * @return char - */ - char separator() default ','; - - /** - * The character to use for quoted elements when parsing - * - * @return char - */ - char quote() default '"'; - - /** - * Path to data source file - * - * @return String - */ - String path() default ""; - - /** - * Column names that need to be inserted into test from row. Several arguments should be split by ",". - * If empty, per row will be created hashMap with all data source columns as keys and row data as values. - * - * @return String - */ - String dsArgs() default ""; - - /** - * Column name with unique test identifiers. Several name arguments should be split by ",". - * - * @return String - */ - String dsUid() default ""; - - /** - * Column name which rows determines whether to execute test or not - * - * @return String - */ - String executeColumn() default "Execute"; - - /** - * Defines to execute test or not. - * If executeValue equalsIgnoreCase to value from executeColumn test will be added to run. - * - * @return String - */ - String executeValue() default "y"; - - /** - * Gets value from testNG suite by defined static arguments name. - * The same argument will present in every test - * - * @return String - */ - String staticArgs() default ""; - - /** - * Name of the column, by which will be performed grouping. - * If used, test will receive {@code ArrayList} argument, - * where data grouped by lists depending on groupColumn values. - * - * @return String - */ - String groupColumn() default ""; - - /** - * Column name, which contains values for test name overriding - * If used with groupColumn parameter, test will be overridden by first occurrence in group - * - * @return String - */ - String testMethodColumn() default ""; - - /** - * Reason: not implemented - * - * @return String - */ - @Deprecated(forRemoval = true, since = "1.0.0") - String testRailColumn() default ""; - - /** - * Reason: not implemented - * - * @return String - */ - @Deprecated(forRemoval = true, since = "1.0.0") - String qTestColumn() default ""; - - /** - * Reason: not implemented - * - * @return String - */ - @Deprecated(forRemoval = true, since = "1.0.0") - String testMethodOwnerColumn() default ""; - - /** - * Reason: not implemented - * - * @return String - */ - @Deprecated(forRemoval = true, since = "1.0.0") - String bugColumn() default ""; - - /** - * Reason: not implemented - * - * @return String[] - */ - @Deprecated(forRemoval = true, since = "1.0.0") - String[] doNotRunTestNames() default {}; -} \ No newline at end of file diff --git a/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/annotations/XlsDataSourceParameters.java b/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/annotations/XlsDataSourceParameters.java deleted file mode 100644 index f9b8e4a7c2..0000000000 --- a/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/annotations/XlsDataSourceParameters.java +++ /dev/null @@ -1,149 +0,0 @@ -/******************************************************************************* - * Copyright 2020-2022 Zebrunner Inc (https://www.zebrunner.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *******************************************************************************/ -package com.zebrunner.carina.dataprovider.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -public @interface XlsDataSourceParameters { - /** - * Define data provider instance - * - * @return String - */ - String className() default "com.qaprosoft.carina.core.foundation.dataprovider.core.impl.XlsDataProvider"; - - /** - * Is mutually exclusive with path - * - * @return String - */ - String spreadsheetId() default ""; - - /** - * Define data provider instance - * - * @return String - */ - String sheet() default ""; - - /** - * Path to data source file. - * Is mutually exclusive with spreadsheetId - * - * @return String - */ - String path() default ""; - - /** - * Column names that need to be inserted into test from row. Several arguments should be split by ",". - * If empty, per row will be created hashMap with all data source columns as keys and row data as values. - * - * @return String - */ - String dsArgs() default ""; - - /** - * Column name with unique test identifiers. Several name arguments should be split by ",". - * - * @return String - */ - String dsUid() default ""; - - /** - * Column name which rows determines whether to execute test or not - * - * @return String - */ - String executeColumn() default "Execute"; - - /** - * Defines to execute test or not. - * If executeValue equalsIgnoreCase to value from executeColumn test will be added to run. - * - * @return String - */ - String executeValue() default "y"; - - /** - * Gets value from testNG suite by defined static arguments name. - * The same argument will present in every test - * - * @return String - */ - String staticArgs() default ""; - - /** - * Name of the column, by which will be performed grouping. - * If used, test will receive {@literal ArrayList>} argument, - * where data grouped by lists depending on groupColumn values. - * - * @return String - */ - String groupColumn() default ""; - - /** - * Column name, which contains values for test name overriding - * If used with groupColumn parameter, test will be overridden by first occurrence in group - * - * @return String - */ - String testMethodColumn() default ""; - - /** - * Reason: not implemented - * - * @return String - */ - @Deprecated(forRemoval = true, since = "1.0.0") - String testRailColumn() default ""; - - /** - * Reason: not implemented - * - * @return String - */ - @Deprecated(forRemoval = true, since = "1.0.0") - String qTestColumn() default ""; - - /** - * Reason: not implemented - * - * @return String - */ - @Deprecated(forRemoval = true, since = "1.0.0") - String testMethodOwnerColumn() default ""; - - /** - * Reason: not implemented - * - * @return String - */ - @Deprecated(forRemoval = true, since = "1.0.0") - String bugColumn() default ""; - - /** - * Reason: not implemented - * - * @return String - */ - @Deprecated(forRemoval = true, since = "1.0.0") - String[] doNotRunTestNames() default {}; -} diff --git a/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/DataProviderFactory.java b/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/DataProviderFactory.java deleted file mode 100644 index 9cb90e35f2..0000000000 --- a/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/DataProviderFactory.java +++ /dev/null @@ -1,152 +0,0 @@ -/******************************************************************************* - * Copyright 2020-2022 Zebrunner Inc (https://www.zebrunner.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *******************************************************************************/ -package com.zebrunner.carina.dataprovider.core; - -import java.lang.annotation.Annotation; -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.lang3.ArrayUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.ITestContext; -import org.testng.ITestNGMethod; - -import com.zebrunner.carina.dataprovider.core.impl.BaseDataProvider; -import com.zebrunner.carina.utils.commons.SpecialKeywords; - -/** - * Created by Patotsky on 16.12.2014. - */ -public class DataProviderFactory { - private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - - private DataProviderFactory() {} - - /** - * Creates data provider from specified source in annotations. - * - * @param annotations test method annotations. For using carina's custom data provider - * test should be annotated with @CsvDataSourceParameters or @XlsDataSourceParameters - * @param context test context - * @param m current test method - * @return Object[][] provider from specified source, - * where provider.length shows number of test to be invoked - * and provider[i][] contains test invocation args for each i test - */ - public static Object[][] getDataProvider(Annotation[] annotations, ITestContext context, ITestNGMethod m) { - Map tuidMap = Collections.synchronizedMap(new HashMap<>()); - Map testNameMap = Collections.synchronizedMap(new HashMap<>()); - - Object[][] provider = new Object[][]{}; - - for (Annotation annotation : annotations) { - String providerClass = findProviderClass(annotation); - if (providerClass.isEmpty()) { - continue; - } - - Object providerObject = initDataProvider(providerClass); - - if (providerObject instanceof BaseDataProvider) { - BaseDataProvider dataProvider = (BaseDataProvider) providerObject; - provider = ArrayUtils.addAll(provider, dataProvider.getDataProvider(annotation, context, m)); - - tuidMap.putAll(dataProvider.getTuidMap()); - testNameMap.putAll(dataProvider.getTestColumnNamesMap()); - } - } - - putValuesToContext(context, tuidMap, testNameMap); - - return provider; - } - - /** - * Put data from test parameters to test's context. Necessary for correct test naming. - * - * @param context ITestContext. - * @param tuidMap contains tuid values for each test (if present) - * @param testNameFromColumn contains values for overriding test names from specified column - */ - private static synchronized void putValuesToContext(ITestContext context, - Map tuidMap, - Map testNameFromColumn) { - @SuppressWarnings("unchecked") - Map contextTUID = (Map) context.getAttribute(SpecialKeywords.TUID); - if (contextTUID != null) { - contextTUID.putAll(tuidMap); - } else { - context.setAttribute(SpecialKeywords.TUID, tuidMap); - } - - @SuppressWarnings("unchecked") - Map contextTestName = (Map) context.getAttribute(SpecialKeywords.TEST_NAME); - if (contextTestName != null) { - contextTestName.putAll(testNameFromColumn); - } else { - context.setAttribute(SpecialKeywords.TEST_NAME, testNameFromColumn); - } - } - - /** - * Finds class name for data provider implementation. - * - * @param annotation test method annotation - * @return String class name of data provider if it was found in annotation classname() method. Empty if not - */ - private static String findProviderClass(Annotation annotation) { - Class type = annotation.annotationType(); - String providerClass = ""; - - try { - for (Method method : type.getDeclaredMethods()) { - if (method.getName().equalsIgnoreCase("classname")) { - providerClass = (String) method.invoke(annotation); - break; - } - } - } catch (ReflectiveOperationException e) { - LOGGER.error("Failure on finding DataProvider class instance", e); - } - - return providerClass; - } - - /** - * Initialize DataProvider based on className parameter. - * - * @param providerClass String full className - * @return Object DataProvider Instance - */ - private static Object initDataProvider(String providerClass) { - Class clazz; - Object dataProvider = null; - try { - clazz = Class.forName(providerClass); - Constructor ctor = clazz.getConstructor(); - dataProvider = ctor.newInstance(); - } catch (Exception e) { - LOGGER.error("DataProvider initialization failure", e); - } - - return dataProvider; - } -} diff --git a/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/groupping/GroupByImpl.java b/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/groupping/GroupByImpl.java deleted file mode 100644 index 91967b16a1..0000000000 --- a/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/groupping/GroupByImpl.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * Copyright 2020-2022 Zebrunner Inc (https://www.zebrunner.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *******************************************************************************/ -package com.zebrunner.carina.dataprovider.core.groupping; - -import java.util.*; - -/** - * Created by Patotsky on 29.12.2014. - */ - -@Deprecated(forRemoval = true, since = "1.0.0") -public class GroupByImpl { - - public static Object[][] getGroupedDataProviderArgs(Object[][] objects, int fieldNumber) { - //add unique group values - Set groupValues = new LinkedHashSet<>(); - for (Object[] item : objects) { - String value = (String) item[fieldNumber]; - groupValues.add(value); - } - - //group maps into lists, that has the same unique group value - List> groupedList = new ArrayList<>(); - for (String groupBy: groupValues) { - List groupOfRows = new ArrayList<>(); - for (Object[] object : objects) { - String value = (String) object[fieldNumber]; - if (value.equals(groupBy)) { - groupOfRows.add(object); - } - } - groupedList.add(groupOfRows); - } - - //cast List> to Object[][] - Object[][] finalObject = new Object[groupedList.size()][1]; - for (int i = 0; i < groupedList.size(); i++) { - finalObject[i][0] = groupedList.get(i); - } - - return finalObject; - } - - public static Object[][] getGroupedDataProviderMap(Object[][] objects, String fieldName) { - //add unique group values - Set groupValues = new LinkedHashSet<>(); - for (Object[] item : objects) { - String value = ((Map) item[0]).get(fieldName); - groupValues.add(value); - } - - //group maps into lists, that has the same unique group value - List>> groupedList = new ArrayList<>(); - for (String groupBy: groupValues) { - List> groupOfRows = new ArrayList<>(); - for (Object[] item : objects) { - String value = ((Map) item[0]).get(fieldName); - if (value.equals(groupBy)) { - groupOfRows.add((Map) item[0]); - } - } - groupedList.add(groupOfRows); - } - - //cast List> to Object[][] - Object[][] finalObject = new Object[groupedList.size()][1]; - for (int i = 0; i < groupedList.size(); i++) { - finalObject[i][0] = groupedList.get(i); - } - - return finalObject; - } -} diff --git a/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/groupping/exceptions/GroupByException.java b/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/groupping/exceptions/GroupByException.java deleted file mode 100644 index 3c3c90eaec..0000000000 --- a/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/groupping/exceptions/GroupByException.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright 2020-2022 Zebrunner Inc (https://www.zebrunner.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *******************************************************************************/ -package com.zebrunner.carina.dataprovider.core.groupping.exceptions; - -/** - * Created by Patotsky on 08.01.2015. - */ - -@Deprecated(forRemoval = true, since = "1.0.0") -@SuppressWarnings("serial") -public class GroupByException extends RuntimeException { - - public GroupByException() { - } - - public GroupByException(String message) { - super(message); - } - - public GroupByException(String message, Throwable cause) { - super(message, cause); - } - - public GroupByException(Throwable cause) { - super(cause); - } - - public GroupByException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { - super(message, cause, enableSuppression, writableStackTrace); - } -} diff --git a/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/impl/BaseDataProvider.java b/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/impl/BaseDataProvider.java deleted file mode 100644 index fd539642ab..0000000000 --- a/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/impl/BaseDataProvider.java +++ /dev/null @@ -1,235 +0,0 @@ -/******************************************************************************* - * Copyright 2020-2022 Zebrunner Inc (https://www.zebrunner.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *******************************************************************************/ -package com.zebrunner.carina.dataprovider.core.impl; - -import java.lang.annotation.Annotation; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import com.zebrunner.carina.dataprovider.parser.DSBean; -import org.testng.ITestContext; -import org.testng.ITestNGMethod; - -import com.zebrunner.carina.utils.ParameterGenerator; -import com.zebrunner.carina.utils.parser.xls.AbstractTable; - -/** - * Created by Patotsky on 19.12.2014. - */ - -public abstract class BaseDataProvider { - protected Map tuidMap = Collections.synchronizedMap(new HashMap<>()); - protected Map testColumnNamesMap = Collections.synchronizedMap(new HashMap<>()); - - public abstract Object[][] getDataProvider(Annotation annotation, ITestContext context, ITestNGMethod testMethod); - - protected void addValueToMap(Map map, String hashCode, String value) { - if (!value.isEmpty()) { - map.put(hashCode, value); - } - } - - /** - * Generate dataProvider based on grouped data rows - * - * @param groupedList grouped data rows - * @param dsBean DSBean test parameters bean - * @param testMethod ITestNGMethod current test method - * @return Object[][] grouped data provider, where object[i][0] contains {@code ArrayList>} - */ - public Object[][] createGroupedDataProvider(List>> groupedList, DSBean dsBean, ITestNGMethod testMethod) { - Object[][] dataProvider = declareDataProviderArray(groupedList, dsBean); - - if (dsBean.getArgs().isEmpty()) { - fillArgsAsMap(dataProvider, groupedList, dsBean); - } else { - fillArgsAsGroupedMap(dataProvider, groupedList, dsBean); - } - - configureTestNamingVarsForGroupedProvider(dataProvider, dsBean, groupedList, testMethod); - return dataProvider; - } - - /** - * Generate dataProvider based on data source rows - * - * @param table AbstractTable contains parsed from data source data rows - * @param dsBean DSBean test parameters bean - * @param testMethod ITestNGMethod current test method - * @return Object[][] grouped data provider - */ - public Object[][] createDataProvider(AbstractTable table, DSBean dsBean, ITestNGMethod testMethod) { - Object[][] dataProvider = declareDataProviderArray(table.getDataRows(), dsBean); - - if (dsBean.isArgsToMap()) { - fillArgsAsMap(dataProvider, table.getDataRows(), dsBean); - } else { - fillArgsAsArray(dataProvider, table, dsBean); - } - - configureTestNamingVars(dataProvider, dsBean, table, testMethod); - - return dataProvider; - } - - private void fillArgsAsGroupedMap(Object[][] dataProvider, List>> groupedList, DSBean dsBean) { - //selecting only specified in test parameters args from whole dataRow into new grouped list - List argsToPass = dsBean.getArgs(); - for (int rowIndex = 0; rowIndex < groupedList.size(); rowIndex++) { - List> listToPass = new ArrayList<>(); - for (Map groupedMap : groupedList.get(rowIndex)) { - Map mapToPass = new HashMap<>(); - for (String argName : argsToPass) { - mapToPass.put(argName, groupedMap.get(argName)); - } - listToPass.add(mapToPass); - } - - //creating grouped data provider with specified args - dataProvider[rowIndex][0] = listToPass; - - for (int staticArgsColumn = 0; staticArgsColumn < dsBean.getStaticArgs().size(); staticArgsColumn++) { - String staticArgName = dsBean.getStaticArgs().get(staticArgsColumn); - dataProvider[rowIndex][staticArgsColumn + 1] = getStaticParam(staticArgName, dsBean); - } - } - } - - private void fillArgsAsMap(Object[][] dataProvider, List dataRows, DSBean dsBean) { - for (int rowIndex = 0; rowIndex < dataProvider.length; rowIndex++) { - // populate arguments by parameters from data source - dataProvider[rowIndex][0] = dataRows.get(rowIndex); - - // populate the rest of arguments by static parameters from testParams - for (int staticArgsColumn = 0; staticArgsColumn < dsBean.getStaticArgs().size(); staticArgsColumn++) { - String staticArgName = dsBean.getStaticArgs().get(staticArgsColumn); - dataProvider[rowIndex][staticArgsColumn + 1] = getStaticParam(staticArgName, dsBean); - } - } - } - - private void fillArgsAsArray(Object[][] dataProvider, AbstractTable table, DSBean dsBean) { - for (int rowIndex = 0; rowIndex < dataProvider.length; rowIndex++) { - Map row = table.getDataRows().get(rowIndex); - - // populate arguments by parameters from data source - for (int argsColumn = 0; argsColumn < dsBean.getArgs().size(); argsColumn++) { - dataProvider[rowIndex][argsColumn] = row.get(dsBean.getArgs().get(argsColumn)); - } - - // populate the rest of arguments by static parameters from testParams - for (int staticArgsColumn = 0; staticArgsColumn < dsBean.getStaticArgs().size(); staticArgsColumn++) { - String staticArgName = dsBean.getStaticArgs().get(staticArgsColumn); - dataProvider[rowIndex][staticArgsColumn + row.entrySet().size()] = getStaticParam(staticArgName, dsBean); - } - } - } - - private Object[][] declareDataProviderArray(List dataRows, DSBean dsBean) { - int numberOfRowsToExecute = dataRows.size(); - - int numberOfArgsInTest; - if (dsBean.isArgsToMap()) { - // first element is dynamic HashMap - numberOfArgsInTest = 1 + dsBean.getStaticArgs().size(); - } else { - numberOfArgsInTest = dsBean.getArgs().size() + dsBean.getStaticArgs().size(); - } - - return new Object[numberOfRowsToExecute][numberOfArgsInTest]; - } - - private void configureTestNamingVars(Object[][] dataProvider, DSBean dsBean, AbstractTable table, ITestNGMethod testNGMethod) { - for (int rowIndex = 0; rowIndex < dataProvider.length; rowIndex++) { - Map row = table.getDataRows().get(rowIndex); - - String rowHash = ParameterGenerator.hash(dataProvider[rowIndex], testNGMethod); - addValueToMap(tuidMap, rowHash, getValueFromRow(row, dsBean.getUidArgs())); - addValueToMap(testColumnNamesMap, rowHash, getValueFromRow(row, List.of(dsBean.getTestMethodColumn()))); - } - } - - private void configureTestNamingVarsForGroupedProvider(Object[][] dataProvider, - DSBean dsBean, - List>> groupedList, - ITestNGMethod testNGMethod) { - for (int rowIndex = 0; rowIndex < dataProvider.length; rowIndex++) { - - String rowHash = ParameterGenerator.hash(dataProvider[rowIndex], testNGMethod); - - //get all unique tuid values from certain group - String testUid = getValueFromGroupList(rowIndex, groupedList, dsBean.getUidArgs()); - addValueToMap(tuidMap, rowHash, testUid); - - //get only first test name occurrence in group - String testName = getValueFromGroupList(rowIndex, groupedList, List.of(dsBean.getTestMethodColumn())); - testName = testName.split(",")[0]; - addValueToMap(testColumnNamesMap, rowHash, testName); - } - } - - private String getValueFromGroupList(int rowIndex, List>> groupedList, List columnNames) { - Set values = new LinkedHashSet<>(); - List> dataRowList = groupedList.get(rowIndex); - - for (Map dataMap : dataRowList) { - values.add(getValueFromRow(dataMap, columnNames)); - } - - StringBuilder valueRes = new StringBuilder(String.join(",", values)); - if (valueRes.indexOf(",") != -1) { - valueRes.replace(valueRes.length() - 1, valueRes.length(), ""); - } - return valueRes.toString(); - } - - private String getValueFromRow(Map row, List columnNames) { - StringBuilder valueRes = new StringBuilder(); - - for (String key : columnNames) { - if (!key.isEmpty() && row.containsKey(key)) { - String value = row.get(key); - if (value != null && !value.isEmpty()) { - valueRes.append(value); - valueRes.append(","); - } - } - } - - if (valueRes.indexOf(",") != -1) { - valueRes.replace(valueRes.length() - 1, valueRes.length(), ""); - } - return valueRes.toString(); - } - - protected static Object getStaticParam(String name, DSBean dsBean) { - //get value from suite by name - return ParameterGenerator.process(dsBean.getTestParams().get(name)); - } - - public Map getTestColumnNamesMap() { - return testColumnNamesMap; - } - - public Map getTuidMap() { - return tuidMap; - } -} diff --git a/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/impl/CsvDataProvider.java b/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/impl/CsvDataProvider.java deleted file mode 100644 index 6b3903941e..0000000000 --- a/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/impl/CsvDataProvider.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright 2020-2022 Zebrunner Inc (https://www.zebrunner.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *******************************************************************************/ -package com.zebrunner.carina.dataprovider.core.impl; - -import com.zebrunner.carina.dataprovider.annotations.CsvDataSourceParameters; -import com.zebrunner.carina.dataprovider.parser.DSBean; -import com.zebrunner.carina.dataprovider.parser.csv.CSVParser; -import com.zebrunner.carina.dataprovider.parser.csv.CSVTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.ITestContext; -import org.testng.ITestNGMethod; - -import java.lang.annotation.Annotation; -import java.lang.invoke.MethodHandles; -import java.util.List; -import java.util.Map; - -/** - * Created by Patotsky on 16.12.2014. - */ -public class CsvDataProvider extends BaseDataProvider { - private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - - /** - * Create data provider for test based on csv data source, suite and annotation parameters - * - * @param annotation Annotation csv data source parameters - * @param context ITestContext suite data source parameters - * @param testMethod ITestNGMethod current test method - * @return Object[][] dataProvider - */ - @SuppressWarnings("unchecked") - @Override - public Object[][] getDataProvider(Annotation annotation, ITestContext context, ITestNGMethod testMethod) { - CsvDataSourceParameters parameters = (CsvDataSourceParameters) annotation; - DSBean dsBean = new DSBean(parameters, context.getCurrentXmlTest().getAllParameters()); - - CSVTable csvTable = CSVParser.parseCsvFile(dsBean, parameters.separator(), parameters.quote()); - csvTable.excludeEntriesForNonExecution(); - csvTable.processTable(); - - String groupColumn = dsBean.getGroupColumn(); - if (groupColumn.isEmpty()) { - return createDataProvider(csvTable, dsBean, testMethod); - } else { - List>> groupedList = csvTable.getGroupedDataProviderMap(groupColumn); - dsBean.setArgsToMap(true); - return createGroupedDataProvider(groupedList, dsBean, testMethod); - } - } -} diff --git a/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/impl/XlsDataProvider.java b/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/impl/XlsDataProvider.java deleted file mode 100644 index 3f6b3ffe94..0000000000 --- a/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/core/impl/XlsDataProvider.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright 2020-2022 Zebrunner Inc (https://www.zebrunner.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *******************************************************************************/ -package com.zebrunner.carina.dataprovider.core.impl; - -import java.lang.annotation.Annotation; -import java.util.List; -import java.util.Map; - -import com.zebrunner.carina.dataprovider.annotations.XlsDataSourceParameters; -import com.zebrunner.carina.dataprovider.parser.DSBean; -import org.testng.ITestContext; -import org.testng.ITestNGMethod; - -import com.zebrunner.carina.utils.parser.xls.XLSParser; -import com.zebrunner.carina.utils.parser.xls.XLSTable; - -/** - * Created by Patotsky on 16.12.2014. - */ -public class XlsDataProvider extends BaseDataProvider { - - /** - * Create data provider for test based on xls data source, suite and annotation parameters - * - * @param annotation Annotation xls data source parameters - * @param context ITestContext suite data source parameters - * @param testMethod ITestNGMethod current test method - * @return Object[][] dataProvider - */ - @Override - public Object[][] getDataProvider(Annotation annotation, ITestContext context, ITestNGMethod testMethod) { - XlsDataSourceParameters parameters = (XlsDataSourceParameters) annotation; - DSBean dsBean = new DSBean(parameters, context.getCurrentXmlTest().getAllParameters()); - - XLSTable xlsTable = XLSParser.parseSpreadSheet(dsBean.getDsFile(), dsBean.getXlsSheet(), dsBean.getExecuteColumn(), dsBean.getExecuteValue()); - xlsTable.processTable(); - - String groupColumn = dsBean.getGroupColumn(); - if (groupColumn.isEmpty()) { - return createDataProvider(xlsTable, dsBean, testMethod); - } else { - List>> groupedList = xlsTable.getGroupedDataProviderMap(groupColumn); - dsBean.setArgsToMap(true); - return createGroupedDataProvider(groupedList, dsBean, testMethod); - } - } -} diff --git a/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/parser/DSBean.java b/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/parser/DSBean.java deleted file mode 100644 index db0dad4162..0000000000 --- a/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/parser/DSBean.java +++ /dev/null @@ -1,210 +0,0 @@ -/******************************************************************************* - * Copyright 2020-2022 Zebrunner Inc (https://www.zebrunner.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *******************************************************************************/ -package com.zebrunner.carina.dataprovider.parser; - -import com.zebrunner.carina.dataprovider.annotations.CsvDataSourceParameters; -import com.zebrunner.carina.dataprovider.annotations.XlsDataSourceParameters; -import com.zebrunner.carina.utils.commons.SpecialKeywords; -import com.zebrunner.carina.utils.exception.InvalidArgsException; -import org.testng.ITestContext; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -public class DSBean { - private Map testParams; - private List args = new ArrayList<>(); - private List uidArgs = new ArrayList<>(); - private List staticArgs = new ArrayList<>(); - - private String dsFile; - private String xlsSheet; - private String executeColumn; - private String executeValue; - private boolean spreadsheet; - private String groupColumn; - private String testMethodColumn; - private boolean argsToMap; - - public DSBean(ITestContext context) { - initParamsFromSuite(context.getCurrentXmlTest().getAllParameters(), "excel"); - this.argsToMap = this.args.size() == 0; - } - - public DSBean(XlsDataSourceParameters xlsDataSourceParameters, Map suiteParams) { - // params initialize order: 1) from test annotation 2) from suite - if (xlsDataSourceParameters != null) { - this.initParamsFromAnnotation(xlsDataSourceParameters); - if (!xlsDataSourceParameters.sheet().isEmpty()) { - xlsSheet = xlsDataSourceParameters.sheet(); - } - } - - if (!suiteParams.isEmpty()) { - initParamsFromSuite(suiteParams, "excel"); - if (suiteParams.get(SpecialKeywords.EXCEL_DS_SHEET) != null) { - this.xlsSheet = suiteParams.get(SpecialKeywords.EXCEL_DS_SHEET); - } - } - - if (xlsDataSourceParameters != null && !xlsDataSourceParameters.spreadsheetId().isEmpty()) { - if (!this.dsFile.isEmpty()) { - throw new InvalidArgsException("Spreadsheet id and path parameters are mutually exclusive"); - } else { - this.dsFile = xlsDataSourceParameters.spreadsheetId(); - this.spreadsheet = true; - } - } - - this.testParams = suiteParams; - this.argsToMap = this.args.size() == 0; - } - - public DSBean(CsvDataSourceParameters csvDataSourceParameters, Map suiteParams) { - // params initialize order: 1) from test annotation 2) from suite - if (csvDataSourceParameters != null) { - this.initParamsFromAnnotation(csvDataSourceParameters); - } - - if (!suiteParams.isEmpty()) { - initParamsFromSuite(suiteParams, ""); - } - this.testParams = suiteParams; - this.xlsSheet = null; - this.argsToMap = this.args.size() == 0; - } - - private void initParamsFromAnnotation(XlsDataSourceParameters parameters) { - // initialize default xls data source parameters from annotation - this.dsFile = parameters.path(); - this.executeColumn = parameters.executeColumn(); - this.executeValue = parameters.executeValue(); - this.groupColumn = parameters.groupColumn(); - this.testMethodColumn = parameters.testMethodColumn(); - - if (!parameters.dsArgs().isEmpty()) { - this.args = Arrays.asList(parameters.dsArgs().replace(" ", "").split(",")); - } - if (!parameters.dsUid().isEmpty()) { - this.uidArgs = Arrays.asList(parameters.dsUid().replace(" ", "").split(",")); - } - if (!parameters.staticArgs().isEmpty()) { - this.staticArgs = Arrays.asList(parameters.staticArgs().replace(" ", "").split(",")); - } - - } - - private void initParamsFromAnnotation(CsvDataSourceParameters parameters) { - // initialize default xls data source parameters from annotation - this.dsFile = parameters.path(); - this.executeColumn = parameters.executeColumn(); - this.executeValue = parameters.executeValue(); - this.groupColumn = parameters.groupColumn(); - this.testMethodColumn = parameters.testMethodColumn(); - - if (!parameters.dsArgs().isEmpty()) { - this.args = Arrays.asList(parameters.dsArgs().replace(" ", "").split(",")); - } - if (!parameters.dsUid().isEmpty()) { - this.uidArgs = Arrays.asList(parameters.dsUid().replace(" ", "").split(",")); - } - if (!parameters.staticArgs().isEmpty()) { - this.staticArgs = Arrays.asList(parameters.staticArgs().replace(" ", "").split(",")); - } - } - - private void initParamsFromSuite(Map suiteParams, String specialKeyPrefix) { - // initialize data source parameters from suite xml file - if (suiteParams.get(insert(SpecialKeywords.DS_FILE, specialKeyPrefix)) != null) { - this.dsFile = suiteParams.get(insert(SpecialKeywords.DS_FILE, specialKeyPrefix)); - } - if (suiteParams.get(SpecialKeywords.DS_EXECUTE_COLUMN) != null) { - this.executeColumn = suiteParams.get(SpecialKeywords.DS_EXECUTE_COLUMN); - } - if (suiteParams.get(SpecialKeywords.DS_EXECUTE_VALUE) != null) { - this.executeValue = suiteParams.get(SpecialKeywords.DS_EXECUTE_VALUE); - } - - String dsArgs = suiteParams.get(insert(SpecialKeywords.DS_ARGS, specialKeyPrefix)); - if (dsArgs != null && !dsArgs.isEmpty()) { - this.args = Arrays.asList(dsArgs.replace(" ", "").split(",")); - } - String dsUid = suiteParams.get(insert(SpecialKeywords.DS_UID, specialKeyPrefix)); - if (dsUid != null && !dsUid.isEmpty()) { - this.uidArgs = Arrays.asList(dsUid.replace(" ", "").split(",")); - } - } - - private String insert(String into, String insertion) { - StringBuilder newString = new StringBuilder(into); - newString.insert(1, insertion); - return newString.toString(); - } - - public Map getTestParams() { - return testParams; - } - - public List getArgs() { - return args; - } - - public List getUidArgs() { - return uidArgs; - } - - public List getStaticArgs() { - return staticArgs; - } - - public String getDsFile() { - return dsFile; - } - - public String getXlsSheet() { - return xlsSheet; - } - - public String getGroupColumn() { - return groupColumn; - } - - public String getTestMethodColumn() { - return testMethodColumn; - } - - public boolean isSpreadsheet() { - return spreadsheet; - } - - public String getExecuteColumn() { - return executeColumn; - } - - public String getExecuteValue() { - return executeValue; - } - - public boolean isArgsToMap() { - return argsToMap; - } - - public void setArgsToMap(boolean argsToMap) { - this.argsToMap = argsToMap; - } -} diff --git a/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/parser/csv/CSVParser.java b/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/parser/csv/CSVParser.java deleted file mode 100644 index a35c892444..0000000000 --- a/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/parser/csv/CSVParser.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.zebrunner.carina.dataprovider.parser.csv; - -import au.com.bytecode.opencsv.CSVReader; -import com.zebrunner.carina.dataprovider.parser.DSBean; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.FileReader; -import java.io.IOException; -import java.lang.invoke.MethodHandles; -import java.util.*; - -public class CSVParser { - private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - - public static CSVTable parseCsvFile(DSBean dsBean, char separator, char quote) { - CSVTable csvTable = new CSVTable(dsBean.getExecuteColumn(), dsBean.getExecuteValue()); - - List data = readData(dsBean, separator, quote); - if (data.size() == 0) { - throw new RuntimeException("Unable to retrieve data from CSV DataProvider! Verify separator and quote settings."); - } - - csvTable.setHeaders(Arrays.asList(data.get(0))); - - mapData(csvTable, data); - - return csvTable; - } - - @SuppressWarnings("unchecked") - private static List readData(DSBean dsBean, char separator, char quote) { - CSVReader reader = null; - List list = new ArrayList<>(); - try { - String csvFile = ClassLoader.getSystemResource(dsBean.getDsFile()).getFile(); - reader = new CSVReader(new FileReader(csvFile), separator, quote); - list = reader.readAll(); - } catch (IOException e) { - LOGGER.error("Unable to read data from CSV DataProvider", e); - } finally { - try { - assert reader != null; - reader.close(); - } catch (IOException e) { - LOGGER.error("Unable to close CSV Reader", e); - } - } - return list; - } - - private static void mapData(CSVTable table, List data) { - for (int i = 1; i < data.size(); i ++) { - table.addDataRow(List.of(data.get(i))); - } - } -} diff --git a/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/parser/csv/CSVTable.java b/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/parser/csv/CSVTable.java deleted file mode 100644 index 92f30236e9..0000000000 --- a/carina-dataprovider/src/main/java/com/zebrunner/carina/dataprovider/parser/csv/CSVTable.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.zebrunner.carina.dataprovider.parser.csv; - -import java.lang.invoke.MethodHandles; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.zebrunner.carina.utils.parser.xls.AbstractTable; - -public class CSVTable extends AbstractTable { - private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - - public CSVTable() { - super(); - } - - public CSVTable(String executeColumn, String executeValue) { - super(executeColumn, executeValue); - } - - @Override - public void addDataRow(List row) { - if (row.size() == headers.size()) { - Map rowMap = new HashMap<>(); - for (int i = 0; i < headers.size(); i++) { - rowMap.put(headers.get(i), row.get(i)); - } - if (!rowMap.isEmpty()) { - dataRows.add(rowMap); - } - } else { - LOGGER.error("Headers size and row size didn't match, can't add data to table"); - } - } - - public void excludeEntriesForNonExecution() { - for (int i = 0; i < dataRows.size(); i++) { - Map row = dataRows.get(i); - if (!row.get(executeColumn).equalsIgnoreCase(executeValue)) { - dataRows.remove(i); - i--; - } - } - } -} diff --git a/carina-dataprovider/src/test/java/CarinaDataproviderLoggerTest.java b/carina-dataprovider/src/test/java/CarinaDataproviderLoggerTest.java deleted file mode 100644 index e4ec528833..0000000000 --- a/carina-dataprovider/src/test/java/CarinaDataproviderLoggerTest.java +++ /dev/null @@ -1,14 +0,0 @@ -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.annotations.Test; - -import java.lang.invoke.MethodHandles; - -public class CarinaDataproviderLoggerTest { - private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - - @Test - public void testReportingAppender(){ - LOGGER.info("logger test"); - } -} diff --git a/carina-dataprovider/src/test/java/com/zebrunner/carina/utils/parser/CellLinksIntegrationTest.java b/carina-dataprovider/src/test/java/com/zebrunner/carina/utils/parser/CellLinksIntegrationTest.java deleted file mode 100644 index ba49557b41..0000000000 --- a/carina-dataprovider/src/test/java/com/zebrunner/carina/utils/parser/CellLinksIntegrationTest.java +++ /dev/null @@ -1,141 +0,0 @@ -/******************************************************************************* - * Copyright 2020-2022 Zebrunner Inc (https://www.zebrunner.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *******************************************************************************/ -package com.zebrunner.carina.utils.parser; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import org.testng.Assert; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; - -import com.zebrunner.carina.utils.parser.xls.XLSParser; -import com.zebrunner.carina.utils.parser.xls.XLSTable; - -public class CellLinksIntegrationTest { - private List headers; - private List firstRow; - private List secondRow; - private List thirdRow; - private List fourthRow; - private List fifsRow; - private List sixthRow; - - @BeforeTest - public void setUp() { - headers = new ArrayList(); - headers.add("Header1"); - headers.add("FK_LINK_HEADER_2"); - headers.add("Header3"); - headers.add("Header7"); - headers.add("Header8"); - headers.add("Header9"); - headers.add("Header4"); - headers.add("Header5"); - headers.add("Header6"); - - firstRow = new ArrayList(); - firstRow.add("Data1"); - firstRow.add(null); - firstRow.add("Data3"); - firstRow.add("Data7"); - firstRow.add("Data8"); - firstRow.add("Data9"); - firstRow.add(null); - firstRow.add(null); - firstRow.add(null); - - secondRow = new ArrayList(); - secondRow.add("Name1"); - secondRow.add(null); - secondRow.add("Name3"); - secondRow.add("User7"); - secondRow.add("User8"); - secondRow.add("User9"); - secondRow.add(null); - secondRow.add(null); - secondRow.add(null); - - thirdRow = new ArrayList(); - thirdRow.add("User1"); - thirdRow.add(null); - thirdRow.add("User3"); - thirdRow.add(""); - thirdRow.add(""); - thirdRow.add(""); - thirdRow.add("User4"); - thirdRow.add("User5"); - thirdRow.add("User6"); - - fourthRow = new ArrayList(); - fourthRow.add("Temp1"); - fourthRow.add("Data5"); - fourthRow.add("Temp3"); - fourthRow.add(""); - fourthRow.add(""); - fourthRow.add(""); - fourthRow.add("Data4"); - fourthRow.add("Data5"); - fourthRow.add("Data6"); - - fifsRow = new ArrayList(); - fifsRow.add("About1"); - fifsRow.add("Data1"); - fifsRow.add("About3"); - fifsRow.add(""); - fifsRow.add(""); - fifsRow.add(""); - fifsRow.add(""); - fifsRow.add(""); - fifsRow.add(""); - - sixthRow = new ArrayList(); - sixthRow.add("New1"); - sixthRow.add("New2"); - sixthRow.add("New3"); - sixthRow.add(""); - sixthRow.add(""); - sixthRow.add(""); - sixthRow.add(""); - sixthRow.add(""); - sixthRow.add(""); - } - - @Test - public void testCellLinksForCurrentWB() { - XLSTable table = XLSParser.parseSpreadSheet("xlsx_data/ParentTest.xlsx", "Sheet1"); - verifyHeaders(table.getHeaders()); - verifyDataRow(firstRow, table.getHeaders(), table.getDataRows().get(0)); - verifyDataRow(secondRow, table.getHeaders(), table.getDataRows().get(1)); - verifyDataRow(thirdRow, table.getHeaders(), table.getDataRows().get(2)); - verifyDataRow(fourthRow, table.getHeaders(), table.getDataRows().get(3)); - verifyDataRow(fifsRow, table.getHeaders(), table.getDataRows().get(4)); - verifyDataRow(sixthRow, table.getHeaders(), table.getDataRows().get(5)); - } - - private void verifyHeaders(List actualHeaders) { - for (int i = 0; i < headers.size(); i++) { - Assert.assertEquals(actualHeaders.get(i), headers.get(i)); - } - } - - private void verifyDataRow(List expected, List headers, Map dataRow) { - for (int i = 0; i < headers.size(); i++) { - Assert.assertEquals(dataRow.get(headers.get(i)), expected.get(i)); - } - } -} diff --git a/carina-dataprovider/src/test/resources/_config.properties b/carina-dataprovider/src/test/resources/_config.properties deleted file mode 100644 index 0cc6ebdb64..0000000000 --- a/carina-dataprovider/src/test/resources/_config.properties +++ /dev/null @@ -1,2 +0,0 @@ -max_screen_history=-1 -max_log_file_size=150 diff --git a/carina-dataprovider/src/test/resources/xlsx_data/ChildTest.xlsx b/carina-dataprovider/src/test/resources/xlsx_data/ChildTest.xlsx deleted file mode 100644 index 7b7f9daecbd299cf8e67322253cb86c079067fe2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 9200 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 Av;Y7A diff --git a/carina-dataprovider/src/test/resources/xlsx_data/ParentTest.xlsx b/carina-dataprovider/src/test/resources/xlsx_data/ParentTest.xlsx deleted file mode 100644 index 9b68c1fd1f51ea5504bb5a314b0d4f94a747e61a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 11360 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 WfB>C3003O*YaUuW*!`#;0RIn1f>RR! diff --git a/pom.xml b/pom.xml index 6dfe46eb8a..b25ea42c5f 100644 --- a/pom.xml +++ b/pom.xml @@ -62,7 +62,6 @@ carina-api carina-webdriver - carina-dataprovider carina-core + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/archetype/src/main/resources/archetype-resources/src/test/resources/testng_suites/test-params.xml b/archetype/src/main/resources/archetype-resources/src/test/resources/testng_suites/test-params.xml deleted file mode 100644 index 0cbaa16969..0000000000 --- a/archetype/src/main/resources/archetype-resources/src/test/resources/testng_suites/test-params.xml +++ /dev/null @@ -1,62 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/archetype/src/main/resources/archetype-resources/src/test/resources/testng_suites/web-open-strategy.xml b/archetype/src/main/resources/archetype-resources/src/test/resources/testng_suites/web-open-strategy.xml new file mode 100644 index 0000000000..19a0907c19 --- /dev/null +++ b/archetype/src/main/resources/archetype-resources/src/test/resources/testng_suites/web-open-strategy.xml @@ -0,0 +1,26 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/archetype/src/main/resources/archetype-resources/src/test/resources/xls/demo.xlsx b/archetype/src/main/resources/archetype-resources/src/test/resources/xls/demo.xlsx deleted file mode 100644 index daf75973f212485eab1d8c416162da0683f7c510..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12650 zcmeIYWmp{B(l$J}yOW^7U4wgY2u^S(xVzgR!6mo{_uvH0V8Ja&aQC3W^_^s&b7dcP zp6`3#-_Plb?q;S}-7KoBYTc`<6lI~Hu>r6EcmM!E1}MGM$oGH%0I*>J04xAJq_&uy zt+T1Ev%ac_y{VHfle>*I=?7>?nj8Qmc>I5l|HT>@Qth|xWI=CxvnTYbUAK z9jC(Z`C9jzgoMiCDKc~b@^?|=<;{6kM`*nTS93P?prtNGS=YCps94CXB9^G6B zU1fd8{eclA#Y=y568iG=5*x6CIKuz{Xkg8_TQj@aIa(Rn*;)Nu((+a3ZSz>ree^9J zL8p8$e8BwTe9QQ^TobNpC5so;jvxeekVJ!YSn0!Uv~+*LVrX&1=U(=URCc`49#a)u z^PYMP8LE^F7<`A+Qn^0Uz{iErRx*iRw$y4->8uqLt}Dm0`}rQN-DI-@J#>In!pg!N z-GxuWR;$UDoSIJH+g#^<28QzquEZ?{cAo7925&;>IDIy<6I`E4$g{)=qs!MN%Ws*xE^8yLHG7$!Aq0tOVroEZrStndL zE5#wSWI~<&@5d`M>^LDc2G1*S>62_%UK_kWfhj}sLMvD#faXD=jarzM_@aAdS0QmM zl>GpS=w=NA{Cx1eO>f&E?kvls)cEv_H=^=`G&j#>$h!1OaF@YOR24OpohzpRwMb0# zt;sPg>sO@=I`#Rx#W!%7D<2=xrckVSQ4rR&OuPuIK)36kuDix|mooSc)rH{OU)~ls zQCboQ4^8rdh;vsax74=k%ih4?C$(r z&sk5=XzK5witE|qZASbS7IiF`2g}c^8BX#kIt~D&DL>>+CEd z+?;g3pA|b>0xf0D@4MA0`-c!Zs>lW@%V^#D&ag=O{n0X)5bkLp!A~Zk002S&JOtP> z|BB#$x6gk^a|kf+0+0RQeY7TwT7sil?@>@&(72C7yshbb-nK}QD(y=EmD1W+_sgUU zYCE9>v1Z|Zrd+%riaQ^nv7-CcqN8p+Sj$YcSV~&>x`HyTd73NkHbMR%(&>hY%-UiD z;XpA5zec~V*G_k@3ePD%gj2$V%pT?EPZ(6uIuP4rOfsFN850ohx_C^Z4Dic0vfWMj z8x_(+P^<7L!z^(PxJ@VuH>SzBfinpQ1(arJw3uH)&PZ z23JUbvO&$WE)!Xnc}~N=9seo5&=k?;a?5GGKo2dPkWi)&Uqs}n^Z5Jqw2S8o2+W7Z zv|rrjLNgYPPLTdY01md8nBIV`M-veM!2ccFoXky4ot>C}-B^DHxeRq}yEztY-|V_a z^y@YXRA4&1nq=-Vi-ne($4ij^6vc?O(`@1WB@rKmKT&-#PE^ABk@uGe@9*p5_pGvQ z0yyy}{1Qz#q%m6v`qkc8c}L4{-F!Br#ZPghJzg81rOP-AJzN<&udIpN(y9@&Y_Lga z7lh{?4VuWZlWVu;@SK%@>I(~0s6H_zqtPTNVmR+2-MJw!m*VH7QO;qZ6@K=7!Ag2@34{Ux%TLG)*ZIAl1kjE=ewsy>r7p zMq2IA4Q6$vR_?_FQRo~^>5vSf=gLXvp zTD`&iX};G3mX1{2u@qU?s<9MGIZ^Y&kh^;l1l_}u zn{AlSiAe|Mseg;HpF|0uoR#jW#S##_PR`0HJ^?nIB5P%`?46%H%VN=8M>ycwlFwR9 zpsw3aX~JsdoL=fjn;SsWH?PlE9!^Orw&?YxP1Q`0{Ltr4aRmx$gEZGf_c>iz1*mh4 z_rlq5`h2DaHIu--@IymN%|OrAdF33H(iFDDxi&6-R)wL07f^-4j)$T5B8!llp>H9$ z&I*$RSUMFbXQe2sZ4Aw$S~gWZ>4*U(%ZN8#KS_rXYv=NQEZ%!B9*8?w4q?PNsM4j# zkmLasQSTgqiJ6wSqAVI)A|h(zqbrIRP?3?*gsv@yhoObU>Oy8iKT;mhGyTz!2G?W> zy-(&)9KnHe(yXGzqW;_kMHjk3^tDb{MQ((-_N~PnfX9x;sdI>sbh?lgXVX*AhJJM$ zg<;x0cg{kMiGu-2#RDGKL`(>)+VInva&t%~PTh((j%hXPQ8->NVz5a+4tD&W6;dM$ zVyNj@psAKqWhoksV%lYDsqQLHe$HCzeZb%-z(a?n$u8AOJra@WJ*k{XYi{MPQ8n9C ze-(4^`XkuY{>jEOn27q?z(gYh?tgSfwqMSuHXl6)W*k+Mejo2pqoGy{DashXm)A+FR(C0jLC$a3~$<4?$nqmX2~4&)cOJ{1(# ztUZQQ+@h=F=RjCR@%>{2qD36#Rn`b`NJ@TnRd%-W_u(FP$IT|yy;*sF5E}#wejL&v zA`~mWs}a*FKj?Gdklm;zR(uF+)aWSng{1yxeNL@+kv2|zZ?2g?)ucl!+$7KtMpLcB zXH#{Q+?$cjJVUC$=Bd`%6oz(FmD*vJvIL>}F3eE8zvz;Fm8S&H;B8e-7kzfNqwggO z+eRH}Hfo3;MSUiegk;|R4q;6b1cAO7v8^x_3Q!nbp5h}K7rDbUv{*>G zR7izXGd!<(up<q`vj zNkwO3m9vh^_&PbIHGB(1iZ~yqyX!Fie5RRfy}?c|s@B|c8E+0$pBPo1`SHEjD?jhW zXx#Q0c%1`#5MBJ0UH*xXjqiiSedm>m6U8fc;o`JzAw;FBz?}Y={O;kDsrwzn zyu8vEqd#CXN;=>(N=7)h;G53(P%Mme@i_-QoN(Z93E_+&!xs`0x$wr4>$& z5Uqy=Z~ls@3P6m&bVNLlL5#~-G}>0?P>@Q zLv2K}>ndc#-v;e~#Ln zJ36liTmJFuJ*+446u*ha%5YjO9vUt%qm*#)0H(qyWn2f>&V=*Ckl*l*uvpNp)8!aB zAvqhTQLJZDy%_ylWD{I}NG!fC4Fq@VH{h7Vc6)aNY zeEVM36aU|j-cr1OH%Z1yRX3VzVo7ejiN&^aOj|bNV<|qfJy{Mo_)4}b&g~>62V~4X zmPgI5@mwrY*ATqDc9yyUpK_iI*)_C;BQ526mnAq!qk31$q4{`GLuA(?g2}J{8tv>e z;+bx|7kl<0j)#JZaN3>RoKN?*l|kRFR1hKN+Xyc2{y|KM?AHj%t%(%xZ*Mcv3b1#- z^yt(>pRy*p(7yy-w@N9s#0?gTV)5dnuPpSdOxjk5jFo(Y-X>1};QE6d__~LR+pPmT zjhx3~(P2l`I?zd9MybURA1yOno`tWsn**NKGP#D#neHX1+%#g0iB0V1AWc);+^7!l zx30GaYs-|ccpoz3zN=dY_UDV^o3QPHNBs5MjS|(11nCHtzI@CqEF&+L)H?VexlWOl zcvkr_f!0GJC-sA3>syE1bT^2i*@n%~N>ufkhgDT{h1RLDsBL??rckH#LzgNvRJ~!^ zb$d+Jd+O&VJh;fX&OP0WjaWUcVo=Yb$^t=y`gGV~s~-2j||mwYHp&Hd*i*PDK7Q z5B@7*;B0PcW6J#N`ioD0*OIk+#)aOFx8p~8k)=^X`Gt)fE{UN>`Yx~{zb{Tpsip4I zAdK|vc!g9n3?jCCgdXDAwAlDdVaT)i2f{|$IqW|Domd@d*@*CpUU7X_e|M5)e- z+zX;0?3pKl=E6K8KsKfMzUXWYIht6Zod#Z#rctqCvnG&4#_DJWnZ!c7v66Jc$g(iZ zdm{aJ&`4HXc*mBnyC;$7Aa&>OHk^4xj?Bl)X+Ipgk2|&~w^Xxk*#YF_*R?9tYt@K< zumhflSsB(1?HRssV^GtEb+>;}C8r7!J>CjjzyH=jr8)k*R z;JKiP2uEa|Ec5twNg9q7g5bsn6ab2e#yEC~p~MY0kj8c`pPmL)F+_!FRm7rtl8F)Y zc%$E=qjq-cp11;;>4QB`BB_N*Atu7EhIR-!lLPShaXQb%oSg?gGX;GeZmvSVQY*YB z@w4;b0j6_Dg#)WP9yTtSgV+8*`wIQc$> zNAh?xtb*pPyJCy6l#38&9-5KkljU#Q%Tl?KPrsG7)1AVL%?-OmJk5y1_c@d7t)Na& zQ?D0kPTiG%BV1^7Ib1b9&7S79UIzDPn-R?*q$-HR-FigaL*$9RjwXC;hg*D-+iBai zNe3INSP}W)*vtkWcB<$UFXSRbNeW8DUAMb1bhKG98KM^3uZs5lw}=Ay#Q`NV6hw0_ zkQSnK(pblXW7MQgbJfEaP?IY|Mdz?Qu5q#GDIUNh^sSVWm&7y~R~oMNo#C*{opcun z9xT{~7&GyR{6rYNN@bGyXXD=y#~N48yzom?XAb7AQ<|i5cj98UakpB-7FHyO@u^ea zyiMyB|4!rqO%^^*{6_HVr5pRJtIV!i*8dKk3vB$Q2 z@AkdaPLwk{duE}wDleIrFu9;u*1>9OCwsR=U=PCx---*hv!UIOqzPSIVw?azY)`>3 zyecJE%3~U6H!IwkHhjL8r1s=YBn#jpoBpRPV;*ie>DVlElORq?K z36Mhv-ntX?XSh%(^->N+4jHpcP@1`?gJ^=|VpAQ|&(8+u6pZSJy)I6a9R_&b8s~=( zQMlBN#lN*5?@6+4oi{S2pOUNnRGJuNUTAEu`mC&6p1v^4)oWmDH z>Mdaj;e%>#8MscDTHGx-3NziMw+~XCO)OY>G{ax-iBvRepeTmbdX9xcFzQedxa;m6 z5e<=ZZ^9>jH1xA&OSjK-uiZi$WE)zjSS-SJ-4mwDpZm<#kZY*7N%mQp{q@UJW_3_` za)Eylp{`tb0SX=p&GgBeebz=}Bu>O1nCu{FOCl*_pFZD5MvKXSxKKti zL0CTNn7+<|f$u z-qY;+5vEsdUE!6qd3y#Q8C3CVW1cZl=&|R_c|tHL?u$=IR`Bz(PUHDnYDtZU$t*%t zz9u3Y<#LC!9_l%3T=Pl)TbFgp`Ncd>6q(Q8U&$FiB3KUfz#nV%pu zcCbE{a_7il#uHuAYyeY&4yHKXw&CW@yUYu+_mEKo@$qX>D=E9W?mFW_0BaF^uQ9@V zH=x&3=DZy@qn43Qoe;BE$2-r&A0B7-$JdMs@4jEbqaVu^CI zO=ho-aCI@7$Pr$b-hivw%(=^IBDDq@`0?3?ir6!HxhX`g&yUa}nB1&5j1suIz=meZ zwo$2jXhP6g8k^AiiK%|oyP@IT`?B~AKfBE(^I?O}kl!4HE(3`7eV1UgTH4ul+GOo^ z!t6=m=XZ**?&?u)_^C;CB}SI#$n${yOuBLCMDf%3iivScnI((Tfw6+u%2rc>FvFMc zY119g#2dMSkTR8UcEZ$0F0g?o%Pc9~_DApsw>|d@s5;Cw>uTupAZW^N2|}3;XY(4`Nmg>;0CzNqVAO^lJw%CeqA-#wPWY;)^S?X;qQJ9mDd3Zo@g|5 z!pvZUDwk1S6;O#O5>l~pe~^=Dt}>iIt9{5<5G4qkB+P2jRLO*%C{;kwfm+2opbWmN z*z%K0E?a0cb|an#0f84B8O#SP8bis0-g`HPYx6s=AE3A#e;`5(?8DTCfZB8~Ko=V% zu-cYUu-RuNbGlvr7b&-sF$=e2P6ys=p04Pt-=g!R&9`&6nez<5eSVrt+)RgVp!)(%nJI-&y8o zSC)?;Cy2c#1Wz5>6ZW4mgr^7X#tRL2EY8OlV1Y1A_uI!C7-!cn=D%c63QEoQRW_EI zNN&!`pFilX`bhQFx0|$}U(96OdKN{VCHPh``1~kylYqV1(K@_*-QRok9`4oh(qH}h=89qKbsBz!Z+UMTGk!QT zzNdrs$4Pu)&i94r(uNQb;tLUc@tOS36XfXxyJxN0%vQ|yZ&QX<$c7x@v>%ouduXvo zx9k%6Eza>qy*N`vMn_w&ENbUR`@0-bsB>l6UN$&0GQ7j*&%|#{s5mt&6N7WJ*wrFI zLx)}boY2`XA)|!9@?2a-DPz}o< zf7LtwDxUqWdi*M#0b@Ynoh;bmmrxI4?p_Jg!N_7NT;xq^+fYU~bFlNtv6tBQUbW9n zKW}c@k8Zw9zvVA^_7*jcVX_%Ac*7Xa{Nu6L9Ak$_HTT{EHUcAmtl?Lt_B5#1uVvnS ziPgYCst#77xX17E?VhcUMkt9D+?ths=fTo{9r0|eywuX>R3EO6`E~sf!-mhBAYK7w z&4=&NJ|z6Mc^xBCr=vh=o>&9H4^ljR;s>YxMk4!e7g<(5sL+KrLxVpq5dLKCSltX* zo&Pr)_?372w+6sPGxS$S!FNI5yeRlW6~ig@Wyofz?g8R@^B*o`%o{1MZ+E@{MWefn zmsoWDH1W>$OjDI4@U`C^eBYJy$kPmAhD-S1@;#ujSgTf?CK_A%aEPWU0$}J)@JH-SU;Y z*Z+w2uKcG8`YGcLcs@u8^r;;T0>LVfyhw4od5#ddKeXuN_Q#}S&Dx-Z5Lg8Z;FJ0< zBd`a1y0fXHim9{nPnTzY@|l&%$imjhAP1SHhNWf!f)L}eBQ7&8Ai)r~5kV3W>ID>^ z7&I1EENmPyax^j(_FPaokqJ4xzqtfOq%Al_@Q0v7AWa}8`TsNrw!h7xb`gSbwKY5L z-QVXRBnBNj3Qdt3z%L1lg?Jz`Jp#Y!Z%##u3t)SI3TQE73Fid=!9UEUm3I z*RClUDho!cx}v!tuhz+S-dJX!I7q^Sx41ODP1KvlCua-gii<}qRA>%qTtMuu>pe-m zv&(?qKz`JRQ?hF!mJdPyf@2ZY$;jH0!ObIp{!iy8%7981q*!Zs6w#m1`cCjGvig1SQl}J$+UQP zb^3ReZBV#%oIX~5rc^y`%Oys?k)8LCk}iu@Cn7{-mA&B7pHJ-5BQ=as2}At=qYybY zAJX&5)#gL7U+`6$C^ZO5@ILgEXv}&!@`Sn6#a!!{I)tQ*WV)lU$Q6$pZW)%< zuG9tvLpE!XySO@+*d2EKoNS-)j(Cu3v_tgKIxDmzm$?e>nr$18b(i+~0qN{Fv4DVN z1QW(TcR&C8_5J()hhAt!+5ZIi&t}Yj3;w*vG?@)YH13H&#TFqpgl0p(Xg{3*)Q zs^V`HcFaGb{Ng%KQJ$vpf1|+T{X%(~)PD-_G#Bw307(1`;CE)?sp!)^$#2m{a8UuQ z2dAeyl&1(!neK0dJc_3}_#^Lq3iy;b{st_d{Qm&_O(UNIKBZy50gI`A0X`vNe Date: Wed, 29 Mar 2023 20:32:04 +0300 Subject: [PATCH 49/52] change version of carina-webdriver to 1.0.1.P6-SNAPSHOT --- carina-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/carina-core/pom.xml b/carina-core/pom.xml index bd66679ab4..1b91dcfc46 100644 --- a/carina-core/pom.xml +++ b/carina-core/pom.xml @@ -19,7 +19,7 @@ UTF-8 - 1.0.1.P5-SNAPSHOT + 1.0.1.P6-SNAPSHOT 1.0.3.P3-SNAPSHOT From 7bef378db0542dd4c4de8ac188aedd165918bd7a Mon Sep 17 00:00:00 2001 From: Dima Grinevich Date: Thu, 30 Mar 2023 11:52:35 +0300 Subject: [PATCH 50/52] refactor(HomePageBase.java): updated archetyp according to carina-demo --- .../main/java/carina/demo/gui/pages/common/HomePageBase.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/archetype/src/main/resources/archetype-resources/src/main/java/carina/demo/gui/pages/common/HomePageBase.java b/archetype/src/main/resources/archetype-resources/src/main/java/carina/demo/gui/pages/common/HomePageBase.java index 4b0254862e..45f4bcb638 100644 --- a/archetype/src/main/resources/archetype-resources/src/main/java/carina/demo/gui/pages/common/HomePageBase.java +++ b/archetype/src/main/resources/archetype-resources/src/main/java/carina/demo/gui/pages/common/HomePageBase.java @@ -7,6 +7,7 @@ import org.openqa.selenium.support.FindBy; import ${package}.carina.demo.gui.components.footer.FooterMenuBase; +import com.zebrunner.carina.webdriver.decorator.PageOpeningStrategy; import com.zebrunner.carina.webdriver.decorator.ExtendedWebElement; import com.zebrunner.carina.webdriver.gui.AbstractPage; @@ -17,6 +18,7 @@ public abstract class HomePageBase extends AbstractPage { public HomePageBase(WebDriver driver) { super(driver); + setPageOpeningStrategy(PageOpeningStrategy.BY_ELEMENT); } public abstract BrandModelsPageBase selectBrand(String brandName); From 727b0144ba40015b74019fe9eaf41bda4b1acd04 Mon Sep 17 00:00:00 2001 From: Andrei Kamarouski Date: Fri, 31 Mar 2023 13:48:49 +0300 Subject: [PATCH 51/52] change version of carina-webdriver and carina-utils to release --- carina-core/pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/carina-core/pom.xml b/carina-core/pom.xml index 1b91dcfc46..238ce1cdf6 100644 --- a/carina-core/pom.xml +++ b/carina-core/pom.xml @@ -19,11 +19,11 @@ UTF-8 - 1.0.1.P6-SNAPSHOT - 1.0.3.P3-SNAPSHOT + 1.0.1 + 1.0.3 - + From 9909ac0dec2f0adf1f21f3b01939e43645807865 Mon Sep 17 00:00:00 2001 From: Andrei Kamarouski Date: Fri, 31 Mar 2023 14:04:03 +0300 Subject: [PATCH 52/52] refactor(CarinaListener.java): missprint --- .../carina/core/foundation/listeners/CarinaListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/carina-core/src/main/java/com/qaprosoft/carina/core/foundation/listeners/CarinaListener.java b/carina-core/src/main/java/com/qaprosoft/carina/core/foundation/listeners/CarinaListener.java index 467155db6a..0b69df9d20 100644 --- a/carina-core/src/main/java/com/qaprosoft/carina/core/foundation/listeners/CarinaListener.java +++ b/carina-core/src/main/java/com/qaprosoft/carina/core/foundation/listeners/CarinaListener.java @@ -258,7 +258,7 @@ public void beforeConfiguration(ITestResult result) { @Override public void onConfigurationSuccess(ITestResult result) { - LOGGER.debug("CarinaListener->onCongigurationSuccess"); + LOGGER.debug("CarinaListener->onConfigurationSuccess"); onConfigurationFinish(result); super.onConfigurationSuccess(result); }