Search in sources :

Example 26 with PluginDependencyInformation

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

the class PluginManagerTest method shouldNotEnablePluginWithUnsatisfiedDependencies.

@Test
public void shouldNotEnablePluginWithUnsatisfiedDependencies() throws Exception {
    // given
    given(plugin.hasState(PluginState.DISABLED)).willReturn(true);
    PluginDependencyResult pluginDependencyResult = PluginDependencyResultImpl.unsatisfiedDependencies(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.UNSATISFIED_DEPENDENCIES, pluginOperationResult.getStatus());
    assertEquals(1, pluginOperationResult.getPluginDependencyResult().getUnsatisfiedDependencies().size());
    assertEquals(1, pluginOperationResult.getPluginDependencyResult().getUnsatisfiedDependencies().size());
    assertTrue(pluginOperationResult.getPluginDependencyResult().getUnsatisfiedDependencies().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 27 with PluginDependencyInformation

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

the class PluginManagerTest method shouldNotDisablePluginWithEnabledDependencies.

@Test
public void shouldNotDisablePluginWithEnabledDependencies() throws Exception {
    // given
    given(plugin.hasState(PluginState.ENABLED)).willReturn(true);
    PluginDependencyResult pluginDependencyResult = PluginDependencyResultImpl.dependenciesToDisable(Collections.singleton(new PluginDependencyInformation("unknownplugin", new VersionOfDependency(""))));
    given(pluginDependencyManager.getDependenciesToDisable(Mockito.eq(singletonList((Plugin) plugin)), Mockito.any(SimplePluginStatusResolver.class))).willReturn(pluginDependencyResult);
    // when
    PluginOperationResult pluginOperationResult = pluginManager.disablePlugin("pluginname");
    // then
    verify(plugin, never()).changeStateTo(PluginState.DISABLED);
    verify(pluginDao, never()).save(plugin);
    verify(pluginAccessor, never()).savePlugin(plugin);
    assertFalse(pluginOperationResult.isSuccess());
    assertEquals(PluginOperationStatus.DEPENDENCIES_TO_DISABLE, pluginOperationResult.getStatus());
    assertEquals(1, pluginOperationResult.getPluginDependencyResult().getDependenciesToDisable().size());
    assertEquals(1, pluginOperationResult.getPluginDependencyResult().getDependenciesToDisable().size());
    assertTrue(pluginOperationResult.getPluginDependencyResult().getDependenciesToDisable().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 28 with PluginDependencyInformation

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

the class PluginManagerTest method shouldNotUninstallPluginWithEnabledDependencies.

@Test
public void shouldNotUninstallPluginWithEnabledDependencies() throws Exception {
    // given
    PluginDependencyResult pluginDependencyResult = PluginDependencyResultImpl.dependenciesToUninstall(Collections.singleton(new PluginDependencyInformation("unknownplugin", new VersionOfDependency(""))));
    given(pluginDependencyManager.getDependenciesToUninstall(Mockito.eq(singletonList((Plugin) plugin)), Mockito.any(SimplePluginStatusResolver.class))).willReturn(pluginDependencyResult);
    given(plugin.getFilename()).willReturn("filename");
    // when
    PluginOperationResult pluginOperationResult = pluginManager.uninstallPlugin("pluginname");
    // then
    verify(plugin, never()).changeStateTo(PluginState.DISABLED);
    verify(pluginDao, never()).delete(plugin);
    verify(pluginAccessor, never()).removePlugin(plugin);
    verify(pluginFileManager, never()).uninstallPlugin("filename");
    assertFalse(pluginOperationResult.isSuccess());
    assertEquals(PluginOperationStatus.DEPENDENCIES_TO_UNINSTALL, pluginOperationResult.getStatus());
    assertEquals(1, pluginOperationResult.getPluginDependencyResult().getDependenciesToUninstall().size());
    assertTrue(pluginOperationResult.getPluginDependencyResult().getDependenciesToUninstall().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 29 with PluginDependencyInformation

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

the class PluginManagmentPerformer method addDependenciesToUrl.

private void addDependenciesToUrl(final StringBuilder url, final Set<PluginDependencyInformation> dependencies) {
    if (dependencies != null) {
        for (PluginDependencyInformation dependencyInfo : dependencies) {
            url.append("&dep_");
            url.append(dependencyInfo.getIdentifier());
            url.append("=");
            if (dependencyInfo.getVersionOfDependency() == null || "0.0.0".equals(dependencyInfo.getVersionOfDependency().toString())) {
                url.append("none");
            } else {
                url.append(dependencyInfo.getVersionOfDependency().toString());
            }
        }
    }
}
Also used : PluginDependencyInformation(com.qcadoo.plugin.api.PluginDependencyInformation)

Example 30 with PluginDependencyInformation

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

the class PluginManagmentPerformer method createConfirmPageUrl.

private String createConfirmPageUrl(final String statusKey, final String cancelLabel, final String acceptLabel, final String acceptRedirect, final Set<PluginDependencyInformation> dependencies, final List<String> pluginIdentifiers) {
    StringBuilder redirectUrl = new StringBuilder(acceptRedirect);
    redirectUrl.append(".html?");
    for (String pluginIdentifier : pluginIdentifiers) {
        if (redirectUrl.charAt(redirectUrl.length() - 1) != '?') {
            redirectUrl.append("&");
        }
        redirectUrl.append("plugin=");
        redirectUrl.append(pluginIdentifier);
    }
    for (PluginDependencyInformation dependency : dependencies) {
        redirectUrl.append("&plugin=");
        redirectUrl.append(dependency.getIdentifier());
    }
    StringBuilder url = new StringBuilder("../pluginPages/infoPage.html?type=confirm&status=");
    url.append(statusKey);
    url.append("&cancelLabel=");
    url.append(cancelLabel);
    url.append("&acceptLabel=");
    url.append(acceptLabel);
    url.append("&acceptRedirect=");
    try {
        url.append(URLEncoder.encode(redirectUrl.toString(), "ISO-8859-1"));
    } catch (UnsupportedEncodingException e) {
        throw new IllegalStateException("Error while generating redirect url", e);
    }
    addDependenciesToUrl(url, dependencies);
    return url.toString();
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) PluginDependencyInformation(com.qcadoo.plugin.api.PluginDependencyInformation)

Aggregations

PluginDependencyInformation (com.qcadoo.plugin.api.PluginDependencyInformation)36 Plugin (com.qcadoo.plugin.api.Plugin)28 PluginDependencyResult (com.qcadoo.plugin.api.PluginDependencyResult)28 Test (org.junit.Test)28 InternalPlugin (com.qcadoo.plugin.internal.api.InternalPlugin)24 HashSet (java.util.HashSet)24 VersionOfDependency (com.qcadoo.plugin.api.VersionOfDependency)10 ArrayList (java.util.ArrayList)8 PluginOperationResult (com.qcadoo.plugin.api.PluginOperationResult)4 SimplePluginStatusResolver (com.qcadoo.plugin.internal.dependencymanager.SimplePluginStatusResolver)4 Version (com.qcadoo.plugin.api.Version)3 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 QcadooPluginPlugin (com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin)1 DefaultPlugin (com.qcadoo.plugin.internal.DefaultPlugin)1 PluginException (com.qcadoo.plugin.internal.PluginException)1 File (java.io.File)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Set (java.util.Set)1