use of com.epam.ta.reportportal.ws.model.log.SearchLogRs in project service-api by reportportal.
the class SearchLogServiceImpl method search.
@Override
public Iterable<SearchLogRs> search(Long itemId, SearchLogRq request, ReportPortalUser.ProjectDetails projectDetails) {
Project project = projectRepository.findById(projectDetails.getProjectId()).orElseThrow(() -> new ReportPortalException(ErrorType.PROJECT_NOT_FOUND, projectDetails.getProjectId()));
TestItem item = testItemRepository.findById(itemId).orElseThrow(() -> new ReportPortalException(ErrorType.TEST_ITEM_NOT_FOUND, itemId));
Launch launch = launchRepository.findById(item.getLaunchId()).orElseThrow(() -> new ReportPortalException(ErrorType.LAUNCH_NOT_FOUND, item.getLaunchId()));
expect(item.getItemResults().getStatus(), not(statusIn(StatusEnum.IN_PROGRESS))).verify(ErrorType.TEST_ITEM_IS_NOT_FINISHED);
return composeRequest(request, project, item, launch).map(searchRq -> processRequest(project.getId(), searchRq)).orElse(Collections.emptyList());
}
use of com.epam.ta.reportportal.ws.model.log.SearchLogRs in project service-api by reportportal.
the class SearchLogServiceImplTest method searchTest.
@Test
void searchTest() {
ReportPortalUser.ProjectDetails projectDetails = new ReportPortalUser.ProjectDetails(1L, "project", ProjectRole.PROJECT_MANAGER);
when(projectRepository.findById(projectDetails.getProjectId())).thenReturn(Optional.of(project));
when(testItemRepository.findById(1L)).thenReturn(Optional.of(testItem));
when(testItemRepository.findAllById(any())).thenReturn(Lists.newArrayList(testItemOfFoundLog));
when(testItem.getLaunchId()).thenReturn(1L);
when(testItemOfFoundLog.getItemId()).thenReturn(2L);
when(testItemOfFoundLog.getLaunchId()).thenReturn(1L);
when(launchRepository.findById(1L)).thenReturn(Optional.of(launch));
when(launch.getId()).thenReturn(1L);
when(testItem.getPath()).thenReturn("1");
when(testItem.getItemResults()).thenReturn(testItemResults);
when(testItem.isHasStats()).thenReturn(true);
when(testItemOfFoundLog.getItemResults()).thenReturn(testItemResults);
when(testItemOfFoundLog.isHasStats()).thenReturn(true);
when(testItemResults.getStatus()).thenReturn(StatusEnum.FAILED);
IssueType issueType = new IssueType();
issueType.setLocator("locator");
IssueEntity issueEntity = new IssueEntity();
issueEntity.setIssueType(issueType);
issueEntity.setIgnoreAnalyzer(false);
when(testItemResults.getIssue()).thenReturn(issueEntity);
when(userFilterRepository.findByIdAndProjectId(1L, 1L)).thenReturn(Optional.of(userFilter));
when(userFilter.getTargetClass()).thenReturn(ObjectType.Launch);
when(userFilter.getFilterCondition()).thenReturn(Collections.emptySet());
when(logRepository.findMessagesByLaunchIdAndItemIdAndPathAndLevelGte(launch.getId(), testItem.getItemId(), testItem.getPath(), LogLevel.ERROR_INT)).thenReturn(Lists.newArrayList("message"));
SearchRs searchRs = new SearchRs();
searchRs.setLogId(1L);
searchRs.setTestItemId(2L);
when(analyzerServiceClient.searchLogs(any(SearchRq.class))).thenReturn(Lists.newArrayList(searchRs));
Log log = new Log();
log.setId(1L);
log.setTestItem(testItem);
log.setLogMessage("message");
log.setLogLevel(40000);
when(logRepository.findAllById(any())).thenReturn(Lists.newArrayList(log));
SearchLogRq searchLogRq = new SearchLogRq();
searchLogRq.setSearchMode(CURRENT_LAUNCH.getValue());
searchLogRq.setFilterId(1L);
when(searchCollectorFactory.getCollector(CURRENT_LAUNCH)).thenReturn(currentLaunchCollector);
when(currentLaunchCollector.collect(any(), any())).thenReturn(Collections.singletonList(1L));
Iterable<SearchLogRs> responses = searchLogService.search(1L, searchLogRq, projectDetails);
Assertions.assertNotNull(responses);
Assertions.assertEquals(1, Lists.newArrayList(responses).size());
}
use of com.epam.ta.reportportal.ws.model.log.SearchLogRs in project service-api by reportportal.
the class SearchLogServiceImpl method composeResponse.
private SearchLogRs composeResponse(Map<Long, TestItem> testItemMapping, Long projectId, Long itemId, Log log) {
TestItem testItem = ofNullable(testItemMapping.get(itemId)).orElseThrow(() -> new ReportPortalException(ErrorType.TEST_ITEM_NOT_FOUND, itemId));
Long launchId = ofNullable(testItem.getLaunchId()).orElseThrow(() -> new ReportPortalException(ErrorType.LAUNCH_NOT_FOUND, testItem.getLaunchId()));
Launch launch = launchRepository.findById(launchId).orElseThrow(() -> new ReportPortalException(ErrorType.LAUNCH_NOT_FOUND, launchId));
Map<Long, PathName> pathNameMapping = testItemRepository.selectPathNames(singletonList(testItem));
SearchLogRs response = new SearchLogRs();
response.setLaunchId(launch.getId());
ofNullable(pathNameMapping.get(testItem.getItemId())).ifPresent(pathName -> {
response.setPathNames(TestItemConverter.PATH_NAME_TO_RESOURCE.apply(pathName));
});
response.setItemId(testItem.getItemId());
response.setItemName(testItem.getName());
response.setPath(testItem.getPath());
response.setPatternTemplates(testItem.getPatternTemplateTestItems().stream().map(patternTemplateTestItem -> patternTemplateTestItem.getPatternTemplate().getName()).collect(toSet()));
response.setDuration(ofNullable(testItem.getItemResults().getDuration()).orElseGet(() -> getDuration(testItem)));
response.setStatus(testItem.getItemResults().getStatus().name());
TestItem itemWithStats = testItem;
while (!itemWithStats.isHasStats()) {
final Long parentId = itemWithStats.getParentId();
itemWithStats = testItemRepository.findById(parentId).orElseThrow(() -> new ReportPortalException(ErrorType.TEST_ITEM_NOT_FOUND, parentId));
}
response.setIssue(IssueConverter.TO_MODEL.apply(itemWithStats.getItemResults().getIssue()));
response.setLogs(Lists.newArrayList(TO_LOG_ENTRY.apply(log)));
return response;
}
Aggregations