use of com.epam.reportportal.annotations.TestCaseId in project agent-java-testNG by reportportal.
the class BuildStepTest method testCaseId_fromAnnotation.
@Test
public void testCaseId_fromAnnotation() {
when(testResult.getMethod()).thenReturn(testNGMethod);
when(testNGMethod.getConstructorOrMethod()).thenReturn(constructorOrMethod);
when(testNGMethod.isTest()).thenReturn(true);
Optional<Method> methodOptional = Arrays.stream(TestMethodsExamples.class.getDeclaredMethods()).filter(it -> it.getName().equals("testCaseId")).findFirst();
assertTrue(methodOptional.isPresent());
String expectedCodeRef = "com.test.BuildStepTest.codeRefTest";
when(constructorOrMethod.getMethod()).thenReturn(methodOptional.get());
when(testResult.getMethod().getQualifiedName()).thenReturn(expectedCodeRef);
StartTestItemRQ request = testNGService.buildStartStepRq(testResult);
assertEquals(expectedCodeRef, request.getCodeRef());
assertEquals("test-case-id", request.getTestCaseId());
}
use of com.epam.reportportal.annotations.TestCaseId 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.annotations.TestCaseId 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;
}
Aggregations