use of com.epam.ta.reportportal.ws.model.item.ItemCreatedRS in project service-api by reportportal.
the class RerunHandlerImplTest method happyRerunRootItem.
@Test
void happyRerunRootItem() {
StartTestItemRQ request = new StartTestItemRQ();
request.setLaunchUuid("launch_uuid");
request.setType("STEP");
String itemName = "name";
request.setName(itemName);
final String testCaseId = "caseId";
request.setTestCaseId(testCaseId);
Launch launch = getLaunch("uuid");
final TestItem item = getItem(itemName, launch);
when(rerunSearcher.findItem(any(Queryable.class))).thenReturn(Optional.of(item.getItemId()));
when(testItemRepository.findById(item.getItemId())).thenReturn(Optional.of(item));
Optional<ItemCreatedRS> rerunCreatedRS = rerunHandler.handleRootItem(request, launch);
assertTrue(rerunCreatedRS.isPresent());
}
use of com.epam.ta.reportportal.ws.model.item.ItemCreatedRS in project service-api by reportportal.
the class RerunHandlerImplTest method returnEmptyOptionalWhenRootItemNotFound.
@Test
void returnEmptyOptionalWhenRootItemNotFound() {
StartTestItemRQ request = new StartTestItemRQ();
request.setLaunchUuid("launch_uuid");
request.setType("STEP");
String itemName = "name";
request.setName(itemName);
final String testCaseId = "caseId";
request.setTestCaseId(testCaseId);
Launch launch = getLaunch("uuid");
when(rerunSearcher.findItem(any(Queryable.class))).thenReturn(Optional.empty());
Optional<ItemCreatedRS> rerunCreatedRS = rerunHandler.handleRootItem(request, launch);
assertFalse(rerunCreatedRS.isPresent());
}
use of com.epam.ta.reportportal.ws.model.item.ItemCreatedRS in project service-api by reportportal.
the class StartTestItemHandlerImpl method startRootItem.
@Override
public ItemCreatedRS startRootItem(ReportPortalUser user, ReportPortalUser.ProjectDetails projectDetails, StartTestItemRQ rq) {
Launch launch = launchRepository.findByUuid(rq.getLaunchUuid()).orElseThrow(() -> new ReportPortalException(LAUNCH_NOT_FOUND, rq.getLaunchUuid()));
validate(user, projectDetails, rq, launch);
if (launch.isRerun()) {
Optional<ItemCreatedRS> rerunCreatedRs = rerunHandler.handleRootItem(rq, launch);
if (rerunCreatedRs.isPresent()) {
return rerunCreatedRs.get();
}
}
TestItem item = new TestItemBuilder().addStartItemRequest(rq).addAttributes(rq.getAttributes()).addLaunchId(launch.getId()).get();
testItemRepository.save(item);
generateUniqueId(launch, item, String.valueOf(item.getItemId()));
LOGGER.debug("Created new root TestItem {}", item.getUuid());
return new ItemCreatedRS(item.getUuid(), item.getUniqueId());
}
use of com.epam.ta.reportportal.ws.model.item.ItemCreatedRS in project service-api by reportportal.
the class StartTestItemHandlerImpl method startChildItem.
@Override
public ItemCreatedRS startChildItem(ReportPortalUser user, ReportPortalUser.ProjectDetails projectDetails, StartTestItemRQ rq, String parentId) {
boolean isRetry = BooleanUtils.toBoolean(rq.isRetry()) || StringUtils.isNotBlank(rq.getRetryOf());
Launch launch = launchRepository.findByUuid(rq.getLaunchUuid()).orElseThrow(() -> new ReportPortalException(LAUNCH_NOT_FOUND, rq.getLaunchUuid()));
if (launch.isRerun()) {
Optional<ItemCreatedRS> rerunCreatedRs = rerunHandler.handleChildItem(rq, launch, parentId);
if (rerunCreatedRs.isPresent()) {
return rerunCreatedRs.get();
}
}
final TestItem parentItem;
if (isRetry) {
// Lock for test
Long lockedParentId = testItemRepository.findIdByUuidForUpdate(parentId).orElseThrow(() -> new ReportPortalException(TEST_ITEM_NOT_FOUND, parentId));
parentItem = testItemRepository.getOne(lockedParentId);
} else {
parentItem = testItemRepository.findByUuid(parentId).orElseThrow(() -> new ReportPortalException(TEST_ITEM_NOT_FOUND, parentId));
}
parentItemValidators.forEach(v -> v.validate(rq, parentItem));
TestItem item = new TestItemBuilder().addStartItemRequest(rq).addAttributes(rq.getAttributes()).addLaunchId(launch.getId()).get();
if (isRetry) {
ofNullable(rq.getRetryOf()).flatMap(testItemRepository::findIdByUuidForUpdate).ifPresentOrElse(retryParentId -> {
saveChildItem(launch, item, parentItem);
retryHandler.handleRetries(launch, item, retryParentId);
}, () -> retrySearcher.findPreviousRetry(launch, item, parentItem).ifPresentOrElse(previousRetryId -> {
saveChildItem(launch, item, parentItem);
retryHandler.handleRetries(launch, item, previousRetryId);
}, () -> saveChildItem(launch, item, parentItem)));
} else {
saveChildItem(launch, item, parentItem);
}
LOGGER.debug("Created new child TestItem {} with root {}", item.getUuid(), parentId);
if (rq.isHasStats() && !parentItem.isHasChildren()) {
parentItem.setHasChildren(true);
}
return new ItemCreatedRS(item.getUuid(), item.getUniqueId());
}
use of com.epam.ta.reportportal.ws.model.item.ItemCreatedRS in project allure-java by reportportal.
the class TestUtils method mockLaunch.
@SuppressWarnings("unchecked")
public static <T extends Collection<String>> void mockLaunch(ReportPortalClient client, String launchUuid, String suiteUuid, Collection<Pair<String, T>> testSteps) {
when(client.startLaunch(any())).thenReturn(createMaybe(new StartLaunchRS(launchUuid, 1L)));
Maybe<ItemCreatedRS> suiteMaybe = createMaybe(new ItemCreatedRS(suiteUuid, suiteUuid));
when(client.startTestItem(any())).thenReturn(suiteMaybe);
List<Maybe<ItemCreatedRS>> testResponses = testSteps.stream().map(Pair::getKey).map(uuid -> createMaybe(new ItemCreatedRS(uuid, uuid))).collect(Collectors.toList());
Maybe<ItemCreatedRS> first = testResponses.get(0);
Maybe<ItemCreatedRS>[] other = testResponses.subList(1, testResponses.size()).toArray(new Maybe[0]);
when(client.startTestItem(same(suiteUuid), any())).thenReturn(first, other);
testSteps.forEach(test -> {
String testClassUuid = test.getKey();
List<Maybe<ItemCreatedRS>> stepResponses = test.getValue().stream().map(uuid -> createMaybe(new ItemCreatedRS(uuid, uuid))).collect(Collectors.toList());
Maybe<ItemCreatedRS> myFirst = stepResponses.get(0);
Maybe<ItemCreatedRS>[] myOther = stepResponses.subList(1, stepResponses.size()).toArray(new Maybe[0]);
when(client.startTestItem(same(testClassUuid), any())).thenReturn(myFirst, myOther);
new HashSet<>(test.getValue()).forEach(testMethodUuid -> when(client.finishTestItem(same(testMethodUuid), any())).thenReturn(createMaybe(new OperationCompletionRS())));
when(client.finishTestItem(same(testClassUuid), any())).thenReturn(createMaybe(new OperationCompletionRS()));
});
Maybe<OperationCompletionRS> suiteFinishMaybe = createMaybe(new OperationCompletionRS());
when(client.finishTestItem(eq(suiteUuid), any())).thenReturn(suiteFinishMaybe);
when(client.finishLaunch(eq(launchUuid), any())).thenReturn(createMaybe(new OperationCompletionRS()));
}
Aggregations