- public class OfficialPlugins {
-
- @Test
- public void fromFreenet() throws ExecutionException, InterruptedException, IOException {
- Future<Optional<PluginInfo>> pluginInfo =
- fcpClient.loadPlugin().officialFromFreenet("superPlugin").execute();
- connectAndAssert(() -> createMatcherForOfficialSource("freenet"));
- assertThat(lines, not(contains(startsWith("Store="))));
- replyWithPluginInfo();
- verifyPluginInfo(pluginInfo);
- }
-
- @Test
- public void persistentFromFreenet() throws ExecutionException, InterruptedException, IOException {
- Future<Optional<PluginInfo>> pluginInfo =
- fcpClient.loadPlugin().addToConfig().officialFromFreenet("superPlugin").execute();
- connectAndAssert(() -> createMatcherForOfficialSource("freenet"));
- assertThat(lines, hasItem("Store=true"));
- replyWithPluginInfo();
- verifyPluginInfo(pluginInfo);
- }
-
- @Test
- public void fromHttps() throws ExecutionException, InterruptedException, IOException {
- Future<Optional<PluginInfo>> pluginInfo =
- fcpClient.loadPlugin().officialFromHttps("superPlugin").execute();
- connectAndAssert(() -> createMatcherForOfficialSource("https"));
- replyWithPluginInfo();
- verifyPluginInfo(pluginInfo);
- }
-
- private Matcher<List<String>> createMatcherForOfficialSource(String officialSource) {
- return matchesFcpMessage(
- "LoadPlugin",
- "Identifier=" + identifier,
- "PluginURL=superPlugin",
- "URLType=official",
- "OfficialSource=" + officialSource,
- "EndMessage"
- );
- }
-
- }
-
- public class FromOtherSources {
-
- private static final String FILE_PATH = "/path/to/plugin.jar";
- private static final String URL = "http://server.com/plugin.jar";
- private static final String KEY = "KSK@plugin.jar";
-
- @Test
- public void fromFile() throws ExecutionException, InterruptedException, IOException {
- Future<Optional<PluginInfo>> pluginInfo = fcpClient.loadPlugin().fromFile(FILE_PATH).execute();
- connectAndAssert(() -> createMatcher("file", FILE_PATH));
- replyWithPluginInfo();
- verifyPluginInfo(pluginInfo);
- }
-
- @Test
- public void fromUrl() throws ExecutionException, InterruptedException, IOException {
- Future<Optional<PluginInfo>> pluginInfo = fcpClient.loadPlugin().fromUrl(URL).execute();
- connectAndAssert(() -> createMatcher("url", URL));
- replyWithPluginInfo();
- verifyPluginInfo(pluginInfo);
- }
-
- @Test
- public void fromFreenet() throws ExecutionException, InterruptedException, IOException {
- Future<Optional<PluginInfo>> pluginInfo = fcpClient.loadPlugin().fromFreenet(KEY).execute();
- connectAndAssert(() -> createMatcher("freenet", KEY));
- replyWithPluginInfo();
- verifyPluginInfo(pluginInfo);
- }
-
- private Matcher<List<String>> createMatcher(String urlType, String url) {
- return matchesFcpMessage(
- "LoadPlugin",
- "Identifier=" + identifier,
- "PluginURL=" + url,
- "URLType=" + urlType,
- "EndMessage"
- );
- }
-
- }
-
- public class Failed {
-
- @Test
- public void failedLoad() throws ExecutionException, InterruptedException, IOException {
- Future<Optional<PluginInfo>> pluginInfo =
- fcpClient.loadPlugin().officialFromFreenet("superPlugin").execute();
- connectNode();
- List<String> lines = fcpServer.collectUntil(is("EndMessage"));
- String identifier = extractIdentifier(lines);
- fcpServer.writeLine(
- "ProtocolError",
- "Identifier=" + identifier,
- "EndMessage"
- );
- assertThat(pluginInfo.get().isPresent(), is(false));
- }
-
- }
-