diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java index b9e9c60..0271a38 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java @@ -26,6 +26,7 @@ import com.epam.reportportal.utils.AttributeParser; import com.epam.reportportal.utils.MemoizingSupplier; import com.epam.reportportal.utils.TestCaseIdUtils; +import com.epam.reportportal.utils.properties.SystemAttributesExtractor; import com.epam.ta.reportportal.ws.model.FinishExecutionRQ; import com.epam.ta.reportportal.ws.model.FinishTestItemRQ; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; @@ -45,6 +46,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import static com.epam.reportportal.karate.ReportPortalUtils.AGENT_PROPERTIES_FILE; import static com.google.common.base.Strings.isNullOrEmpty; import static java.util.Optional.ofNullable; import static org.apache.commons.lang3.StringUtils.isNotBlank; @@ -91,6 +93,15 @@ protected StartLaunchRQ buildStartLaunchRq(ListenerParameters parameters) { if (isNotBlank(parameters.getRerunOf())) { rq.setRerunOf(parameters.getRerunOf()); } + if (null != parameters.getSkippedAnIssue()) { + ItemAttributesRQ skippedIssueAttribute = new ItemAttributesRQ(); + skippedIssueAttribute.setKey(ReportPortalUtils.SKIPPED_ISSUE_KEY); + skippedIssueAttribute.setValue(parameters.getSkippedAnIssue().toString()); + skippedIssueAttribute.setSystem(true); + rq.getAttributes().add(skippedIssueAttribute); + } + rq.getAttributes().addAll(SystemAttributesExtractor.extract(AGENT_PROPERTIES_FILE, + ReportPortalUtils.class.getClassLoader())); return rq; } diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java b/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java index 475e0f8..37c9b11 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java @@ -24,15 +24,18 @@ */ public class ReportPortalUtils { - private ReportPortalUtils() { - throw new AssertionError("No instances should exist for the class!"); - } - private static final String PARAMETER_ITEMS_START = "["; private static final String PARAMETER_ITEMS_END = "]"; private static final String PARAMETER_ITEMS_DELIMITER = ";"; private static final String KEY_VALUE_SEPARATOR = ":"; + public static final String AGENT_PROPERTIES_FILE = "agent.properties"; + public static final String SKIPPED_ISSUE_KEY = "skippedIssue"; + + private ReportPortalUtils() { + throw new AssertionError("No instances should exist for the class!"); + } + /** * Create a String from a parameter Map to be used as a test key and title * diff --git a/src/test/java/com/epam/reportportal/karate/attributes/SystemAttributesTest.java b/src/test/java/com/epam/reportportal/karate/attributes/SystemAttributesTest.java new file mode 100644 index 0000000..7ea6812 --- /dev/null +++ b/src/test/java/com/epam/reportportal/karate/attributes/SystemAttributesTest.java @@ -0,0 +1,78 @@ +/* + * Copyright 2023 EPAM Systems + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.epam.reportportal.karate.attributes; + +import com.epam.reportportal.karate.utils.TestUtils; +import com.epam.reportportal.service.ReportPortal; +import com.epam.reportportal.service.ReportPortalClient; +import com.epam.reportportal.util.test.CommonUtils; +import com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ; +import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static com.epam.reportportal.karate.utils.TestUtils.*; +import static com.epam.reportportal.karate.utils.TestUtils.mockBatchLogging; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +public class SystemAttributesTest { + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); + + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } + + @Test + public void verify_start_launch_request_contains_system_attributes() { + var results = TestUtils.runAsReport(rp, "classpath:feature/simple.feature"); + assertThat(results.getFailCount(), equalTo(0)); + + ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); + verify(client).startLaunch(startCaptor.capture()); + + StartLaunchRQ launchStart = startCaptor.getValue(); + + Set attributes = launchStart.getAttributes(); + assertThat(attributes, allOf(notNullValue(), hasSize(greaterThan(0)))); + Set attributesStr = attributes.stream() + .filter(ItemAttributesRQ::isSystem) + .map(e -> e.getKey() + ":" + e.getValue()) + .collect(Collectors.toSet()); + assertThat(attributesStr, hasSize(4)); + assertThat(attributesStr, hasItem("skippedIssue:true")); + assertThat(attributesStr, hasItem("agent:karate-test-agent|test-1.0")); + assertThat(attributesStr, hasItem(startsWith("os:"))); + assertThat(attributesStr, hasItem(startsWith("jvm:"))); + } +}