Search in sources :

Example 91 with ConfigurationModel

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

the class ConfigurationModelConfigurationAccessorTestIT method updateConfigurationMultipleValueTest.

@Test
public void updateConfigurationMultipleValueTest() throws AlertConfigurationException {
    final String initialValue = "initial value";
    ConfigurationFieldModel originalField = ConfigurationFieldModel.create(FIELD_KEY_INSENSITIVE);
    originalField.setFieldValue(initialValue);
    DescriptorKey descriptorKey = createDescriptorKey(DESCRIPTOR_NAME);
    ConfigurationModel createdModel = configurationModelConfigurationAccessor.createConfiguration(descriptorKey, ConfigContextEnum.DISTRIBUTION, Arrays.asList(originalField));
    List<ConfigurationFieldModel> copyOfFieldList = createdModel.getCopyOfFieldList();
    assertEquals(1, copyOfFieldList.size());
    Optional<String> optionalValue = copyOfFieldList.get(0).getFieldValue();
    assertTrue(optionalValue.isPresent());
    assertEquals(initialValue, optionalValue.get());
    final String additionalValue = "additional value";
    ConfigurationFieldModel newFieldWithSameKey = ConfigurationFieldModel.create(FIELD_KEY_INSENSITIVE);
    newFieldWithSameKey.setFieldValue(additionalValue);
    ConfigurationModel updatedModel = configurationModelConfigurationAccessor.updateConfiguration(createdModel.getConfigurationId(), Arrays.asList(originalField, newFieldWithSameKey));
    List<ConfigurationFieldModel> configuredFields = updatedModel.getCopyOfFieldList();
    assertEquals(1, configuredFields.size());
    ConfigurationFieldModel configuredField = configuredFields.get(0);
    assertEquals(originalField, configuredField);
    assertTrue(configuredField.getFieldValues().contains(initialValue));
    assertTrue(configuredField.getFieldValues().contains(additionalValue));
    List<FieldValueEntity> databaseFieldValues = fieldValueRepository.findByConfigId(updatedModel.getConfigurationId());
    assertNotNull(databaseFieldValues);
    assertEquals(2, databaseFieldValues.size());
    assertEquals(configuredField.getFieldValues().size(), databaseFieldValues.size());
}
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) FieldValueEntity(com.synopsys.integration.alert.database.configuration.FieldValueEntity) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 92 with ConfigurationModel

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

the class DefaultDescriptorGlobalConfigUtilityTest method testConfigurationExists.

@Test
public void testConfigurationExists() throws Exception {
    DescriptorKey descriptorKey = createDescriptorKey();
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    DefaultDescriptorGlobalConfigUtility configUtility = new DefaultDescriptorGlobalConfigUtility(descriptorKey, configurationModelConfigurationAccessor, null, null);
    assertFalse(configUtility.doesConfigurationExist());
    ConfigurationModel configurationModel = Mockito.mock(ConfigurationModel.class);
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(Mockito.any(DescriptorKey.class), Mockito.any(ConfigContextEnum.class))).thenReturn(List.of(configurationModel));
    assertTrue(configUtility.doesConfigurationExist());
}
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 93 with ConfigurationModel

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

the class DefaultDescriptorGlobalConfigUtilityTest method testUpdateNoExistingConfig.

@Test
public void testUpdateNoExistingConfig() throws Exception {
    DescriptorKey descriptorKey = createDescriptorKey();
    FieldModel fieldModel = new FieldModel(descriptorKey.getUniversalKey(), ConfigContextEnum.GLOBAL.name(), Map.of());
    Map<String, ConfigurationFieldModel> configurationFieldModelCollection = 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.createConfiguration(Mockito.eq(descriptorKey), Mockito.any(ConfigContextEnum.class), Mockito.anyCollection())).thenReturn(configurationModel);
    Mockito.when(converter.convertToConfigurationFieldModelMap(Mockito.eq(fieldModel))).thenReturn(configurationFieldModelCollection);
    Mockito.when(converter.convertToFieldModel(Mockito.any())).thenReturn(fieldModel);
    Mockito.when(apiAction.beforeUpdateAction(Mockito.eq(fieldModel))).thenReturn(fieldModel);
    Mockito.when(apiAction.afterUpdateAction(Mockito.eq(fieldModel), Mockito.eq(fieldModel))).thenReturn(fieldModel);
    DefaultDescriptorGlobalConfigUtility configUtility = new DefaultDescriptorGlobalConfigUtility(descriptorKey, configurationModelConfigurationAccessor, apiAction, converter);
    FieldModel savedModel = configUtility.update(1L, fieldModel);
    assertEquals(fieldModel, savedModel);
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) 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 94 with ConfigurationModel

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

the class DefaultDescriptorGlobalConfigUtilityTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    DescriptorKey descriptorKey = createDescriptorKey();
    FieldModel fieldModel = new FieldModel(descriptorKey.getUniversalKey(), ConfigContextEnum.GLOBAL.name(), Map.of());
    Map<String, ConfigurationFieldModel> configurationFieldModelCollection = 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.getConfigurationById(Mockito.anyLong())).thenReturn(Optional.of(configurationModel));
    Mockito.when(configurationModelConfigurationAccessor.createConfiguration(Mockito.eq(descriptorKey), Mockito.any(ConfigContextEnum.class), Mockito.anyCollection())).thenReturn(configurationModel);
    Mockito.when(converter.convertToConfigurationFieldModelMap(Mockito.eq(fieldModel))).thenReturn(configurationFieldModelCollection);
    Mockito.when(converter.convertToFieldModel(Mockito.any())).thenReturn(fieldModel);
    Mockito.when(apiAction.beforeUpdateAction(Mockito.eq(fieldModel))).thenReturn(fieldModel);
    Mockito.when(apiAction.afterUpdateAction(Mockito.eq(fieldModel), Mockito.eq(fieldModel))).thenReturn(fieldModel);
    DefaultDescriptorGlobalConfigUtility configUtility = new DefaultDescriptorGlobalConfigUtility(descriptorKey, configurationModelConfigurationAccessor, apiAction, converter);
    FieldModel savedModel = configUtility.update(1L, fieldModel);
    assertEquals(fieldModel, savedModel);
    Mockito.verify(configurationModelConfigurationAccessor).updateConfiguration(Mockito.anyLong(), Mockito.anyCollection());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) 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 95 with ConfigurationModel

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

the class DefaultDescriptorGlobalConfigUtilityTest method testSave.

@Test
public void testSave() throws Exception {
    DescriptorKey descriptorKey = createDescriptorKey();
    FieldModel fieldModel = new FieldModel(descriptorKey.getUniversalKey(), ConfigContextEnum.GLOBAL.name(), Map.of());
    Map<String, ConfigurationFieldModel> configurationFieldModelCollection = 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.createConfiguration(Mockito.eq(descriptorKey), Mockito.any(ConfigContextEnum.class), Mockito.anyCollection())).thenReturn(configurationModel);
    Mockito.when(converter.convertToConfigurationFieldModelMap(Mockito.eq(fieldModel))).thenReturn(configurationFieldModelCollection);
    Mockito.when(converter.convertToFieldModel(Mockito.any())).thenReturn(fieldModel);
    Mockito.when(apiAction.beforeSaveAction(Mockito.eq(fieldModel))).thenReturn(fieldModel);
    Mockito.when(apiAction.afterSaveAction(Mockito.eq(fieldModel))).thenReturn(fieldModel);
    DefaultDescriptorGlobalConfigUtility configUtility = new DefaultDescriptorGlobalConfigUtility(descriptorKey, configurationModelConfigurationAccessor, apiAction, converter);
    FieldModel savedModel = configUtility.save(fieldModel);
    assertEquals(fieldModel, savedModel);
    Mockito.verify(configurationModelConfigurationAccessor).createConfiguration(Mockito.eq(descriptorKey), Mockito.eq(ConfigContextEnum.GLOBAL), Mockito.anyCollection());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) 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)

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