use of com.synopsys.integration.alert.common.message.model.MessageResult in project hub-alert by blackducksoftware.
the class EmailGlobalTestActionTest method testSmtpPasswordMissingTest.
@Test
public void testSmtpPasswordMissingTest() throws AlertException {
AuthorizationManager authorizationManager = createAuthorizationManager(255);
EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
EmailChannelMessagingService emailChannelMessagingService = Mockito.mock(EmailChannelMessagingService.class);
Mockito.when(emailChannelMessagingService.sendMessage(Mockito.any(), Mockito.any())).thenReturn(new MessageResult("PASS"));
JavamailPropertiesFactory javamailPropertiesFactory = new JavamailPropertiesFactory();
EmailGlobalTestAction emailGlobalTestAction = new EmailGlobalTestAction(authorizationManager, validator, emailChannelMessagingService, javamailPropertiesFactory, configurationAccessor);
EmailGlobalConfigModel emailGlobalConfigModel = new EmailGlobalConfigModel();
emailGlobalConfigModel.setIsSmtpPasswordSet(true);
EmailGlobalConfigModel configModelWithPassword = new EmailGlobalConfigModel();
configModelWithPassword.setIsSmtpPasswordSet(true);
configModelWithPassword.setSmtpPassword("password");
Mockito.when(configurationAccessor.getConfiguration()).thenReturn(Optional.of(configModelWithPassword));
ConfigurationTestResult testResult = emailGlobalTestAction.testConfigModelContent("noreply@synopsys.com", emailGlobalConfigModel);
assertTrue(testResult.isSuccess(), "Expected the message result to not have errors");
}
use of com.synopsys.integration.alert.common.message.model.MessageResult in project hub-alert by blackducksoftware.
the class EmailGlobalTestActionTest method testConfigValidTest.
@Test
public void testConfigValidTest() throws AlertException {
AuthorizationManager authorizationManager = createAuthorizationManager(255);
EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
EmailChannelMessagingService emailChannelMessagingService = Mockito.mock(EmailChannelMessagingService.class);
Mockito.when(emailChannelMessagingService.sendMessage(Mockito.any(), Mockito.any())).thenReturn(new MessageResult("PASS"));
JavamailPropertiesFactory javamailPropertiesFactory = new JavamailPropertiesFactory();
EmailGlobalTestAction emailGlobalTestAction = new EmailGlobalTestAction(authorizationManager, validator, emailChannelMessagingService, javamailPropertiesFactory, configurationAccessor);
ConfigurationTestResult testResult = emailGlobalTestAction.testConfigModelContent("noreply@synopsys.com", new EmailGlobalConfigModel());
assertTrue(testResult.isSuccess(), "Expected the message result to not have errors");
}
use of com.synopsys.integration.alert.common.message.model.MessageResult in project hub-alert by blackducksoftware.
the class JobConfigActions method testWithoutChecks.
@Override
protected ValidationActionResponse testWithoutChecks(JobFieldModel resource) {
ValidationResponseModel responseModel;
String jobIdString = resource.getJobId();
UUID jobId = Optional.ofNullable(jobIdString).filter(StringUtils::isNotBlank).map(UUID::fromString).orElse(null);
try {
Collection<FieldModel> otherJobModels = new LinkedList<>();
FieldModel channelFieldModel = getChannelFieldModelAndPopulateOtherJobModels(resource, otherJobModels);
if (null != channelFieldModel) {
String channelDescriptorName = channelFieldModel.getDescriptorName();
Map<String, ConfigurationFieldModel> fields = createFieldsMap(channelFieldModel, otherJobModels);
// The custom message fields are not written to the database or defined fields in the database. Need to manually add them.
// TODO Create a mechanism to create the field accessor with a combination of fields in the database and fields that are not.
Optional<ConfigurationFieldModel> topicField = convertFieldToConfigurationField(channelFieldModel, FieldModelTestAction.KEY_CUSTOM_TOPIC);
Optional<ConfigurationFieldModel> messageField = convertFieldToConfigurationField(channelFieldModel, FieldModelTestAction.KEY_CUSTOM_MESSAGE);
topicField.ifPresent(model -> fields.put(FieldModelTestAction.KEY_CUSTOM_TOPIC, model));
messageField.ifPresent(model -> fields.put(FieldModelTestAction.KEY_CUSTOM_MESSAGE, model));
MessageResult providerTestResult = testProviderConfig(new FieldUtility(fields), jobIdString, channelFieldModel);
if (providerTestResult.hasErrors()) {
responseModel = ValidationResponseModel.fromStatusCollection(providerTestResult.getStatusMessage(), providerTestResult.getFieldStatuses());
return new ValidationActionResponse(HttpStatus.OK, responseModel);
}
List<BlackDuckProjectDetailsModel> projectFilterDetails = Optional.ofNullable(resource.getConfiguredProviderProjects()).orElse(List.of()).stream().map(jobProject -> new BlackDuckProjectDetailsModel(jobProject.getName(), jobProject.getHref())).collect(Collectors.toList());
DistributionJobModel testJobModel = distributionJobModelExtractor.convertToJobModel(jobId, fields, DateUtils.createCurrentDateTimestamp(), null, projectFilterDetails);
DistributionChannelTestAction distributionChannelTestAction = channelTestActionMap.findRequiredAction(channelDescriptorName);
MessageResult testActionResult = distributionChannelTestAction.testConfig(testJobModel, testJobModel.getName(), topicField.flatMap(ConfigurationFieldModel::getFieldValue).orElse(null), messageField.flatMap(ConfigurationFieldModel::getFieldValue).orElse(null));
List<AlertFieldStatus> resultFieldStatuses = testActionResult.getFieldStatuses();
List<AlertFieldStatus> allStatuses = Stream.concat(resultFieldStatuses.stream(), providerTestResult.fieldWarnings().stream()).collect(Collectors.toList());
responseModel = ValidationResponseModel.fromStatusCollection(testActionResult.getStatusMessage(), allStatuses);
return new ValidationActionResponse(HttpStatus.OK, responseModel);
}
responseModel = ValidationResponseModel.generalError("No field model of type channel was was sent to test.");
return new ValidationActionResponse(HttpStatus.BAD_REQUEST, responseModel);
} catch (IntegrationRestException e) {
logger.error(e.getMessage(), e);
return ValidationActionResponse.createResponseFromIntegrationRestException(e);
} catch (AlertFieldException e) {
logger.error("Test Error with field Errors", e);
responseModel = ValidationResponseModel.fromStatusCollection(e.getMessage(), e.getFieldErrors());
return new ValidationActionResponse(HttpStatus.OK, responseModel);
} catch (IntegrationException e) {
// TODO this is not necessarily a PKIX
responseModel = pkixErrorResponseFactory.createSSLExceptionResponse(e).orElse(ValidationResponseModel.generalError(e.getMessage()));
return new ValidationActionResponse(HttpStatus.OK, responseModel);
} catch (Exception e) {
logger.error(e.getMessage(), e);
responseModel = pkixErrorResponseFactory.createSSLExceptionResponse(e).orElse(ValidationResponseModel.generalError(e.getMessage()));
return new ValidationActionResponse(HttpStatus.OK, responseModel);
}
}
use of com.synopsys.integration.alert.common.message.model.MessageResult 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.message.model.MessageResult in project hub-alert by blackducksoftware.
the class IssueTrackerFieldModelTestActionTest method testConfigNoReopen.
@Test
public void testConfigNoReopen() throws AlertException {
IssueTrackerMessageSender<String> messageSender = Mockito.mock(IssueTrackerMessageSender.class);
Mockito.when(messageSender.sendMessages(Mockito.any())).thenReturn(List.of(TEST_ISSUE_RESPONSE_MODEL));
IssueTrackerMessageSenderFactory<TestJobDetails, String> messageSenderFactory = distributionDetails -> messageSender;
TestIssueTrackerTestAction issueTrackerTestAction = new TestIssueTrackerTestAction(messageSenderFactory, true, false);
MessageResult messageResult = issueTrackerTestAction.testConfig(TEST_JOB_MODEL, "jobName", null, null);
assertFalse(messageResult.hasErrors(), EXPECTED_NO_ERRORS);
assertFalse(messageResult.hasWarnings(), EXPECTED_NO_WARNINGS);
}
Aggregations