use of org.springframework.core.env.Environment in project hub-alert by blackducksoftware.
the class JiraServerEnvironmentHandlerFactoryTestIT method setupMockedEnvironment.
private Environment setupMockedEnvironment() {
Environment environment = Mockito.mock(Environment.class);
Predicate<String> hasEnvVarCheck = (variableName) -> !JiraServerEnvironmentVariableHandlerFactory.VARIABLE_NAMES.contains(variableName);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, hasEnvVarCheck, JiraServerEnvironmentVariableHandlerFactory.DISABLE_PLUGIN_KEY, TEST_DISABLE_PLUGIN_CHECK);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, hasEnvVarCheck, JiraServerEnvironmentVariableHandlerFactory.URL_KEY, TEST_URL);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, hasEnvVarCheck, JiraServerEnvironmentVariableHandlerFactory.PASSWORD_KEY, TEST_PASSWORD);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, hasEnvVarCheck, JiraServerEnvironmentVariableHandlerFactory.USERNAME_KEY, TEST_USER);
return environment;
}
use of org.springframework.core.env.Environment in project hub-alert by blackducksoftware.
the class JiraServerEnvironmentVariableHandlerFactoryTest method testSetInEnvironmentUserNameMissing.
@Test
void testSetInEnvironmentUserNameMissing() {
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";
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);
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"));
assertTrue(result.getVariableValue(JiraServerEnvironmentVariableHandlerFactory.USERNAME_KEY).isEmpty());
}
use of org.springframework.core.env.Environment in project hub-alert by blackducksoftware.
the class EnvironmentVariableProcessorTest method testUpdatingHandler.
@Test
void testUpdatingHandler() {
Environment environment = Mockito.mock(Environment.class);
for (String variableName : EnvironmentTestHandlerFactory.VARIABLE_NAMES) {
Mockito.when(environment.containsProperty(variableName)).thenReturn(Boolean.TRUE);
Mockito.when(environment.getProperty(variableName)).thenReturn(EnvironmentTestHandlerFactory.DEFAULT_VALUE);
}
EnvironmentVariableUtility environmentVariableUtility = new EnvironmentVariableUtility(environment);
EnvironmentTestHandlerFactory handler = new EnvironmentTestHandlerFactory(environmentVariableUtility);
EnvironmentVariableProcessor processor = new EnvironmentVariableProcessor(List.of(handler));
processor.updateConfigurations();
assertTrue(handler.hasUpdateOccurred());
EnvironmentProcessingResult result = handler.getUpdatedProperties().orElseThrow(() -> new AssertionError("Properties should exist"));
assertTrue(result.hasValues());
assertTrue(EnvironmentTestHandlerFactory.VARIABLE_NAMES.containsAll(result.getVariableNames()));
}
use of org.springframework.core.env.Environment in project hub-alert by blackducksoftware.
the class EnvironmentVariableProcessorTest method testMissingEnvironmentVariablesHandler.
@Test
void testMissingEnvironmentVariablesHandler() {
Environment environment = Mockito.mock(Environment.class);
EnvironmentVariableUtility environmentVariableUtility = new EnvironmentVariableUtility(environment);
EnvironmentTestHandlerFactory handler = new EnvironmentTestHandlerFactory(environmentVariableUtility);
EnvironmentVariableProcessor processor = new EnvironmentVariableProcessor(List.of(handler));
processor.updateConfigurations();
assertFalse(handler.hasUpdateOccurred());
assertFalse(handler.getUpdatedProperties().stream().allMatch(EnvironmentProcessingResult::hasValues));
}
use of org.springframework.core.env.Environment in project hub-alert by blackducksoftware.
the class EnvironmentVariableUtilityTest method testKeyConversion.
@Test
void testKeyConversion() {
Environment environment = Mockito.mock(Environment.class);
EnvironmentVariableUtility environmentVariableUtility = new EnvironmentVariableUtility(environment);
String actualPropertyKey = environmentVariableUtility.convertKeyToProperty(DESCRIPTOR_KEY, "specific.property.key");
assertEquals(WORKING_PROPERTY_KEY, actualPropertyKey);
}
Aggregations