Search in sources :

Example 1 with EmailConfigurationsPropertyEntity

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

the class EmailGlobalConfigAccessor method populateConfiguration.

private EmailGlobalConfigModel populateConfiguration(UUID configurationId, EmailGlobalConfigModel configuration, OffsetDateTime createdAt) {
    OffsetDateTime currentTime = DateUtils.createCurrentDateTimestamp();
    EmailConfigurationEntity configurationToSave = toEntity(configurationId, configuration, createdAt, currentTime);
    EmailConfigurationEntity savedEmailConfig = emailConfigurationRepository.save(configurationToSave);
    emailConfigurationPropertiesRepository.bulkDeleteByConfigurationId(savedEmailConfig.getConfigurationId());
    List<EmailConfigurationsPropertyEntity> emailProperties = toPropertyEntityList(configurationId, configuration);
    emailConfigurationPropertiesRepository.saveAll(emailProperties);
    savedEmailConfig = emailConfigurationRepository.getOne(savedEmailConfig.getConfigurationId());
    return createConfigModel(savedEmailConfig);
}
Also used : OffsetDateTime(java.time.OffsetDateTime) EmailConfigurationEntity(com.synopsys.integration.alert.channel.email.database.configuration.EmailConfigurationEntity) EmailConfigurationsPropertyEntity(com.synopsys.integration.alert.channel.email.database.configuration.properties.EmailConfigurationsPropertyEntity)

Example 2 with EmailConfigurationsPropertyEntity

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

the class EmailGlobalConfigAccessor method toPropertyEntityList.

private List<EmailConfigurationsPropertyEntity> toPropertyEntityList(UUID configurationId, EmailGlobalConfigModel configuration) {
    Map<String, String> emailProperties = configuration.getAdditionalJavaMailProperties().orElse(Map.of());
    List<EmailConfigurationsPropertyEntity> propertyList = new LinkedList<>();
    for (Map.Entry<String, String> entry : emailProperties.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();
        if (StringUtils.isNotBlank(key)) {
            propertyList.add(new EmailConfigurationsPropertyEntity(configurationId, key.trim(), value.trim()));
        }
    }
    return propertyList;
}
Also used : EmailConfigurationsPropertyEntity(com.synopsys.integration.alert.channel.email.database.configuration.properties.EmailConfigurationsPropertyEntity) Map(java.util.Map) LinkedList(java.util.LinkedList)

Example 3 with EmailConfigurationsPropertyEntity

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

the class EmailGlobalConfigurationModelSaveActionsTest method updateTest.

@Test
void updateTest() {
    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(emailConfigurationRepository.findByName(Mockito.anyString())).thenAnswer(invocation -> Optional.ofNullable(savedEntity.get()));
    Mockito.when(emailConfigurationRepository.findById(Mockito.any())).thenAnswer(invocation -> Optional.ofNullable(savedEntity.get()));
    Mockito.when(emailConfigurationRepository.existsByName(Mockito.any())).thenAnswer(invocation -> savedEntity.get() != null);
    // Mockito.when(emailConfigurationRepository.existsByName(Mockito.anyString())).thenReturn(true);
    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);
    String newPassword = "updatedPassword";
    String newHost = "updated." + TEST_SMTP_HOST;
    ConfigurationModel configurationModel = createDefaultConfigurationModel();
    saveActions.createConcreteModel(configurationModel);
    updateField(configurationModel, EmailPropertyKeys.JAVAMAIL_HOST_KEY.getPropertyKey(), newHost);
    updateField(configurationModel, EmailPropertyKeys.JAVAMAIL_PASSWORD_KEY.getPropertyKey(), newPassword);
    updateField(configurationModel, EmailPropertyKeys.JAVAMAIL_EHLO_KEY.getPropertyKey(), "false");
    saveActions.updateConcreteModel(configurationModel);
    EmailConfigurationEntity actualEntity = savedEntity.get();
    assertEquals(ChannelKeys.EMAIL, saveActions.getDescriptorKey());
    assertEquals(Boolean.TRUE, actualEntity.getAuthRequired());
    assertEquals(TEST_AUTH_USER, actualEntity.getAuthUsername());
    assertEquals(newPassword, encryptionUtility.decrypt(actualEntity.getAuthPassword()));
    assertEquals(newHost, 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("false", emailProperty.getPropertyValue());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) EmailConfigurationRepository(com.synopsys.integration.alert.channel.email.database.configuration.EmailConfigurationRepository) EmailConfigurationEntity(com.synopsys.integration.alert.channel.email.database.configuration.EmailConfigurationEntity) EmailConfigurationPropertiesRepository(com.synopsys.integration.alert.channel.email.database.configuration.properties.EmailConfigurationPropertiesRepository) AtomicReference(java.util.concurrent.atomic.AtomicReference) 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) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 4 with EmailConfigurationsPropertyEntity

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

the class EmailGlobalConfigurationModelSaveActionsTest method updateInvalidConversionTest.

@Test
void updateInvalidConversionTest() {
    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(emailConfigurationRepository.findByName(Mockito.anyString())).thenAnswer(invocation -> Optional.ofNullable(savedEntity.get()));
    Mockito.when(emailConfigurationRepository.findById(Mockito.any())).thenAnswer(invocation -> Optional.ofNullable(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);
    String newPassword = "updatedPassword";
    String newHost = "updated." + TEST_SMTP_HOST;
    ConfigurationModel configurationModel = createDefaultConfigurationModel();
    saveActions.createConcreteModel(configurationModel);
    updateField(configurationModel, EmailPropertyKeys.JAVAMAIL_PORT_KEY.getPropertyKey(), "badport");
    updateField(configurationModel, EmailPropertyKeys.JAVAMAIL_HOST_KEY.getPropertyKey(), newHost);
    updateField(configurationModel, EmailPropertyKeys.JAVAMAIL_PORT_KEY.getPropertyKey(), newPassword);
    updateField(configurationModel, EmailPropertyKeys.JAVAMAIL_EHLO_KEY.getPropertyKey(), "false");
    saveActions.updateConcreteModel(configurationModel);
    // make sure the values are not the updated values
    EmailConfigurationEntity actualEntity = savedEntity.get();
    assertEquals(TEST_AUTH_PASSWORD, encryptionUtility.decrypt(actualEntity.getAuthPassword()));
    assertEquals(TEST_SMTP_HOST, actualEntity.getSmtpHost());
    assertEquals(Integer.valueOf(TEST_SMTP_PORT), actualEntity.getSmtpPort());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) EmailConfigurationRepository(com.synopsys.integration.alert.channel.email.database.configuration.EmailConfigurationRepository) EmailConfigurationEntity(com.synopsys.integration.alert.channel.email.database.configuration.EmailConfigurationEntity) EmailConfigurationPropertiesRepository(com.synopsys.integration.alert.channel.email.database.configuration.properties.EmailConfigurationPropertiesRepository) AtomicReference(java.util.concurrent.atomic.AtomicReference) 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) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 5 with EmailConfigurationsPropertyEntity

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

the class EmailGlobalConfigurationModelSaveActionsTest method updateItemNotFoundTest.

@Test
void updateItemNotFoundTest() {
    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(emailConfigurationRepository.findByName(Mockito.anyString())).thenAnswer(invocation -> Optional.ofNullable(savedEntity.get()));
    Mockito.when(emailConfigurationRepository.findById(Mockito.any())).thenAnswer(invocation -> Optional.ofNullable(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);
    String newPassword = "updatedPassword";
    String newHost = "updated." + TEST_SMTP_HOST;
    ConfigurationModel configurationModel = createDefaultConfigurationModel();
    saveActions.createConcreteModel(configurationModel);
    updateField(configurationModel, EmailPropertyKeys.JAVAMAIL_PORT_KEY.getPropertyKey(), "badport");
    updateField(configurationModel, EmailPropertyKeys.JAVAMAIL_HOST_KEY.getPropertyKey(), newHost);
    updateField(configurationModel, EmailPropertyKeys.JAVAMAIL_PORT_KEY.getPropertyKey(), newPassword);
    updateField(configurationModel, EmailPropertyKeys.JAVAMAIL_EHLO_KEY.getPropertyKey(), "false");
    saveActions.updateConcreteModel(configurationModel);
    // make sure the values are not the updated values
    EmailConfigurationEntity actualEntity = savedEntity.get();
    assertEquals(TEST_AUTH_PASSWORD, encryptionUtility.decrypt(actualEntity.getAuthPassword()));
    assertEquals(TEST_SMTP_HOST, actualEntity.getSmtpHost());
    assertEquals(Integer.valueOf(TEST_SMTP_PORT), actualEntity.getSmtpPort());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) EmailConfigurationRepository(com.synopsys.integration.alert.channel.email.database.configuration.EmailConfigurationRepository) EmailConfigurationEntity(com.synopsys.integration.alert.channel.email.database.configuration.EmailConfigurationEntity) EmailConfigurationPropertiesRepository(com.synopsys.integration.alert.channel.email.database.configuration.properties.EmailConfigurationPropertiesRepository) AtomicReference(java.util.concurrent.atomic.AtomicReference) 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) List(java.util.List) Test(org.junit.jupiter.api.Test)

Aggregations

EmailConfigurationsPropertyEntity (com.synopsys.integration.alert.channel.email.database.configuration.properties.EmailConfigurationsPropertyEntity)8 EmailConfigurationEntity (com.synopsys.integration.alert.channel.email.database.configuration.EmailConfigurationEntity)7 EmailGlobalCrudActions (com.synopsys.integration.alert.channel.email.action.EmailGlobalCrudActions)6 EmailGlobalConfigAccessor (com.synopsys.integration.alert.channel.email.database.accessor.EmailGlobalConfigAccessor)6 EmailConfigurationRepository (com.synopsys.integration.alert.channel.email.database.configuration.EmailConfigurationRepository)6 EmailConfigurationPropertiesRepository (com.synopsys.integration.alert.channel.email.database.configuration.properties.EmailConfigurationPropertiesRepository)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 OffsetDateTime (java.time.OffsetDateTime)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1