@Override public Encryption apply( Function<String,String> stringStringFunction ) { return s.apply( stringStringFunction ); }
/** * @return list of all configured bolt connectors which are enabled */ @Nonnull public List<BoltConnector> enabledBoltConnectors( @Nonnull Map<String,String> params ) { return boltConnectors( params ) .filter( c -> c.enabled.apply( params::get ) ) .collect( Collectors.toList() ); }
@Override public OUT apply( Function<String, String> config ) { String override = config.apply( name() ); if ( override != null ) { return overrideConverter.apply( override ); } return derivation.apply( in1.apply( config ) ); }
@Override public AdvertisedSocketAddress apply( Function<String, String> config ) { ListenSocketAddress listenSocketAddress = listenAddressSetting.apply( config ); String hostname = default_advertised_address.apply( config ); int port = listenSocketAddress.socketAddress().getPort(); String name = name(); String value = config.apply( name ); return SocketAddressParser.deriveSocketAddress( name, value, hostname, port, AdvertisedSocketAddress::new ); }
@Override public ListenSocketAddress apply( Function<String, String> config ) { String name = name(); String value = config.apply( name ); String hostname = default_listen_address.apply( config ); return SocketAddressParser.deriveSocketAddress( name, value, hostname, defaultPort, ListenSocketAddress::new ); }
@Test void testNormalizedRelativeURI() { // Given Setting<URI> uri = setting( "mySetting", NORMALIZED_RELATIVE_URI, "http://localhost:7474///db///data///" ); // When && then assertThat( uri.apply( always -> null ).toString(), equalTo( "/db/data" ) ); }
@Test void testPaths() { File directory = new File( "myDirectory" ); Setting<File> config = buildSetting( "config", PATH, new File( directory, "config.properties" ).getAbsolutePath() ).constraint( isFile ).build(); assertThat( config.apply( map( stringMap() ) ).getAbsolutePath(), equalTo( new File( directory, "config.properties" ).getAbsolutePath() ) ); }
@Test void testDefault() { Setting<Integer> setting = setting( "foo", INTEGER, "3" ); // Ok assertThat( setting.apply( map( stringMap() ) ), equalTo( 3 ) ); }
@Test void testInheritOneLevel() { Setting<Integer> root = setting( "root", INTEGER, "4" ); Setting<Integer> setting = buildSetting( "foo", INTEGER ).inherits( root ).build(); // Ok assertThat( setting.apply( map( stringMap( "foo", "1" ) ) ), equalTo( 1 ) ); assertThat( setting.apply( map( stringMap() ) ), equalTo( 4 ) ); }
@Test void testDuration() { Setting<Duration> setting = buildSetting( "foo.bar", DURATION, "3s").constraint( min( DURATION.apply( "3s" ) ) ).build(); assertThat( setting.apply( map( stringMap( "foo.bar", "4s" ) ) ), equalTo( Duration.ofSeconds( 4 ) ) ); }
@Test void testStringList() { Setting<List<String>> setting1 = setting( "apa", STRING_LIST, "foo,bar,baz" ); assertEquals( Arrays.asList( "foo", "bar", "baz" ), setting1.apply( map( stringMap() ) ) ); Setting<List<String>> setting2 = setting( "apa", STRING_LIST, "foo, bar, BAZ " ); assertEquals( Arrays.asList( "foo", "bar", "BAZ" ), setting2.apply( map( stringMap() ) ) ); Setting<List<String>> setting3 = setting( "apa", STRING_LIST, "" ); assertEquals( Collections.emptyList(), setting3.apply( map( stringMap() ) ) ); }
@Test void exceptDoesNotAllowForbiddenValues() { Setting<String> restrictedSetting = buildSetting( "foo", STRING, "test" ).constraint( except( "a", "b", "c" ) ).build(); assertEquals( "test", restrictedSetting.apply( map( stringMap() ) ) ); assertEquals( "d", restrictedSetting.apply( map( stringMap( "foo", "d" ) ) ) ); assertThrows( InvalidSettingException.class, () -> restrictedSetting.apply( map( stringMap( "foo", "a" ) ) ) ); assertThrows( InvalidSettingException.class, () -> restrictedSetting.apply( map( stringMap( "foo", "b" ) ) ) ); InvalidSettingException exception = assertThrows( InvalidSettingException.class, () -> restrictedSetting.apply( map( stringMap( "foo", "c" ) ) ) ); assertThat( exception.getMessage(), containsString( "not allowed value is: c" ) ); }
@Test void testMax() { Setting<Integer> setting = buildSetting( "foo", INTEGER, "3" ).constraint( max( 5 ) ).build(); // Ok assertThat( setting.apply( map( stringMap( "foo", "4" ) ) ), equalTo( 4 ) ); // Bad assertThrows( InvalidSettingException.class, () -> setting.apply( map( stringMap( "foo", "7" ) ) ) ); }
@Test void testMin() { Setting<Integer> setting = buildSetting( "foo", INTEGER, "3" ).constraint( min( 2 ) ).build(); // Ok assertThat( setting.apply( map( stringMap( "foo", "4" ) ) ), equalTo( 4 ) ); // Bad assertThrows( InvalidSettingException.class, () -> setting.apply( map( stringMap( "foo", "1" ) ) ) ); }
@Test void testDurationWithValueNotWithinConstraint() { Setting<Duration> setting = buildSetting( "foo.bar", DURATION, "3s" ).constraint( min( DURATION.apply( "3s" ) ) ).build(); assertThrows( InvalidSettingException.class, () -> setting.apply( map( stringMap( "foo.bar", "2s" ) ) ) ); }
@Test void testDurationWithBrokenDefault() { // Notice that the default value is less that the minimum Setting<Duration> setting = buildSetting( "foo.bar", DURATION, "1s" ).constraint( min( DURATION.apply( "3s" ) ) ).build(); assertThrows( InvalidSettingException.class, () -> setting.apply( map( stringMap() ) ) ); }
@Test public void shouldCombineDefaultHostnameWithSettingSpecificPortWhenNoValueProvided() { // given Map<String,String> config = stringMap( GraphDatabaseSettings.default_listen_address.name(), "server1.example.com" ); // when ListenSocketAddress listenSocketAddress = listen_address_setting.apply( config::get ); // then assertEquals( "server1.example.com", listenSocketAddress.getHostname() ); assertEquals( 1234, listenSocketAddress.getPort() ); }
@Test public void shouldCombineDefaultHostnameWithPortFromListenAddressSettingWhenNoValueProvided() { // given Map<String,String> config = stringMap( GraphDatabaseSettings.default_advertised_address.name(), "server1.example.com" ); // when AdvertisedSocketAddress advertisedSocketAddress = advertised_address_setting.apply( config::get ); // then assertEquals( "server1.example.com", advertisedSocketAddress.getHostname() ); assertEquals( 1234, advertisedSocketAddress.getPort() ); }