Search in sources :

Example 21 with PluginOperationResult

use of com.qcadoo.plugin.api.PluginOperationResult 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 22 with PluginOperationResult

use of com.qcadoo.plugin.api.PluginOperationResult 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)

Example 23 with PluginOperationResult

use of com.qcadoo.plugin.api.PluginOperationResult 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 24 with PluginOperationResult

use of com.qcadoo.plugin.api.PluginOperationResult 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 25 with PluginOperationResult

use of com.qcadoo.plugin.api.PluginOperationResult 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)

Aggregations

PluginOperationResult (com.qcadoo.plugin.api.PluginOperationResult)35 Test (org.junit.Test)31 PluginDependencyResult (com.qcadoo.plugin.api.PluginDependencyResult)15 SimplePluginStatusResolver (com.qcadoo.plugin.internal.dependencymanager.SimplePluginStatusResolver)15 InternalPlugin (com.qcadoo.plugin.internal.api.InternalPlugin)9 Plugin (com.qcadoo.plugin.api.Plugin)8 JarPluginArtifact (com.qcadoo.plugin.api.artifact.JarPluginArtifact)7 File (java.io.File)7 PluginDependencyInformation (com.qcadoo.plugin.api.PluginDependencyInformation)4 VersionOfDependency (com.qcadoo.plugin.api.VersionOfDependency)4 Version (com.qcadoo.plugin.api.Version)3 InOrder (org.mockito.InOrder)3