use of com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter in project hub-alert by blackducksoftware.
the class DefaultDescriptorGlobalConfigUtilityTest method testGetFieldModelActionNull.
@Test
public void testGetFieldModelActionNull() throws Exception {
DescriptorKey descriptorKey = createDescriptorKey();
FieldModel fieldModel = new FieldModel(descriptorKey.getUniversalKey(), ConfigContextEnum.GLOBAL.name(), Map.of());
ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
ConfigurationFieldModelConverter converter = Mockito.mock(ConfigurationFieldModelConverter.class);
ConfigurationModel configurationModel = Mockito.mock(ConfigurationModel.class);
ApiAction apiAction = Mockito.mock(ApiAction.class);
Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(Mockito.any(DescriptorKey.class), Mockito.any(ConfigContextEnum.class))).thenReturn(List.of(configurationModel));
Mockito.when(converter.convertToFieldModel(Mockito.any())).thenReturn(fieldModel);
Mockito.when(apiAction.afterGetAction(Mockito.eq(fieldModel))).thenReturn(null);
DefaultDescriptorGlobalConfigUtility configUtility = new DefaultDescriptorGlobalConfigUtility(descriptorKey, configurationModelConfigurationAccessor, apiAction, converter);
Optional<FieldModel> actualFieldModel = configUtility.getFieldModel();
assertFalse(actualFieldModel.isPresent());
}
use of com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter in project hub-alert by blackducksoftware.
the class DefaultDescriptorGlobalConfigUtilityTest method testGetFieldModelEmptyConfiguration.
@Test
public void testGetFieldModelEmptyConfiguration() throws Exception {
DescriptorKey descriptorKey = createDescriptorKey();
ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
ConfigurationFieldModelConverter converter = Mockito.mock(ConfigurationFieldModelConverter.class);
DefaultDescriptorGlobalConfigUtility configUtility = new DefaultDescriptorGlobalConfigUtility(descriptorKey, configurationModelConfigurationAccessor, null, converter);
assertFalse(configUtility.getFieldModel().isPresent());
}
use of com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter in project hub-alert by blackducksoftware.
the class ConfigurationFieldModelTest method convertFromFieldModelTest.
@Test
public void convertFromFieldModelTest() throws Exception {
FieldModel fieldModel = createFieldModel();
List<DefinedFieldModel> configFields = createConfigFields();
EncryptionUtility encryptionUtility = Mockito.mock(EncryptionUtility.class);
Mockito.when(encryptionUtility.isInitialized()).thenReturn(Boolean.TRUE);
DescriptorAccessor descriptorAccessor = new MockDescriptorAccessor(configFields);
List<DescriptorKey> descriptorKeys = createDescriptorKeyList();
ConfigurationFieldModelConverter modelConverter = new ConfigurationFieldModelConverter(encryptionUtility, descriptorAccessor, descriptorKeys);
Map<String, ConfigurationFieldModel> actualModelMap = modelConverter.convertToConfigurationFieldModelMap(fieldModel);
assertTrue(actualModelMap.containsKey(KEY_FIELD_1));
assertTrue(actualModelMap.containsKey(KEY_FIELD_2));
assertEquals(VALUE_FIELD_1, actualModelMap.get(KEY_FIELD_1).getFieldValue().orElse(null));
assertEquals(VALUE_FIELD_2, actualModelMap.get(KEY_FIELD_2).getFieldValue().orElse(null));
}
use of com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter in project hub-alert by blackducksoftware.
the class ConfigurationFieldModelTest method convertDefinedFieldModelWithValuesTest.
@Test
public void convertDefinedFieldModelWithValuesTest() throws Exception {
List<DefinedFieldModel> configFields = createConfigFields();
EncryptionUtility encryptionUtility = Mockito.mock(EncryptionUtility.class);
Mockito.when(encryptionUtility.isInitialized()).thenReturn(true);
DescriptorAccessor descriptorAccessor = new MockDescriptorAccessor(configFields);
List<DescriptorKey> descriptorKeys = createDescriptorKeyList();
ConfigurationFieldModelConverter modelConverter = new ConfigurationFieldModelConverter(encryptionUtility, descriptorAccessor, descriptorKeys);
Optional<ConfigurationFieldModel> optionalModel = modelConverter.convertFromDefinedFieldModel(new DefinedFieldModel(KEY_FIELD_1, ConfigContextEnum.GLOBAL, false), List.of(VALUE_FIELD_1, VALUE_FIELD_2), true);
assertTrue(optionalModel.isPresent());
ConfigurationFieldModel actualModel = optionalModel.get();
assertTrue(actualModel.getFieldValues().containsAll(List.of(VALUE_FIELD_1, VALUE_FIELD_2)));
assertFalse(actualModel.isSensitive());
assertEquals(KEY_FIELD_1, actualModel.getFieldKey());
optionalModel = modelConverter.convertFromDefinedFieldModel(new DefinedFieldModel(KEY_FIELD_1, ConfigContextEnum.GLOBAL, true), List.of(VALUE_FIELD_1, VALUE_FIELD_2), true);
assertTrue(optionalModel.isPresent());
actualModel = optionalModel.get();
assertTrue(actualModel.getFieldValues().containsAll(List.of(VALUE_FIELD_1, VALUE_FIELD_2)));
assertTrue(actualModel.isSensitive());
assertEquals(KEY_FIELD_1, actualModel.getFieldKey());
}
use of com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter in project hub-alert by blackducksoftware.
the class ConfigurationFieldModelTest method convertToFieldAccessorTest.
@Test
public void convertToFieldAccessorTest() throws Exception {
FieldModel fieldModel = createFieldModel();
List<DefinedFieldModel> configFields = createConfigFields();
EncryptionUtility encryptionUtility = Mockito.mock(EncryptionUtility.class);
Mockito.when(encryptionUtility.isInitialized()).thenReturn(true);
DescriptorAccessor descriptorAccessor = new MockDescriptorAccessor(configFields);
List<DescriptorKey> descriptorKeys = createDescriptorKeyList();
ConfigurationFieldModelConverter modelConverter = new ConfigurationFieldModelConverter(encryptionUtility, descriptorAccessor, descriptorKeys);
FieldUtility accessor = modelConverter.convertToFieldAccessor(fieldModel);
assertEquals(VALUE_FIELD_1, accessor.getString(KEY_FIELD_1).orElse(null));
assertEquals(VALUE_FIELD_2, accessor.getString(KEY_FIELD_2).orElse(null));
}
Aggregations