Add uninstalled plugins to pending resource

This commit is contained in:
René Pfeuffer
2019-09-16 18:00:02 +02:00
parent fc319f90e3
commit 3e0169b667
2 changed files with 27 additions and 5 deletions

View File

@@ -61,16 +61,24 @@ public class PendingPluginResource {
Stream<InstalledPlugin> updatePlugins = installed Stream<InstalledPlugin> updatePlugins = installed
.stream() .stream()
.filter(i -> contains(pending, i)); .filter(i -> contains(pending, i));
Stream<InstalledPlugin> uninstallPlugins = installed
.stream()
.filter(InstalledPlugin::isMarkedForUninstall);
Links.Builder linksBuilder = linkingTo().self(resourceLinks.pendingPluginCollection().self()); Links.Builder linksBuilder = linkingTo().self(resourceLinks.pendingPluginCollection().self());
if (!pending.isEmpty()) { List<PluginDto> installDtos = newPlugins.map(mapper::mapAvailable).collect(toList());
List<PluginDto> updateDtos = updatePlugins.map(i -> mapper.mapInstalled(i, pending)).collect(toList());
List<PluginDto> uninstallDtos = uninstallPlugins.map(i -> mapper.mapInstalled(i, pending)).collect(toList());
if (!installDtos.isEmpty() || !updateDtos.isEmpty() || !uninstallDtos.isEmpty()) {
linksBuilder.single(link("install", resourceLinks.pendingPluginCollection().installPending())); linksBuilder.single(link("install", resourceLinks.pendingPluginCollection().installPending()));
} }
Embedded.Builder embedded = Embedded.embeddedBuilder(); Embedded.Builder embedded = Embedded.embeddedBuilder();
embedded.with("new", newPlugins.map(mapper::mapAvailable).collect(toList())); embedded.with("new", installDtos);
embedded.with("update", updatePlugins.map(i -> mapper.mapInstalled(i, pending)).collect(toList())); embedded.with("update", updateDtos);
embedded.with("uninstall", uninstallDtos);
return Response.ok(new HalRepresentation(linksBuilder.build(), embedded.build())).build(); return Response.ok(new HalRepresentation(linksBuilder.build(), embedded.build())).build();
} }

View File

@@ -30,6 +30,7 @@ import java.io.UnsupportedEncodingException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import static java.net.URI.create; import static java.net.URI.create;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList; import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
@@ -123,7 +124,6 @@ class PendingPluginResourceTest {
assertThat(response.getStatus()).isEqualTo(HttpServletResponse.SC_OK); assertThat(response.getStatus()).isEqualTo(HttpServletResponse.SC_OK);
assertThat(response.getContentAsString()).contains("\"new\":[{\"name\":\"pending-available-plugin\""); assertThat(response.getContentAsString()).contains("\"new\":[{\"name\":\"pending-available-plugin\"");
assertThat(response.getContentAsString()).contains("\"install\":{\"href\":\"/v2/plugins/pending/install\"}"); assertThat(response.getContentAsString()).contains("\"install\":{\"href\":\"/v2/plugins/pending/install\"}");
System.out.println(response.getContentAsString());
} }
@Test @Test
@@ -140,7 +140,21 @@ class PendingPluginResourceTest {
assertThat(response.getStatus()).isEqualTo(HttpServletResponse.SC_OK); assertThat(response.getStatus()).isEqualTo(HttpServletResponse.SC_OK);
assertThat(response.getContentAsString()).contains("\"update\":[{\"name\":\"available-plugin\""); assertThat(response.getContentAsString()).contains("\"update\":[{\"name\":\"available-plugin\"");
assertThat(response.getContentAsString()).contains("\"install\":{\"href\":\"/v2/plugins/pending/install\"}"); assertThat(response.getContentAsString()).contains("\"install\":{\"href\":\"/v2/plugins/pending/install\"}");
System.out.println(response.getContentAsString()); }
@Test
void shouldGetPendingUninstallPluginListWithInstallLink() throws URISyntaxException, UnsupportedEncodingException {
when(pluginManager.getAvailable()).thenReturn(emptyList());
InstalledPlugin installedPlugin = createInstalledPlugin("uninstalled-plugin");
when(installedPlugin.isMarkedForUninstall()).thenReturn(true);
when(pluginManager.getInstalled()).thenReturn(singletonList(installedPlugin));
MockHttpRequest request = MockHttpRequest.get("/v2/plugins/pending");
dispatcher.invoke(request, response);
assertThat(response.getStatus()).isEqualTo(HttpServletResponse.SC_OK);
assertThat(response.getContentAsString()).contains("\"uninstall\":[{\"name\":\"uninstalled-plugin\"");
assertThat(response.getContentAsString()).contains("\"install\":{\"href\":\"/v2/plugins/pending/install\"}");
} }
@Test @Test