You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2022/03/01 12:44:54 UTC

[sling-org-apache-sling-event] branch master updated: SLING-11167 - Sling jobs inventory printer for json produces invalid json

This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-event.git


The following commit(s) were added to refs/heads/master by this push:
     new f89ff5b  SLING-11167 - Sling jobs inventory printer for json produces invalid json
f89ff5b is described below

commit f89ff5bfad3faa52c3782b890ebba437786cbd2c
Author: AnguloHerrera <na...@gmail.com>
AuthorDate: Tue Mar 1 13:42:59 2022 +0100

    SLING-11167 - Sling jobs inventory printer for json produces invalid json
    
    Fix json output in correct format
---
 .../sling/event/impl/jobs/console/InventoryPlugin.java   |  3 +--
 .../event/impl/jobs/console/InventoryPluginTest.java     | 16 +++++++++++-----
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/src/main/java/org/apache/sling/event/impl/jobs/console/InventoryPlugin.java b/src/main/java/org/apache/sling/event/impl/jobs/console/InventoryPlugin.java
index b81c302..9f345c0 100644
--- a/src/main/java/org/apache/sling/event/impl/jobs/console/InventoryPlugin.java
+++ b/src/main/java/org/apache/sling/event/impl/jobs/console/InventoryPlugin.java
@@ -35,7 +35,6 @@ import org.apache.sling.discovery.InstanceDescription;
 import org.apache.sling.event.impl.jobs.JobConsumerManager;
 import org.apache.sling.event.impl.jobs.config.InternalQueueConfiguration;
 import org.apache.sling.event.impl.jobs.config.JobManagerConfiguration;
-import org.apache.sling.event.impl.jobs.config.QueueConfigurationManager;
 import org.apache.sling.event.impl.jobs.config.TopologyCapabilities;
 import org.apache.sling.event.jobs.JobManager;
 import org.apache.sling.event.jobs.Queue;
@@ -442,7 +441,7 @@ public class InventoryPlugin implements InventoryPrinter {
             pw.printf("      \"stateInfo\" : \"%s\",%n", q.getStateInfo());
             pw.println("      \"configuration\" : {");
             pw.printf("        \"type\" : \"%s\",%n", c.getType());
-            pw.printf("        \"topics\" : \"%s\",%n", formatArrayAsJson(c.getTopics()));
+            pw.printf("        \"topics\" : %s,%n", formatArrayAsJson(c.getTopics()));
             pw.printf("        \"maxParallel\" : %s,%n", c.getMaxParallel());
             pw.printf("        \"maxRetries\" : %s,%n", c.getMaxRetries());
             pw.printf("        \"retryDelayInMs\" : %s,%n", c.getRetryDelayInMs());
diff --git a/src/test/java/org/apache/sling/event/impl/jobs/console/InventoryPluginTest.java b/src/test/java/org/apache/sling/event/impl/jobs/console/InventoryPluginTest.java
index f2c7d98..8c27b90 100644
--- a/src/test/java/org/apache/sling/event/impl/jobs/console/InventoryPluginTest.java
+++ b/src/test/java/org/apache/sling/event/impl/jobs/console/InventoryPluginTest.java
@@ -48,9 +48,8 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.equalTo;
-import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
+import static com.jayway.jsonpath.matchers.JsonPathMatchers.*;
+import static org.hamcrest.Matchers.*;
 import static org.junit.Assert.assertThat;
 
 public class InventoryPluginTest extends JsonTestBase {
@@ -88,6 +87,7 @@ public class InventoryPluginTest extends JsonTestBase {
 
         QueueConfiguration mockConfiguration = Mockito.mock(QueueConfiguration.class);
         Mockito.when(mockConfiguration.getType()).thenReturn(QueueConfiguration.Type.ORDERED);
+        Mockito.when(mockConfiguration.getTopics()).thenReturn(new String[]{"topic-1", "topic-2"});
         Mockito.when(mockQueue.getConfiguration()).thenReturn(mockConfiguration);
         Mockito.when(jobManager.getQueues()).thenReturn(new ArrayList<>(Arrays.asList(mockQueue)));
 
@@ -187,7 +187,7 @@ public class InventoryPluginTest extends JsonTestBase {
                 put("$.queues[0].statistics.averageWaitingTime", 0);
                 put("$.queues[0].configuration", null);
                 put("$.queues[0].configuration.type", "ORDERED");
-                put("$.queues[0].configuration.topics", "[]");
+                put("$.queues[0].configuration.topics", new String[]{"topic-1", "topic-2"});
                 put("$.queues[0].configuration.maxParallel", 0);
                 put("$.queues[0].configuration.maxRetries", 0);
                 put("$.queues[0].configuration.retryDelayInMs", 0);
@@ -217,7 +217,13 @@ public class InventoryPluginTest extends JsonTestBase {
 
             expectedJsonPaths.forEach((k, v) -> {
                 if (v != null) {
-                    assertThat(json, hasJsonPath(k, equalTo(v)));
+                    if (v instanceof String[]) {
+                        for (String val : (String[]) v) {
+                            assertThat(json, isJson(withJsonPath(k, hasItem(val))));
+                        }
+                    } else {
+                        assertThat(json, hasJsonPath(k, equalTo(v)));
+                    }
                 } else {
                     assertThat(json, hasJsonPath(k));
                 }