Search in sources :

Example 1 with TestCaseIdEntry

use of com.epam.reportportal.service.item.TestCaseIdEntry in project agent-java-testNG by reportportal.

the class TestNGService method getTestCaseId.

@Nullable
private TestCaseIdEntry getTestCaseId(@Nonnull String codeRef, @Nonnull ITestResult testResult) {
    Method method = getMethod(testResult);
    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, parameters))).orElse(TestCaseIdUtils.getTestCaseId(codeRef, parameters));
    return id == null ? null : id.getId().endsWith("[]") ? new TestCaseIdEntry(id.getId().substring(0, id.getId().length() - 2)) : id;
}
Also used : XmlClass(org.testng.xml.XmlClass) LimitedSizeConcurrentHashMap(com.epam.reportportal.testng.util.internal.LimitedSizeConcurrentHashMap) Lists(org.testng.collections.Lists) Launch(com.epam.reportportal.service.Launch) com.epam.ta.reportportal.ws.model(com.epam.ta.reportportal.ws.model) ReportPortal(com.epam.reportportal.service.ReportPortal) AttributeParser(com.epam.reportportal.utils.AttributeParser) Test(org.testng.annotations.Test) SystemAttributesExtractor(com.epam.reportportal.utils.properties.SystemAttributesExtractor) TestCaseIdEntry(com.epam.reportportal.service.item.TestCaseIdEntry) Pair(org.apache.commons.lang3.tuple.Pair) org.testng(org.testng) XmlTest(org.testng.xml.XmlTest) Method(java.lang.reflect.Method) ParameterUtils(com.epam.reportportal.utils.ParameterUtils) Predicate(java.util.function.Predicate) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ExceptionUtils.getStackTrace(org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace) SaveLogRQ(com.epam.ta.reportportal.ws.model.log.SaveLogRQ) ParameterKey(com.epam.reportportal.annotations.ParameterKey) Collectors(java.util.stream.Collectors) UniqueID(com.epam.reportportal.annotations.UniqueID) Stream(java.util.stream.Stream) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) StartLaunchRQ(com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ) Annotation(java.lang.annotation.Annotation) ConstructorOrMethod(org.testng.internal.ConstructorOrMethod) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) IntStream(java.util.stream.IntStream) java.util(java.util) ListenerParameters(com.epam.reportportal.listeners.ListenerParameters) Maybe(io.reactivex.Maybe) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestCaseId(com.epam.reportportal.annotations.TestCaseId) TestItemTree(com.epam.reportportal.service.tree.TestItemTree) Constructor(java.lang.reflect.Constructor) Supplier(java.util.function.Supplier) Attributes(com.epam.reportportal.annotations.attribute.Attributes) TestCaseIdUtils(com.epam.reportportal.utils.TestCaseIdUtils) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Factory(org.testng.annotations.Factory) Optional.ofNullable(java.util.Optional.ofNullable) ItemTreeUtils.createKey(com.epam.reportportal.testng.util.ItemTreeUtils.createKey) MemoizingSupplier(com.epam.reportportal.utils.MemoizingSupplier) ItemStatus(com.epam.reportportal.listeners.ItemStatus) ItemAttributesRQ(com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ) Collectors.toList(java.util.stream.Collectors.toList) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) Parameters(org.testng.annotations.Parameters) Method(java.lang.reflect.Method) ConstructorOrMethod(org.testng.internal.ConstructorOrMethod) TestCaseIdEntry(com.epam.reportportal.service.item.TestCaseIdEntry) Nullable(javax.annotation.Nullable) Optional.ofNullable(java.util.Optional.ofNullable)

Example 2 with TestCaseIdEntry

use of com.epam.reportportal.service.item.TestCaseIdEntry in project agent-java-junit5 by reportportal.

the class ReportPortalExtension method buildStartConfigurationRq.

/**
 * Extension point to customize beforeXXX creation event/request
 *
 * @param method        JUnit's test method reference
 * @param parentContext JUnit's context of a parent item
 * @param context       JUnit's test context
 * @param itemType      a type of the item to build
 * @return Request to ReportPortal
 */
@Nonnull
protected StartTestItemRQ buildStartConfigurationRq(@Nonnull Method method, @Nonnull ExtensionContext parentContext, @Nonnull ExtensionContext context, @Nonnull ItemType itemType) {
    StartTestItemRQ rq = new StartTestItemRQ();
    rq.setStartTime(Calendar.getInstance().getTime());
    Optional<Class<?>> testClass = context.getTestClass();
    if (testClass.isPresent()) {
        rq.setName(createConfigurationName(testClass.get(), method));
        rq.setDescription(createConfigurationDescription(testClass.get(), method));
    } else {
        rq.setName(createConfigurationName(method.getDeclaringClass(), method));
        rq.setDescription(createConfigurationDescription(method.getDeclaringClass(), method));
    }
    String uniqueId = parentContext.getUniqueId() + "/[method:" + method.getName() + "()]";
    rq.setUniqueId(uniqueId);
    ofNullable(context.getTags()).ifPresent(it -> rq.setAttributes(it.stream().map(tag -> new ItemAttributesRQ(null, tag)).collect(Collectors.toSet())));
    rq.setType(itemType.name());
    rq.setRetry(false);
    String codeRef = method.getDeclaringClass().getCanonicalName() + "." + method.getName();
    rq.setCodeRef(codeRef);
    TestCaseIdEntry caseId = ofNullable(method.getAnnotation(TestCaseId.class)).map(TestCaseId::value).map(TestCaseIdEntry::new).orElseGet(() -> TestCaseIdUtils.getTestCaseId(codeRef, Collections.emptyList()));
    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) TestCaseId(com.epam.reportportal.annotations.TestCaseId) ItemAttributesRQ(com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ) TestCaseIdEntry(com.epam.reportportal.service.item.TestCaseIdEntry) Nonnull(javax.annotation.Nonnull)

Example 3 with TestCaseIdEntry

use of com.epam.reportportal.service.item.TestCaseIdEntry in project agent-java-junit5 by reportportal.

the class ReportPortalExtension method getTestCaseId.

/**
 * Calculates a test case ID based on code reference and parameters
 *
 * @param method    a test method reference
 * @param codeRef   a code reference which will be used for the calculation
 * @param arguments a list of test arguments
 * @param instance  current test instance
 * @return a test case ID
 */
protected TestCaseIdEntry getTestCaseId(@Nonnull final Method method, @Nonnull final String codeRef, @Nonnull final List<Object> arguments, @Nullable Object instance) {
    TestCaseId caseId = method.getAnnotation(TestCaseId.class);
    TestCaseIdEntry id = TestCaseIdUtils.getTestCaseId(caseId, method, codeRef, arguments, instance);
    if (id == null) {
        return null;
    }
    return id.getId().endsWith("[]") ? new TestCaseIdEntry(id.getId().substring(0, id.getId().length() - 2)) : id;
}
Also used : TestCaseId(com.epam.reportportal.annotations.TestCaseId) TestCaseIdEntry(com.epam.reportportal.service.item.TestCaseIdEntry)

Example 4 with TestCaseIdEntry

use of com.epam.reportportal.service.item.TestCaseIdEntry 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)

Aggregations

TestCaseId (com.epam.reportportal.annotations.TestCaseId)4 TestCaseIdEntry (com.epam.reportportal.service.item.TestCaseIdEntry)4 ParameterKey (com.epam.reportportal.annotations.ParameterKey)3 Attributes (com.epam.reportportal.annotations.attribute.Attributes)3 ItemStatus (com.epam.reportportal.listeners.ItemStatus)3 ListenerParameters (com.epam.reportportal.listeners.ListenerParameters)3 Launch (com.epam.reportportal.service.Launch)3 ReportPortal (com.epam.reportportal.service.ReportPortal)3 TestItemTree (com.epam.reportportal.service.tree.TestItemTree)3 AttributeParser (com.epam.reportportal.utils.AttributeParser)3 ParameterUtils (com.epam.reportportal.utils.ParameterUtils)3 TestCaseIdUtils (com.epam.reportportal.utils.TestCaseIdUtils)3 com.epam.ta.reportportal.ws.model (com.epam.ta.reportportal.ws.model)3 ItemAttributesRQ (com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ)3 StartLaunchRQ (com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ)3 SaveLogRQ (com.epam.ta.reportportal.ws.model.log.SaveLogRQ)3 Maybe (io.reactivex.Maybe)3 Method (java.lang.reflect.Method)3 java.util (java.util)3 Optional.ofNullable (java.util.Optional.ofNullable)3