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);
}
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());
}
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());
}
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);
}
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;
}
Aggregations