Search in sources :

Example 1 with CreateIssueSubTypeRQ

use of com.epam.ta.reportportal.ws.model.project.config.CreateIssueSubTypeRQ in project service-api by reportportal.

the class CreateProjectSettingsHandlerImplTest method createSubtypeOnNotExistProject.

@Test
void createSubtypeOnNotExistProject() {
    long projectId = 1L;
    ReportPortalUser user = getRpUser("user", UserRole.USER, ProjectRole.PROJECT_MANAGER, projectId);
    when(projectRepository.findByName(TEST_PROJECT_NAME)).thenReturn(Optional.empty());
    ReportPortalException exception = assertThrows(ReportPortalException.class, () -> handler.createProjectIssueSubType(TEST_PROJECT_NAME, user, new CreateIssueSubTypeRQ()));
    assertEquals("Project 'test_project' not found. Did you use correct project name?", exception.getMessage());
}
Also used : ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) CreateIssueSubTypeRQ(com.epam.ta.reportportal.ws.model.project.config.CreateIssueSubTypeRQ) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) Test(org.junit.jupiter.api.Test)

Example 2 with CreateIssueSubTypeRQ

use of com.epam.ta.reportportal.ws.model.project.config.CreateIssueSubTypeRQ in project service-api by reportportal.

the class CreateProjectSettingsHandlerImplTest method createSubtypeWithWrongGroup.

@Test
void createSubtypeWithWrongGroup() {
    long projectId = 1L;
    ReportPortalUser user = getRpUser("user", UserRole.USER, ProjectRole.PROJECT_MANAGER, projectId);
    when(projectRepository.findByName(TEST_PROJECT_NAME)).thenReturn(Optional.of(new Project()));
    CreateIssueSubTypeRQ createIssueSubTypeRQ = new CreateIssueSubTypeRQ();
    createIssueSubTypeRQ.setTypeRef("wrongType");
    ReportPortalException exception = assertThrows(ReportPortalException.class, () -> handler.createProjectIssueSubType(TEST_PROJECT_NAME, user, createIssueSubTypeRQ));
    assertEquals("Error in handled Request. Please, check specified parameters: 'wrongType'", exception.getMessage());
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) CreateIssueSubTypeRQ(com.epam.ta.reportportal.ws.model.project.config.CreateIssueSubTypeRQ) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) Test(org.junit.jupiter.api.Test)

Example 3 with CreateIssueSubTypeRQ

use of com.epam.ta.reportportal.ws.model.project.config.CreateIssueSubTypeRQ in project service-api by reportportal.

the class CreateProjectSettingsHandlerImplTest method maxSubtypesCount.

@Test
void maxSubtypesCount() {
    Project project = new Project();
    project.setProjectIssueTypes(getSubTypes());
    long projectId = 1L;
    ReportPortalUser user = getRpUser("user", UserRole.USER, ProjectRole.PROJECT_MANAGER, projectId);
    when(projectRepository.findByName(TEST_PROJECT_NAME)).thenReturn(Optional.of(project));
    CreateIssueSubTypeRQ createIssueSubTypeRQ = new CreateIssueSubTypeRQ();
    createIssueSubTypeRQ.setTypeRef("product_bug");
    ReportPortalException exception = assertThrows(ReportPortalException.class, () -> handler.createProjectIssueSubType(TEST_PROJECT_NAME, user, createIssueSubTypeRQ));
    assertEquals("Incorrect Request. Sub Issues count is bound of size limit", exception.getMessage());
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) CreateIssueSubTypeRQ(com.epam.ta.reportportal.ws.model.project.config.CreateIssueSubTypeRQ) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) Test(org.junit.jupiter.api.Test)

Example 4 with CreateIssueSubTypeRQ

use of com.epam.ta.reportportal.ws.model.project.config.CreateIssueSubTypeRQ in project service-api by reportportal.

the class ProjectSettingsControllerTest method createSubType.

@Test
void createSubType() throws Exception {
    CreateIssueSubTypeRQ rq = new CreateIssueSubTypeRQ();
    rq.setTypeRef("PRODUCT_BUG");
    rq.setColor("#eeeeee");
    rq.setLongName("LongName");
    rq.setShortName("name");
    mockMvc.perform(post(DEFAULT_PROJECT_BASE_URL + "/settings/sub-type").contentType(APPLICATION_JSON).with(token(oAuthHelper.getDefaultToken())).content(objectMapper.writeValueAsBytes(rq))).andExpect(status().isCreated());
}
Also used : CreateIssueSubTypeRQ(com.epam.ta.reportportal.ws.model.project.config.CreateIssueSubTypeRQ) BaseMvcTest(com.epam.ta.reportportal.ws.BaseMvcTest) Test(org.junit.jupiter.api.Test)

Example 5 with CreateIssueSubTypeRQ

use of com.epam.ta.reportportal.ws.model.project.config.CreateIssueSubTypeRQ 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

CreateIssueSubTypeRQ (com.epam.ta.reportportal.ws.model.project.config.CreateIssueSubTypeRQ)5 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)4 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)4 Test (org.junit.jupiter.api.Test)4 Project (com.epam.ta.reportportal.entity.project.Project)3 Predicates.equalTo (com.epam.ta.reportportal.commons.Predicates.equalTo)1 BusinessRule.expect (com.epam.ta.reportportal.commons.validation.BusinessRule.expect)1 Suppliers (com.epam.ta.reportportal.commons.validation.Suppliers)1 CreatePatternTemplateHandler (com.epam.ta.reportportal.core.analyzer.pattern.CreatePatternTemplateHandler)1 MessageBus (com.epam.ta.reportportal.core.events.MessageBus)1 DefectTypeCreatedEvent (com.epam.ta.reportportal.core.events.activity.DefectTypeCreatedEvent)1 PatternCreatedEvent (com.epam.ta.reportportal.core.events.activity.PatternCreatedEvent)1 CreateProjectSettingsHandler (com.epam.ta.reportportal.core.project.settings.CreateProjectSettingsHandler)1 IssueGroupRepository (com.epam.ta.reportportal.dao.IssueGroupRepository)1 IssueTypeRepository (com.epam.ta.reportportal.dao.IssueTypeRepository)1 ProjectRepository (com.epam.ta.reportportal.dao.ProjectRepository)1 WidgetRepository (com.epam.ta.reportportal.dao.WidgetRepository)1 TestItemIssueGroup (com.epam.ta.reportportal.entity.enums.TestItemIssueGroup)1 IssueGroup (com.epam.ta.reportportal.entity.item.issue.IssueGroup)1 IssueType (com.epam.ta.reportportal.entity.item.issue.IssueType)1