use of com.epam.ta.reportportal.ws.model.item.UnlinkExternalIssueRQ in project service-api by reportportal.
the class TestItemControllerTest method unlinkExternalIssues.
@Test
void unlinkExternalIssues() throws Exception {
UnlinkExternalIssueRQ rq = new UnlinkExternalIssueRQ();
rq.setTestItemIds(Collections.singletonList(3L));
rq.setTicketIds(Collections.singletonList("ticket"));
mockMvc.perform(put(DEFAULT_PROJECT_BASE_URL + "/item/issue/unlink").with(token(oAuthHelper.getDefaultToken())).contentType(APPLICATION_JSON).content(objectMapper.writeValueAsBytes(rq))).andExpect(status().isOk());
}
use of com.epam.ta.reportportal.ws.model.item.UnlinkExternalIssueRQ in project service-api by reportportal.
the class TestItemControllerValidationTest method shouldReturnBadRequestWhenMoreThan300ItemIdsToUnlink.
@Test
public void shouldReturnBadRequestWhenMoreThan300ItemIdsToUnlink() throws Exception {
// GIVEN
final UnlinkExternalIssueRQ unlinkExternalIssueRQ = new UnlinkExternalIssueRQ();
unlinkExternalIssueRQ.setTicketIds(List.of("id"));
unlinkExternalIssueRQ.setTestItemIds(Stream.generate(() -> 1L).limit(301).collect(Collectors.toList()));
// WHEN
MvcResult mvcResult = mockMvc.perform(put(DEFAULT_PROJECT_BASE_URL + ITEM_PATH + "/issue/unlink").with(token(oAuthHelper.getDefaultToken())).content(objectMapper.writeValueAsBytes(unlinkExternalIssueRQ)).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());
}
use of com.epam.ta.reportportal.ws.model.item.UnlinkExternalIssueRQ in project service-api by reportportal.
the class TestItemControllerValidationTest method shouldReturnBadRequestWhenMoreThan300TicketsToUnlink.
@Test
public void shouldReturnBadRequestWhenMoreThan300TicketsToUnlink() throws Exception {
// GIVEN
final UnlinkExternalIssueRQ unlinkExternalIssueRQ = new UnlinkExternalIssueRQ();
unlinkExternalIssueRQ.setTicketIds(Stream.generate(() -> "id").limit(301).collect(Collectors.toList()));
unlinkExternalIssueRQ.setTestItemIds(List.of(1L));
// WHEN
MvcResult mvcResult = mockMvc.perform(put(DEFAULT_PROJECT_BASE_URL + ITEM_PATH + "/issue/unlink").with(token(oAuthHelper.getDefaultToken())).content(objectMapper.writeValueAsBytes(unlinkExternalIssueRQ)).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 'ticketIds' should have size from '0' to '300'.] ", error.getMessage());
}
use of com.epam.ta.reportportal.ws.model.item.UnlinkExternalIssueRQ 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.UnlinkExternalIssueRQ in project service-api by reportportal.
the class TestItemControllerTest method unlinkExternalIssuesNegative.
@Test
void unlinkExternalIssuesNegative() throws Exception {
UnlinkExternalIssueRQ rq = new UnlinkExternalIssueRQ();
rq.setTestItemIds(Collections.singletonList(2L));
rq.setTicketIds(Collections.singletonList("ticket"));
mockMvc.perform(put(DEFAULT_PROJECT_BASE_URL + "/item/issue/unlink").with(token(oAuthHelper.getDefaultToken())).contentType(APPLICATION_JSON).content(objectMapper.writeValueAsBytes(rq))).andExpect(status().isBadRequest());
}
Aggregations