@Test @SuppressWarnings("unchecked") void testPopulateDoNotRemoveExistingAppPlugin() { Plugin deletedPlugin = when(mock(Plugin.class).getId()).thenReturn(DELETED_PLUGIN).getMock(); Plugin existingAppPlugin = when(mock(Plugin.class).getId()).thenReturn(EXISTING_APP_PLUGIN).getMock(); when(dataService.findAll(PluginMetadata.PLUGIN, Plugin.class)) .thenReturn(Stream.of(existingAppPlugin, deletedPlugin)); pluginPopulator.populate(mock(ApplicationContext.class)); verify(pluginRepository, times(0)).upsertBatch(any(List.class)); verify(dataService).delete(eq(PluginMetadata.PLUGIN), deleteStreamArgumentCaptor.capture()); assertEquals( newArrayList(deletedPlugin), deleteStreamArgumentCaptor.getValue().collect(toList())); }
public void populate(ApplicationContext ctx) { Map<String, Plugin> newOrChangedPluginMap = getPlugins(ctx); List<Plugin> deletedPlugins = new ArrayList<>(); Map<String, Plugin> existingPluginMap = dataService .findAll(PLUGIN, Plugin.class) .collect(toMap(Plugin::getId, Function.identity())); existingPluginMap.forEach( (pluginId, plugin) -> { if (newOrChangedPluginMap.get(pluginId) == null && !pluginId.startsWith(APP_PREFIX)) { deletedPlugins.add(plugin); } }); if (!newOrChangedPluginMap.isEmpty()) { dataService .getRepository(PLUGIN, Plugin.class) .upsertBatch(newArrayList(newOrChangedPluginMap.values())); } if (!deletedPlugins.isEmpty()) { dataService.delete(PLUGIN, deletedPlugins.stream()); } }
PluginPopulator { public void populate(ApplicationContext ctx) { Map<String, Plugin> newOrChangedPluginMap = getPlugins(ctx); List<Plugin> deletedPlugins = new ArrayList<>(); Map<String, Plugin> existingPluginMap = dataService .findAll(PLUGIN, Plugin.class) .collect(toMap(Plugin::getId, Function.identity())); existingPluginMap.forEach( (pluginId, plugin) -> { if (newOrChangedPluginMap.get(pluginId) == null && !pluginId.startsWith(APP_PREFIX)) { deletedPlugins.add(plugin); } }); if (!newOrChangedPluginMap.isEmpty()) { dataService .getRepository(PLUGIN, Plugin.class) .upsertBatch(newArrayList(newOrChangedPluginMap.values())); } if (!deletedPlugins.isEmpty()) { dataService.delete(PLUGIN, deletedPlugins.stream()); } } }
PluginPopulator { public void populate(ApplicationContext ctx) { Map<String, Plugin> newOrChangedPluginMap = getPlugins(ctx); List<Plugin> deletedPlugins = new ArrayList<>(); Map<String, Plugin> existingPluginMap = dataService .findAll(PLUGIN, Plugin.class) .collect(toMap(Plugin::getId, Function.identity())); existingPluginMap.forEach( (pluginId, plugin) -> { if (newOrChangedPluginMap.get(pluginId) == null && !pluginId.startsWith(APP_PREFIX)) { deletedPlugins.add(plugin); } }); if (!newOrChangedPluginMap.isEmpty()) { dataService .getRepository(PLUGIN, Plugin.class) .upsertBatch(newArrayList(newOrChangedPluginMap.values())); } if (!deletedPlugins.isEmpty()) { dataService.delete(PLUGIN, deletedPlugins.stream()); } } PluginPopulator(DataService dataService, PluginFactory pluginFactory); }
PluginPopulator { public void populate(ApplicationContext ctx) { Map<String, Plugin> newOrChangedPluginMap = getPlugins(ctx); List<Plugin> deletedPlugins = new ArrayList<>(); Map<String, Plugin> existingPluginMap = dataService .findAll(PLUGIN, Plugin.class) .collect(toMap(Plugin::getId, Function.identity())); existingPluginMap.forEach( (pluginId, plugin) -> { if (newOrChangedPluginMap.get(pluginId) == null && !pluginId.startsWith(APP_PREFIX)) { deletedPlugins.add(plugin); } }); if (!newOrChangedPluginMap.isEmpty()) { dataService .getRepository(PLUGIN, Plugin.class) .upsertBatch(newArrayList(newOrChangedPluginMap.values())); } if (!deletedPlugins.isEmpty()) { dataService.delete(PLUGIN, deletedPlugins.stream()); } } PluginPopulator(DataService dataService, PluginFactory pluginFactory); void populate(ApplicationContext ctx); }
PluginPopulator { public void populate(ApplicationContext ctx) { Map<String, Plugin> newOrChangedPluginMap = getPlugins(ctx); List<Plugin> deletedPlugins = new ArrayList<>(); Map<String, Plugin> existingPluginMap = dataService .findAll(PLUGIN, Plugin.class) .collect(toMap(Plugin::getId, Function.identity())); existingPluginMap.forEach( (pluginId, plugin) -> { if (newOrChangedPluginMap.get(pluginId) == null && !pluginId.startsWith(APP_PREFIX)) { deletedPlugins.add(plugin); } }); if (!newOrChangedPluginMap.isEmpty()) { dataService .getRepository(PLUGIN, Plugin.class) .upsertBatch(newArrayList(newOrChangedPluginMap.values())); } if (!deletedPlugins.isEmpty()) { dataService.delete(PLUGIN, deletedPlugins.stream()); } } PluginPopulator(DataService dataService, PluginFactory pluginFactory); void populate(ApplicationContext ctx); static final String APP_PREFIX; }