Search in sources :

Example 21 with DescriptorMap

use of com.synopsys.integration.alert.common.descriptor.DescriptorMap in project hub-alert by blackducksoftware.

the class AlertStartupInitializerTest method testSetRestModelValueCreate.

@Test
public void testSetRestModelValueCreate() 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);
    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.anyString())).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(4)).getFieldsForDescriptor(Mockito.any(DescriptorKey.class), Mockito.any(ConfigContextEnum.class));
    Mockito.verify(baseConfigurationModelConfigurationAccessor, Mockito.times(2)).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));
}
Also used : FieldModelProcessor(com.synopsys.integration.alert.common.rest.FieldModelProcessor) SettingsUtility(com.synopsys.integration.alert.common.descriptor.accessor.SettingsUtility) EnvironmentVariableProcessor(com.synopsys.integration.alert.environment.EnvironmentVariableProcessor) SettingsDescriptorKey(com.synopsys.integration.alert.component.settings.descriptor.SettingsDescriptorKey) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) DescriptorAccessor(com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) EmailDescriptor(com.synopsys.integration.alert.channel.email.descriptor.EmailDescriptor) ConfigurationFieldModelConverter(com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter) ChannelDescriptor(com.synopsys.integration.alert.common.descriptor.ChannelDescriptor) EncryptionUtility(com.synopsys.integration.alert.common.security.EncryptionUtility) DescriptorMap(com.synopsys.integration.alert.common.descriptor.DescriptorMap) EnvironmentVariableUtility(com.synopsys.integration.alert.environment.EnvironmentVariableUtility) DescriptorProcessor(com.synopsys.integration.alert.common.descriptor.DescriptorProcessor) SettingsDescriptorKey(com.synopsys.integration.alert.component.settings.descriptor.SettingsDescriptorKey) Environment(org.springframework.core.env.Environment) Descriptor(com.synopsys.integration.alert.common.descriptor.Descriptor) ChannelDescriptor(com.synopsys.integration.alert.common.descriptor.ChannelDescriptor) EmailDescriptor(com.synopsys.integration.alert.channel.email.descriptor.EmailDescriptor) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) Test(org.junit.jupiter.api.Test)

Aggregations

DescriptorMap (com.synopsys.integration.alert.common.descriptor.DescriptorMap)21 Test (org.junit.jupiter.api.Test)20 GlobalConfigurationModelToConcreteSaveActions (com.synopsys.integration.alert.common.action.api.GlobalConfigurationModelToConcreteSaveActions)12 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)12 DescriptorProcessor (com.synopsys.integration.alert.common.descriptor.DescriptorProcessor)11 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)11 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)11 DescriptorAccessor (com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor)11 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)11 ConfigurationFieldModelConverter (com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter)11 FieldModelProcessor (com.synopsys.integration.alert.common.rest.FieldModelProcessor)11 Descriptor (com.synopsys.integration.alert.common.descriptor.Descriptor)7 EncryptionUtility (com.synopsys.integration.alert.common.security.EncryptionUtility)7 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)7 PKIXErrorResponseFactory (com.synopsys.integration.alert.component.certificates.web.PKIXErrorResponseFactory)7 SettingsDescriptorKey (com.synopsys.integration.alert.component.settings.descriptor.SettingsDescriptorKey)7 BeforeEach (org.junit.jupiter.api.BeforeEach)7 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)6 ChannelDescriptor (com.synopsys.integration.alert.common.descriptor.ChannelDescriptor)6 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)6