From 2b5f27190a27f6f411a59b8b40a3f1b6a2d4df35 Mon Sep 17 00:00:00 2001 From: Andrei Kamarouski Date: Wed, 22 Mar 2023 16:27:15 +0300 Subject: [PATCH 1/7] refactor: code formatting --- .../dataprovider/IAbstractDataProvider.java | 5 +++-- .../annotations/CsvDataSourceParameters.java | 13 +++++++------ .../annotations/XlsDataSourceParameters.java | 11 ++++++----- .../dataprovider/core/DataProviderFactory.java | 1 + .../core/groupping/GroupByImpl.java | 7 +++++-- .../core/impl/BaseDataProvider.java | 3 ++- .../core/impl/CsvDataProvider.java | 18 ++++++++++-------- .../carina/dataprovider/parser/DSBean.java | 15 ++++++++------- .../dataprovider/parser/csv/CSVParser.java | 17 +++++++++++------ .../dataprovider/parser/csv/CSVTable.java | 1 + .../java/CarinaDataproviderLoggerTest.java | 5 +++-- .../utils/parser/CellLinksIntegrationTest.java | 1 + 12 files changed, 58 insertions(+), 39 deletions(-) diff --git a/src/main/java/com/zebrunner/carina/dataprovider/IAbstractDataProvider.java b/src/main/java/com/zebrunner/carina/dataprovider/IAbstractDataProvider.java index 18b8202..e089ebc 100644 --- a/src/main/java/com/zebrunner/carina/dataprovider/IAbstractDataProvider.java +++ b/src/main/java/com/zebrunner/carina/dataprovider/IAbstractDataProvider.java @@ -1,11 +1,12 @@ package com.zebrunner.carina.dataprovider; -import com.zebrunner.carina.dataprovider.core.DataProviderFactory; +import java.lang.annotation.Annotation; + import org.testng.ITestContext; import org.testng.ITestNGMethod; import org.testng.annotations.DataProvider; -import java.lang.annotation.Annotation; +import com.zebrunner.carina.dataprovider.core.DataProviderFactory; public interface IAbstractDataProvider { diff --git a/src/main/java/com/zebrunner/carina/dataprovider/annotations/CsvDataSourceParameters.java b/src/main/java/com/zebrunner/carina/dataprovider/annotations/CsvDataSourceParameters.java index ae703df..0720362 100644 --- a/src/main/java/com/zebrunner/carina/dataprovider/annotations/CsvDataSourceParameters.java +++ b/src/main/java/com/zebrunner/carina/dataprovider/annotations/CsvDataSourceParameters.java @@ -23,6 +23,7 @@ @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface CsvDataSourceParameters { + /** * Define data provider instance * @@ -107,7 +108,7 @@ String testMethodColumn() default ""; /** - * Reason: not implemented + * @deprecated Reason: not implemented * * @return String */ @@ -115,7 +116,7 @@ String testRailColumn() default ""; /** - * Reason: not implemented + * @deprecated Reason: not implemented * * @return String */ @@ -123,7 +124,7 @@ String qTestColumn() default ""; /** - * Reason: not implemented + * @deprecated Reason: not implemented * * @return String */ @@ -131,7 +132,7 @@ String testMethodOwnerColumn() default ""; /** - * Reason: not implemented + * @deprecated Reason: not implemented * * @return String */ @@ -139,10 +140,10 @@ String bugColumn() default ""; /** - * Reason: not implemented + * @deprecated Reason: not implemented * * @return String[] */ @Deprecated(forRemoval = true, since = "1.0.0") String[] doNotRunTestNames() default {}; -} \ No newline at end of file +} diff --git a/src/main/java/com/zebrunner/carina/dataprovider/annotations/XlsDataSourceParameters.java b/src/main/java/com/zebrunner/carina/dataprovider/annotations/XlsDataSourceParameters.java index f9b8e4a..33fc731 100644 --- a/src/main/java/com/zebrunner/carina/dataprovider/annotations/XlsDataSourceParameters.java +++ b/src/main/java/com/zebrunner/carina/dataprovider/annotations/XlsDataSourceParameters.java @@ -23,6 +23,7 @@ @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface XlsDataSourceParameters { + /** * Define data provider instance * @@ -108,7 +109,7 @@ String testMethodColumn() default ""; /** - * Reason: not implemented + * @deprecated Reason: not implemented * * @return String */ @@ -116,7 +117,7 @@ String testRailColumn() default ""; /** - * Reason: not implemented + * @deprecated Reason: not implemented * * @return String */ @@ -124,7 +125,7 @@ String qTestColumn() default ""; /** - * Reason: not implemented + * @deprecated Reason: not implemented * * @return String */ @@ -132,7 +133,7 @@ String testMethodOwnerColumn() default ""; /** - * Reason: not implemented + * @deprecated Reason: not implemented * * @return String */ @@ -140,7 +141,7 @@ String bugColumn() default ""; /** - * Reason: not implemented + * @deprecated Reason: not implemented * * @return String */ diff --git a/src/main/java/com/zebrunner/carina/dataprovider/core/DataProviderFactory.java b/src/main/java/com/zebrunner/carina/dataprovider/core/DataProviderFactory.java index 9cb90e3..a33f2d8 100644 --- a/src/main/java/com/zebrunner/carina/dataprovider/core/DataProviderFactory.java +++ b/src/main/java/com/zebrunner/carina/dataprovider/core/DataProviderFactory.java @@ -36,6 +36,7 @@ * Created by Patotsky on 16.12.2014. */ public class DataProviderFactory { + private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private DataProviderFactory() {} diff --git a/src/main/java/com/zebrunner/carina/dataprovider/core/groupping/GroupByImpl.java b/src/main/java/com/zebrunner/carina/dataprovider/core/groupping/GroupByImpl.java index 91967b1..b86b80c 100644 --- a/src/main/java/com/zebrunner/carina/dataprovider/core/groupping/GroupByImpl.java +++ b/src/main/java/com/zebrunner/carina/dataprovider/core/groupping/GroupByImpl.java @@ -15,12 +15,15 @@ *******************************************************************************/ package com.zebrunner.carina.dataprovider.core.groupping; -import java.util.*; +import java.util.ArrayList; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; /** * Created by Patotsky on 29.12.2014. */ - @Deprecated(forRemoval = true, since = "1.0.0") public class GroupByImpl { diff --git a/src/main/java/com/zebrunner/carina/dataprovider/core/impl/BaseDataProvider.java b/src/main/java/com/zebrunner/carina/dataprovider/core/impl/BaseDataProvider.java index fd53964..085ea89 100644 --- a/src/main/java/com/zebrunner/carina/dataprovider/core/impl/BaseDataProvider.java +++ b/src/main/java/com/zebrunner/carina/dataprovider/core/impl/BaseDataProvider.java @@ -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.zebrunner.carina.dataprovider.parser.DSBean; import com.zebrunner.carina.utils.ParameterGenerator; import com.zebrunner.carina.utils.parser.xls.AbstractTable; @@ -36,6 +36,7 @@ */ public abstract class BaseDataProvider { + protected Map tuidMap = Collections.synchronizedMap(new HashMap<>()); protected Map testColumnNamesMap = Collections.synchronizedMap(new HashMap<>()); diff --git a/src/main/java/com/zebrunner/carina/dataprovider/core/impl/CsvDataProvider.java b/src/main/java/com/zebrunner/carina/dataprovider/core/impl/CsvDataProvider.java index 6b39039..8d10225 100644 --- a/src/main/java/com/zebrunner/carina/dataprovider/core/impl/CsvDataProvider.java +++ b/src/main/java/com/zebrunner/carina/dataprovider/core/impl/CsvDataProvider.java @@ -15,24 +15,26 @@ *******************************************************************************/ 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 java.lang.annotation.Annotation; +import java.lang.invoke.MethodHandles; +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 java.lang.annotation.Annotation; -import java.lang.invoke.MethodHandles; -import java.util.List; -import java.util.Map; +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; /** * Created by Patotsky on 16.12.2014. */ public class CsvDataProvider extends BaseDataProvider { + private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); /** diff --git a/src/main/java/com/zebrunner/carina/dataprovider/parser/DSBean.java b/src/main/java/com/zebrunner/carina/dataprovider/parser/DSBean.java index db0dad4..22beb67 100644 --- a/src/main/java/com/zebrunner/carina/dataprovider/parser/DSBean.java +++ b/src/main/java/com/zebrunner/carina/dataprovider/parser/DSBean.java @@ -15,23 +15,24 @@ *******************************************************************************/ 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; +import org.testng.ITestContext; + +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; + 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; diff --git a/src/main/java/com/zebrunner/carina/dataprovider/parser/csv/CSVParser.java b/src/main/java/com/zebrunner/carina/dataprovider/parser/csv/CSVParser.java index a35c892..87dd62f 100644 --- a/src/main/java/com/zebrunner/carina/dataprovider/parser/csv/CSVParser.java +++ b/src/main/java/com/zebrunner/carina/dataprovider/parser/csv/CSVParser.java @@ -1,16 +1,21 @@ 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.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.zebrunner.carina.dataprovider.parser.DSBean; + +import au.com.bytecode.opencsv.CSVReader; public class CSVParser { + private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); public static CSVTable parseCsvFile(DSBean dsBean, char separator, char quote) { diff --git a/src/main/java/com/zebrunner/carina/dataprovider/parser/csv/CSVTable.java b/src/main/java/com/zebrunner/carina/dataprovider/parser/csv/CSVTable.java index 92f3023..578e5f1 100644 --- a/src/main/java/com/zebrunner/carina/dataprovider/parser/csv/CSVTable.java +++ b/src/main/java/com/zebrunner/carina/dataprovider/parser/csv/CSVTable.java @@ -11,6 +11,7 @@ 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() { diff --git a/src/test/java/CarinaDataproviderLoggerTest.java b/src/test/java/CarinaDataproviderLoggerTest.java index e4ec528..ec4db6b 100644 --- a/src/test/java/CarinaDataproviderLoggerTest.java +++ b/src/test/java/CarinaDataproviderLoggerTest.java @@ -1,10 +1,11 @@ +import java.lang.invoke.MethodHandles; + 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 diff --git a/src/test/java/com/zebrunner/carina/utils/parser/CellLinksIntegrationTest.java b/src/test/java/com/zebrunner/carina/utils/parser/CellLinksIntegrationTest.java index ba49557..abddd2d 100644 --- a/src/test/java/com/zebrunner/carina/utils/parser/CellLinksIntegrationTest.java +++ b/src/test/java/com/zebrunner/carina/utils/parser/CellLinksIntegrationTest.java @@ -27,6 +27,7 @@ import com.zebrunner.carina.utils.parser.xls.XLSTable; public class CellLinksIntegrationTest { + private List headers; private List firstRow; private List secondRow; From e449545d4d42964c296175628b1f178dd15e5383 Mon Sep 17 00:00:00 2001 From: Andrei Kamarouski Date: Thu, 23 Mar 2023 11:12:13 +0300 Subject: [PATCH 2/7] fix(annotations): rename className packages --- .../dataprovider/annotations/CsvDataSourceParameters.java | 2 +- .../dataprovider/annotations/XlsDataSourceParameters.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/zebrunner/carina/dataprovider/annotations/CsvDataSourceParameters.java b/src/main/java/com/zebrunner/carina/dataprovider/annotations/CsvDataSourceParameters.java index 0720362..857f22c 100644 --- a/src/main/java/com/zebrunner/carina/dataprovider/annotations/CsvDataSourceParameters.java +++ b/src/main/java/com/zebrunner/carina/dataprovider/annotations/CsvDataSourceParameters.java @@ -29,7 +29,7 @@ * * @return String */ - String className() default "com.qaprosoft.carina.core.foundation.dataprovider.core.impl.CsvDataProvider"; + String className() default "com.zebrunner.carina.dataprovider.core.impl.CsvDataProvider"; /** * Define column separator for parsing diff --git a/src/main/java/com/zebrunner/carina/dataprovider/annotations/XlsDataSourceParameters.java b/src/main/java/com/zebrunner/carina/dataprovider/annotations/XlsDataSourceParameters.java index 33fc731..98c4340 100644 --- a/src/main/java/com/zebrunner/carina/dataprovider/annotations/XlsDataSourceParameters.java +++ b/src/main/java/com/zebrunner/carina/dataprovider/annotations/XlsDataSourceParameters.java @@ -29,7 +29,7 @@ * * @return String */ - String className() default "com.qaprosoft.carina.core.foundation.dataprovider.core.impl.XlsDataProvider"; + String className() default "com.zebrunner.carina.dataprovider.core.impl.XlsDataProvider"; /** * Is mutually exclusive with path From 87adf2a4e3e24d1177b1a739ef0fcbc8f9967c9e Mon Sep 17 00:00:00 2001 From: Dima Grinevich Date: Fri, 24 Mar 2023 12:22:58 +0300 Subject: [PATCH 3/7] fix(BaseDataProvider.java): indexOutOfBounds for static params fix --- .../annotations/CsvDataSourceParameters.java | 2 +- .../annotations/XlsDataSourceParameters.java | 4 ++-- .../carina/dataprovider/core/impl/BaseDataProvider.java | 9 ++++++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/zebrunner/carina/dataprovider/annotations/CsvDataSourceParameters.java b/src/main/java/com/zebrunner/carina/dataprovider/annotations/CsvDataSourceParameters.java index ae703df..d3c997b 100644 --- a/src/main/java/com/zebrunner/carina/dataprovider/annotations/CsvDataSourceParameters.java +++ b/src/main/java/com/zebrunner/carina/dataprovider/annotations/CsvDataSourceParameters.java @@ -28,7 +28,7 @@ * * @return String */ - String className() default "com.qaprosoft.carina.core.foundation.dataprovider.core.impl.CsvDataProvider"; + String className() default "com.zebrunner.carina.dataprovider.core.impl.CsvDataProvider"; /** * Define column separator for parsing diff --git a/src/main/java/com/zebrunner/carina/dataprovider/annotations/XlsDataSourceParameters.java b/src/main/java/com/zebrunner/carina/dataprovider/annotations/XlsDataSourceParameters.java index f9b8e4a..c47f2c9 100644 --- a/src/main/java/com/zebrunner/carina/dataprovider/annotations/XlsDataSourceParameters.java +++ b/src/main/java/com/zebrunner/carina/dataprovider/annotations/XlsDataSourceParameters.java @@ -28,7 +28,7 @@ * * @return String */ - String className() default "com.qaprosoft.carina.core.foundation.dataprovider.core.impl.XlsDataProvider"; + String className() default "com.zebrunner.carina.dataprovider.core.impl.XlsDataProvider"; /** * Is mutually exclusive with path @@ -38,7 +38,7 @@ String spreadsheetId() default ""; /** - * Define data provider instance + * Define sheet from xls file * * @return String */ diff --git a/src/main/java/com/zebrunner/carina/dataprovider/core/impl/BaseDataProvider.java b/src/main/java/com/zebrunner/carina/dataprovider/core/impl/BaseDataProvider.java index fd53964..e3df88f 100644 --- a/src/main/java/com/zebrunner/carina/dataprovider/core/impl/BaseDataProvider.java +++ b/src/main/java/com/zebrunner/carina/dataprovider/core/impl/BaseDataProvider.java @@ -138,7 +138,7 @@ private void fillArgsAsArray(Object[][] dataProvider, AbstractTable table, DSBea // 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); + dataProvider[rowIndex][staticArgsColumn + dsBean.getArgs().size()] = getStaticParam(staticArgName, dsBean); } } } @@ -221,8 +221,11 @@ private 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)); + Object param = ParameterGenerator.process(dsBean.getTestParams().get(name)); + if (param == null) { + throw new RuntimeException("Cant find parameter " + name + " in suite"); + } + return param; } public Map getTestColumnNamesMap() { From 4ef5ba472a15f190176a1de8de9fc6353d0f211c Mon Sep 17 00:00:00 2001 From: Dima Grinevich Date: Mon, 27 Mar 2023 15:07:08 +0300 Subject: [PATCH 4/7] refactor(DSBean.java): deprecated for removal implementation of SpecialKeywords.EXCEL_DS_... --- .../carina/dataprovider/parser/DSBean.java | 58 ++++++++++++++----- 1 file changed, 43 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/zebrunner/carina/dataprovider/parser/DSBean.java b/src/main/java/com/zebrunner/carina/dataprovider/parser/DSBean.java index 22beb67..e264782 100644 --- a/src/main/java/com/zebrunner/carina/dataprovider/parser/DSBean.java +++ b/src/main/java/com/zebrunner/carina/dataprovider/parser/DSBean.java @@ -15,24 +15,27 @@ *******************************************************************************/ package com.zebrunner.carina.dataprovider.parser; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -import org.testng.ITestContext; - 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.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.ITestContext; -public class DSBean { +import java.lang.invoke.MethodHandles; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +public class DSBean { + private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); 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; @@ -42,8 +45,26 @@ public class DSBean { private String testMethodColumn; private boolean argsToMap; + /** + * @deprecated test method should have {@link com.zebrunner.carina.dataprovider.annotations.CsvDataSourceParameters} + * or {@link com.zebrunner.carina.dataprovider.annotations.XlsDataSourceParameters} annotation + */ + @Deprecated(forRemoval = true, since = "1.0.0") public DSBean(ITestContext context) { - initParamsFromSuite(context.getCurrentXmlTest().getAllParameters(), "excel"); + this.testParams = context.getCurrentXmlTest().getAllParameters(); + ////Delete this if/else after removal of SpecialKeywords.EXCEL_DS_... keys + if (testParams.keySet().stream().anyMatch(param -> param.contains("excel_ds_") + && !param.equalsIgnoreCase(SpecialKeywords.EXCEL_DS_SHEET))){ + + LOGGER.warn("Found usage of deprecated {excel_ds_...} suite parameters," + + " implement new approach without \"excel\" word {ds_...}"); + + initParamsFromSuite(testParams, "excel"); + } else { + initParamsFromSuite(testParams, ""); + } + + this.xlsSheet = testParams.get(SpecialKeywords.EXCEL_DS_SHEET); this.argsToMap = this.args.size() == 0; } @@ -51,13 +72,18 @@ public DSBean(XlsDataSourceParameters xlsDataSourceParameters, Map param.contains("excel_ds_") + && !param.equalsIgnoreCase(SpecialKeywords.EXCEL_DS_SHEET))){ + LOGGER.warn("Found usage of deprecated {excel_ds_...} suite parameters," + + " implement new approach without \"excel\" word {ds_...}"); + + initParamsFromSuite(suiteParams, "excel"); + } else { + initParamsFromSuite(suiteParams, ""); + } if (suiteParams.get(SpecialKeywords.EXCEL_DS_SHEET) != null) { this.xlsSheet = suiteParams.get(SpecialKeywords.EXCEL_DS_SHEET); } @@ -97,6 +123,7 @@ private void initParamsFromAnnotation(XlsDataSourceParameters parameters) { this.executeValue = parameters.executeValue(); this.groupColumn = parameters.groupColumn(); this.testMethodColumn = parameters.testMethodColumn(); + this.xlsSheet = parameters.sheet(); if (!parameters.dsArgs().isEmpty()) { this.args = Arrays.asList(parameters.dsArgs().replace(" ", "").split(",")); @@ -107,11 +134,10 @@ private void initParamsFromAnnotation(XlsDataSourceParameters parameters) { 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 + // initialize default csv data source parameters from annotation this.dsFile = parameters.path(); this.executeColumn = parameters.executeColumn(); this.executeValue = parameters.executeValue(); @@ -129,6 +155,7 @@ private void initParamsFromAnnotation(CsvDataSourceParameters parameters) { } } + //Delete specialKeyPrefix parameter after removal of SpecialKeywords.EXCEL_DS_... keys private void initParamsFromSuite(Map suiteParams, String specialKeyPrefix) { // initialize data source parameters from suite xml file if (suiteParams.get(insert(SpecialKeywords.DS_FILE, specialKeyPrefix)) != null) { @@ -151,6 +178,7 @@ private void initParamsFromSuite(Map suiteParams, String special } } + //Delete this method after removal of SpecialKeywords.EXCEL_DS_... keys private String insert(String into, String insertion) { StringBuilder newString = new StringBuilder(into); newString.insert(1, insertion); From 0606881715cbe632e4f892d2649f9d7371b88757 Mon Sep 17 00:00:00 2001 From: Andrei Kamarouski Date: Mon, 27 Mar 2023 15:13:03 +0300 Subject: [PATCH 5/7] change version of carina-utils to 1.0.3.P2-SNAPSHOT --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4639975..141503a 100644 --- a/pom.xml +++ b/pom.xml @@ -49,7 +49,7 @@ UTF-8 11 - 1.0.3.P1-SNAPSHOT + 1.0.3.P2-SNAPSHOT 1.7 1.7.30 3.5 From b5258746b55c059e96d56eb6e5f0fbb109836162 Mon Sep 17 00:00:00 2001 From: Andrei Kamarouski Date: Wed, 29 Mar 2023 14:47:25 +0300 Subject: [PATCH 6/7] refactor: resolve sonar warnings --- .../dataprovider/IAbstractDataProvider.java | 6 ++--- .../core/groupping/GroupByImpl.java | 6 +++++ .../exceptions/GroupByException.java | 3 ++- .../core/impl/CsvDataProvider.java | 18 +++++---------- .../carina/dataprovider/parser/DSBean.java | 6 ++--- .../dataprovider/parser/csv/CSVParser.java | 22 +++++++++++-------- 6 files changed, 32 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/zebrunner/carina/dataprovider/IAbstractDataProvider.java b/src/main/java/com/zebrunner/carina/dataprovider/IAbstractDataProvider.java index e089ebc..f99516c 100644 --- a/src/main/java/com/zebrunner/carina/dataprovider/IAbstractDataProvider.java +++ b/src/main/java/com/zebrunner/carina/dataprovider/IAbstractDataProvider.java @@ -13,14 +13,12 @@ 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; + return DataProviderFactory.getDataProvider(annotations, context, testMethod); } @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; + return DataProviderFactory.getDataProvider(annotations, context, testMethod); } } diff --git a/src/main/java/com/zebrunner/carina/dataprovider/core/groupping/GroupByImpl.java b/src/main/java/com/zebrunner/carina/dataprovider/core/groupping/GroupByImpl.java index b86b80c..9328cf1 100644 --- a/src/main/java/com/zebrunner/carina/dataprovider/core/groupping/GroupByImpl.java +++ b/src/main/java/com/zebrunner/carina/dataprovider/core/groupping/GroupByImpl.java @@ -23,10 +23,16 @@ /** * Created by Patotsky on 29.12.2014. + * + * @deprecated unused */ @Deprecated(forRemoval = true, since = "1.0.0") public class GroupByImpl { + private GroupByImpl() { + // hide + } + public static Object[][] getGroupedDataProviderArgs(Object[][] objects, int fieldNumber) { //add unique group values Set groupValues = new LinkedHashSet<>(); diff --git a/src/main/java/com/zebrunner/carina/dataprovider/core/groupping/exceptions/GroupByException.java b/src/main/java/com/zebrunner/carina/dataprovider/core/groupping/exceptions/GroupByException.java index 3c3c90e..9ff60e0 100644 --- a/src/main/java/com/zebrunner/carina/dataprovider/core/groupping/exceptions/GroupByException.java +++ b/src/main/java/com/zebrunner/carina/dataprovider/core/groupping/exceptions/GroupByException.java @@ -17,8 +17,9 @@ /** * Created by Patotsky on 08.01.2015. + * + * @deprecated unused */ - @Deprecated(forRemoval = true, since = "1.0.0") @SuppressWarnings("serial") public class GroupByException extends RuntimeException { diff --git a/src/main/java/com/zebrunner/carina/dataprovider/core/impl/CsvDataProvider.java b/src/main/java/com/zebrunner/carina/dataprovider/core/impl/CsvDataProvider.java index 8d10225..8de9b2d 100644 --- a/src/main/java/com/zebrunner/carina/dataprovider/core/impl/CsvDataProvider.java +++ b/src/main/java/com/zebrunner/carina/dataprovider/core/impl/CsvDataProvider.java @@ -15,28 +15,22 @@ *******************************************************************************/ package com.zebrunner.carina.dataprovider.core.impl; -import java.lang.annotation.Annotation; -import java.lang.invoke.MethodHandles; -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 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.testng.ITestContext; +import org.testng.ITestNGMethod; + +import java.lang.annotation.Annotation; +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 * diff --git a/src/main/java/com/zebrunner/carina/dataprovider/parser/DSBean.java b/src/main/java/com/zebrunner/carina/dataprovider/parser/DSBean.java index e264782..6596b47 100644 --- a/src/main/java/com/zebrunner/carina/dataprovider/parser/DSBean.java +++ b/src/main/java/com/zebrunner/carina/dataprovider/parser/DSBean.java @@ -65,7 +65,7 @@ public DSBean(ITestContext context) { } this.xlsSheet = testParams.get(SpecialKeywords.EXCEL_DS_SHEET); - this.argsToMap = this.args.size() == 0; + this.argsToMap = this.args.isEmpty(); } public DSBean(XlsDataSourceParameters xlsDataSourceParameters, Map suiteParams) { @@ -99,7 +99,7 @@ public DSBean(XlsDataSourceParameters xlsDataSourceParameters, Map suiteParams) { @@ -113,7 +113,7 @@ public DSBean(CsvDataSourceParameters csvDataSourceParameters, Map data = readData(dsBean, separator, quote); - if (data.size() == 0) { + if (data.isEmpty()) { throw new RuntimeException("Unable to retrieve data from CSV DataProvider! Verify separator and quote settings."); } @@ -39,7 +41,9 @@ private static List readData(DSBean dsBean, char separator, char quote List list = new ArrayList<>(); try { String csvFile = ClassLoader.getSystemResource(dsBean.getDsFile()).getFile(); - reader = new CSVReader(new FileReader(csvFile), separator, quote); + try (FileReader fileReader = new FileReader(csvFile)) { + reader = new CSVReader(fileReader, separator, quote); + } list = reader.readAll(); } catch (IOException e) { LOGGER.error("Unable to read data from CSV DataProvider", e); From cb9044f39b14c09c645fef4babf31f51c6c0c90c Mon Sep 17 00:00:00 2001 From: Andrei Kamarouski Date: Fri, 31 Mar 2023 13:11:29 +0300 Subject: [PATCH 7/7] change version of carina-utils to 1.0.3 --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 141503a..2d6630b 100644 --- a/pom.xml +++ b/pom.xml @@ -49,7 +49,7 @@ UTF-8 11 - 1.0.3.P2-SNAPSHOT + 1.0.3 1.7 1.7.30 3.5 @@ -62,7 +62,7 @@ 1.6 - +