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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations