Skip to content

Commit

Permalink
@Issue and @Issues annotations support
Browse files Browse the repository at this point in the history
  • Loading branch information
HardNorth committed Nov 12, 2024
1 parent f15580c commit edbd871
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [Unreleased]
### Added
- Common Stack Trace frames skip in description and logs, by @HardNorth
- `@Issue` and `@Issues` annotations support, by @HardNorth
### Changed
- Client version upgraded on [5.2.20](https://github.com/reportportal/client-java/releases/tag/5.2.20), by @HardNorth

Expand Down
35 changes: 18 additions & 17 deletions src/main/java/com/epam/reportportal/testng/TestNGService.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
*/
package com.epam.reportportal.testng;

import com.epam.reportportal.annotations.Description;
import com.epam.reportportal.annotations.DisplayName;
import com.epam.reportportal.annotations.ParameterKey;
import com.epam.reportportal.annotations.TestCaseId;
import com.epam.reportportal.annotations.*;
import com.epam.reportportal.annotations.attribute.Attributes;
import com.epam.reportportal.listeners.ItemStatus;
import com.epam.reportportal.listeners.ListenerParameters;
Expand All @@ -27,10 +24,7 @@
import com.epam.reportportal.service.item.TestCaseIdEntry;
import com.epam.reportportal.service.tree.TestItemTree;
import com.epam.reportportal.testng.util.internal.LimitedSizeConcurrentHashMap;
import com.epam.reportportal.utils.AttributeParser;
import com.epam.reportportal.utils.MemoizingSupplier;
import com.epam.reportportal.utils.ParameterUtils;
import com.epam.reportportal.utils.TestCaseIdUtils;
import com.epam.reportportal.utils.*;
import com.epam.reportportal.utils.formatting.MarkdownUtils;
import com.epam.reportportal.utils.properties.SystemAttributesExtractor;
import com.epam.ta.reportportal.ws.model.*;
Expand Down Expand Up @@ -386,8 +380,7 @@ public void startTestMethod(@Nonnull ITestResult testResult) {
*/
@Nullable
private String getLogMessage(@Nonnull ITestResult testResult) {
String error = ofNullable(testResult.getThrowable()).map(t -> String.format(
DESCRIPTION_ERROR_FORMAT,
String error = ofNullable(testResult.getThrowable()).map(t -> String.format(DESCRIPTION_ERROR_FORMAT,
getStackTrace(t, new Throwable())
)).orElse(null);
if (error == null) {
Expand Down Expand Up @@ -479,6 +472,15 @@ private void processFinishRetryFlag(ITestResult testResult, FinishTestItemRQ rq)
protected void createSkippedSteps(ITestResult testResult) {
}

@Nullable
protected com.epam.ta.reportportal.ws.model.issue.Issue createIssue(@Nonnull ITestResult testResult) {
String stepName = createStepName(testResult);
List<ParameterResource> parameters = createStepParameters(testResult);
return getMethodAnnotation(Issues.class, testResult).map(i -> IssueUtils.createIssue(i, stepName, parameters))
.orElseGet(() -> getMethodAnnotation(Issue.class, testResult).map(i -> IssueUtils.createIssue(i, stepName, parameters))
.orElse(null));
}

@Override
public void finishTestMethod(ItemStatus status, ITestResult testResult) {
Maybe<String> itemId = getAttribute(testResult, RP_ID);
Expand Down Expand Up @@ -514,6 +516,10 @@ && getAttribute(testResult, RP_RETRY) != null))) {

processFinishRetryFlag(testResult, rq);

if (type == TestMethodType.STEP) {
rq.setIssue(createIssue(testResult));
}

Maybe<OperationCompletionRS> finishItemResponse = launch.get().finishTestItem(itemId, rq);
if (launch.get().getParameters().isCallbackReportingEnabled()) {
updateTestItemTree(finishItemResponse, testResult);
Expand Down Expand Up @@ -758,13 +764,8 @@ private TestCaseIdEntry getTestCaseId(@Nonnull String codeRef, @Nonnull ITestRes
List<Object> parameters = ofNullable(testResult.getParameters()).map(Arrays::asList).orElse(null);
TestCaseIdEntry id = getMethodAnnotation(TestCaseId.class,
testResult
).flatMap(a -> ofNullable(method).map(m -> TestCaseIdUtils.getTestCaseId(
a,
m,
codeRef,
parameters,
instance
))).orElse(TestCaseIdUtils.getTestCaseId(codeRef, parameters));
).flatMap(a -> ofNullable(method).map(m -> TestCaseIdUtils.getTestCaseId(a, m, codeRef, parameters, instance)))
.orElse(TestCaseIdUtils.getTestCaseId(codeRef, parameters));

return id == null ? null : id.getId().endsWith("[]") ? new TestCaseIdEntry(id.getId().substring(0, id.getId().length() - 2)) : id;
}
Expand Down

0 comments on commit edbd871

Please sign in to comment.