Skip to content

Commit

Permalink
Add JSON5 merge test case
Browse files Browse the repository at this point in the history
  • Loading branch information
ks-yim committed Dec 10, 2021
1 parent 7e79ea2 commit 5723c68
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ default <T> CompletableFuture<MergedEntry<T>> mergeFiles(Revision revision, Merg
requireNonNull(query, "query");

final List<MergeSource> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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();
Expand Down Expand Up @@ -113,31 +116,31 @@ 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();
String expectedJson =
'{' +
" \"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);
}
Expand Down Expand Up @@ -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";

Expand Down Expand Up @@ -220,27 +223,27 @@ 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\"" +
" }" +
'}';
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();
body =
'{' +
" \"path\" : \"/foo2.json\"," +
" \"type\" : \"UPSERT_JSON\"," +
" \"content\" : {\"a\": \"new_bar\"}," +
" \"content\" : {\"a\": \"new_bar\", \"c\": \"new_qux\"}," +
" \"commitMessage\" : {" +
" \"summary\" : \"Add foo3.json\"" +
" }" +
Expand Down

0 comments on commit 5723c68

Please sign in to comment.