forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Neo4jFunctionalityTest.java
75 lines (64 loc) · 2.48 KB
/
Neo4jFunctionalityTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package io.quarkus.it.neo4j;
import static org.hamcrest.Matchers.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.hamcrest.Matcher;
import org.junit.jupiter.api.Test;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
/**
* Test connecting via Neo4j Java-Driver to Neo4j.
* Can quickly start a matching database with:
*
* <pre>
* docker run --publish=7474:7474 --publish=7687:7687 -e 'NEO4J_AUTH=neo4j/music' neo4j/neo4j-experimental:4.0.0-rc01
* </pre>
*/
@QuarkusTest
public class Neo4jFunctionalityTest {
@Test
public void testBlockingNeo4jFunctionality() {
RestAssured.given().when().get("/neo4j/blocking").then().body(is("OK"));
}
@Test
public void testAsynchronousNeo4jFunctionality() {
RestAssured.given()
.when().get("/neo4j/asynchronous")
.then().statusCode(200)
.body(is(equalTo(Stream.of(1, 2, 3).map(i -> i.toString()).collect(Collectors.joining(",", "[", "]")))));
}
@Test
public void testReactiveNeo4jFunctionality() {
RestAssured.given()
.when().get("/neo4j/reactive")
.prettyPeek()
.then().statusCode(200)
.contentType("text/event-stream");
}
@Test
public void health() {
RestAssured.when().get("/q/health/ready").then()
.log().all()
.body("status", is("UP"),
"checks.status", containsInAnyOrder("UP"),
"checks.name", containsInAnyOrder("Neo4j connection health check"),
"checks.data.server", containsInAnyOrder(matchesRegex("Neo4j/.*@.*:\\d*")));
}
@Test
public void metrics() {
RestAssured.given().when().get("/neo4j/blocking").then().body(is("OK"));
assertMetricValue("neo4j.acquired", greaterThan(0));
assertMetricValue("neo4j.created", greaterThan(0));
assertMetricValue("neo4j.totalAcquisitionTime", greaterThan(0));
assertMetricValue("neo4j.totalConnectionTime", greaterThan(0));
assertMetricValue("neo4j.totalInUseTime", greaterThan(0));
}
private void assertMetricValue(String name, Matcher<Integer> valueMatcher) {
RestAssured
.given().accept(ContentType.JSON)
.when().get("/q/metrics/vendor/" + name)
.then()
.body("'" + name + "'", valueMatcher);
}
}