use of com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin in project qcadoo by qcadoo.
the class PluginAccessorTest method shouldNotDeleteTemporaryPlugins.
@Test
public void shouldNotDeleteTemporaryPlugins() throws Exception {
// given
QcadooPluginPlugin pluginsPlugin1 = mock(QcadooPluginPlugin.class);
given(pluginsPlugin1.getState()).willReturn(PluginState.TEMPORARY.toString());
QcadooPluginPlugin pluginsPlugin2 = mock(QcadooPluginPlugin.class);
given(pluginsPlugin2.getState()).willReturn(PluginState.ENABLED.toString());
Set<InternalPlugin> pluginsFromDescriptor = Sets.newHashSet();
Set<QcadooPluginPlugin> pluginsFromDatabase = Sets.newHashSet(pluginsPlugin1, pluginsPlugin2);
given(pluginDescriptorParser.loadPlugins()).willReturn(pluginsFromDescriptor);
given(pluginDao.list()).willReturn(pluginsFromDatabase);
// when
pluginAccessor.init();
verify(pluginDao, never()).delete(pluginsPlugin1);
verify(pluginDao).delete(pluginsPlugin2);
}
use of com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin in project qcadoo by qcadoo.
the class DefaultPluginDao method save.
@Override
@Transactional(L_PLUGIN)
public void save(final Plugin plugin) {
QcadooPluginPlugin existingPlugin = get(plugin.getIdentifier());
if (existingPlugin == null) {
existingPlugin = new QcadooPluginPlugin(plugin);
} else {
existingPlugin.setState(plugin.getState().toString());
existingPlugin.setVersion(plugin.getVersion().toString());
existingPlugin.setIsSystem(plugin.isSystemPlugin());
existingPlugin.setGroupName(plugin.getPluginInformation() == null ? null : plugin.getPluginInformation().getGroup());
existingPlugin.setLicense(plugin.getPluginInformation() == null ? null : plugin.getPluginInformation().getLicense());
}
save(existingPlugin);
}
use of com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin in project qcadoo by qcadoo.
the class PluginAccessorTest method shouldPerformEnableOnEnablingPlugins.
@SuppressWarnings("unchecked")
@Test
public void shouldPerformEnableOnEnablingPlugins() 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("ENABLING");
given(pluginsPlugin1.getVersion()).willReturn("0.0.0");
given(plugin1.hasState(PluginState.ENABLING)).willReturn(true);
InternalPlugin plugin2 = mock(InternalPlugin.class);
QcadooPluginPlugin pluginsPlugin2 = mock(QcadooPluginPlugin.class);
given(plugin2.getIdentifier()).willReturn("identifier2");
given(pluginsPlugin2.getIdentifier()).willReturn("identifier2");
given(pluginsPlugin2.getState()).willReturn("ENABLING");
given(pluginsPlugin2.getVersion()).willReturn("0.0.0");
given(plugin2.hasState(PluginState.ENABLING)).willReturn(true);
InternalPlugin plugin3 = mock(InternalPlugin.class);
QcadooPluginPlugin pluginsPlugin3 = mock(QcadooPluginPlugin.class);
given(pluginsPlugin3.getIdentifier()).willReturn("identifier3");
given(pluginsPlugin3.getVersion()).willReturn("0.0.0");
given(pluginsPlugin3.getState()).willReturn("DISABLED");
given(plugin3.getIdentifier()).willReturn("identifier3");
Set<InternalPlugin> pluginsFromDescriptor = Sets.newHashSet(plugin1, plugin2, plugin3);
Set<QcadooPluginPlugin> pluginsFromDatabase = Sets.newHashSet(pluginsPlugin1, pluginsPlugin2, pluginsPlugin3);
List<Plugin> sortedPluginsToInitialize = Lists.newArrayList((Plugin) plugin2, (Plugin) plugin1);
given(pluginDependencyManager.sortPluginsInDependencyOrder(Mockito.anyCollectionOf(Plugin.class), Mockito.anyMap())).willReturn(sortedPluginsToInitialize);
given(pluginDescriptorParser.loadPlugins()).willReturn(pluginsFromDescriptor);
given(pluginDao.list()).willReturn(pluginsFromDatabase);
// when
pluginAccessor.init();
pluginAccessor.onApplicationEvent(null);
// then
InOrder inOrder = inOrder(plugin2, plugin1, moduleFactoryAccessor);
inOrder.verify(moduleFactoryAccessor).init(sortedPluginsToInitialize);
inOrder.verify(plugin2).changeStateTo(PluginState.ENABLED);
inOrder.verify(plugin1).changeStateTo(PluginState.ENABLED);
verify(plugin3, never()).changeStateTo(PluginState.ENABLED);
verify(pluginDao).save(plugin1);
verify(pluginDao).save(plugin2);
verify(pluginDao, never()).save(plugin3);
}
use of com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin in project qcadoo by qcadoo.
the class PluginAccessorTest method shouldFailOnPluginDowngrade.
@Test(expected = IllegalStateException.class)
public void shouldFailOnPluginDowngrade() throws Exception {
// given
InternalPlugin plugin11 = mock(InternalPlugin.class);
given(plugin11.getIdentifier()).willReturn("identifier11");
QcadooPluginPlugin pluginsPlugin12 = mock(QcadooPluginPlugin.class);
given(pluginsPlugin12.getIdentifier()).willReturn("identifier11");
given(pluginsPlugin12.getVersion()).willReturn("0.0.0");
given(pluginsPlugin12.getState()).willReturn("ENABLED");
given(plugin11.compareVersion(new Version(pluginsPlugin12.getVersion()))).willReturn(-1);
Set<InternalPlugin> pluginsFromDescriptor = Sets.newHashSet(plugin11);
Set<QcadooPluginPlugin> pluginsFromDatabase = Sets.newHashSet(pluginsPlugin12);
given(pluginDescriptorParser.loadPlugins()).willReturn(pluginsFromDescriptor);
given(pluginDao.list()).willReturn(pluginsFromDatabase);
// when
pluginAccessor.init();
}
use of com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin in project qcadoo by qcadoo.
the class PluginAccessorTest method shouldPerformInit.
@SuppressWarnings("unchecked")
@Test
public void shouldPerformInit() throws Exception {
// given
InternalPlugin plugin1 = mock(InternalPlugin.class, "plugin1");
QcadooPluginPlugin pluginsPlugin1 = mock(QcadooPluginPlugin.class, "plugin1");
given(plugin1.getIdentifier()).willReturn("identifier1");
given(pluginsPlugin1.getIdentifier()).willReturn("identifier1");
given(pluginsPlugin1.getState()).willReturn("ENABLED");
given(pluginsPlugin1.getVersion()).willReturn("0.0.0");
InternalPlugin plugin2 = mock(InternalPlugin.class, "plugin2");
QcadooPluginPlugin pluginsPlugin2 = mock(QcadooPluginPlugin.class, "plugin2");
given(plugin2.getIdentifier()).willReturn("identifier2");
given(pluginsPlugin2.getIdentifier()).willReturn("identifier2");
given(pluginsPlugin2.getVersion()).willReturn("0.0.0");
given(pluginsPlugin2.getState()).willReturn("ENABLED");
Set<InternalPlugin> pluginsFromDescriptor = Sets.newHashSet(plugin1, plugin2);
Set<QcadooPluginPlugin> pluginsFromDatabase = Sets.newHashSet(pluginsPlugin1, pluginsPlugin2);
List<Plugin> sortedPluginsToInitialize = Lists.newArrayList((Plugin) plugin2, (Plugin) plugin1);
given(pluginDependencyManager.sortPluginsInDependencyOrder(Mockito.anyCollectionOf(Plugin.class), Mockito.anyMap())).willReturn(sortedPluginsToInitialize);
given(pluginDescriptorParser.loadPlugins()).willReturn(pluginsFromDescriptor);
given(pluginDao.list()).willReturn(pluginsFromDatabase);
// when
pluginAccessor.init();
pluginAccessor.onApplicationEvent(null);
// then
InOrder inOrder = inOrder(plugin2, plugin1, moduleFactoryAccessor);
inOrder.verify(moduleFactoryAccessor).init(sortedPluginsToInitialize);
}
Aggregations