Search in sources :

Example 6 with FieldValueEntity

use of com.synopsys.integration.alert.database.configuration.FieldValueEntity in project hub-alert by blackducksoftware.

the class DefaultConfigurationModelConfigurationAccessorTest method decryptTest.

@Test
public void decryptTest() {
    final String decryptedString = "decryptedString";
    final String providerConfigName = "provider-config-name-test";
    final String emptyProviderConfigName = "bad-config-name";
    final Long fieldId = 1L;
    final Long descriptorId = 4L;
    final Long configurationId = 6L;
    DefinedFieldEntity definedFieldEntity = new DefinedFieldEntity(fieldKey, true);
    definedFieldEntity.setId(fieldId);
    FieldValueEntity fieldValueEntity = new FieldValueEntity(2L, 3L, fieldValue);
    DescriptorConfigEntity descriptorConfigEntity = new DescriptorConfigEntity(descriptorId, 5L, DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp());
    descriptorConfigEntity.setId(configurationId);
    ConfigContextEntity configContextEntity = new ConfigContextEntity(configContextEnum.name());
    EncryptionUtility encryptionUtilityDecrypt = Mockito.mock(EncryptionUtility.class);
    Mockito.when(definedFieldRepository.findFirstByKey(Mockito.any())).thenReturn(Optional.of(definedFieldEntity));
    Mockito.when(fieldValueRepository.findAllByFieldIdAndValue(fieldId, providerConfigName)).thenReturn(List.of(fieldValueEntity));
    Mockito.when(fieldValueRepository.findAllByFieldIdAndValue(fieldId, emptyProviderConfigName)).thenReturn(List.of());
    setupGetJobMocks(descriptorConfigEntity, configContextEntity, fieldValueEntity, definedFieldEntity);
    Mockito.when(encryptionUtilityDecrypt.decrypt(Mockito.any())).thenReturn(decryptedString);
    DefaultConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = new DefaultConfigurationModelConfigurationAccessor(null, definedFieldRepository, descriptorConfigRepository, configContextRepository, fieldValueRepository, encryptionUtilityDecrypt);
    Optional<ConfigurationModel> configurationModelOptional = configurationModelConfigurationAccessor.getProviderConfigurationByName(providerConfigName);
    assertTrue(configurationModelOptional.isPresent());
    ConfigurationModel configurationModel = configurationModelOptional.get();
    testConfigurationModel(configurationId, descriptorId, configurationModel);
    assertEquals(decryptedString, configurationModel.getField(fieldKey).get().getFieldValue().get());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) DescriptorConfigEntity(com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity) DefinedFieldEntity(com.synopsys.integration.alert.database.configuration.DefinedFieldEntity) FieldValueEntity(com.synopsys.integration.alert.database.configuration.FieldValueEntity) ConfigContextEntity(com.synopsys.integration.alert.database.configuration.ConfigContextEntity) EncryptionUtility(com.synopsys.integration.alert.common.security.EncryptionUtility) Test(org.junit.jupiter.api.Test)

Example 7 with FieldValueEntity

use of com.synopsys.integration.alert.database.configuration.FieldValueEntity in project hub-alert by blackducksoftware.

the class DefaultConfigurationModelConfigurationAccessorTest method getProviderConfigurationByNameTest.

@Test
public void getProviderConfigurationByNameTest() {
    final String providerConfigName = "provider-config-name-test";
    final String emptyProviderConfigName = "bad-config-name";
    final Long fieldId = 1L;
    final Long descriptorId = 4L;
    final Long configurationId = 6L;
    DefinedFieldEntity definedFieldEntity = new DefinedFieldEntity(fieldKey, false);
    definedFieldEntity.setId(fieldId);
    FieldValueEntity fieldValueEntity = new FieldValueEntity(2L, 3L, fieldValue);
    DescriptorConfigEntity descriptorConfigEntity = new DescriptorConfigEntity(descriptorId, 5L, DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp());
    descriptorConfigEntity.setId(configurationId);
    ConfigContextEntity configContextEntity = new ConfigContextEntity(configContextEnum.name());
    Mockito.when(definedFieldRepository.findFirstByKey(Mockito.any())).thenReturn(Optional.of(definedFieldEntity));
    Mockito.when(fieldValueRepository.findAllByFieldIdAndValue(fieldId, providerConfigName)).thenReturn(List.of(fieldValueEntity));
    Mockito.when(fieldValueRepository.findAllByFieldIdAndValue(fieldId, emptyProviderConfigName)).thenReturn(List.of());
    setupGetJobMocks(descriptorConfigEntity, configContextEntity, fieldValueEntity, definedFieldEntity);
    DefaultConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = new DefaultConfigurationModelConfigurationAccessor(null, definedFieldRepository, descriptorConfigRepository, configContextRepository, fieldValueRepository, encryptionUtility);
    Optional<ConfigurationModel> configurationModelOptional = configurationModelConfigurationAccessor.getProviderConfigurationByName(providerConfigName);
    Optional<ConfigurationModel> configurationModelProviderConfigsEmpty = configurationModelConfigurationAccessor.getProviderConfigurationByName(emptyProviderConfigName);
    assertTrue(configurationModelOptional.isPresent());
    assertFalse(configurationModelProviderConfigsEmpty.isPresent());
    ConfigurationModel configurationModel = configurationModelOptional.get();
    testConfigurationModel(configurationId, descriptorId, configurationModel);
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) DescriptorConfigEntity(com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity) DefinedFieldEntity(com.synopsys.integration.alert.database.configuration.DefinedFieldEntity) FieldValueEntity(com.synopsys.integration.alert.database.configuration.FieldValueEntity) ConfigContextEntity(com.synopsys.integration.alert.database.configuration.ConfigContextEntity) Test(org.junit.jupiter.api.Test)

Example 8 with FieldValueEntity

use of com.synopsys.integration.alert.database.configuration.FieldValueEntity 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 9 with FieldValueEntity

use of com.synopsys.integration.alert.database.configuration.FieldValueEntity 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 10 with FieldValueEntity

use of com.synopsys.integration.alert.database.configuration.FieldValueEntity in project hub-alert by blackducksoftware.

the class DefaultConfigurationModelConfigurationAccessor method createConfiguration.

private ConfigurationModel createConfiguration(String descriptorKey, ConfigContextEnum context, Collection<ConfigurationFieldModel> configuredFields) {
    Long descriptorId = getDescriptorIdOrThrowException(descriptorKey);
    Long configContextId = getConfigContextIdOrThrowException(context);
    OffsetDateTime currentTime = DateUtils.createCurrentDateTimestamp();
    DescriptorConfigEntity descriptorConfigToSave = new DescriptorConfigEntity(descriptorId, configContextId, currentTime, currentTime);
    DescriptorConfigEntity savedDescriptorConfig = descriptorConfigsRepository.save(descriptorConfigToSave);
    ConfigurationModelMutable createdConfig = createEmptyConfigModel(descriptorId, savedDescriptorConfig.getId(), savedDescriptorConfig.getCreatedAt(), savedDescriptorConfig.getLastUpdated(), context);
    if (configuredFields != null && !configuredFields.isEmpty()) {
        List<FieldValueEntity> fieldValuesToSave = new ArrayList<>(configuredFields.size());
        for (ConfigurationFieldModel configuredField : configuredFields) {
            String fieldKey = configuredField.getFieldKey();
            if (configuredField.isSet()) {
                DefinedFieldEntity associatedField = definedFieldRepository.findFirstByKey(fieldKey).orElseThrow(() -> new AlertRuntimeException(String.format("FATAL: Field with key '%s' did not exist", fieldKey)));
                for (String value : configuredField.getFieldValues()) {
                    FieldValueEntity newFieldValueEntity = new FieldValueEntity(createdConfig.getConfigurationId(), associatedField.getId(), encrypt(value, configuredField.isSensitive()));
                    fieldValuesToSave.add(newFieldValueEntity);
                }
            }
            createdConfig.put(configuredField);
        }
        fieldValueRepository.saveAll(fieldValuesToSave);
    }
    return createdConfig;
}
Also used : ConfigurationModelMutable(com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) OffsetDateTime(java.time.OffsetDateTime) DescriptorConfigEntity(com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity) ArrayList(java.util.ArrayList) DefinedFieldEntity(com.synopsys.integration.alert.database.configuration.DefinedFieldEntity) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) FieldValueEntity(com.synopsys.integration.alert.database.configuration.FieldValueEntity)

Aggregations

FieldValueEntity (com.synopsys.integration.alert.database.configuration.FieldValueEntity)13 DefinedFieldEntity (com.synopsys.integration.alert.database.configuration.DefinedFieldEntity)10 DescriptorConfigEntity (com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity)10 Test (org.junit.jupiter.api.Test)10 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)8 ConfigContextEntity (com.synopsys.integration.alert.database.configuration.ConfigContextEntity)8 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)6 RegisteredDescriptorEntity (com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity)5 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)4 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)4 ConfigurationModelMutable (com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable)3 OffsetDateTime (java.time.OffsetDateTime)3 AlertRuntimeException (com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)2 EncryptionUtility (com.synopsys.integration.alert.common.security.EncryptionUtility)2 DescriptorFieldRelation (com.synopsys.integration.alert.database.configuration.DescriptorFieldRelation)2 ArrayList (java.util.ArrayList)2 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)1 DescriptorType (com.synopsys.integration.alert.common.enumeration.DescriptorType)1 DescriptorTypeEntity (com.synopsys.integration.alert.database.configuration.DescriptorTypeEntity)1