use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class IssueTrackerFieldModelTestActionTest method testConfigSendMessagesThrowsException.
@Test
public void testConfigSendMessagesThrowsException() throws AlertException {
String testExceptionMessage = "test exception message";
IssueTrackerMessageSender<String> messageSender = Mockito.mock(IssueTrackerMessageSender.class);
Mockito.when(messageSender.sendMessages(Mockito.any())).thenThrow(new AlertException(testExceptionMessage));
IssueTrackerMessageSenderFactory<TestJobDetails, String> messageSenderFactory = distributionDetails -> messageSender;
TestIssueTrackerTestAction issueTrackerTestAction = new TestIssueTrackerTestAction(messageSenderFactory);
MessageResult messageResult = issueTrackerTestAction.testConfig(TEST_JOB_MODEL, "jobName", null, null);
assertTrue(messageResult.getStatusMessage().contains(testExceptionMessage), "Expected the message result to contain the expected exception message");
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class JiraErrorMessageUtilityTest method verifyReporterRestExceptionTest.
@Test
void verifyReporterRestExceptionTest() throws IntegrationException, IOException {
JiraCustomFieldResolver jiraCustomFieldResolver = new JiraCustomFieldResolver(() -> List.of());
JiraErrorMessageUtility jiraErrorMessageUtility = new JiraErrorMessageUtility(new Gson(), jiraCustomFieldResolver);
IntegrationRestException integrationRestException = createRestException(JsonTestResource.REPORTER_ERROR);
String issueCreatorKey = "issueCreatorFieldKey";
String issueCreatorEmail = "issueCreatorEmail";
AlertException alertException = jiraErrorMessageUtility.improveRestException(integrationRestException, issueCreatorKey, issueCreatorEmail);
assertTrue(alertException instanceof AlertFieldException);
AlertFieldException alertFieldException = (AlertFieldException) alertException;
List<AlertFieldStatus> fieldErrors = alertFieldException.getFieldErrors();
assertEquals(1, fieldErrors.size());
AlertFieldStatus alertFieldStatus = fieldErrors.get(0);
assertEquals(issueCreatorKey, alertFieldStatus.getFieldName());
assertEquals(FieldStatusSeverity.ERROR, alertFieldStatus.getSeverity());
String fieldMessage = alertFieldStatus.getFieldMessage();
assertTrue(fieldMessage.contains(issueCreatorEmail));
assertTrue(fieldMessage.contains("It'sa me, Mario"));
assertFalse(fieldMessage.contains(" | Details: "));
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class JiraErrorMessageUtilityTest method verifyFieldErrorsRestExceptionTest.
@Test
void verifyFieldErrorsRestExceptionTest() throws IntegrationException, IOException {
String customFieldKey = "customfield_1";
String customFieldName = "Custom Field 1 Name";
String nonExistentCustomName = "Field 33 Name";
Map<String, String> fieldIdsToNames = Map.of("customfield_6", "lol", "customfield_33", nonExistentCustomName, customFieldKey, customFieldName);
JiraCustomFieldResolver jiraCustomFieldResolver = new JiraCustomFieldResolver(() -> createCustomFieldResponseModels(fieldIdsToNames));
JiraErrorMessageUtility jiraErrorMessageUtility = new JiraErrorMessageUtility(new Gson(), jiraCustomFieldResolver);
IntegrationRestException integrationRestException = createRestException(JsonTestResource.ERROR_MESSAGES_ERROR);
String issueCreatorKey = "issueCreatorFieldKey";
String issueCreatorEmail = "issueCreatorEmail";
AlertException alertException = jiraErrorMessageUtility.improveRestException(integrationRestException, issueCreatorKey, issueCreatorEmail);
String message = alertException.getMessage();
assertTrue(message.contains(customFieldName));
assertTrue(message.contains("This field should have had another value"));
assertTrue(message.contains(customFieldKey));
assertFalse(message.contains(nonExistentCustomName));
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class IssueTrackerSearcher method findIssueByProjectIssueModel.
private ActionableIssueSearchResult<T> findIssueByProjectIssueModel(ProjectIssueModel projectIssueModel) throws AlertException {
ExistingIssueDetails<T> existingIssue = null;
ItemOperation searchResultOperation = ItemOperation.UPDATE;
List<ExistingIssueDetails<T>> existingIssues = exactIssueFinder.findExistingIssuesByProjectIssueModel(projectIssueModel);
int foundIssuesCount = existingIssues.size();
if (foundIssuesCount == 1) {
existingIssue = existingIssues.get(0);
Optional<ItemOperation> policyOperation = projectIssueModel.getPolicyDetails().map(IssuePolicyDetails::getOperation);
Optional<IssueVulnerabilityDetails> optionalVulnerabilityDetails = projectIssueModel.getVulnerabilityDetails();
Optional<ItemOperation> componentUnknownOperation = projectIssueModel.getComponentUnknownVersionDetails().map(IssueComponentUnknownVersionDetails::getItemOperation);
if (policyOperation.isPresent()) {
searchResultOperation = policyOperation.get();
} else if (optionalVulnerabilityDetails.isPresent()) {
IssueVulnerabilityDetails issueVulnerabilityDetails = optionalVulnerabilityDetails.get();
searchResultOperation = findVulnerabilitySearchResultOperation(existingIssue, issueVulnerabilityDetails);
} else if (componentUnknownOperation.isPresent()) {
searchResultOperation = componentUnknownOperation.get();
}
} else if (foundIssuesCount > 1) {
Set<String> issueKeys = existingIssues.stream().map(ExistingIssueDetails::getIssueKey).collect(Collectors.toSet());
String issueKeyString = StringUtils.join(issueKeys, ", ");
throw new AlertException("Expected to find a unique issue, but more than one was found. " + issueKeyString);
} else {
searchResultOperation = ItemOperation.ADD;
}
return new ActionableIssueSearchResult<>(existingIssue, projectIssueModel, searchResultOperation);
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class IssueTrackerChannelTest method distributeMessagesTest.
@Test
public void distributeMessagesTest() throws AlertException {
IssueTrackerModelExtractor<String> modelExtractor = new IssueTrackerModelExtractor<>(createFormatter(), null);
IssueTrackerMessageSender<String> messageSender = createMessageSender();
IssueTrackerProcessor<String> processor = new IssueTrackerProcessor<>(modelExtractor, messageSender);
IssueTrackerProcessorFactory<DistributionJobDetailsModel, String> processorFactory = x -> processor;
IssueTrackerResponsePostProcessor postProcessor = new IssueTrackerResponsePostProcessor() {
@Override
public <T extends Serializable> void postProcess(IssueTrackerResponse<T> response) {
}
};
IssueTrackerChannel<DistributionJobDetailsModel, String> issueTrackerChannel = new IssueTrackerChannel<>(processorFactory, postProcessor) {
};
MessageResult testResult = issueTrackerChannel.distributeMessages(null, ProviderMessageHolder.empty(), null);
IssueTrackerResponse<?> processorResponse = processor.processMessages(ProviderMessageHolder.empty(), "jobName");
assertEquals(processorResponse.getStatusMessage(), testResult.getStatusMessage());
}
Aggregations