Search in sources :

Example 6 with EmailConfigurationRepository

use of com.synopsys.integration.alert.channel.email.database.configuration.EmailConfigurationRepository in project hub-alert by blackducksoftware.

the class EmailGlobalConfigurationModelSaveActionsTest method createTest.

@Test
void createTest() {
    AtomicReference<EmailConfigurationEntity> savedEntity = new AtomicReference<>();
    AtomicReference<EmailConfigurationsPropertyEntity> savedProperty = new AtomicReference<>();
    EmailConfigurationRepository emailConfigurationRepository = Mockito.mock(EmailConfigurationRepository.class);
    EmailConfigurationPropertiesRepository emailConfigurationPropertiesRepository = Mockito.mock(EmailConfigurationPropertiesRepository.class);
    Mockito.when(emailConfigurationRepository.save(Mockito.any(EmailConfigurationEntity.class))).thenAnswer(invocation -> {
        savedEntity.set(invocation.getArgument(0));
        return savedEntity.get();
    });
    Mockito.when(emailConfigurationPropertiesRepository.saveAll(Mockito.any(List.class))).thenAnswer(invocation -> {
        Iterable<EmailConfigurationsPropertyEntity> iterable = invocation.getArgument(0);
        for (EmailConfigurationsPropertyEntity entity : iterable) {
            savedProperty.set(entity);
        }
        return List.of(savedProperty.get());
    });
    EmailGlobalConfigAccessor configurationAccessor = new EmailGlobalConfigAccessor(encryptionUtility, emailConfigurationRepository, emailConfigurationPropertiesRepository);
    EmailGlobalCrudActions crudActions = new EmailGlobalCrudActions(authorizationManager, configurationAccessor, validator);
    EmailGlobalConfigurationModelSaveActions saveActions = new EmailGlobalConfigurationModelSaveActions(converter, crudActions, configurationAccessor);
    saveActions.createConcreteModel(createDefaultConfigurationModel());
    EmailConfigurationEntity actualEntity = savedEntity.get();
    assertEquals(Boolean.TRUE, actualEntity.getAuthRequired());
    assertEquals(TEST_AUTH_USER, actualEntity.getAuthUsername());
    assertEquals(TEST_AUTH_PASSWORD, encryptionUtility.decrypt(actualEntity.getAuthPassword()));
    assertEquals(TEST_SMTP_HOST, actualEntity.getSmtpHost());
    assertEquals(Integer.valueOf(TEST_SMTP_PORT), actualEntity.getSmtpPort());
    assertEquals(TEST_FROM, actualEntity.getSmtpFrom());
    EmailConfigurationsPropertyEntity emailProperty = savedProperty.get();
    assertNotNull(emailProperty);
    assertEquals(EmailPropertyKeys.JAVAMAIL_EHLO_KEY.getPropertyKey(), emailProperty.getPropertyKey());
    assertEquals("true", emailProperty.getPropertyValue());
}
Also used : EmailConfigurationRepository(com.synopsys.integration.alert.channel.email.database.configuration.EmailConfigurationRepository) EmailConfigurationEntity(com.synopsys.integration.alert.channel.email.database.configuration.EmailConfigurationEntity) EmailGlobalConfigAccessor(com.synopsys.integration.alert.channel.email.database.accessor.EmailGlobalConfigAccessor) EmailGlobalCrudActions(com.synopsys.integration.alert.channel.email.action.EmailGlobalCrudActions) EmailConfigurationsPropertyEntity(com.synopsys.integration.alert.channel.email.database.configuration.properties.EmailConfigurationsPropertyEntity) EmailConfigurationPropertiesRepository(com.synopsys.integration.alert.channel.email.database.configuration.properties.EmailConfigurationPropertiesRepository) AtomicReference(java.util.concurrent.atomic.AtomicReference) List(java.util.List) Test(org.junit.jupiter.api.Test)

Aggregations

EmailGlobalCrudActions (com.synopsys.integration.alert.channel.email.action.EmailGlobalCrudActions)6 EmailGlobalConfigAccessor (com.synopsys.integration.alert.channel.email.database.accessor.EmailGlobalConfigAccessor)6 EmailConfigurationEntity (com.synopsys.integration.alert.channel.email.database.configuration.EmailConfigurationEntity)6 EmailConfigurationRepository (com.synopsys.integration.alert.channel.email.database.configuration.EmailConfigurationRepository)6 EmailConfigurationPropertiesRepository (com.synopsys.integration.alert.channel.email.database.configuration.properties.EmailConfigurationPropertiesRepository)6 EmailConfigurationsPropertyEntity (com.synopsys.integration.alert.channel.email.database.configuration.properties.EmailConfigurationsPropertyEntity)6 List (java.util.List)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 Test (org.junit.jupiter.api.Test)6 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)5