@Test public void testOverrideByUserProperties() { myLog.debug( "Calling productive code" ); myClassUnderTest.overrideByUserProperties(); String name = SdiMainProperties.USER_OVERRIDE_PREFIX + ConfigUtils.makePropertyResourceName( InputCollectorMappingProperties.class ); Assert.assertNotNull( myEnv.getPropertySources().get( name ) ); Assert.assertEquals( "universe", myEnv.getProperty( "hello" ) ); Assert.assertEquals( "Screenname", myEnv.getProperty( "inputcollector.thing.alternateName" ) ); }
public void overrideByUserProperties() { List<Class<?>> candidates = findCandidates(); for ( Class<?> clazz : candidates ) { myLog.debug( "candidate for user property overloading: " + clazz.getName() ); String fileName = SdiMainProperties.USER_OVERRIDE_PREFIX + ConfigUtils.makePropertyResourceName( clazz ); InputStream is = this.getClass().getResourceAsStream( "/" + fileName ); if ( is == null ) { myLog.debug( "Skipping non existing user overloading property file: " + fileName ); continue; } myLog.debug( "Found overloading property file: " + fileName ); Properties props = new Properties(); try { props.load( is ); } catch ( IOException t ) { myLog.error( "Problems loading property file " + fileName ); } myEnv.setIgnoreUnresolvableNestedPlaceholders( true ); try { props.stringPropertyNames().stream() .map( key -> { String origValue = myEnv.getProperty( key ); String result = "Key " + key + ": "; return ( origValue == null || origValue.isEmpty() ) ? result + "No default value found. Adding new value to environment: \"" + props.getProperty( key ) + "\"" : result + "Overriding default value \"" + origValue + "\" with new value: \"" + props.getProperty( key ) + "\""; }) .forEach( msg -> myLog.debug( msg ) ) ; } finally { myEnv.setIgnoreUnresolvableNestedPlaceholders( false ); } PropertySource<?> ps = new PropertiesPropertySource( fileName, props ); MutablePropertySources mps = myEnv.getPropertySources(); if ( mps.get( ConfigUtils.PROP_SOURCE_NAME_CMD_LINE ) != null ) { mps.addAfter( ConfigUtils.PROP_SOURCE_NAME_CMD_LINE, ps ); } else { mps.addFirst( ps ); } myLog.debug( "PropertySources after adding overloading: " + mps ); } }
UserPropertyOverloader { public void overrideByUserProperties() { List<Class<?>> candidates = findCandidates(); for ( Class<?> clazz : candidates ) { myLog.debug( "candidate for user property overloading: " + clazz.getName() ); String fileName = SdiMainProperties.USER_OVERRIDE_PREFIX + ConfigUtils.makePropertyResourceName( clazz ); InputStream is = this.getClass().getResourceAsStream( "/" + fileName ); if ( is == null ) { myLog.debug( "Skipping non existing user overloading property file: " + fileName ); continue; } myLog.debug( "Found overloading property file: " + fileName ); Properties props = new Properties(); try { props.load( is ); } catch ( IOException t ) { myLog.error( "Problems loading property file " + fileName ); } myEnv.setIgnoreUnresolvableNestedPlaceholders( true ); try { props.stringPropertyNames().stream() .map( key -> { String origValue = myEnv.getProperty( key ); String result = "Key " + key + ": "; return ( origValue == null || origValue.isEmpty() ) ? result + "No default value found. Adding new value to environment: \"" + props.getProperty( key ) + "\"" : result + "Overriding default value \"" + origValue + "\" with new value: \"" + props.getProperty( key ) + "\""; }) .forEach( msg -> myLog.debug( msg ) ) ; } finally { myEnv.setIgnoreUnresolvableNestedPlaceholders( false ); } PropertySource<?> ps = new PropertiesPropertySource( fileName, props ); MutablePropertySources mps = myEnv.getPropertySources(); if ( mps.get( ConfigUtils.PROP_SOURCE_NAME_CMD_LINE ) != null ) { mps.addAfter( ConfigUtils.PROP_SOURCE_NAME_CMD_LINE, ps ); } else { mps.addFirst( ps ); } myLog.debug( "PropertySources after adding overloading: " + mps ); } } }
UserPropertyOverloader { public void overrideByUserProperties() { List<Class<?>> candidates = findCandidates(); for ( Class<?> clazz : candidates ) { myLog.debug( "candidate for user property overloading: " + clazz.getName() ); String fileName = SdiMainProperties.USER_OVERRIDE_PREFIX + ConfigUtils.makePropertyResourceName( clazz ); InputStream is = this.getClass().getResourceAsStream( "/" + fileName ); if ( is == null ) { myLog.debug( "Skipping non existing user overloading property file: " + fileName ); continue; } myLog.debug( "Found overloading property file: " + fileName ); Properties props = new Properties(); try { props.load( is ); } catch ( IOException t ) { myLog.error( "Problems loading property file " + fileName ); } myEnv.setIgnoreUnresolvableNestedPlaceholders( true ); try { props.stringPropertyNames().stream() .map( key -> { String origValue = myEnv.getProperty( key ); String result = "Key " + key + ": "; return ( origValue == null || origValue.isEmpty() ) ? result + "No default value found. Adding new value to environment: \"" + props.getProperty( key ) + "\"" : result + "Overriding default value \"" + origValue + "\" with new value: \"" + props.getProperty( key ) + "\""; }) .forEach( msg -> myLog.debug( msg ) ) ; } finally { myEnv.setIgnoreUnresolvableNestedPlaceholders( false ); } PropertySource<?> ps = new PropertiesPropertySource( fileName, props ); MutablePropertySources mps = myEnv.getPropertySources(); if ( mps.get( ConfigUtils.PROP_SOURCE_NAME_CMD_LINE ) != null ) { mps.addAfter( ConfigUtils.PROP_SOURCE_NAME_CMD_LINE, ps ); } else { mps.addFirst( ps ); } myLog.debug( "PropertySources after adding overloading: " + mps ); } } UserPropertyOverloader(); }
UserPropertyOverloader { public void overrideByUserProperties() { List<Class<?>> candidates = findCandidates(); for ( Class<?> clazz : candidates ) { myLog.debug( "candidate for user property overloading: " + clazz.getName() ); String fileName = SdiMainProperties.USER_OVERRIDE_PREFIX + ConfigUtils.makePropertyResourceName( clazz ); InputStream is = this.getClass().getResourceAsStream( "/" + fileName ); if ( is == null ) { myLog.debug( "Skipping non existing user overloading property file: " + fileName ); continue; } myLog.debug( "Found overloading property file: " + fileName ); Properties props = new Properties(); try { props.load( is ); } catch ( IOException t ) { myLog.error( "Problems loading property file " + fileName ); } myEnv.setIgnoreUnresolvableNestedPlaceholders( true ); try { props.stringPropertyNames().stream() .map( key -> { String origValue = myEnv.getProperty( key ); String result = "Key " + key + ": "; return ( origValue == null || origValue.isEmpty() ) ? result + "No default value found. Adding new value to environment: \"" + props.getProperty( key ) + "\"" : result + "Overriding default value \"" + origValue + "\" with new value: \"" + props.getProperty( key ) + "\""; }) .forEach( msg -> myLog.debug( msg ) ) ; } finally { myEnv.setIgnoreUnresolvableNestedPlaceholders( false ); } PropertySource<?> ps = new PropertiesPropertySource( fileName, props ); MutablePropertySources mps = myEnv.getPropertySources(); if ( mps.get( ConfigUtils.PROP_SOURCE_NAME_CMD_LINE ) != null ) { mps.addAfter( ConfigUtils.PROP_SOURCE_NAME_CMD_LINE, ps ); } else { mps.addFirst( ps ); } myLog.debug( "PropertySources after adding overloading: " + mps ); } } UserPropertyOverloader(); void overrideByUserProperties(); }
UserPropertyOverloader { public void overrideByUserProperties() { List<Class<?>> candidates = findCandidates(); for ( Class<?> clazz : candidates ) { myLog.debug( "candidate for user property overloading: " + clazz.getName() ); String fileName = SdiMainProperties.USER_OVERRIDE_PREFIX + ConfigUtils.makePropertyResourceName( clazz ); InputStream is = this.getClass().getResourceAsStream( "/" + fileName ); if ( is == null ) { myLog.debug( "Skipping non existing user overloading property file: " + fileName ); continue; } myLog.debug( "Found overloading property file: " + fileName ); Properties props = new Properties(); try { props.load( is ); } catch ( IOException t ) { myLog.error( "Problems loading property file " + fileName ); } myEnv.setIgnoreUnresolvableNestedPlaceholders( true ); try { props.stringPropertyNames().stream() .map( key -> { String origValue = myEnv.getProperty( key ); String result = "Key " + key + ": "; return ( origValue == null || origValue.isEmpty() ) ? result + "No default value found. Adding new value to environment: \"" + props.getProperty( key ) + "\"" : result + "Overriding default value \"" + origValue + "\" with new value: \"" + props.getProperty( key ) + "\""; }) .forEach( msg -> myLog.debug( msg ) ) ; } finally { myEnv.setIgnoreUnresolvableNestedPlaceholders( false ); } PropertySource<?> ps = new PropertiesPropertySource( fileName, props ); MutablePropertySources mps = myEnv.getPropertySources(); if ( mps.get( ConfigUtils.PROP_SOURCE_NAME_CMD_LINE ) != null ) { mps.addAfter( ConfigUtils.PROP_SOURCE_NAME_CMD_LINE, ps ); } else { mps.addFirst( ps ); } myLog.debug( "PropertySources after adding overloading: " + mps ); } } UserPropertyOverloader(); void overrideByUserProperties();  }