Search in sources :

Example 6 with EnvironmentVariableHandler

use of com.synopsys.integration.alert.environment.EnvironmentVariableHandler 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());
}
Also used : EnvironmentVariableHandlerFactory(com.synopsys.integration.alert.environment.EnvironmentVariableHandlerFactory) EnvironmentVariableUtility(com.synopsys.integration.alert.environment.EnvironmentVariableUtility) Environment(org.springframework.core.env.Environment) EnvironmentVariableHandler(com.synopsys.integration.alert.environment.EnvironmentVariableHandler) JiraServerGlobalConfigAccessor(com.synopsys.integration.alert.channel.jira.server.database.accessor.JiraServerGlobalConfigAccessor) EnvironmentProcessingResult(com.synopsys.integration.alert.environment.EnvironmentProcessingResult) Test(org.junit.jupiter.api.Test)

Example 7 with EnvironmentVariableHandler

use of com.synopsys.integration.alert.environment.EnvironmentVariableHandler 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());
}
Also used : EnvironmentVariableHandlerFactory(com.synopsys.integration.alert.environment.EnvironmentVariableHandlerFactory) EnvironmentVariableUtility(com.synopsys.integration.alert.environment.EnvironmentVariableUtility) Environment(org.springframework.core.env.Environment) EnvironmentVariableHandler(com.synopsys.integration.alert.environment.EnvironmentVariableHandler) JiraServerGlobalConfigAccessor(com.synopsys.integration.alert.channel.jira.server.database.accessor.JiraServerGlobalConfigAccessor) EnvironmentProcessingResult(com.synopsys.integration.alert.environment.EnvironmentProcessingResult) Test(org.junit.jupiter.api.Test)

Example 8 with EnvironmentVariableHandler

use of com.synopsys.integration.alert.environment.EnvironmentVariableHandler 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());
}
Also used : EnvironmentVariableUtility(com.synopsys.integration.alert.environment.EnvironmentVariableUtility) Predicate(java.util.function.Predicate) Set(java.util.Set) EnvironmentVariableMockingUtil(com.synopsys.integration.alert.test.common.EnvironmentVariableMockingUtil) JiraServerGlobalConfigAccessor(com.synopsys.integration.alert.channel.jira.server.database.accessor.JiraServerGlobalConfigAccessor) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) EnvironmentProcessingResult(com.synopsys.integration.alert.environment.EnvironmentProcessingResult) EnvironmentVariableHandlerFactory(com.synopsys.integration.alert.environment.EnvironmentVariableHandlerFactory) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Environment(org.springframework.core.env.Environment) EnvironmentVariableHandler(com.synopsys.integration.alert.environment.EnvironmentVariableHandler) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ChannelKeys(com.synopsys.integration.alert.descriptor.api.model.ChannelKeys) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) AlertConstants(com.synopsys.integration.alert.api.common.model.AlertConstants) EnvironmentVariableHandlerFactory(com.synopsys.integration.alert.environment.EnvironmentVariableHandlerFactory) EnvironmentVariableUtility(com.synopsys.integration.alert.environment.EnvironmentVariableUtility) Environment(org.springframework.core.env.Environment) EnvironmentVariableHandler(com.synopsys.integration.alert.environment.EnvironmentVariableHandler) JiraServerGlobalConfigAccessor(com.synopsys.integration.alert.channel.jira.server.database.accessor.JiraServerGlobalConfigAccessor) EnvironmentProcessingResult(com.synopsys.integration.alert.environment.EnvironmentProcessingResult) Test(org.junit.jupiter.api.Test)

Example 9 with EnvironmentVariableHandler

use of com.synopsys.integration.alert.environment.EnvironmentVariableHandler in project hub-alert by blackducksoftware.

the class ProxySettingsEnvironmentHandlerFactoryTest method testProxySetInEnvironment.

@Test
void testProxySetInEnvironment() {
    Environment environment = Mockito.mock(Environment.class);
    SettingsProxyConfigAccessor configAccessor = Mockito.mock(SettingsProxyConfigAccessor.class);
    Mockito.when(configAccessor.getConfiguration()).thenReturn(Optional.empty());
    Set<String> expectedVariableNames = ProxySettingsEnvironmentHandlerFactory.PROXY_CONFIGURATION_KEYSET;
    String proxyHost = "https://proxyHostUrl";
    String proxyPort = "3128";
    String proxyUsername = "testUser";
    String proxyPassword = "testPassword";
    String nonProxyHosts = "https://nonProxyHostUrl";
    EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, (ignored) -> Boolean.TRUE, ProxySettingsEnvironmentHandlerFactory.PROXY_HOST_KEY, proxyHost);
    EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, (ignored) -> Boolean.TRUE, ProxySettingsEnvironmentHandlerFactory.PROXY_PORT_KEY, proxyPort);
    EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, (ignored) -> Boolean.TRUE, ProxySettingsEnvironmentHandlerFactory.PROXY_USERNAME_KEY, proxyUsername);
    EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, (ignored) -> Boolean.TRUE, ProxySettingsEnvironmentHandlerFactory.PROXY_PASSWORD_KEY, proxyPassword);
    EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, (ignored) -> Boolean.TRUE, ProxySettingsEnvironmentHandlerFactory.PROXY_NON_PROXY_HOSTS_KEY, nonProxyHosts);
    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());
    assertEquals(expectedVariableNames, handler.getVariableNames());
    assertTrue(result.hasValues());
    assertEquals(proxyHost, result.getVariableValue(ProxySettingsEnvironmentHandlerFactory.PROXY_HOST_KEY).orElse("Proxy host value is missing"));
    assertEquals(proxyPort, result.getVariableValue(ProxySettingsEnvironmentHandlerFactory.PROXY_PORT_KEY).orElse("Proxy port value is missing"));
    assertEquals(proxyUsername, result.getVariableValue(ProxySettingsEnvironmentHandlerFactory.PROXY_USERNAME_KEY).orElse("Proxy username value is missing"));
    assertEquals(AlertConstants.MASKED_VALUE, result.getVariableValue(ProxySettingsEnvironmentHandlerFactory.PROXY_PASSWORD_KEY).orElse("Proxy password value is missing"));
    assertEquals(List.of(nonProxyHosts).toString(), result.getVariableValue(ProxySettingsEnvironmentHandlerFactory.PROXY_NON_PROXY_HOSTS_KEY).orElse("Proxy non-proxy hosts value is missing"));
}
Also used : EnvironmentVariableHandlerFactory(com.synopsys.integration.alert.environment.EnvironmentVariableHandlerFactory) EnvironmentVariableUtility(com.synopsys.integration.alert.environment.EnvironmentVariableUtility) Environment(org.springframework.core.env.Environment) SettingsProxyConfigAccessor(com.synopsys.integration.alert.component.settings.proxy.database.accessor.SettingsProxyConfigAccessor) EnvironmentVariableHandler(com.synopsys.integration.alert.environment.EnvironmentVariableHandler) EnvironmentProcessingResult(com.synopsys.integration.alert.environment.EnvironmentProcessingResult) Test(org.junit.jupiter.api.Test)

Example 10 with EnvironmentVariableHandler

use of com.synopsys.integration.alert.environment.EnvironmentVariableHandler in project hub-alert by blackducksoftware.

the class EncryptionSettingsEnvironmentHandlerFactoryTest method testEncryptionSetInEnvironment.

@Test
void testEncryptionSetInEnvironment() {
    Environment environment = Mockito.mock(Environment.class);
    Set<String> variableNames = Set.of(EncryptionSettingsEnvironmentHandlerFactory.ENCRYPTION_PASSWORD_KEY, EncryptionSettingsEnvironmentHandlerFactory.ENCRYPTION_SALT_KEY);
    for (String variableName : variableNames) {
        Mockito.when(environment.containsProperty(variableName)).thenReturn(Boolean.TRUE);
        Mockito.when(environment.getProperty(variableName)).thenReturn("a value");
    }
    EnvironmentVariableUtility environmentVariableUtility = new EnvironmentVariableUtility(environment);
    EnvironmentVariableHandlerFactory factory = new EncryptionSettingsEnvironmentHandlerFactory(environmentVariableUtility);
    EnvironmentVariableHandler handler = factory.build();
    EnvironmentProcessingResult result = handler.updateFromEnvironment();
    assertTrue(result.hasValues());
    assertEquals(AlertConstants.MASKED_VALUE, result.getVariableValue(EncryptionSettingsEnvironmentHandlerFactory.ENCRYPTION_PASSWORD_KEY).orElse("Password value is missing"));
    assertEquals(AlertConstants.MASKED_VALUE, result.getVariableValue(EncryptionSettingsEnvironmentHandlerFactory.ENCRYPTION_SALT_KEY).orElse("Salt value is missing"));
}
Also used : EnvironmentVariableHandlerFactory(com.synopsys.integration.alert.environment.EnvironmentVariableHandlerFactory) EnvironmentVariableUtility(com.synopsys.integration.alert.environment.EnvironmentVariableUtility) Environment(org.springframework.core.env.Environment) EnvironmentVariableHandler(com.synopsys.integration.alert.environment.EnvironmentVariableHandler) EnvironmentProcessingResult(com.synopsys.integration.alert.environment.EnvironmentProcessingResult) Test(org.junit.jupiter.api.Test)

Aggregations

EnvironmentProcessingResult (com.synopsys.integration.alert.environment.EnvironmentProcessingResult)17 EnvironmentVariableHandler (com.synopsys.integration.alert.environment.EnvironmentVariableHandler)17 EnvironmentVariableHandlerFactory (com.synopsys.integration.alert.environment.EnvironmentVariableHandlerFactory)17 EnvironmentVariableUtility (com.synopsys.integration.alert.environment.EnvironmentVariableUtility)17 Test (org.junit.jupiter.api.Test)17 Environment (org.springframework.core.env.Environment)17 AlertConstants (com.synopsys.integration.alert.api.common.model.AlertConstants)5 JiraServerGlobalConfigAccessor (com.synopsys.integration.alert.channel.jira.server.database.accessor.JiraServerGlobalConfigAccessor)5 ChannelKeys (com.synopsys.integration.alert.descriptor.api.model.ChannelKeys)5 EnvironmentVariableMockingUtil (com.synopsys.integration.alert.test.common.EnvironmentVariableMockingUtil)5 Set (java.util.Set)5 Predicate (java.util.function.Predicate)5 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)5 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)5 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)5 Mockito (org.mockito.Mockito)5 EmailGlobalConfigAccessor (com.synopsys.integration.alert.channel.email.database.accessor.EmailGlobalConfigAccessor)4 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)4 EmailGlobalConfigurationValidator (com.synopsys.integration.alert.channel.email.validator.EmailGlobalConfigurationValidator)2 JiraServerEnvironmentVariableHandlerFactory (com.synopsys.integration.alert.channel.jira.server.environment.JiraServerEnvironmentVariableHandlerFactory)2