Search in sources :

Example 1 with ConfigurationModel

use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.

the class DefaultDescriptorGlobalConfigUtilityTest method testGetFieldModelActionNull.

@Test
public void testGetFieldModelActionNull() throws Exception {
    DescriptorKey descriptorKey = createDescriptorKey();
    FieldModel fieldModel = new FieldModel(descriptorKey.getUniversalKey(), ConfigContextEnum.GLOBAL.name(), Map.of());
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    ConfigurationFieldModelConverter converter = Mockito.mock(ConfigurationFieldModelConverter.class);
    ConfigurationModel configurationModel = Mockito.mock(ConfigurationModel.class);
    ApiAction apiAction = Mockito.mock(ApiAction.class);
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(Mockito.any(DescriptorKey.class), Mockito.any(ConfigContextEnum.class))).thenReturn(List.of(configurationModel));
    Mockito.when(converter.convertToFieldModel(Mockito.any())).thenReturn(fieldModel);
    Mockito.when(apiAction.afterGetAction(Mockito.eq(fieldModel))).thenReturn(null);
    DefaultDescriptorGlobalConfigUtility configUtility = new DefaultDescriptorGlobalConfigUtility(descriptorKey, configurationModelConfigurationAccessor, apiAction, converter);
    Optional<FieldModel> actualFieldModel = configUtility.getFieldModel();
    assertFalse(actualFieldModel.isPresent());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ApiAction(com.synopsys.integration.alert.common.action.ApiAction) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) ConfigurationFieldModelConverter(com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter) Test(org.junit.jupiter.api.Test)

Example 2 with ConfigurationModel

use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.

the class DefaultDescriptorGlobalConfigUtilityTest method testGetConfiguration.

@Test
public void testGetConfiguration() throws Exception {
    DescriptorKey descriptorKey = createDescriptorKey();
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    DefaultDescriptorGlobalConfigUtility configUtility = new DefaultDescriptorGlobalConfigUtility(descriptorKey, configurationModelConfigurationAccessor, null, null);
    assertFalse(configUtility.getConfiguration().isPresent());
    ConfigurationModel configurationModel = Mockito.mock(ConfigurationModel.class);
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(Mockito.any(DescriptorKey.class), Mockito.any(ConfigContextEnum.class))).thenReturn(List.of(configurationModel));
    assertTrue(configUtility.getConfiguration().isPresent());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) Test(org.junit.jupiter.api.Test)

Example 3 with ConfigurationModel

use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.

the class SAMLContext method disableSAML.

public void disableSAML() {
    try {
        ConfigurationModel configurationModel = getCurrentConfiguration();
        Map<String, ConfigurationFieldModel> fields = configurationModel.getCopyOfKeyToFieldMap();
        ConfigurationFieldModel enabledField = fields.get(AuthenticationDescriptor.KEY_SAML_ENABLED);
        if (null == enabledField) {
            enabledField = ConfigurationFieldModel.create(AuthenticationDescriptor.KEY_SAML_ENABLED);
            fields.put(AuthenticationDescriptor.KEY_SAML_ENABLED, enabledField);
        }
        enabledField.setFieldValue(String.valueOf(false));
        configurationModelConfigurationAccessor.updateConfiguration(configurationModel.getConfigurationId(), fields.values());
    } catch (AlertException ex) {
        logger.error("Error disabling SAML configuration.");
    }
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 4 with ConfigurationModel

use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.

the class ConfigurationModelConfigurationAccessorTestIT method getConfigurationByIdTest.

@Test
public void getConfigurationByIdTest() {
    ConfigurationFieldModel configField1 = ConfigurationFieldModel.create(FIELD_KEY_INSENSITIVE);
    ConfigurationFieldModel configField2 = ConfigurationFieldModel.createSensitive(FIELD_KEY_SENSITIVE);
    DescriptorKey descriptorKey = createDescriptorKey(DESCRIPTOR_NAME);
    ConfigurationModel configurationModel1 = configurationModelConfigurationAccessor.createConfiguration(descriptorKey, ConfigContextEnum.DISTRIBUTION, Arrays.asList(configField1));
    ConfigurationModel configurationModel2 = configurationModelConfigurationAccessor.createConfiguration(descriptorKey, ConfigContextEnum.DISTRIBUTION, Arrays.asList(configField2));
    Optional<ConfigurationModel> optionalFoundConfig1 = configurationModelConfigurationAccessor.getConfigurationById(configurationModel1.getConfigurationId());
    assertTrue(optionalFoundConfig1.isPresent());
    ConfigurationModel foundConfig1 = optionalFoundConfig1.get();
    assertEquals(configurationModel1.getDescriptorId(), foundConfig1.getDescriptorId());
    assertEquals(configurationModel1.getConfigurationId(), foundConfig1.getConfigurationId());
    Optional<ConfigurationModel> optionalFoundConfig2 = configurationModelConfigurationAccessor.getConfigurationById(configurationModel2.getConfigurationId());
    assertTrue(optionalFoundConfig2.isPresent());
    ConfigurationModel foundConfig2 = optionalFoundConfig2.get();
    assertEquals(configurationModel2.getDescriptorId(), foundConfig2.getDescriptorId());
    assertEquals(configurationModel2.getConfigurationId(), foundConfig2.getConfigurationId());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 5 with ConfigurationModel

use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.

the class ConfigurationModelConfigurationAccessorTestIT method configurationModelTest.

@Test
public void configurationModelTest() {
    DescriptorKey descriptorKey = createDescriptorKey(DESCRIPTOR_NAME);
    ConfigurationModel configurationModel = configurationModelConfigurationAccessor.createConfiguration(descriptorKey, ConfigContextEnum.DISTRIBUTION, List.of());
    assertNotNull(configurationModel.getConfigurationId());
    assertNotNull(configurationModel.getDescriptorId());
    assertNotNull(configurationModel.getCopyOfFieldList());
    assertNotNull(configurationModel.getCopyOfKeyToFieldMap());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)140 Test (org.junit.jupiter.api.Test)89 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)49 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)33 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)31 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)22 List (java.util.List)15 AtomicReference (java.util.concurrent.atomic.AtomicReference)14 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)13 DescriptorMap (com.synopsys.integration.alert.common.descriptor.DescriptorMap)13 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)13 HashMap (java.util.HashMap)13 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)11 NotificationContentRepository (com.synopsys.integration.alert.database.notification.NotificationContentRepository)11 NotificationEntity (com.synopsys.integration.alert.database.notification.NotificationEntity)11 DescriptorConfigEntity (com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity)10 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)10 ArrayList (java.util.ArrayList)10 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)9 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)9