Search in sources :

Example 6 with InternalPlugin

use of com.qcadoo.plugin.internal.api.InternalPlugin in project qcadoo by qcadoo.

the class PluginChangeStateToTest method assertOperationNotSupported.

private void assertOperationNotSupported(final PluginState from, final PluginState to) throws Exception {
    // given
    InternalPlugin plugin = DefaultPlugin.Builder.identifier("identifier", Collections.<ModuleFactory<?>>emptyList()).build();
    if (from != null) {
        plugin.changeStateTo(from);
    }
    // when
    try {
        plugin.changeStateTo(to);
        Assert.fail();
    } catch (IllegalStateException e) {
        LOG.info("ignore");
    }
}
Also used : InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) ModuleFactory(com.qcadoo.plugin.api.ModuleFactory)

Example 7 with InternalPlugin

use of com.qcadoo.plugin.internal.api.InternalPlugin in project qcadoo by qcadoo.

the class PluginAccessorTest method shouldRemovePlugin.

@Test
public void shouldRemovePlugin() throws Exception {
    // given
    InternalPlugin plugin1 = mock(InternalPlugin.class, "plugin1");
    given(plugin1.getIdentifier()).willReturn("identifier1");
    QcadooPluginPlugin pluginsPlugin1 = mock(QcadooPluginPlugin.class);
    given(pluginsPlugin1.getIdentifier()).willReturn("identifier1");
    given(pluginsPlugin1.getState()).willReturn("ENABLED");
    given(pluginsPlugin1.getVersion()).willReturn("0.0.0");
    InternalPlugin plugin2 = mock(InternalPlugin.class);
    given(plugin2.getIdentifier()).willReturn("identifier2");
    QcadooPluginPlugin pluginsPlugin2 = mock(QcadooPluginPlugin.class);
    given(pluginsPlugin2.getIdentifier()).willReturn("identifier2");
    given(pluginsPlugin2.getState()).willReturn("ENABLED");
    given(pluginsPlugin2.getVersion()).willReturn("0.0.0");
    given(pluginDescriptorParser.loadPlugins()).willReturn(Sets.newHashSet(plugin1, plugin2));
    given(pluginDao.list()).willReturn(Sets.<QcadooPluginPlugin>newHashSet(pluginsPlugin1, pluginsPlugin2));
    pluginAccessor.init();
    // when
    pluginAccessor.removePlugin(plugin1);
    // then
    assertEquals(1, pluginAccessor.getPlugins().size());
    assertThat(pluginAccessor.getPlugins(), hasItems((Plugin) plugin2));
}
Also used : InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) QcadooPluginPlugin(com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin) QcadooPluginPlugin(com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin) Plugin(com.qcadoo.plugin.api.Plugin) InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) Test(org.junit.Test)

Example 8 with InternalPlugin

use of com.qcadoo.plugin.internal.api.InternalPlugin in project qcadoo by qcadoo.

the class PluginAccessorTest method shouldSynchronizePluginsFromClasspathAndDatabase.

@Test
public void shouldSynchronizePluginsFromClasspathAndDatabase() throws Exception {
    // given
    InternalPlugin plugin1 = mock(InternalPlugin.class);
    QcadooPluginPlugin pluginsPlugin1 = mock(QcadooPluginPlugin.class);
    given(plugin1.getIdentifier()).willReturn("identifier1");
    given(pluginsPlugin1.getIdentifier()).willReturn("identifier1");
    given(pluginsPlugin1.getState()).willReturn("ENABLED");
    given(pluginsPlugin1.getVersion()).willReturn("0.0.0");
    given(plugin1.compareVersion(new Version(pluginsPlugin1.getVersion()))).willReturn(0);
    QcadooPluginPlugin pluginsPlugin21 = mock(QcadooPluginPlugin.class);
    given(pluginsPlugin21.getIdentifier()).willReturn("identifier21");
    given(pluginsPlugin21.getIdentifier()).willReturn("identifier21");
    given(pluginsPlugin21.getState()).willReturn("ENABLED");
    InternalPlugin plugin22 = mock(InternalPlugin.class);
    given(plugin22.getIdentifier()).willReturn("identifier21");
    given(pluginsPlugin21.getVersion()).willReturn("0.0.0");
    given(plugin22.compareVersion(new Version(pluginsPlugin21.getVersion()))).willReturn(1);
    InternalPlugin plugin3 = mock(InternalPlugin.class);
    given(plugin3.getIdentifier()).willReturn("identifier3");
    QcadooPluginPlugin pluginsPlugin4 = mock(QcadooPluginPlugin.class);
    given(pluginsPlugin4.getIdentifier()).willReturn("identifier4");
    given(pluginsPlugin4.getState()).willReturn("ENABLED");
    Set<InternalPlugin> pluginsFromDescriptor = Sets.newHashSet(plugin1, plugin22, plugin3);
    Set<QcadooPluginPlugin> pluginsFromDatabase = Sets.newHashSet(pluginsPlugin1, pluginsPlugin21, pluginsPlugin4);
    given(pluginDescriptorParser.loadPlugins()).willReturn(pluginsFromDescriptor);
    given(pluginDao.list()).willReturn(pluginsFromDatabase);
    // when
    pluginAccessor.init();
    // then
    verify(pluginDao, never()).save(plugin1);
    verify(plugin22).changeStateTo(PluginState.ENABLED);
    verify(pluginDao).save(plugin22);
    verify(pluginDao).save(plugin3);
    verify(pluginDao).delete(pluginsPlugin4);
}
Also used : InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) QcadooPluginPlugin(com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin) Version(com.qcadoo.plugin.api.Version) Test(org.junit.Test)

Example 9 with InternalPlugin

use of com.qcadoo.plugin.internal.api.InternalPlugin in project qcadoo by qcadoo.

the class PluginAccessorTest method shouldSaveExistingPlugin.

@Test
public void shouldSaveExistingPlugin() throws Exception {
    // given
    InternalPlugin plugin1 = mock(InternalPlugin.class, "plugin1");
    given(plugin1.getIdentifier()).willReturn("identifier1");
    InternalPlugin plugin2 = mock(InternalPlugin.class);
    given(plugin2.getIdentifier()).willReturn("identifier1");
    QcadooPluginPlugin pluginsPlugin2 = mock(QcadooPluginPlugin.class);
    given(pluginsPlugin2.getIdentifier()).willReturn("identifier1");
    given(pluginsPlugin2.getState()).willReturn("ENABLED");
    given(pluginsPlugin2.getVersion()).willReturn("0.0.0");
    given(pluginDescriptorParser.loadPlugins()).willReturn(Sets.newHashSet(plugin1));
    given(pluginDao.list()).willReturn(Sets.<QcadooPluginPlugin>newHashSet(pluginsPlugin2));
    pluginAccessor.init();
    // when
    pluginAccessor.savePlugin(plugin2);
    // then
    assertEquals(1, pluginAccessor.getPlugins().size());
    assertThat(pluginAccessor.getPlugins(), hasItems((Plugin) plugin2));
}
Also used : InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) QcadooPluginPlugin(com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin) QcadooPluginPlugin(com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin) Plugin(com.qcadoo.plugin.api.Plugin) InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) Test(org.junit.Test)

Example 10 with InternalPlugin

use of com.qcadoo.plugin.internal.api.InternalPlugin in project qcadoo by qcadoo.

the class PluginAccessorTest method shouldSaveNewPlugin.

@Test
public void shouldSaveNewPlugin() throws Exception {
    // given
    InternalPlugin plugin1 = mock(InternalPlugin.class, "plugin1");
    given(plugin1.getIdentifier()).willReturn("identifier1");
    QcadooPluginPlugin pluginsPlugin1 = mock(QcadooPluginPlugin.class);
    given(pluginsPlugin1.getIdentifier()).willReturn("identifier1");
    given(pluginsPlugin1.getState()).willReturn("ENABLED");
    given(pluginsPlugin1.getVersion()).willReturn("0.0.0");
    InternalPlugin plugin2 = mock(InternalPlugin.class);
    given(plugin2.getIdentifier()).willReturn("identifier2");
    given(pluginDescriptorParser.loadPlugins()).willReturn(Sets.newHashSet(plugin1));
    given(pluginDao.list()).willReturn(Sets.<QcadooPluginPlugin>newHashSet(pluginsPlugin1));
    pluginAccessor.init();
    // when
    pluginAccessor.savePlugin(plugin2);
    // then
    assertThat(pluginAccessor.getPlugins(), hasItems((Plugin) plugin1, (Plugin) plugin2));
}
Also used : InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) QcadooPluginPlugin(com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin) QcadooPluginPlugin(com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin) Plugin(com.qcadoo.plugin.api.Plugin) InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) Test(org.junit.Test)

Aggregations

InternalPlugin (com.qcadoo.plugin.internal.api.InternalPlugin)31 Plugin (com.qcadoo.plugin.api.Plugin)21 Test (org.junit.Test)18 QcadooPluginPlugin (com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin)15 PluginDependencyResult (com.qcadoo.plugin.api.PluginDependencyResult)9 ArrayList (java.util.ArrayList)8 Version (com.qcadoo.plugin.api.Version)6 InOrder (org.mockito.InOrder)6 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)5 ModuleFactory (com.qcadoo.plugin.api.ModuleFactory)5 Module (com.qcadoo.plugin.api.Module)4 PluginDependencyInformation (com.qcadoo.plugin.api.PluginDependencyInformation)4 PluginOperationResult (com.qcadoo.plugin.api.PluginOperationResult)4 PluginException (com.qcadoo.plugin.internal.PluginException)4 SimplePluginStatusResolver (com.qcadoo.plugin.internal.dependencymanager.SimplePluginStatusResolver)3 File (java.io.File)3 HashSet (java.util.HashSet)3 MultiTenantCallback (com.qcadoo.tenant.api.MultiTenantCallback)2 Resource (org.springframework.core.io.Resource)2 PluginStateResolver (com.qcadoo.plugin.api.PluginStateResolver)1