use of com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel in project hub-alert by blackducksoftware.
the class EmailGlobalConfigurationValidatorTest method verifyIsPasswordSet.
@Test
void verifyIsPasswordSet() {
EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
EmailGlobalConfigModel model = new EmailGlobalConfigModel();
model.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
model.setSmtpHost("host");
model.setSmtpFrom("from");
model.setSmtpAuth(true);
model.setSmtpUsername("user");
model.setIsSmtpPasswordSet(true);
ValidationResponseModel validationResponseModel = validator.validate(model);
Collection<AlertFieldStatus> alertFieldStatuses = validationResponseModel.getErrors().values();
assertEquals(0, alertFieldStatuses.size(), "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 verifyValidConfig.
/*
* Email host: Required
* Email from: Required
*
* Email user: Required if email auth is true
* Email password: Required if email auth is true
*/
@Test
void verifyValidConfig() {
EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
EmailGlobalConfigModel model = new EmailGlobalConfigModel();
model.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
model.setSmtpHost("host");
model.setSmtpFrom("from");
model.setSmtpAuth(true);
model.setSmtpUsername("user");
model.setSmtpPassword("password");
ValidationResponseModel validationResponseModel = validator.validate(model);
Collection<AlertFieldStatus> alertFieldStatuses = validationResponseModel.getErrors().values();
assertEquals(0, alertFieldStatuses.size(), "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 verifyNameMissingConfig.
@Test
void verifyNameMissingConfig() {
EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
EmailGlobalConfigModel model = new EmailGlobalConfigModel();
model.setSmtpHost("host");
model.setSmtpFrom("from");
model.setSmtpAuth(true);
model.setSmtpUsername("user");
model.setSmtpPassword("password");
ValidationResponseModel validationResponseModel = validator.validate(model);
Collection<AlertFieldStatus> alertFieldStatuses = validationResponseModel.getErrors().values();
assertEquals(1, alertFieldStatuses.size(), "There were errors no errors when 1 for the name was expected.");
}
use of com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel in project hub-alert by blackducksoftware.
the class EmailGlobalConfigurationModelConverter method convert.
@Override
public Optional<EmailGlobalConfigModel> convert(ConfigurationModel globalConfigurationModel) {
Optional<EmailGlobalConfigModel> convertedModel = Optional.empty();
EmailGlobalConfigModel model = new EmailGlobalConfigModel();
try {
globalConfigurationModel.getField(EmailPropertyKeys.JAVAMAIL_FROM_KEY.getPropertyKey()).flatMap(ConfigurationFieldModel::getFieldValue).ifPresent(model::setSmtpFrom);
globalConfigurationModel.getField(EmailPropertyKeys.JAVAMAIL_HOST_KEY.getPropertyKey()).flatMap(ConfigurationFieldModel::getFieldValue).ifPresent(model::setSmtpHost);
globalConfigurationModel.getField(EmailPropertyKeys.JAVAMAIL_PORT_KEY.getPropertyKey()).flatMap(ConfigurationFieldModel::getFieldValue).map(Integer::valueOf).ifPresent(model::setSmtpPort);
globalConfigurationModel.getField(EmailPropertyKeys.JAVAMAIL_AUTH_KEY.getPropertyKey()).flatMap(ConfigurationFieldModel::getFieldValue).map(Boolean::valueOf).ifPresent(model::setSmtpAuth);
globalConfigurationModel.getField(EmailPropertyKeys.JAVAMAIL_USER_KEY.getPropertyKey()).flatMap(ConfigurationFieldModel::getFieldValue).ifPresent(model::setSmtpUsername);
globalConfigurationModel.getField(EmailPropertyKeys.JAVAMAIL_PASSWORD_KEY.getPropertyKey()).flatMap(ConfigurationFieldModel::getFieldValue).ifPresent(model::setSmtpPassword);
model.setAdditionalJavaMailProperties(createAdditionalProperties(globalConfigurationModel));
convertedModel = Optional.of(model);
} catch (NumberFormatException ex) {
logger.error("Error converting field model to concrete email configuration", ex);
}
return convertedModel;
}
use of com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel in project hub-alert by blackducksoftware.
the class EmailEnvironmentHandlerFactoryTestIT method testExistingEmailConfig.
@Test
void testExistingEmailConfig() throws AlertConfigurationException {
EmailGlobalConfigModel emailGlobalConfigModel = new EmailGlobalConfigModel();
emailGlobalConfigModel.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
emailGlobalConfigModel.setSmtpAuth(Boolean.valueOf(TEST_AUTH_REQUIRED));
emailGlobalConfigModel.setSmtpFrom(TEST_FROM);
emailGlobalConfigModel.setSmtpHost(TEST_SMTP_HOST);
emailGlobalConfigModel.setSmtpPassword(TEST_PASSWORD);
emailGlobalConfigModel.setSmtpPort(Integer.valueOf(TEST_PORT));
emailGlobalConfigModel.setSmtpUsername(TEST_USER);
emailGlobalConfigAccessor.createConfiguration(emailGlobalConfigModel);
Environment environment = setupMockedEnvironment();
EnvironmentVariableUtility environmentVariableUtility = new EnvironmentVariableUtility(environment);
EnvironmentVariableHandlerFactory factory = new EmailEnvironmentVariableHandlerFactory(emailGlobalConfigAccessor, environmentVariableUtility, validator);
EnvironmentVariableHandler handler = factory.build();
EnvironmentProcessingResult result = handler.updateFromEnvironment();
assertEquals(ChannelKeys.EMAIL.getDisplayName(), handler.getName());
assertFalse(result.hasValues());
}
Aggregations