use of com.qcadoo.plugin.api.Version 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);
}
use of com.qcadoo.plugin.api.Version in project qcadoo by qcadoo.
the class PluginAccessorTest method shouldListAllPlugins.
@Test
public void shouldListAllPlugins() 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.getVersion()).willReturn("0.0.0");
given(plugin1.compareVersion(new Version(pluginsPlugin1.getVersion()))).willReturn(0);
given(plugin1.hasState(PluginState.ENABLED)).willReturn(false);
given(pluginsPlugin1.getState()).willReturn("DISABLED");
QcadooPluginPlugin pluginsPlugin21 = mock(QcadooPluginPlugin.class, "plugin21");
given(pluginsPlugin21.getIdentifier()).willReturn("identifier21");
given(pluginsPlugin21.getState()).willReturn("ENABLED");
InternalPlugin plugin22 = mock(InternalPlugin.class, "plugin22");
given(plugin22.getIdentifier()).willReturn("identifier21");
given(plugin22.hasState(PluginState.ENABLED)).willReturn(true);
given(pluginsPlugin21.getVersion()).willReturn("0.0.0");
given(plugin22.compareVersion(new Version(pluginsPlugin21.getVersion()))).willReturn(1);
InternalPlugin plugin3 = mock(InternalPlugin.class, "plugin3");
QcadooPluginPlugin pluginsPlugin3 = mock(QcadooPluginPlugin.class, "plugin3");
given(plugin3.getIdentifier()).willReturn("identifier3");
given(pluginsPlugin3.getIdentifier()).willReturn("identifier3");
given(pluginsPlugin3.getVersion()).willReturn("0.0.0");
given(plugin3.hasState(PluginState.ENABLED)).willReturn(true);
given(plugin3.isSystemPlugin()).willReturn(true);
given(pluginsPlugin3.getState()).willReturn("ENABLED");
InternalPlugin plugin4 = mock(InternalPlugin.class, "plugin4");
given(plugin4.getIdentifier()).willReturn("identifier4");
given(plugin4.hasState(PluginState.ENABLED)).willReturn(false);
Set<InternalPlugin> pluginsFromDescriptor = Sets.newHashSet(plugin1, plugin22, plugin3, plugin4);
Set<QcadooPluginPlugin> pluginsFromDatabase = Sets.newHashSet(pluginsPlugin1, pluginsPlugin21, pluginsPlugin3);
given(pluginDescriptorParser.loadPlugins()).willReturn(pluginsFromDescriptor);
given(pluginDao.list()).willReturn(pluginsFromDatabase);
// when
pluginAccessor.init();
// then
verify(plugin1).changeStateTo(PluginState.DISABLED);
verify(plugin22).changeStateTo(PluginState.ENABLED);
verify(plugin3).changeStateTo(PluginState.ENABLED);
verify(plugin4).changeStateTo(PluginState.ENABLING);
assertThat(pluginAccessor.getPlugins(), hasItems((Plugin) plugin1, (Plugin) plugin22, (Plugin) plugin3, (Plugin) plugin4));
assertThat(pluginAccessor.getEnabledPlugins(), hasItems((Plugin) plugin22, (Plugin) plugin3));
assertThat(pluginAccessor.getEnabledPlugins(), not(hasItem((Plugin) plugin1)));
assertThat(pluginAccessor.getEnabledPlugins(), not(hasItem((Plugin) plugin4)));
assertThat(pluginAccessor.getSystemPlugins(), hasItem((Plugin) plugin3));
assertEquals(plugin1, pluginAccessor.getPlugin("identifier1"));
assertEquals(plugin22, pluginAccessor.getPlugin("identifier21"));
assertEquals(plugin3, pluginAccessor.getPlugin("identifier3"));
assertEquals(plugin4, pluginAccessor.getPlugin("identifier4"));
assertNull(pluginAccessor.getEnabledPlugin("identifier1"));
assertEquals(plugin22, pluginAccessor.getEnabledPlugin("identifier21"));
assertEquals(plugin3, pluginAccessor.getEnabledPlugin("identifier3"));
assertNull(pluginAccessor.getEnabledPlugin("identifier4"));
}
use of com.qcadoo.plugin.api.Version in project qcadoo by qcadoo.
the class PluginDaoTest method shouldSaveNotPersistentExistingPlugin.
@Test
public void shouldSaveNotPersistentExistingPlugin() throws Exception {
// given
given(criteria.uniqueResult()).willReturn(plugin1);
given(plugin11.getState()).willReturn(PluginState.ENABLED);
given(plugin11.getVersion()).willReturn(new Version("0.0.0"));
// when
pluginDao.save(plugin11);
// then
assertEquals(plugin1.getState(), PluginState.ENABLED.toString());
assertEquals(plugin1.getVersion(), "0.0.0");
verify(session).save(plugin1);
}
use of com.qcadoo.plugin.api.Version in project qcadoo by qcadoo.
the class PluginDependencyInformationTest method shouldReturnTrueWhenVersionIsSattisfied.
@Test
public void shouldReturnTrueWhenVersionIsSattisfied() throws Exception {
// given
Version v1 = new Version("1.1");
Version v2 = new Version("0.9");
Version v3 = new Version("1.2.10");
Version v4 = new Version("4.2.0");
Version v5 = new Version("3.0.1");
// when
boolean res1 = dependencyInformation1.contains(v1);
boolean res2 = dependencyInformation2.contains(v2);
boolean res3 = dependencyInformation3.contains(v3);
boolean res4 = dependencyInformation4.contains(v4);
boolean res5 = dependencyInformation5.contains(v5);
// then
Assert.assertTrue(res1);
Assert.assertTrue(res2);
Assert.assertTrue(res3);
Assert.assertTrue(res4);
Assert.assertTrue(res5);
}
use of com.qcadoo.plugin.api.Version 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