Search in sources :

Example 6 with PluginOperationResult

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

the class PluginManagerTest method shouldNotEnableEnabledPlugin.

@Test
public void shouldNotEnableEnabledPlugin() throws Exception {
    // given
    given(plugin.hasState(PluginState.ENABLED)).willReturn(true);
    // when
    PluginOperationResult pluginOperationResult = pluginManager.enablePlugin("pluginname");
    // then
    verify(plugin, never()).changeStateTo(PluginState.ENABLED);
    verify(pluginDao, never()).save(plugin);
    verify(pluginAccessor, never()).savePlugin(plugin);
    assertTrue(pluginOperationResult.isSuccess());
    assertEquals(PluginOperationStatus.SUCCESS, pluginOperationResult.getStatus());
}
Also used : PluginOperationResult(com.qcadoo.plugin.api.PluginOperationResult) Test(org.junit.Test)

Example 7 with PluginOperationResult

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

the class PluginManagerTest method shouldEnableDisabledPlugin.

@Test
public void shouldEnableDisabledPlugin() throws Exception {
    // given
    PluginDependencyResult pluginDependencyResult = PluginDependencyResultImpl.satisfiedDependencies();
    given(pluginDependencyManager.getDependenciesToEnable(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.enablePlugin("pluginname");
    // then
    verify(plugin).changeStateTo(PluginState.ENABLED);
    verify(pluginDao).save(plugin);
    verify(pluginAccessor).savePlugin(plugin);
    assertTrue(pluginOperationResult.isSuccess());
    assertEquals(PluginOperationStatus.SUCCESS, pluginOperationResult.getStatus());
    assertEquals(0, pluginOperationResult.getPluginDependencyResult().getDependenciesToEnable().size());
    assertEquals(0, pluginOperationResult.getPluginDependencyResult().getUnsatisfiedDependencies().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 8 with PluginOperationResult

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

the class PluginManagerTest method shouldNotUninstallSystemPlugin.

@Test
public void shouldNotUninstallSystemPlugin() throws Exception {
    // given
    given(plugin.hasState(PluginState.TEMPORARY)).willReturn(false);
    given(plugin.isSystemPlugin()).willReturn(true);
    PluginDependencyResult pluginDependencyResult = PluginDependencyResultImpl.satisfiedDependencies();
    given(pluginDependencyManager.getDependenciesToDisable(Mockito.eq(newArrayList((Plugin) plugin)), Mockito.any(SimplePluginStatusResolver.class))).willReturn(pluginDependencyResult);
    // when
    PluginOperationResult pluginOperationResult = pluginManager.uninstallPlugin("pluginname");
    // then
    verify(plugin, never()).changeStateTo(PluginState.DISABLED);
    verify(pluginDao, never()).delete(plugin);
    verify(pluginAccessor, never()).removePlugin(plugin);
    assertFalse(pluginOperationResult.isSuccess());
    assertEquals(PluginOperationStatus.SYSTEM_PLUGIN_UNINSTALLING, 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) Test(org.junit.Test)

Example 9 with PluginOperationResult

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

the class PluginManagerTest method shouldUninstallMultiplePlugins.

@Test
public void shouldUninstallMultiplePlugins() throws Exception {
    // given
    given(plugin.hasState(PluginState.TEMPORARY)).willReturn(false);
    given(plugin.hasState(PluginState.ENABLED)).willReturn(true);
    given(plugin.getFilename()).willReturn("filename");
    given(anotherPlugin.hasState(PluginState.TEMPORARY)).willReturn(true);
    given(anotherPlugin.hasState(PluginState.ENABLED)).willReturn(false);
    given(anotherPlugin.getFilename()).willReturn("anotherFilename");
    InternalPlugin nextPlugin = mock(InternalPlugin.class, "nextPlugin");
    given(nextPlugin.hasState(PluginState.TEMPORARY)).willReturn(false);
    given(nextPlugin.hasState(PluginState.ENABLED)).willReturn(true);
    given(nextPlugin.getFilename()).willReturn("nextPluginFilename");
    given(pluginAccessor.getPlugin("nextPluginname")).willReturn(nextPlugin);
    PluginDependencyResult pluginDependencyResult = PluginDependencyResultImpl.satisfiedDependencies();
    given(pluginDependencyManager.getDependenciesToUninstall(Mockito.eq(newArrayList((Plugin) plugin, (Plugin) anotherPlugin, (Plugin) nextPlugin)), Mockito.any(SimplePluginStatusResolver.class))).willReturn(pluginDependencyResult);
    given(pluginDependencyManager.sortPluginsInDependencyOrder(newArrayList((Plugin) plugin, (Plugin) anotherPlugin, (Plugin) nextPlugin))).willReturn(newArrayList((Plugin) nextPlugin, (Plugin) plugin, (Plugin) anotherPlugin));
    // when
    PluginOperationResult pluginOperationResult = pluginManager.uninstallPlugin("pluginname", "anotherPluginname", "nextPluginname");
    // then
    InOrder inOrder = inOrder(plugin, nextPlugin);
    inOrder.verify(plugin).changeStateTo(PluginState.DISABLED);
    inOrder.verify(nextPlugin).changeStateTo(PluginState.DISABLED);
    verify(anotherPlugin, never()).changeStateTo(PluginState.DISABLED);
    verify(pluginDao).delete(plugin);
    verify(pluginAccessor).removePlugin(plugin);
    verify(pluginDao).delete(nextPlugin);
    verify(pluginAccessor).removePlugin(nextPlugin);
    verify(pluginDao).delete(anotherPlugin);
    verify(pluginAccessor).removePlugin(anotherPlugin);
    verify(pluginFileManager).uninstallPlugin("filename", "anotherFilename", "nextPluginFilename");
    assertTrue(pluginOperationResult.isSuccess());
    assertEquals(PluginOperationStatus.SUCCESS_WITH_RESTART, pluginOperationResult.getStatus());
    assertEquals(0, pluginOperationResult.getPluginDependencyResult().getDependenciesToUninstall().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 10 with PluginOperationResult

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

the class PluginIntegrationTest method shouldUpdateEnabledPlugin.

@Test
public void shouldUpdateEnabledPlugin() throws Exception {
    // given
    JarPluginArtifact artifact = new JarPluginArtifact(new File("src/test/resources/com/qcadoo/plugin/integration/plugin4.jar"));
    JarPluginArtifact artifact2 = new JarPluginArtifact(new File("src/test/resources/com/qcadoo/plugin/integration/plugin4.1.jar"));
    pluginManager.installPlugin(artifact);
    pluginManager.enablePlugin("plugin4");
    ((InternalPlugin) pluginAccessor.getPlugin("plugin4")).changeStateTo(PluginState.ENABLED);
    // when
    PluginOperationResult result = pluginManager.installPlugin(artifact2);
    // then
    assertTrue(result.isSuccess());
    assertTrue(result.isRestartNeccessary());
    assertNotNull(pluginAccessor.getPlugin("plugin4"));
    assertTrue(pluginAccessor.getPlugin("plugin4").hasState(PluginState.ENABLING));
    assertEquals(new Version("1.2.4"), pluginAccessor.getPlugin("plugin4").getVersion());
}
Also used : InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) JarPluginArtifact(com.qcadoo.plugin.api.artifact.JarPluginArtifact) Version(com.qcadoo.plugin.api.Version) PluginOperationResult(com.qcadoo.plugin.api.PluginOperationResult) File(java.io.File) 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