Skip to content

Commit

Permalink
Client version update and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
HardNorth committed Jan 18, 2024
1 parent c9fc7ef commit 7615fa5
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 179 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -53,15 +53,16 @@ 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'
}
testImplementation "org.junit.jupiter:junit-jupiter-api:${project.junit_version}"
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 {
Expand Down
84 changes: 36 additions & 48 deletions src/main/java/com/epam/reportportal/cucumber/AbstractReporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,28 @@
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.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;
Expand All @@ -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.*;
Expand All @@ -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;
Expand All @@ -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 = ": ";
Expand Down Expand Up @@ -448,27 +448,18 @@ protected void afterStep(@Nonnull TestCase testCase, @Nonnull TestStep testStep,
*/
@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);
}

/**
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -976,7 +959,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 @@ -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;
}

/**
Expand Down
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.HookTestStep;
Expand Down Expand Up @@ -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<Maybe<String>> rootSuiteId;
Expand Down
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 @@ -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();
Expand Down
Loading

0 comments on commit 7615fa5

Please sign in to comment.