Skip to content

Commit 6a318ca

Browse files
committed
Merge pull request #155 from pontusmelke/1.0-load-csv-test-fix
Fix broken test
2 parents 6efc096 + 922d0fd commit 6a318ca

File tree

5 files changed

+68
-24
lines changed

5 files changed

+68
-24
lines changed

driver/src/test/java/org/neo4j/driver/v1/integration/LoadCSVIT.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,27 @@
1818
*/
1919
package org.neo4j.driver.v1.integration;
2020

21-
import org.junit.Ignore;
2221
import org.junit.Rule;
2322
import org.junit.Test;
2423

2524
import java.io.IOException;
2625

2726
import org.neo4j.driver.v1.Driver;
2827
import org.neo4j.driver.v1.GraphDatabase;
29-
import org.neo4j.driver.v1.StatementResult;
3028
import org.neo4j.driver.v1.Session;
29+
import org.neo4j.driver.v1.StatementResult;
30+
import org.neo4j.driver.v1.util.Neo4jSettings;
3131
import org.neo4j.driver.v1.util.TestNeo4j;
3232

3333
import static org.hamcrest.CoreMatchers.equalTo;
3434
import static org.hamcrest.MatcherAssert.assertThat;
3535
import static org.junit.Assert.assertFalse;
3636
import static org.neo4j.driver.v1.Values.parameters;
3737

38-
@Ignore
3938
public class LoadCSVIT
4039
{
4140
@Rule
42-
public TestNeo4j neo4j = new TestNeo4j();
41+
public TestNeo4j neo4j = new TestNeo4j( Neo4jSettings.DEFAULT.without( Neo4jSettings.IMPORT_DIR ));
4342

4443
@Test
4544
public void shouldLoadCSV() throws Throwable

driver/src/test/java/org/neo4j/driver/v1/util/FileTools.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.io.PrintWriter;
3333
import java.net.URL;
3434
import java.nio.file.Files;
35+
import java.util.Collections;
3536
import java.util.HashMap;
3637
import java.util.HashSet;
3738
import java.util.Map;
@@ -198,10 +199,10 @@ public static void updateProperty( File propFile, String key, String value ) thr
198199
{
199200
Map<String, String> propertiesMap = new HashMap<>( 1 );
200201
propertiesMap.put( key, value );
201-
updateProperties( propFile, propertiesMap );
202+
updateProperties( propFile, propertiesMap, Collections.<String>emptySet() );
202203
}
203204

204-
public static void updateProperties( File propFile, Map<String, String> propertiesMap ) throws IOException
205+
public static void updateProperties( File propFile, Map<String, String> propertiesMap, Set<String> excludes ) throws IOException
205206
{
206207
Scanner in = new Scanner( propFile );
207208

@@ -222,6 +223,11 @@ public static void updateProperties( File propFile, Map<String, String> properti
222223
if ( tokens.length == 2 )
223224
{
224225
String name = tokens[0].trim();
226+
if (excludes.contains( name ))
227+
{
228+
continue;
229+
}
230+
225231
Object value = propertiesMap.get( name );
226232
if ( value != null && !updatedProperties.contains( name ) )
227233
{

driver/src/test/java/org/neo4j/driver/v1/util/Neo4jRunner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ private void updateServerSettingsFile()
198198
debug( "%s=%s", name, value );
199199
}
200200

201-
updateProperties( oldFile, propertiesMap );
201+
updateProperties( oldFile, propertiesMap, currentSettings.excludes() );
202202
}
203203
catch ( Exception e )
204204
{

driver/src/test/java/org/neo4j/driver/v1/util/Neo4jSettings.java

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@
1919
package org.neo4j.driver.v1.util;
2020

2121
import java.io.File;
22+
import java.util.Collections;
2223
import java.util.HashMap;
24+
import java.util.HashSet;
2325
import java.util.Map;
26+
import java.util.Set;
2427

2528
import static org.neo4j.driver.internal.util.Iterables.map;
2629

@@ -29,24 +32,32 @@ public class Neo4jSettings
2932
public static final String AUTH_ENABLED = "dbms.security.auth_enabled";
3033
public static final String DATA_DIR = "dbms.directories.data";
3134
public static final String CERT_DIR = "dbms.directories.certificates";
35+
public static final String IMPORT_DIR = "dbms.directories.import";
3236

37+
private static final String DEFAULT_IMPORT_DIR = "import";
3338
private static final String DEFAULT_CERT_DIR = "certificates";
3439
private static final String DEFAULT_TLS_CERT_PATH = DEFAULT_CERT_DIR + "/neo4j.cert";
3540
private static final String DEFAULT_TLS_KEY_PATH = DEFAULT_CERT_DIR + "/neo4j.key";
3641

42+
public static final String DEFAULT_DATA_DIR = "data";
3743
public static final File DEFAULT_TLS_KEY_FILE = new File( Neo4jInstaller.neo4jHomeDir, DEFAULT_TLS_KEY_PATH );
3844
public static final File DEFAULT_TLS_CERT_FILE = new File( Neo4jInstaller.neo4jHomeDir, DEFAULT_TLS_CERT_PATH );
3945

4046

4147
private final Map<String, String> settings;
48+
private final Set<String> excludes;
49+
4250

4351
public static Neo4jSettings DEFAULT = new Neo4jSettings( map(
4452
CERT_DIR, DEFAULT_CERT_DIR,
45-
AUTH_ENABLED, "false" ) );
53+
DATA_DIR, DEFAULT_DATA_DIR,
54+
IMPORT_DIR, DEFAULT_IMPORT_DIR,
55+
AUTH_ENABLED, "false" ), Collections.<String>emptySet() );
4656

47-
private Neo4jSettings( Map<String, String> settings )
57+
private Neo4jSettings( Map<String, String> settings, Set<String> excludes )
4858
{
4959
this.settings = settings;
60+
this.excludes = excludes;
5061
}
5162

5263
public Map<String, String> propertiesMap()
@@ -56,38 +67,62 @@ public Map<String, String> propertiesMap()
5667

5768
public Neo4jSettings updateWith( Neo4jSettings other )
5869
{
59-
return updateWith( other.settings );
70+
return updateWith( other.settings, other.excludes );
6071
}
6172

6273
public Neo4jSettings updateWith( String key, String value )
6374
{
64-
return updateWith( map(key, value) );
75+
return updateWith( map(key, value), excludes );
6576
}
6677

67-
private Neo4jSettings updateWith( Map<String,String> updates )
78+
private Neo4jSettings updateWith( Map<String,String> updates, Set<String> excludes )
6879
{
6980
HashMap<String,String> newSettings = new HashMap<>( settings );
7081
for ( Map.Entry<String,String> entry : updates.entrySet() )
7182
{
7283
newSettings.put( entry.getKey(), entry.getValue() );
7384
}
74-
return new Neo4jSettings( newSettings );
85+
for ( String exclude : excludes )
86+
{
87+
newSettings.remove( exclude );
88+
}
89+
return new Neo4jSettings( newSettings, excludes );
90+
}
91+
92+
public Neo4jSettings without(String key)
93+
{
94+
Set<String> newExcludes = new HashSet<>( excludes );
95+
newExcludes.add( key );
96+
Map<String,String> newMap = new HashMap<>( this.settings );
97+
newMap.remove( key );
98+
Neo4jSettings newSettings = new Neo4jSettings( newMap, newExcludes );
99+
return newSettings;
75100
}
76101

77102
@Override
78103
public boolean equals( Object o )
79104
{
80-
if ( this == o ) { return true; }
81-
if ( o == null || getClass() != o.getClass() ) { return false; }
105+
if ( this == o )
106+
{ return true; }
107+
if ( o == null || getClass() != o.getClass() )
108+
{ return false; }
82109

83110
Neo4jSettings that = (Neo4jSettings) o;
84111

85-
return settings.equals( that.settings );
112+
if ( !settings.equals( that.settings ) )
113+
{ return false; }
114+
return excludes.equals( that.excludes );
115+
86116
}
87117

88118
@Override
89119
public int hashCode()
90120
{
91121
return settings.hashCode();
92122
}
123+
124+
public Set<String> excludes()
125+
{
126+
return excludes;
127+
}
93128
}

driver/src/test/java/org/neo4j/driver/v1/util/TestNeo4j.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,19 @@
3434

3535
public class TestNeo4j implements TestRule
3636
{
37-
private Neo4jSettings settings = Neo4jSettings.DEFAULT;
37+
private final Neo4jSettings settings;
3838
private Neo4jRunner runner;
3939

40+
public TestNeo4j()
41+
{
42+
this( Neo4jSettings.DEFAULT );
43+
}
44+
45+
public TestNeo4j( Neo4jSettings settings )
46+
{
47+
this.settings = settings;
48+
}
49+
4050
@Override
4151
public Statement apply( final Statement base, final Description description )
4252
{
@@ -74,7 +84,7 @@ public URL putTmpFile( String prefix, String suffix, String contents ) throws IO
7484
tmpFile.deleteOnExit();
7585
try ( PrintWriter out = new PrintWriter( tmpFile ) )
7686
{
77-
out.println( contents);
87+
out.println( contents );
7888
}
7989
return tmpFile.toURI().toURL();
8090
}
@@ -99,12 +109,6 @@ public void restartServerOnEmptyDatabase( Neo4jSettings neo4jSettings ) throws E
99109
runner.restart( neo4jSettings );
100110
}
101111

102-
public TestNeo4j withSettings( Neo4jSettings settings )
103-
{
104-
this.settings = settings;
105-
return this;
106-
}
107-
108112
public void updateEncryptionKeyAndCert( File key, File cert ) throws Exception
109113
{
110114
Files.copy( key.toPath(), Neo4jSettings.DEFAULT_TLS_KEY_FILE.toPath(), StandardCopyOption.REPLACE_EXISTING );

0 commit comments

Comments
 (0)