Skip to content

Commit

Permalink
Client version update
Browse files Browse the repository at this point in the history
  • Loading branch information
HardNorth committed Jan 19, 2024
1 parent da63540 commit d60362a
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 148 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changelog

## [Unreleased]
### Changed
- Client version updated on [5.2.0](https://github.com/reportportal/client-java/releases/tag/5.2.0), by @HardNorth

## [5.1.4]
### Changed
Expand Down
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ 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'
api "io.cucumber:cucumber-java:${project.cucumber_version}"

implementation 'com.squareup.okhttp3:okhttp:4.12.0'
implementation 'org.slf4j:slf4j-api:2.0.7'

testImplementation 'com.epam.reportportal:agent-java-test-utils:0.0.2'
Expand All @@ -50,8 +51,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.3.8'
testImplementation 'com.epam.reportportal:logger-java-logback:5.1.5'
testImplementation 'ch.qos.logback:logback-classic:1.3.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'
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=5.1.5-SNAPSHOT
version=5.2.0-SNAPSHOT
description=EPAM Report portal. Cucumber JVM version [5.0.0; 6.0.0) adapter
cucumber_version=5.7.0
junit_version=5.6.3
Expand Down
87 changes: 43 additions & 44 deletions src/main/java/com/epam/reportportal/cucumber/AbstractReporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,24 @@
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;
import com.epam.reportportal.service.ReportPortal;
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.internal.gherkin.ast.Feature;
import io.cucumber.core.internal.gherkin.ast.Step;
import io.cucumber.core.internal.gherkin.ast.Tag;
Expand All @@ -48,8 +51,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.*;
Expand All @@ -61,7 +62,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;
Expand All @@ -82,6 +82,7 @@ public abstract class AbstractReporter implements ConcurrentEventListener {
private static final String HOOK_ = "Hook: ";
private static final String GET_LOCATION_METHOD_NAME = "getLocation";
private static final String METHOD_OPENING_BRACKET = "(";
private static final String DEFINITION_MATCH_FIELD_NAME = "definitionMatch";
private static final String STEP_DEFINITION_FIELD_NAME = "stepDefinition";
private static final String DOCSTRING_DECORATOR = "\n\"\"\"\n";

Expand Down Expand Up @@ -714,6 +715,7 @@ protected void finishFeature(@Nullable Maybe<String> itemId, @Nullable Date date
LOGGER.error("BUG: Trying to finish unspecified test item.");
return;
}
//noinspection ReactiveStreamsUnusedPublisher
launch.get().finishTestItem(itemId, buildFinishTestItemRequest(itemId, dateTime, null));
}

Expand All @@ -732,6 +734,7 @@ protected Date finishTestItem(@Nullable Maybe<String> itemId, @Nullable Status s
}
FinishTestItemRQ rq = buildFinishTestItemRequest(itemId, null, mapItemStatus(status));
new FinishTestItemRQ();
//noinspection ReactiveStreamsUnusedPublisher
launch.get().finishTestItem(itemId, rq);
return rq.getEndTime();
}
Expand Down Expand Up @@ -789,7 +792,7 @@ protected String mapLevel(@Nullable Status cukesStatus) {
*/
@Nonnull
protected String formatDataTable(@Nonnull final List<List<String>> table) {
return Utils.formatDataTable(table);
return MarkdownUtils.formatDataTable(table);
}

/**
Expand Down Expand Up @@ -851,10 +854,10 @@ protected Set<ItemAttributesRQ> extractAttributes(@Nonnull List<?> tags) {
*/
@Nullable
protected Set<ItemAttributesRQ> getAttributes(@Nonnull TestStep testStep) {
Field definitionMatchField = getDefinitionMatchField(testStep);
if (definitionMatchField != null) {
Object definitionMatch = getDefinitionMatch(testStep);
if (definitionMatch != null) {
try {
Method method = retrieveMethod(definitionMatchField, testStep);
Method method = retrieveMethod(definitionMatch);
Attributes attributesAnnotation = method.getAnnotation(Attributes.class);
if (attributesAnnotation != null) {
return AttributeParser.retrieveAttributes(attributesAnnotation);
Expand All @@ -874,26 +877,31 @@ protected Set<ItemAttributesRQ> getAttributes(@Nonnull TestStep testStep) {
*/
@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;
}

/**
Expand Down Expand Up @@ -950,11 +958,11 @@ protected List<ParameterResource> getParameters(@Nullable String codeRef, @Nonnu
@Nullable
@SuppressWarnings("unchecked")
protected TestCaseIdEntry getTestCaseId(@Nonnull TestStep testStep, @Nullable String codeRef) {
Field definitionMatchField = getDefinitionMatchField(testStep);
Object definitionMatch = getDefinitionMatch(testStep);
List<Argument> arguments = ((PickleStepTestStep) testStep).getDefinitionArgument();
if (definitionMatchField != null) {
if (definitionMatch != null) {
try {
Method method = retrieveMethod(definitionMatchField, testStep);
Method method = retrieveMethod(definitionMatch);
return TestCaseIdUtils.getTestCaseId(method.getAnnotation(TestCaseId.class),
method,
codeRef,
Expand Down Expand Up @@ -1013,26 +1021,17 @@ protected String getDescription(@Nonnull TestCase testCase, @Nonnull URI uri) {
*/
@Nonnull
protected Pair<String, String> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.HookType;
Expand Down Expand Up @@ -48,9 +49,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<Maybe<String>> rootSuiteId;
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/com/epam/reportportal/cucumber/StepReporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.epam.reportportal.cucumber;

import com.epam.reportportal.listeners.ItemType;
import io.reactivex.Maybe;

import javax.annotation.Nonnull;
Expand All @@ -36,14 +37,12 @@
* created in hooks will be attached to these, and not to the actual failing
* steps!)
*
* @author Sergey_Gvozdyukevich
* @author Serhii Zharskyi
* @author Vitaliy Tsvihun
* @author Vadzim Hushchanskou
* @deprecated Use {@link ScenarioReporter}, since the semantic of this class is completely broken and will be removed
*/
@Deprecated
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();

@Override
@Nonnull
Expand Down
Loading

0 comments on commit d60362a

Please sign in to comment.