Search in sources :

Example 1 with IssueMissingTransitionException

use of com.synopsys.integration.alert.common.channel.issuetracker.exception.IssueMissingTransitionException in project hub-alert by blackducksoftware.

the class IssueTrackerTransitionTestAction method transitionTestIssueOrReturnFailureResult.

public Optional<MessageResult> transitionTestIssueOrReturnFailureResult(IssueOperation operation, ExistingIssueDetails<T> existingIssueDetails, ProjectIssueModel testProjectIssueModel) {
    String postTransitionComment = String.format("Successfully tested the %s operation", operation.name());
    IssueTransitionModel<T> resolveRequest = new IssueTransitionModel<>(existingIssueDetails, operation, List.of(postTransitionComment), testProjectIssueModel);
    IssueTrackerModelHolder<T> resolveRequestModelHolder = new IssueTrackerModelHolder<>(List.of(), List.of(resolveRequest), List.of());
    List<IssueTrackerIssueResponseModel<T>> transitionedIssues;
    try {
        transitionedIssues = messageSender.sendMessages(resolveRequestModelHolder);
    } catch (IssueMissingTransitionException e) {
        MessageResult issueMissingResult = handleIssueMessingTransitionException(e);
        return Optional.of(issueMissingResult);
    } catch (AlertException e) {
        MessageResult alertExceptionResult = handleAlertException(e, operation);
        return Optional.of(alertExceptionResult);
    }
    int transitionedIssuesSize = transitionedIssues.size();
    if (transitionedIssuesSize != 1) {
        String errorMessage = String.format("Expected [1] issue to be transitioned, but there were actually [%d]", transitionedIssuesSize);
        return Optional.of(new MessageResult(errorMessage, fieldStatusCreator.createWithoutField(errorMessage)));
    }
    return Optional.empty();
}
Also used : IssueTransitionModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTransitionModel) IssueTrackerIssueResponseModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel) IssueTrackerModelHolder(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder) IssueMissingTransitionException(com.synopsys.integration.alert.common.channel.issuetracker.exception.IssueMissingTransitionException) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 2 with IssueMissingTransitionException

use of com.synopsys.integration.alert.common.channel.issuetracker.exception.IssueMissingTransitionException in project hub-alert by blackducksoftware.

the class AzureBoardsIssueTransitioner method findAndPerformTransition.

@Override
protected void findAndPerformTransition(ExistingIssueDetails<Integer> existingIssueDetails, String transitionName) throws AlertException {
    WorkItemElementOperationModel replaceSystemStateField = WorkItemElementOperationModel.fieldElement(WorkItemElementOperation.REPLACE, WorkItemResponseFields.System_State, transitionName);
    WorkItemRequest request = new WorkItemRequest(List.of(replaceSystemStateField));
    Integer issueId = existingIssueDetails.getIssueId();
    try {
        workItemService.updateWorkItem(organizationName, distributionDetails.getProjectNameOrId(), issueId, request);
    } catch (HttpServiceException e) {
        List<String> availableStates = retrieveAvailableStates(existingIssueDetails.getIssueId()).stream().map(WorkItemTypeStateResponseModel::getName).collect(Collectors.toList());
        throw new IssueMissingTransitionException(existingIssueDetails.getIssueKey(), transitionName, availableStates);
    }
}
Also used : HttpServiceException(com.synopsys.integration.azure.boards.common.http.HttpServiceException) WorkItemRequest(com.synopsys.integration.azure.boards.common.service.workitem.request.WorkItemRequest) IssueMissingTransitionException(com.synopsys.integration.alert.common.channel.issuetracker.exception.IssueMissingTransitionException) List(java.util.List) WorkItemElementOperationModel(com.synopsys.integration.azure.boards.common.service.workitem.request.WorkItemElementOperationModel) WorkItemTypeStateResponseModel(com.synopsys.integration.azure.boards.common.service.state.WorkItemTypeStateResponseModel)

Example 3 with IssueMissingTransitionException

use of com.synopsys.integration.alert.common.channel.issuetracker.exception.IssueMissingTransitionException in project hub-alert by blackducksoftware.

the class IssueTrackerIssueTransitionerTest method transitionIssueThrowsExceptionTest.

@Test
public void transitionIssueThrowsExceptionTest() throws AlertException {
    IssueOperation testOperation = IssueOperation.RESOLVE;
    IssueTransitionModel<String> issueTransitionModel = new IssueTransitionModel<>(null, testOperation, List.of("comment 1"), null);
    IssueTrackerCallbackInfoCreator callbackInfoCreator = new IssueTrackerCallbackInfoCreator();
    IssueTrackerIssueResponseCreator issueResponseCreator = new IssueTrackerIssueResponseCreator(callbackInfoCreator);
    IssueTrackerIssueCommenter<String> exceptionThrowingCommenter = Mockito.mock(IssueTrackerIssueCommenter.class);
    Mockito.when(exceptionThrowingCommenter.commentOnIssue(Mockito.any())).thenThrow(new AlertException("Test exception"));
    IssueTrackerIssueTransitioner<String> transitioner = new TestTransitioner(exceptionThrowingCommenter, issueResponseCreator, "TODO", true, true);
    try {
        transitioner.transitionIssue(issueTransitionModel);
        fail("Expected an exception to be thrown");
    } catch (IssueMissingTransitionException e) {
        assertEquals(TEST_EXCEPTION, e);
    }
}
Also used : IssueTrackerCallbackInfoCreator(com.synopsys.integration.alert.api.channel.issue.callback.IssueTrackerCallbackInfoCreator) IssueTransitionModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTransitionModel) IssueMissingTransitionException(com.synopsys.integration.alert.common.channel.issuetracker.exception.IssueMissingTransitionException) IssueOperation(com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) Test(org.junit.jupiter.api.Test)

Example 4 with IssueMissingTransitionException

use of com.synopsys.integration.alert.common.channel.issuetracker.exception.IssueMissingTransitionException in project hub-alert by blackducksoftware.

the class IssueTrackerTransitionFieldModelTestActionTest method messageSenderThrowsIssueMissingTransitionException.

@Test
public void messageSenderThrowsIssueMissingTransitionException() throws AlertException {
    IssueTrackerMessageSender<String> messageSender = Mockito.mock(IssueTrackerMessageSender.class);
    Mockito.when(messageSender.sendMessages(Mockito.any())).thenThrow(new IssueMissingTransitionException(EXISTING_ISSUE_DETAILS.getIssueKey(), "Missing Transition Name", List.of("Valid Transition Name")));
    testAndAssertHasErrors(messageSender);
}
Also used : IssueMissingTransitionException(com.synopsys.integration.alert.common.channel.issuetracker.exception.IssueMissingTransitionException) Test(org.junit.jupiter.api.Test)

Aggregations

IssueMissingTransitionException (com.synopsys.integration.alert.common.channel.issuetracker.exception.IssueMissingTransitionException)4 IssueTransitionModel (com.synopsys.integration.alert.api.channel.issue.model.IssueTransitionModel)2 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)2 Test (org.junit.jupiter.api.Test)2 IssueTrackerCallbackInfoCreator (com.synopsys.integration.alert.api.channel.issue.callback.IssueTrackerCallbackInfoCreator)1 IssueTrackerIssueResponseModel (com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel)1 IssueTrackerModelHolder (com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder)1 IssueOperation (com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation)1 MessageResult (com.synopsys.integration.alert.common.message.model.MessageResult)1 HttpServiceException (com.synopsys.integration.azure.boards.common.http.HttpServiceException)1 WorkItemTypeStateResponseModel (com.synopsys.integration.azure.boards.common.service.state.WorkItemTypeStateResponseModel)1 WorkItemElementOperationModel (com.synopsys.integration.azure.boards.common.service.workitem.request.WorkItemElementOperationModel)1 WorkItemRequest (com.synopsys.integration.azure.boards.common.service.workitem.request.WorkItemRequest)1 List (java.util.List)1