Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set to JsonObject.mergeIn(deep = true) for FileSet and stores #87

Open
wants to merge 2 commits into
base: 3.7
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private Future<Buffer> compute(List<File> files) {
} else {
JsonObject json = new JsonObject();
futures.stream().map(f -> (JsonObject) f.result())
.forEach(json::mergeIn);
.forEach(config -> json.mergeIn(config, true));
result.complete(Buffer.buffer(json.encode()));
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,31 @@ public void testWith2FileSetsAndWithIntersectionReversed(TestContext tc) throws

}

@Test
public void testWithDeepConfigMerge(TestContext tc) throws GitAPIException, IOException {
Async async = tc.async();
add(git, root, new File("src/test/resources/files/b.json"), "dir");
add(git, root, new File("src/test/resources/files/a.json"), "dir");
push(git);

retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions().addStore(new
ConfigStoreOptions().setType("git").setConfig(new JsonObject()
.put("url", bareRoot.getAbsolutePath())
.put("path", "target/junk/work")
.put("filesets", new JsonArray()
.add(new JsonObject().put("pattern", "dir/b.json"))
.add(new JsonObject().put("pattern", "dir/a.*son"))
))));

retriever.getConfig(ar -> {
// Both level-3 objects must exist.
assertThat(ar.result().getJsonObject("parent").getJsonObject("level_2").getString("key1")).isEqualTo("A");
assertThat(ar.result().getJsonObject("parent").getJsonObject("level_2").getString("key2")).isEqualTo("B");
async.complete();
});

}

@Test
public void testWithAFileSetMatching2FilesWithConflict(TestContext tc) throws GitAPIException, IOException {
Async async = tc.async();
Expand Down
9 changes: 7 additions & 2 deletions vertx-config-git/src/test/resources/files/a.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"a.name" : "A",
"conflict": "A"
}
"conflict": "A",
"parent": {
"level_2": {
"key1": "A"
}
}
}
9 changes: 7 additions & 2 deletions vertx-config-git/src/test/resources/files/b.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"b.name" : "B",
"conflict": "B"
}
"conflict": "B",
"parent": {
"level_2": {
"key2": "B"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private void parseFromStandard(JsonObject body, Handler<AsyncResult<Buffer>> han
for (int i = sources.size() - 1; i >= 0; i--) {
JsonObject source = sources.getJsonObject(i);
JsonObject content = source.getJsonObject("source");
configuration = configuration.mergeIn(content);
configuration = configuration.mergeIn(content, true);
}
handler.handle(Future.succeededFuture(Buffer.buffer(configuration.encode())));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void get(Handler<AsyncResult<Buffer>> completionHandler) {
} else {
JsonObject json = new JsonObject();
futures.stream().map(f -> (JsonObject) f.result())
.forEach(json::mergeIn);
.forEach(config -> json.mergeIn(config, true));
completionHandler.handle(Future.succeededFuture(Buffer.buffer(json.encode())));
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void buildConfiguration(List<File> files, Handler<AsyncResult<JsonObject>
JsonObject result = new JsonObject();
futures.stream()
.map(future -> (JsonObject) future.result())
.forEach(result::mergeIn);
.forEach(config -> result.mergeIn(config, true));
handler.handle(Future.succeededFuture(result));
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,24 @@ public void testWithAFileSetMatching2FilesWithConflict(TestContext context) {
});
}

@Test
public void testWithDeepConfigMerge(TestContext context) {
Async async = context.async();
retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions()
.addStore(new ConfigStoreOptions()
.setType("directory")
.setConfig(new JsonObject().put("path", "src/test/resources")
.put("filesets", new JsonArray()
.add(new JsonObject().put("pattern", "dir/?.json"))
))));
retriever.getConfig(ar -> {
// Both level-3 objects must exist.
assertThat(ar.result().getJsonObject("parent").getJsonObject("level_2").getString("key1")).isEqualTo("A");
assertThat(ar.result().getJsonObject("parent").getJsonObject("level_2").getString("key2")).isEqualTo("B");
async.complete();
});
}

@Test
public void testWithAFileSetMatching2FilesWithoutConflict(TestContext context) {
Async async = context.async();
Expand Down
9 changes: 7 additions & 2 deletions vertx-config/src/test/resources/dir/a.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"a.name" : "A",
"conflict": "A"
}
"conflict": "A",
"parent": {
"level_2": {
"key1": "A"
}
}
}
9 changes: 7 additions & 2 deletions vertx-config/src/test/resources/dir/b.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"b.name" : "B",
"conflict": "B"
}
"conflict": "B",
"parent": {
"level_2": {
"key2": "B"
}
}
}