Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update configuration builder settings classes setup, fallback to conf…
…ig map in case if settings classes is missing.
- Loading branch information
1 parent
f7dd1dc
commit 5617444
Showing
8 changed files
with
179 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
community/server/src/test/java/org/neo4j/server/modules/ExtensionInitializerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,131 @@ | |||
/* | |||
* Copyright (c) 2002-2015 "Neo Technology," | |||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | |||
* | |||
* This file is part of Neo4j. | |||
* | |||
* Neo4j is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
package org.neo4j.server.modules; | |||
|
|||
import org.apache.commons.configuration.Configuration; | |||
import org.hamcrest.BaseMatcher; | |||
import org.hamcrest.Description; | |||
import org.hamcrest.Matchers; | |||
import org.junit.Test; | |||
import org.mockito.Mockito; | |||
|
|||
import java.util.Arrays; | |||
import java.util.Collection; | |||
|
|||
import org.neo4j.function.Function; | |||
import org.neo4j.graphdb.GraphDatabaseService; | |||
import org.neo4j.helpers.collection.Iterables; | |||
import org.neo4j.kernel.configuration.Config; | |||
import org.neo4j.server.NeoServer; | |||
import org.neo4j.server.configuration.ServerSettings; | |||
import org.neo4j.server.plugins.Injectable; | |||
import org.neo4j.server.plugins.PluginLifecycle; | |||
|
|||
import static org.junit.Assert.assertThat; | |||
import static org.neo4j.helpers.collection.MapUtil.stringMap; | |||
|
|||
|
|||
public class ExtensionInitializerTest | |||
{ | |||
|
|||
@Test | |||
public void testPluginInitialization() | |||
{ | |||
Config config = new Config( stringMap( ServerSettings.transaction_timeout.name(), "600" ) ); | |||
NeoServer neoServer = Mockito.mock( NeoServer.class, Mockito.RETURNS_DEEP_STUBS ); | |||
Mockito.when( neoServer.getConfig() ).thenReturn( config ); | |||
ExtensionInitializer extensionInitializer = new ExtensionInitializer( neoServer ); | |||
|
|||
Collection<Injectable<?>> injectableProperties = | |||
extensionInitializer.initializePackages( Arrays.asList( "org.neo4j.server.modules" ) ); | |||
|
|||
assertThat( injectableProperties, Matchers.hasSize( 1 ) ); | |||
assertThat( injectableProperties, Matchers.contains( new InjectableMatcher<>( ServerSettings | |||
.transaction_timeout.name() ) ) ); | |||
} | |||
|
|||
private class InjectableMatcher<T> extends BaseMatcher<Injectable<?>> | |||
{ | |||
private T value; | |||
|
|||
public InjectableMatcher( T value ) | |||
{ | |||
this.value = value; | |||
} | |||
|
|||
@Override | |||
public boolean matches( Object o ) | |||
{ | |||
return o instanceof Injectable && value.equals( ((Injectable) o).getValue() ); | |||
} | |||
|
|||
@Override | |||
public void describeMismatch( Object o, Description description ) | |||
{ | |||
description.appendValue( String.format( "Expect Injectable with value: '%s', but actual value was: '%s'", | |||
value, o ) ); | |||
} | |||
|
|||
@Override | |||
public void describeTo( Description description ) | |||
{ | |||
|
|||
} | |||
} | |||
|
|||
public static class PropertyCollectorPlugin implements PluginLifecycle | |||
{ | |||
|
|||
@Override | |||
public Collection<Injectable<?>> start( GraphDatabaseService graphDatabaseService, Configuration config ) | |||
{ | |||
return Iterables.toList( Iterables.map( new StringToInjectableFunction(), config.getKeys() ) ); | |||
} | |||
|
|||
@Override | |||
public void stop() | |||
{ | |||
|
|||
} | |||
|
|||
private class StringToInjectableFunction implements Function<String,Injectable<?>> | |||
{ | |||
|
|||
@Override | |||
public Injectable<String> apply( final String value ) | |||
{ | |||
return new Injectable<String>() | |||
{ | |||
@Override | |||
public String getValue() | |||
{ | |||
return value; | |||
} | |||
|
|||
@Override | |||
public Class<String> getType() | |||
{ | |||
return String.class; | |||
} | |||
}; | |||
} | |||
} | |||
} | |||
} |
1 change: 1 addition & 0 deletions
1
...nity/server/src/test/resources/META-INF/services/org.neo4j.server.plugins.PluginLifecycle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
org.neo4j.server.modules.ExtensionInitializerTest$PropertyCollectorPlugin |