Add method to load plugin from official HTTPS
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Fri, 21 Aug 2015 17:07:23 +0000 (19:07 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Fri, 21 Aug 2015 17:18:29 +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 16686a4..0432f14 100644 (file)
@@ -13,5 +13,6 @@ public interface LoadPluginCommand {
 
        LoadPluginCommand addToConfig();
        Executable<Optional<PluginInfo>> officialFromFreenet(String pluginIdentifier);
+       Executable<Optional<PluginInfo>> officialFromHttps(String pluginIdentifier);
 
 }
index 3109e8a..eccb10f 100644 (file)
@@ -48,6 +48,14 @@ public class LoadPluginCommandImpl implements LoadPluginCommand {
                return this::execute;
        }
 
+       @Override
+       public Executable<Optional<PluginInfo>> officialFromHttps(String pluginIdentifier) {
+               loadPlugin.setUrlType(UrlType.OFFICIAL);
+               loadPlugin.setOfficialSource(OfficialSource.HTTPS);
+               loadPlugin.setPluginUrl(pluginIdentifier);
+               return this::execute;
+       }
+
        private ListenableFuture<Optional<PluginInfo>> execute() {
                return threadPool.submit(this::executeDialog);
        }
index 77e3588..f54298f 100644 (file)
@@ -2059,6 +2059,40 @@ public class DefaultFcpClientTest {
        }
 
        @Test
+       public void defaultFcpClientCanLoadPluginFromHttps() throws ExecutionException, InterruptedException,
+       IOException {
+               Future<Optional<PluginInfo>> pluginInfo = fcpClient.loadPlugin().officialFromHttps("superPlugin").execute();
+               connectNode();
+               List<String> lines = fcpServer.collectUntil(is("EndMessage"));
+               String identifier = extractIdentifier(lines);
+               assertThat(lines, matchesFcpMessage(
+                       "LoadPlugin",
+                       "Identifier=" + identifier,
+                       "PluginURL=superPlugin",
+                       "URLType=official",
+                       "OfficialSource=https",
+                       "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();