ModuleMetadata implements MetadataNode { public Optional<ConfigMetadataNode> findConfig(String configPath) { String[] split = splitFirstComponent(configPath); for (ConfigMetadataNode c : configs) { if (c.getName().equals(split[0])) { return findConfig(c, split[1]); } } return Optional.empty(); } private  ModuleMetadata(); static Builder builder(); static Builder builder(String name); @Override String getName(); String getProviderName(); @Override String getDescription(); Collection<ConfigMetadataNode> getConfigs(); Optional<ConfigMetadataNode> findConfig(String configPath);  }
@Test public void testFindConfig() { ConfigObjectMetadata c1 = ConfigObjectMetadata.builder("r1") .description("r1 desc") .type(Object.class) .addProperty(ConfigValueMetadata.builder("r1_p1").description("r1_p1 desc").type(String.class).build()) .addProperty(ConfigValueMetadata.builder("r1_p2").description("r1_p2 desc").type(Boolean.TYPE).build()) .build(); ConfigMapMetadata c2 = ConfigMapMetadata .builder("r2") .description("r2 desc") .keysType(String.class) .valuesType(c1).build(); ConfigObjectMetadata c3 = ConfigObjectMetadata .builder("r3") .description("r3 desc") .type(Object.class) .addProperty(c2) .build(); ModuleMetadata md = ModuleMetadata.builder("x").addConfig(c3).build(); Optional<ConfigMetadataNode> r1 = md.findConfig("r3.r2.somekey"); assertTrue(r1.isPresent()); assertEquals("r1", r1.get().getName()); assertEquals("r1 desc", r1.get().getDescription()); assertEquals(Object.class, r1.get().getType()); Optional<ConfigMetadataNode> r1P2 = md.findConfig("r3.r2.somekey.r1_p2"); assertTrue(r1P2.isPresent()); assertEquals("r1_p2", r1P2.get().getName()); assertEquals("r1_p2 desc", r1P2.get().getDescription()); assertEquals(Boolean.TYPE, r1P2.get().getType()); }