@Test void testRemoveReferenceAndDeleteConfiguration() { List<Object> idsToRemove = asList("id1", "id2", "id3"); DecoratorConfiguration config = mock(DecoratorConfiguration.class); when(config.getIdValue()).thenReturn("configId"); DecoratorParameters params1 = mock(DecoratorParameters.class); DecoratorParameters params2 = mock(DecoratorParameters.class); when(params1.getId()).thenReturn("id1"); when(params2.getId()).thenReturn("id2"); when(config.getEntities(PARAMETERS, DecoratorParameters.class)) .thenReturn(asList(params1, params2)); DecoratorConfiguration returnedConfig = populator.removeReferencesOrDeleteIfEmpty(idsToRemove, config); verify(dataService).deleteById(DECORATOR_CONFIGURATION, "configId"); assertNull(returnedConfig); }
DecoratorConfiguration removeReferencesOrDeleteIfEmpty( List<Object> decoratorParametersToRemove, DecoratorConfiguration configuration) { List<DecoratorParameters> decoratorParameters = stream( configuration.getEntities(PARAMETERS, DecoratorParameters.class).spliterator(), false) .filter(parameters -> !decoratorParametersToRemove.contains(parameters.getId())) .collect(toList()); if (decoratorParameters.isEmpty()) { dataService.deleteById(DECORATOR_CONFIGURATION, configuration.getIdValue()); return null; } else { configuration.setDecoratorParameters(decoratorParameters.stream()); return configuration; } }
DynamicDecoratorPopulator { DecoratorConfiguration removeReferencesOrDeleteIfEmpty( List<Object> decoratorParametersToRemove, DecoratorConfiguration configuration) { List<DecoratorParameters> decoratorParameters = stream( configuration.getEntities(PARAMETERS, DecoratorParameters.class).spliterator(), false) .filter(parameters -> !decoratorParametersToRemove.contains(parameters.getId())) .collect(toList()); if (decoratorParameters.isEmpty()) { dataService.deleteById(DECORATOR_CONFIGURATION, configuration.getIdValue()); return null; } else { configuration.setDecoratorParameters(decoratorParameters.stream()); return configuration; } } }
DynamicDecoratorPopulator { DecoratorConfiguration removeReferencesOrDeleteIfEmpty( List<Object> decoratorParametersToRemove, DecoratorConfiguration configuration) { List<DecoratorParameters> decoratorParameters = stream( configuration.getEntities(PARAMETERS, DecoratorParameters.class).spliterator(), false) .filter(parameters -> !decoratorParametersToRemove.contains(parameters.getId())) .collect(toList()); if (decoratorParameters.isEmpty()) { dataService.deleteById(DECORATOR_CONFIGURATION, configuration.getIdValue()); return null; } else { configuration.setDecoratorParameters(decoratorParameters.stream()); return configuration; } } DynamicDecoratorPopulator(
      DataService dataService,
      DynamicRepositoryDecoratorRegistry dynamicRepositoryDecoratorRegistry,
      DynamicDecoratorFactory dynamicDecoratorFactory); }
DynamicDecoratorPopulator { DecoratorConfiguration removeReferencesOrDeleteIfEmpty( List<Object> decoratorParametersToRemove, DecoratorConfiguration configuration) { List<DecoratorParameters> decoratorParameters = stream( configuration.getEntities(PARAMETERS, DecoratorParameters.class).spliterator(), false) .filter(parameters -> !decoratorParametersToRemove.contains(parameters.getId())) .collect(toList()); if (decoratorParameters.isEmpty()) { dataService.deleteById(DECORATOR_CONFIGURATION, configuration.getIdValue()); return null; } else { configuration.setDecoratorParameters(decoratorParameters.stream()); return configuration; } } DynamicDecoratorPopulator(
      DataService dataService,
      DynamicRepositoryDecoratorRegistry dynamicRepositoryDecoratorRegistry,
      DynamicDecoratorFactory dynamicDecoratorFactory); void populate(); }
DynamicDecoratorPopulator { DecoratorConfiguration removeReferencesOrDeleteIfEmpty( List<Object> decoratorParametersToRemove, DecoratorConfiguration configuration) { List<DecoratorParameters> decoratorParameters = stream( configuration.getEntities(PARAMETERS, DecoratorParameters.class).spliterator(), false) .filter(parameters -> !decoratorParametersToRemove.contains(parameters.getId())) .collect(toList()); if (decoratorParameters.isEmpty()) { dataService.deleteById(DECORATOR_CONFIGURATION, configuration.getIdValue()); return null; } else { configuration.setDecoratorParameters(decoratorParameters.stream()); return configuration; } } DynamicDecoratorPopulator(
      DataService dataService,
      DynamicRepositoryDecoratorRegistry dynamicRepositoryDecoratorRegistry,
      DynamicDecoratorFactory dynamicDecoratorFactory); void populate();  }