use of com.synopsys.integration.alert.api.common.model.ValidationResponseModel in project blackduck-alert by blackducksoftware.
the class EmailGlobalTestActionTest method testPermissionConfigValidTest.
@Test
void testPermissionConfigValidTest() throws AlertException {
TestProperties testProperties = new TestProperties();
AuthorizationManager authorizationManager = createAuthorizationManager(AuthenticationTestUtils.FULL_PERMISSIONS);
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 globalConfigModel = createValidEmailGlobalConfigModel(testProperties);
ActionResponse<ValidationResponseModel> response = emailGlobalTestAction.testWithPermissionCheck("noreply@synopsys.com", globalConfigModel);
assertEquals(HttpStatus.OK, response.getHttpStatus());
assertTrue(response.isSuccessful());
assertTrue(response.hasContent());
assertFalse(response.getContent().get().hasErrors(), "Expected the message result to not have errors");
}
use of com.synopsys.integration.alert.api.common.model.ValidationResponseModel in project blackduck-alert by blackducksoftware.
the class EmailGlobalConfigurationValidatorTest method verifyValidConfig.
/*
* Email host: Required
* Email from: Required
*
* Email user: Required if email auth is true
* Email password: Required if email auth is true
*/
@Test
void verifyValidConfig() {
EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
EmailGlobalConfigModel model = new EmailGlobalConfigModel(null, AlertRestConstants.DEFAULT_CONFIGURATION_NAME, "from", "host");
model.setSmtpAuth(true);
model.setSmtpUsername("user");
model.setSmtpPassword("password");
ValidationResponseModel validationResponseModel = validator.validate(model);
Collection<AlertFieldStatus> alertFieldStatuses = validationResponseModel.getErrors().values();
assertEquals(0, alertFieldStatuses.size(), "There were errors in the configuration when none were expected.");
}
use of com.synopsys.integration.alert.api.common.model.ValidationResponseModel in project blackduck-alert by blackducksoftware.
the class EmailGlobalTestActionTest method testPermissionConfigInvalidDestinationTest.
@Test
void testPermissionConfigInvalidDestinationTest() {
AuthorizationManager authorizationManager = createAuthorizationManager(AuthenticationTestUtils.FULL_PERMISSIONS);
EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
EmailGlobalTestAction emailGlobalTestAction = new EmailGlobalTestAction(authorizationManager, validator, null, null, configurationAccessor);
ActionResponse<ValidationResponseModel> response = emailGlobalTestAction.testWithPermissionCheck("not a valid email address", new EmailGlobalConfigModel(null, AlertRestConstants.DEFAULT_CONFIGURATION_NAME, "from", "host"));
assertEquals(HttpStatus.OK, response.getHttpStatus());
assertTrue(response.hasContent());
assertTrue(response.getContent().get().hasErrors(), "Expected the message result to not have errors");
}
use of com.synopsys.integration.alert.api.common.model.ValidationResponseModel in project blackduck-alert by blackducksoftware.
the class JiraServerGlobalConfigurationValidatorTest method verifyMalformedUrl.
@Test
void verifyMalformedUrl() {
JiraServerGlobalConfigAccessor jiraServerGlobalConfigAccessor = Mockito.mock(JiraServerGlobalConfigAccessor.class);
Mockito.when(jiraServerGlobalConfigAccessor.getConfigurationByName(Mockito.anyString())).thenReturn(Optional.empty());
String badUrl = "notAValidUrl";
JiraServerGlobalConfigurationValidator validator = new JiraServerGlobalConfigurationValidator(jiraServerGlobalConfigAccessor);
JiraServerGlobalConfigModel model = new JiraServerGlobalConfigModel(ID, NAME, CREATED_AT, LAST_UPDATED, badUrl, USER_NAME, PASSWORD, Boolean.FALSE, Boolean.FALSE);
ValidationResponseModel validationResponseModel = validator.validate(model, null);
Collection<AlertFieldStatus> alertFieldStatuses = validationResponseModel.getErrors().values();
assertEquals(1, alertFieldStatuses.size(), "There were errors in the configuration when none were expected.");
for (AlertFieldStatus status : alertFieldStatuses) {
assertEquals("url", status.getFieldName(), "Validation reported an error for an unexpected field.");
}
}
use of com.synopsys.integration.alert.api.common.model.ValidationResponseModel in project blackduck-alert by blackducksoftware.
the class JiraServerGlobalConfigurationValidatorTest method verifyPasswordIsSavedAndMissingFromModel.
@Test
void verifyPasswordIsSavedAndMissingFromModel() {
JiraServerGlobalConfigAccessor jiraServerGlobalConfigAccessor = Mockito.mock(JiraServerGlobalConfigAccessor.class);
Mockito.when(jiraServerGlobalConfigAccessor.getConfigurationByName(Mockito.anyString())).thenReturn(Optional.empty());
JiraServerGlobalConfigurationValidator validator = new JiraServerGlobalConfigurationValidator(jiraServerGlobalConfigAccessor);
JiraServerGlobalConfigModel model = new JiraServerGlobalConfigModel(ID, NAME, CREATED_AT, LAST_UPDATED, URL, USER_NAME, null, Boolean.TRUE, Boolean.FALSE);
ValidationResponseModel validationResponseModel = validator.validate(model, null);
Collection<AlertFieldStatus> alertFieldStatuses = validationResponseModel.getErrors().values();
assertEquals(0, alertFieldStatuses.size(), "There were errors in the configuration when none were expected.");
}
Aggregations