ConfigMapper { Collection<ConfigProperty> getGlobalProperties() { return globalPropertiesMap.values(); } @Inject  ConfigMapper(final AppConfig appConfig); static void decorateWithPropertyPaths(final AppConfig appConfig); boolean validatePropertyPath(final PropertyPath fullPath); Optional<Prop> getProp(final PropertyPath propertyPath); static final String LIST_EXAMPLE; static final String MAP_EXAMPLE; static final String DOCREF_EXAMPLE; }
@Test void getGlobalProperties() throws IOException, ConfigurationException { AppConfig appConfig = getAppConfig(); ConfigMapper configMapper = new ConfigMapper(appConfig); Collection<ConfigProperty> configProperties = configMapper.getGlobalProperties(); String txt = configProperties.stream() .sorted(Comparator.comparing(ConfigProperty::getName)) .map(configProperty -> LogUtil.message("{} - [{}] - [{}] - [{}] - [{}] - [{}] - [{}]", configProperty.getName(), configProperty.getDefaultValue().orElse(""), configProperty.getDatabaseOverrideValue().getValueOrElse("UNSET", null), configProperty.getYamlOverrideValue().getValueOrElse("UNSET", null), configProperty.getEffectiveValue().orElse(""), configProperty.getSource(), configProperty.getDescription())) .collect(Collectors.joining("\n")); LOGGER.debug("Properties\n{}", txt); }
@Test void testGetGlobalProperties_defaultValueWithValue() { AppConfig appConfig = getAppConfig(); String initialValue = appConfig.getPipelineConfig().getReferenceDataConfig().getLocalDir(); String newValue = initialValue + "xxx"; appConfig.getPipelineConfig().getReferenceDataConfig().setLocalDir(newValue); ConfigMapper configMapper = new ConfigMapper(appConfig); final Collection<ConfigProperty> configProperties = configMapper.getGlobalProperties(); final ConfigProperty configProperty = configProperties.stream() .filter(confProp -> confProp.getName() .equalsIgnoreCase(PropertyPath.fromPathString("stroom.pipeline.referenceData.localDir"))) .findFirst() .orElseThrow(); assertValues(configProperty, initialValue, OverrideValue.unSet(String.class), OverrideValue.with(newValue), newValue); }
@Test void testGetGlobalProperties_defaultValueWithNullValue() { AppConfig appConfig = getAppConfig(); String initialValue = appConfig.getPipelineConfig().getReferenceDataConfig().getLocalDir(); String newYamlValue = null; appConfig.getPipelineConfig().getReferenceDataConfig().setLocalDir(newYamlValue); ConfigMapper configMapper = new ConfigMapper(appConfig); final Collection<ConfigProperty> configProperties = configMapper.getGlobalProperties(); final ConfigProperty configProperty = configProperties.stream() .filter(confProp -> confProp.getName().equalsIgnoreCase(PropertyPath.fromPathString("stroom.pipeline.referenceData.localDir"))) .findFirst() .orElseThrow(); assertValues( configProperty, initialValue, OverrideValue.unSet(String.class), OverrideValue.with(newYamlValue), newYamlValue); }
@Test void testGetGlobalProperties2() { TestConfig testConfig = new TestConfig(); ConfigMapper configMapper = new ConfigMapper(testConfig); Collection<ConfigProperty> configProperties = configMapper.getGlobalProperties(); configProperties.forEach(configProperty -> LOGGER.debug("{} - {}", configProperty.getName(), configProperty.getEffectiveValue().orElse(null))); }
@Test void testFindPropsWithNoDescription() { final ConfigMapper configMapper = new ConfigMapper(new AppConfig()); final Collection<ConfigProperty> configProperties = configMapper.getGlobalProperties(); LOGGER.info("Properties with no description"); final List<String> propsWithNoDesc = configProperties.stream() .filter(configProperty -> configProperty.getDescription() == null || configProperty.getDescription().isEmpty()) .map(ConfigProperty::getName) .map(PropertyPath::toString) .sorted() .peek(name -> LOGGER.info("{}", name)) .collect(Collectors.toList()); org.assertj.core.api.Assertions.assertThat(propsWithNoDesc) .isEmpty(); }