Search in sources :

Example 1 with ProjectAttribute

use of com.epam.ta.reportportal.entity.project.ProjectAttribute in project service-api by reportportal.

the class LaunchPatternAnalysisStrategyTest method analyzeTest.

@Test
void analyzeTest() {
    when(launchRepository.findById(1L)).thenReturn(Optional.of(launch));
    when(launch.getProjectId()).thenReturn(1L);
    when(launch.getMode()).thenReturn(LaunchModeEnum.DEFAULT);
    when(projectRepository.findById(1L)).thenReturn(Optional.of(project));
    ProjectAttribute projectAttribute = new ProjectAttribute();
    projectAttribute.setValue("true");
    Attribute attribute = new Attribute();
    projectAttribute.setAttribute(attribute);
    when(project.getProjectAttributes()).thenReturn(Sets.newHashSet(projectAttribute));
    ReportPortalUser user = getRpUser("user", UserRole.USER, ProjectRole.PROJECT_MANAGER, 1L);
    ReportPortalUser.ProjectDetails projectDetails = new ReportPortalUser.ProjectDetails(1L, "name", ProjectRole.PROJECT_MANAGER);
    AnalyzeLaunchRQ analyzeLaunchRQ = new AnalyzeLaunchRQ();
    analyzeLaunchRQ.setLaunchId(1L);
    analyzeLaunchRQ.setAnalyzeItemsModes(Lists.newArrayList("TO_INVESTIGATE"));
    analyzeLaunchRQ.setAnalyzerTypeName("patternAnalyzer");
    launchPatternAnalysisStrategy.analyze(analyzeLaunchRQ, projectDetails, user);
    verify(patternAnalyzer, times(1)).analyzeTestItems(launch, Sets.newHashSet(AnalyzeItemsMode.TO_INVESTIGATE));
}
Also used : Attribute(com.epam.ta.reportportal.entity.attribute.Attribute) ProjectAttribute(com.epam.ta.reportportal.entity.project.ProjectAttribute) AnalyzeLaunchRQ(com.epam.ta.reportportal.ws.model.launch.AnalyzeLaunchRQ) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) ProjectAttribute(com.epam.ta.reportportal.entity.project.ProjectAttribute) Test(org.junit.jupiter.api.Test)

Example 2 with ProjectAttribute

use of com.epam.ta.reportportal.entity.project.ProjectAttribute in project service-api by reportportal.

the class CreateProjectHandlerImpl method createProject.

@Override
public EntryCreatedRS createProject(CreateProjectRQ createProjectRQ, ReportPortalUser user) {
    String projectName = createProjectRQ.getProjectName().toLowerCase().trim();
    expect(projectName, not(equalTo(RESERVED_PROJECT_NAME))).verify(ErrorType.INCORRECT_REQUEST, Suppliers.formattedSupplier("Project with name '{}' is reserved by system", projectName));
    expect(projectName, com.epam.ta.reportportal.util.Predicates.SPECIAL_CHARS_ONLY.negate()).verify(ErrorType.INCORRECT_REQUEST, Suppliers.formattedSupplier("Project name '{}' consists only of special characters", projectName));
    Optional<Project> existProject = projectRepository.findByName(projectName);
    expect(existProject, not(isPresent())).verify(ErrorType.PROJECT_ALREADY_EXISTS, projectName);
    ProjectType projectType = ProjectType.findByName(createProjectRQ.getEntryType()).orElseThrow(() -> new ReportPortalException(ErrorType.BAD_REQUEST_ERROR, createProjectRQ.getEntryType()));
    expect(projectType, equalTo(ProjectType.INTERNAL)).verify(ErrorType.BAD_REQUEST_ERROR, "Only internal projects can be created via API");
    User dbUser = userRepository.findRawById(user.getUserId()).orElseThrow(() -> new ReportPortalException(ErrorType.USER_NOT_FOUND, user.getUsername()));
    Project project = new Project();
    project.setName(projectName);
    project.setCreationDate(new Date());
    project.setProjectIssueTypes(ProjectUtils.defaultIssueTypes(project, issueTypeRepository.getDefaultIssueTypes()));
    Set<ProjectAttribute> projectAttributes = ProjectUtils.defaultProjectAttributes(project, attributeRepository.getDefaultProjectAttributes());
    project.setProjectType(projectType);
    project.setProjectAttributes(projectAttributes);
    ProjectUser projectUser = new ProjectUser().withProject(project).withUser(dbUser).withProjectRole(ProjectRole.PROJECT_MANAGER);
    projectRepository.save(project);
    projectUserRepository.save(projectUser);
    applicationEventPublisher.publishEvent(new ProjectEvent(project.getId(), CREATE_KEY));
    return new EntryCreatedRS(project.getId());
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) ProjectUser(com.epam.ta.reportportal.entity.user.ProjectUser) ProjectUser(com.epam.ta.reportportal.entity.user.ProjectUser) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) User(com.epam.ta.reportportal.entity.user.User) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) ProjectType(com.epam.ta.reportportal.entity.enums.ProjectType) EntryCreatedRS(com.epam.ta.reportportal.ws.model.EntryCreatedRS) ProjectAttribute(com.epam.ta.reportportal.entity.project.ProjectAttribute) Date(java.util.Date) ProjectEvent(com.epam.reportportal.extension.event.ProjectEvent)

Example 3 with ProjectAttribute

use of com.epam.ta.reportportal.entity.project.ProjectAttribute in project service-api by reportportal.

the class ProjectControllerTest method updateProjectPositive.

@Test
void updateProjectPositive() throws Exception {
    final UpdateProjectRQ rq = new UpdateProjectRQ();
    ProjectConfigurationUpdate configuration = new ProjectConfigurationUpdate();
    HashMap<String, String> projectAttributes = new HashMap<>();
    projectAttributes.put("notifications.enabled", "false");
    // 2 weeks in seconds
    projectAttributes.put("job.keepLaunches", String.valueOf(3600 * 24 * 14));
    // 2 weeks in seconds
    projectAttributes.put("job.keepLogs", String.valueOf(3600 * 24 * 14));
    // 1 week in seconds
    projectAttributes.put("job.interruptJobTime", String.valueOf(3600 * 24 * 7));
    // 1 week in seconds
    projectAttributes.put("job.keepScreenshots", String.valueOf(3600 * 24 * 7));
    projectAttributes.put("analyzer.autoAnalyzerMode", "CURRENT_LAUNCH");
    projectAttributes.put("analyzer.minShouldMatch", "5");
    projectAttributes.put("analyzer.numberOfLogLines", "5");
    projectAttributes.put("analyzer.isAutoAnalyzerEnabled", "false");
    configuration.setProjectAttributes(projectAttributes);
    rq.setConfiguration(configuration);
    HashMap<String, String> userRoles = new HashMap<>();
    userRoles.put("test_user", "PROJECT_MANAGER");
    rq.setUserRoles(userRoles);
    mockMvc.perform(put("/v1/project/test_project").content(objectMapper.writeValueAsBytes(rq)).contentType(APPLICATION_JSON).with(token(oAuthHelper.getSuperadminToken()))).andExpect(status().isOk());
    Project project = projectRepository.findByName("test_project").get();
    projectAttributes.forEach((key, value) -> {
        Optional<ProjectAttribute> pa = project.getProjectAttributes().stream().filter(it -> it.getAttribute().getName().equalsIgnoreCase(key)).findAny();
        assertTrue(pa.isPresent());
        assertEquals(value, pa.get().getValue());
    });
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) java.util(java.util) Project(com.epam.ta.reportportal.entity.project.Project) MockMvcResultMatchers.jsonPath(org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath) DeleteBulkRQ(com.epam.ta.reportportal.ws.model.DeleteBulkRQ) Autowired(org.springframework.beans.factory.annotation.Autowired) CreateProjectRQ(com.epam.ta.reportportal.ws.model.project.CreateProjectRQ) AssignUsersRQ(com.epam.ta.reportportal.ws.model.project.AssignUsersRQ) Collections.singletonList(java.util.Collections.singletonList) ItemAttributeResource(com.epam.ta.reportportal.ws.model.attribute.ItemAttributeResource) ExchangeInfo(com.rabbitmq.http.client.domain.ExchangeInfo) ResultActions(org.springframework.test.web.servlet.ResultActions) Lists(com.google.common.collect.Lists) ProjectAttribute(com.epam.ta.reportportal.entity.project.ProjectAttribute) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) Qualifier(org.springframework.beans.factory.annotation.Qualifier) Matchers.hasSize(org.hamcrest.Matchers.hasSize) APPLICATION_JSON(org.springframework.http.MediaType.APPLICATION_JSON) RabbitTemplate(org.springframework.amqp.rabbit.core.RabbitTemplate) SenderCaseDTO(com.epam.ta.reportportal.ws.model.project.email.SenderCaseDTO) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) UpdateProjectRQ(com.epam.ta.reportportal.ws.model.project.UpdateProjectRQ) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BaseMvcTest(com.epam.ta.reportportal.ws.BaseMvcTest) Sql(org.springframework.test.context.jdbc.Sql) MockMvcRequestBuilders(org.springframework.test.web.servlet.request.MockMvcRequestBuilders) Sets(com.google.common.collect.Sets) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) UnassignUsersRQ(com.epam.ta.reportportal.ws.model.project.UnassignUsersRQ) AfterEach(org.junit.jupiter.api.AfterEach) ProjectRepository(com.epam.ta.reportportal.dao.ProjectRepository) Assertions(org.junit.jupiter.api.Assertions) ProjectConfigurationUpdate(com.epam.ta.reportportal.ws.model.project.config.ProjectConfigurationUpdate) Client(com.rabbitmq.http.client.Client) ProjectNotificationConfigDTO(com.epam.ta.reportportal.ws.model.project.email.ProjectNotificationConfigDTO) Project(com.epam.ta.reportportal.entity.project.Project) ProjectConfigurationUpdate(com.epam.ta.reportportal.ws.model.project.config.ProjectConfigurationUpdate) UpdateProjectRQ(com.epam.ta.reportportal.ws.model.project.UpdateProjectRQ) ProjectAttribute(com.epam.ta.reportportal.entity.project.ProjectAttribute) BaseMvcTest(com.epam.ta.reportportal.ws.BaseMvcTest) Test(org.junit.jupiter.api.Test)

Example 4 with ProjectAttribute

use of com.epam.ta.reportportal.entity.project.ProjectAttribute in project service-api by reportportal.

the class InterruptBrokenLaunchesJobTest method noInProgressItemsTest.

@Test
void noInProgressItemsTest() {
    String name = "name";
    Project project = new Project();
    final ProjectAttribute projectAttribute = new ProjectAttribute();
    final Attribute attribute = new Attribute();
    attribute.setName("job.interruptJobTime");
    projectAttribute.setAttribute(attribute);
    // 1 day in seconds
    projectAttribute.setValue(String.valueOf(3600 * 24));
    project.setProjectAttributes(Sets.newHashSet(projectAttribute));
    project.setName(name);
    long launchId = 1L;
    when(projectRepository.findAllIdsAndProjectAttributes(any())).thenReturn(new PageImpl<>(Collections.singletonList(project)));
    when(launchRepository.streamIdsWithStatusAndStartTimeBefore(any(), any(), any())).thenReturn(Stream.of(launchId));
    when(testItemRepository.hasItemsInStatusByLaunch(launchId, StatusEnum.IN_PROGRESS)).thenReturn(false);
    when(launchRepository.findById(launchId)).thenReturn(Optional.of(new Launch()));
    interruptBrokenLaunchesJob.execute(null);
    verify(launchRepository, times(1)).findById(launchId);
    verify(launchRepository, times(1)).save(any());
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) Attribute(com.epam.ta.reportportal.entity.attribute.Attribute) ProjectAttribute(com.epam.ta.reportportal.entity.project.ProjectAttribute) ProjectAttribute(com.epam.ta.reportportal.entity.project.ProjectAttribute) Launch(com.epam.ta.reportportal.entity.launch.Launch) Test(org.junit.jupiter.api.Test)

Example 5 with ProjectAttribute

use of com.epam.ta.reportportal.entity.project.ProjectAttribute in project service-api by reportportal.

the class ProjectActivityConverterTest method getProject.

private static Project getProject() {
    Project project = new Project();
    project.setId(1L);
    project.setName("name");
    final Attribute attribute = new Attribute();
    attribute.setId(2L);
    attribute.setName("attr.lol");
    final ProjectAttribute projectAttribute = new ProjectAttribute().withProject(project).withValue("value").withAttribute(attribute);
    project.setProjectAttributes(Sets.newHashSet(projectAttribute));
    return project;
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) Attribute(com.epam.ta.reportportal.entity.attribute.Attribute) ProjectAttribute(com.epam.ta.reportportal.entity.project.ProjectAttribute) ProjectAttribute(com.epam.ta.reportportal.entity.project.ProjectAttribute)

Aggregations

ProjectAttribute (com.epam.ta.reportportal.entity.project.ProjectAttribute)6 Project (com.epam.ta.reportportal.entity.project.Project)5 Attribute (com.epam.ta.reportportal.entity.attribute.Attribute)4 Test (org.junit.jupiter.api.Test)4 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)2 Launch (com.epam.ta.reportportal.entity.launch.Launch)2 ProjectEvent (com.epam.reportportal.extension.event.ProjectEvent)1 ProjectRepository (com.epam.ta.reportportal.dao.ProjectRepository)1 ProjectType (com.epam.ta.reportportal.entity.enums.ProjectType)1 ProjectUser (com.epam.ta.reportportal.entity.user.ProjectUser)1 User (com.epam.ta.reportportal.entity.user.User)1 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)1 BaseMvcTest (com.epam.ta.reportportal.ws.BaseMvcTest)1 DeleteBulkRQ (com.epam.ta.reportportal.ws.model.DeleteBulkRQ)1 EntryCreatedRS (com.epam.ta.reportportal.ws.model.EntryCreatedRS)1 ItemAttributeResource (com.epam.ta.reportportal.ws.model.attribute.ItemAttributeResource)1 AnalyzeLaunchRQ (com.epam.ta.reportportal.ws.model.launch.AnalyzeLaunchRQ)1 AssignUsersRQ (com.epam.ta.reportportal.ws.model.project.AssignUsersRQ)1 CreateProjectRQ (com.epam.ta.reportportal.ws.model.project.CreateProjectRQ)1 UnassignUsersRQ (com.epam.ta.reportportal.ws.model.project.UnassignUsersRQ)1