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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations