From 0eebf20f43604d6321db53f701f8ca3739c68d36 Mon Sep 17 00:00:00 2001 From: Jack <jack20220723@gmail.com> Date: Fri, 4 Oct 2024 00:34:19 +0800 Subject: [PATCH] update --- checkstyle.xml | 1 - pom.xml | 4 ++-- .../wilhelm/web/endpoints/DataServlet.java | 22 +++++++------------ .../web/endpoints/DataServletITSpec.groovy | 15 +++++++++---- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/checkstyle.xml b/checkstyle.xml index 758eb2a..2b46383 100755 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -140,7 +140,6 @@ <module name="JavadocMethod"> <property name="allowedAnnotations" value="Override"/> <property name="validateThrows" value="true"/> - <property name="scope" value="anoninner"/> <property name="allowMissingParamTags" value="false"/> <property name="allowMissingReturnTag" value="false"/> <property name="tokens" value="METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF"/> diff --git a/pom.xml b/pom.xml index cce952c..b701ac9 100644 --- a/pom.xml +++ b/pom.xml @@ -280,13 +280,13 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> - <version>3.1.2</version> + <version>3.4.0</version> <dependencies> <!-- override default checkstyle version --> <dependency> <groupId>com.puppycrawl.tools</groupId> <artifactId>checkstyle</artifactId> - <version>8.30</version> + <version>10.18.1</version> </dependency> </dependencies> <configuration> diff --git a/src/main/java/org/qubitpi/wilhelm/web/endpoints/DataServlet.java b/src/main/java/org/qubitpi/wilhelm/web/endpoints/DataServlet.java index 72329b2..14b5254 100644 --- a/src/main/java/org/qubitpi/wilhelm/web/endpoints/DataServlet.java +++ b/src/main/java/org/qubitpi/wilhelm/web/endpoints/DataServlet.java @@ -22,7 +22,6 @@ import org.neo4j.driver.GraphDatabase; import org.neo4j.driver.QueryConfig; import org.neo4j.driver.Value; -import org.neo4j.driver.exceptions.ClientException; import org.neo4j.driver.internal.types.InternalTypeSystem; import org.qubitpi.wilhelm.config.ApplicationConfig; @@ -42,13 +41,9 @@ import java.util.AbstractMap; import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.stream.StreamSupport; @@ -136,17 +131,14 @@ public Response getVocabularyByLanguagePaged( LANGUAGES.get(language), (Integer.parseInt(page) - 1) * Integer.parseInt(perPage), perPage ); - EagerResult result = executeNativeQuery(query); + final EagerResult result = executeNativeQuery(query); - Object responseBody = result.records() + final Object responseBody = result.records() .stream() .map( record -> record.keys() .stream() - .map(key -> new AbstractMap.SimpleImmutableEntry<>( - key, - expand(record.get(key)) - )) + .map(key -> new AbstractMap.SimpleImmutableEntry<>(key, expand(record.get(key)))) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)) ) .collect(Collectors.toList()); @@ -167,6 +159,7 @@ record -> record.keys() @GET @Path("/expand/{word}") @Produces(MediaType.APPLICATION_JSON) + @SuppressWarnings("MultipleStringLiterals") public Response expand(@NotNull @PathParam("word") final String word) { final String query = String.format( """ @@ -181,9 +174,10 @@ RETURN path, length(path) AS hops final EagerResult result = executeNativeQuery(query); - final Map<String, List<Map<String, Object>>> responseBody = new HashMap<>(); - responseBody.put("nodes", new ArrayList<>()); - responseBody.put("links", new ArrayList<>()); + final Map<String, List<Map<String, Object>>> responseBody = Map.of( + "nodes", new ArrayList<>(), + "links", new ArrayList<>() + ); result.records().stream() .map(record -> record.get("path").asPath()) diff --git a/src/test/groovy/org/qubitpi/wilhelm/web/endpoints/DataServletITSpec.groovy b/src/test/groovy/org/qubitpi/wilhelm/web/endpoints/DataServletITSpec.groovy index c091bcf..e6fc5c4 100644 --- a/src/test/groovy/org/qubitpi/wilhelm/web/endpoints/DataServletITSpec.groovy +++ b/src/test/groovy/org/qubitpi/wilhelm/web/endpoints/DataServletITSpec.groovy @@ -16,6 +16,8 @@ package org.qubitpi.wilhelm.web.endpoints import static org.hamcrest.Matchers.equalTo +import static org.hamcrest.Matchers.hasKey +import static org.hamcrest.Matchers.matchesPattern import org.hamcrest.Description import org.hamcrest.Matcher @@ -89,7 +91,7 @@ class DataServletITSpec extends Specification { .statusCode(200) } - def "Get vocabulary by language and retrieve the very first word"() { + def "Get vocabulary by language returns a list of map, with each entry containing 'term' and 'definition' keys"() { expect: RestAssured .given() @@ -100,10 +102,11 @@ class DataServletITSpec extends Specification { .get("/data/languages/german") .then() .statusCode(200) - .body("[0]", equalTo([term: "dieser", definition: "this"])) + .body("[0]", hasKey("term")) + .body("[0]", hasKey("definition")) } - def "Expand"() { + def "Expand a word returns a map of two keys - 'nodes' & 'links'"() { expect: RestAssured .given() @@ -113,6 +116,10 @@ class DataServletITSpec extends Specification { .get("/data/expand/nämlich") .then() .statusCode(200) - .body("[0]", equalTo([term: "dieser", definition: "this"])) + .body("", hasKey("nodes")) + .body("", hasKey("links")) + .body("nodes[0]", hasKey("id")) + .body("links[0]", hasKey("sourceNodeId")) + .body("links[0]", hasKey("targetNodeId")) } }