Search in sources :

Example 31 with PluginDependencyResult

use of com.qcadoo.plugin.api.PluginDependencyResult in project qcadoo by qcadoo.

the class PluginDependencyManagerTest method shouldReturnEmptyDependencyToEnableWhenNoDependenciesSpecifiedInOnePlugin.

@Test
public void shouldReturnEmptyDependencyToEnableWhenNoDependenciesSpecifiedInOnePlugin() throws Exception {
    // given
    given(plugin1.getRequiredPlugins()).willReturn(Collections.<PluginDependencyInformation>emptySet());
    // when
    PluginDependencyResult result = manager.getDependenciesToEnable(singletonList((Plugin) plugin1), pluginStatusResolver);
    // then
    assertFalse(result.isCyclic());
    assertEquals(0, result.getDependenciesToEnable().size());
    assertEquals(0, result.getUnsatisfiedDependencies().size());
    assertEquals(0, result.getDependenciesToDisable().size());
}
Also used : PluginDependencyResult(com.qcadoo.plugin.api.PluginDependencyResult) Plugin(com.qcadoo.plugin.api.Plugin) InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) Test(org.junit.Test)

Example 32 with PluginDependencyResult

use of com.qcadoo.plugin.api.PluginDependencyResult in project qcadoo by qcadoo.

the class PluginDependencyManagerTest method shouldReturnDisabledDependenciesForMultiplePlugins.

@Test
public void shouldReturnDisabledDependenciesForMultiplePlugins() throws Exception {
    // given
    Set<PluginDependencyInformation> disabledRequiredPlugins = new HashSet<PluginDependencyInformation>();
    disabledRequiredPlugins.add(dependencyInfo2);
    disabledRequiredPlugins.add(dependencyInfo4);
    given(plugin1.getRequiredPlugins()).willReturn(disabledRequiredPlugins);
    Set<PluginDependencyInformation> disabledRequiredPlugins2 = new HashSet<PluginDependencyInformation>();
    disabledRequiredPlugins2.add(dependencyInfo3);
    given(plugin2.getRequiredPlugins()).willReturn(disabledRequiredPlugins2);
    given(plugin3.getState()).willReturn(PluginState.TEMPORARY);
    given(plugin4.getState()).willReturn(PluginState.TEMPORARY);
    given(pluginAccessor.getPlugin("testPlugin3")).willReturn(plugin3);
    given(pluginAccessor.getPlugin("testPlugin4")).willReturn(plugin4);
    List<Plugin> plugins = new ArrayList<Plugin>();
    plugins.add(plugin1);
    plugins.add(plugin2);
    // when
    PluginDependencyResult result = manager.getDependenciesToEnable(plugins, pluginStatusResolver);
    // then
    assertFalse(result.isCyclic());
    assertEquals(2, result.getDependenciesToEnable().size());
    assertTrue(result.getDependenciesToEnable().contains(new PluginDependencyInformation("testPlugin3")));
    assertTrue(result.getDependenciesToEnable().contains(new PluginDependencyInformation("testPlugin4")));
    assertEquals(0, result.getUnsatisfiedDependencies().size());
    assertEquals(0, result.getDependenciesToDisable().size());
}
Also used : PluginDependencyResult(com.qcadoo.plugin.api.PluginDependencyResult) ArrayList(java.util.ArrayList) PluginDependencyInformation(com.qcadoo.plugin.api.PluginDependencyInformation) HashSet(java.util.HashSet) Plugin(com.qcadoo.plugin.api.Plugin) InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) Test(org.junit.Test)

Example 33 with PluginDependencyResult

use of com.qcadoo.plugin.api.PluginDependencyResult in project qcadoo by qcadoo.

the class PluginDependencyManagerTest method shouldSetCyclicFlagWhenCyclicDependenciesDependencies.

@Test
public void shouldSetCyclicFlagWhenCyclicDependenciesDependencies() throws Exception {
    // given
    Set<PluginDependencyInformation> disabledRequiredPlugins1 = new HashSet<PluginDependencyInformation>();
    disabledRequiredPlugins1.add(dependencyInfo2);
    given(plugin1.getRequiredPlugins()).willReturn(disabledRequiredPlugins1);
    Set<PluginDependencyInformation> disabledRequiredPlugins2 = new HashSet<PluginDependencyInformation>();
    disabledRequiredPlugins2.add(dependencyInfo3);
    given(plugin2.getState()).willReturn(PluginState.DISABLED);
    given(plugin2.getRequiredPlugins()).willReturn(disabledRequiredPlugins2);
    Set<PluginDependencyInformation> disabledRequiredPlugins3 = new HashSet<PluginDependencyInformation>();
    disabledRequiredPlugins3.add(dependencyInfo1);
    given(plugin3.getState()).willReturn(PluginState.TEMPORARY);
    given(plugin3.getRequiredPlugins()).willReturn(disabledRequiredPlugins3);
    given(pluginAccessor.getPlugin("testPlugin1")).willReturn(plugin1);
    given(pluginAccessor.getPlugin("testPlugin2")).willReturn(plugin2);
    given(pluginAccessor.getPlugin("testPlugin3")).willReturn(plugin3);
    given(pluginAccessor.getPlugin("testPlugin4")).willReturn(plugin4);
    // when
    PluginDependencyResult result = manager.getDependenciesToEnable(singletonList((Plugin) plugin1), pluginStatusResolver);
    // then
    assertTrue(result.isCyclic());
    assertEquals(0, result.getDependenciesToEnable().size());
    assertEquals(0, result.getUnsatisfiedDependencies().size());
    assertEquals(0, result.getDependenciesToDisable().size());
}
Also used : PluginDependencyResult(com.qcadoo.plugin.api.PluginDependencyResult) PluginDependencyInformation(com.qcadoo.plugin.api.PluginDependencyInformation) HashSet(java.util.HashSet) Plugin(com.qcadoo.plugin.api.Plugin) InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) Test(org.junit.Test)

Example 34 with PluginDependencyResult

use of com.qcadoo.plugin.api.PluginDependencyResult in project qcadoo by qcadoo.

the class PluginManagerTest method shouldNotDisableSystemPlugin.

@Test
public void shouldNotDisableSystemPlugin() throws Exception {
    // given
    given(plugin.hasState(PluginState.ENABLED)).willReturn(true);
    given(plugin.isSystemPlugin()).willReturn(true);
    given(anotherPlugin.hasState(PluginState.ENABLED)).willReturn(true);
    PluginDependencyResult pluginDependencyResult = PluginDependencyResultImpl.satisfiedDependencies();
    given(pluginDependencyManager.getDependenciesToDisable(Mockito.eq(newArrayList((Plugin) plugin, (Plugin) anotherPlugin)), Mockito.any(SimplePluginStatusResolver.class))).willReturn(pluginDependencyResult);
    // when
    PluginOperationResult pluginOperationResult = pluginManager.disablePlugin("pluginname", "anotherPluginname");
    // then
    verify(plugin, never()).changeStateTo(PluginState.DISABLED);
    verify(anotherPlugin, never()).changeStateTo(PluginState.DISABLED);
    verify(pluginDao, never()).save(plugin);
    verify(pluginAccessor, never()).savePlugin(plugin);
    verify(pluginDao, never()).save(anotherPlugin);
    verify(pluginAccessor, never()).savePlugin(anotherPlugin);
    assertFalse(pluginOperationResult.isSuccess());
    assertEquals(PluginOperationStatus.SYSTEM_PLUGIN_DISABLING, pluginOperationResult.getStatus());
    assertEquals(0, pluginOperationResult.getPluginDependencyResult().getDependenciesToDisable().size());
}
Also used : PluginDependencyResult(com.qcadoo.plugin.api.PluginDependencyResult) PluginOperationResult(com.qcadoo.plugin.api.PluginOperationResult) SimplePluginStatusResolver(com.qcadoo.plugin.internal.dependencymanager.SimplePluginStatusResolver) Test(org.junit.Test)

Example 35 with PluginDependencyResult

use of com.qcadoo.plugin.api.PluginDependencyResult in project qcadoo by qcadoo.

the class PluginManagerTest method shouldDisableMultipleEnabledPlugin.

@Test
public void shouldDisableMultipleEnabledPlugin() throws Exception {
    // given
    given(plugin.hasState(PluginState.ENABLED)).willReturn(true);
    InternalPlugin nextPlugin = mock(InternalPlugin.class, "nextPlugin");
    given(nextPlugin.hasState(PluginState.ENABLED)).willReturn(true);
    given(pluginAccessor.getPlugin("nextPluginname")).willReturn(nextPlugin);
    PluginDependencyResult pluginDependencyResult = PluginDependencyResultImpl.satisfiedDependencies();
    given(pluginDependencyManager.getDependenciesToDisable(Mockito.eq(newArrayList((Plugin) plugin, (Plugin) nextPlugin)), Mockito.any(SimplePluginStatusResolver.class))).willReturn(pluginDependencyResult);
    given(pluginDependencyManager.sortPluginsInDependencyOrder(newArrayList((Plugin) plugin, (Plugin) nextPlugin))).willReturn(newArrayList((Plugin) plugin, (Plugin) nextPlugin));
    // when
    PluginOperationResult pluginOperationResult = pluginManager.disablePlugin("pluginname", "nextPluginname");
    // then
    InOrder inOrder = inOrder(nextPlugin, plugin);
    inOrder.verify(nextPlugin).changeStateTo(PluginState.DISABLED);
    inOrder.verify(plugin).changeStateTo(PluginState.DISABLED);
    verify(pluginDao).save(nextPlugin);
    verify(pluginAccessor).savePlugin(nextPlugin);
    verify(pluginDao).save(plugin);
    verify(pluginAccessor).savePlugin(plugin);
    assertTrue(pluginOperationResult.isSuccess());
    assertEquals(PluginOperationStatus.SUCCESS, pluginOperationResult.getStatus());
    assertEquals(0, pluginOperationResult.getPluginDependencyResult().getDependenciesToDisable().size());
}
Also used : InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) PluginDependencyResult(com.qcadoo.plugin.api.PluginDependencyResult) InOrder(org.mockito.InOrder) PluginOperationResult(com.qcadoo.plugin.api.PluginOperationResult) SimplePluginStatusResolver(com.qcadoo.plugin.internal.dependencymanager.SimplePluginStatusResolver) Plugin(com.qcadoo.plugin.api.Plugin) InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) Test(org.junit.Test)

Aggregations

PluginDependencyResult (com.qcadoo.plugin.api.PluginDependencyResult)46 Test (org.junit.Test)39 Plugin (com.qcadoo.plugin.api.Plugin)38 InternalPlugin (com.qcadoo.plugin.internal.api.InternalPlugin)36 PluginDependencyInformation (com.qcadoo.plugin.api.PluginDependencyInformation)28 HashSet (java.util.HashSet)23 PluginOperationResult (com.qcadoo.plugin.api.PluginOperationResult)15 SimplePluginStatusResolver (com.qcadoo.plugin.internal.dependencymanager.SimplePluginStatusResolver)15 ArrayList (java.util.ArrayList)11 VersionOfDependency (com.qcadoo.plugin.api.VersionOfDependency)7 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)4 QcadooPluginPlugin (com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin)4 InOrder (org.mockito.InOrder)3 Version (com.qcadoo.plugin.api.Version)2 PluginException (com.qcadoo.plugin.internal.PluginException)2 File (java.io.File)1 LinkedList (java.util.LinkedList)1 CycleDetector (org.jgrapht.alg.CycleDetector)1 DefaultDirectedGraph (org.jgrapht.graph.DefaultDirectedGraph)1 DefaultEdge (org.jgrapht.graph.DefaultEdge)1