Skip to content

Commit

Permalink
Upgrade to json-path-2.8.0
Browse files Browse the repository at this point in the history
* Fix `IntegrationGraphServerTests` to not use `net.minidev.json.JSONArray` API
since it is not available as transitive from `json-path` in the `testCompileClasspath`
  • Loading branch information
artembilan committed Apr 19, 2023
1 parent 1a579a6 commit 0391bed
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ ext {
jmsApiVersion = '3.1.0'
jpaApiVersion = '3.1.0'
jrubyVersion = '9.4.1.0'
jsonpathVersion = '2.7.0'
jsonpathVersion = '2.8.0'
junit4Version = '4.13.2'
junitJupiterVersion = '5.9.2'
jythonVersion = '2.7.3'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import io.micrometer.core.instrument.observation.DefaultMeterObservationHandler;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import io.micrometer.observation.ObservationRegistry;
import net.minidev.json.JSONArray;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -128,10 +127,10 @@ void test() throws Exception {
assertThat(nodes).isNotNull();
assertThat(nodes.size()).isEqualTo(35);

JSONArray jsonArray =
List<?> jsonArray =
JsonPathUtils.evaluate(baos.toByteArray(), "$..nodes[?(@.componentType == 'gateway')]");

assertThat(jsonArray.size()).isEqualTo(3);
assertThat(jsonArray).hasSize(3);

Map<String, Object> gateway1 = (Map<String, Object>) jsonArray.get(0);

Expand Down Expand Up @@ -159,9 +158,6 @@ void test() throws Exception {
this.testSource.receive();
this.expressionRouterInput.send(MessageBuilder.withPayload("foo").setHeader("foo", "fizChannel").build());

jsonArray = JsonPathUtils.evaluate(baos.toByteArray(), "$..nodes[?(@.name == 'router.router')]");
String routerJson = jsonArray.toJSONString();

this.server.rebuild();
graph = this.server.getGraph();
baos = new ByteArrayOutputStream();
Expand All @@ -181,13 +177,13 @@ void test() throws Exception {
assertThat(links.size()).isEqualTo(35);

jsonArray = JsonPathUtils.evaluate(baos.toByteArray(), "$..nodes[?(@.name == 'router.router')]");
routerJson = jsonArray.toJSONString();
String routerJson = jsonArray.toString();
assertThat(routerJson).contains("\"sendTimers\":{\"successes\":{\"count\":4");
jsonArray = JsonPathUtils.evaluate(baos.toByteArray(), "$..nodes[?(@.name == 'toRouter')]");
String toRouterJson = jsonArray.toJSONString();
String toRouterJson = jsonArray.toString();
assertThat(toRouterJson).contains("\"sendTimers\":{\"successes\":{\"count\":4");
jsonArray = JsonPathUtils.evaluate(baos.toByteArray(), "$..nodes[?(@.name == 'testSource')]");
String sourceJson = jsonArray.toJSONString();
String sourceJson = jsonArray.toString();
assertThat(sourceJson).contains("\"receiveCounters\":{\"successes\":1,\"failures\":0");

// stats refresh without rebuild()
Expand All @@ -196,29 +192,29 @@ void test() throws Exception {
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
objectMapper.writeValue(baos, graph);
jsonArray = JsonPathUtils.evaluate(baos.toByteArray(), "$..nodes[?(@.name == 'testSource')]");
sourceJson = jsonArray.toJSONString();
sourceJson = jsonArray.toString();
assertThat(sourceJson).contains("\"receiveCounters\":{\"successes\":2,\"failures\":0");

assertThatIllegalStateException().isThrownBy(() -> this.testSource.receive());
baos = new ByteArrayOutputStream();
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
objectMapper.writeValue(baos, graph);
jsonArray = JsonPathUtils.evaluate(baos.toByteArray(), "$..nodes[?(@.name == 'testSource')]");
sourceJson = jsonArray.toJSONString();
sourceJson = jsonArray.toString();
assertThat(sourceJson).contains("\"receiveCounters\":{\"successes\":2,\"failures\":1");

jsonArray =
JsonPathUtils.evaluate(baos.toByteArray(), "$..nodes[?(@.name == 'expressionRouter.router')]");

expressionRouter = (Map<String, Object>) jsonArray.get(0);
JSONArray routes = (JSONArray) expressionRouter.get("routes");
List<?> routes = (List<?>) expressionRouter.get("routes");
assertThat(routes).hasSize(1);
assertThat(routes.get(0)).isEqualTo("fizChannel");

Object routerNodeId = expressionRouter.get("nodeId");

Object fizChannelNodeId =
((JSONArray) JsonPathUtils.evaluate(baos.toByteArray(),
((List<?>) JsonPathUtils.evaluate(baos.toByteArray(),
"$..nodes[?(@.name == 'fizChannel')].nodeId")).get(0);

jsonArray =
Expand Down

0 comments on commit 0391bed

Please sign in to comment.