use of com.synopsys.integration.alert.channel.email.database.configuration.properties.EmailConfigurationsPropertyEntity in project hub-alert by blackducksoftware.
the class EmailGlobalConfigurationModelSaveActionsTest method createInvalidConversionTest.
@Test
void createInvalidConversionTest() {
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);
ConfigurationModel configurationModel = createDefaultConfigurationModel();
updateField(configurationModel, EmailPropertyKeys.JAVAMAIL_PORT_KEY.getPropertyKey(), "badport");
saveActions.createConcreteModel(configurationModel);
EmailConfigurationEntity actualEntity = savedEntity.get();
EmailConfigurationsPropertyEntity emailProperty = savedProperty.get();
assertNull(actualEntity);
assertNull(emailProperty);
}
use of com.synopsys.integration.alert.channel.email.database.configuration.properties.EmailConfigurationsPropertyEntity in project hub-alert by blackducksoftware.
the class EmailGlobalConfigurationModelSaveActionsTest method deleteTest.
@Test
void deleteTest() {
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.anyString())).thenAnswer(invocation -> savedEntity.get() != null);
Mockito.doAnswer(invocation -> {
savedEntity.set(null);
savedProperty.set(null);
return null;
}).when(emailConfigurationRepository).deleteByName(Mockito.anyString());
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);
ConfigurationModel configurationModel = createDefaultConfigurationModel();
saveActions.createConcreteModel(configurationModel);
EmailConfigurationEntity actualEntity = savedEntity.get();
EmailConfigurationsPropertyEntity actualPropertyEntity = savedProperty.get();
assertNotNull(actualEntity);
assertNotNull(actualPropertyEntity);
saveActions.deleteConcreteModel(configurationModel);
actualEntity = savedEntity.get();
actualPropertyEntity = savedProperty.get();
assertNull(actualEntity);
assertNull(actualPropertyEntity);
}
use of com.synopsys.integration.alert.channel.email.database.configuration.properties.EmailConfigurationsPropertyEntity 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());
}
Aggregations