use of com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel 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.service.email.model.EmailGlobalConfigModel in project hub-alert by blackducksoftware.
the class EmailGlobalConfigurationModelSaveActions method createConcreteModel.
@Override
public void createConcreteModel(ConfigurationModel configurationModel) {
Optional<EmailGlobalConfigModel> emailGlobalConfigModel = emailFieldModelConverter.convert(configurationModel);
if (emailGlobalConfigModel.isPresent()) {
EmailGlobalConfigModel model = emailGlobalConfigModel.get();
model.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
configurationActions.create(model);
}
}
use of com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel in project hub-alert by blackducksoftware.
the class EmailGlobalConfigurationModelSaveActions method updateConcreteModel.
@Override
public void updateConcreteModel(ConfigurationModel configurationModel) {
Optional<UUID> defaultConfigurationId = configurationAccessor.getConfiguration().map(EmailGlobalConfigModel::getId).map(UUID::fromString);
Optional<EmailGlobalConfigModel> emailGlobalConfigModel = emailFieldModelConverter.convert(configurationModel);
if (defaultConfigurationId.isPresent() && emailGlobalConfigModel.isPresent()) {
EmailGlobalConfigModel model = emailGlobalConfigModel.get();
model.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
configurationActions.update(model);
}
}
use of com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel in project hub-alert by blackducksoftware.
the class EmailEnvironmentVariableHandlerFactory method updateConfiguration.
private EnvironmentProcessingResult updateConfiguration() {
EnvironmentProcessingResult.Builder builder = new EnvironmentProcessingResult.Builder(EMAIL_CONFIGURATION_KEYSET).addVariableNames(OLD_ADDITIONAL_PROPERTY_KEYSET);
EmailGlobalConfigModel configModel = new EmailGlobalConfigModel();
configModel.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
configureEmailSettings(configModel);
configureAdditionalProperties(builder, configModel);
ValidationResponseModel validationResponseModel = validator.validate(configModel);
if (validationResponseModel.hasErrors()) {
logger.error("Error inserting startup values: {}", validationResponseModel.getMessage());
Map<String, AlertFieldStatus> errors = validationResponseModel.getErrors();
for (Map.Entry<String, AlertFieldStatus> error : errors.entrySet()) {
AlertFieldStatus status = error.getValue();
logger.error("Field: '{}' failed with the error: {}", status.getFieldName(), status.getFieldMessage());
}
return EnvironmentProcessingResult.empty();
}
EmailGlobalConfigModel obfuscatedModel = configModel.obfuscate();
obfuscatedModel.getSmtpHost().ifPresent(value -> builder.addVariableValue(EMAIL_HOST_KEY, value));
obfuscatedModel.getSmtpPort().map(String::valueOf).ifPresent(value -> builder.addVariableValue(EMAIL_PORT_KEY, value));
obfuscatedModel.getSmtpFrom().ifPresent(value -> builder.addVariableValue(EMAIL_FROM_KEY, value));
obfuscatedModel.getSmtpAuth().map(String::valueOf).ifPresent(value -> builder.addVariableValue(AUTH_REQUIRED_KEY, value));
obfuscatedModel.getSmtpUsername().ifPresent(value -> builder.addVariableValue(AUTH_USER_KEY, value));
if (Boolean.TRUE.equals(obfuscatedModel.getIsSmtpPasswordSet())) {
builder.addVariableValue(AUTH_PASSWORD_KEY, AlertConstants.MASKED_VALUE);
}
EnvironmentProcessingResult result = builder.build();
if (result.hasValues()) {
try {
configAccessor.createConfiguration(configModel);
} catch (AlertConfigurationException ex) {
logger.error("Failed to create config: ", ex);
}
}
return result;
}
use of com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel in project hub-alert by blackducksoftware.
the class EmailGlobalConfigurationActionTest method testUpdateNotFound.
@Test
public void testUpdateNotFound() {
AuthenticationTestUtils authenticationTestUtils = new AuthenticationTestUtils();
DescriptorKey descriptorKey = ChannelKeys.EMAIL;
PermissionKey permissionKey = new PermissionKey(ConfigContextEnum.GLOBAL.name(), descriptorKey.getUniversalKey());
Map<PermissionKey, Integer> permissions = Map.of(permissionKey, AuthenticationTestUtils.FULL_PERMISSIONS);
AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
UUID configId = UUID.randomUUID();
EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
EmailGlobalConfigAccessor emailGlobalConfigAccessor = Mockito.mock(EmailGlobalConfigAccessor.class);
Mockito.when(emailGlobalConfigAccessor.getConfiguration()).thenReturn(Optional.empty());
EmailGlobalConfigModel model = new EmailGlobalConfigModel();
model.setSmtpHost("host");
model.setSmtpFrom("from");
model.setSmtpAuth(true);
model.setSmtpUsername("user");
model.setSmtpPassword("password");
EmailGlobalCrudActions configActions = new EmailGlobalCrudActions(authorizationManager, emailGlobalConfigAccessor, validator);
ActionResponse<EmailGlobalConfigModel> response = configActions.update(model);
assertEquals(HttpStatus.NOT_FOUND, response.getHttpStatus());
}
Aggregations