use of com.synopsys.integration.alert.environment.EnvironmentProcessingResult in project hub-alert by blackducksoftware.
the class EmailEnvironmentHandlerFactoryTestIT method testExistingEmailConfig.
@Test
void testExistingEmailConfig() throws AlertConfigurationException {
EmailGlobalConfigModel emailGlobalConfigModel = new EmailGlobalConfigModel();
emailGlobalConfigModel.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
emailGlobalConfigModel.setSmtpAuth(Boolean.valueOf(TEST_AUTH_REQUIRED));
emailGlobalConfigModel.setSmtpFrom(TEST_FROM);
emailGlobalConfigModel.setSmtpHost(TEST_SMTP_HOST);
emailGlobalConfigModel.setSmtpPassword(TEST_PASSWORD);
emailGlobalConfigModel.setSmtpPort(Integer.valueOf(TEST_PORT));
emailGlobalConfigModel.setSmtpUsername(TEST_USER);
emailGlobalConfigAccessor.createConfiguration(emailGlobalConfigModel);
Environment environment = setupMockedEnvironment();
EnvironmentVariableUtility environmentVariableUtility = new EnvironmentVariableUtility(environment);
EnvironmentVariableHandlerFactory factory = new EmailEnvironmentVariableHandlerFactory(emailGlobalConfigAccessor, 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.environment.EnvironmentProcessingResult in project hub-alert by blackducksoftware.
the class JiraServerEnvironmentHandlerFactoryTestIT method testCleanEnvironment.
@Test
void testCleanEnvironment() {
Environment environment = setupMockedEnvironment();
EnvironmentVariableUtility environmentVariableUtility = new EnvironmentVariableUtility(environment);
EnvironmentVariableHandlerFactory factory = new JiraServerEnvironmentVariableHandlerFactory(jiraGlobalConfigAccessor, environmentVariableUtility);
EnvironmentVariableHandler handler = factory.build();
EnvironmentProcessingResult result = handler.updateFromEnvironment();
assertEquals(ChannelKeys.JIRA_SERVER.getDisplayName(), handler.getName());
assertTrue(result.hasValues());
assertEquals(TEST_DISABLE_PLUGIN_CHECK, result.getVariableValue(JiraServerEnvironmentVariableHandlerFactory.DISABLE_PLUGIN_KEY).orElse("Disable plugin check value missing"));
assertEquals(TEST_URL, result.getVariableValue(JiraServerEnvironmentVariableHandlerFactory.URL_KEY).orElse("Url value missing"));
assertEquals(AlertConstants.MASKED_VALUE, result.getVariableValue(JiraServerEnvironmentVariableHandlerFactory.PASSWORD_KEY).orElse("Password value missing"));
assertEquals(TEST_USER, result.getVariableValue(JiraServerEnvironmentVariableHandlerFactory.USERNAME_KEY).orElse("Username value missing"));
}
use of com.synopsys.integration.alert.environment.EnvironmentProcessingResult in project hub-alert by blackducksoftware.
the class JiraServerEnvironmentHandlerFactoryTestIT method testExistingConfig.
@Test
void testExistingConfig() throws AlertConfigurationException {
String createdAt = DateUtils.formatDate(DateUtils.createCurrentDateTimestamp(), DateUtils.UTC_DATE_FORMAT_TO_MINUTE);
JiraServerGlobalConfigModel emailGlobalConfigModel = new JiraServerGlobalConfigModel(null, AlertRestConstants.DEFAULT_CONFIGURATION_NAME, createdAt, createdAt, TEST_URL, TEST_USER, TEST_PASSWORD, false, true);
jiraGlobalConfigAccessor.createConfiguration(emailGlobalConfigModel);
Environment environment = setupMockedEnvironment();
EnvironmentVariableUtility environmentVariableUtility = new EnvironmentVariableUtility(environment);
EnvironmentVariableHandlerFactory factory = new JiraServerEnvironmentVariableHandlerFactory(jiraGlobalConfigAccessor, environmentVariableUtility);
EnvironmentVariableHandler handler = factory.build();
EnvironmentProcessingResult result = handler.updateFromEnvironment();
assertEquals(ChannelKeys.JIRA_SERVER.getDisplayName(), handler.getName());
assertFalse(result.hasValues());
}
use of com.synopsys.integration.alert.environment.EnvironmentProcessingResult in project hub-alert by blackducksoftware.
the class ProxySettingsEnvironmentHandlerFactoryTest method testProxyMissingFromEnvironment.
@Test
void testProxyMissingFromEnvironment() {
Environment environment = Mockito.mock(Environment.class);
SettingsProxyConfigAccessor configAccessor = Mockito.mock(SettingsProxyConfigAccessor.class);
Mockito.when(configAccessor.getConfiguration()).thenReturn(Optional.empty());
EnvironmentVariableUtility environmentVariableUtility = new EnvironmentVariableUtility(environment);
EnvironmentVariableHandlerFactory factory = new ProxySettingsEnvironmentHandlerFactory(configAccessor, environmentVariableUtility, validator);
EnvironmentVariableHandler handler = factory.build();
EnvironmentProcessingResult result = handler.updateFromEnvironment();
assertEquals(ProxySettingsEnvironmentHandlerFactory.HANDLER_NAME, handler.getName());
assertFalse(result.hasValues());
}
use of com.synopsys.integration.alert.environment.EnvironmentProcessingResult in project hub-alert by blackducksoftware.
the class ProxySettingsEnvironmentHandlerFactory method updateFunction.
private EnvironmentProcessingResult updateFunction() {
EnvironmentProcessingResult.Builder builder = new EnvironmentProcessingResult.Builder(PROXY_CONFIGURATION_KEYSET);
SettingsProxyModel configModel = new SettingsProxyModel();
configModel.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
configureProxySettings(configModel);
// TODO: Refactor and remove duplicate code after 6.10.0 model package refactor
ValidationResponseModel validationResponseModel = validator.validate(configModel);
if (validationResponseModel.hasErrors()) {
logger.error("Error inserting startup values: {}", validationResponseModel.getMessage());
Map<String, AlertFieldStatus> errors = validationResponseModel.getErrors();
for (Map.Entry<String, AlertFieldStatus> error : errors.entrySet()) {
AlertFieldStatus status = error.getValue();
logger.error("Field: '{}' failed with the error: {}", status.getFieldName(), status.getFieldMessage());
}
return EnvironmentProcessingResult.empty();
}
SettingsProxyModel obfuscatedModel = configModel.obfuscate();
obfuscatedModel.getProxyHost().ifPresent(value -> builder.addVariableValue(PROXY_HOST_KEY, value));
obfuscatedModel.getProxyPort().map(String::valueOf).ifPresent(value -> builder.addVariableValue(PROXY_PORT_KEY, value));
obfuscatedModel.getProxyUsername().ifPresent(value -> builder.addVariableValue(PROXY_USERNAME_KEY, value));
obfuscatedModel.getNonProxyHosts().map(String::valueOf).ifPresent(value -> builder.addVariableValue(PROXY_NON_PROXY_HOSTS_KEY, value));
if (Boolean.TRUE.equals(obfuscatedModel.getIsProxyPasswordSet())) {
builder.addVariableValue(PROXY_PASSWORD_KEY, AlertConstants.MASKED_VALUE);
}
EnvironmentProcessingResult result = builder.build();
if (result.hasValues()) {
try {
configAccessor.createConfiguration(configModel);
} catch (AlertConfigurationException ex) {
logger.error("Error creating the configuration: {}", ex.getMessage());
}
}
return result;
}
Aggregations