use of com.synopsys.integration.alert.common.persistence.accessor.FieldUtility in project hub-alert by blackducksoftware.
the class EmailGlobalFieldModelTestActionTest method testConfigInvalidDestinationTest.
@Test
public void testConfigInvalidDestinationTest() {
EmailGlobalFieldModelTestAction emailGlobalFieldModelTestAction = new EmailGlobalFieldModelTestAction(null, null);
FieldModel validFieldModel = createFieldModelToTest("not a valid email address");
try {
emailGlobalFieldModelTestAction.testConfig("0", validFieldModel, new FieldUtility(Map.of()));
fail("Expected an exception to be thrown");
} catch (AlertException e) {
// Pass
}
}
use of com.synopsys.integration.alert.common.persistence.accessor.FieldUtility in project hub-alert by blackducksoftware.
the class ConfigurationTest method getFieldAccessorTest.
@Test
public void getFieldAccessorTest() {
String fieldKey = "Key1";
ConfigurationFieldModel testConfigurationFieldModel = Mockito.mock(ConfigurationFieldModel.class);
Map<String, ConfigurationFieldModel> keyToFieldMapTest = new HashMap<>();
keyToFieldMapTest.put(fieldKey, testConfigurationFieldModel);
Configuration testConfig = new Configuration(keyToFieldMapTest);
FieldUtility testFieldUtility = testConfig.getFieldUtility();
Optional<ConfigurationFieldModel> newConfigurationFieldModel = testFieldUtility.getField(fieldKey);
assertTrue(newConfigurationFieldModel.isPresent());
assertEquals(testConfigurationFieldModel, newConfigurationFieldModel.get());
}
use of com.synopsys.integration.alert.common.persistence.accessor.FieldUtility in project hub-alert by blackducksoftware.
the class JobConfigActions method testProviderConfig.
private MessageResult testProviderConfig(FieldUtility fieldUtility, String jobId, FieldModel fieldModel) throws IntegrationException {
Optional<FieldModelTestAction> providerTestAction = fieldUtility.getString(ChannelDescriptor.KEY_PROVIDER_TYPE).flatMap(providerName -> descriptorProcessor.retrieveTestAction(providerName, ConfigContextEnum.DISTRIBUTION));
if (providerTestAction.isPresent()) {
MessageResult providerConfigTestResult = providerTestAction.get().testConfig(jobId, fieldModel, fieldUtility);
if (!providerConfigTestResult.hasErrors()) {
return providerConfigTestResult;
} else {
List<AlertFieldStatus> deescalatedErrors = providerConfigTestResult.fieldErrors().stream().map(fieldStatus -> AlertFieldStatus.warning(fieldStatus.getFieldName(), fieldStatus.getFieldMessage())).collect(Collectors.toList());
List<AlertFieldStatus> allWarnings = ListUtils.union(providerConfigTestResult.fieldWarnings(), deescalatedErrors);
return new MessageResult("Provider Config Invalid", allWarnings);
}
}
return new MessageResult("Provider Config Valid");
}
use of com.synopsys.integration.alert.common.persistence.accessor.FieldUtility in project hub-alert by blackducksoftware.
the class EmailGlobalFieldModelTestActionTest method testConfigValidTest.
@Test
public void testConfigValidTest() throws AlertException {
EmailChannelMessagingService emailChannelMessagingService = Mockito.mock(EmailChannelMessagingService.class);
Mockito.when(emailChannelMessagingService.sendMessage(Mockito.any(), Mockito.any())).thenReturn(new MessageResult("PASS"));
JavamailPropertiesFactory javamailPropertiesFactory = new JavamailPropertiesFactory();
EmailGlobalFieldModelTestAction emailGlobalFieldModelTestAction = new EmailGlobalFieldModelTestAction(emailChannelMessagingService, javamailPropertiesFactory);
FieldModel validFieldModel = createFieldModelToTest("noreply@synopsys.com");
try {
MessageResult messageResult = emailGlobalFieldModelTestAction.testConfig("0", validFieldModel, new FieldUtility(Map.of()));
assertFalse(messageResult.hasErrors(), "Expected the message result to not have errors");
assertFalse(messageResult.hasWarnings(), "Expected the message result to not have warnings");
} catch (AlertException e) {
fail("An exception was thrown where none was expected", e);
}
}
use of com.synopsys.integration.alert.common.persistence.accessor.FieldUtility in project hub-alert by blackducksoftware.
the class EmailGlobalFieldModelTestActionTest method testConfigMissingDestinationTest.
@Test
public void testConfigMissingDestinationTest() {
JobEmailAddressValidator emailAddressValidator = Mockito.mock(JobEmailAddressValidator.class);
Mockito.when(emailAddressValidator.validate(Mockito.any(), Mockito.anyCollection())).thenReturn(new ValidatedEmailAddresses(Set.of(), Set.of()));
MockAlertProperties testAlertProperties = new MockAlertProperties();
MessageContentGroupCsvCreator messageContentGroupCsvCreator = new MessageContentGroupCsvCreator();
Gson gson = new Gson();
EmailAttachmentFileCreator emailAttachmentFileCreator = new EmailAttachmentFileCreator(testAlertProperties, messageContentGroupCsvCreator, gson);
FreemarkerTemplatingService freemarkerTemplatingService = new FreemarkerTemplatingService();
EmailMessagingService emailMessagingService = new EmailMessagingService(freemarkerTemplatingService);
EmailChannelMessagingService emailChannelMessagingService = new EmailChannelMessagingService(testAlertProperties, emailMessagingService, emailAttachmentFileCreator);
JavamailPropertiesFactory javamailPropertiesFactory = new JavamailPropertiesFactory();
EmailGlobalFieldModelTestAction emailGlobalFieldModelTestAction = new EmailGlobalFieldModelTestAction(emailChannelMessagingService, javamailPropertiesFactory);
FieldModel validFieldModel = createFieldModelToTest("");
try {
emailGlobalFieldModelTestAction.testConfig("0", validFieldModel, new FieldUtility(Map.of()));
fail("Expected an exception to be thrown");
} catch (AlertException e) {
// Pass
}
}
Aggregations