Search in sources :

Example 86 with ConfigurationModel

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

the class JiraServerGlobalConfigurationModelConverterTest method validConversionMissingOptionalFieldsTest.

@Test
void validConversionMissingOptionalFieldsTest() {
    ConfigurationModel configurationModel = createDefaultConfigurationModel();
    Map<String, ConfigurationFieldModel> fields = configurationModel.getCopyOfKeyToFieldMap();
    fields.remove(JiraServerGlobalConfigurationModelConverter.PASSWORD_KEY);
    fields.remove(JiraServerGlobalConfigurationModelConverter.DISABLE_PLUGIN_CHECK_KEY);
    configurationModel = new ConfigurationModel(1L, 1L, "", "", ConfigContextEnum.GLOBAL, fields);
    JiraServerGlobalConfigurationModelConverter converter = new JiraServerGlobalConfigurationModelConverter();
    Optional<JiraServerGlobalConfigModel> model = converter.convert(configurationModel);
    assertTrue(model.isPresent());
    JiraServerGlobalConfigModel jiraModel = model.get();
    assertNull(jiraModel.getId());
    assertEquals(TEST_URL, jiraModel.getUrl());
    assertEquals(TEST_USERNAME, jiraModel.getUserName());
    assertTrue(jiraModel.getPassword().isEmpty());
    assertTrue(jiraModel.getDisablePluginCheck().isEmpty());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) JiraServerGlobalConfigModel(com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel) Test(org.junit.jupiter.api.Test)

Example 87 with ConfigurationModel

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

the class JiraServerGlobalConfigurationModelConverterTest method createDefaultConfigurationModel.

private ConfigurationModel createDefaultConfigurationModel() {
    Map<String, ConfigurationFieldModel> fieldValuesMap = new HashMap<>();
    ConfigurationFieldModel urlField = ConfigurationFieldModel.create(JiraServerGlobalConfigurationModelConverter.URL_KEY);
    ConfigurationFieldModel userField = ConfigurationFieldModel.create(JiraServerGlobalConfigurationModelConverter.USERNAME_KEY);
    ConfigurationFieldModel passwordField = ConfigurationFieldModel.create(JiraServerGlobalConfigurationModelConverter.PASSWORD_KEY);
    ConfigurationFieldModel disableCheckField = ConfigurationFieldModel.create(JiraServerGlobalConfigurationModelConverter.DISABLE_PLUGIN_CHECK_KEY);
    urlField.setFieldValue(TEST_URL);
    passwordField.setFieldValue(TEST_PASSWORD);
    userField.setFieldValue(TEST_USERNAME);
    disableCheckField.setFieldValue(TEST_DISABLE_PLUGIN_CHECK);
    fieldValuesMap.put(JiraServerGlobalConfigurationModelConverter.URL_KEY, urlField);
    fieldValuesMap.put(JiraServerGlobalConfigurationModelConverter.PASSWORD_KEY, passwordField);
    fieldValuesMap.put(JiraServerGlobalConfigurationModelConverter.USERNAME_KEY, userField);
    fieldValuesMap.put(JiraServerGlobalConfigurationModelConverter.DISABLE_PLUGIN_CHECK_KEY, disableCheckField);
    return new ConfigurationModel(1L, 1L, "", "", ConfigContextEnum.GLOBAL, fieldValuesMap);
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) HashMap(java.util.HashMap)

Example 88 with ConfigurationModel

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

the class ConfigurationModelConfigurationAccessorTestIT method deleteConfigurationTest.

@Test
public void deleteConfigurationTest() {
    DescriptorKey descriptorKey = createDescriptorKey(DESCRIPTOR_NAME);
    ConfigurationModel createdModel1 = configurationModelConfigurationAccessor.createConfiguration(descriptorKey, ConfigContextEnum.DISTRIBUTION, List.of());
    ConfigurationModel createdModel2 = configurationModelConfigurationAccessor.createConfiguration(descriptorKey, ConfigContextEnum.DISTRIBUTION, List.of());
    List<ConfigurationModel> foundModels = configurationModelConfigurationAccessor.getConfigurationsByDescriptorKey(descriptorKey);
    assertEquals(2, foundModels.size());
    configurationModelConfigurationAccessor.deleteConfiguration(createdModel1);
    List<ConfigurationModel> afterFirstDeletion = configurationModelConfigurationAccessor.getConfigurationsByDescriptorKey(descriptorKey);
    assertEquals(foundModels.size() - 1, afterFirstDeletion.size());
    configurationModelConfigurationAccessor.deleteConfiguration(createdModel2);
    List<ConfigurationModel> afterSecondDeletion = configurationModelConfigurationAccessor.getConfigurationsByDescriptorKey(descriptorKey);
    assertEquals(foundModels.size() - 2, afterSecondDeletion.size());
}
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)

Example 89 with ConfigurationModel

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

the class ConfigurationModelConfigurationAccessorTestIT method updateConfigurationReplaceValueTest.

@Test
public void updateConfigurationReplaceValueTest() 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(newFieldWithSameKey));
    List<ConfigurationFieldModel> configuredFields = updatedModel.getCopyOfFieldList();
    assertEquals(1, configuredFields.size());
    ConfigurationFieldModel configuredField = configuredFields.get(0);
    assertEquals(originalField, configuredField);
    assertTrue(configuredField.getFieldValues().contains(additionalValue));
    List<FieldValueEntity> databaseFieldValues = fieldValueRepository.findByConfigId(updatedModel.getConfigurationId());
    assertNotNull(databaseFieldValues);
    assertEquals(1, 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 90 with ConfigurationModel

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

the class ConfigurationModelConfigurationAccessorTestIT method createConfigTest.

@Test
public void createConfigTest() {
    ConfigurationFieldModel configField1 = ConfigurationFieldModel.create(FIELD_KEY_INSENSITIVE);
    ConfigurationFieldModel configField2 = ConfigurationFieldModel.createSensitive(FIELD_KEY_SENSITIVE);
    DescriptorKey descriptorKey = createDescriptorKey(DESCRIPTOR_NAME);
    ConfigurationModel createdConfig = configurationModelConfigurationAccessor.createConfiguration(descriptorKey, ConfigContextEnum.DISTRIBUTION, List.of(configField1, configField2));
    assertTrue(createdConfig.getCopyOfFieldList().contains(configField1));
    assertTrue(createdConfig.getCopyOfFieldList().contains(configField2));
    Optional<DescriptorConfigEntity> configEntityOptional = descriptorConfigsRepository.findById(createdConfig.getConfigurationId());
    assertTrue(configEntityOptional.isPresent());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) DescriptorConfigEntity(com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity) 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