use of com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel in project hub-alert by blackducksoftware.
the class EmailGlobalTestActionTest method testPermissionConfigITTest.
@Test
@Tags(value = { @Tag(TestTags.DEFAULT_INTEGRATION), @Tag(TestTags.CUSTOM_EXTERNAL_CONNECTION) })
public void testPermissionConfigITTest() {
AuthorizationManager authorizationManager = createAuthorizationManager(AuthenticationTestUtils.FULL_PERMISSIONS);
EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
TestProperties testProperties = new TestProperties();
String emailAddress = testProperties.getProperty(TestPropertyKey.TEST_EMAIL_RECIPIENT);
JavamailPropertiesFactory javamailPropertiesFactory = new JavamailPropertiesFactory();
EmailChannelMessagingService validEmailChannelMessagingService = createValidEmailChannelMessagingService(emailAddress);
EmailGlobalTestAction emailGlobalTestAction = new EmailGlobalTestAction(authorizationManager, validator, validEmailChannelMessagingService, javamailPropertiesFactory, configurationAccessor);
EmailGlobalConfigModel globalConfigModel = createValidEmailGlobalConfigModel(testProperties);
ActionResponse<ValidationResponseModel> response = emailGlobalTestAction.testWithPermissionCheck(emailAddress, globalConfigModel);
assertEquals(HttpStatus.OK, response.getHttpStatus());
assertTrue(response.hasContent());
assertFalse(response.getContent().get().hasErrors(), "Expected the message result to not have errors");
}
use of com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel in project hub-alert by blackducksoftware.
the class EmailGlobalTestActionTest method testSmtpPasswordMissingTestIT.
@Test
@Tags(value = { @Tag(TestTags.DEFAULT_INTEGRATION), @Tag(TestTags.CUSTOM_EXTERNAL_CONNECTION) })
public void testSmtpPasswordMissingTestIT() {
AuthorizationManager authorizationManager = createAuthorizationManager(AuthenticationTestUtils.FULL_PERMISSIONS);
EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
TestProperties testProperties = new TestProperties();
String emailAddress = testProperties.getProperty(TestPropertyKey.TEST_EMAIL_RECIPIENT);
assumeTrue(testProperties.getOptionalProperty(TestPropertyKey.TEST_EMAIL_SMTP_PASSWORD).isPresent());
JavamailPropertiesFactory javamailPropertiesFactory = new JavamailPropertiesFactory();
EmailChannelMessagingService validEmailChannelMessagingService = createValidEmailChannelMessagingService(emailAddress);
EmailGlobalTestAction emailGlobalTestAction = new EmailGlobalTestAction(authorizationManager, validator, validEmailChannelMessagingService, javamailPropertiesFactory, configurationAccessor);
EmailGlobalConfigModel globalConfigModelWithoutPassword = createEmailGlobalConfigModelObfuscated(testProperties);
EmailGlobalConfigModel globalConfigModelWithPassword = createValidEmailGlobalConfigModel(testProperties);
Mockito.when(configurationAccessor.getConfiguration()).thenReturn(Optional.of(globalConfigModelWithPassword));
ConfigurationTestResult testResult = emailGlobalTestAction.testConfigModelContent(emailAddress, globalConfigModelWithoutPassword);
assertTrue(testResult.isSuccess(), "Expected the message result to not have errors");
}
use of com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel in project hub-alert by blackducksoftware.
the class EmailGlobalTestActionTest method createValidEmailGlobalConfigModel.
private EmailGlobalConfigModel createValidEmailGlobalConfigModel(TestProperties testProperties) {
EmailGlobalConfigModel emailGlobalConfigModel = new EmailGlobalConfigModel();
emailGlobalConfigModel.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
emailGlobalConfigModel.setSmtpFrom(testProperties.getProperty(TestPropertyKey.TEST_EMAIL_SMTP_FROM));
emailGlobalConfigModel.setSmtpHost(testProperties.getProperty(TestPropertyKey.TEST_EMAIL_SMTP_HOST));
testProperties.getOptionalProperty(TestPropertyKey.TEST_EMAIL_SMTP_PORT).map(Integer::valueOf).ifPresent(emailGlobalConfigModel::setSmtpPort);
testProperties.getOptionalProperty(TestPropertyKey.TEST_EMAIL_SMTP_AUTH).map(Boolean::valueOf).ifPresent(emailGlobalConfigModel::setSmtpAuth);
testProperties.getOptionalProperty(TestPropertyKey.TEST_EMAIL_SMTP_USER).ifPresent(emailGlobalConfigModel::setSmtpUsername);
testProperties.getOptionalProperty(TestPropertyKey.TEST_EMAIL_SMTP_PASSWORD).ifPresent(emailGlobalConfigModel::setSmtpPassword);
Map<String, String> additionalPropertiesMap = new HashMap<>();
testProperties.getOptionalProperty(TestPropertyKey.TEST_EMAIL_SMTP_EHLO).ifPresent(prop -> additionalPropertiesMap.put(EmailPropertyKeys.JAVAMAIL_EHLO_KEY.getPropertyKey(), prop));
emailGlobalConfigModel.setAdditionalJavaMailProperties(additionalPropertiesMap);
return emailGlobalConfigModel;
}
use of com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel in project hub-alert by blackducksoftware.
the class EmailGlobalTestActionTest method testSmtpPasswordMissingTest.
@Test
public void testSmtpPasswordMissingTest() throws AlertException {
AuthorizationManager authorizationManager = createAuthorizationManager(255);
EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
EmailChannelMessagingService emailChannelMessagingService = Mockito.mock(EmailChannelMessagingService.class);
Mockito.when(emailChannelMessagingService.sendMessage(Mockito.any(), Mockito.any())).thenReturn(new MessageResult("PASS"));
JavamailPropertiesFactory javamailPropertiesFactory = new JavamailPropertiesFactory();
EmailGlobalTestAction emailGlobalTestAction = new EmailGlobalTestAction(authorizationManager, validator, emailChannelMessagingService, javamailPropertiesFactory, configurationAccessor);
EmailGlobalConfigModel emailGlobalConfigModel = new EmailGlobalConfigModel();
emailGlobalConfigModel.setIsSmtpPasswordSet(true);
EmailGlobalConfigModel configModelWithPassword = new EmailGlobalConfigModel();
configModelWithPassword.setIsSmtpPasswordSet(true);
configModelWithPassword.setSmtpPassword("password");
Mockito.when(configurationAccessor.getConfiguration()).thenReturn(Optional.of(configModelWithPassword));
ConfigurationTestResult testResult = emailGlobalTestAction.testConfigModelContent("noreply@synopsys.com", emailGlobalConfigModel);
assertTrue(testResult.isSuccess(), "Expected the message result to not have errors");
}
use of com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel in project hub-alert by blackducksoftware.
the class EmailGlobalTestActionTest method testConfigInvalidDestinationTest.
@Test
public void testConfigInvalidDestinationTest() {
AuthorizationManager authorizationManager = createAuthorizationManager(AuthenticationTestUtils.FULL_PERMISSIONS);
EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
EmailGlobalTestAction emailGlobalTestAction = new EmailGlobalTestAction(authorizationManager, validator, null, null, null);
ConfigurationTestResult testResult = emailGlobalTestAction.testConfigModelContent("not a valid email address", new EmailGlobalConfigModel());
assertFalse(testResult.isSuccess());
}
Aggregations