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);
}
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;
}
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());
}
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());
}
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());
}
Aggregations