Search in sources :

Example 1 with PluginController

use of org.molgenis.web.PluginController in project molgenis by molgenis.

the class PluginPopulatorTest method testPopulate.

@Test
public void testPopulate() throws Exception {
    PluginController pluginController0 = when(mock(PluginController.class).getId()).thenReturn("newPlugin").getMock();
    PluginController pluginController1 = when(mock(PluginController.class).getId()).thenReturn("changedPlugin").getMock();
    ApplicationContext ctx = mock(ApplicationContext.class);
    when(ctx.getBeansOfType(PluginController.class)).thenReturn(ImmutableMap.of("newPlugin", pluginController0, "changedPlugin", pluginController1));
    Plugin newPlugin = when(mock(Plugin.class).getId()).thenReturn("newPlugin").getMock();
    when(newPlugin.setLabel("newPlugin")).thenReturn(newPlugin);
    Plugin changedPlugin = when(mock(Plugin.class).getId()).thenReturn("changedPlugin").getMock();
    when(changedPlugin.setLabel("changedPlugin")).thenReturn(changedPlugin);
    Plugin existingChangedPlugin = when(mock(Plugin.class).getId()).thenReturn("changedPlugin").getMock();
    when(existingChangedPlugin.setLabel("oldChangedPlugin")).thenReturn(existingChangedPlugin);
    Plugin deletedPlugin = when(mock(Plugin.class).getId()).thenReturn("deletedPlugin").getMock();
    when(deletedPlugin.setLabel("deletedPlugin")).thenReturn(deletedPlugin);
    when(pluginFactory.create("newPlugin")).thenReturn(newPlugin);
    when(pluginFactory.create("changedPlugin")).thenReturn(changedPlugin);
    when(dataService.getRepository(PluginMetadata.PLUGIN, Plugin.class)).thenReturn(pluginRepository);
    when(dataService.findAll(PluginMetadata.PLUGIN, Plugin.class)).thenReturn(Stream.of(existingChangedPlugin, deletedPlugin));
    pluginPopulator.populate(ctx);
    verify(pluginRepository).upsertBatch(updateStreamArgumentCaptor.capture());
    assertEquals(newHashSet(updateStreamArgumentCaptor.getValue()), newHashSet(newPlugin, changedPlugin));
    verify(dataService).delete(eq(PluginMetadata.PLUGIN), deleteStreamArgumentCaptor.capture());
    assertEquals(deleteStreamArgumentCaptor.getValue().collect(toList()), singletonList(deletedPlugin));
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) PluginController(org.molgenis.web.PluginController) Plugin(org.molgenis.data.plugin.model.Plugin) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Aggregations

Plugin (org.molgenis.data.plugin.model.Plugin)1 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)1 PluginController (org.molgenis.web.PluginController)1 ApplicationContext (org.springframework.context.ApplicationContext)1 Test (org.testng.annotations.Test)1