Search in sources :

Example 46 with EmailGlobalConfigModel

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.");
}
Also used : EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) Test(org.junit.jupiter.api.Test)

Example 47 with EmailGlobalConfigModel

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.");
}
Also used : EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) Test(org.junit.jupiter.api.Test)

Example 48 with EmailGlobalConfigModel

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.");
}
Also used : EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) Test(org.junit.jupiter.api.Test)

Example 49 with EmailGlobalConfigModel

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;
}
Also used : EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)

Example 50 with EmailGlobalConfigModel

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());
}
Also used : EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) EnvironmentVariableHandlerFactory(com.synopsys.integration.alert.environment.EnvironmentVariableHandlerFactory) EnvironmentVariableUtility(com.synopsys.integration.alert.environment.EnvironmentVariableUtility) Environment(org.springframework.core.env.Environment) EnvironmentVariableHandler(com.synopsys.integration.alert.environment.EnvironmentVariableHandler) EnvironmentProcessingResult(com.synopsys.integration.alert.environment.EnvironmentProcessingResult) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

EmailGlobalConfigModel (com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel)51 Test (org.junit.jupiter.api.Test)41 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)27 EmailGlobalConfigurationValidator (com.synopsys.integration.alert.channel.email.validator.EmailGlobalConfigurationValidator)26 PermissionKey (com.synopsys.integration.alert.common.persistence.model.PermissionKey)15 PermissionMatrixModel (com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel)15 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)15 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)15 AuthenticationTestUtils (com.synopsys.integration.alert.test.common.AuthenticationTestUtils)15 EmailGlobalConfigAccessor (com.synopsys.integration.alert.channel.email.database.accessor.EmailGlobalConfigAccessor)14 JavamailPropertiesFactory (com.synopsys.integration.alert.service.email.JavamailPropertiesFactory)10 EmailChannelMessagingService (com.synopsys.integration.alert.channel.email.distribution.EmailChannelMessagingService)9 AlertFieldStatus (com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)8 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)6 ConfigurationTestResult (com.synopsys.integration.alert.common.message.model.ConfigurationTestResult)6 MessageResult (com.synopsys.integration.alert.common.message.model.MessageResult)5 UUID (java.util.UUID)5 EmailGlobalCrudActions (com.synopsys.integration.alert.channel.email.action.EmailGlobalCrudActions)4 ValidatedEmailAddresses (com.synopsys.integration.alert.channel.email.distribution.address.ValidatedEmailAddresses)4 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)4