use of com.epam.ta.reportportal.ws.model.item.LinkExternalIssueRQ in project service-api by reportportal.
the class TestItemControllerTest method linkExternalIssues.
@Test
void linkExternalIssues() throws Exception {
LinkExternalIssueRQ rq = new LinkExternalIssueRQ();
rq.setTestItemIds(Collections.singletonList(3L));
Issue.ExternalSystemIssue issue = new Issue.ExternalSystemIssue();
issue.setBtsUrl("jira.com");
issue.setBtsProject("project");
issue.setTicketId("ticket1");
issue.setUrl("https://example.com/NEWTICKET1");
rq.setIssues(Collections.singletonList(issue));
mockMvc.perform(put(DEFAULT_PROJECT_BASE_URL + "/item/issue/link").with(token(oAuthHelper.getDefaultToken())).content(objectMapper.writeValueAsBytes(rq)).contentType(APPLICATION_JSON)).andExpect(status().isOk());
}
use of com.epam.ta.reportportal.ws.model.item.LinkExternalIssueRQ in project service-api by reportportal.
the class TestItemControllerValidationTest method shouldReturnBadRequestWhenMoreThan300IssuesToLink.
@Test
public void shouldReturnBadRequestWhenMoreThan300IssuesToLink() throws Exception {
// GIVEN
final LinkExternalIssueRQ linkExternalIssueRQ = new LinkExternalIssueRQ();
final Issue.ExternalSystemIssue externalSystemIssue = getExternalSystemIssue();
linkExternalIssueRQ.setIssues(Stream.generate(() -> externalSystemIssue).limit(301).collect(Collectors.toList()));
linkExternalIssueRQ.setTestItemIds(List.of(1L));
// WHEN
MvcResult mvcResult = mockMvc.perform(put(DEFAULT_PROJECT_BASE_URL + ITEM_PATH + "/issue/link").with(token(oAuthHelper.getDefaultToken())).content(objectMapper.writeValueAsBytes(linkExternalIssueRQ)).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.item.LinkExternalIssueRQ in project service-api by reportportal.
the class UpdateTestItemHandlerImpl method processExternalIssues.
@Override
public List<OperationCompletionRS> processExternalIssues(ExternalIssueRQ request, ReportPortalUser.ProjectDetails projectDetails, ReportPortalUser user) {
List<String> errors = new ArrayList<>();
List<TestItem> testItems = testItemRepository.findAllById(request.getTestItemIds());
testItems.forEach(testItem -> {
try {
verifyTestItem(testItem, testItem.getItemId());
} catch (Exception e) {
errors.add(e.getMessage());
}
});
expect(errors.isEmpty(), equalTo(TRUE)).verify(FAILED_TEST_ITEM_ISSUE_TYPE_DEFINITION, errors.toString());
List<TestItemActivityResource> before = testItems.stream().map(it -> TO_ACTIVITY_RESOURCE.apply(it, projectDetails.getProjectId())).collect(Collectors.toList());
if (LinkExternalIssueRQ.class.equals(request.getClass())) {
LinkExternalIssueRQ linkRequest = (LinkExternalIssueRQ) request;
externalTicketHandler.linkExternalTickets(user.getUsername(), testItems.stream().map(it -> it.getItemResults().getIssue()).collect(Collectors.toList()), linkRequest.getIssues());
}
if (UnlinkExternalIssueRQ.class.equals(request.getClass())) {
externalTicketHandler.unlinkExternalTickets(testItems, (UnlinkExternalIssueRQ) request);
}
testItemRepository.saveAll(testItems);
List<TestItemActivityResource> after = testItems.stream().map(it -> TO_ACTIVITY_RESOURCE.apply(it, projectDetails.getProjectId())).collect(Collectors.toList());
before.forEach(it -> messageBus.publishActivity(new LinkTicketEvent(it, after.stream().filter(t -> t.getId().equals(it.getId())).findFirst().get(), user.getUserId(), user.getUsername(), ActivityAction.LINK_ISSUE)));
return testItems.stream().map(TestItem::getItemId).map(COMPOSE_UPDATE_RESPONSE).collect(toList());
}
use of com.epam.ta.reportportal.ws.model.item.LinkExternalIssueRQ in project service-api by reportportal.
the class TestItemControllerTest method linkExternalIssueNegative.
@Test
void linkExternalIssueNegative() throws Exception {
LinkExternalIssueRQ rq = new LinkExternalIssueRQ();
rq.setTestItemIds(Collections.singletonList(2L));
Issue.ExternalSystemIssue issue = new Issue.ExternalSystemIssue();
issue.setBtsUrl("jira.com");
issue.setBtsProject("project");
issue.setTicketId("ticket1");
issue.setUrl("https://example.com/NEWTICKET1");
rq.setIssues(Collections.singletonList(issue));
mockMvc.perform(put(DEFAULT_PROJECT_BASE_URL + "/item/issue/link").with(token(oAuthHelper.getDefaultToken())).content(objectMapper.writeValueAsBytes(rq)).contentType(APPLICATION_JSON)).andExpect(status().isBadRequest());
}
use of com.epam.ta.reportportal.ws.model.item.LinkExternalIssueRQ in project service-api by reportportal.
the class TestItemControllerValidationTest method shouldReturnBadRequestWhenMoreThan300ItemIdsToLink.
@Test
public void shouldReturnBadRequestWhenMoreThan300ItemIdsToLink() throws Exception {
// GIVEN
final LinkExternalIssueRQ linkExternalIssueRQ = new LinkExternalIssueRQ();
final Issue.ExternalSystemIssue externalSystemIssue = getExternalSystemIssue();
linkExternalIssueRQ.setIssues(List.of(externalSystemIssue));
final List<Long> itemIds = Stream.generate(() -> 1L).limit(301).collect(Collectors.toList());
linkExternalIssueRQ.setTestItemIds(itemIds);
// WHEN
MvcResult mvcResult = mockMvc.perform(put(DEFAULT_PROJECT_BASE_URL + ITEM_PATH + "/issue/link").with(token(oAuthHelper.getDefaultToken())).content(objectMapper.writeValueAsBytes(linkExternalIssueRQ)).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 'testItemIds' should have size from '0' to '300'.] ", error.getMessage());
}
Aggregations