Search in sources :

Example 1 with VersionOfDependency

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

the class PluginDependencyManagerTest method shouldReturnValidListToDisableAndDisabeUnsatisfiedWhenUpdateAndDependentPluginIsDisabled.

@Test
public void shouldReturnValidListToDisableAndDisabeUnsatisfiedWhenUpdateAndDependentPluginIsDisabled() 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);
    PluginDependencyInformation dependency = new PluginDependencyInformation("testPlugin1", new VersionOfDependency("[1.0.0,2.0.0]"));
    given(plugin2.getRequiredPlugins()).willReturn(Collections.singleton(dependency));
    given(plugin2.getState()).willReturn(PluginState.DISABLED);
    given(plugin3.getRequiredPlugins()).willReturn(Collections.singleton(dependencyInfo2));
    given(plugin3.getState()).willReturn(PluginState.DISABLED);
    given(plugin1.getVersion()).willReturn(new Version("1.1.0"));
    given(plugin4.getVersion()).willReturn(new Version("2.1.0"));
    // when
    PluginDependencyResult result = manager.getDependenciesToUpdate(plugin1, plugin4, pluginStatusResolver);
    // then
    assertEquals(0, result.getDependenciesToEnable().size());
    assertEquals(0, result.getUnsatisfiedDependencies().size());
    assertEquals(0, result.getDependenciesToDisable().size());
    assertEquals(1, result.getDependenciesToDisableUnsatisfiedAfterUpdate().size());
    assertEquals(0, result.getDependenciesToUninstall().size());
    assertTrue(result.getDependenciesToDisableUnsatisfiedAfterUpdate().contains(new PluginDependencyInformation("testPlugin2")));
}
Also used : PluginDependencyResult(com.qcadoo.plugin.api.PluginDependencyResult) VersionOfDependency(com.qcadoo.plugin.api.VersionOfDependency) Version(com.qcadoo.plugin.api.Version) 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 2 with VersionOfDependency

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

the class PluginDescriptorParserTest method shouldHavePluginDependenciesInformationsForXml1.

@Test
public void shouldHavePluginDependenciesInformationsForXml1() {
    // given
    // when
    Plugin result = parser.parse(xmlFile1);
    // then
    Set<PluginDependencyInformation> dependencies = result.getRequiredPlugins();
    assertEquals(3, dependencies.size());
    assertTrue(dependencies.contains(new PluginDependencyInformation("testPluginDependency1", new VersionOfDependency("(1.2.3,2.3.4]"))));
    assertTrue(dependencies.contains(new PluginDependencyInformation("testPluginDependency2", new VersionOfDependency("1.1.1"))));
    assertTrue(dependencies.contains(new PluginDependencyInformation("testPluginDependency3", new VersionOfDependency(null))));
}
Also used : VersionOfDependency(com.qcadoo.plugin.api.VersionOfDependency) PluginDependencyInformation(com.qcadoo.plugin.api.PluginDependencyInformation) Plugin(com.qcadoo.plugin.api.Plugin) InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) DefaultPlugin(com.qcadoo.plugin.internal.DefaultPlugin) Test(org.junit.Test)

Example 3 with VersionOfDependency

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

Example 4 with VersionOfDependency

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

the class PluginDependencyManagerTest method shouldReturnUnsatisfiedDependenciesForOnePluginWhenNoDependencyPluginFoundOrVersionIsNotMet.

@Test
public void shouldReturnUnsatisfiedDependenciesForOnePluginWhenNoDependencyPluginFoundOrVersionIsNotMet() throws Exception {
    // given
    given(plugin1.getState()).willReturn(PluginState.DISABLED);
    given(plugin1.getIdentifier()).willReturn("testPlugin1");
    given(plugin2.getState()).willReturn(PluginState.TEMPORARY);
    given(plugin2.getIdentifier()).willReturn("testPlugin2");
    given(plugin3.getState()).willReturn(PluginState.TEMPORARY);
    given(plugin3.getIdentifier()).willReturn("testPlugin3");
    given(pluginAccessor.getPlugin("testPlugin1")).willReturn(plugin1);
    given(pluginAccessor.getPlugin("testPlugin2")).willReturn(plugin2);
    given(pluginAccessor.getPlugin("testPlugin3")).willReturn(plugin3);
    given(pluginAccessor.getPlugin("testPlugin4")).willReturn(null);
    dependencyInfo3 = new PluginDependencyInformation("testPlugin3", new VersionOfDependency("[2"));
    InternalPlugin pluginToEnable = mock(InternalPlugin.class);
    Set<PluginDependencyInformation> disabledRequiredPlugins = new HashSet<PluginDependencyInformation>();
    disabledRequiredPlugins.add(dependencyInfo1);
    disabledRequiredPlugins.add(dependencyInfo2);
    disabledRequiredPlugins.add(dependencyInfo3);
    disabledRequiredPlugins.add(dependencyInfo4);
    given(pluginToEnable.getRequiredPlugins()).willReturn(disabledRequiredPlugins);
    given(pluginToEnable.getIdentifier()).willReturn("plugin");
    // when
    PluginDependencyResult result = manager.getDependenciesToEnable(singletonList((Plugin) pluginToEnable), pluginStatusResolver);
    // then
    assertFalse(result.isCyclic());
    assertEquals(0, result.getDependenciesToEnable().size());
    assertEquals(2, result.getUnsatisfiedDependencies().size());
    assertTrue(result.getUnsatisfiedDependencies().contains(new PluginDependencyInformation("testPlugin3", new VersionOfDependency("[2"))));
    assertTrue(result.getUnsatisfiedDependencies().contains(new PluginDependencyInformation("testPlugin4")));
    assertEquals(0, result.getDependenciesToDisable().size());
}
Also used : InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) PluginDependencyResult(com.qcadoo.plugin.api.PluginDependencyResult) VersionOfDependency(com.qcadoo.plugin.api.VersionOfDependency) PluginDependencyInformation(com.qcadoo.plugin.api.PluginDependencyInformation) HashSet(java.util.HashSet) Plugin(com.qcadoo.plugin.api.Plugin) InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) Test(org.junit.Test)

Example 5 with VersionOfDependency

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

the class PluginDependencyManagerTest method shouldReturnValidListToDisableAndDisabeUnsatisfiedWhenUpdate.

@Test
public void shouldReturnValidListToDisableAndDisabeUnsatisfiedWhenUpdate() 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);
    PluginDependencyInformation dependency = new PluginDependencyInformation("testPlugin1", new VersionOfDependency("[1.0.0,2.0.0]"));
    given(plugin2.getRequiredPlugins()).willReturn(Collections.singleton(dependency));
    given(plugin2.getState()).willReturn(PluginState.ENABLED);
    given(plugin3.getRequiredPlugins()).willReturn(Collections.singleton(dependencyInfo2));
    given(plugin3.getState()).willReturn(PluginState.ENABLED);
    given(plugin1.getVersion()).willReturn(new Version("1.1.0"));
    given(plugin4.getVersion()).willReturn(new Version("2.1.0"));
    // when
    PluginDependencyResult result = manager.getDependenciesToUpdate(plugin1, plugin4, pluginStatusResolver);
    // then
    assertEquals(0, result.getDependenciesToEnable().size());
    assertEquals(0, result.getUnsatisfiedDependencies().size());
    assertEquals(2, result.getDependenciesToDisable().size());
    assertEquals(1, result.getDependenciesToDisableUnsatisfiedAfterUpdate().size());
    assertEquals(0, result.getDependenciesToUninstall().size());
    assertTrue(result.getDependenciesToDisable().contains(new PluginDependencyInformation("testPlugin2")));
    assertTrue(result.getDependenciesToDisable().contains(new PluginDependencyInformation("testPlugin3")));
    assertTrue(result.getDependenciesToDisableUnsatisfiedAfterUpdate().contains(new PluginDependencyInformation("testPlugin2")));
}
Also used : PluginDependencyResult(com.qcadoo.plugin.api.PluginDependencyResult) VersionOfDependency(com.qcadoo.plugin.api.VersionOfDependency) Version(com.qcadoo.plugin.api.Version) 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)

Aggregations

VersionOfDependency (com.qcadoo.plugin.api.VersionOfDependency)11 PluginDependencyInformation (com.qcadoo.plugin.api.PluginDependencyInformation)10 Test (org.junit.Test)9 PluginDependencyResult (com.qcadoo.plugin.api.PluginDependencyResult)7 Plugin (com.qcadoo.plugin.api.Plugin)4 PluginOperationResult (com.qcadoo.plugin.api.PluginOperationResult)4 InternalPlugin (com.qcadoo.plugin.internal.api.InternalPlugin)4 SimplePluginStatusResolver (com.qcadoo.plugin.internal.dependencymanager.SimplePluginStatusResolver)4 HashSet (java.util.HashSet)3 Version (com.qcadoo.plugin.api.Version)2 DefaultPlugin (com.qcadoo.plugin.internal.DefaultPlugin)1 Before (org.junit.Before)1