use of com.epam.ta.reportportal.ws.model.issue.IssueDefinition in project service-api by reportportal.
the class TestItemControllerTest method defineTestItemIssue.
@Test
void defineTestItemIssue() throws Exception {
DefineIssueRQ rq = new DefineIssueRQ();
IssueDefinition issueDefinition = new IssueDefinition();
issueDefinition.setId(3L);
Issue issue = new Issue();
issue.setIssueType("pb001");
issue.setIgnoreAnalyzer(false);
issueDefinition.setIssue(issue);
rq.setIssues(Collections.singletonList(issueDefinition));
mockMvc.perform(put(DEFAULT_PROJECT_BASE_URL + "/item").with(token(oAuthHelper.getDefaultToken())).contentType(APPLICATION_JSON).content(objectMapper.writeValueAsBytes(rq))).andExpect(status().isOk());
}
use of com.epam.ta.reportportal.ws.model.issue.IssueDefinition in project service-api by reportportal.
the class TestItemControllerValidationTest method shouldReturnBadRequestWhenMoreThan300Issues.
@Test
public void shouldReturnBadRequestWhenMoreThan300Issues() throws Exception {
// GIVEN
final DefineIssueRQ defineIssueRQ = new DefineIssueRQ();
defineIssueRQ.setIssues(Stream.generate(() -> {
final IssueDefinition issueDefinition = new IssueDefinition();
issueDefinition.setId(1L);
final Issue issue = new Issue();
issue.setComment("comment");
issue.setIssueType("ab001");
issueDefinition.setIssue(issue);
return issueDefinition;
}).limit(301).collect(Collectors.toList()));
// WHEN
MvcResult mvcResult = mockMvc.perform(put(DEFAULT_PROJECT_BASE_URL + ITEM_PATH).with(token(oAuthHelper.getDefaultToken())).content(objectMapper.writeValueAsBytes(defineIssueRQ)).contentType(APPLICATION_JSON)).andExpect(status().isBadRequest()).andReturn();
// THEN
ErrorRS error = objectMapper.readValue(mvcResult.getResponse().getContentAsString(), ErrorRS.class);
assertEquals(INCORRECT_REQUEST, error.getErrorType());
assertEquals(INCORRECT_REQUEST_MESSAGE + "[Field 'issues' should have size from '0' to '300'.] ", error.getMessage());
}
use of com.epam.ta.reportportal.ws.model.issue.IssueDefinition in project service-api by reportportal.
the class UpdateTestItemHandlerImpl method defineTestItemsIssues.
@Override
public List<Issue> defineTestItemsIssues(ReportPortalUser.ProjectDetails projectDetails, DefineIssueRQ defineIssue, ReportPortalUser user) {
Project project = projectRepository.findById(projectDetails.getProjectId()).orElseThrow(() -> new ReportPortalException(PROJECT_NOT_FOUND, projectDetails.getProjectId()));
List<String> errors = new ArrayList<>();
List<IssueDefinition> definitions = defineIssue.getIssues();
expect(CollectionUtils.isEmpty(definitions), equalTo(false)).verify(FAILED_TEST_ITEM_ISSUE_TYPE_DEFINITION);
List<Issue> updated = new ArrayList<>(defineIssue.getIssues().size());
List<ItemIssueTypeDefinedEvent> events = new ArrayList<>();
List<TestItem> itemsForIndexUpdate = new ArrayList<>();
List<Long> itemsForIndexRemove = new ArrayList<>();
definitions.forEach(issueDefinition -> {
try {
TestItem testItem = testItemRepository.findById(issueDefinition.getId()).orElseThrow(() -> new BusinessRuleViolationException(formattedSupplier("Cannot update issue type for test item '{}', cause it is not found.", issueDefinition.getId()).get()));
verifyTestItem(testItem, issueDefinition.getId());
TestItemActivityResource before = TO_ACTIVITY_RESOURCE.apply(testItem, projectDetails.getProjectId());
Issue issue = issueDefinition.getIssue();
IssueType issueType = issueTypeHandler.defineIssueType(projectDetails.getProjectId(), issue.getIssueType());
IssueEntity issueEntity = new IssueEntityBuilder(testItem.getItemResults().getIssue()).addIssueType(issueType).addDescription(issue.getComment()).addIgnoreFlag(issue.getIgnoreAnalyzer()).addAutoAnalyzedFlag(issue.getAutoAnalyzed()).get();
externalTicketHandler.updateLinking(user.getUsername(), issueEntity, issueDefinition.getIssue().getExternalSystemIssues());
testItem.getItemResults().setIssue(issueEntity);
issueEntity.setTestItemResults(testItem.getItemResults());
testItemRepository.save(testItem);
if (ITEM_CAN_BE_INDEXED.test(testItem)) {
itemsForIndexUpdate.add(testItem);
} else {
itemsForIndexRemove.add(testItem.getItemId());
}
updated.add(IssueConverter.TO_MODEL.apply(issueEntity));
TestItemActivityResource after = TO_ACTIVITY_RESOURCE.apply(testItem, projectDetails.getProjectId());
events.add(new ItemIssueTypeDefinedEvent(before, after, user.getUserId(), user.getUsername()));
} catch (BusinessRuleViolationException e) {
errors.add(e.getMessage());
}
});
expect(errors.isEmpty(), equalTo(TRUE)).verify(FAILED_TEST_ITEM_ISSUE_TYPE_DEFINITION, errors.toString());
logIndexerService.indexDefectsUpdate(project.getId(), AnalyzerUtils.getAnalyzerConfig(project), itemsForIndexUpdate);
logIndexerService.indexItemsRemoveAsync(project.getId(), itemsForIndexRemove);
events.forEach(messageBus::publishActivity);
return updated;
}
use of com.epam.ta.reportportal.ws.model.issue.IssueDefinition in project service-api by reportportal.
the class TestItemControllerTest method defineTestItemIssueNegative.
@Test
void defineTestItemIssueNegative() throws Exception {
DefineIssueRQ rq = new DefineIssueRQ();
IssueDefinition issueDefinition = new IssueDefinition();
issueDefinition.setId(100L);
Issue issue = new Issue();
issue.setIssueType("pb001");
issue.setIgnoreAnalyzer(false);
issueDefinition.setIssue(issue);
rq.setIssues(Collections.singletonList(issueDefinition));
mockMvc.perform(put(DEFAULT_PROJECT_BASE_URL + "/item").with(token(oAuthHelper.getDefaultToken())).contentType(APPLICATION_JSON).content(objectMapper.writeValueAsBytes(rq))).andExpect(status().isBadRequest());
}
use of com.epam.ta.reportportal.ws.model.issue.IssueDefinition in project service-api by reportportal.
the class JaskonRequiredPropertiesValidatorTest method testInnerRequiredFields.
@Test
public void testInnerRequiredFields() {
IssueDefinition issueRQ = new IssueDefinition();
JaskonRequiredPropertiesValidator validator = new JaskonRequiredPropertiesValidator();
Errors errors = new BeanPropertyBindingResult(issueRQ, "issueRQ");
validator.validate(issueRQ, errors);
assertThat(errors.getAllErrors(), not(empty()));
assertThat(errors.getFieldError("issue"), not(nullValue()));
}
Aggregations