public Object get(Optional<String> configPrefix, Map<String, Object> config) { return config.get(StringUtils.join(".", configPrefix, Optional.of(key))); } public <T> T getAndConvert(Optional<String> configPrefix, Map<String, Object> config, Class<T> clazz) {
@Test public void testPatchParserFromKeyValue() throws Exception { // push the parser config File configFile = new File(parsersDir, "myparser.json"); TestUtils.write(configFile, squidParserConfig); pushConfigs(PARSER, configDir, Optional.of("myparser")); // patch the parser configuration patchConfigs(PARSER, Optional.empty(), Optional.of("myparser"), Optional.of(ADD), Optional.of("/parserConfig/timestampField"), Optional.of("\"\"heyjoe\"\"")); // validate the patch byte[] expected = JSONUtils.INSTANCE.toJSONPretty(expectedPatchedParser); byte[] actual = JSONUtils.INSTANCE.toJSONPretty(stripLines(dumpConfigs(PARSER, Optional.of("myparser")), 1)); Assert.assertThat(actual, equalTo(expected)); }
@Test public void testPatchGlobalFromComplexKeyValue() throws Exception { // write a global configuration File configFile = new File(configDir, "global.json"); TestUtils.write(configFile, globalConfig); pushConfigs(GLOBAL, configDir, Optional.of("global")); // patch the global configuration patchConfigs(GLOBAL, Optional.empty(), Optional.of("global"), Optional.of(ADD), Optional.of("/foo"), Optional.of("{ \"bar\" : { \"baz\" : [ \"bazval1\", \"bazval2\" ] } }")); // validate the patch byte[] expected = JSONUtils.INSTANCE.toJSONPretty(expectedComplexConfig); byte[] actual = JSONUtils.INSTANCE.toJSONPretty(stripLines(dumpConfigs(GLOBAL, Optional.of("global")), 1)); Assert.assertThat(actual, equalTo(expected)); }
@Test public void testPatchParserFromFile() throws Exception { // create a patch file File patchFile = new File(tmpDir, "parser-patch.json"); TestUtils.write(patchFile, someParserPatch); // create a parser configuration File configFile = new File(parsersDir, "myparser.json"); TestUtils.write(configFile, squidParserConfig); pushConfigs(PARSER, configDir, Optional.of("myparser")); // patch the configuration patchConfigs(PARSER, Optional.of(patchFile), Optional.of("myparser"), Optional.empty(), Optional.empty(), Optional.empty()); // validate the patch byte[] expected = JSONUtils.INSTANCE.toJSONPretty(expectedPatchedParser); byte[] actual = JSONUtils.INSTANCE.toJSONPretty(stripLines(dumpConfigs(PARSER, Optional.of("myparser")), 1)); Assert.assertThat(actual, equalTo(expected)); }
@Test public void testPushIndexing() throws Exception { // write the indexing config File configFile = new File(indexingDir, "myindex.json"); TestUtils.write(configFile, someIndexingConfig); // push the index config pushConfigs(INDEXING, configDir, Optional.of("myindex")); // validate byte[] expected = JSONUtils.INSTANCE.toJSONPretty(someIndexingConfig); byte[] actual = JSONUtils.INSTANCE.toJSONPretty(stripLines(dumpConfigs(INDEXING, Optional.of("myindex")), 1)); Assert.assertThat(actual, equalTo(expected)); }
@Test public void testPatchGlobalFromFile() throws Exception { // create a patch file File patchFile = new File(tmpDir, "global-config-patch.json"); TestUtils.write(patchFile, somePatchConfig); // create the global config File configFile = new File(configDir, "global.json"); TestUtils.write(configFile, globalConfig); pushConfigs(GLOBAL, configDir, Optional.of("global")); // patch the global config patchConfigs(GLOBAL, Optional.of(patchFile), Optional.of("global"), Optional.empty(), Optional.empty(), Optional.empty()); // validate the patch byte[] expected = JSONUtils.INSTANCE.toJSONPretty(expectedSomeConfig); byte[] actual = JSONUtils.INSTANCE.toJSONPretty(stripLines(dumpConfigs(GLOBAL, Optional.of("global")), 1)); Assert.assertThat(actual, equalTo(expected)); }
@Test public void testPushParser() throws Exception { // create a parser config File configFile = new File(parsersDir, "myparser.json"); TestUtils.write(configFile, squidParserConfig); // push the parser config pushConfigs(PARSER, configDir, Optional.of("myparser")); // validate byte[] expected = JSONUtils.INSTANCE.toJSONPretty(squidParserConfig); byte[] actual = JSONUtils.INSTANCE.toJSONPretty(stripLines(dumpConfigs(PARSER, Optional.of("myparser")), 1)); Assert.assertThat(actual, equalTo(expected)); }
@Test public void testPushEnrichment() throws Exception { // create enrichment config File configFile = new File(enrichmentsDir, "myenrichment.json"); TestUtils.write(configFile, someEnrichmentConfig); // push enrichment config pushConfigs(ENRICHMENT, configDir, Optional.of("myenrichment")); // validate byte[] expected = JSONUtils.INSTANCE.toJSONPretty(someEnrichmentConfig); byte[] actual = JSONUtils.INSTANCE.toJSONPretty(stripLines(dumpConfigs(ENRICHMENT, Optional.of("myenrichment")), 1)); Assert.assertThat(actual, equalTo(expected)); }
@Test public void testPushProfiler() throws Exception { // create the profiler config File configFile = new File(configDir, "profiler.json"); TestUtils.write(configFile, someProfilerConfig); // push the profiler config Optional<String> configName = Optional.empty(); pushConfigs(PROFILER, configDir, configName); // validate byte[] expected = JSONUtils.INSTANCE.toJSONPretty(someProfilerConfig); byte[] actual = JSONUtils.INSTANCE.toJSONPretty(stripLines(dumpConfigs(PROFILER, configName), 1)); Assert.assertThat(actual, equalTo(expected)); }
@Test public void testPushGlobal() throws Exception { // create the config File configFile = new File(configDir, "global.json"); TestUtils.write(configFile, globalConfig); // push the global config pushConfigs(GLOBAL, configDir); // validate byte[] expected = JSONUtils.INSTANCE.toJSONPretty(globalConfig); byte[] actual = JSONUtils.INSTANCE.toJSONPretty(stripLines(dumpConfigs(GLOBAL), 1)); Assert.assertThat(actual, equalTo(expected)); }