use of com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel in project hub-alert by blackducksoftware.
the class EmailGlobalConfigurationValidatorTest method verifyEmptyConfig.
@Test
void verifyEmptyConfig() {
EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
EmailGlobalConfigModel model = new EmailGlobalConfigModel();
ValidationResponseModel validationResponseModel = validator.validate(model);
Collection<AlertFieldStatus> alertFieldStatuses = validationResponseModel.getErrors().values();
assertEquals(3, alertFieldStatuses.size(), "Validation found more or fewer errors than expected.");
for (AlertFieldStatus status : alertFieldStatuses) {
assertEquals(ConfigurationFieldValidator.REQUIRED_FIELD_MISSING_MESSAGE, status.getFieldMessage(), "Validation had unexpected field message.");
}
}
use of com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel in project hub-alert by blackducksoftware.
the class EmailGlobalConfigurationValidatorTest method verifyAuthNotProvided.
@Test
void verifyAuthNotProvided() {
EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
EmailGlobalConfigModel model = new EmailGlobalConfigModel();
model.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
model.setSmtpHost("host");
model.setSmtpFrom("from");
model.setSmtpUsername("user");
model.setSmtpPassword("password");
ValidationResponseModel validationResponseModel = validator.validate(model);
assertFalse(validationResponseModel.hasErrors(), "There were errors in the configuration when none were expected.");
}
use of com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel in project hub-alert by blackducksoftware.
the class EmailGlobalConfigurationValidatorTest method verifyMissingAuth.
@Test
void verifyMissingAuth() {
EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
EmailGlobalConfigModel model = new EmailGlobalConfigModel();
model.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
model.setSmtpHost("host");
model.setSmtpFrom("from");
model.setSmtpAuth(true);
ValidationResponseModel validationResponseModel = validator.validate(model);
Collection<AlertFieldStatus> alertFieldStatuses = validationResponseModel.getErrors().values();
assertEquals(2, alertFieldStatuses.size(), "Validation found more or fewer errors than expected.");
for (AlertFieldStatus status : alertFieldStatuses) {
assertEquals(EmailGlobalConfigurationValidator.REQUIRED_BECAUSE_AUTH, status.getFieldMessage(), "Validation had unexpected field message.");
}
}
use of com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel in project hub-alert by blackducksoftware.
the class EmailConfigActionTestIT method updatePasswordEmailGlobalConfigTest.
@Test
void updatePasswordEmailGlobalConfigTest() throws AlertConfigurationException {
AuthorizationManager authorizationManager = createEmailAuthorizationManager();
EmailGlobalCrudActions emailGlobalCrudActions = createEmailCrudActions(authorizationManager);
GlobalConfigurationModelToConcreteConversionService globalConfigurationModelToConcreteConversionService = createConversionService(emailGlobalCrudActions);
ConfigActions configActions = new ConfigActions(authorizationManager, descriptorAccessor, configurationModelConfigurationAccessor, fieldModelProcessor, descriptorProcessor, configurationFieldModelConverter, descriptorMap, pkixErrorResponseFactory, encryptionUtility, settingsDescriptorKey, globalConfigurationModelToConcreteConversionService);
FieldModel fieldModel = createEmailFieldModel();
fieldModel = configActions.create(fieldModel).getContent().orElseThrow(() -> new AlertConfigurationException("Couldn't create configuration"));
String updatedHost = "updated." + TEST_SMTP_HOST;
String updatedPassword = "updatedPassword";
fieldModel.putField(EmailPropertyKeys.JAVAMAIL_HOST_KEY.getPropertyKey(), new FieldValueModel(List.of(updatedHost), false));
fieldModel.putField(EmailPropertyKeys.JAVAMAIL_PASSWORD_KEY.getPropertyKey(), new FieldValueModel(List.of(updatedPassword), false));
configActions.update(Long.valueOf(fieldModel.getId()), fieldModel);
Optional<EmailGlobalConfigModel> staticEmailConfig = emailGlobalConfigAccessor.getConfiguration();
assertTrue(staticEmailConfig.isPresent());
EmailGlobalConfigModel staticModel = staticEmailConfig.get();
assertEquals(Boolean.TRUE, staticModel.getSmtpAuth().orElse(null));
assertEquals(TEST_AUTH_USER, staticModel.getSmtpUsername().orElse(null));
assertEquals(updatedPassword, staticModel.getSmtpPassword().orElse(null));
assertEquals(updatedHost, staticModel.getSmtpHost().orElse(null));
assertEquals(Integer.valueOf(TEST_SMTP_PORT), staticModel.getSmtpPort().orElse(null));
assertEquals(TEST_FROM, staticModel.getSmtpFrom().orElse(null));
String propertyValue = staticModel.getAdditionalJavaMailProperties().map(map -> map.get(EmailPropertyKeys.JAVAMAIL_EHLO_KEY.getPropertyKey())).orElse(null);
assertEquals("true", propertyValue);
}
use of com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel in project hub-alert by blackducksoftware.
the class EmailGlobalConfigAccessor method createConfigModel.
private EmailGlobalConfigModel createConfigModel(EmailConfigurationEntity emailConfiguration) {
EmailGlobalConfigModel newModel = new EmailGlobalConfigModel();
String createdAtFormatted = "";
String lastUpdatedFormatted = "";
if (null != emailConfiguration) {
createdAtFormatted = DateUtils.formatDate(emailConfiguration.getCreatedAt(), DateUtils.UTC_DATE_FORMAT_TO_MINUTE);
if (null != emailConfiguration.getLastUpdated()) {
lastUpdatedFormatted = DateUtils.formatDate(emailConfiguration.getLastUpdated(), DateUtils.UTC_DATE_FORMAT_TO_MINUTE);
}
newModel.setId(String.valueOf(emailConfiguration.getConfigurationId()));
newModel.setName(emailConfiguration.getName());
newModel.setSmtpHost(emailConfiguration.getSmtpHost());
newModel.setSmtpPort(emailConfiguration.getSmtpPort());
newModel.setSmtpFrom(emailConfiguration.getSmtpFrom());
newModel.setSmtpAuth(emailConfiguration.getAuthRequired());
newModel.setSmtpUsername(emailConfiguration.getAuthUsername());
String authPassword = emailConfiguration.getAuthPassword();
boolean doesPasswordExist = StringUtils.isNotBlank(authPassword);
newModel.setIsSmtpPasswordSet(doesPasswordExist);
if (doesPasswordExist) {
newModel.setSmtpPassword(encryptionUtility.decrypt(authPassword));
}
newModel.setAdditionalJavaMailProperties(getAdditionalProperties(emailConfiguration.getEmailConfigurationProperties()));
}
newModel.setCreatedAt(createdAtFormatted);
newModel.setLastUpdated(lastUpdatedFormatted);
return newModel;
}
Aggregations