use of com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel in project hub-alert by blackducksoftware.
the class EmailGlobalConfigurationActionTest method testGetOne.
@Test
public void testGetOne() {
AuthenticationTestUtils authenticationTestUtils = new AuthenticationTestUtils();
DescriptorKey descriptorKey = ChannelKeys.EMAIL;
PermissionKey permissionKey = new PermissionKey(ConfigContextEnum.GLOBAL.name(), descriptorKey.getUniversalKey());
Map<PermissionKey, Integer> permissions = Map.of(permissionKey, AuthenticationTestUtils.FULL_PERMISSIONS);
AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
EmailGlobalConfigAccessor emailGlobalConfigAccessor = Mockito.mock(EmailGlobalConfigAccessor.class);
EmailGlobalConfigModel model = new EmailGlobalConfigModel();
model.setSmtpHost("host");
model.setSmtpFrom("from");
model.setSmtpAuth(true);
model.setSmtpUsername("user");
model.setSmtpPassword("password");
Mockito.when(emailGlobalConfigAccessor.getConfiguration()).thenReturn(Optional.of(model));
EmailGlobalCrudActions configActions = new EmailGlobalCrudActions(authorizationManager, emailGlobalConfigAccessor, validator);
ActionResponse<EmailGlobalConfigModel> response = configActions.getOne();
assertEquals(HttpStatus.OK, response.getHttpStatus());
assertTrue(response.hasContent());
assertEquals(model.obfuscate(), response.getContent().get());
}
use of com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel in project hub-alert by blackducksoftware.
the class EmailGlobalConfigurationActionTest method testCreate.
@Test
public void testCreate() throws AlertConfigurationException {
AuthenticationTestUtils authenticationTestUtils = new AuthenticationTestUtils();
DescriptorKey descriptorKey = ChannelKeys.EMAIL;
PermissionKey permissionKey = new PermissionKey(ConfigContextEnum.GLOBAL.name(), descriptorKey.getUniversalKey());
Map<PermissionKey, Integer> permissions = Map.of(permissionKey, AuthenticationTestUtils.FULL_PERMISSIONS);
AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
EmailGlobalConfigAccessor emailGlobalConfigAccessor = Mockito.mock(EmailGlobalConfigAccessor.class);
EmailGlobalConfigModel model = new EmailGlobalConfigModel();
model.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
model.setSmtpHost("host");
model.setSmtpFrom("from");
model.setSmtpAuth(true);
model.setSmtpUsername("user");
model.setSmtpPassword("password");
Mockito.when(emailGlobalConfigAccessor.createConfiguration(Mockito.eq(model))).thenReturn(model);
EmailGlobalCrudActions configActions = new EmailGlobalCrudActions(authorizationManager, emailGlobalConfigAccessor, validator);
ActionResponse<EmailGlobalConfigModel> response = configActions.create(model);
assertEquals(HttpStatus.OK, response.getHttpStatus());
assertTrue(response.hasContent());
assertEquals(model.obfuscate(), response.getContent().get());
}
use of com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel in project hub-alert by blackducksoftware.
the class EmailGlobalConfigurationModelConverterTest method emptyFieldsTest.
@Test
void emptyFieldsTest() {
ConfigurationModel emptyModel = new ConfigurationModel(1L, 1L, "", "", ConfigContextEnum.GLOBAL, Map.of());
EmailGlobalConfigurationModelConverter converter = new EmailGlobalConfigurationModelConverter();
Optional<EmailGlobalConfigModel> model = converter.convert(emptyModel);
assertTrue(model.isPresent());
EmailGlobalConfigModel emailModel = model.get();
assertTrue(emailModel.getSmtpAuth().isEmpty());
assertTrue(emailModel.getSmtpUsername().isEmpty());
assertTrue(emailModel.getSmtpPassword().isEmpty());
assertTrue(emailModel.getSmtpHost().isEmpty());
assertTrue(emailModel.getSmtpPort().isEmpty());
assertTrue(emailModel.getSmtpFrom().isEmpty());
assertTrue(emailModel.getAdditionalJavaMailProperties().isPresent());
assertTrue(emailModel.getAdditionalJavaMailProperties().orElseThrow(() -> new AssertionError("Expected an additional properties map.")).isEmpty());
}
use of com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel in project hub-alert by blackducksoftware.
the class EmailChannelTestIT method sendEmailTest.
@Test
@Tag(TestTags.CUSTOM_EXTERNAL_CONNECTION)
public void sendEmailTest() {
MockAlertProperties testAlertProperties = new MockAlertProperties();
String testEmailRecipient = testProperties.getProperty(TestPropertyKey.TEST_EMAIL_RECIPIENT);
EmailAttachmentFileCreator emailAttachmentFileCreator = new EmailAttachmentFileCreator(testAlertProperties, new MessageContentGroupCsvCreator(), gson);
FreemarkerTemplatingService freemarkerTemplatingService = new FreemarkerTemplatingService();
EmailMessagingService emailMessagingService = new EmailMessagingService(freemarkerTemplatingService);
JavamailPropertiesFactory javamailPropertiesFactory = new JavamailPropertiesFactory();
EmailChannelMessagingService emailChannelMessagingService = new EmailChannelMessagingService(testAlertProperties, emailMessagingService, emailAttachmentFileCreator);
EmailGlobalConfigModel emailGlobalConfig = createEmailGlobalConfig();
EmailGlobalConfigAccessor emailConfigurationAccessor = Mockito.mock(EmailGlobalConfigAccessor.class);
Mockito.when(emailConfigurationAccessor.getConfiguration()).thenReturn(Optional.of(emailGlobalConfig));
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, emailChannelMessagingService, emailAddressValidator, javamailPropertiesFactory);
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.assertSendSimpleMessageSuccess(emailChannel, emailJobDetails);
}
use of com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel in project hub-alert by blackducksoftware.
the class EmailChannelTestIT method createEmailGlobalConfig.
private EmailGlobalConfigModel createEmailGlobalConfig() {
EmailGlobalConfigModel emailGlobalConfigModel = new EmailGlobalConfigModel();
emailGlobalConfigModel.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
emailGlobalConfigModel.setSmtpHost(testProperties.getProperty(TestPropertyKey.TEST_EMAIL_SMTP_HOST));
emailGlobalConfigModel.setSmtpFrom(testProperties.getProperty(TestPropertyKey.TEST_EMAIL_SMTP_FROM));
emailGlobalConfigModel.setSmtpUsername(testProperties.getProperty(TestPropertyKey.TEST_EMAIL_SMTP_USER));
emailGlobalConfigModel.setSmtpPassword(testProperties.getProperty(TestPropertyKey.TEST_EMAIL_SMTP_PASSWORD));
emailGlobalConfigModel.setSmtpAuth(Boolean.parseBoolean(testProperties.getProperty(TestPropertyKey.TEST_EMAIL_SMTP_AUTH)));
String port = testProperties.getProperty(TestPropertyKey.TEST_EMAIL_SMTP_PORT);
if (StringUtils.isNotBlank(port)) {
emailGlobalConfigModel.setSmtpPort(Integer.parseInt(port));
}
Map<String, String> properties = Map.of(TestPropertyKey.TEST_EMAIL_SMTP_EHLO.getPropertyKey(), testProperties.getProperty(TestPropertyKey.TEST_EMAIL_SMTP_EHLO));
emailGlobalConfigModel.setAdditionalJavaMailProperties(properties);
return emailGlobalConfigModel;
}
Aggregations