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