Skip to content

Commit

Permalink
Pass 'hierarchical' property down to processors for FileSet
Browse files Browse the repository at this point in the history
The change is tested in DirectoryConfigStoreTest.

Signed-off-by: Johannes Leupold <[email protected]>
  • Loading branch information
Traderjoe95 authored and vietj committed May 10, 2021
1 parent 805c1cf commit 0d5037e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class FileSet {
private final File root;
private final Vertx vertx;
private final Boolean rawData;
private final Boolean hierarchical;

/**
* Creates a new {@link FileSet} from a json object.
Expand All @@ -60,6 +61,7 @@ public FileSet(Vertx vertx, File root, JsonObject set) {
throw new IllegalArgumentException("Each file set needs to contain a `pattern`");
}
this.rawData = set.getBoolean("raw-data", false);
this.hierarchical = set.getBoolean("hierarchical", false);
String format = set.getString("format", "json");
this.processor = Processors.get(format);
if (this.processor == null) {
Expand Down Expand Up @@ -107,7 +109,9 @@ public void buildConfiguration(List<File> files, Handler<AsyncResult<JsonObject>
if (buffer.failed()) {
promise.fail(buffer.cause());
} else {
processor.process(vertx, new JsonObject().put("raw-data", rawData), buffer.result()).onComplete(promise);
processor.process(vertx, new JsonObject().put("raw-data", rawData)
.put("hierarchical", hierarchical), buffer.result())
.onComplete(promise);
}
});
} catch (RejectedExecutionException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,38 @@ public void testLoadingASinglePropertiesFileWithRawData(TestContext context) {
});
}

@Test
public void testLoadingASinglePropertiesFileHierarchical(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("format", "properties")
.put("pattern", "**/hierarchical.properties")
.put("hierarchical", true))))));

JsonObject expected = new JsonObject()
.put("server", new JsonObject()
.put("port", 8080)
.put("host", "http://localhost")
)
.put("some", new JsonObject()
.put("double", new JsonObject().put("value", 1.0))
.put("integer", new JsonObject().put("values", new JsonArray().add(1).add(2).add(3)))
)
.put("single", 0);

retriever.getConfig(ar -> {
assertThat(ar.succeeded()).isTrue();
JsonObject json = ar.result();
assertThat(json).isEqualTo(expected);

async.complete();
});
}


@Test
public void testWhenNoFileMatch(TestContext context) {
Expand Down

0 comments on commit 0d5037e

Please sign in to comment.