From 175fcdabe46976db28fab7955d14351db8319f03 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Thu, 13 Jul 2023 11:39:59 +0300 Subject: [PATCH 1/6] Logging dependencies update --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index e4f6d1a..b00aa5e 100644 --- a/build.gradle +++ b/build.gradle @@ -44,7 +44,7 @@ dependencies { api 'com.google.code.findbugs:jsr305:3.0.2' implementation "io.cucumber:cucumber-gherkin:${project.cucumber_version}" - implementation 'org.slf4j:slf4j-api:2.0.4' + implementation 'org.slf4j:slf4j-api:2.0.7' testImplementation "io.cucumber:cucumber-java:${project.cucumber_version}" testImplementation 'com.epam.reportportal:agent-java-test-utils:0.0.2' @@ -53,7 +53,7 @@ dependencies { testImplementation 'org.hamcrest:hamcrest-core:2.2' testImplementation 'org.mockito:mockito-core:3.3.3' testImplementation 'org.mockito:mockito-junit-jupiter:3.3.3' - testImplementation 'ch.qos.logback:logback-classic:1.4.5' + testImplementation 'ch.qos.logback:logback-classic:1.4.8' testImplementation 'com.epam.reportportal:logger-java-logback:5.1.5' testImplementation ("org.junit.platform:junit-platform-runner:${project.junit_runner_version}") { exclude module: 'junit' From e644ed9264aa5dc92e3f0c569e46679aa355e3a8 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 8 Aug 2023 13:28:00 +0300 Subject: [PATCH 2/6] Maven Central link update --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index dbf0862..77f0e54 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -# Reportportal agent for Cucumber v.6 +# ReportPortal agent for Cucumber v.6 Cucumber JVM version [6.0.0; ) adapter -> **DISCLAIMER**: We use Google Analytics for sending anonymous usage information such as agent's and client's names, and their versions -> after a successful launch start. This information might help us to improve both ReportPortal backend and client sides. It is used by the -> ReportPortal team only and is not supposed for sharing with 3rd parties. +> **DISCLAIMER**: We use Google Analytics for sending anonymous usage information such as agent's and client's names, +> and their versions after a successful launch start. This information might help us to improve both ReportPortal +> backend and client sides. It is used by the ReportPortal team only and is not supposed for sharing with 3rd parties. -[![Maven Central](https://img.shields.io/maven-central/v/com.epam.reportportal/agent-java-cucumber6.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.epam.reportportal%22%20AND%20a:%22agent-java-cucumber6%22) +[![Maven Central](https://img.shields.io/maven-central/v/com.epam.reportportal/agent-java-cucumber6.svg?label=Maven%20Central)](https://central.sonatype.com/artifact/com.epam.reportportal/agent-java-cucumber6) [![CI Build](https://github.com/reportportal/agent-java-cucumber6/actions/workflows/ci.yml/badge.svg)](https://github.com/reportportal/agent-java-cucumber6/actions/workflows/ci.yml) [![codecov](https://codecov.io/gh/reportportal/agent-java-cucumber6/branch/develop/graph/badge.svg?token=GDQZ46X0H0)](https://codecov.io/gh/reportportal/agent-java-cucumber6) [![Join Slack chat!](https://slack.epmrpp.reportportal.io/badge.svg)](https://slack.epmrpp.reportportal.io/) From 623c25fc864bfc995764899ab112a884dd4b6f3e Mon Sep 17 00:00:00 2001 From: Dmitriy Gumeniuk Date: Fri, 8 Sep 2023 16:34:19 -0400 Subject: [PATCH 3/6] include v7 in description --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 77f0e54..21c04f0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# ReportPortal agent for Cucumber v.6 +# ReportPortal agent for Cucumber v.6 and v.7 Cucumber JVM version [6.0.0; ) adapter > **DISCLAIMER**: We use Google Analytics for sending anonymous usage information such as agent's and client's names, From c9fc7efffb9f3d7e9a5edc5cdada9969e3519fcf Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Wed, 17 Jan 2024 16:54:39 +0300 Subject: [PATCH 4/6] Version update --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 2c7edc6..db05fc7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -version=5.2.1-SNAPSHOT +version=5.3.0-SNAPSHOT description=EPAM Report portal. Cucumber JVM version [6.0.0; ) adapter cucumber_version=7.13.0 junit_version=5.6.3 From 7615fa52eabb9f5cda55c3dd9ccf8c92ff5fdcc7 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Thu, 18 Jan 2024 18:22:56 +0300 Subject: [PATCH 5/6] Client version update and refactoring --- CHANGELOG.md | 4 + build.gradle | 7 +- .../cucumber/AbstractReporter.java | 84 +++++------ .../cucumber/ScenarioReporter.java | 7 +- .../reportportal/cucumber/StepReporter.java | 7 +- .../com/epam/reportportal/cucumber/Utils.java | 133 +++--------------- .../ParameterScenarioReporterTest.java | 3 +- .../cucumber/ParameterStepReporterTest.java | 24 ++-- 8 files changed, 90 insertions(+), 179 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10a81d2..5b0a3c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog ## [Unreleased] +### Changed +- Client version updated on [5.2.0](https://github.com/reportportal/client-java/releases/tag/5.2.0), by @HardNorth +### Removed +- Deprecated code, by @HardNorth ## [5.2.0] ### Changed diff --git a/build.gradle b/build.gradle index b00aa5e..b28ab3a 100644 --- a/build.gradle +++ b/build.gradle @@ -39,7 +39,7 @@ repositories { } dependencies { - api 'com.epam.reportportal:client-java:5.1.22' + api 'com.epam.reportportal:client-java:5.2.1' api 'com.epam.reportportal:commons-model:5.0.0' api 'com.google.code.findbugs:jsr305:3.0.2' @@ -53,8 +53,8 @@ dependencies { testImplementation 'org.hamcrest:hamcrest-core:2.2' testImplementation 'org.mockito:mockito-core:3.3.3' testImplementation 'org.mockito:mockito-junit-jupiter:3.3.3' - testImplementation 'ch.qos.logback:logback-classic:1.4.8' - testImplementation 'com.epam.reportportal:logger-java-logback:5.1.5' + testImplementation 'ch.qos.logback:logback-classic:1.4.12' + testImplementation 'com.epam.reportportal:logger-java-logback:5.2.0' testImplementation ("org.junit.platform:junit-platform-runner:${project.junit_runner_version}") { exclude module: 'junit' } @@ -62,6 +62,7 @@ dependencies { testImplementation "org.junit.jupiter:junit-jupiter-params:${project.junit_version}" testImplementation "org.junit.jupiter:junit-jupiter-engine:${project.junit_version}" testImplementation 'org.apache.commons:commons-io:1.3.2' + testImplementation 'com.squareup.okhttp3:okhttp:4.12.0' } test { diff --git a/src/main/java/com/epam/reportportal/cucumber/AbstractReporter.java b/src/main/java/com/epam/reportportal/cucumber/AbstractReporter.java index 251400b..69a803d 100644 --- a/src/main/java/com/epam/reportportal/cucumber/AbstractReporter.java +++ b/src/main/java/com/epam/reportportal/cucumber/AbstractReporter.java @@ -18,6 +18,7 @@ import com.epam.reportportal.annotations.TestCaseId; import com.epam.reportportal.annotations.attribute.Attributes; import com.epam.reportportal.listeners.ItemStatus; +import com.epam.reportportal.listeners.ItemType; import com.epam.reportportal.listeners.ListenerParameters; import com.epam.reportportal.message.ReportPortalMessage; import com.epam.reportportal.service.Launch; @@ -25,19 +26,20 @@ import com.epam.reportportal.service.item.TestCaseIdEntry; import com.epam.reportportal.service.tree.TestItemTree; import com.epam.reportportal.utils.*; +import com.epam.reportportal.utils.files.ByteSource; +import com.epam.reportportal.utils.markdown.MarkdownUtils; import com.epam.reportportal.utils.properties.SystemAttributesExtractor; +import com.epam.reportportal.utils.reflect.Accessible; import com.epam.ta.reportportal.ws.model.FinishExecutionRQ; import com.epam.ta.reportportal.ws.model.FinishTestItemRQ; import com.epam.ta.reportportal.ws.model.ParameterResource; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; import com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ; import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ; -import com.google.common.io.ByteSource; import io.cucumber.core.gherkin.Feature; import io.cucumber.plugin.ConcurrentEventListener; import io.cucumber.plugin.event.*; import io.reactivex.Maybe; -import okhttp3.MediaType; import org.apache.commons.lang3.tuple.Pair; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,8 +48,6 @@ import javax.annotation.Nullable; import java.io.File; import java.io.IOException; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URI; import java.util.*; @@ -58,7 +58,6 @@ import static com.epam.reportportal.cucumber.Utils.*; import static com.epam.reportportal.cucumber.util.ItemTreeUtils.createKey; import static com.epam.reportportal.cucumber.util.ItemTreeUtils.retrieveLeaf; -import static java.util.Optional.of; import static java.util.Optional.ofNullable; import static org.apache.commons.lang3.StringUtils.isNotBlank; import static org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace; @@ -74,6 +73,7 @@ public abstract class AbstractReporter implements ConcurrentEventListener { private static final String NO_NAME = "No name"; private static final String AGENT_PROPERTIES_FILE = "agent.properties"; + private static final String DEFINITION_MATCH_FIELD_NAME = "definitionMatch"; private static final String STEP_DEFINITION_FIELD_NAME = "stepDefinition"; private static final String GET_LOCATION_METHOD_NAME = "getLocation"; private static final String COLON_INFIX = ": "; @@ -448,27 +448,18 @@ protected void afterStep(@Nonnull TestCase testCase, @Nonnull TestStep testStep, */ @Nonnull protected Pair getHookTypeAndName(@Nonnull HookType hookType) { - String name = null; - String type = null; switch (hookType) { case BEFORE: - name = "Before hooks"; - type = "BEFORE_TEST"; - break; + return Pair.of(ItemType.BEFORE_TEST.name(), "Before hooks"); case AFTER: - name = "After hooks"; - type = "AFTER_TEST"; - break; + return Pair.of(ItemType.AFTER_TEST.name(), "After hooks"); case AFTER_STEP: - name = "After step"; - type = "AFTER_METHOD"; - break; + return Pair.of(ItemType.AFTER_METHOD.name(), "After step"); case BEFORE_STEP: - name = "Before step"; - type = "BEFORE_METHOD"; - break; + return Pair.of(ItemType.BEFORE_METHOD.name(), "Before step"); + default: + return Pair.of(ItemType.TEST.name(), "Hook"); } - return Pair.of(type, name); } /** @@ -589,15 +580,7 @@ private static String getDataType(@Nonnull byte[] data, @Nullable String name) { * @param data data to attach */ protected void embedding(@Nullable String name, @Nullable String mimeType, @Nonnull byte[] data) { - String type = ofNullable(mimeType).filter(m -> { - try { - MediaType.get(m); - return true; - } catch (IllegalArgumentException e) { - LOGGER.warn("Incorrect media type '{}'", m); - return false; - } - }).orElseGet(() -> getDataType(data, name)); + String type = ofNullable(mimeType).orElseGet(() -> getDataType(data, name)); String attachmentName = ofNullable(name).filter(m -> !m.isEmpty()) .orElseGet(() -> ofNullable(type).map(t -> t.substring(0, t.indexOf("/"))).orElse("")); ReportPortal.emitLog(new ReportPortalMessage(ByteSource.wrap(data), type, attachmentName), @@ -976,7 +959,7 @@ protected String mapLevel(@Nullable Status cukesStatus) { */ @Nonnull protected String formatDataTable(@Nonnull final List> table) { - return Utils.formatDataTable(table); + return MarkdownUtils.formatDataTable(table); } /** @@ -1019,26 +1002,31 @@ protected String buildMultilineArgument(@Nonnull TestStep step) { */ @Nullable protected String getCodeRef(@Nonnull TestStep testStep) { - return ofNullable(getDefinitionMatchField(testStep)).flatMap(match -> { - try { - Object stepDefinitionMatch = match.get(testStep); - Field stepDefinitionField = stepDefinitionMatch.getClass().getDeclaredField(STEP_DEFINITION_FIELD_NAME); - stepDefinitionField.setAccessible(true); - Object javaStepDefinition = stepDefinitionField.get(stepDefinitionMatch); - Method getLocationMethod = javaStepDefinition.getClass().getMethod(GET_LOCATION_METHOD_NAME); - getLocationMethod.setAccessible(true); - return of(String.valueOf(getLocationMethod.invoke(javaStepDefinition))).filter(r -> !r.isEmpty()).map(r -> { - int openingBracketIndex = r.indexOf(METHOD_OPENING_BRACKET); - if (openingBracketIndex > 0) { - return r.substring(0, r.indexOf(METHOD_OPENING_BRACKET)); - } else { - return r; + String cucumberLocation = testStep.getCodeLocation(); + try { + Object stepDefinitionMatch = Accessible.on(testStep).field(DEFINITION_MATCH_FIELD_NAME).getValue(); + if (stepDefinitionMatch != null) { + Object javaStepDefinition = Accessible.on(stepDefinitionMatch).field(STEP_DEFINITION_FIELD_NAME).getValue(); + if (javaStepDefinition != null) { + Object codeLocationObject = Accessible.on(javaStepDefinition).method(GET_LOCATION_METHOD_NAME).invoke(); + if (codeLocationObject != null) { + String codeLocation = codeLocationObject.toString(); + if (isNotBlank(codeLocation)) { + int openingBracketIndex = codeLocation.indexOf(METHOD_OPENING_BRACKET); + if (openingBracketIndex > 0) { + return codeLocation.substring(0, codeLocation.indexOf(METHOD_OPENING_BRACKET)); + } else { + return codeLocation; + } + } } - }); - } catch (NoSuchFieldException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignore) { + } } - return Optional.empty(); - }).orElseGet(testStep::getCodeLocation); + } catch (Throwable e) { + LOGGER.error("Unable to get java code reference for the Test Step: " + cucumberLocation, e); + return cucumberLocation; + } + return cucumberLocation; } /** diff --git a/src/main/java/com/epam/reportportal/cucumber/ScenarioReporter.java b/src/main/java/com/epam/reportportal/cucumber/ScenarioReporter.java index 25adf2d..0a7bb88 100644 --- a/src/main/java/com/epam/reportportal/cucumber/ScenarioReporter.java +++ b/src/main/java/com/epam/reportportal/cucumber/ScenarioReporter.java @@ -15,6 +15,7 @@ */ package com.epam.reportportal.cucumber; +import com.epam.reportportal.listeners.ItemType; import com.epam.reportportal.utils.MemoizingSupplier; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; import io.cucumber.plugin.event.HookTestStep; @@ -47,9 +48,9 @@ * @author Vadzim Hushchanskou */ public class ScenarioReporter extends AbstractReporter { - private static final String RP_STORY_TYPE = "SUITE"; - private static final String RP_TEST_TYPE = "STORY"; - private static final String RP_STEP_TYPE = "STEP"; + private static final String RP_STORY_TYPE = ItemType.SUITE.name(); + private static final String RP_TEST_TYPE = ItemType.STORY.name(); + private static final String RP_STEP_TYPE = ItemType.STEP.name(); private static final String DUMMY_ROOT_SUITE_NAME = "Root User Story"; protected MemoizingSupplier> rootSuiteId; diff --git a/src/main/java/com/epam/reportportal/cucumber/StepReporter.java b/src/main/java/com/epam/reportportal/cucumber/StepReporter.java index b5294e7..8c55382 100644 --- a/src/main/java/com/epam/reportportal/cucumber/StepReporter.java +++ b/src/main/java/com/epam/reportportal/cucumber/StepReporter.java @@ -15,6 +15,7 @@ */ package com.epam.reportportal.cucumber; +import com.epam.reportportal.listeners.ItemType; import io.reactivex.Maybe; import javax.annotation.Nonnull; @@ -37,10 +38,12 @@ * steps!) * * @author Vadzim Hushchanskou + * @deprecated Use {@link ScenarioReporter}, since the semantic of this class is completely broken and will be removed */ +@Deprecated(forRemoval = true, since = "5.3.0") public class StepReporter extends AbstractReporter { - private static final String RP_STORY_TYPE = "STORY"; - private static final String RP_TEST_TYPE = "SCENARIO"; + private static final String RP_STORY_TYPE = ItemType.STORY.name(); + private static final String RP_TEST_TYPE = ItemType.SCENARIO.name(); public StepReporter() { super(); diff --git a/src/main/java/com/epam/reportportal/cucumber/Utils.java b/src/main/java/com/epam/reportportal/cucumber/Utils.java index d3ba796..5b29992 100644 --- a/src/main/java/com/epam/reportportal/cucumber/Utils.java +++ b/src/main/java/com/epam/reportportal/cucumber/Utils.java @@ -19,16 +19,11 @@ import io.cucumber.core.gherkin.Feature; import io.cucumber.plugin.event.Argument; import io.cucumber.plugin.event.Status; -import io.cucumber.plugin.event.TestStep; -import com.google.common.collect.ImmutableMap; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.lang.reflect.Field; -import java.lang.reflect.Method; import java.util.*; import java.util.stream.Collectors; -import java.util.stream.IntStream; import static java.util.Optional.ofNullable; @@ -39,15 +34,6 @@ */ public class Utils { private static final String EMPTY = ""; - - private static final String DEFINITION_MATCH_FIELD_NAME = "definitionMatch"; - private static final String STEP_DEFINITION_FIELD_NAME = "stepDefinition"; - private static final String METHOD_FIELD_NAME = "method"; - public static final String ONE_SPACE = "\u00A0"; - public static final String NEW_LINE = "\r\n"; - public static final String TABLE_INDENT = "\u00A0\u00A0\u00A0\u00A0"; - public static final String TABLE_COLUMN_SEPARATOR = "|"; - public static final String TABLE_ROW_SEPARATOR = "-"; public static final String TAG_KEY = "@"; private Utils() { @@ -55,24 +41,26 @@ private Utils() { } //@formatter:off - public static final Map STATUS_MAPPING = ImmutableMap.builder() - .put(Status.PASSED, ItemStatus.PASSED) - .put(Status.FAILED, ItemStatus.FAILED) - .put(Status.SKIPPED, ItemStatus.SKIPPED) - .put(Status.PENDING, ItemStatus.SKIPPED) - .put(Status.AMBIGUOUS, ItemStatus.SKIPPED) - .put(Status.UNDEFINED, ItemStatus.SKIPPED) - .put(Status.UNUSED, ItemStatus.SKIPPED).build(); - - public static final Map LOG_LEVEL_MAPPING = ImmutableMap.builder() - .put(Status.PASSED, "INFO") - .put(Status.FAILED, "ERROR") - .put(Status.SKIPPED, "WARN") - .put(Status.PENDING, "WARN") - .put(Status.AMBIGUOUS, "WARN") - .put(Status.UNDEFINED, "WARN") - .put(Status.UNUSED, "WARN").build(); - //@formatter:on + public static final Map STATUS_MAPPING = Map.of( + Status.PASSED, ItemStatus.PASSED, + Status.FAILED, ItemStatus.FAILED, + Status.SKIPPED, ItemStatus.SKIPPED, + Status.PENDING, ItemStatus.SKIPPED, + Status.AMBIGUOUS, ItemStatus.SKIPPED, + Status.UNDEFINED, ItemStatus.SKIPPED, + Status.UNUSED, ItemStatus.SKIPPED + ); + + public static final Map LOG_LEVEL_MAPPING = Map.of( + Status.PASSED, "INFO", + Status.FAILED, "ERROR", + Status.SKIPPED, "WARN", + Status.PENDING, "WARN", + Status.AMBIGUOUS, "WARN", + Status.UNDEFINED, "WARN", + Status.UNUSED, "WARN" + ); + //@formatter:on /** * Generate name representation @@ -86,84 +74,9 @@ public static String buildName(@Nullable String prefix, @Nullable String infix, return (prefix == null ? EMPTY : prefix) + infix + argument; } - @Deprecated - public static Method retrieveMethod(Field definitionMatchField, TestStep testStep) throws IllegalAccessException, NoSuchFieldException { - Object stepDefinitionMatch = definitionMatchField.get(testStep); - Field stepDefinitionField = stepDefinitionMatch.getClass().getDeclaredField(STEP_DEFINITION_FIELD_NAME); - stepDefinitionField.setAccessible(true); - Object javaStepDefinition = stepDefinitionField.get(stepDefinitionMatch); - Field methodField = javaStepDefinition.getClass().getSuperclass().getDeclaredField(METHOD_FIELD_NAME); - methodField.setAccessible(true); - return (Method) methodField.get(javaStepDefinition); - } - public static final java.util.function.Function, List> ARGUMENTS_TRANSFORM = arguments -> ofNullable(arguments).map( args -> args.stream().map(Argument::getValue).collect(Collectors.toList())).orElse(null); - public static Field getDefinitionMatchField(TestStep testStep) { - Class clazz = testStep.getClass(); - try { - return clazz.getField(DEFINITION_MATCH_FIELD_NAME); - } catch (NoSuchFieldException e) { - do { - try { - Field definitionMatchField = clazz.getDeclaredField(DEFINITION_MATCH_FIELD_NAME); - definitionMatchField.setAccessible(true); - return definitionMatchField; - } catch (NoSuchFieldException ignore) { - } - - clazz = clazz.getSuperclass(); - } while (clazz != null); - - return null; - } - } - - /** - * Converts a table represented as List of Lists to a formatted table string - * - * @param table a table object - * @return string representation of the table - */ - @Nonnull - public static String formatDataTable(@Nonnull final List> table) { - StringBuilder result = new StringBuilder(); - int tableLength = table.stream().mapToInt(List::size).max().orElse(-1); - List> iterList = table.stream().map(List::iterator).collect(Collectors.toList()); - List colSizes = IntStream.range(0, tableLength) - .mapToObj(n -> iterList.stream().filter(Iterator::hasNext).map(Iterator::next).collect(Collectors.toList())) - .map(col -> col.stream().mapToInt(String::length).max().orElse(0)) - .collect(Collectors.toList()); - - boolean header = true; - for (List row : table) { - result.append(TABLE_INDENT).append(TABLE_COLUMN_SEPARATOR); - for (int i = 0; i < row.size(); i++) { - String cell = row.get(i); - int maxSize = colSizes.get(i) - cell.length() + 2; - int lSpace = maxSize / 2; - int rSpace = maxSize - lSpace; - IntStream.range(0, lSpace).forEach(j -> result.append(ONE_SPACE)); - result.append(cell); - IntStream.range(0, rSpace).forEach(j -> result.append(ONE_SPACE)); - result.append(TABLE_COLUMN_SEPARATOR); - } - if(header) { - header = false; - result.append(NEW_LINE); - result.append(TABLE_INDENT).append(TABLE_COLUMN_SEPARATOR); - for (int i = 0; i < row.size(); i++) { - int maxSize = colSizes.get(i) + 2; - IntStream.range(0, maxSize).forEach(j -> result.append(TABLE_ROW_SEPARATOR)); - result.append(TABLE_COLUMN_SEPARATOR); - } - } - result.append(NEW_LINE); - } - return result.toString().trim(); - } - /** * Parses a feature source and return all declared tags before the feature. * @@ -172,11 +85,11 @@ public static String formatDataTable(@Nonnull final List> table) { */ @Nonnull public static Set getTags(@Nonnull Feature feature) { - return feature.getKeyword().map(k->{ + return feature.getKeyword().map(k -> { Set tags = new HashSet<>(); - for(String line : feature.getSource().split("\\r?\\n")) { + for (String line : feature.getSource().split("\\r?\\n")) { String bareLine = line.trim(); - if(bareLine.startsWith(k)) { + if (bareLine.startsWith(k)) { return tags; } if (!line.startsWith(TAG_KEY)) { diff --git a/src/test/java/com/epam/reportportal/cucumber/ParameterScenarioReporterTest.java b/src/test/java/com/epam/reportportal/cucumber/ParameterScenarioReporterTest.java index 7dfe473..941b310 100644 --- a/src/test/java/com/epam/reportportal/cucumber/ParameterScenarioReporterTest.java +++ b/src/test/java/com/epam/reportportal/cucumber/ParameterScenarioReporterTest.java @@ -23,6 +23,7 @@ import com.epam.reportportal.service.ReportPortal; import com.epam.reportportal.service.ReportPortalClient; import com.epam.reportportal.util.test.CommonUtils; +import com.epam.reportportal.utils.markdown.MarkdownUtils; import com.epam.ta.reportportal.ws.model.ParameterResource; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; import com.epam.ta.reportportal.ws.model.log.SaveLogRQ; @@ -73,7 +74,7 @@ public static class DataTableParameterTest extends AbstractTestNGCucumberTests { } private static final String DOCSTRING_PARAM = "My very long parameter\nWith some new lines"; - private static final String TABLE_PARAM = Utils.formatDataTable(Arrays.asList(Arrays.asList("key", "value"), + private static final String TABLE_PARAM = MarkdownUtils.formatDataTable(Arrays.asList(Arrays.asList("key", "value"), Arrays.asList("myKey", "myValue") )); diff --git a/src/test/java/com/epam/reportportal/cucumber/ParameterStepReporterTest.java b/src/test/java/com/epam/reportportal/cucumber/ParameterStepReporterTest.java index 7ab9d09..613f534 100644 --- a/src/test/java/com/epam/reportportal/cucumber/ParameterStepReporterTest.java +++ b/src/test/java/com/epam/reportportal/cucumber/ParameterStepReporterTest.java @@ -23,6 +23,7 @@ import com.epam.reportportal.service.ReportPortal; import com.epam.reportportal.service.ReportPortalClient; import com.epam.reportportal.util.test.CommonUtils; +import com.epam.reportportal.utils.markdown.MarkdownUtils; import com.epam.ta.reportportal.ws.model.ParameterResource; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; import com.epam.ta.reportportal.ws.model.log.SaveLogRQ; @@ -56,39 +57,38 @@ public class ParameterStepReporterTest { @CucumberOptions(features = "src/test/resources/features/BasicScenarioOutlineParameters.feature", glue = { "com.epam.reportportal.cucumber.integration.feature" }, plugin = { "pretty", "com.epam.reportportal.cucumber.integration.TestStepReporter" }) - public static class RunOutlineParametersTestStepReporter extends AbstractTestNGCucumberTests { + public static class RunOutlineParametersTestStepReporterTest extends AbstractTestNGCucumberTests { } @CucumberOptions(features = "src/test/resources/features/TwoScenarioOutlineParameters.feature", glue = { "com.epam.reportportal.cucumber.integration.feature" }, plugin = { "pretty", "com.epam.reportportal.cucumber.integration.TestStepReporter" }) - public static class RunTwoOutlineParametersTestStepReporter extends AbstractTestNGCucumberTests { + public static class RunTwoOutlineParametersTestStepReporterTest extends AbstractTestNGCucumberTests { } @CucumberOptions(features = "src/test/resources/features/BasicInlineParameters.feature", glue = { "com.epam.reportportal.cucumber.integration.feature" }, plugin = { "pretty", "com.epam.reportportal.cucumber.integration.TestStepReporter" }) - public static class InlineParametersTestStepReporter extends AbstractTestNGCucumberTests { + public static class InlineParametersTestStepReporterTest extends AbstractTestNGCucumberTests { } @CucumberOptions(features = "src/test/resources/features/DocStringParameters.feature", glue = { "com.epam.reportportal.cucumber.integration.feature" }, plugin = { "pretty", "com.epam.reportportal.cucumber.integration.TestStepReporter" }) - public static class DocstringParameterTestStepReporter extends AbstractTestNGCucumberTests { + public static class DocstringParameterTestStepReporterTest extends AbstractTestNGCucumberTests { } @CucumberOptions(features = "src/test/resources/features/DataTableParameter.feature", glue = { "com.epam.reportportal.cucumber.integration.feature" }, plugin = { "pretty", "com.epam.reportportal.cucumber.integration.TestStepReporter" }) - public static class DataTableParameterTestStepReporter extends AbstractTestNGCucumberTests { + public static class DataTableParameterTestStepReporterTest extends AbstractTestNGCucumberTests { } private static final String DOCSTRING_PARAM = "My very long parameter\nWith some new lines"; - private static final String TABLE_PARAM = Utils.formatDataTable(Arrays.asList( - Arrays.asList("key", "value"), + private static final String TABLE_PARAM = MarkdownUtils.formatDataTable(Arrays.asList(Arrays.asList("key", "value"), Arrays.asList("myKey", "myValue") )); @@ -129,7 +129,7 @@ public void initLaunch() { @Test public void verify_agent_retrieves_parameters_from_request() { - TestUtils.runTests(RunOutlineParametersTestStepReporter.class); + TestUtils.runTests(RunOutlineParametersTestStepReporterTest.class); verify(client, times(1)).startTestItem(any()); verify(client, times(3)).startTestItem(same(suiteId), any()); @@ -163,7 +163,7 @@ public void verify_agent_retrieves_parameters_from_request() { @Test public void verify_agent_retrieves_two_parameters_from_request() { - TestUtils.runTests(RunTwoOutlineParametersTestStepReporter.class); + TestUtils.runTests(RunTwoOutlineParametersTestStepReporterTest.class); verify(client, times(1)).startTestItem(any()); verify(client, times(3)).startTestItem(same(suiteId), any()); @@ -185,7 +185,7 @@ public void verify_agent_retrieves_two_parameters_from_request() { @Test public void verify_inline_parameters() { - TestUtils.runTests(InlineParametersTestStepReporter.class); + TestUtils.runTests(InlineParametersTestStepReporterTest.class); ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); verify(client, times(3)).startTestItem(same(testIds.get(0)), captor.capture()); @@ -210,7 +210,7 @@ public void verify_inline_parameters() { @Test @SuppressWarnings("unchecked") public void verify_docstring_parameters() { - TestUtils.runTests(DocstringParameterTestStepReporter.class); + TestUtils.runTests(DocstringParameterTestStepReporterTest.class); ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); verify(client, times(2)).startTestItem(same(testIds.get(0)), captor.capture()); @@ -235,7 +235,7 @@ public void verify_docstring_parameters() { @Test @SuppressWarnings("unchecked") public void verify_data_table_parameters() { - TestUtils.runTests(DataTableParameterTestStepReporter.class); + TestUtils.runTests(DataTableParameterTestStepReporterTest.class); ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); verify(client, times(1)).startTestItem(same(testIds.get(0)), captor.capture()); From a7d21bfe3104eb795a0adcac37c23dc9b520e4e2 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Fri, 19 Jan 2024 12:29:51 +0300 Subject: [PATCH 6/6] Fix tests --- build.gradle | 2 +- .../cucumber/AbstractReporter.java | 11 +++++- .../reportportal/cucumber/EmbeddingTest.java | 37 +++++++++---------- .../embedding/ImageEmbeddingFeature.feature | 2 +- 4 files changed, 30 insertions(+), 22 deletions(-) diff --git a/build.gradle b/build.gradle index b28ab3a..d76b677 100644 --- a/build.gradle +++ b/build.gradle @@ -43,6 +43,7 @@ dependencies { api 'com.epam.reportportal:commons-model:5.0.0' api 'com.google.code.findbugs:jsr305:3.0.2' + implementation 'com.squareup.okhttp3:okhttp:4.12.0' implementation "io.cucumber:cucumber-gherkin:${project.cucumber_version}" implementation 'org.slf4j:slf4j-api:2.0.7' @@ -62,7 +63,6 @@ dependencies { testImplementation "org.junit.jupiter:junit-jupiter-params:${project.junit_version}" testImplementation "org.junit.jupiter:junit-jupiter-engine:${project.junit_version}" testImplementation 'org.apache.commons:commons-io:1.3.2' - testImplementation 'com.squareup.okhttp3:okhttp:4.12.0' } test { diff --git a/src/main/java/com/epam/reportportal/cucumber/AbstractReporter.java b/src/main/java/com/epam/reportportal/cucumber/AbstractReporter.java index 69a803d..854eec7 100644 --- a/src/main/java/com/epam/reportportal/cucumber/AbstractReporter.java +++ b/src/main/java/com/epam/reportportal/cucumber/AbstractReporter.java @@ -40,6 +40,7 @@ import io.cucumber.plugin.ConcurrentEventListener; import io.cucumber.plugin.event.*; import io.reactivex.Maybe; +import okhttp3.MediaType; import org.apache.commons.lang3.tuple.Pair; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -580,7 +581,15 @@ private static String getDataType(@Nonnull byte[] data, @Nullable String name) { * @param data data to attach */ protected void embedding(@Nullable String name, @Nullable String mimeType, @Nonnull byte[] data) { - String type = ofNullable(mimeType).orElseGet(() -> getDataType(data, name)); + String type = ofNullable(mimeType).filter(m -> { + try { + MediaType.get(m); + return true; + } catch (IllegalArgumentException e) { + LOGGER.warn("Incorrect media type '{}'", m); + return false; + } + }).orElseGet(() -> getDataType(data, name)); String attachmentName = ofNullable(name).filter(m -> !m.isEmpty()) .orElseGet(() -> ofNullable(type).map(t -> t.substring(0, t.indexOf("/"))).orElse("")); ReportPortal.emitLog(new ReportPortalMessage(ByteSource.wrap(data), type, attachmentName), diff --git a/src/test/java/com/epam/reportportal/cucumber/EmbeddingTest.java b/src/test/java/com/epam/reportportal/cucumber/EmbeddingTest.java index 2fd7b7e..04fad6e 100644 --- a/src/test/java/com/epam/reportportal/cucumber/EmbeddingTest.java +++ b/src/test/java/com/epam/reportportal/cucumber/EmbeddingTest.java @@ -54,42 +54,42 @@ public class EmbeddingTest { @CucumberOptions(features = "src/test/resources/features/embedding/ImageEmbeddingFeature.feature", glue = { "com.epam.reportportal.cucumber.integration.embed.image" }, plugin = { "pretty", "com.epam.reportportal.cucumber.integration.TestStepReporter" }) - public static class ImageStepReporter extends AbstractTestNGCucumberTests { + public static class ImageStepReporterTest extends AbstractTestNGCucumberTests { } @CucumberOptions(features = "src/test/resources/features/embedding/TextEmbeddingFeature.feature", glue = { "com.epam.reportportal.cucumber.integration.embed.text" }, plugin = { "pretty", "com.epam.reportportal.cucumber.integration.TestStepReporter" }) - public static class TextStepReporter extends AbstractTestNGCucumberTests { + public static class TextStepReporterTest extends AbstractTestNGCucumberTests { } @CucumberOptions(features = "src/test/resources/features/embedding/PdfEmbeddingFeature.feature", glue = { "com.epam.reportportal.cucumber.integration.embed.pdf" }, plugin = { "pretty", "com.epam.reportportal.cucumber.integration.TestStepReporter" }) - public static class PdfStepReporter extends AbstractTestNGCucumberTests { + public static class PdfStepReporterTest extends AbstractTestNGCucumberTests { } @CucumberOptions(features = "src/test/resources/features/embedding/ArchiveEmbeddingFeature.feature", glue = { "com.epam.reportportal.cucumber.integration.embed.zip" }, plugin = { "pretty", "com.epam.reportportal.cucumber.integration.TestStepReporter" }) - public static class ZipStepReporter extends AbstractTestNGCucumberTests { + public static class ZipStepReporterTest extends AbstractTestNGCucumberTests { } @CucumberOptions(features = "src/test/resources/features/embedding/EmbedImageWithoutName.feature", glue = { "com.epam.reportportal.cucumber.integration.embed.image" }, plugin = { "pretty", "com.epam.reportportal.cucumber.integration.TestStepReporter" }) - public static class ImageNoNameStepReporter extends AbstractTestNGCucumberTests { + public static class ImageNoNameStepReporterTest extends AbstractTestNGCucumberTests { } @CucumberOptions(features = "src/test/resources/features/embedding/EmbedImageWithEmptyName.feature", glue = { "com.epam.reportportal.cucumber.integration.embed.image" }, plugin = { "pretty", "com.epam.reportportal.cucumber.integration.TestStepReporter" }) - public static class ImageEmptyNameStepReporter extends AbstractTestNGCucumberTests { + public static class ImageEmptyNameStepReporterTest extends AbstractTestNGCucumberTests { } @@ -129,7 +129,7 @@ private static List getLogFiles(String name, ArgumentCaptor< @Test public void verify_image_embedding() { - TestUtils.runTests(ImageStepReporter.class); + TestUtils.runTests(ImageStepReporterTest.class); ArgumentCaptor> logCaptor = ArgumentCaptor.forClass(List.class); verify(client, atLeastOnce()).log(logCaptor.capture()); @@ -138,16 +138,15 @@ public void verify_image_embedding() { List types = logs.stream() .flatMap(l -> getLogFiles(l.getFile().getName(), logCaptor).stream()) - .flatMap(f -> ofNullable(f.body().contentType()).map(MediaType::toString).map(Stream::of).orElse(Stream.empty())) + .flatMap(f -> ofNullable(f.body().contentType()).map(MediaType::toString).stream()) .collect(Collectors.toList()); assertThat(types, hasSize(3)); assertThat(types, containsInAnyOrder("image/jpeg", "image/png", "image/jpeg")); - } @Test public void verify_text_embedding() { - TestUtils.runTests(TextStepReporter.class); + TestUtils.runTests(TextStepReporterTest.class); ArgumentCaptor> logCaptor = ArgumentCaptor.forClass(List.class); verify(client, atLeastOnce()).log(logCaptor.capture()); @@ -155,7 +154,7 @@ public void verify_text_embedding() { List types = logs.stream() .flatMap(l -> getLogFiles(l.getFile().getName(), logCaptor).stream()) - .flatMap(f -> ofNullable(f.body().contentType()).map(MediaType::toString).map(Stream::of).orElse(Stream.empty())) + .flatMap(f -> ofNullable(f.body().contentType()).map(MediaType::toString).stream()) .collect(Collectors.toList()); assertThat(types, hasSize(3)); @@ -164,7 +163,7 @@ public void verify_text_embedding() { @Test public void verify_pfd_embedding() { - TestUtils.runTests(PdfStepReporter.class); + TestUtils.runTests(PdfStepReporterTest.class); ArgumentCaptor> logCaptor = ArgumentCaptor.forClass(List.class); verify(client, atLeastOnce()).log(logCaptor.capture()); @@ -174,7 +173,7 @@ public void verify_pfd_embedding() { List types = logs.stream() .flatMap(l -> getLogFiles(l.getFile().getName(), logCaptor).stream()) - .flatMap(f -> ofNullable(f.body().contentType()).map(MediaType::toString).map(Stream::of).orElse(Stream.empty())) + .flatMap(f -> ofNullable(f.body().contentType()).map(MediaType::toString).stream()) .collect(Collectors.toList()); assertThat(types, hasSize(3)); assertThat(types, containsInAnyOrder("application/pdf", "image/png", "application/octet-stream")); @@ -182,7 +181,7 @@ public void verify_pfd_embedding() { @Test public void verify_archive_embedding() { - TestUtils.runTests(ZipStepReporter.class); + TestUtils.runTests(ZipStepReporterTest.class); ArgumentCaptor> logCaptor = ArgumentCaptor.forClass(List.class); verify(client, atLeastOnce()).log(logCaptor.capture()); @@ -190,7 +189,7 @@ public void verify_archive_embedding() { List types = logs.stream() .flatMap(l -> getLogFiles(l.getFile().getName(), logCaptor).stream()) - .flatMap(f -> ofNullable(f.body().contentType()).map(MediaType::toString).map(Stream::of).orElse(Stream.empty())) + .flatMap(f -> ofNullable(f.body().contentType()).map(MediaType::toString).stream()) .collect(Collectors.toList()); assertThat(types, hasSize(3)); assertThat(types, containsInAnyOrder("application/zip", "image/png", "application/octet-stream")); @@ -198,7 +197,7 @@ public void verify_archive_embedding() { @Test public void verify_image_no_name_embedding() { - TestUtils.runTests(ImageNoNameStepReporter.class); + TestUtils.runTests(ImageNoNameStepReporterTest.class); ArgumentCaptor> logCaptor = ArgumentCaptor.forClass(List.class); verify(client, atLeastOnce()).log(logCaptor.capture()); @@ -208,7 +207,7 @@ public void verify_image_no_name_embedding() { List types = logs.stream() .flatMap(l -> getLogFiles(l.getFile().getName(), logCaptor).stream()) - .flatMap(f -> ofNullable(f.body().contentType()).map(MediaType::toString).map(Stream::of).orElse(Stream.empty())) + .flatMap(f -> ofNullable(f.body().contentType()).map(MediaType::toString).stream()) .collect(Collectors.toList()); assertThat(types, hasSize(1)); assertThat(types, containsInAnyOrder("image/jpeg")); @@ -216,7 +215,7 @@ public void verify_image_no_name_embedding() { @Test public void verify_image_empty_name_embedding() { - TestUtils.runTests(ImageEmptyNameStepReporter.class); + TestUtils.runTests(ImageEmptyNameStepReporterTest.class); ArgumentCaptor> logCaptor = ArgumentCaptor.forClass(List.class); verify(client, atLeastOnce()).log(logCaptor.capture()); @@ -226,7 +225,7 @@ public void verify_image_empty_name_embedding() { List types = logs.stream() .flatMap(l -> getLogFiles(l.getFile().getName(), logCaptor).stream()) - .flatMap(f -> ofNullable(f.body().contentType()).map(MediaType::toString).map(Stream::of).orElse(Stream.empty())) + .flatMap(f -> ofNullable(f.body().contentType()).map(MediaType::toString).stream()) .collect(Collectors.toList()); assertThat(types, hasSize(1)); assertThat(types, containsInAnyOrder("image/jpeg")); diff --git a/src/test/resources/features/embedding/ImageEmbeddingFeature.feature b/src/test/resources/features/embedding/ImageEmbeddingFeature.feature index 243449d..feab8e2 100644 --- a/src/test/resources/features/embedding/ImageEmbeddingFeature.feature +++ b/src/test/resources/features/embedding/ImageEmbeddingFeature.feature @@ -7,4 +7,4 @@ Feature: Image embedding feature Given I have a dummy step to make a screenshot with incorrect mime type Scenario: Embed a partially correct mime type image - Given I have a dummy step to make a screenshot with partially correct mime type \ No newline at end of file + Given I have a dummy step to make a screenshot with partially correct mime type