Skip to content

Commit

Permalink
add testEnvironmentNodeListing
Browse files Browse the repository at this point in the history
  • Loading branch information
aali309 committed Apr 2, 2024
1 parent 72a3c59 commit 144b9ba
Showing 1 changed file with 87 additions and 39 deletions.
126 changes: 87 additions & 39 deletions src/test/java/itest/GraphQLTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
Expand All @@ -34,8 +32,10 @@
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import io.cryostat.discovery.DiscoveryNode;
import io.cryostat.util.HttpMimeType;

import com.fasterxml.jackson.core.type.TypeReference;
import io.vertx.core.MultiMap;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.HttpHeaders;
Expand All @@ -55,7 +55,7 @@
import org.junit.jupiter.params.provider.ValueSource;

@TestMethodOrder(OrderAnnotation.class)
@Disabled("TODO not all GraphQL queries are implemented")
// @Disabled("TODO not all GraphQL queries are implemented")
class GraphQLTest extends StandardSelfTest {

private final ExecutorService worker = ForkJoinPool.commonPool();
Expand All @@ -69,39 +69,50 @@ void testEnvironmentNodeListing() throws Exception {
query.put(
"query",
"query { environmentNodes(filter: { name: \"Custom Targets\" }) { name nodeType"
+ " descendantTargets { name nodeType } } }");
+ " children { name nodeType } } }");

System.out.println("+++ Query sent: " + query.encodePrettily());

HttpResponse<Buffer> resp =
webClient
.extensions()
.post("/api/v2.2/graphql", query.toBuffer(), REQUEST_TIMEOUT_SECONDS);
MatcherAssert.assertThat(
resp.statusCode(),
Matchers.both(Matchers.greaterThanOrEqualTo(200)).and(Matchers.lessThan(300)));
EnvironmentNodesResponse actual =
mapper.readValue(resp.bodyAsString(), EnvironmentNodesResponse.class);

EnvironmentNodes expected = new EnvironmentNodes();
TypeReference<EnvironmentNodesResponse> typeRef =
new TypeReference<EnvironmentNodesResponse>() {};
EnvironmentNodesResponse actual = mapper.readValue(resp.bodyAsString(), typeRef);

EnvironmentNode jdp = new EnvironmentNode();
jdp.name = "JDP";
jdp.nodeType = "Realm";
List<DiscoveryNode> expectedChildren = new ArrayList<>();
DiscoveryNode expectedChild = new DiscoveryNode();
expectedChild.name = "service:jmx:rmi:///jndi/rmi://localhost:0/jmxrmi";
expectedChild.nodeType = "JVM";
expectedChildren.add(expectedChild);

jdp.descendantTargets = new ArrayList<>();
Node cryostat = new Node();
cryostat.name = "service:jmx:rmi:///jndi/rmi://localhost:0/jmxrmi";
cryostat.nodeType = "JVM";
jdp.descendantTargets.add(cryostat);
DiscoveryNode expectedNode = new DiscoveryNode();
expectedNode.name = "Custom Targets";
expectedNode.nodeType = "Realm";
expectedNode.children = expectedChildren;

assertThat(actual.getData().getEnvironmentNodes().size(), is(1));

Node target = new Node();
target.name = "service:jmx:rmi:///jndi/rmi://localhost:0/jmxrmi";
target.nodeType = "JVM";
jdp.descendantTargets.add(target);
DiscoveryNode actualNode = actual.getData().getEnvironmentNodes().get(0);

expected.environmentNodes = List.of(jdp);
assertThat(actualNode.name, is(expectedNode.name));
assertThat(actualNode.nodeType, is(expectedNode.nodeType));
assertThat(actualNode.children.size(), is(expectedNode.children.size()));

MatcherAssert.assertThat(actual.data, Matchers.equalTo(expected));
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));
}
}

@Disabled
@Test
@Order(1)
void testOtherContainersFound() throws Exception {
Expand Down Expand Up @@ -163,6 +174,7 @@ void testOtherContainersFound() throws Exception {
MatcherAssert.assertThat(actual.data.targetNodes, Matchers.hasItem(ext));
}

@Disabled
@Test
@Order(2)
void testQueryForSpecificTargetWithSpecificFields() throws Exception {
Expand Down Expand Up @@ -190,6 +202,7 @@ void testQueryForSpecificTargetWithSpecificFields() throws Exception {
MatcherAssert.assertThat(actual.data.targetNodes, Matchers.hasItem(ext));
}

@Disabled
@Test
@Order(3)
void testStartRecordingMutationOnSpecificTarget() throws Exception {
Expand Down Expand Up @@ -277,6 +290,7 @@ void testStartRecordingMutationOnSpecificTarget() throws Exception {
MatcherAssert.assertThat(actual.data, Matchers.equalTo(nodes));
}

@Disabled
@Test
@Order(4)
void testArchiveMutation() throws Exception {
Expand Down Expand Up @@ -314,6 +328,7 @@ void testArchiveMutation() throws Exception {
"^es-andrewazor-demo-Main_graphql-itest_[0-9]{8}T[0-9]{6}Z\\.jfr$"));
}

@Disabled
@Test
@Order(5)
void testActiveRecordingMetadataMutation() throws Exception {
Expand Down Expand Up @@ -360,6 +375,7 @@ void testActiveRecordingMetadataMutation() throws Exception {
"newValue"))));
}

@Disabled
@Test
@Order(6)
void testArchivedRecordingMetadataMutation() throws Exception {
Expand Down Expand Up @@ -407,6 +423,7 @@ void testArchivedRecordingMetadataMutation() throws Exception {
"newArchivedValue"))));
}

@Disabled
@Test
@Order(7)
void testDeleteMutation() throws Exception {
Expand Down Expand Up @@ -451,6 +468,7 @@ void testDeleteMutation() throws Exception {
"^es-andrewazor-demo-Main_graphql-itest_[0-9]{8}T[0-9]{6}Z\\.jfr$"));
}

/* @Disabled
@Test
@Order(8)
void testNodesHaveIds() throws Exception {
Expand Down Expand Up @@ -481,8 +499,9 @@ void testNodesHaveIds() throws Exception {
observedIds.add(target.id);
}
}
}
} */

@Disabled
@Test
@Order(9)
void testQueryForSpecificTargetsByNames() throws Exception {
Expand Down Expand Up @@ -521,6 +540,7 @@ void testQueryForSpecificTargetsByNames() throws Exception {
assertThat(targetNodes, hasItem(target2));
}

@Disabled
@Test
@Order(10)
public void testQueryForFilteredActiveRecordingsByNames() throws Exception {
Expand Down Expand Up @@ -653,6 +673,7 @@ public void testQueryForFilteredActiveRecordingsByNames() throws Exception {
Matchers.equalTo(0));
}

@Disabled
@Test
@Order(11)
public void shouldReturnArchivedRecordingsFilteredByNames() throws Exception {
Expand Down Expand Up @@ -876,6 +897,7 @@ public void shouldReturnArchivedRecordingsFilteredByNames() throws Exception {
}
}

/* @Disabled
@Test
@Order(12)
public void testQueryforFilteredEnvironmentNodesByNames() throws Exception {
Expand Down Expand Up @@ -906,8 +928,9 @@ public void testQueryforFilteredEnvironmentNodesByNames() throws Exception {
}
}
Assertions.assertTrue(nameExists, "Name not found");
}
} */

@Disabled
@Test
@Order(13)
void testReplaceAlwaysOnStoppedRecording() throws Exception {
Expand All @@ -932,6 +955,7 @@ void testReplaceAlwaysOnStoppedRecording() throws Exception {
}
}

@Disabled
@Test
@Order(14)
void testReplaceNeverOnStoppedRecording() throws Exception {
Expand Down Expand Up @@ -959,6 +983,7 @@ void testReplaceNeverOnStoppedRecording() throws Exception {
}
}

@Disabled
@Test
@Order(15)
void testReplaceStoppedOnStoppedRecording() throws Exception {
Expand All @@ -983,6 +1008,7 @@ void testReplaceStoppedOnStoppedRecording() throws Exception {
}
}

@Disabled
@ParameterizedTest
@ValueSource(strings = {"STOPPED", "NEVER"})
@Order(16)
Expand All @@ -1006,6 +1032,7 @@ void testReplaceStoppedOrNeverOnRunningRecording(String replace) throws Exceptio
}
}

@Disabled
@Test
@Order(17)
void testReplaceAlwaysOnRunningRecording() throws Exception {
Expand All @@ -1025,6 +1052,7 @@ void testReplaceAlwaysOnRunningRecording() throws Exception {
}
}

@Disabled
@Test
@Order(18)
void testRestartTrueOnRunningRecording() throws Exception {
Expand All @@ -1044,6 +1072,7 @@ void testRestartTrueOnRunningRecording() throws Exception {
}
}

@Disabled
@Test
@Order(19)
void testRestartFalseOnRunningRecording() throws Exception {
Expand All @@ -1066,6 +1095,7 @@ void testRestartFalseOnRunningRecording() throws Exception {
}
}

@Disabled
@Test
@Order(20)
void testRestartTrueOnStoppedRecording() throws Exception {
Expand All @@ -1090,6 +1120,7 @@ void testRestartTrueOnStoppedRecording() throws Exception {
}
}

@Disabled
@Test
@Order(21)
void testRestartFalseOnStoppedRecording() throws Exception {
Expand Down Expand Up @@ -1117,6 +1148,7 @@ void testRestartFalseOnStoppedRecording() throws Exception {
}
}

@Disabled
@ParameterizedTest
@ValueSource(strings = {"ALWAYS", "STOPPED", "NEVER"})
@Order(22)
Expand All @@ -1131,6 +1163,7 @@ void testStartRecordingwithReplaceNever(String replace) throws Exception {
}
}

@Disabled
@ParameterizedTest
@ValueSource(booleans = {true, false})
@Order(23)
Expand Down Expand Up @@ -1737,12 +1770,12 @@ public boolean equals(Object obj) {
}

static class EnvironmentNode extends Node {
List<Node> descendantTargets;
List<Node> children;

@Override
public String toString() {
return "EnvironmentNode [descendantTargets="
+ descendantTargets
return "EnvironmentNode [children ="
+ children
+ ", name="
+ name
+ ", nodeType="
Expand All @@ -1752,7 +1785,7 @@ public String toString() {

@Override
public int hashCode() {
return Objects.hash(descendantTargets);
return Objects.hash(children);
}

@Override
Expand All @@ -1767,12 +1800,20 @@ public boolean equals(Object obj) {
return false;
}
EnvironmentNode other = (EnvironmentNode) obj;
return Objects.equals(descendantTargets, other.descendantTargets);
return Objects.equals(children, other.children);
}
}

static class EnvironmentNodes {
List<EnvironmentNode> environmentNodes;
public class EnvironmentNodes {
private List<EnvironmentNode> environmentNodes;

public List<EnvironmentNode> getEnvironmentNodes() {
return environmentNodes;
}

public void setEnvironmentNodes(List<EnvironmentNode> environmentNodes) {
this.environmentNodes = environmentNodes;
}

@Override
public String toString() {
Expand Down Expand Up @@ -1800,21 +1841,28 @@ public boolean equals(Object obj) {
}
}

static class EnvironmentNodesResponse {
EnvironmentNodes data;

@Override
public String toString() {
return "EnvironmentNodesResponse [data=" + data + "]";
}
public static class EnvironmentNodesResponse {
private Data data;

public EnvironmentNodes getData() {
public Data getData() {
return data;
}

public void setData(EnvironmentNodes data) {
public void setData(Data data) {
this.data = data;
}

public static class Data {
private List<DiscoveryNode> environmentNodes;

public List<DiscoveryNode> getEnvironmentNodes() {
return environmentNodes;
}

public void setEnvironmentNodes(List<DiscoveryNode> environmentNodes) {
this.environmentNodes = environmentNodes;
}
}
}

static class ArchiveMutationResponse {
Expand Down

0 comments on commit 144b9ba

Please sign in to comment.