use of com.synopsys.integration.alert.common.rest.FieldModelProcessor in project hub-alert by blackducksoftware.
the class AlertStartupInitializerTest method testInitializeConfigsEmptyInitializerList.
@Test
public void testInitializeConfigsEmptyInitializerList() throws Exception {
Environment environment = Mockito.mock(Environment.class);
DescriptorAccessor baseDescriptorAccessor = Mockito.mock(DescriptorAccessor.class);
ConfigurationModelConfigurationAccessor baseConfigurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
DescriptorMap descriptorMap = new DescriptorMap(List.of(), List.of());
EncryptionUtility encryptionUtility = Mockito.mock(EncryptionUtility.class);
Mockito.when(encryptionUtility.isInitialized()).thenReturn(Boolean.TRUE);
EnvironmentVariableUtility environmentVariableUtility = new EnvironmentVariableUtility(environment);
EnvironmentVariableProcessor environmentVariableProcessor = new EnvironmentVariableProcessor(List.of());
ConfigurationFieldModelConverter modelConverter = new ConfigurationFieldModelConverter(encryptionUtility, baseDescriptorAccessor, List.of());
FieldModelProcessor fieldModelProcessor = new FieldModelProcessor(modelConverter, new DescriptorProcessor(descriptorMap, baseConfigurationModelConfigurationAccessor, List.of()));
SettingsUtility settingsUtility = Mockito.mock(SettingsUtility.class);
Mockito.when(settingsUtility.getKey()).thenReturn(new SettingsDescriptorKey());
AlertStartupInitializer initializer = new AlertStartupInitializer(descriptorMap, environmentVariableUtility, baseDescriptorAccessor, baseConfigurationModelConfigurationAccessor, modelConverter, fieldModelProcessor, settingsUtility, environmentVariableProcessor);
initializer.initializeComponent();
// called to get the settings component configuration and fields.
Mockito.verify(baseDescriptorAccessor, Mockito.times(1)).getFieldsForDescriptor(Mockito.any(DescriptorKey.class), Mockito.any(ConfigContextEnum.class));
Mockito.verify(baseConfigurationModelConfigurationAccessor, Mockito.times(1)).getConfigurationsByDescriptorKeyAndContext(Mockito.any(DescriptorKey.class), Mockito.any(ConfigContextEnum.class));
// nothing should be saved
// Mockito.verify(baseConfigurationAccessor, Mockito.times(1)).createConfiguration(Mockito.anyString(), Mockito.any(ConfigContextEnum.class), Mockito.anyCollection());
}
use of com.synopsys.integration.alert.common.rest.FieldModelProcessor in project hub-alert by blackducksoftware.
the class AlertStartupInitializerTest method testOverwrite.
@Test
public void testOverwrite() throws Exception {
Environment environment = Mockito.mock(Environment.class);
DescriptorAccessor baseDescriptorAccessor = Mockito.mock(DescriptorAccessor.class);
ConfigurationModelConfigurationAccessor baseConfigurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
EncryptionUtility encryptionUtility = Mockito.mock(EncryptionUtility.class);
Mockito.when(encryptionUtility.isInitialized()).thenReturn(Boolean.TRUE);
ChannelDescriptor channelDescriptor = new EmailDescriptor(null, null);
ConfigurationModel settingsModel = Mockito.mock(ConfigurationModel.class);
ConfigurationFieldModel envOverrideField = Mockito.mock(ConfigurationFieldModel.class);
ConfigurationModel slackModel = Mockito.mock(ConfigurationModel.class);
Mockito.when(envOverrideField.getFieldValue()).thenReturn(Optional.of("true"));
Mockito.when(baseConfigurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(SETTINGS_DESCRIPTOR_KEY, ConfigContextEnum.GLOBAL)).thenReturn(List.of(settingsModel));
Mockito.when(baseConfigurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(channelDescriptor.getDescriptorKey(), ConfigContextEnum.GLOBAL)).thenReturn(List.of(slackModel));
List<DescriptorKey> descriptorKeys = List.of(channelDescriptor.getDescriptorKey(), SETTINGS_DESCRIPTOR_KEY);
List<Descriptor> descriptors = List.of(channelDescriptor);
DescriptorMap descriptorMap = new DescriptorMap(descriptorKeys, descriptors);
ConfigurationFieldModelConverter modelConverter = new ConfigurationFieldModelConverter(encryptionUtility, baseDescriptorAccessor, descriptorKeys);
Mockito.when(baseDescriptorAccessor.getFieldsForDescriptor(Mockito.any(DescriptorKey.class), Mockito.any(ConfigContextEnum.class))).thenReturn(List.of());
final String value = "newValue";
Mockito.when(environment.getProperty(Mockito.startsWith("ALERT_CHANNEL_"))).thenReturn(value);
EnvironmentVariableUtility environmentVariableUtility = new EnvironmentVariableUtility(environment);
EnvironmentVariableProcessor environmentVariableProcessor = new EnvironmentVariableProcessor(List.of());
FieldModelProcessor fieldModelProcessor = new FieldModelProcessor(modelConverter, new DescriptorProcessor(descriptorMap, baseConfigurationModelConfigurationAccessor, List.of()));
SettingsUtility settingsUtility = Mockito.mock(SettingsUtility.class);
Mockito.when(settingsUtility.getKey()).thenReturn(new SettingsDescriptorKey());
AlertStartupInitializer initializer = new AlertStartupInitializer(descriptorMap, environmentVariableUtility, baseDescriptorAccessor, baseConfigurationModelConfigurationAccessor, modelConverter, fieldModelProcessor, settingsUtility, environmentVariableProcessor);
initializer.initializeComponent();
Mockito.verify(baseDescriptorAccessor, Mockito.times(2)).getFieldsForDescriptor(Mockito.any(DescriptorKey.class), Mockito.any(ConfigContextEnum.class));
Mockito.verify(baseConfigurationModelConfigurationAccessor, Mockito.times(0)).createConfiguration(Mockito.any(DescriptorKey.class), Mockito.any(ConfigContextEnum.class), Mockito.anyCollection());
Mockito.verify(baseConfigurationModelConfigurationAccessor, Mockito.times(2)).getConfigurationsByDescriptorKeyAndContext(Mockito.any(DescriptorKey.class), Mockito.any(ConfigContextEnum.class));
// Mockito.verify(baseConfigurationAccessor, Mockito.times(2)).updateConfiguration(Mockito.anyLong(), Mockito.anyCollection());
}
use of com.synopsys.integration.alert.common.rest.FieldModelProcessor in project hub-alert by blackducksoftware.
the class AlertStartupInitializerTest method testInitializeConfigs.
// TODO these tests need to be re-written
@Test
public void testInitializeConfigs() {
Environment environment = Mockito.mock(Environment.class);
DescriptorAccessor baseDescriptorAccessor = Mockito.mock(DescriptorAccessor.class);
ConfigurationModelConfigurationAccessor baseConfigurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
EncryptionUtility encryptionUtility = Mockito.mock(EncryptionUtility.class);
Mockito.when(encryptionUtility.isInitialized()).thenReturn(Boolean.TRUE);
ChannelDescriptor channelDescriptor = new EmailDescriptor(null, null);
SettingsDescriptorKey settingsDescriptorKey = new SettingsDescriptorKey();
List<DescriptorKey> descriptorKeys = List.of(channelDescriptor.getDescriptorKey(), settingsDescriptorKey);
List<Descriptor> descriptors = List.of(channelDescriptor);
EnvironmentVariableUtility environmentVariableUtility = new EnvironmentVariableUtility(environment);
EnvironmentVariableProcessor environmentVariableProcessor = new EnvironmentVariableProcessor(List.of());
DescriptorMap descriptorMap = new DescriptorMap(descriptorKeys, descriptors);
ConfigurationFieldModelConverter modelConverter = new ConfigurationFieldModelConverter(encryptionUtility, baseDescriptorAccessor, descriptorKeys);
Mockito.when(baseDescriptorAccessor.getFieldsForDescriptor(Mockito.any(DescriptorKey.class), Mockito.any(ConfigContextEnum.class))).thenReturn(List.of());
FieldModelProcessor fieldModelProcessor = new FieldModelProcessor(modelConverter, new DescriptorProcessor(descriptorMap, baseConfigurationModelConfigurationAccessor, List.of()));
SettingsUtility settingsUtility = Mockito.mock(SettingsUtility.class);
Mockito.when(settingsUtility.getKey()).thenReturn(settingsDescriptorKey);
AlertStartupInitializer initializer = new AlertStartupInitializer(descriptorMap, environmentVariableUtility, baseDescriptorAccessor, baseConfigurationModelConfigurationAccessor, modelConverter, fieldModelProcessor, settingsUtility, environmentVariableProcessor);
initializer.initializeComponent();
Mockito.verify(baseDescriptorAccessor, Mockito.times(4)).getFieldsForDescriptor(Mockito.any(DescriptorKey.class), Mockito.any(ConfigContextEnum.class));
Mockito.verify(baseConfigurationModelConfigurationAccessor, Mockito.times(2)).getConfigurationsByDescriptorKeyAndContext(Mockito.any(DescriptorKey.class), Mockito.any(ConfigContextEnum.class));
}
use of com.synopsys.integration.alert.common.rest.FieldModelProcessor in project hub-alert by blackducksoftware.
the class EmailConfigActionTestIT method updatePasswordEmailGlobalConfigTest.
@Test
void updatePasswordEmailGlobalConfigTest() throws AlertConfigurationException {
AuthorizationManager authorizationManager = createEmailAuthorizationManager();
EmailGlobalCrudActions emailGlobalCrudActions = createEmailCrudActions(authorizationManager);
GlobalConfigurationModelToConcreteConversionService globalConfigurationModelToConcreteConversionService = createConversionService(emailGlobalCrudActions);
ConfigActions configActions = new ConfigActions(authorizationManager, descriptorAccessor, configurationModelConfigurationAccessor, fieldModelProcessor, descriptorProcessor, configurationFieldModelConverter, descriptorMap, pkixErrorResponseFactory, encryptionUtility, settingsDescriptorKey, globalConfigurationModelToConcreteConversionService);
FieldModel fieldModel = createEmailFieldModel();
fieldModel = configActions.create(fieldModel).getContent().orElseThrow(() -> new AlertConfigurationException("Couldn't create configuration"));
String updatedHost = "updated." + TEST_SMTP_HOST;
String updatedPassword = "updatedPassword";
fieldModel.putField(EmailPropertyKeys.JAVAMAIL_HOST_KEY.getPropertyKey(), new FieldValueModel(List.of(updatedHost), false));
fieldModel.putField(EmailPropertyKeys.JAVAMAIL_PASSWORD_KEY.getPropertyKey(), new FieldValueModel(List.of(updatedPassword), false));
configActions.update(Long.valueOf(fieldModel.getId()), fieldModel);
Optional<EmailGlobalConfigModel> staticEmailConfig = emailGlobalConfigAccessor.getConfiguration();
assertTrue(staticEmailConfig.isPresent());
EmailGlobalConfigModel staticModel = staticEmailConfig.get();
assertEquals(Boolean.TRUE, staticModel.getSmtpAuth().orElse(null));
assertEquals(TEST_AUTH_USER, staticModel.getSmtpUsername().orElse(null));
assertEquals(updatedPassword, staticModel.getSmtpPassword().orElse(null));
assertEquals(updatedHost, staticModel.getSmtpHost().orElse(null));
assertEquals(Integer.valueOf(TEST_SMTP_PORT), staticModel.getSmtpPort().orElse(null));
assertEquals(TEST_FROM, staticModel.getSmtpFrom().orElse(null));
String propertyValue = staticModel.getAdditionalJavaMailProperties().map(map -> map.get(EmailPropertyKeys.JAVAMAIL_EHLO_KEY.getPropertyKey())).orElse(null);
assertEquals("true", propertyValue);
}
use of com.synopsys.integration.alert.common.rest.FieldModelProcessor in project hub-alert by blackducksoftware.
the class EmailConfigActionTestIT method updateReadExistingPasswordEmailGlobalConfigTest.
@Test
void updateReadExistingPasswordEmailGlobalConfigTest() throws AlertConfigurationException {
AuthorizationManager authorizationManager = createEmailAuthorizationManager();
EmailGlobalCrudActions emailGlobalCrudActions = createEmailCrudActions(authorizationManager);
GlobalConfigurationModelToConcreteConversionService globalConfigurationModelToConcreteConversionService = createConversionService(emailGlobalCrudActions);
ConfigActions configActions = new ConfigActions(authorizationManager, descriptorAccessor, configurationModelConfigurationAccessor, fieldModelProcessor, descriptorProcessor, configurationFieldModelConverter, descriptorMap, pkixErrorResponseFactory, encryptionUtility, settingsDescriptorKey, globalConfigurationModelToConcreteConversionService);
FieldModel fieldModel = createEmailFieldModel();
fieldModel = configActions.create(fieldModel).getContent().orElseThrow(() -> new AlertConfigurationException("Couldn't create configuration"));
String updatedHost = "updated." + TEST_SMTP_HOST;
fieldModel.putField(EmailPropertyKeys.JAVAMAIL_HOST_KEY.getPropertyKey(), new FieldValueModel(List.of(updatedHost), false));
configActions.update(Long.valueOf(fieldModel.getId()), fieldModel);
Optional<EmailGlobalConfigModel> staticEmailConfig = emailGlobalConfigAccessor.getConfiguration();
assertTrue(staticEmailConfig.isPresent());
EmailGlobalConfigModel staticModel = staticEmailConfig.get();
assertEquals(Boolean.TRUE, staticModel.getSmtpAuth().orElse(null));
assertEquals(TEST_AUTH_USER, staticModel.getSmtpUsername().orElse(null));
assertEquals(TEST_AUTH_PASSWORD, staticModel.getSmtpPassword().orElse(null));
assertEquals(updatedHost, staticModel.getSmtpHost().orElse(null));
assertEquals(Integer.valueOf(TEST_SMTP_PORT), staticModel.getSmtpPort().orElse(null));
assertEquals(TEST_FROM, staticModel.getSmtpFrom().orElse(null));
String propertyValue = staticModel.getAdditionalJavaMailProperties().map(map -> map.get(EmailPropertyKeys.JAVAMAIL_EHLO_KEY.getPropertyKey())).orElse(null);
assertEquals("true", propertyValue);
}
Aggregations