Search in sources :

Example 1 with SearchLogRq

use of com.epam.ta.reportportal.ws.model.log.SearchLogRq 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());
}
Also used : StatusEnum(com.epam.ta.reportportal.entity.enums.StatusEnum) java.util(java.util) Project(com.epam.ta.reportportal.entity.project.Project) TestItem(com.epam.ta.reportportal.entity.item.TestItem) LogLevel(com.epam.ta.reportportal.entity.enums.LogLevel) Autowired(org.springframework.beans.factory.annotation.Autowired) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) SearchCollectorFactory(com.epam.ta.reportportal.core.analyzer.auto.strategy.search.SearchCollectorFactory) Collections.singletonList(java.util.Collections.singletonList) Preconditions.statusIn(com.epam.ta.reportportal.commons.Preconditions.statusIn) Lists(com.google.common.collect.Lists) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) Collectors.toMap(java.util.stream.Collectors.toMap) CollectionUtils(org.apache.commons.collections.CollectionUtils) Service(org.springframework.stereotype.Service) Log(com.epam.ta.reportportal.entity.log.Log) TestItemConverter(com.epam.ta.reportportal.ws.converter.converters.TestItemConverter) LogRepository(com.epam.ta.reportportal.dao.LogRepository) Predicates.not(com.epam.ta.reportportal.commons.Predicates.not) SearchLogRs(com.epam.ta.reportportal.ws.model.log.SearchLogRs) SearchLogService(com.epam.ta.reportportal.core.analyzer.auto.SearchLogService) TestItemRepository(com.epam.ta.reportportal.dao.TestItemRepository) SearchLogRq(com.epam.ta.reportportal.ws.model.log.SearchLogRq) TO_LOG_ENTRY(com.epam.ta.reportportal.ws.converter.converters.LogConverter.TO_LOG_ENTRY) Collectors.toSet(java.util.stream.Collectors.toSet) Launch(com.epam.ta.reportportal.entity.launch.Launch) SearchRq(com.epam.ta.reportportal.ws.model.analyzer.SearchRq) BusinessRule.expect(com.epam.ta.reportportal.commons.validation.BusinessRule.expect) Optional.ofNullable(java.util.Optional.ofNullable) IssueConverter(com.epam.ta.reportportal.ws.converter.converters.IssueConverter) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) AnalyzerConfig(com.epam.ta.reportportal.ws.model.project.AnalyzerConfig) Maps(com.google.common.collect.Maps) PathName(com.epam.ta.reportportal.entity.item.PathName) ChronoUnit(java.time.temporal.ChronoUnit) SearchLogsMode(com.epam.ta.reportportal.core.analyzer.auto.strategy.search.SearchLogsMode) LaunchRepository(com.epam.ta.reportportal.dao.LaunchRepository) ProjectRepository(com.epam.ta.reportportal.dao.ProjectRepository) SearchRs(com.epam.ta.reportportal.ws.model.analyzer.SearchRs) AnalyzerServiceClient(com.epam.ta.reportportal.core.analyzer.auto.client.AnalyzerServiceClient) Transactional(org.springframework.transaction.annotation.Transactional) Project(com.epam.ta.reportportal.entity.project.Project) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) Launch(com.epam.ta.reportportal.entity.launch.Launch) TestItem(com.epam.ta.reportportal.entity.item.TestItem)

Example 2 with SearchLogRq

use of com.epam.ta.reportportal.ws.model.log.SearchLogRq in project service-api by reportportal.

the class LogControllerTest method searchLogsNegative.

@Test
void searchLogsNegative() throws Exception {
    SearchLogRq rq = new SearchLogRq();
    rq.setSearchMode("currentLaunch");
    rq.setFilterId(1L);
    mockMvc.perform(post(DEFAULT_PROJECT_BASE_URL + "/log/search/1").with(token(oAuthHelper.getDefaultToken())).contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsBytes(rq))).andExpect(result -> assertTrue(result.getResolvedException() instanceof ReportPortalException)).andExpect(result -> assertEquals("Unable to perform operation for non-finished test item.", result.getResolvedException().getMessage()));
    ;
}
Also used : Date(java.util.Date) MediaType(org.springframework.http.MediaType) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LocalDateTime(java.time.LocalDateTime) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) Autowired(org.springframework.beans.factory.annotation.Autowired) BaseMvcTest(com.epam.ta.reportportal.ws.BaseMvcTest) SaveLogRQ(com.epam.ta.reportportal.ws.model.log.SaveLogRQ) UUID(java.util.UUID) Sql(org.springframework.test.context.jdbc.Sql) MockMvcRequestBuilders(org.springframework.test.web.servlet.request.MockMvcRequestBuilders) ZoneId(java.time.ZoneId) Test(org.junit.jupiter.api.Test) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SearchLogRq(com.epam.ta.reportportal.ws.model.log.SearchLogRq) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) SearchLogRq(com.epam.ta.reportportal.ws.model.log.SearchLogRq) BaseMvcTest(com.epam.ta.reportportal.ws.BaseMvcTest) Test(org.junit.jupiter.api.Test)

Example 3 with SearchLogRq

use of com.epam.ta.reportportal.ws.model.log.SearchLogRq 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());
}
Also used : SearchRq(com.epam.ta.reportportal.ws.model.analyzer.SearchRq) Log(com.epam.ta.reportportal.entity.log.Log) IssueType(com.epam.ta.reportportal.entity.item.issue.IssueType) IssueEntity(com.epam.ta.reportportal.entity.item.issue.IssueEntity) SearchLogRs(com.epam.ta.reportportal.ws.model.log.SearchLogRs) SearchRs(com.epam.ta.reportportal.ws.model.analyzer.SearchRs) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) SearchLogRq(com.epam.ta.reportportal.ws.model.log.SearchLogRq) Test(org.junit.jupiter.api.Test)

Aggregations

SearchLogRq (com.epam.ta.reportportal.ws.model.log.SearchLogRq)3 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)2 Log (com.epam.ta.reportportal.entity.log.Log)2 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)2 SearchRq (com.epam.ta.reportportal.ws.model.analyzer.SearchRq)2 SearchRs (com.epam.ta.reportportal.ws.model.analyzer.SearchRs)2 SearchLogRs (com.epam.ta.reportportal.ws.model.log.SearchLogRs)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Preconditions.statusIn (com.epam.ta.reportportal.commons.Preconditions.statusIn)1 Predicates.not (com.epam.ta.reportportal.commons.Predicates.not)1 BusinessRule.expect (com.epam.ta.reportportal.commons.validation.BusinessRule.expect)1 SearchLogService (com.epam.ta.reportportal.core.analyzer.auto.SearchLogService)1 AnalyzerServiceClient (com.epam.ta.reportportal.core.analyzer.auto.client.AnalyzerServiceClient)1 SearchCollectorFactory (com.epam.ta.reportportal.core.analyzer.auto.strategy.search.SearchCollectorFactory)1 SearchLogsMode (com.epam.ta.reportportal.core.analyzer.auto.strategy.search.SearchLogsMode)1 LaunchRepository (com.epam.ta.reportportal.dao.LaunchRepository)1 LogRepository (com.epam.ta.reportportal.dao.LogRepository)1 ProjectRepository (com.epam.ta.reportportal.dao.ProjectRepository)1 TestItemRepository (com.epam.ta.reportportal.dao.TestItemRepository)1 LogLevel (com.epam.ta.reportportal.entity.enums.LogLevel)1