use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.
the class MockConfigurationModelFactory method createSensitiveFieldModel.
public static ConfigurationFieldModel createSensitiveFieldModel(String fieldKey, Collection<String> fieldValues) {
ConfigurationFieldModel configurationFieldModel = ConfigurationFieldModel.createSensitive(fieldKey);
configurationFieldModel.setFieldValues(fieldValues);
return configurationFieldModel;
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.
the class DefaultConfigurationModelConfigurationAccessorTest method createConfigurationTest.
@Test
public void createConfigurationTest() {
final Long descriptorId = 3L;
final Long configurationId = 5L;
DescriptorKey descriptorKey = createDescriptorKey("descriptorKeyName");
ConfigurationFieldModel configurationFieldModel = ConfigurationFieldModel.create("channel.common.name");
configurationFieldModel.setFieldValue(fieldValue);
List<ConfigurationFieldModel> configuredFields = List.of(configurationFieldModel);
RegisteredDescriptorEntity registeredDescriptorEntity = new RegisteredDescriptorEntity("name", 1L);
registeredDescriptorEntity.setId(descriptorId);
ConfigContextEntity configContextEntity = new ConfigContextEntity(configContextEnum.name());
configContextEntity.setId(3L);
DefinedFieldEntity definedFieldEntity = new DefinedFieldEntity(fieldKey, false);
definedFieldEntity.setId(4L);
DescriptorConfigEntity descriptorConfigEntity = new DescriptorConfigEntity(5L, 6L, DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp());
descriptorConfigEntity.setId(configurationId);
Mockito.when(registeredDescriptorRepository.findFirstByName(Mockito.any())).thenReturn(Optional.of(registeredDescriptorEntity));
Mockito.when(configContextRepository.findFirstByContext(Mockito.any())).thenReturn(Optional.of(configContextEntity));
Mockito.when(definedFieldRepository.findByDescriptorIdAndContext(Mockito.any(), Mockito.any())).thenReturn(List.of(definedFieldEntity));
Mockito.when(descriptorConfigRepository.save(Mockito.any())).thenReturn(descriptorConfigEntity);
Mockito.when(definedFieldRepository.findFirstByKey(Mockito.any())).thenReturn(Optional.of(definedFieldEntity));
DefaultConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = new DefaultConfigurationModelConfigurationAccessor(registeredDescriptorRepository, definedFieldRepository, descriptorConfigRepository, configContextRepository, fieldValueRepository, null);
ConfigurationModel configurationModel = configurationModelConfigurationAccessor.createConfiguration(descriptorKey, configContextEnum, configuredFields);
testConfigurationModel(configurationId, descriptorId, configurationModel);
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.
the class DefaultNotificationAccessorTest method createConfigurationModel.
private ConfigurationModelMutable createConfigurationModel() {
ConfigurationModelMutable configurationModel = new ConfigurationModelMutable(1L, 1L, "createdAt-test", "lastUpdate-test", ConfigContextEnum.DISTRIBUTION);
ConfigurationFieldModel configurationFieldModel = ConfigurationFieldModel.create(KEY_PROVIDER_CONFIG_NAME);
configurationFieldModel.setFieldValue(fieldValue);
configurationModel.put(configurationFieldModel);
return configurationModel;
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.
the class DefaultConfigurationModelConfigurationAccessor method createConfigModel.
private ConfigurationModelMutable createConfigModel(Long descriptorId, Long configId, OffsetDateTime createdAt, OffsetDateTime lastUpdated, Long contextId) {
String configContext = getContextById(contextId);
String createdAtFormatted = DateUtils.formatDate(createdAt, DateUtils.UTC_DATE_FORMAT_TO_MINUTE);
String lastUpdatedFormatted = DateUtils.formatDate(lastUpdated, DateUtils.UTC_DATE_FORMAT_TO_MINUTE);
ConfigurationModelMutable newModel = new ConfigurationModelMutable(descriptorId, configId, createdAtFormatted, lastUpdatedFormatted, configContext);
List<FieldValueEntity> fieldValueEntities = fieldValueRepository.findByConfigId(configId);
for (FieldValueEntity fieldValueEntity : fieldValueEntities) {
DefinedFieldEntity definedFieldEntity = definedFieldRepository.findById(fieldValueEntity.getFieldId()).orElseThrow(() -> new AlertRuntimeException("Field Id missing from the database"));
String fieldKey = definedFieldEntity.getKey();
ConfigurationFieldModel fieldModel = BooleanUtils.isTrue(definedFieldEntity.getSensitive()) ? ConfigurationFieldModel.createSensitive(fieldKey) : ConfigurationFieldModel.create(fieldKey);
String decryptedValue = decrypt(fieldValueEntity.getValue(), fieldModel.isSensitive());
fieldModel.setFieldValue(decryptedValue);
newModel.put(fieldModel);
}
return newModel;
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.
the class DefaultConfigurationModelConfigurationAccessorTest method updateConfigurationTest.
@Test
public void updateConfigurationTest() throws Exception {
Long configurationId = 2L;
Long descriptorId = 3L;
ConfigurationFieldModel configurationFieldModel = ConfigurationFieldModel.create("channel.common.name");
configurationFieldModel.setFieldValue(fieldValue);
List<ConfigurationFieldModel> configuredFields = List.of(configurationFieldModel);
DescriptorConfigEntity descriptorConfigEntity = new DescriptorConfigEntity(descriptorId, 4L, DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp());
descriptorConfigEntity.setId(configurationId);
FieldValueEntity fieldValueEntity = new FieldValueEntity(5L, 6L, fieldValue);
ConfigContextEntity configContextEntity = new ConfigContextEntity(configContextEnum.name());
DefinedFieldEntity definedFieldEntity = new DefinedFieldEntity(fieldKey, false);
definedFieldEntity.setId(7L);
Mockito.when(descriptorConfigRepository.findById(Mockito.any())).thenReturn(Optional.of(descriptorConfigEntity));
Mockito.when(fieldValueRepository.findByConfigId(Mockito.any())).thenReturn(List.of(fieldValueEntity));
Mockito.when(configContextRepository.findById(Mockito.any())).thenReturn(Optional.of(configContextEntity));
Mockito.when(definedFieldRepository.findFirstByKey(Mockito.any())).thenReturn(Optional.of(definedFieldEntity));
DefaultConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = new DefaultConfigurationModelConfigurationAccessor(null, definedFieldRepository, descriptorConfigRepository, configContextRepository, fieldValueRepository, null);
ConfigurationModel configurationModel = configurationModelConfigurationAccessor.updateConfiguration(1L, configuredFields);
Mockito.verify(fieldValueRepository).deleteAll(Mockito.any());
Mockito.verify(descriptorConfigRepository).save(Mockito.any());
testConfigurationModel(configurationId, descriptorId, configurationModel);
}
Aggregations