@Test public void reload_list_if_plugin_uninstalled_during_blue_green_switch() throws IOException { WsTestUtil.mockReader(wsClient, "api/plugins/installed", new InputStreamReader(getClass().getResourceAsStream("ScannerPluginInstallerTest/blue-installed.json")), new InputStreamReader(getClass().getResourceAsStream("ScannerPluginInstallerTest/green-installed.json"))); enqueueNotFoundDownload("scmgit", "abc"); enqueueDownload("java", "def"); enqueueDownload("cobol", "ghi"); when(pluginPredicate.apply(any())).thenReturn(true); Map<String, ScannerPlugin> result = underTest.installRemotes(); assertThat(result.keySet()).containsExactlyInAnyOrder("java", "cobol"); }
@Test public void filter_blacklisted_plugins() throws IOException { WsTestUtil.mockReader(wsClient, "api/plugins/installed", new InputStreamReader(getClass().getResourceAsStream("ScannerPluginInstallerTest/installed-plugins-ws.json"))); enqueueDownload("scmgit", "abc"); enqueueDownload("java", "def"); when(pluginPredicate.apply("scmgit")).thenReturn(true); when(pluginPredicate.apply("java")).thenReturn(false); Map<String, ScannerPlugin> result = underTest.installRemotes(); assertThat(result.keySet()).containsExactlyInAnyOrder("scmgit"); verify(pluginFiles, times(1)).get(any()); }
@Test public void fail_if_plugin_not_found_two_times() throws IOException { WsTestUtil.mockReader(wsClient, "api/plugins/installed", new InputStreamReader(getClass().getResourceAsStream("ScannerPluginInstallerTest/blue-installed.json")), new InputStreamReader(getClass().getResourceAsStream("ScannerPluginInstallerTest/green-installed.json"))); enqueueDownload("scmgit", "abc"); enqueueDownload("cobol", "ghi"); enqueueNotFoundDownload("java", "def"); when(pluginPredicate.apply(any())).thenReturn(true); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Fail to download plugin [java]. Not found."); underTest.installRemotes(); }
@Test public void fail_if_json_of_installed_plugins_is_not_valid() { WsTestUtil.mockReader(wsClient, "api/plugins/installed", new StringReader("not json")); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Fail to parse response of api/plugins/installed"); underTest.installRemotes(); }
@Test public void download_installed_plugins() throws IOException { WsTestUtil.mockReader(wsClient, "api/plugins/installed", new InputStreamReader(getClass().getResourceAsStream("ScannerPluginInstallerTest/installed-plugins-ws.json"))); enqueueDownload("scmgit", "abc"); enqueueDownload("java", "def"); when(pluginPredicate.apply(any())).thenReturn(true); Map<String, ScannerPlugin> result = underTest.installRemotes(); assertThat(result.keySet()).containsExactlyInAnyOrder("scmgit", "java"); ScannerPlugin gitPlugin = result.get("scmgit"); assertThat(gitPlugin.getKey()).isEqualTo("scmgit"); assertThat(gitPlugin.getInfo().getNonNullJarFile()).exists().isFile(); assertThat(gitPlugin.getUpdatedAt()).isEqualTo(100L); ScannerPlugin javaPlugin = result.get("java"); assertThat(javaPlugin.getKey()).isEqualTo("java"); assertThat(javaPlugin.getInfo().getNonNullJarFile()).exists().isFile(); assertThat(javaPlugin.getUpdatedAt()).isEqualTo(200L); }