use of com.synopsys.integration.alert.database.configuration.ConfigContextEntity 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);
}
use of com.synopsys.integration.alert.database.configuration.ConfigContextEntity in project hub-alert by blackducksoftware.
the class DefaultConfigurationModelConfigurationAccessorTest method getConfigurationsByDescriptorKeyAndContextTest.
@Test
public void getConfigurationsByDescriptorKeyAndContextTest() {
final Long descriptorId = 3L;
final Long configurationId = 5L;
DescriptorKey descriptorKey = createDescriptorKey("descriptorKeyName");
DescriptorConfigEntity descriptorConfigEntity = new DescriptorConfigEntity(descriptorId, 4L, DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp());
descriptorConfigEntity.setId(configurationId);
ConfigContextEntity configContextEntity = new ConfigContextEntity(configContextEnum.name());
configContextEntity.setId(3L);
RegisteredDescriptorEntity registeredDescriptorEntity = new RegisteredDescriptorEntity("name", 1L);
registeredDescriptorEntity.setId(2L);
FieldValueEntity fieldValueEntity = new FieldValueEntity(6L, 7L, fieldValue);
DefinedFieldEntity definedFieldEntity = new DefinedFieldEntity(fieldKey, false);
definedFieldEntity.setId(8L);
Mockito.when(descriptorConfigRepository.findByDescriptorIdAndContextId(Mockito.any(), Mockito.any())).thenReturn(List.of(descriptorConfigEntity));
Mockito.when(configContextRepository.findFirstByContext(Mockito.any())).thenReturn(Optional.of(configContextEntity));
Mockito.when(configContextRepository.findById(Mockito.any())).thenReturn(Optional.of(configContextEntity));
Mockito.when(registeredDescriptorRepository.findFirstByName(Mockito.any())).thenReturn(Optional.of(registeredDescriptorEntity));
Mockito.when(fieldValueRepository.findByConfigId(Mockito.any())).thenReturn(List.of(fieldValueEntity));
Mockito.when(definedFieldRepository.findById(Mockito.any())).thenReturn(Optional.of(definedFieldEntity));
EncryptionUtility encryptionUtility = createEncryptionUtility();
DefaultConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = new DefaultConfigurationModelConfigurationAccessor(registeredDescriptorRepository, definedFieldRepository, descriptorConfigRepository, configContextRepository, fieldValueRepository, encryptionUtility);
List<ConfigurationModel> configurationModelList = configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(descriptorKey, configContextEnum);
assertEquals(1, configurationModelList.size());
ConfigurationModel configurationModel = configurationModelList.get(0);
testConfigurationModel(configurationId, descriptorId, configurationModel);
}
use of com.synopsys.integration.alert.database.configuration.ConfigContextEntity in project hub-alert by blackducksoftware.
the class DefaultConfigurationModelConfigurationAccessorTest method getConfigurationsByDescriptorTypeTest.
@Test
public void getConfigurationsByDescriptorTypeTest() {
final Long descriptorId = 3L;
final Long configurationId = 5L;
DescriptorType descriptorType = DescriptorType.CHANNEL;
DescriptorTypeEntity descriptorTypeEntity = new DescriptorTypeEntity("CHANNEL");
descriptorTypeEntity.setId(1L);
RegisteredDescriptorEntity registeredDescriptorEntity = new RegisteredDescriptorEntity("name-test", 1L);
registeredDescriptorEntity.setId(2L);
DescriptorConfigEntity descriptorConfigEntity = new DescriptorConfigEntity(descriptorId, 4L, DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp());
descriptorConfigEntity.setId(configurationId);
ConfigContextEntity configContextEntity = new ConfigContextEntity(configContextEnum.name());
FieldValueEntity fieldValueEntity = new FieldValueEntity(6L, 7L, fieldValue);
DefinedFieldEntity definedFieldEntity = new DefinedFieldEntity(fieldKey, false);
definedFieldEntity.setId(8L);
Mockito.when(descriptorConfigRepository.findByDescriptorType(Mockito.eq(descriptorType.name()))).thenReturn(List.of(descriptorConfigEntity));
setupCreatConfigMocks(descriptorConfigEntity, configContextEntity, fieldValueEntity, definedFieldEntity);
DefaultConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = new DefaultConfigurationModelConfigurationAccessor(registeredDescriptorRepository, definedFieldRepository, descriptorConfigRepository, configContextRepository, fieldValueRepository, encryptionUtility);
List<ConfigurationModel> configurationModelList = configurationModelConfigurationAccessor.getConfigurationsByDescriptorType(descriptorType);
assertEquals(1, configurationModelList.size());
ConfigurationModel configurationModel = configurationModelList.get(0);
testConfigurationModel(configurationId, descriptorId, configurationModel);
}
use of com.synopsys.integration.alert.database.configuration.ConfigContextEntity 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.ConfigContextEntity in project hub-alert by blackducksoftware.
the class DefaultDescriptorAccessorTest method getFieldsForDescriptorTest.
@Test
public void getFieldsForDescriptorTest() {
final String name = "name-test";
final Long typeId = 1L;
final ConfigContextEnum configContextEnum = ConfigContextEnum.GLOBAL;
final ConfigContextEnum invalidConfigContextEnum = ConfigContextEnum.DISTRIBUTION;
final String definedFieldsKey = "defined-field-key-test";
Boolean isSensitive = Boolean.TRUE;
RegisteredDescriptorEntity registeredDescriptorEntity = new RegisteredDescriptorEntity(name, typeId);
registeredDescriptorEntity.setId(1L);
DescriptorKey descriptorKey = createDescriptorKey("descriptorKey-test");
ConfigContextEntity configContextEntity = new ConfigContextEntity(configContextEnum.name());
configContextEntity.setId(3L);
DefinedFieldEntity definedFieldEntity = new DefinedFieldEntity(definedFieldsKey, isSensitive);
RegisteredDescriptorRepository registeredDescriptorRepository = Mockito.mock(RegisteredDescriptorRepository.class);
DefinedFieldRepository definedFieldRepository = Mockito.mock(DefinedFieldRepository.class);
ConfigContextRepository configContextRepository = Mockito.mock(ConfigContextRepository.class);
DescriptorTypeRepository descriptorTypeRepository = Mockito.mock(DescriptorTypeRepository.class);
Mockito.when(registeredDescriptorRepository.findFirstByName(descriptorKey.getUniversalKey())).thenReturn(Optional.of(registeredDescriptorEntity));
Mockito.when(configContextRepository.findFirstByContext(configContextEnum.name())).thenReturn(Optional.of(configContextEntity));
// Used to test the optional expression
Mockito.when(configContextRepository.findFirstByContext(invalidConfigContextEnum.name())).thenReturn(Optional.empty());
Mockito.when(configContextRepository.save(Mockito.any())).thenReturn(configContextEntity);
Mockito.when(definedFieldRepository.findByDescriptorIdAndContext(Mockito.any(), Mockito.any())).thenReturn(List.of(definedFieldEntity));
DefaultDescriptorAccessor descriptorAccessor = new DefaultDescriptorAccessor(registeredDescriptorRepository, definedFieldRepository, configContextRepository, descriptorTypeRepository);
List<DefinedFieldModel> definedFieldModelList = descriptorAccessor.getFieldsForDescriptor(descriptorKey, configContextEnum);
List<DefinedFieldModel> emptyConfigContextDefinedFieldModelList = descriptorAccessor.getFieldsForDescriptor(descriptorKey, invalidConfigContextEnum);
assertEquals(1, definedFieldModelList.size());
DefinedFieldModel definedFieldModel = definedFieldModelList.get(0);
assertEquals(definedFieldsKey, definedFieldModel.getKey());
assertEquals(isSensitive, definedFieldModel.getSensitive());
List<ConfigContextEnum> configContextList = new ArrayList<>(definedFieldModel.getContexts());
assertEquals(configContextEnum, configContextList.get(0));
assertEquals(1, emptyConfigContextDefinedFieldModelList.size());
DefinedFieldModel emptyConfigContextDefinedFieldModel = emptyConfigContextDefinedFieldModelList.get(0);
assertEquals(definedFieldsKey, emptyConfigContextDefinedFieldModel.getKey());
assertEquals(isSensitive, emptyConfigContextDefinedFieldModel.getSensitive());
List<ConfigContextEnum> configContextList2 = new ArrayList<>(emptyConfigContextDefinedFieldModel.getContexts());
assertEquals(invalidConfigContextEnum, configContextList2.get(0));
}
Aggregations