Search in sources :

Example 6 with PluginDependencyResult

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

the class PluginDependencyManagerTest method shouldReturnValidListToDisableWhenUpdate.

@Test
public void shouldReturnValidListToDisableWhenUpdate() throws Exception {
    // given
    Set<Plugin> plugins = new HashSet<Plugin>();
    plugins.add(plugin1);
    plugins.add(plugin2);
    plugins.add(plugin3);
    plugins.add(plugin4);
    given(pluginAccessor.getPlugins()).willReturn(plugins);
    given(plugin2.getRequiredPlugins()).willReturn(Collections.singleton(dependencyInfo1));
    given(plugin2.getState()).willReturn(PluginState.ENABLED);
    given(plugin3.getRequiredPlugins()).willReturn(Collections.singleton(dependencyInfo2));
    given(plugin3.getState()).willReturn(PluginState.DISABLED);
    // when
    PluginDependencyResult result = manager.getDependenciesToUpdate(plugin1, plugin4, pluginStatusResolver);
    // then
    assertEquals(0, result.getDependenciesToEnable().size());
    assertEquals(0, result.getUnsatisfiedDependencies().size());
    assertEquals(1, result.getDependenciesToDisable().size());
    assertEquals(0, result.getDependenciesToDisableUnsatisfiedAfterUpdate().size());
    assertEquals(0, result.getDependenciesToUninstall().size());
    assertTrue(result.getDependenciesToDisable().contains(new PluginDependencyInformation("testPlugin2")));
}
Also used : PluginDependencyResult(com.qcadoo.plugin.api.PluginDependencyResult) PluginDependencyInformation(com.qcadoo.plugin.api.PluginDependencyInformation) Plugin(com.qcadoo.plugin.api.Plugin) InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with PluginDependencyResult

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

the class PluginDependencyManagerTest method shouldCheckDependenciesDependenciesAndReturnMultipleDependenciesForDisableWhenMultiplePlugins.

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

Example 8 with PluginDependencyResult

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

the class PluginDependencyManagerTest method shouldReturnSingleEnabledDependencyForOnePlugin.

@Test
public void shouldReturnSingleEnabledDependencyForOnePlugin() throws Exception {
    // given
    given(plugin2.getRequiredPlugins()).willReturn(Collections.singleton(dependencyInfo1));
    given(plugin2.getState()).willReturn(PluginState.ENABLED);
    Set<Plugin> plugins = new HashSet<Plugin>();
    plugins.add(plugin1);
    plugins.add(plugin2);
    plugins.add(plugin3);
    given(pluginAccessor.getPlugins()).willReturn(plugins);
    // when
    PluginDependencyResult result = manager.getDependenciesToDisable(singletonList((Plugin) plugin1), pluginStatusResolver);
    // then
    assertEquals(0, result.getDependenciesToEnable().size());
    assertEquals(0, result.getUnsatisfiedDependencies().size());
    assertEquals(1, result.getDependenciesToDisable().size());
    assertTrue(result.getDependenciesToDisable().contains(new PluginDependencyInformation("testPlugin2")));
}
Also used : PluginDependencyResult(com.qcadoo.plugin.api.PluginDependencyResult) PluginDependencyInformation(com.qcadoo.plugin.api.PluginDependencyInformation) Plugin(com.qcadoo.plugin.api.Plugin) InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with PluginDependencyResult

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

the class PluginDependencyManagerTest method shouldReturnDisabledDependenciesForMultiplePluginsHardExample.

@Test
public void shouldReturnDisabledDependenciesForMultiplePluginsHardExample() throws Exception {
    // given
    given(plugin1.getRequiredPlugins()).willReturn(Collections.singleton(dependencyInfo2));
    given(plugin2.getRequiredPlugins()).willReturn(Collections.singleton(dependencyInfo3));
    given(plugin3.getRequiredPlugins()).willReturn(Collections.singleton(dependencyInfo4));
    given(plugin2.getState()).willReturn(PluginState.TEMPORARY);
    given(plugin3.getState()).willReturn(PluginState.TEMPORARY);
    given(plugin4.getState()).willReturn(PluginState.TEMPORARY);
    given(pluginAccessor.getPlugin("testPlugin2")).willReturn(plugin2);
    given(pluginAccessor.getPlugin("testPlugin3")).willReturn(plugin3);
    given(pluginAccessor.getPlugin("testPlugin4")).willReturn(plugin4);
    List<Plugin> plugins = new ArrayList<Plugin>();
    plugins.add(plugin1);
    plugins.add(plugin3);
    // when
    PluginDependencyResult result = manager.getDependenciesToEnable(plugins, pluginStatusResolver);
    // then
    assertFalse(result.isCyclic());
    assertEquals(2, result.getDependenciesToEnable().size());
    assertTrue(result.getDependenciesToEnable().contains(new PluginDependencyInformation("testPlugin2")));
    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) Plugin(com.qcadoo.plugin.api.Plugin) InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) Test(org.junit.Test)

Example 10 with PluginDependencyResult

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

the class PluginManagerTest method shouldNotEnablePluginWithDisabledDependencies.

@Test
public void shouldNotEnablePluginWithDisabledDependencies() throws Exception {
    // given
    given(plugin.hasState(PluginState.DISABLED)).willReturn(true);
    PluginDependencyResult pluginDependencyResult = PluginDependencyResultImpl.dependenciesToEnable(Collections.singleton(new PluginDependencyInformation("unknownplugin", new VersionOfDependency(""))));
    given(pluginDependencyManager.getDependenciesToEnable(Mockito.eq(singletonList((Plugin) plugin)), Mockito.any(SimplePluginStatusResolver.class))).willReturn(pluginDependencyResult);
    // when
    PluginOperationResult pluginOperationResult = pluginManager.enablePlugin("pluginname");
    // then
    verify(plugin, never()).changeStateTo(PluginState.ENABLED);
    verify(pluginDao, never()).save(plugin);
    verify(pluginAccessor, never()).savePlugin(plugin);
    assertFalse(pluginOperationResult.isSuccess());
    assertEquals(PluginOperationStatus.DEPENDENCIES_TO_ENABLE, pluginOperationResult.getStatus());
    assertEquals(0, pluginOperationResult.getPluginDependencyResult().getUnsatisfiedDependencies().size());
    assertEquals(1, pluginOperationResult.getPluginDependencyResult().getDependenciesToEnable().size());
    assertEquals(1, pluginOperationResult.getPluginDependencyResult().getDependenciesToEnable().size());
    assertTrue(pluginOperationResult.getPluginDependencyResult().getDependenciesToEnable().contains(new PluginDependencyInformation("unknownplugin", new VersionOfDependency(""))));
}
Also used : PluginDependencyResult(com.qcadoo.plugin.api.PluginDependencyResult) VersionOfDependency(com.qcadoo.plugin.api.VersionOfDependency) PluginOperationResult(com.qcadoo.plugin.api.PluginOperationResult) PluginDependencyInformation(com.qcadoo.plugin.api.PluginDependencyInformation) SimplePluginStatusResolver(com.qcadoo.plugin.internal.dependencymanager.SimplePluginStatusResolver) 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