Search in sources :

Example 36 with PluginDependencyResult

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

the class PluginManagerTest method shouldNotEnablePluginWithUnsatisfiedDependencies.

@Test
public void shouldNotEnablePluginWithUnsatisfiedDependencies() throws Exception {
    // given
    given(plugin.hasState(PluginState.DISABLED)).willReturn(true);
    PluginDependencyResult pluginDependencyResult = PluginDependencyResultImpl.unsatisfiedDependencies(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.UNSATISFIED_DEPENDENCIES, pluginOperationResult.getStatus());
    assertEquals(1, pluginOperationResult.getPluginDependencyResult().getUnsatisfiedDependencies().size());
    assertEquals(1, pluginOperationResult.getPluginDependencyResult().getUnsatisfiedDependencies().size());
    assertTrue(pluginOperationResult.getPluginDependencyResult().getUnsatisfiedDependencies().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)

Example 37 with PluginDependencyResult

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

the class PluginManagerTest method shouldDisableEnabledPlugin.

@Test
public void shouldDisableEnabledPlugin() throws Exception {
    // given
    given(plugin.hasState(PluginState.ENABLED)).willReturn(true);
    PluginDependencyResult pluginDependencyResult = PluginDependencyResultImpl.satisfiedDependencies();
    given(pluginDependencyManager.getDependenciesToDisable(Mockito.eq(singletonList((Plugin) plugin)), Mockito.any(SimplePluginStatusResolver.class))).willReturn(pluginDependencyResult);
    given(pluginDependencyManager.sortPluginsInDependencyOrder(singletonList((Plugin) plugin))).willReturn(singletonList((Plugin) plugin));
    // when
    PluginOperationResult pluginOperationResult = pluginManager.disablePlugin("pluginname");
    // then
    verify(plugin).changeStateTo(PluginState.DISABLED);
    verify(pluginDao).save(plugin);
    verify(pluginAccessor).savePlugin(plugin);
    assertTrue(pluginOperationResult.isSuccess());
    assertEquals(PluginOperationStatus.SUCCESS, 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) Plugin(com.qcadoo.plugin.api.Plugin) InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) Test(org.junit.Test)

Example 38 with PluginDependencyResult

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

the class PluginManagerTest method shouldNotDisablePluginWithEnabledDependencies.

@Test
public void shouldNotDisablePluginWithEnabledDependencies() throws Exception {
    // given
    given(plugin.hasState(PluginState.ENABLED)).willReturn(true);
    PluginDependencyResult pluginDependencyResult = PluginDependencyResultImpl.dependenciesToDisable(Collections.singleton(new PluginDependencyInformation("unknownplugin", new VersionOfDependency(""))));
    given(pluginDependencyManager.getDependenciesToDisable(Mockito.eq(singletonList((Plugin) plugin)), Mockito.any(SimplePluginStatusResolver.class))).willReturn(pluginDependencyResult);
    // when
    PluginOperationResult pluginOperationResult = pluginManager.disablePlugin("pluginname");
    // then
    verify(plugin, never()).changeStateTo(PluginState.DISABLED);
    verify(pluginDao, never()).save(plugin);
    verify(pluginAccessor, never()).savePlugin(plugin);
    assertFalse(pluginOperationResult.isSuccess());
    assertEquals(PluginOperationStatus.DEPENDENCIES_TO_DISABLE, pluginOperationResult.getStatus());
    assertEquals(1, pluginOperationResult.getPluginDependencyResult().getDependenciesToDisable().size());
    assertEquals(1, pluginOperationResult.getPluginDependencyResult().getDependenciesToDisable().size());
    assertTrue(pluginOperationResult.getPluginDependencyResult().getDependenciesToDisable().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)

Example 39 with PluginDependencyResult

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

the class PluginManagerTest method shouldNotUninstallPluginWithEnabledDependencies.

@Test
public void shouldNotUninstallPluginWithEnabledDependencies() throws Exception {
    // given
    PluginDependencyResult pluginDependencyResult = PluginDependencyResultImpl.dependenciesToUninstall(Collections.singleton(new PluginDependencyInformation("unknownplugin", new VersionOfDependency(""))));
    given(pluginDependencyManager.getDependenciesToUninstall(Mockito.eq(singletonList((Plugin) plugin)), Mockito.any(SimplePluginStatusResolver.class))).willReturn(pluginDependencyResult);
    given(plugin.getFilename()).willReturn("filename");
    // when
    PluginOperationResult pluginOperationResult = pluginManager.uninstallPlugin("pluginname");
    // then
    verify(plugin, never()).changeStateTo(PluginState.DISABLED);
    verify(pluginDao, never()).delete(plugin);
    verify(pluginAccessor, never()).removePlugin(plugin);
    verify(pluginFileManager, never()).uninstallPlugin("filename");
    assertFalse(pluginOperationResult.isSuccess());
    assertEquals(PluginOperationStatus.DEPENDENCIES_TO_UNINSTALL, pluginOperationResult.getStatus());
    assertEquals(1, pluginOperationResult.getPluginDependencyResult().getDependenciesToUninstall().size());
    assertTrue(pluginOperationResult.getPluginDependencyResult().getDependenciesToUninstall().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)

Example 40 with PluginDependencyResult

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

the class PluginManagerTest method shouldUninstallTemporaryPlugin.

@Test
public void shouldUninstallTemporaryPlugin() throws Exception {
    // given
    given(plugin.hasState(PluginState.TEMPORARY)).willReturn(true);
    PluginDependencyResult pluginDependencyResult = PluginDependencyResultImpl.satisfiedDependencies();
    given(pluginDependencyManager.getDependenciesToUninstall(Mockito.eq(singletonList((Plugin) plugin)), Mockito.any(SimplePluginStatusResolver.class))).willReturn(pluginDependencyResult);
    given(pluginDependencyManager.sortPluginsInDependencyOrder(singletonList((Plugin) plugin))).willReturn(singletonList((Plugin) plugin));
    given(plugin.getFilename()).willReturn("filename");
    // when
    PluginOperationResult pluginOperationResult = pluginManager.uninstallPlugin("pluginname");
    // then
    verify(plugin, never()).changeStateTo(PluginState.DISABLED);
    verify(pluginDao).delete(plugin);
    verify(pluginAccessor).removePlugin(plugin);
    verify(pluginFileManager).uninstallPlugin("filename");
    assertTrue(pluginOperationResult.isSuccess());
    assertEquals(PluginOperationStatus.SUCCESS, pluginOperationResult.getStatus());
    assertEquals(0, pluginOperationResult.getPluginDependencyResult().getDependenciesToUninstall().size());
}
Also used : PluginDependencyResult(com.qcadoo.plugin.api.PluginDependencyResult) 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