Add method to load plugin from file
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Fri, 21 Aug 2015 17:15:31 +0000 (19:15 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Fri, 21 Aug 2015 17:18:41 +0000 (19:18 +0200)
src/main/java/net/pterodactylus/fcp/quelaton/LoadPluginCommand.java
src/main/java/net/pterodactylus/fcp/quelaton/LoadPluginCommandImpl.java
src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java

index 0432f14..959f559 100644 (file)
@@ -14,5 +14,6 @@ public interface LoadPluginCommand {
        LoadPluginCommand addToConfig();
        Executable<Optional<PluginInfo>> officialFromFreenet(String pluginIdentifier);
        Executable<Optional<PluginInfo>> officialFromHttps(String pluginIdentifier);
+       Executable<Optional<PluginInfo>> fromFile(String filename);
 
 }
index eccb10f..209e394 100644 (file)
@@ -56,6 +56,13 @@ public class LoadPluginCommandImpl implements LoadPluginCommand {
                return this::execute;
        }
 
+       @Override
+       public Executable<Optional<PluginInfo>> fromFile(String filename) {
+               loadPlugin.setUrlType(UrlType.FILE);
+               loadPlugin.setPluginUrl(filename);
+               return this::execute;
+       }
+
        private ListenableFuture<Optional<PluginInfo>> execute() {
                return threadPool.submit(this::executeDialog);
        }
index f54298f..5d70ff2 100644 (file)
@@ -2093,6 +2093,39 @@ public class DefaultFcpClientTest {
        }
 
        @Test
+       public void defaultFcpClientCanLoadPluginFromFile() throws ExecutionException, InterruptedException,
+       IOException {
+               Future<Optional<PluginInfo>> pluginInfo = fcpClient.loadPlugin().fromFile("/path/to/plugin.jar").execute();
+               connectNode();
+               List<String> lines = fcpServer.collectUntil(is("EndMessage"));
+               String identifier = extractIdentifier(lines);
+               assertThat(lines, matchesFcpMessage(
+                       "LoadPlugin",
+                       "Identifier=" + identifier,
+                       "PluginURL=/path/to/plugin.jar",
+                       "URLType=file",
+                       "EndMessage"
+               ));
+               fcpServer.writeLine(
+                       "PluginInfo",
+                       "Identifier=" + identifier,
+                       "PluginName=superPlugin",
+                       "IsTalkable=true",
+                       "LongVersion=1.2.3",
+                       "Version=42",
+                       "OriginUri=superPlugin",
+                       "Started=true",
+                       "EndMessage"
+               );
+               assertThat(pluginInfo.get().get().getPluginName(), is("superPlugin"));
+               assertThat(pluginInfo.get().get().getOriginalURI(), is("superPlugin"));
+               assertThat(pluginInfo.get().get().isTalkable(), is(true));
+               assertThat(pluginInfo.get().get().getVersion(), is("42"));
+               assertThat(pluginInfo.get().get().getLongVersion(), is("1.2.3"));
+               assertThat(pluginInfo.get().get().isStarted(), is(true));
+       }
+
+       @Test
        public void failedLoadingPluginIsRecognized() throws ExecutionException, InterruptedException,
        IOException {
                Future<Optional<PluginInfo>> pluginInfo = fcpClient.loadPlugin().officialFromFreenet("superPlugin").execute();