use of com.synopsys.integration.alert.environment.EnvironmentVariableHandlerFactory in project hub-alert by blackducksoftware.
the class EncryptionSettingsEnvironmentHandlerFactoryTest method testEncryptionMissingFromEnvironment.
@Test
void testEncryptionMissingFromEnvironment() {
Environment environment = Mockito.mock(Environment.class);
EnvironmentVariableUtility environmentVariableUtility = new EnvironmentVariableUtility(environment);
Set<String> expectedVariableNames = Set.of(EncryptionSettingsEnvironmentHandlerFactory.ENCRYPTION_PASSWORD_KEY, EncryptionSettingsEnvironmentHandlerFactory.ENCRYPTION_SALT_KEY);
EnvironmentVariableHandlerFactory factory = new EncryptionSettingsEnvironmentHandlerFactory(environmentVariableUtility);
EnvironmentVariableHandler handler = factory.build();
EnvironmentProcessingResult result = handler.updateFromEnvironment();
assertEquals(EncryptionSettingsEnvironmentHandlerFactory.HANDLER_NAME, handler.getName());
assertEquals(expectedVariableNames, handler.getVariableNames());
assertFalse(result.hasValues());
}
use of com.synopsys.integration.alert.environment.EnvironmentVariableHandlerFactory in project hub-alert by blackducksoftware.
the class EmailEnvironmentHandlerFactoryTest method testEmailConfigPresent.
@Test
void testEmailConfigPresent() {
Environment environment = Mockito.mock(Environment.class);
EmailGlobalConfigAccessor configAccessor = Mockito.mock(EmailGlobalConfigAccessor.class);
Mockito.when(configAccessor.doesConfigurationExist()).thenReturn(true);
EnvironmentVariableUtility environmentVariableUtility = new EnvironmentVariableUtility(environment);
EnvironmentVariableHandlerFactory factory = new EmailEnvironmentVariableHandlerFactory(configAccessor, 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.EnvironmentVariableHandlerFactory in project hub-alert by blackducksoftware.
the class EmailEnvironmentHandlerFactoryTest method testEmailSetInEnvironment.
@Test
void testEmailSetInEnvironment() {
Environment environment = Mockito.mock(Environment.class);
EmailGlobalConfigAccessor configAccessor = Mockito.mock(EmailGlobalConfigAccessor.class);
Mockito.when(configAccessor.doesConfigurationExist()).thenReturn(false);
Set<String> expectedVariableNames = Stream.concat(EmailEnvironmentVariableHandlerFactory.EMAIL_CONFIGURATION_KEYSET.stream(), EmailEnvironmentVariableHandlerFactory.OLD_ADDITIONAL_PROPERTY_KEYSET.stream()).collect(Collectors.toSet());
String authRequired = "true";
String from = "noreply@example.com";
String smtpHost = "test.smtp.server.example.com";
String passwordValue = "a test value";
String port = "25";
String username = "testuser";
Predicate<String> hasEnvVarCheck = (variableName) -> !EmailEnvironmentVariableHandlerFactory.OLD_ADDITIONAL_PROPERTY_KEYSET.contains(variableName);
Mockito.when(environment.containsProperty(Mockito.anyString())).thenReturn(Boolean.TRUE);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, hasEnvVarCheck, EmailEnvironmentVariableHandlerFactory.AUTH_REQUIRED_KEY, authRequired);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, hasEnvVarCheck, EmailEnvironmentVariableHandlerFactory.EMAIL_FROM_KEY, from);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, hasEnvVarCheck, EmailEnvironmentVariableHandlerFactory.EMAIL_HOST_KEY, smtpHost);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, hasEnvVarCheck, EmailEnvironmentVariableHandlerFactory.AUTH_PASSWORD_KEY, passwordValue);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, hasEnvVarCheck, EmailEnvironmentVariableHandlerFactory.EMAIL_PORT_KEY, port);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, hasEnvVarCheck, EmailEnvironmentVariableHandlerFactory.AUTH_USER_KEY, username);
EnvironmentVariableUtility environmentVariableUtility = new EnvironmentVariableUtility(environment);
EnvironmentVariableHandlerFactory factory = new EmailEnvironmentVariableHandlerFactory(configAccessor, environmentVariableUtility, validator);
EnvironmentVariableHandler handler = factory.build();
EnvironmentProcessingResult result = handler.updateFromEnvironment();
assertEquals(ChannelKeys.EMAIL.getDisplayName(), handler.getName());
assertEquals(expectedVariableNames, handler.getVariableNames());
assertTrue(result.hasValues());
assertEquals(authRequired, result.getVariableValue(EmailEnvironmentVariableHandlerFactory.AUTH_REQUIRED_KEY).orElse("Auth required value missing"));
assertEquals(from, result.getVariableValue(EmailEnvironmentVariableHandlerFactory.EMAIL_FROM_KEY).orElse("SMTP from value missing"));
assertEquals(smtpHost, result.getVariableValue(EmailEnvironmentVariableHandlerFactory.EMAIL_HOST_KEY).orElse("SMTP host value missing"));
assertEquals(AlertConstants.MASKED_VALUE, result.getVariableValue(EmailEnvironmentVariableHandlerFactory.AUTH_PASSWORD_KEY).orElse("Auth password value missing"));
assertEquals(port, result.getVariableValue(EmailEnvironmentVariableHandlerFactory.EMAIL_PORT_KEY).orElse("SMTP port value missing"));
assertEquals(username, result.getVariableValue(EmailEnvironmentVariableHandlerFactory.AUTH_USER_KEY).orElse("Auth user value missing"));
}
use of com.synopsys.integration.alert.environment.EnvironmentVariableHandlerFactory 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.EnvironmentVariableHandlerFactory 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"));
}
Aggregations