Search in sources :

Example 6 with Issue

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

Example 7 with Issue

use of com.epam.ta.reportportal.ws.model.issue.Issue 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 8 with Issue

use of com.epam.ta.reportportal.ws.model.issue.Issue in project service-api by reportportal.

the class ContentUtils method getIssue.

private static Issue getIssue(String locator, String comment) {
    Issue issue = new Issue();
    issue.setIssueType(locator);
    issue.setComment(comment);
    return issue;
}
Also used : Issue(com.epam.ta.reportportal.ws.model.issue.Issue)

Example 9 with Issue

use of com.epam.ta.reportportal.ws.model.issue.Issue 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;
}
Also used : Issue(com.epam.ta.reportportal.ws.model.issue.Issue) ItemIssueTypeDefinedEvent(com.epam.ta.reportportal.core.events.activity.ItemIssueTypeDefinedEvent) IssueType(com.epam.ta.reportportal.entity.item.issue.IssueType) IssueEntity(com.epam.ta.reportportal.entity.item.issue.IssueEntity) TestItemActivityResource(com.epam.ta.reportportal.ws.model.activity.TestItemActivityResource) Project(com.epam.ta.reportportal.entity.project.Project) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) BusinessRuleViolationException(com.epam.ta.reportportal.commons.validation.BusinessRuleViolationException) IssueEntityBuilder(com.epam.ta.reportportal.ws.converter.builders.IssueEntityBuilder) IssueDefinition(com.epam.ta.reportportal.ws.model.issue.IssueDefinition) TestItem(com.epam.ta.reportportal.entity.item.TestItem)

Example 10 with Issue

use of com.epam.ta.reportportal.ws.model.issue.Issue in project service-api by reportportal.

the class IssueConverterTest method getIssue.

private static Issue getIssue() {
    Issue issue = new Issue();
    issue.setComment("comment");
    issue.setIgnoreAnalyzer(false);
    issue.setAutoAnalyzed(false);
    return issue;
}
Also used : Issue(com.epam.ta.reportportal.ws.model.issue.Issue)

Aggregations

Issue (com.epam.ta.reportportal.ws.model.issue.Issue)23 Test (org.junit.jupiter.api.Test)19 BaseMvcTest (com.epam.ta.reportportal.ws.BaseMvcTest)15 FinishTestItemRQ (com.epam.ta.reportportal.ws.model.FinishTestItemRQ)10 IssueEntity (com.epam.ta.reportportal.entity.item.issue.IssueEntity)4 LinkExternalIssueRQ (com.epam.ta.reportportal.ws.model.item.LinkExternalIssueRQ)4 TestItem (com.epam.ta.reportportal.entity.item.TestItem)3 IssueDefinition (com.epam.ta.reportportal.ws.model.issue.IssueDefinition)3 IssueType (com.epam.ta.reportportal.entity.item.issue.IssueType)2 Launch (com.epam.ta.reportportal.entity.launch.Launch)2 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)2 ErrorRS (com.epam.ta.reportportal.ws.model.ErrorRS)2 DefineIssueRQ (com.epam.ta.reportportal.ws.model.issue.DefineIssueRQ)2 MvcResult (org.springframework.test.web.servlet.MvcResult)2 TO_LOCAL_DATE_TIME (com.epam.ta.reportportal.commons.EntityUtils.TO_LOCAL_DATE_TIME)1 Preconditions (com.epam.ta.reportportal.commons.Preconditions)1 Predicates.equalTo (com.epam.ta.reportportal.commons.Predicates.equalTo)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