Search in sources :

Example 11 with DescriptorConfigEntity

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

use of com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity 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)

Example 13 with DescriptorConfigEntity

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

the class DescriptorConfigRepositoryTestIT method findByDescriptorIdTest.

@Test
public void findByDescriptorIdTest() {
    RegisteredDescriptorEntity descriptorEntity1 = new RegisteredDescriptorEntity(DESCRIPTOR_NAME, 1L);
    RegisteredDescriptorEntity descriptorEntity2 = new RegisteredDescriptorEntity(DESCRIPTOR_NAME + "Alt", 1L);
    RegisteredDescriptorEntity savedDescriptorEntity1 = registeredDescriptorRepository.save(descriptorEntity1);
    RegisteredDescriptorEntity savedDescriptorEntity2 = registeredDescriptorRepository.save(descriptorEntity2);
    ConfigContextEntity configContextEntity = new ConfigContextEntity(CONTEXT_NAME);
    ConfigContextEntity savedContextEntity = configContextRepository.save(configContextEntity);
    OffsetDateTime currentTime = DateUtils.createCurrentDateTimestamp();
    DescriptorConfigEntity descriptorConfigEntity1 = new DescriptorConfigEntity(savedDescriptorEntity1.getId(), savedContextEntity.getId(), currentTime, currentTime);
    DescriptorConfigEntity descriptorConfigEntity2 = new DescriptorConfigEntity(savedDescriptorEntity1.getId(), savedContextEntity.getId(), currentTime, currentTime);
    DescriptorConfigEntity descriptorConfigEntity3 = new DescriptorConfigEntity(savedDescriptorEntity2.getId(), savedContextEntity.getId(), currentTime, currentTime);
    descriptorConfigRepository.save(descriptorConfigEntity1);
    descriptorConfigRepository.save(descriptorConfigEntity2);
    descriptorConfigRepository.save(descriptorConfigEntity3);
    List<DescriptorConfigEntity> descriptorConfig1List = descriptorConfigRepository.findByDescriptorId(savedDescriptorEntity1.getId());
    assertEquals(2, descriptorConfig1List.size());
    List<DescriptorConfigEntity> descriptorConfig2List = descriptorConfigRepository.findByDescriptorId(savedDescriptorEntity2.getId());
    assertEquals(1, descriptorConfig2List.size());
}
Also used : OffsetDateTime(java.time.OffsetDateTime) DescriptorConfigEntity(com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity) RegisteredDescriptorEntity(com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity) ConfigContextEntity(com.synopsys.integration.alert.database.configuration.ConfigContextEntity) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 14 with DescriptorConfigEntity

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

the class NotificationContentRepositoryTestIT method createProviderConfig.

private DescriptorConfigEntity createProviderConfig() {
    RegisteredDescriptorEntity providerDescriptor = registeredDescriptorRepository.findFirstByName(BLACK_DUCK_PROVIDER_KEY.getUniversalKey()).orElseThrow();
    ConfigContextEntity context = configContextRepository.findFirstByContext(ConfigContextEnum.GLOBAL.name()).orElseThrow();
    DescriptorConfigEntity providerConfigToSave = new DescriptorConfigEntity(providerDescriptor.getId(), context.getId(), OffsetDateTime.now(), OffsetDateTime.now());
    return descriptorConfigRepository.save(providerConfigToSave);
}
Also used : DescriptorConfigEntity(com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity) RegisteredDescriptorEntity(com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity) ConfigContextEntity(com.synopsys.integration.alert.database.configuration.ConfigContextEntity)

Example 15 with DescriptorConfigEntity

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

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