Search in sources :

Example 1 with LinkExternalIssueRQ

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());
}
Also used : LinkExternalIssueRQ(com.epam.ta.reportportal.ws.model.item.LinkExternalIssueRQ) Issue(com.epam.ta.reportportal.ws.model.issue.Issue) BaseMvcTest(com.epam.ta.reportportal.ws.BaseMvcTest) Test(org.junit.jupiter.api.Test)

Example 2 with LinkExternalIssueRQ

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());
}
Also used : LinkExternalIssueRQ(com.epam.ta.reportportal.ws.model.item.LinkExternalIssueRQ) Issue(com.epam.ta.reportportal.ws.model.issue.Issue) ErrorRS(com.epam.ta.reportportal.ws.model.ErrorRS) MvcResult(org.springframework.test.web.servlet.MvcResult) BaseMvcTest(com.epam.ta.reportportal.ws.BaseMvcTest) Test(org.junit.jupiter.api.Test)

Example 3 with LinkExternalIssueRQ

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());
}
Also used : StatusEnum(com.epam.ta.reportportal.entity.enums.StatusEnum) IssueEntity(com.epam.ta.reportportal.entity.item.issue.IssueEntity) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS) TestItemService(com.epam.ta.reportportal.core.item.TestItemService) LogIndexerService(com.epam.ta.reportportal.core.analyzer.auto.impl.LogIndexerService) Autowired(org.springframework.beans.factory.annotation.Autowired) DefineIssueRQ(com.epam.ta.reportportal.ws.model.issue.DefineIssueRQ) UnlinkExternalIssueRQ(com.epam.ta.reportportal.ws.model.item.UnlinkExternalIssueRQ) MessageBus(com.epam.ta.reportportal.core.events.MessageBus) StringUtils(org.apache.commons.lang3.StringUtils) ItemAttribute(com.epam.ta.reportportal.entity.ItemAttribute) Predicates(com.epam.ta.reportportal.commons.Predicates) TestItemRepository(com.epam.ta.reportportal.dao.TestItemRepository) Suppliers.formattedSupplier(com.epam.ta.reportportal.commons.validation.Suppliers.formattedSupplier) TestItemActivityResource(com.epam.ta.reportportal.ws.model.activity.TestItemActivityResource) Launch(com.epam.ta.reportportal.entity.launch.Launch) TestItemStatusChangedEvent(com.epam.ta.reportportal.core.events.activity.TestItemStatusChangedEvent) Predicate(java.util.function.Predicate) BusinessRule.expect(com.epam.ta.reportportal.commons.validation.BusinessRule.expect) IssueConverter(com.epam.ta.reportportal.ws.converter.converters.IssueConverter) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) TestItemBuilder(com.epam.ta.reportportal.ws.converter.builders.TestItemBuilder) Collectors(java.util.stream.Collectors) LinkExternalIssueRQ(com.epam.ta.reportportal.ws.model.item.LinkExternalIssueRQ) AnalyzerUtils(com.epam.ta.reportportal.core.analyzer.auto.impl.AnalyzerUtils) ProjectRole(com.epam.ta.reportportal.entity.project.ProjectRole) Stream(java.util.stream.Stream) ITEM_CAN_BE_INDEXED(com.epam.ta.reportportal.util.Predicates.ITEM_CAN_BE_INDEXED) IssueEntityRepository(com.epam.ta.reportportal.dao.IssueEntityRepository) BusinessRuleViolationException(com.epam.ta.reportportal.commons.validation.BusinessRuleViolationException) UpdateTestItemHandler(com.epam.ta.reportportal.core.item.UpdateTestItemHandler) ItemInfoUtils.extractAttributeResource(com.epam.ta.reportportal.util.ItemInfoUtils.extractAttributeResource) TRUE(java.lang.Boolean.TRUE) TestItemTypeEnum(com.epam.ta.reportportal.entity.enums.TestItemTypeEnum) java.util(java.util) Project(com.epam.ta.reportportal.entity.project.Project) Issue(com.epam.ta.reportportal.ws.model.issue.Issue) TestItem(com.epam.ta.reportportal.entity.item.TestItem) ItemInfoUtils.extractAttribute(com.epam.ta.reportportal.util.ItemInfoUtils.extractAttribute) BulkInfoUpdateRQ(com.epam.ta.reportportal.ws.model.BulkInfoUpdateRQ) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) StatusChangingStrategy(com.epam.ta.reportportal.core.item.impl.status.StatusChangingStrategy) Function(java.util.function.Function) ExternalTicketHandler(com.epam.ta.reportportal.core.item.ExternalTicketHandler) ItemIssueTypeDefinedEvent(com.epam.ta.reportportal.core.events.activity.ItemIssueTypeDefinedEvent) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) CollectionUtils(org.apache.commons.collections.CollectionUtils) UpdateTestItemRQ(com.epam.ta.reportportal.ws.model.item.UpdateTestItemRQ) Service(org.springframework.stereotype.Service) UserRole(com.epam.ta.reportportal.entity.user.UserRole) IssueDefinition(com.epam.ta.reportportal.ws.model.issue.IssueDefinition) IssueType(com.epam.ta.reportportal.entity.item.issue.IssueType) ActivityAction(com.epam.ta.reportportal.entity.activity.ActivityAction) FALSE(java.lang.Boolean.FALSE) ExternalIssueRQ(com.epam.ta.reportportal.ws.model.item.ExternalIssueRQ) TestItemIssueGroup(com.epam.ta.reportportal.entity.enums.TestItemIssueGroup) TO_ACTIVITY_RESOURCE(com.epam.ta.reportportal.ws.converter.converters.TestItemConverter.TO_ACTIVITY_RESOURCE) Consumer(java.util.function.Consumer) Collectors.toList(java.util.stream.Collectors.toList) IssueEntityBuilder(com.epam.ta.reportportal.ws.converter.builders.IssueEntityBuilder) ProjectRepository(com.epam.ta.reportportal.dao.ProjectRepository) LinkTicketEvent(com.epam.ta.reportportal.core.events.activity.LinkTicketEvent) ItemAttributeConverter(com.epam.ta.reportportal.ws.converter.converters.ItemAttributeConverter) ItemInfoUtils(com.epam.ta.reportportal.util.ItemInfoUtils) LinkExternalIssueRQ(com.epam.ta.reportportal.ws.model.item.LinkExternalIssueRQ) LinkTicketEvent(com.epam.ta.reportportal.core.events.activity.LinkTicketEvent) TestItemActivityResource(com.epam.ta.reportportal.ws.model.activity.TestItemActivityResource) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) BusinessRuleViolationException(com.epam.ta.reportportal.commons.validation.BusinessRuleViolationException) TestItem(com.epam.ta.reportportal.entity.item.TestItem)

Example 4 with LinkExternalIssueRQ

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());
}
Also used : LinkExternalIssueRQ(com.epam.ta.reportportal.ws.model.item.LinkExternalIssueRQ) Issue(com.epam.ta.reportportal.ws.model.issue.Issue) BaseMvcTest(com.epam.ta.reportportal.ws.BaseMvcTest) Test(org.junit.jupiter.api.Test)

Example 5 with LinkExternalIssueRQ

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());
}
Also used : LinkExternalIssueRQ(com.epam.ta.reportportal.ws.model.item.LinkExternalIssueRQ) Issue(com.epam.ta.reportportal.ws.model.issue.Issue) ErrorRS(com.epam.ta.reportportal.ws.model.ErrorRS) MvcResult(org.springframework.test.web.servlet.MvcResult) BaseMvcTest(com.epam.ta.reportportal.ws.BaseMvcTest) Test(org.junit.jupiter.api.Test)

Aggregations

Issue (com.epam.ta.reportportal.ws.model.issue.Issue)5 LinkExternalIssueRQ (com.epam.ta.reportportal.ws.model.item.LinkExternalIssueRQ)5 BaseMvcTest (com.epam.ta.reportportal.ws.BaseMvcTest)4 Test (org.junit.jupiter.api.Test)4 Predicates (com.epam.ta.reportportal.commons.Predicates)1 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)1 BusinessRule.expect (com.epam.ta.reportportal.commons.validation.BusinessRule.expect)1 BusinessRuleViolationException (com.epam.ta.reportportal.commons.validation.BusinessRuleViolationException)1 Suppliers.formattedSupplier (com.epam.ta.reportportal.commons.validation.Suppliers.formattedSupplier)1 AnalyzerUtils (com.epam.ta.reportportal.core.analyzer.auto.impl.AnalyzerUtils)1 LogIndexerService (com.epam.ta.reportportal.core.analyzer.auto.impl.LogIndexerService)1 MessageBus (com.epam.ta.reportportal.core.events.MessageBus)1 ItemIssueTypeDefinedEvent (com.epam.ta.reportportal.core.events.activity.ItemIssueTypeDefinedEvent)1 LinkTicketEvent (com.epam.ta.reportportal.core.events.activity.LinkTicketEvent)1 TestItemStatusChangedEvent (com.epam.ta.reportportal.core.events.activity.TestItemStatusChangedEvent)1 ExternalTicketHandler (com.epam.ta.reportportal.core.item.ExternalTicketHandler)1 TestItemService (com.epam.ta.reportportal.core.item.TestItemService)1 UpdateTestItemHandler (com.epam.ta.reportportal.core.item.UpdateTestItemHandler)1 StatusChangingStrategy (com.epam.ta.reportportal.core.item.impl.status.StatusChangingStrategy)1 IssueEntityRepository (com.epam.ta.reportportal.dao.IssueEntityRepository)1