Skip to content

Commit

Permalink
exposed documenteddefaultvalue in ConfigValue
Browse files Browse the repository at this point in the history
  • Loading branch information
spacecowboy committed Mar 8, 2017
1 parent 954f6ad commit fde3dfd
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 22 deletions.
Expand Up @@ -72,8 +72,8 @@ public Optional<String> documentedDefaultValue() {
public List<ConfigValue> asConfigValues( @Nonnull Map<String,String> validConfig )
{
return settingGroup.values( validConfig ).entrySet().stream()
.map( val -> new ConfigValue( val.getKey(), description(), Optional.ofNullable( val.getValue() ),
internal, deprecated, replacement ) )
.map( val -> new ConfigValue( val.getKey(), description(), documentedDefaultValue(),
Optional.ofNullable( val.getValue() ), internal, deprecated, replacement ) )
.collect( Collectors.toList() );
}

Expand Down
Expand Up @@ -29,16 +29,19 @@ public class ConfigValue
{
private final String name;
private final Optional<String> description;
private final Optional<String> documentedDefaultValue;
private final Optional<?> value;
private final boolean internal;
private final boolean deprecated;
private final Optional<String> replacement;

public ConfigValue( @Nonnull String name, @Nonnull Optional<String> description, @Nonnull Optional<?> value,
public ConfigValue( @Nonnull String name, @Nonnull Optional<String> description,
@Nonnull Optional<String> documentedDefaultValue, @Nonnull Optional<?> value,
boolean internal, boolean deprecated, @Nonnull Optional<String> replacement )
{
this.name = name;
this.description = description;
this.documentedDefaultValue = documentedDefaultValue;
this.value = value;
this.internal = internal;
this.deprecated = deprecated;
Expand Down Expand Up @@ -84,4 +87,10 @@ public boolean internal()
{
return internal;
}

@Nonnull
public Optional<String> getDocumentedDefaultValue()
{
return documentedDefaultValue;
}
}
Expand Up @@ -32,7 +32,7 @@ public class ConfigValueTest
@Test
public void handlesEmptyValue() throws Exception
{
ConfigValue value = new ConfigValue( "name", Optional.empty(), Optional.empty(), false, false, Optional.empty() );
ConfigValue value = new ConfigValue( "name", Optional.empty(), Optional.empty(), Optional.empty(), false, false, Optional.empty() );

assertEquals( Optional.empty(), value.value() );
assertEquals( "null", value.toString() );
Expand All @@ -44,16 +44,16 @@ public void handlesEmptyValue() throws Exception
@Test
public void handlesInternal() throws Exception
{
ConfigValue value = new ConfigValue( "name", Optional.empty(), Optional.empty(), true, false, Optional.empty
() );
ConfigValue value = new ConfigValue( "name", Optional.empty(), Optional.empty(), Optional.empty(), true, false,
Optional.empty() );

assertTrue( value.internal() );
}

@Test
public void handlesNonEmptyValue() throws Exception
{
ConfigValue value = new ConfigValue( "name", Optional.empty(), Optional.of( 1 ), false, false, Optional.empty() );
ConfigValue value = new ConfigValue( "name", Optional.empty(), Optional.empty(), Optional.of( 1 ), false, false, Optional.empty() );

assertEquals( Optional.of( 1 ), value.value() );
assertEquals( "1", value.toString() );
Expand All @@ -65,7 +65,7 @@ public void handlesNonEmptyValue() throws Exception
@Test
public void handlesDeprecationAndReplacement() throws Exception
{
ConfigValue value = new ConfigValue( "old_name", Optional.empty(), Optional.of( 1 ), false, true,
ConfigValue value = new ConfigValue( "old_name", Optional.empty(), Optional.empty(), Optional.of( 1 ), false, true,
Optional.of( "new_name" ) );

assertEquals( Optional.of( 1 ), value.value() );
Expand Down
Expand Up @@ -30,6 +30,7 @@
import java.util.Optional;
import javax.annotation.Nonnull;

import org.neo4j.configuration.DocumentedDefaultValue;
import org.neo4j.configuration.Internal;
import org.neo4j.configuration.LoadableConfig;
import org.neo4j.configuration.ReplacedBy;
Expand Down Expand Up @@ -89,6 +90,7 @@ public static class MySettingsWithDefaults implements LoadableConfig
public static final Setting<Boolean> boolSetting = setting( "bool_setting", BOOLEAN, Settings.TRUE );

@Internal
@DocumentedDefaultValue( "<documented default value>" )
public static final Setting<Boolean> secretSetting = setting( "secret_setting", BOOLEAN, Settings.TRUE );

@Deprecated
Expand Down Expand Up @@ -233,12 +235,8 @@ public void shouldSetInternalParameter()
throws Exception
{
// Given
Log log = mock( Log.class );
File confFile = testDirectory.file( "test.conf" );
assertTrue( confFile.createNewFile() );

Config config =
new Config( Optional.of( confFile ),
new Config( Optional.empty(),
stringMap( MySettingsWithDefaults.secretSetting.name(), "false",
MySettingsWithDefaults.hello.name(), "ABC"),
s -> {},
Expand All @@ -250,6 +248,27 @@ public void shouldSetInternalParameter()
assertFalse( config.getConfigValues().get( MySettingsWithDefaults.hello.name() ).internal() );
}

@Test
public void shouldSetDocumentedDefaultValue()
throws Exception
{
// Given
Config config =
new Config( Optional.empty(),
stringMap( MySettingsWithDefaults.secretSetting.name(), "false",
MySettingsWithDefaults.hello.name(), "ABC"),
s -> {},
Collections.emptyList(), Optional.empty(),
Arrays.asList( mySettingsWithDefaults, myMigratingSettings ) );

// Then
assertEquals( Optional.of( "<documented default value>" ),
config.getConfigValues().get( MySettingsWithDefaults.secretSetting.name() )
.getDocumentedDefaultValue() );
assertEquals( Optional.empty(),
config.getConfigValues().get( MySettingsWithDefaults.hello.name() ).getDocumentedDefaultValue() );
}

@Test
public void shouldPassOnValidatorsOnWithMethods() throws Exception
{
Expand Down
Expand Up @@ -19,11 +19,11 @@
*/
package org.neo4j.server.configuration;

import org.junit.Test;

import java.util.List;
import java.util.Map.Entry;

import org.junit.Test;

import org.neo4j.kernel.configuration.Config;

import static java.util.stream.Collectors.toList;
Expand All @@ -38,14 +38,16 @@ public void webServerThreadCountDefaultShouldBeDocumented() throws Exception
{
Config config = Config.serverDefaults();

String documentedDefaultValue = config.getDocumentedDefaults().entrySet().stream()
.filter( c -> c.getKey().equals( ServerSettings.webserver_max_threads.name() ) )
.findAny()
.orElseThrow( () -> new RuntimeException( "Setting not present!" ) )
.getValue()
.orElseThrow( () -> new RuntimeException( "Default value not present!" ) );
String documentedDefaultValue =
config.getConfigValues().entrySet().stream()
.filter( c -> c.getKey().equals( ServerSettings.webserver_max_threads.name() ) )
.map( Entry::getValue )
.findAny()
.orElseThrow( () -> new RuntimeException( "Setting not present!" ) )
.getDocumentedDefaultValue()
.orElseThrow( () -> new RuntimeException( "Default value not present!" ) );

assertEquals( "Number of available processors (max 500).", documentedDefaultValue);
assertEquals( "Number of available processors (max 500).", documentedDefaultValue );
}

@Test
Expand Down

0 comments on commit fde3dfd

Please sign in to comment.