@Test public void testUpdate() throws Exception { DescriptorKey descriptorKey = createDescriptorKey(); FieldModel fieldModel = new FieldModel(descriptorKey.getUniversalKey(), ConfigContextEnum.GLOBAL.name(), Map.of()); Map<String, ConfigurationFieldModel> configurationFieldModelCollection = Map.of(); ConfigurationAccessor configurationAccessor = Mockito.mock(ConfigurationAccessor.class); ConfigurationFieldModelConverter converter = Mockito.mock(ConfigurationFieldModelConverter.class); ConfigurationModel configurationModel = Mockito.mock(ConfigurationModel.class); ApiAction apiAction = Mockito.mock(ApiAction.class); Mockito.when(configurationAccessor.getConfigurationById(Mockito.anyLong())).thenReturn(Optional.of(configurationModel)); Mockito.when(configurationAccessor.createConfiguration(Mockito.eq(descriptorKey), Mockito.any(ConfigContextEnum.class), Mockito.anyCollection())).thenReturn(configurationModel); Mockito.when(converter.convertToConfigurationFieldModelMap(Mockito.eq(fieldModel))).thenReturn(configurationFieldModelCollection); Mockito.when(converter.convertToFieldModel(Mockito.any())).thenReturn(fieldModel); Mockito.when(apiAction.beforeUpdateAction(Mockito.eq(fieldModel))).thenReturn(fieldModel); Mockito.when(apiAction.afterUpdateAction(Mockito.eq(fieldModel), Mockito.eq(fieldModel))).thenReturn(fieldModel); DefaultDescriptorGlobalConfigUtility configUtility = new DefaultDescriptorGlobalConfigUtility(descriptorKey, configurationAccessor, apiAction, converter); FieldModel savedModel = configUtility.update(1L, fieldModel); assertEquals(fieldModel, savedModel); Mockito.verify(configurationAccessor).updateConfiguration(Mockito.anyLong(), Mockito.anyCollection()); }
public FieldModel update(Long id, FieldModel fieldModel) throws AlertException { FieldModel beforeUpdateActionFieldModel = apiAction.beforeUpdateAction(fieldModel); Map<String, ConfigurationFieldModel> valueMap = configurationFieldModelConverter.convertToConfigurationFieldModelMap(beforeUpdateActionFieldModel); Optional<ConfigurationModel> existingConfig = configurationAccessor.getConfigurationById(id); ConfigurationModel configurationModel; if (existingConfig.isPresent()) { Map<String, ConfigurationFieldModel> updatedValues = updateSensitiveFields(valueMap, existingConfig.get()); configurationModel = configurationAccessor.updateConfiguration(id, updatedValues.values()); } else { configurationModel = configurationAccessor.createConfiguration(key, context, valueMap.values()); } FieldModel convertedFieldModel = configurationFieldModelConverter.convertToFieldModel(configurationModel); return apiAction.afterUpdateAction(beforeUpdateActionFieldModel, convertedFieldModel); }
DefaultDescriptorGlobalConfigUtility { public FieldModel update(Long id, FieldModel fieldModel) throws AlertException { FieldModel beforeUpdateActionFieldModel = apiAction.beforeUpdateAction(fieldModel); Map<String, ConfigurationFieldModel> valueMap = configurationFieldModelConverter.convertToConfigurationFieldModelMap(beforeUpdateActionFieldModel); Optional<ConfigurationModel> existingConfig = configurationAccessor.getConfigurationById(id); ConfigurationModel configurationModel; if (existingConfig.isPresent()) { Map<String, ConfigurationFieldModel> updatedValues = updateSensitiveFields(valueMap, existingConfig.get()); configurationModel = configurationAccessor.updateConfiguration(id, updatedValues.values()); } else { configurationModel = configurationAccessor.createConfiguration(key, context, valueMap.values()); } FieldModel convertedFieldModel = configurationFieldModelConverter.convertToFieldModel(configurationModel); return apiAction.afterUpdateAction(beforeUpdateActionFieldModel, convertedFieldModel); } }
DefaultDescriptorGlobalConfigUtility { public FieldModel update(Long id, FieldModel fieldModel) throws AlertException { FieldModel beforeUpdateActionFieldModel = apiAction.beforeUpdateAction(fieldModel); Map<String, ConfigurationFieldModel> valueMap = configurationFieldModelConverter.convertToConfigurationFieldModelMap(beforeUpdateActionFieldModel); Optional<ConfigurationModel> existingConfig = configurationAccessor.getConfigurationById(id); ConfigurationModel configurationModel; if (existingConfig.isPresent()) { Map<String, ConfigurationFieldModel> updatedValues = updateSensitiveFields(valueMap, existingConfig.get()); configurationModel = configurationAccessor.updateConfiguration(id, updatedValues.values()); } else { configurationModel = configurationAccessor.createConfiguration(key, context, valueMap.values()); } FieldModel convertedFieldModel = configurationFieldModelConverter.convertToFieldModel(configurationModel); return apiAction.afterUpdateAction(beforeUpdateActionFieldModel, convertedFieldModel); } DefaultDescriptorGlobalConfigUtility(DescriptorKey descriptorKey, ConfigurationAccessor configurationAccessor, ApiAction apiAction,
        ConfigurationFieldModelConverter configurationFieldModelConverter); }
DefaultDescriptorGlobalConfigUtility { public FieldModel update(Long id, FieldModel fieldModel) throws AlertException { FieldModel beforeUpdateActionFieldModel = apiAction.beforeUpdateAction(fieldModel); Map<String, ConfigurationFieldModel> valueMap = configurationFieldModelConverter.convertToConfigurationFieldModelMap(beforeUpdateActionFieldModel); Optional<ConfigurationModel> existingConfig = configurationAccessor.getConfigurationById(id); ConfigurationModel configurationModel; if (existingConfig.isPresent()) { Map<String, ConfigurationFieldModel> updatedValues = updateSensitiveFields(valueMap, existingConfig.get()); configurationModel = configurationAccessor.updateConfiguration(id, updatedValues.values()); } else { configurationModel = configurationAccessor.createConfiguration(key, context, valueMap.values()); } FieldModel convertedFieldModel = configurationFieldModelConverter.convertToFieldModel(configurationModel); return apiAction.afterUpdateAction(beforeUpdateActionFieldModel, convertedFieldModel); } DefaultDescriptorGlobalConfigUtility(DescriptorKey descriptorKey, ConfigurationAccessor configurationAccessor, ApiAction apiAction,
        ConfigurationFieldModelConverter configurationFieldModelConverter); DescriptorKey getKey(); boolean doesConfigurationExist(); Optional<ConfigurationModel> getConfiguration(); Optional<FieldModel> getFieldModel(); FieldModel save(FieldModel fieldModel); FieldModel update(Long id, FieldModel fieldModel); }
DefaultDescriptorGlobalConfigUtility { public FieldModel update(Long id, FieldModel fieldModel) throws AlertException { FieldModel beforeUpdateActionFieldModel = apiAction.beforeUpdateAction(fieldModel); Map<String, ConfigurationFieldModel> valueMap = configurationFieldModelConverter.convertToConfigurationFieldModelMap(beforeUpdateActionFieldModel); Optional<ConfigurationModel> existingConfig = configurationAccessor.getConfigurationById(id); ConfigurationModel configurationModel; if (existingConfig.isPresent()) { Map<String, ConfigurationFieldModel> updatedValues = updateSensitiveFields(valueMap, existingConfig.get()); configurationModel = configurationAccessor.updateConfiguration(id, updatedValues.values()); } else { configurationModel = configurationAccessor.createConfiguration(key, context, valueMap.values()); } FieldModel convertedFieldModel = configurationFieldModelConverter.convertToFieldModel(configurationModel); return apiAction.afterUpdateAction(beforeUpdateActionFieldModel, convertedFieldModel); } DefaultDescriptorGlobalConfigUtility(DescriptorKey descriptorKey, ConfigurationAccessor configurationAccessor, ApiAction apiAction,
        ConfigurationFieldModelConverter configurationFieldModelConverter); DescriptorKey getKey(); boolean doesConfigurationExist(); Optional<ConfigurationModel> getConfiguration(); Optional<FieldModel> getFieldModel(); FieldModel save(FieldModel fieldModel); FieldModel update(Long id, FieldModel fieldModel);  }