Skip to content

Commit

Permalink
Fixing the confusion around Neo4jRule#copyFrom
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhen Li authored and zhenlineo committed Dec 12, 2018
1 parent d593d00 commit f91d56c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
Expand Up @@ -102,7 +102,8 @@ public interface TestServerBuilder
TestServerBuilder withFixture( Function<GraphDatabaseService, Void> fixtureFunction );

/**
* Pre-populate the server with a database copied from the specified directory
* Pre-populate the server with databases copied from the specified source directory.
* The source directory needs to have sub-folders `databases/graph.db` in which the source store files are located.
* @param sourceDirectory the directory to copy from
* @return this builder instance
*/
Expand Down
Expand Up @@ -23,15 +23,18 @@
import org.junit.Test;
import org.junit.runners.model.Statement;

import java.io.File;
import java.util.List;

import org.neo4j.dbms.DatabaseManagementSystemSettings;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Label;
import org.neo4j.graphdb.Result;
import org.neo4j.graphdb.Transaction;
import org.neo4j.harness.extensionpackage.MyUnmanagedExtension;
import org.neo4j.harness.junit.Neo4jRule;
import org.neo4j.helpers.collection.Iterators;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.configuration.Settings;
import org.neo4j.kernel.configuration.ssl.LegacySslPolicyConfig;
import org.neo4j.server.configuration.ServerSettings;
Expand Down Expand Up @@ -109,13 +112,14 @@ public void shouldGraphDatabaseServiceBeAccessible()
}

@Test
public void shouldRuleWorkWithExsitingDirectory()
public void shouldRuleWorkWithExistingDirectory() throws Throwable
{
// given
// given a data folder, create /databases/graph.db sub-folders.
File existingDir = testDirectory.directory( "existing" );
File storeDir = Config.defaults( DatabaseManagementSystemSettings.data_directory, existingDir.toPath().toString() )
.get( DatabaseManagementSystemSettings.database_path );
GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabase( storeDir );

GraphDatabaseService db = new TestGraphDatabaseFactory()
.newEmbeddedDatabaseBuilder( testDirectory.directory() )
.newGraphDatabase();
try
{
db.execute( "CREATE ()" );
Expand All @@ -125,23 +129,26 @@ public void shouldRuleWorkWithExsitingDirectory()
db.shutdown();
}

// When a rule with an pre-populated graph db directory is used
final Neo4jRule ruleWithDirectory = new Neo4jRule( testDirectory.directory() )
// When a rule with an pre-populated data directory is used
File newDir = testDirectory.directory( "new" );
final Neo4jRule ruleWithDirectory = new Neo4jRule( newDir )
.withConfig( ServerSettings.script_enabled, Settings.TRUE )
.copyFrom( testDirectory.directory() );
ruleWithDirectory.apply( new Statement()
.copyFrom( existingDir );
Statement statement = ruleWithDirectory.apply( new Statement()
{
@Override
public void evaluate() throws Throwable
public void evaluate()
{
// Then the database is not empty
Result result = ruleWithDirectory.getGraphDatabaseService()
.execute( "MATCH (n) RETURN count(n) AS " + "count" );
Result result = ruleWithDirectory.getGraphDatabaseService().execute( "MATCH (n) RETURN count(n) AS " + "count" );

List<Object> column = Iterators.asList( result.columnAs( "count" ) );
assertEquals( 1, column.size() );
assertEquals( 1, column.get( 0 ) );
assertEquals( 1L, column.get( 0 ) );
}
}, null );

// Then
statement.evaluate();
}
}

0 comments on commit f91d56c

Please sign in to comment.