From 5723c68cacaad6746565d1de05b136e9123281a2 Mon Sep 17 00:00:00 2001 From: "K.S. Yim" Date: Fri, 10 Dec 2021 14:37:52 +0900 Subject: [PATCH] Add JSON5 merge test case --- .../server/storage/repository/Repository.java | 2 +- .../server/internal/api/MergeFileTest.java | 39 ++++++++++--------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/server/src/main/java/com/linecorp/centraldogma/server/storage/repository/Repository.java b/server/src/main/java/com/linecorp/centraldogma/server/storage/repository/Repository.java index d64f33dc8b..bbd65af264 100644 --- a/server/src/main/java/com/linecorp/centraldogma/server/storage/repository/Repository.java +++ b/server/src/main/java/com/linecorp/centraldogma/server/storage/repository/Repository.java @@ -505,7 +505,7 @@ default CompletableFuture> mergeFiles(Revision revision, Merg requireNonNull(query, "query"); final List mergeSources = query.mergeSources(); - // Only JSON files can currently be merged. + // Only JSON and JSON5 files can currently be merged. mergeSources.forEach(path -> validateJsonFilePath(path.path(), "path")); final Revision normalizedRevision; diff --git a/server/src/test/java/com/linecorp/centraldogma/server/internal/api/MergeFileTest.java b/server/src/test/java/com/linecorp/centraldogma/server/internal/api/MergeFileTest.java index a56a38cdf7..ce72936ea0 100644 --- a/server/src/test/java/com/linecorp/centraldogma/server/internal/api/MergeFileTest.java +++ b/server/src/test/java/com/linecorp/centraldogma/server/internal/api/MergeFileTest.java @@ -56,8 +56,10 @@ void mergeJsonFiles() { addFilesForMergeJson(client); // The property "a" in "/foo.json" is overwritten by the property "a" in "/foo2.json" + //// and the property "b" in "/foo.json" is overwritten by the property "b" in "/foo1.json5". + //// and the property "c" in "/foo1.json5" is overwritten by the property "c" in "/foo2.json". String queryString = "path=/foo.json" + '&' + - "path=/foo1.json" + '&' + + "path=/foo1.json5" + '&' + "path=/foo2.json" + '&' + "optional_path=/foo3.json"; @@ -70,14 +72,15 @@ void mergeJsonFiles() { " \"type\" : \"JSON\"," + " \"content\" : {" + " \"a\" : \"new_bar\"," + - " \"b\" : \"baz\" " + + " \"b\" : \"new_baz\"," + + " \"c\" : \"new_qux\"" + " }," + - " \"paths\" : [\"/foo.json\", \"/foo1.json\", \"/foo2.json\"] " + + " \"paths\" : [\"/foo.json\", \"/foo1.json5\", \"/foo2.json\"] " + '}'; assertThatJson(aRes.contentUtf8()).isEqualTo(expectedJson); queryString = "path=/foo.json" + '&' + - "path=/foo1.json" + '&' + + "path=/foo1.json5" + '&' + "path=/foo2.json" + '&' + "path=/foo3.json"; aRes = client.get("/api/v1/projects/myPro/repos/myRepo/merge?" + queryString).aggregate().join(); @@ -113,9 +116,9 @@ void mergeJsonPaths() { final WebClient client = dogma.httpClient(); addFilesForMergeJson(client); String queryString = "path=/foo.json" + '&' + - "path=/foo1.json" + '&' + + "path=/foo1.json5" + '&' + "path=/foo2.json" + '&' + - "jsonpath=$[?(@.b == \"baz\")]&jsonpath=$[0].b"; + "jsonpath=$[?(@.b == \"new_baz\")]&jsonpath=$[0].b"; AggregatedHttpResponse aRes = client.get("/api/v1/projects/myPro/repos/myRepo/merge?" + queryString).aggregate().join(); @@ -123,21 +126,21 @@ void mergeJsonPaths() { '{' + " \"revision\" : 4," + " \"type\" : \"JSON\"," + - " \"content\" : \"baz\"," + - " \"paths\" : [\"/foo.json\", \"/foo1.json\", \"/foo2.json\"] " + + " \"content\" : \"new_baz\"," + + " \"paths\" : [\"/foo.json\", \"/foo1.json5\", \"/foo2.json\"] " + '}'; assertThatJson(aRes.contentUtf8()).isEqualTo(expectedJson); queryString = "path=/foo.json" + '&' + - "path=/foo1.json" + '&' + + "path=/foo1.json5" + '&' + "path=/foo2.json" + '&' + - "jsonpath=$.c"; + "jsonpath=$.d"; aRes = client.get("/api/v1/projects/myPro/repos/myRepo/merge?" + queryString).aggregate().join(); assertThat(aRes.status()).isEqualTo(HttpStatus.BAD_REQUEST); expectedJson = '{' + " \"exception\": \"com.linecorp.centraldogma.common.QueryExecutionException\"," + - " \"message\": \"JSON path evaluation failed: $.c\"" + + " \"message\": \"JSON path evaluation failed: $.d\"" + '}'; assertThatJson(aRes.contentUtf8()).isEqualTo(expectedJson); } @@ -181,7 +184,7 @@ void mismatchedValueWhileMerging() { client.execute(headers, body).aggregate().join(); final String queryString = "path=/foo.json" + '&' + - "path=/foo1.json" + '&' + + "path=/foo1.json5" + '&' + "path=/foo2.json" + '&' + "path=/foo10.json"; @@ -220,7 +223,7 @@ private static void addFilesForMergeJson(WebClient client) { '{' + " \"path\" : \"/foo.json\"," + " \"type\" : \"UPSERT_JSON\"," + - " \"content\" : {\"a\": \"bar\"}," + + " \"content\" : {\"a\": \"bar\", \"b\": \"baz\"}," + " \"commitMessage\" : {" + " \"summary\" : \"Add foo.json\"" + " }" + @@ -228,11 +231,11 @@ private static void addFilesForMergeJson(WebClient client) { client.execute(headers, body).aggregate().join(); body = '{' + - " \"path\" : \"/foo1.json\"," + - " \"type\" : \"UPSERT_JSON\"," + - " \"content\" : {\"b\": \"baz\"}," + + " \"path\" : \"/foo1.json5\"," + + " \"type\" : \"UPSERT_JSON5\"," + + " \"content\" : \"{\\n // comments\\n b: 'new_baz',\\n c: 'qux',\\n}\\n\"," + " \"commitMessage\" : {" + - " \"summary\" : \"Add foo1.json\"" + + " \"summary\" : \"Add foo1.json5\"" + " }" + '}'; client.execute(headers, body).aggregate().join(); @@ -240,7 +243,7 @@ private static void addFilesForMergeJson(WebClient client) { '{' + " \"path\" : \"/foo2.json\"," + " \"type\" : \"UPSERT_JSON\"," + - " \"content\" : {\"a\": \"new_bar\"}," + + " \"content\" : {\"a\": \"new_bar\", \"c\": \"new_qux\"}," + " \"commitMessage\" : {" + " \"summary\" : \"Add foo3.json\"" + " }" +