Search in sources :

Example 1 with Plugin

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

the class PluginDependencyManagerTest method shouldSetCyclicFlagWhenCyclicDependenciesDependenciesButNotDependencyToArgument.

// 
@Test
public void shouldSetCyclicFlagWhenCyclicDependenciesDependenciesButNotDependencyToArgument() throws Exception {
    // given
    Set<PluginDependencyInformation> disabledRequiredPlugins1 = new HashSet<PluginDependencyInformation>();
    disabledRequiredPlugins1.add(dependencyInfo2);
    given(plugin1.getRequiredPlugins()).willReturn(disabledRequiredPlugins1);
    Set<PluginDependencyInformation> disabledRequiredPlugins2 = new HashSet<PluginDependencyInformation>();
    disabledRequiredPlugins2.add(dependencyInfo3);
    given(plugin2.getState()).willReturn(PluginState.DISABLED);
    given(plugin2.getRequiredPlugins()).willReturn(disabledRequiredPlugins2);
    Set<PluginDependencyInformation> disabledRequiredPlugins3 = new HashSet<PluginDependencyInformation>();
    disabledRequiredPlugins3.add(dependencyInfo2);
    given(plugin3.getState()).willReturn(PluginState.TEMPORARY);
    given(plugin3.getRequiredPlugins()).willReturn(disabledRequiredPlugins3);
    given(pluginAccessor.getPlugin("testPlugin2")).willReturn(plugin2);
    given(pluginAccessor.getPlugin("testPlugin3")).willReturn(plugin3);
    // when
    PluginDependencyResult result = manager.getDependenciesToEnable(singletonList((Plugin) plugin1), pluginStatusResolver);
    // then
    assertTrue(result.isCyclic());
    assertEquals(0, result.getDependenciesToEnable().size());
    assertEquals(0, result.getUnsatisfiedDependencies().size());
    assertEquals(0, result.getDependenciesToDisable().size());
}
Also used : PluginDependencyResult(com.qcadoo.plugin.api.PluginDependencyResult) 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 2 with Plugin

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

the class PluginDependencyManagerTest method shouldReturnEnabledDependenciesForMultiplePlugins.

@Test
public void shouldReturnEnabledDependenciesForMultiplePlugins() throws Exception {
    // given
    given(plugin2.getRequiredPlugins()).willReturn(Collections.singleton(dependencyInfo1));
    given(plugin2.getState()).willReturn(PluginState.ENABLED);
    Set<Plugin> plugins = new HashSet<Plugin>();
    plugins.add(plugin1);
    plugins.add(plugin2);
    plugins.add(plugin3);
    plugins.add(plugin4);
    given(pluginAccessor.getPlugins()).willReturn(plugins);
    List<Plugin> argumentPlugins = new ArrayList<Plugin>();
    argumentPlugins.add(plugin1);
    argumentPlugins.add(plugin2);
    // when
    PluginDependencyResult result = manager.getDependenciesToDisable(argumentPlugins, pluginStatusResolver);
    // then
    assertEquals(0, result.getDependenciesToEnable().size());
    assertEquals(0, result.getUnsatisfiedDependencies().size());
    assertEquals(0, result.getDependenciesToDisable().size());
}
Also used : PluginDependencyResult(com.qcadoo.plugin.api.PluginDependencyResult) ArrayList(java.util.ArrayList) Plugin(com.qcadoo.plugin.api.Plugin) InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with Plugin

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

the class PluginDependencyManagerTest method shouldSortPluginsWithMissingDependencies.

@Test
public void shouldSortPluginsWithMissingDependencies() {
    // given
    Set<PluginDependencyInformation> rp1 = new HashSet<PluginDependencyInformation>();
    rp1.add(new PluginDependencyInformation("p2"));
    Set<PluginDependencyInformation> rp2 = new HashSet<PluginDependencyInformation>();
    rp2.add(new PluginDependencyInformation("p3"));
    Set<PluginDependencyInformation> rp3 = new HashSet<PluginDependencyInformation>();
    Set<PluginDependencyInformation> rp4 = new HashSet<PluginDependencyInformation>();
    rp4.add(new PluginDependencyInformation("p2"));
    rp4.add(new PluginDependencyInformation("p3"));
    Set<PluginDependencyInformation> rp5 = new HashSet<PluginDependencyInformation>();
    rp5.add(new PluginDependencyInformation("p1"));
    rp5.add(new PluginDependencyInformation("p3"));
    InternalPlugin p1 = mock(InternalPlugin.class, "p1");
    given(p1.getIdentifier()).willReturn("p1");
    given(p1.getVersion()).willReturn(new Version("1.1"));
    given(p1.getRequiredPlugins()).willReturn(rp1);
    InternalPlugin p2 = mock(InternalPlugin.class, "p2");
    given(p2.getIdentifier()).willReturn("p2");
    given(p2.getVersion()).willReturn(new Version("1.1"));
    given(p2.getRequiredPlugins()).willReturn(rp2);
    InternalPlugin p3 = mock(InternalPlugin.class, "p3");
    given(p3.getIdentifier()).willReturn("p3");
    given(p3.getVersion()).willReturn(new Version("1.1"));
    given(p3.getRequiredPlugins()).willReturn(rp3);
    InternalPlugin p4 = mock(InternalPlugin.class, "p4");
    given(p4.getIdentifier()).willReturn("p4");
    given(p4.getVersion()).willReturn(new Version("1.1"));
    given(p4.getRequiredPlugins()).willReturn(rp4);
    InternalPlugin p5 = mock(InternalPlugin.class, "p5");
    given(p5.getIdentifier()).willReturn("p5");
    given(p5.getVersion()).willReturn(new Version("1.1"));
    given(p5.getRequiredPlugins()).willReturn(rp5);
    given(pluginAccessor.getPlugin("p1")).willReturn(p1);
    given(pluginAccessor.getPlugin("p2")).willReturn(p2);
    given(pluginAccessor.getPlugin("p3")).willReturn(p3);
    given(pluginAccessor.getPlugin("p4")).willReturn(p4);
    given(pluginAccessor.getPlugin("p5")).willReturn(p5);
    List<Plugin> argumentPlugins = new ArrayList<Plugin>();
    argumentPlugins.add(p1);
    argumentPlugins.add(p2);
    argumentPlugins.add(p4);
    argumentPlugins.add(p5);
    // when
    List<Plugin> sortedPlugins = manager.sortPluginsInDependencyOrder(argumentPlugins);
    // then
    assertEquals(4, sortedPlugins.size());
    assertEquals(p2, sortedPlugins.get(0));
    assertEquals(p4, sortedPlugins.get(1));
    assertEquals(p1, sortedPlugins.get(2));
    assertEquals(p5, sortedPlugins.get(3));
}
Also used : InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) Version(com.qcadoo.plugin.api.Version) ArrayList(java.util.ArrayList) 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 4 with Plugin

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

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

the class PluginDependencyManagerTest method shouldSetCyclicFlagWhenCyclicDependenciesDependenciesToArgumentsDependency.

@Test
public void shouldSetCyclicFlagWhenCyclicDependenciesDependenciesToArgumentsDependency() throws Exception {
    // given
    Set<PluginDependencyInformation> disabledRequiredPlugins1 = new HashSet<PluginDependencyInformation>();
    disabledRequiredPlugins1.add(dependencyInfo2);
    given(plugin1.getRequiredPlugins()).willReturn(disabledRequiredPlugins1);
    Set<PluginDependencyInformation> disabledRequiredPlugins2 = new HashSet<PluginDependencyInformation>();
    disabledRequiredPlugins2.add(dependencyInfo3);
    given(plugin2.getState()).willReturn(PluginState.DISABLED);
    given(plugin2.getRequiredPlugins()).willReturn(disabledRequiredPlugins2);
    Set<PluginDependencyInformation> disabledRequiredPlugins3 = new HashSet<PluginDependencyInformation>();
    disabledRequiredPlugins3.add(dependencyInfo4);
    given(plugin3.getState()).willReturn(PluginState.TEMPORARY);
    given(plugin3.getRequiredPlugins()).willReturn(disabledRequiredPlugins3);
    Set<PluginDependencyInformation> disabledRequiredPlugins4 = new HashSet<PluginDependencyInformation>();
    disabledRequiredPlugins4.add(dependencyInfo2);
    given(plugin4.getState()).willReturn(PluginState.TEMPORARY);
    given(plugin4.getRequiredPlugins()).willReturn(disabledRequiredPlugins4);
    given(pluginAccessor.getPlugin("testPlugin2")).willReturn(plugin2);
    given(pluginAccessor.getPlugin("testPlugin3")).willReturn(plugin3);
    given(pluginAccessor.getPlugin("testPlugin4")).willReturn(plugin4);
    // when
    PluginDependencyResult result = manager.getDependenciesToEnable(singletonList((Plugin) plugin1), pluginStatusResolver);
    // then
    assertTrue(result.isCyclic());
    assertEquals(0, result.getDependenciesToEnable().size());
    assertEquals(0, result.getUnsatisfiedDependencies().size());
    assertEquals(0, result.getDependenciesToDisable().size());
}
Also used : PluginDependencyResult(com.qcadoo.plugin.api.PluginDependencyResult) 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)

Aggregations

Plugin (com.qcadoo.plugin.api.Plugin)71 InternalPlugin (com.qcadoo.plugin.internal.api.InternalPlugin)59 Test (org.junit.Test)58 PluginDependencyResult (com.qcadoo.plugin.api.PluginDependencyResult)38 PluginDependencyInformation (com.qcadoo.plugin.api.PluginDependencyInformation)28 HashSet (java.util.HashSet)25 ArrayList (java.util.ArrayList)15 QcadooPluginPlugin (com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin)13 DefaultPlugin (com.qcadoo.plugin.internal.DefaultPlugin)11 PluginOperationResult (com.qcadoo.plugin.api.PluginOperationResult)8 Version (com.qcadoo.plugin.api.Version)8 SimplePluginStatusResolver (com.qcadoo.plugin.internal.dependencymanager.SimplePluginStatusResolver)8 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)6 InOrder (org.mockito.InOrder)6 ModuleFactory (com.qcadoo.plugin.api.ModuleFactory)5 VersionOfDependency (com.qcadoo.plugin.api.VersionOfDependency)4 Entity (com.qcadoo.model.api.Entity)2 EntityList (com.qcadoo.model.api.EntityList)2 Module (com.qcadoo.plugin.api.Module)2 PluginException (com.qcadoo.plugin.internal.PluginException)2