From 75550d45b85924bc9675f523698b1127e60fa536 Mon Sep 17 00:00:00 2001 From: Dzmitry Yurtsevich Date: Mon, 2 Sep 2024 19:53:52 +0200 Subject: [PATCH] fix: Sort rows in Extension configuration status table by configuration name (#150) Refs: #148 --- .../configuration/ConfigurationStatus.java | 9 +++++++-- .../ConfigurationStatusProvider.java | 11 ++++++----- .../META-INF/resources/common/jsp/about.jsp | 3 ++- .../ConfigurationStatusProviderTest.java | 15 +++++++++------ 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/ch/sbb/polarion/extension/generic/configuration/ConfigurationStatus.java b/app/src/main/java/ch/sbb/polarion/extension/generic/configuration/ConfigurationStatus.java index 7c78241..246d04f 100644 --- a/app/src/main/java/ch/sbb/polarion/extension/generic/configuration/ConfigurationStatus.java +++ b/app/src/main/java/ch/sbb/polarion/extension/generic/configuration/ConfigurationStatus.java @@ -10,7 +10,7 @@ @Builder @NoArgsConstructor @AllArgsConstructor -public class ConfigurationStatus { +public class ConfigurationStatus implements Comparable { private @NotNull String name; private @NotNull Status status; private @NotNull String details; @@ -18,4 +18,9 @@ public class ConfigurationStatus { public ConfigurationStatus(@NotNull String name, @NotNull Status status) { this(name, status, ""); } -} + + @Override + public int compareTo(@NotNull ConfigurationStatus o) { + return name.compareTo(o.name); + } +} \ No newline at end of file diff --git a/app/src/main/java/ch/sbb/polarion/extension/generic/configuration/ConfigurationStatusProvider.java b/app/src/main/java/ch/sbb/polarion/extension/generic/configuration/ConfigurationStatusProvider.java index 8c9d194..d8d4188 100644 --- a/app/src/main/java/ch/sbb/polarion/extension/generic/configuration/ConfigurationStatusProvider.java +++ b/app/src/main/java/ch/sbb/polarion/extension/generic/configuration/ConfigurationStatusProvider.java @@ -8,18 +8,19 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Set; +import java.util.TreeSet; @SuppressWarnings("unused") public abstract class ConfigurationStatusProvider { @SneakyThrows - public static List getAllStatuses(String scope) { + public static Collection getAllStatuses(String scope) { Context context = new Context(scope); Set> subTypes = ContextUtils.findSubTypes(ConfigurationStatusProvider.class); - List statuses = new ArrayList<>(); + Collection statuses = new TreeSet<>(); for (Class subType : subTypes) { ConfigurationStatusProvider provider = subType.getConstructor().newInstance(); statuses.addAll(provider.getStatuses(context)); @@ -27,7 +28,7 @@ public static List getAllStatuses(String scope) { return statuses; } - public @NotNull List getStatuses(@NotNull Context context) { + public @NotNull Collection getStatuses(@NotNull Context context) { return List.of(getStatus(context)); } @@ -56,4 +57,4 @@ private static boolean contains(@NotNull String input, @NotNull String regex) { public static class Context { private String scope; } -} +} \ No newline at end of file diff --git a/app/src/main/resources/META-INF/resources/common/jsp/about.jsp b/app/src/main/resources/META-INF/resources/common/jsp/about.jsp index 7ce6869..7915b02 100644 --- a/app/src/main/resources/META-INF/resources/common/jsp/about.jsp +++ b/app/src/main/resources/META-INF/resources/common/jsp/about.jsp @@ -12,6 +12,7 @@ <%@ page import="ch.sbb.polarion.extension.generic.rest.model.Context" %> <%@ page import="ch.sbb.polarion.extension.generic.configuration.ConfigurationStatus" %> <%@ page import="ch.sbb.polarion.extension.generic.configuration.ConfigurationStatusProvider" %> +<%@ page import="java.util.Collection" %> <%@ page contentType="text/html; charset=UTF-8" %> @@ -91,7 +92,7 @@ - <% List configurationStatuses = ConfigurationStatusProvider.getAllStatuses(request.getParameter("scope")); %> + <% Collection configurationStatuses = ConfigurationStatusProvider.getAllStatuses(request.getParameter("scope")); %> <% if (!configurationStatuses.isEmpty()) { %>

Extension configuration status

diff --git a/app/src/test/java/ch/sbb/polarion/extension/generic/configuration/ConfigurationStatusProviderTest.java b/app/src/test/java/ch/sbb/polarion/extension/generic/configuration/ConfigurationStatusProviderTest.java index 60412b9..96ae659 100644 --- a/app/src/test/java/ch/sbb/polarion/extension/generic/configuration/ConfigurationStatusProviderTest.java +++ b/app/src/test/java/ch/sbb/polarion/extension/generic/configuration/ConfigurationStatusProviderTest.java @@ -5,6 +5,7 @@ import org.junit.jupiter.api.Test; import org.mockito.MockedStatic; +import java.util.Collection; import java.util.List; import java.util.Set; @@ -19,13 +20,15 @@ class ConfigurationStatusProviderTest { void testGetAllStatuses() { try (MockedStatic contextUtilsMockedStatic = mockStatic(ContextUtils.class)) { contextUtilsMockedStatic.when(() -> ContextUtils.findSubTypes(any())).thenReturn(Set.of(TestSingleProvider.class, TestMultipleProvider.class)); - List statuses = ConfigurationStatusProvider.getAllStatuses("some scope"); + Collection statuses = ConfigurationStatusProvider.getAllStatuses("some scope"); + assertEquals(3, statuses.size()); - assertTrue(statuses.containsAll(List.of( - new ConfigurationStatus("single", Status.OK, "single details"), - new ConfigurationStatus("multiple 1", Status.WARNING, "multiple 1 details"), - new ConfigurationStatus("multiple 2", Status.ERROR, "multiple 2 details") - ))); + + // Check alphabetical order of configurations + ConfigurationStatus[] statusesArray = statuses.toArray(new ConfigurationStatus[0]); + assertEquals(statusesArray[0], new ConfigurationStatus("multiple 1", Status.WARNING, "multiple 1 details")); + assertEquals(statusesArray[1], new ConfigurationStatus("multiple 2", Status.ERROR, "multiple 2 details")); + assertEquals(statusesArray[2], new ConfigurationStatus("single", Status.OK, "single details")); } }