use of com.synopsys.integration.alert.channel.email.database.accessor.EmailGlobalConfigAccessor in project hub-alert by blackducksoftware.
the class EmailChannelTestIT method sendEmailNullGlobalTest.
@Test
public void sendEmailNullGlobalTest() {
String testEmailRecipient = testProperties.getProperty(TestPropertyKey.TEST_EMAIL_RECIPIENT);
EmailGlobalConfigAccessor emailConfigurationAccessor = Mockito.mock(EmailGlobalConfigAccessor.class);
Mockito.when(emailConfigurationAccessor.getConfiguration()).thenReturn(Optional.empty());
JobEmailAddressValidator emailAddressValidator = Mockito.mock(JobEmailAddressValidator.class);
Mockito.when(emailAddressValidator.validate(Mockito.any(), Mockito.anyCollection())).thenReturn(new ValidatedEmailAddresses(Set.of(testEmailRecipient), Set.of()));
EmailAddressGatherer emailAddressGatherer = new EmailAddressGatherer(null, null);
EmailChannelMessageConverter emailChannelMessageConverter = new EmailChannelMessageConverter(new EmailChannelMessageFormatter());
EmailChannelMessageSender emailChannelMessageSender = new EmailChannelMessageSender(emailConfigurationAccessor, emailAddressGatherer, null, emailAddressValidator, null);
EmailChannel emailChannel = new EmailChannel(emailChannelMessageConverter, emailChannelMessageSender);
List<String> emailAddresses = List.of(testEmailRecipient);
EmailJobDetailsModel emailJobDetails = new EmailJobDetailsModel(null, EmailChannelTestIT.class.getSimpleName(), false, true, EmailAttachmentFormat.NONE.name(), emailAddresses);
EmailITTestAssertions.assertSendSimpleMessageException(emailChannel, emailJobDetails, "ERROR: Missing Email global config.");
}
use of com.synopsys.integration.alert.channel.email.database.accessor.EmailGlobalConfigAccessor in project hub-alert by blackducksoftware.
the class EmailEnvironmentHandlerFactoryTest method testEmailConfigPresent.
@Test
void testEmailConfigPresent() {
Environment environment = Mockito.mock(Environment.class);
EmailGlobalConfigAccessor configAccessor = Mockito.mock(EmailGlobalConfigAccessor.class);
Mockito.when(configAccessor.doesConfigurationExist()).thenReturn(true);
EnvironmentVariableUtility environmentVariableUtility = new EnvironmentVariableUtility(environment);
EnvironmentVariableHandlerFactory factory = new EmailEnvironmentVariableHandlerFactory(configAccessor, environmentVariableUtility, validator);
EnvironmentVariableHandler handler = factory.build();
EnvironmentProcessingResult result = handler.updateFromEnvironment();
assertEquals(ChannelKeys.EMAIL.getDisplayName(), handler.getName());
assertFalse(result.hasValues());
}
use of com.synopsys.integration.alert.channel.email.database.accessor.EmailGlobalConfigAccessor in project hub-alert by blackducksoftware.
the class EmailEnvironmentHandlerFactoryTest method testEmailSetInEnvironment.
@Test
void testEmailSetInEnvironment() {
Environment environment = Mockito.mock(Environment.class);
EmailGlobalConfigAccessor configAccessor = Mockito.mock(EmailGlobalConfigAccessor.class);
Mockito.when(configAccessor.doesConfigurationExist()).thenReturn(false);
Set<String> expectedVariableNames = Stream.concat(EmailEnvironmentVariableHandlerFactory.EMAIL_CONFIGURATION_KEYSET.stream(), EmailEnvironmentVariableHandlerFactory.OLD_ADDITIONAL_PROPERTY_KEYSET.stream()).collect(Collectors.toSet());
String authRequired = "true";
String from = "noreply@example.com";
String smtpHost = "test.smtp.server.example.com";
String passwordValue = "a test value";
String port = "25";
String username = "testuser";
Predicate<String> hasEnvVarCheck = (variableName) -> !EmailEnvironmentVariableHandlerFactory.OLD_ADDITIONAL_PROPERTY_KEYSET.contains(variableName);
Mockito.when(environment.containsProperty(Mockito.anyString())).thenReturn(Boolean.TRUE);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, hasEnvVarCheck, EmailEnvironmentVariableHandlerFactory.AUTH_REQUIRED_KEY, authRequired);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, hasEnvVarCheck, EmailEnvironmentVariableHandlerFactory.EMAIL_FROM_KEY, from);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, hasEnvVarCheck, EmailEnvironmentVariableHandlerFactory.EMAIL_HOST_KEY, smtpHost);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, hasEnvVarCheck, EmailEnvironmentVariableHandlerFactory.AUTH_PASSWORD_KEY, passwordValue);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, hasEnvVarCheck, EmailEnvironmentVariableHandlerFactory.EMAIL_PORT_KEY, port);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, hasEnvVarCheck, EmailEnvironmentVariableHandlerFactory.AUTH_USER_KEY, username);
EnvironmentVariableUtility environmentVariableUtility = new EnvironmentVariableUtility(environment);
EnvironmentVariableHandlerFactory factory = new EmailEnvironmentVariableHandlerFactory(configAccessor, environmentVariableUtility, validator);
EnvironmentVariableHandler handler = factory.build();
EnvironmentProcessingResult result = handler.updateFromEnvironment();
assertEquals(ChannelKeys.EMAIL.getDisplayName(), handler.getName());
assertEquals(expectedVariableNames, handler.getVariableNames());
assertTrue(result.hasValues());
assertEquals(authRequired, result.getVariableValue(EmailEnvironmentVariableHandlerFactory.AUTH_REQUIRED_KEY).orElse("Auth required value missing"));
assertEquals(from, result.getVariableValue(EmailEnvironmentVariableHandlerFactory.EMAIL_FROM_KEY).orElse("SMTP from value missing"));
assertEquals(smtpHost, result.getVariableValue(EmailEnvironmentVariableHandlerFactory.EMAIL_HOST_KEY).orElse("SMTP host value missing"));
assertEquals(AlertConstants.MASKED_VALUE, result.getVariableValue(EmailEnvironmentVariableHandlerFactory.AUTH_PASSWORD_KEY).orElse("Auth password value missing"));
assertEquals(port, result.getVariableValue(EmailEnvironmentVariableHandlerFactory.EMAIL_PORT_KEY).orElse("SMTP port value missing"));
assertEquals(username, result.getVariableValue(EmailEnvironmentVariableHandlerFactory.AUTH_USER_KEY).orElse("Auth user value missing"));
}
use of com.synopsys.integration.alert.channel.email.database.accessor.EmailGlobalConfigAccessor 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.accessor.EmailGlobalConfigAccessor 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);
}
Aggregations