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();
}
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);
}
}
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);
}
}
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);
}
Aggregations