use of com.synopsys.integration.alert.environment.EnvironmentProcessingResult in project hub-alert by blackducksoftware.
the class JiraServerEnvironmentVariableHandlerFactoryTest method testSetInEnvironment.
@Test
void testSetInEnvironment() {
Environment environment = Mockito.mock(Environment.class);
JiraServerGlobalConfigAccessor configAccessor = Mockito.mock(JiraServerGlobalConfigAccessor.class);
Mockito.when(configAccessor.getConfigurationCount()).thenReturn(0L);
Set<String> expectedVariableNames = JiraServerEnvironmentVariableHandlerFactory.VARIABLE_NAMES;
String disablePluginCheck = "true";
String url = "test.jira.server.example.com";
String passwordValue = "a test value";
String username = "testuser";
Predicate<String> hasEnvVarCheck = (variableName) -> !JiraServerEnvironmentVariableHandlerFactory.VARIABLE_NAMES.contains(variableName);
Mockito.when(environment.containsProperty(Mockito.anyString())).thenReturn(Boolean.TRUE);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, hasEnvVarCheck, JiraServerEnvironmentVariableHandlerFactory.DISABLE_PLUGIN_KEY, disablePluginCheck);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, hasEnvVarCheck, JiraServerEnvironmentVariableHandlerFactory.URL_KEY, url);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, hasEnvVarCheck, JiraServerEnvironmentVariableHandlerFactory.PASSWORD_KEY, passwordValue);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, hasEnvVarCheck, JiraServerEnvironmentVariableHandlerFactory.USERNAME_KEY, username);
EnvironmentVariableUtility environmentVariableUtility = new EnvironmentVariableUtility(environment);
EnvironmentVariableHandlerFactory factory = new JiraServerEnvironmentVariableHandlerFactory(configAccessor, environmentVariableUtility);
EnvironmentVariableHandler handler = factory.build();
EnvironmentProcessingResult result = handler.updateFromEnvironment();
assertEquals(ChannelKeys.JIRA_SERVER.getDisplayName(), handler.getName());
assertEquals(expectedVariableNames, handler.getVariableNames());
assertTrue(result.hasValues());
assertEquals(disablePluginCheck, result.getVariableValue(JiraServerEnvironmentVariableHandlerFactory.DISABLE_PLUGIN_KEY).orElse("Disable plugin check value missing"));
assertEquals(url, result.getVariableValue(JiraServerEnvironmentVariableHandlerFactory.URL_KEY).orElse("Url value missing"));
assertEquals(AlertConstants.MASKED_VALUE, result.getVariableValue(JiraServerEnvironmentVariableHandlerFactory.PASSWORD_KEY).orElse("Password value missing"));
assertEquals(username, 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 JiraServerEnvironmentVariableHandlerFactoryTest method testConfigPresent.
@Test
void testConfigPresent() {
Environment environment = Mockito.mock(Environment.class);
JiraServerGlobalConfigAccessor configAccessor = Mockito.mock(JiraServerGlobalConfigAccessor.class);
Mockito.when(configAccessor.getConfigurationCount()).thenReturn(1L);
EnvironmentVariableUtility environmentVariableUtility = new EnvironmentVariableUtility(environment);
EnvironmentVariableHandlerFactory factory = new JiraServerEnvironmentVariableHandlerFactory(configAccessor, 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 JiraServerEnvironmentVariableHandlerFactoryTest method testMissingFromEnvironment.
@Test
void testMissingFromEnvironment() {
Environment environment = Mockito.mock(Environment.class);
JiraServerGlobalConfigAccessor configAccessor = Mockito.mock(JiraServerGlobalConfigAccessor.class);
Mockito.when(configAccessor.getConfigurationCount()).thenReturn(0L);
EnvironmentVariableUtility environmentVariableUtility = new EnvironmentVariableUtility(environment);
EnvironmentVariableHandlerFactory factory = new JiraServerEnvironmentVariableHandlerFactory(configAccessor, 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 JiraServerEnvironmentVariableHandlerFactoryTest method testSetInEnvironmentURLMissing.
@Test
void testSetInEnvironmentURLMissing() {
Environment environment = Mockito.mock(Environment.class);
JiraServerGlobalConfigAccessor configAccessor = Mockito.mock(JiraServerGlobalConfigAccessor.class);
Mockito.when(configAccessor.getConfigurationCount()).thenReturn(0L);
Set<String> expectedVariableNames = JiraServerEnvironmentVariableHandlerFactory.VARIABLE_NAMES;
String disablePluginCheck = "true";
String passwordValue = "a test value";
String username = "testuser";
Predicate<String> hasEnvVarCheck = (variableName) -> !JiraServerEnvironmentVariableHandlerFactory.VARIABLE_NAMES.contains(variableName);
Mockito.when(environment.containsProperty(Mockito.anyString())).thenReturn(Boolean.TRUE);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, hasEnvVarCheck, JiraServerEnvironmentVariableHandlerFactory.DISABLE_PLUGIN_KEY, disablePluginCheck);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, hasEnvVarCheck, JiraServerEnvironmentVariableHandlerFactory.PASSWORD_KEY, passwordValue);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, hasEnvVarCheck, JiraServerEnvironmentVariableHandlerFactory.USERNAME_KEY, username);
EnvironmentVariableUtility environmentVariableUtility = new EnvironmentVariableUtility(environment);
EnvironmentVariableHandlerFactory factory = new JiraServerEnvironmentVariableHandlerFactory(configAccessor, environmentVariableUtility);
EnvironmentVariableHandler handler = factory.build();
EnvironmentProcessingResult result = handler.updateFromEnvironment();
assertEquals(ChannelKeys.JIRA_SERVER.getDisplayName(), handler.getName());
assertEquals(expectedVariableNames, handler.getVariableNames());
assertFalse(result.hasValues());
}
use of com.synopsys.integration.alert.environment.EnvironmentProcessingResult in project hub-alert by blackducksoftware.
the class JiraServerEnvironmentVariableHandlerFactory method updateConfiguration.
private EnvironmentProcessingResult updateConfiguration() {
EnvironmentProcessingResult.Builder builder = new EnvironmentProcessingResult.Builder(VARIABLE_NAMES);
String url = environmentVariableUtility.getEnvironmentValue(URL_KEY).orElse(null);
if (StringUtils.isBlank(url)) {
return EnvironmentProcessingResult.empty();
}
String name = AlertRestConstants.DEFAULT_CONFIGURATION_NAME;
String userName = environmentVariableUtility.getEnvironmentValue(USERNAME_KEY).orElse(null);
String password = environmentVariableUtility.getEnvironmentValue(PASSWORD_KEY).orElse(null);
String createdAt = DateUtils.formatDate(DateUtils.createCurrentDateTimestamp(), DateUtils.UTC_DATE_FORMAT_TO_MINUTE);
JiraServerGlobalConfigModel configModel = new JiraServerGlobalConfigModel(null, name, url, userName, password);
configModel.setCreatedAt(createdAt);
configModel.setLastUpdated(createdAt);
environmentVariableUtility.getEnvironmentValue(DISABLE_PLUGIN_KEY).map(Boolean::valueOf).ifPresent(configModel::setDisablePluginCheck);
JiraServerGlobalConfigModel obfuscatedModel = configModel.obfuscate();
if (StringUtils.isNotBlank(obfuscatedModel.getUrl())) {
builder.addVariableValue(URL_KEY, obfuscatedModel.getUrl());
}
if (StringUtils.isNotBlank(obfuscatedModel.getUserName())) {
builder.addVariableValue(USERNAME_KEY, obfuscatedModel.getUserName());
}
obfuscatedModel.getDisablePluginCheck().map(String::valueOf).ifPresent(value -> builder.addVariableValue(DISABLE_PLUGIN_KEY, value));
obfuscatedModel.getIsPasswordSet().filter(Boolean::booleanValue).ifPresent(ignored -> builder.addVariableValue(PASSWORD_KEY, AlertConstants.MASKED_VALUE));
EnvironmentProcessingResult result = builder.build();
if (result.hasValues() && configAccessor.getConfigurationByName(name).isEmpty()) {
try {
configAccessor.createConfiguration(configModel);
} catch (AlertConfigurationException ex) {
logger.error("Failed to create config: ", ex);
}
}
return result;
}
Aggregations