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;
}
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;
}
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;
}
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;
}
Aggregations