use of com.epam.ta.reportportal.ws.model.StartTestItemRQ in project service-api by reportportal.
the class StartTestItemHandlerImplTest method startRootItemUnderNotExistedLaunch.
@Test
void startRootItemUnderNotExistedLaunch() {
final ReportPortalUser rpUser = getRpUser("test", UserRole.USER, ProjectRole.MEMBER, 1L);
when(launchRepository.findByUuid("1")).thenReturn(Optional.empty());
final StartTestItemRQ rq = new StartTestItemRQ();
rq.setLaunchUuid("1");
final ReportPortalException exception = assertThrows(ReportPortalException.class, () -> handler.startRootItem(rpUser, extractProjectDetails(rpUser, "test_project"), rq));
assertEquals("Launch '1' not found. Did you use correct Launch ID?", exception.getMessage());
}
use of com.epam.ta.reportportal.ws.model.StartTestItemRQ 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.StartTestItemRQ 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.StartTestItemRQ in project service-api by reportportal.
the class DemoDataTestItemService method startTestItem.
@Transactional
public String startTestItem(DemoItemMetadata metadata, RootMetaData rootMetaData) {
StartTestItemRQ rq = new StartTestItemRQ();
if (hasChildren(metadata.getType())) {
rq.setAttributes(ContentUtils.getAttributesInRange(ATTRIBUTES_COUNT));
rq.setDescription(ContentUtils.getTestDescription());
} else {
rq.setAttributes(ContentUtils.getAttributesInRange(ATTRIBUTES_COUNT));
rq.setDescription(ContentUtils.getStepDescription());
}
rq.setHasStats(!metadata.isNested());
rq.setCodeRef(PACKAGE + metadata.getName());
rq.setRetry(metadata.isRetry());
rq.setLaunchUuid(rootMetaData.getLaunchUuid());
rq.setStartTime(new Date());
rq.setName(metadata.getName());
rq.setType(metadata.getType().name());
return startTestItemHandler.startChildItem(rootMetaData.getUser(), rootMetaData.getProjectDetails(), rq, metadata.getParentId()).getId();
}
use of com.epam.ta.reportportal.ws.model.StartTestItemRQ 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());
}
Aggregations