From 5672df4c5e713524e7c5268be7eeb71b0fbb56b4 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Tue, 25 Jun 2024 14:39:39 -0400 Subject: [PATCH] resolve more issues --- .../io/cryostat/discovery/DiscoveryNode.java | 14 ++++++ src/test/java/itest/GraphQLTest.java | 43 +++++++++++-------- 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/src/main/java/io/cryostat/discovery/DiscoveryNode.java b/src/main/java/io/cryostat/discovery/DiscoveryNode.java index 9df011891..f2f229410 100644 --- a/src/main/java/io/cryostat/discovery/DiscoveryNode.java +++ b/src/main/java/io/cryostat/discovery/DiscoveryNode.java @@ -177,6 +177,20 @@ public boolean equals(Object obj) { && Objects.equals(children, other.children); } + @Override + public String toString() { + return "DiscoveryNode{" + + "name='" + + name + + '\'' + + ", nodeType='" + + nodeType + + '\'' + + ", children=" + + children + + '}'; + } + @ApplicationScoped static class Listener { diff --git a/src/test/java/itest/GraphQLTest.java b/src/test/java/itest/GraphQLTest.java index 43637217b..92f0d28ea 100644 --- a/src/test/java/itest/GraphQLTest.java +++ b/src/test/java/itest/GraphQLTest.java @@ -24,6 +24,7 @@ import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; +import java.util.Comparator; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -49,8 +50,11 @@ import io.vertx.core.json.JsonObject; import io.vertx.ext.web.client.HttpResponse; import itest.bases.StandardSelfTest; +import org.hamcrest.Matcher; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; +import org.hamcrest.collection.IsIterableContainingInOrder; +import org.hamcrest.comparator.ComparatorMatcherBuilder; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; import org.junit.jupiter.api.Order; @@ -79,7 +83,7 @@ void testEnvironmentNodeListing() throws Exception { HttpResponse resp = webClient .extensions() - .post("/api/v2.2/graphql", query.toBuffer(), REQUEST_TIMEOUT_SECONDS); + .post("/api/v3/graphql", query.toBuffer(), REQUEST_TIMEOUT_SECONDS); MatcherAssert.assertThat( resp.statusCode(), Matchers.both(Matchers.greaterThanOrEqualTo(200)).and(Matchers.lessThan(300))); @@ -102,17 +106,25 @@ void testEnvironmentNodeListing() throws Exception { assertThat(actual.getData().getEnvironmentNodes().size(), is(1)); DiscoveryNode actualNode = actual.getData().getEnvironmentNodes().get(0); - assertThat(actualNode.name, is(expectedNode.name)); assertThat(actualNode.nodeType, is(expectedNode.nodeType)); assertThat(actualNode.children.size(), is(expectedNode.children.size())); - for (int i = 0; i < actualNode.children.size(); i++) { - DiscoveryNode actualChild = actualNode.children.get(i); - DiscoveryNode expectedChildNode = expectedNode.children.get(i); - assertThat(actualChild.name, is(expectedChildNode.name)); - assertThat(actualChild.nodeType, is(expectedChildNode.nodeType)); - } + Comparator byNameAndType = + Comparator.comparing((DiscoveryNode node) -> node.name) + .thenComparing(node -> node.nodeType); + Matcher> listMatcher = + IsIterableContainingInOrder.contains( + expectedChildren.stream() + .map( + child -> + ComparatorMatcherBuilder.comparedBy(byNameAndType) + .comparesEqualTo(child)) + .collect(Collectors.toList())); + assertThat( + "Children nodes do not match expected configuration", + actualNode.children, + listMatcher); } @Test @@ -513,11 +525,9 @@ void testDeleteMutation() throws Exception { DeleteMutationResponse actual = mapper.readValue(resp2.bodyAsString(), DeleteMutationResponse.class); - MatcherAssert.assertThat(actual.getData().getTargetNodes(), Matchers.hasSize(1)); TargetNode node = actual.getData().getTargetNodes().get(0); - MatcherAssert.assertThat( node.getTarget().getRecordings().getActive().getData(), Matchers.hasSize(1)); MatcherAssert.assertThat( @@ -536,7 +546,6 @@ void testDeleteMutation() throws Exception { MatcherAssert.assertThat(activeRecording.name, Matchers.equalTo("test")); MatcherAssert.assertThat(activeRecording.doDelete.name, Matchers.equalTo("test")); - MatcherAssert.assertThat( archivedRecording.name, Matchers.matchesRegex("^selftest_test_[0-9]{8}T[0-9]{6}Z\\.jfr$")); @@ -546,13 +555,9 @@ void testDeleteMutation() throws Exception { @Order(8) void testNodesHaveIds() throws Exception { - // Create a mock instance of RootNode RootNode rootNode = mock(RootNode.class); - - // Create instances of DiscoveryNode and set properties manually DiscoveryNode node1 = new DiscoveryNode(); - node1.id = - 1L; // Setting ID directly if it's public; if not, use setter methods if available + node1.id = 1L; DiscoveryNode node2 = new DiscoveryNode(); node2.id = 2L; @@ -1070,7 +1075,6 @@ public boolean equals(Object obj) { Target other = (Target) obj; return Objects.equals(alias, other.alias) && Objects.equals(connectUrl, other.connectUrl) - && Objects.equals(jvmId, other.jvmId) && Objects.equals(annotations, other.annotations) && Objects.equals(recordings, other.recordings); } @@ -2306,6 +2310,11 @@ public List getEnvironmentNodes() { public void setEnvironmentNodes(List environmentNodes) { this.environmentNodes = environmentNodes; } + + @Override + public String toString() { + return "Data{environmentNodes=" + environmentNodes + '}'; + } } @Override