Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Sort rows in Extension configuration status table by configuration name #149

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ConfigurationStatus {
public class ConfigurationStatus implements Comparable<ConfigurationStatus> {
private @NotNull String name;
private @NotNull Status status;
private @NotNull String details;

public ConfigurationStatus(@NotNull String name, @NotNull Status status) {
this(name, status, "");
}

@Override
public int compareTo(@NotNull ConfigurationStatus o) {
return name.compareTo(o.name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,27 @@
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<ConfigurationStatus> getAllStatuses(String scope) {
public static Collection<ConfigurationStatus> getAllStatuses(String scope) {
Context context = new Context(scope);
Set<Class<? extends ConfigurationStatusProvider>> subTypes = ContextUtils.findSubTypes(ConfigurationStatusProvider.class);
List<ConfigurationStatus> statuses = new ArrayList<>();
Collection<ConfigurationStatus> statuses = new TreeSet<>();
for (Class<? extends ConfigurationStatusProvider> subType : subTypes) {
ConfigurationStatusProvider provider = subType.getConstructor().newInstance();
statuses.addAll(provider.getStatuses(context));
}
return statuses;
}

public @NotNull List<ConfigurationStatus> getStatuses(@NotNull Context context) {
public @NotNull Collection<ConfigurationStatus> getStatuses(@NotNull Context context) {
return List.of(getStatus(context));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
Expand Down Expand Up @@ -91,7 +92,7 @@
</tbody>
</table>

<% List<ConfigurationStatus> configurationStatuses = ConfigurationStatusProvider.getAllStatuses(request.getParameter("scope")); %>
<% Collection<ConfigurationStatus> configurationStatuses = ConfigurationStatusProvider.getAllStatuses(request.getParameter("scope")); %>
<% if (!configurationStatuses.isEmpty()) { %>
<h3>Extension configuration status</h3>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -19,7 +20,7 @@ class ConfigurationStatusProviderTest {
void testGetAllStatuses() {
try (MockedStatic<ContextUtils> contextUtilsMockedStatic = mockStatic(ContextUtils.class)) {
contextUtilsMockedStatic.when(() -> ContextUtils.findSubTypes(any())).thenReturn(Set.of(TestSingleProvider.class, TestMultipleProvider.class));
List<ConfigurationStatus> statuses = ConfigurationStatusProvider.getAllStatuses("some scope");
Collection<ConfigurationStatus> statuses = ConfigurationStatusProvider.getAllStatuses("some scope");
assertEquals(3, statuses.size());
assertTrue(statuses.containsAll(List.of(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here we need to check not contains all, but the sequence in alphabetical order. could you please change the validation?

new ConfigurationStatus("single", Status.OK, "single details"),
Expand Down
Loading