Search in sources :

Example 1 with ProjectIssueType

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

the class UserControllerTest method createUserByAdminPositive.

@Test
void createUserByAdminPositive() throws Exception {
    CreateUserRQFull rq = new CreateUserRQFull();
    rq.setLogin("testLogin");
    rq.setPassword("testPassword");
    rq.setFullName("Test User");
    rq.setEmail("test@test.com");
    rq.setAccountRole("USER");
    rq.setProjectRole("MEMBER");
    rq.setDefaultProject("default_personal");
    MvcResult mvcResult = mockMvc.perform(post("/v1/user").with(token(oAuthHelper.getSuperadminToken())).contentType(APPLICATION_JSON).content(objectMapper.writeValueAsBytes(rq))).andExpect(status().isCreated()).andReturn();
    CreateUserRS createUserRS = objectMapper.readValue(mvcResult.getResponse().getContentAsString(), CreateUserRS.class);
    assertNotNull(createUserRS.getId());
    assertEquals(normalizeId(rq.getLogin()), createUserRS.getLogin());
    assertTrue(userRepository.findById(createUserRS.getId()).isPresent());
    final Optional<Project> projectOptional = projectRepository.findByName("default_personal");
    assertTrue(projectOptional.isPresent());
    assertTrue(projectOptional.get().getUsers().stream().anyMatch(config -> config.getUser().getLogin().equals("testlogin")));
    Optional<Project> personalProject = projectRepository.findByName("testlogin_personal");
    assertTrue(personalProject.isPresent(), "Personal project isn't created");
    Project project = personalProject.get();
    List<IssueType> defaultIssueTypes = issueTypeRepository.getDefaultIssueTypes();
    project.getProjectAttributes().forEach(projectAttribute -> assertTrue(projectAttribute.getValue().equalsIgnoreCase(ProjectAttributeEnum.findByAttributeName(projectAttribute.getAttribute().getName()).get().getDefaultValue())));
    assertTrue(defaultIssueTypes.containsAll(project.getProjectIssueTypes().stream().map(ProjectIssueType::getIssueType).collect(Collectors.toList())));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Project(com.epam.ta.reportportal.entity.project.Project) DeleteBulkRQ(com.epam.ta.reportportal.ws.model.DeleteBulkRQ) Autowired(org.springframework.beans.factory.annotation.Autowired) ProjectAttributeEnum(com.epam.ta.reportportal.entity.enums.ProjectAttributeEnum) Lists(com.google.common.collect.Lists) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) MvcResult(org.springframework.test.web.servlet.MvcResult) IssueType(com.epam.ta.reportportal.entity.item.issue.IssueType) ValidationConstraints(com.epam.ta.reportportal.ws.model.ValidationConstraints) APPLICATION_JSON(org.springframework.http.MediaType.APPLICATION_JSON) Integration(com.epam.ta.reportportal.entity.integration.Integration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IssueTypeRepository(com.epam.ta.reportportal.dao.IssueTypeRepository) UserRepository(com.epam.ta.reportportal.dao.UserRepository) BaseMvcTest(com.epam.ta.reportportal.ws.BaseMvcTest) Mockito.doNothing(org.mockito.Mockito.doNothing) Mockito.when(org.mockito.Mockito.when) com.epam.ta.reportportal.ws.model.user(com.epam.ta.reportportal.ws.model.user) Sql(org.springframework.test.context.jdbc.Sql) Collectors(java.util.stream.Collectors) MockMvcRequestBuilders(org.springframework.test.web.servlet.request.MockMvcRequestBuilders) Test(org.junit.jupiter.api.Test) List(java.util.List) EntityUtils.normalizeId(com.epam.ta.reportportal.commons.EntityUtils.normalizeId) ProjectRepository(com.epam.ta.reportportal.dao.ProjectRepository) ProjectIssueType(com.epam.ta.reportportal.entity.project.ProjectIssueType) Assertions(org.junit.jupiter.api.Assertions) Page(com.epam.ta.reportportal.ws.model.Page) Optional(java.util.Optional) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) Project(com.epam.ta.reportportal.entity.project.Project) IssueType(com.epam.ta.reportportal.entity.item.issue.IssueType) ProjectIssueType(com.epam.ta.reportportal.entity.project.ProjectIssueType) MvcResult(org.springframework.test.web.servlet.MvcResult) BaseMvcTest(com.epam.ta.reportportal.ws.BaseMvcTest) Test(org.junit.jupiter.api.Test)

Example 2 with ProjectIssueType

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

the class UpdateProjectSettingsHandlerImpl method updateProjectIssueSubType.

@Override
public OperationCompletionRS updateProjectIssueSubType(String projectName, ReportPortalUser user, UpdateIssueSubTypeRQ updateIssueSubTypeRQ) {
    expect(updateIssueSubTypeRQ.getIds().size() > 0, equalTo(true)).verify(FORBIDDEN_OPERATION, "Please specify at least one item data for update.");
    Project project = projectRepository.findByName(projectName).orElseThrow(() -> new ReportPortalException(PROJECT_NOT_FOUND, projectName));
    List<IssueTypeActivityResource> issueTypeActivityResources = updateIssueSubTypeRQ.getIds().stream().map(subTypeRQ -> TO_ACTIVITY_RESOURCE.apply(validateAndUpdate(subTypeRQ, project.getProjectIssueTypes().stream().map(ProjectIssueType::getIssueType).collect(Collectors.toList())))).collect(Collectors.toList());
    projectRepository.save(project);
    issueTypeActivityResources.forEach(it -> messageBus.publishActivity(new DefectTypeUpdatedEvent(it, user.getUserId(), user.getUsername(), project.getId())));
    return new OperationCompletionRS("Issue sub-type(s) was updated successfully.");
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS) UpdateIssueSubTypeRQ(com.epam.ta.reportportal.ws.model.project.config.UpdateIssueSubTypeRQ) UpdateOneIssueSubTypeRQ(com.epam.ta.reportportal.ws.model.project.config.UpdateOneIssueSubTypeRQ) PatternTemplate(com.epam.ta.reportportal.entity.pattern.PatternTemplate) Autowired(org.springframework.beans.factory.annotation.Autowired) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) MessageBus(com.epam.ta.reportportal.core.events.MessageBus) UpdateProjectSettingsHandler(com.epam.ta.reportportal.core.project.settings.UpdateProjectSettingsHandler) StringUtils(org.apache.commons.lang3.StringUtils) DefectTypeUpdatedEvent(com.epam.ta.reportportal.core.events.activity.DefectTypeUpdatedEvent) PatternTemplateActivityResource(com.epam.ta.reportportal.ws.model.activity.PatternTemplateActivityResource) Predicates(com.epam.ta.reportportal.commons.Predicates) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) PatternUpdatedEvent(com.epam.ta.reportportal.core.events.activity.PatternUpdatedEvent) Service(org.springframework.stereotype.Service) IssueType(com.epam.ta.reportportal.entity.item.issue.IssueType) PatternTemplateConverter(com.epam.ta.reportportal.ws.converter.converters.PatternTemplateConverter) BusinessRule(com.epam.ta.reportportal.commons.validation.BusinessRule) IssueTypeActivityResource(com.epam.ta.reportportal.ws.model.activity.IssueTypeActivityResource) BusinessRule.expect(com.epam.ta.reportportal.commons.validation.BusinessRule.expect) Optional.ofNullable(java.util.Optional.ofNullable) TestItemIssueGroup(com.epam.ta.reportportal.entity.enums.TestItemIssueGroup) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) PatternTemplateRepository(com.epam.ta.reportportal.dao.PatternTemplateRepository) List(java.util.List) TO_ACTIVITY_RESOURCE(com.epam.ta.reportportal.ws.converter.converters.IssueTypeConverter.TO_ACTIVITY_RESOURCE) ProjectRepository(com.epam.ta.reportportal.dao.ProjectRepository) ProjectIssueType(com.epam.ta.reportportal.entity.project.ProjectIssueType) Suppliers(com.epam.ta.reportportal.commons.validation.Suppliers) UpdatePatternTemplateRQ(com.epam.ta.reportportal.ws.model.project.config.pattern.UpdatePatternTemplateRQ) Transactional(org.springframework.transaction.annotation.Transactional) Project(com.epam.ta.reportportal.entity.project.Project) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) DefectTypeUpdatedEvent(com.epam.ta.reportportal.core.events.activity.DefectTypeUpdatedEvent) IssueTypeActivityResource(com.epam.ta.reportportal.ws.model.activity.IssueTypeActivityResource) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS)

Example 3 with ProjectIssueType

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

the class CreateProjectSettingsHandlerImplTest method getSubTypes.

private Set<ProjectIssueType> getSubTypes() {
    HashSet<ProjectIssueType> subTypes = new HashSet<>();
    for (int i = 1; i < 16; i++) {
        IssueType issueType = new IssueType();
        issueType.setId((long) i);
        issueType.setIssueGroup(new IssueGroup(TestItemIssueGroup.PRODUCT_BUG));
        ProjectIssueType projectIssueType = new ProjectIssueType();
        projectIssueType.setIssueType(issueType);
        subTypes.add(projectIssueType);
    }
    return subTypes;
}
Also used : ProjectIssueType(com.epam.ta.reportportal.entity.project.ProjectIssueType) TestItemIssueGroup(com.epam.ta.reportportal.entity.enums.TestItemIssueGroup) IssueGroup(com.epam.ta.reportportal.entity.item.issue.IssueGroup) ProjectIssueType(com.epam.ta.reportportal.entity.project.ProjectIssueType) IssueType(com.epam.ta.reportportal.entity.item.issue.IssueType) HashSet(java.util.HashSet)

Example 4 with ProjectIssueType

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

the class EmailServiceTest method prepareLaunchTest.

@Test
void prepareLaunchTest() {
    when(templateEngine.merge(any(String.class), any(Map.class))).thenReturn("EMAIL MESSAGE");
    ProjectIssueType projectIssueType = new ProjectIssueType();
    IssueType issueType = new IssueType();
    issueType.setLocator("pb001");
    issueType.setLongName("ProductBug");
    projectIssueType.setIssueType(issueType);
    String url = emailService.mergeFinishLaunchText("url", getLaunch(), Sets.newHashSet(projectIssueType));
    System.out.println(url);
}
Also used : ProjectIssueType(com.epam.ta.reportportal.entity.project.ProjectIssueType) ProjectIssueType(com.epam.ta.reportportal.entity.project.ProjectIssueType) IssueType(com.epam.ta.reportportal.entity.item.issue.IssueType) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 5 with ProjectIssueType

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

the class CreateProjectSettingsHandlerImpl method createProjectIssueSubType.

@Override
public IssueSubTypeCreatedRS createProjectIssueSubType(String projectName, ReportPortalUser user, CreateIssueSubTypeRQ rq) {
    Project project = projectRepository.findByName(projectName).orElseThrow(() -> new ReportPortalException(PROJECT_NOT_FOUND, projectName));
    expect(NOT_ISSUE_FLAG.getValue().equalsIgnoreCase(rq.getTypeRef()), equalTo(false)).verify(INCORRECT_REQUEST, "Impossible to create sub-type for 'Not Issue' type.");
    /* Check if global issue type reference is valid */
    TestItemIssueGroup expectedGroup = TestItemIssueGroup.fromValue(rq.getTypeRef()).orElseThrow(() -> new ReportPortalException(BAD_REQUEST_ERROR, rq.getTypeRef()));
    List<ProjectIssueType> existingSubTypes = project.getProjectIssueTypes().stream().filter(projectIssueType -> projectIssueType.getIssueType().getIssueGroup().getTestItemIssueGroup().equals(expectedGroup)).collect(Collectors.toList());
    expect(existingSubTypes.size() < ValidationConstraints.MAX_ISSUE_SUBTYPES, equalTo(true)).verify(INCORRECT_REQUEST, "Sub Issues count is bound of size limit");
    String locator = PREFIX.get(expectedGroup.getValue()) + shortUUID();
    IssueType subType = new IssueTypeBuilder().addLocator(locator).addIssueGroup(issueGroupRepository.findByTestItemIssueGroup(expectedGroup)).addLongName(rq.getLongName()).addShortName(rq.getShortName()).addHexColor(rq.getColor()).get();
    ProjectIssueType projectIssueType = new ProjectIssueType();
    projectIssueType.setIssueType(subType);
    projectIssueType.setProject(project);
    project.getProjectIssueTypes().add(projectIssueType);
    issueTypeRepository.save(subType);
    projectRepository.save(project);
    updateWidgets(project, subType);
    messageBus.publishActivity(new DefectTypeCreatedEvent(TO_ACTIVITY_RESOURCE.apply(subType), user.getUserId(), user.getUsername(), project.getId()));
    return new IssueSubTypeCreatedRS(subType.getId(), subType.getLocator());
}
Also used : ProjectIssueType(com.epam.ta.reportportal.entity.project.ProjectIssueType) Arrays(java.util.Arrays) Project(com.epam.ta.reportportal.entity.project.Project) PatternTemplate(com.epam.ta.reportportal.entity.pattern.PatternTemplate) Autowired(org.springframework.beans.factory.annotation.Autowired) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) MessageBus(com.epam.ta.reportportal.core.events.MessageBus) ByteBuffer(java.nio.ByteBuffer) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) IssueTypeBuilder(com.epam.ta.reportportal.ws.converter.builders.IssueTypeBuilder) Predicates.equalTo(com.epam.ta.reportportal.commons.Predicates.equalTo) Service(org.springframework.stereotype.Service) IssueGroupRepository(com.epam.ta.reportportal.dao.IssueGroupRepository) IssueSubTypeCreatedRS(com.epam.ta.reportportal.ws.model.project.config.IssueSubTypeCreatedRS) Map(java.util.Map) IssueType(com.epam.ta.reportportal.entity.item.issue.IssueType) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ValidationConstraints(com.epam.ta.reportportal.ws.model.ValidationConstraints) PatternTemplateConverter(com.epam.ta.reportportal.ws.converter.converters.PatternTemplateConverter) Charsets(com.google.common.base.Charsets) CreatePatternTemplateRQ(com.epam.ta.reportportal.ws.model.project.config.pattern.CreatePatternTemplateRQ) ImmutableMap(com.google.common.collect.ImmutableMap) BusinessRule.expect(com.epam.ta.reportportal.commons.validation.BusinessRule.expect) DefectTypeCreatedEvent(com.epam.ta.reportportal.core.events.activity.DefectTypeCreatedEvent) TestItemIssueGroup(com.epam.ta.reportportal.entity.enums.TestItemIssueGroup) IssueTypeRepository(com.epam.ta.reportportal.dao.IssueTypeRepository) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) CreateProjectSettingsHandler(com.epam.ta.reportportal.core.project.settings.CreateProjectSettingsHandler) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) PatternCreatedEvent(com.epam.ta.reportportal.core.events.activity.PatternCreatedEvent) WidgetRepository(com.epam.ta.reportportal.dao.WidgetRepository) WidgetType(com.epam.ta.reportportal.entity.widget.WidgetType) List(java.util.List) CreatePatternTemplateHandler(com.epam.ta.reportportal.core.analyzer.pattern.CreatePatternTemplateHandler) TO_ACTIVITY_RESOURCE(com.epam.ta.reportportal.ws.converter.converters.IssueTypeConverter.TO_ACTIVITY_RESOURCE) EntryCreatedRS(com.epam.ta.reportportal.ws.model.EntryCreatedRS) ProjectRepository(com.epam.ta.reportportal.dao.ProjectRepository) IssueGroup(com.epam.ta.reportportal.entity.item.issue.IssueGroup) ProjectIssueType(com.epam.ta.reportportal.entity.project.ProjectIssueType) CreateIssueSubTypeRQ(com.epam.ta.reportportal.ws.model.project.config.CreateIssueSubTypeRQ) Widget(com.epam.ta.reportportal.entity.widget.Widget) Suppliers(com.epam.ta.reportportal.commons.validation.Suppliers) PatternTemplateType(com.epam.ta.reportportal.entity.pattern.PatternTemplateType) Transactional(org.springframework.transaction.annotation.Transactional) Project(com.epam.ta.reportportal.entity.project.Project) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) IssueType(com.epam.ta.reportportal.entity.item.issue.IssueType) ProjectIssueType(com.epam.ta.reportportal.entity.project.ProjectIssueType) IssueSubTypeCreatedRS(com.epam.ta.reportportal.ws.model.project.config.IssueSubTypeCreatedRS) DefectTypeCreatedEvent(com.epam.ta.reportportal.core.events.activity.DefectTypeCreatedEvent) TestItemIssueGroup(com.epam.ta.reportportal.entity.enums.TestItemIssueGroup) IssueTypeBuilder(com.epam.ta.reportportal.ws.converter.builders.IssueTypeBuilder)

Aggregations

IssueType (com.epam.ta.reportportal.entity.item.issue.IssueType)6 ProjectIssueType (com.epam.ta.reportportal.entity.project.ProjectIssueType)6 Project (com.epam.ta.reportportal.entity.project.Project)4 ProjectRepository (com.epam.ta.reportportal.dao.ProjectRepository)3 TestItemIssueGroup (com.epam.ta.reportportal.entity.enums.TestItemIssueGroup)3 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)3 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)2 BusinessRule.expect (com.epam.ta.reportportal.commons.validation.BusinessRule.expect)2 Suppliers (com.epam.ta.reportportal.commons.validation.Suppliers)2 MessageBus (com.epam.ta.reportportal.core.events.MessageBus)2 IssueTypeRepository (com.epam.ta.reportportal.dao.IssueTypeRepository)2 IssueGroup (com.epam.ta.reportportal.entity.item.issue.IssueGroup)2 PatternTemplate (com.epam.ta.reportportal.entity.pattern.PatternTemplate)2 TO_ACTIVITY_RESOURCE (com.epam.ta.reportportal.ws.converter.converters.IssueTypeConverter.TO_ACTIVITY_RESOURCE)2 PatternTemplateConverter (com.epam.ta.reportportal.ws.converter.converters.PatternTemplateConverter)2 ErrorType (com.epam.ta.reportportal.ws.model.ErrorType)2 OperationCompletionRS (com.epam.ta.reportportal.ws.model.OperationCompletionRS)2 ValidationConstraints (com.epam.ta.reportportal.ws.model.ValidationConstraints)2 List (java.util.List)2 Map (java.util.Map)2