Search in sources :

Example 26 with ItemAttributesRQ

use of com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ in project agent-java-junit5 by reportportal.

the class ReportPortalExtension method buildStartStepRq.

/**
 * Extension point to customize test step creation event/request
 *
 * @param context     JUnit's test context
 * @param arguments   a test arguments list
 * @param itemType    a test method item type
 * @param description a test method description
 * @param startTime   a start time of the test
 * @return Request to ReportPortal
 */
@Nonnull
protected StartTestItemRQ buildStartStepRq(@Nonnull final ExtensionContext context, @Nonnull final List<Object> arguments, @Nonnull final ItemType itemType, @Nonnull final String description, @Nonnull final Date startTime) {
    StartTestItemRQ rq = new StartTestItemRQ();
    rq.setStartTime(startTime);
    rq.setName(createStepName(context));
    rq.setDescription(description);
    rq.setUniqueId(context.getUniqueId());
    rq.setType(itemType == TEMPLATE ? SUITE.name() : itemType.name());
    String codeRef = getCodeRef(context);
    rq.setCodeRef(codeRef);
    rq.setAttributes(context.getTags().stream().map(it -> new ItemAttributesRQ(null, it)).collect(Collectors.toSet()));
    if (SUITE == itemType) {
        context.getTestClass().ifPresent(c -> rq.getAttributes().addAll(getAttributes(c)));
    }
    Optional<Method> testMethod = getTestMethod(context);
    TestCaseIdEntry caseId = testMethod.map(m -> {
        rq.getAttributes().addAll(getAttributes(m));
        rq.setParameters(getParameters(m, arguments));
        return getTestCaseId(m, codeRef, arguments, context.getTestInstance().orElse(null));
    }).orElseGet(() -> TestCaseIdUtils.getTestCaseId(codeRef, arguments));
    rq.setTestCaseId(ofNullable(caseId).map(TestCaseIdEntry::getId).orElse(null));
    return rq;
}
Also used : java.util(java.util) ListenerParameters(com.epam.reportportal.listeners.ListenerParameters) Launch(com.epam.reportportal.service.Launch) com.epam.ta.reportportal.ws.model(com.epam.ta.reportportal.ws.model) Maybe(io.reactivex.Maybe) LoggerFactory(org.slf4j.LoggerFactory) ReportPortal(com.epam.reportportal.service.ReportPortal) AttributeParser(com.epam.reportportal.utils.AttributeParser) TestCaseId(com.epam.reportportal.annotations.TestCaseId) TestItemTree(com.epam.reportportal.service.tree.TestItemTree) StringUtils(org.apache.commons.lang3.StringUtils) TestCaseIdEntry(com.epam.reportportal.service.item.TestCaseIdEntry) SystemAttributesFetcher.collectSystemAttributes(com.epam.reportportal.junit5.SystemAttributesFetcher.collectSystemAttributes) Attributes(com.epam.reportportal.annotations.attribute.Attributes) TestCaseIdUtils(com.epam.reportportal.utils.TestCaseIdUtils) Nonnull(javax.annotation.Nonnull) Method(java.lang.reflect.Method) Nullable(javax.annotation.Nullable) ParameterUtils(com.epam.reportportal.utils.ParameterUtils) TestItemTree.createTestItemLeaf(com.epam.reportportal.service.tree.TestItemTree.createTestItemLeaf) Logger(org.slf4j.Logger) Optional.ofNullable(java.util.Optional.ofNullable) TestAbortedException(org.opentest4j.TestAbortedException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ExceptionUtils.getStackTrace(org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace) ItemStatus(com.epam.reportportal.listeners.ItemStatus) SaveLogRQ(com.epam.ta.reportportal.ws.model.log.SaveLogRQ) ParameterKey(com.epam.reportportal.annotations.ParameterKey) Collectors(java.util.stream.Collectors) ItemAttributesRQ(com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ) StartLaunchRQ(com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ) org.junit.jupiter.api(org.junit.jupiter.api) ItemType(com.epam.reportportal.junit5.ItemType) org.junit.jupiter.api.extension(org.junit.jupiter.api.extension) ItemTreeUtils.createItemTreeKey(com.epam.reportportal.junit5.utils.ItemTreeUtils.createItemTreeKey) AnnotatedElement(java.lang.reflect.AnnotatedElement) ItemAttributesRQ(com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ) Method(java.lang.reflect.Method) TestCaseIdEntry(com.epam.reportportal.service.item.TestCaseIdEntry) Nonnull(javax.annotation.Nonnull)

Example 27 with ItemAttributesRQ

use of com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ in project agent-java-junit5 by reportportal.

the class SystemAttributesFetcher method skippedAnIssue.

private static ItemAttributesRQ skippedAnIssue(Boolean fromParams) {
    ItemAttributesRQ skippedIssueAttr = new ItemAttributesRQ();
    skippedIssueAttr.setKey(SKIPPED_ISSUE_KEY);
    skippedIssueAttr.setValue(fromParams == null ? "true" : fromParams.toString());
    skippedIssueAttr.setSystem(true);
    return skippedIssueAttr;
}
Also used : ItemAttributesRQ(com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ)

Example 28 with ItemAttributesRQ

use of com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ in project allure-java by reportportal.

the class AnnotationUtils method processFlaky.

public static void processFlaky(@Nonnull StartTestItemRQ rq, @Nullable Method source) {
    ofNullable(source).ifPresent(s -> {
        Flaky annotation = ofNullable(s.getAnnotation(Flaky.class)).orElseGet(() -> source.getDeclaringClass().getAnnotation(Flaky.class));
        if (annotation != null) {
            ItemAttributesRQ attribute = new ItemAttributesRQ(Flaky.class.getSimpleName().toLowerCase(Locale.ROOT));
            Set<ItemAttributesRQ> attributes = retrieveAttributes(rq);
            attributes.add(attribute);
        }
    });
}
Also used : Flaky(io.qameta.allure.Flaky) ItemAttributesRQ(com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ)

Example 29 with ItemAttributesRQ

use of com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ in project allure-java by reportportal.

the class LabelAnnotationTest method test_attributes_should_contain_attached_labels.

@Test
public void test_attributes_should_contain_attached_labels() {
    TestNG result = runTests(TestMyFirstFeature.class);
    assertThat(result.getStatus(), equalTo(0));
    // Start launch
    verify(client).startLaunch(any());
    // Start parent suites
    verify(client).startTestItem(any());
    ArgumentCaptor<StartTestItemRQ> startTestCapture = ArgumentCaptor.forClass(StartTestItemRQ.class);
    // Start test class
    verify(client).startTestItem(same(suitedUuid), startTestCapture.capture());
    ArgumentCaptor<StartTestItemRQ> startMethodCapture = ArgumentCaptor.forClass(StartTestItemRQ.class);
    // Start test step
    verify(client).startTestItem(same(testClassUuid), startMethodCapture.capture());
    Set<ItemAttributesRQ> attributes = startTestCapture.getValue().getAttributes();
    assertThat(attributes, hasSize(1));
    assertThat(attributes.iterator().next(), allOf(hasProperty("key", equalTo("feature")), hasProperty("value", equalTo("My feature"))));
    attributes = startMethodCapture.getValue().getAttributes();
    assertThat(attributes, hasSize(1));
    assertThat(attributes.iterator().next(), allOf(hasProperty("key", equalTo("story")), hasProperty("value", equalTo("My story 1"))));
}
Also used : TestNG(org.testng.TestNG) ItemAttributesRQ(com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ) StartTestItemRQ(com.epam.ta.reportportal.ws.model.StartTestItemRQ) Test(org.junit.jupiter.api.Test)

Example 30 with ItemAttributesRQ

use of com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ in project allure-java by reportportal.

the class ScenarioMetaTest method verify_a_scenario_with_meta_attributes.

@Test
public void verify_a_scenario_with_meta_attributes() {
    run(format, STORY_PATH, new EmptySteps());
    ArgumentCaptor<StartTestItemRQ> startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class);
    verify(client).startTestItem(startCaptor.capture());
    verify(client).startTestItem(same(storyId), startCaptor.capture());
    verify(client).startTestItem(same(scenarioId), any());
    List<StartTestItemRQ> items = startCaptor.getAllValues();
    StartTestItemRQ startSuite = items.get(0);
    assertThat(startSuite.getAttributes(), empty());
    StartTestItemRQ startScenario = items.get(1);
    assertThat(startScenario.getAttributes(), allOf(notNullValue(), hasSize(STEP_ATTRIBUTES.size())));
    Set<ItemAttributesRQ> scenarioAttributes = startScenario.getAttributes();
    scenarioAttributes.forEach(a -> assertThat(STEP_ATTRIBUTES, hasItem(Pair.of(a.getKey(), a.getValue()))));
}
Also used : ItemAttributesRQ(com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ) EmptySteps(com.epam.reportportal.jbehave.integration.EmptySteps) StartTestItemRQ(com.epam.ta.reportportal.ws.model.StartTestItemRQ) Test(org.junit.jupiter.api.Test)

Aggregations

ItemAttributesRQ (com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ)33 Test (org.junit.jupiter.api.Test)19 StartTestItemRQ (com.epam.ta.reportportal.ws.model.StartTestItemRQ)13 StartLaunchRQ (com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ)11 Collectors (java.util.stream.Collectors)10 ReportPortal (com.epam.reportportal.service.ReportPortal)9 List (java.util.List)8 Set (java.util.Set)8 ReportPortalClient (com.epam.reportportal.service.ReportPortalClient)7 TestNgListener (com.epam.reportportal.testng.util.TestNgListener)7 TestUtils (com.epam.reportportal.testng.util.TestUtils)7 Collections (java.util.Collections)7 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)7 Matchers.hasSize (org.hamcrest.Matchers.hasSize)7 BeforeEach (org.junit.jupiter.api.BeforeEach)7 ArgumentCaptor (org.mockito.ArgumentCaptor)7 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)7 ArgumentMatchers.same (org.mockito.ArgumentMatchers.same)7 Mockito.mock (org.mockito.Mockito.mock)7 Mockito.verify (org.mockito.Mockito.verify)7