Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,15 @@ public StatementResult run( String statementText )
@Override
public StatementResult run( String statementText, Map<String, Object> statementParameters )
{
return run( statementText, value( statementParameters ) );
Value params = statementParameters == null ? Values.EmptyMap : value(statementParameters);
return run( statementText, params );
}

@Override
public StatementResult run( String statementTemplate, Record statementParameters )
{
// TODO: This conversion to map here is pointless, it gets converted right back
return run( statementTemplate, statementParameters.asMap() );
Value params = statementParameters == null ? Values.EmptyMap : value( statementParameters.asMap() );
return run( statementTemplate, params );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.neo4j.driver.v1.types.TypeSystem;

import static org.neo4j.driver.v1.Values.ofValue;
import static org.neo4j.driver.v1.Values.value;

public class InternalTransaction implements Transaction
{
Expand Down Expand Up @@ -142,14 +143,15 @@ public StatementResult run( String statementText )
@Override
public StatementResult run( String statementText, Map<String,Object> statementParameters )
{
return run( statementText, Values.value( statementParameters ) );
Value params = statementParameters == null ? Values.EmptyMap : value(statementParameters);
return run( statementText, params );
}

@Override
public StatementResult run( String statementTemplate, Record statementParameters )
{
// TODO: This conversion to map here is pointless, it gets converted right back
return run( statementTemplate, statementParameters.asMap() );
Value params = statementParameters == null ? Values.EmptyMap : value( statementParameters.asMap() );
return run( statementTemplate, params );
}

@Override
Expand Down
5 changes: 4 additions & 1 deletion driver/src/main/java/org/neo4j/driver/v1/GraphDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ public static Driver driver( String url, AuthToken authToken, Config config )
*/
public static Driver driver( URI url, AuthToken authToken, Config config )
{
return new InternalDriver( url, authToken, config );
AuthToken tokenToUse = authToken != null ? authToken: AuthTokens.none();
Config configToUse = config != null ? config: Config.defaultConfig();

return new InternalDriver( url, tokenToUse, configToUse );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.junit.Rule;
import org.junit.Test;

import org.neo4j.driver.v1.AuthToken;
import org.neo4j.driver.v1.AuthTokens;
import org.neo4j.driver.v1.Driver;
import org.neo4j.driver.v1.GraphDatabase;
import org.neo4j.driver.v1.Session;
Expand All @@ -46,4 +48,34 @@ public void shouldKnowSessionIsClosed() throws Throwable
// Then
assertFalse( session.isOpen() );
}

@Test
public void shouldHandleNullConfig() throws Throwable
{
// Given
Driver driver = GraphDatabase.driver( neo4j.address(), AuthTokens.none(), null );
Session session = driver.session();

// When
session.close();

// Then
assertFalse( session.isOpen() );
}

@SuppressWarnings( "ConstantConditions" )
@Test
public void shouldHandleNullAuthToken() throws Throwable
{
// Given
AuthToken token = null;
Driver driver = GraphDatabase.driver( neo4j.address(), token);
Session session = driver.session();

// When
session.close();

// Then
assertFalse( session.isOpen() );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.neo4j.driver.v1.Record;
import org.neo4j.driver.v1.StatementResult;
Expand Down Expand Up @@ -74,6 +75,45 @@ public void shouldRunWithParameters() throws Throwable
// Then nothing should've failed
}

@SuppressWarnings( "ConstantConditions" )
@Test
public void shouldRunWithNullValuesAsParameters() throws Throwable
{
// Given
Value params = null;

// When
session.run( "CREATE (n:FirstNode {name:'Steven'})", params );

// Then nothing should've failed
}

@SuppressWarnings( "ConstantConditions" )
@Test
public void shouldRunWithNullRecordAsParameters() throws Throwable
{
// Given
Record params = null;

// When
session.run( "CREATE (n:FirstNode {name:'Steven'})", params );

// Then nothing should've failed
}

@SuppressWarnings( "ConstantConditions" )
@Test
public void shouldRunWithNullMapAsParameters() throws Throwable
{
// Given
Map<String, Object> params = null;

// When
session.run( "CREATE (n:FirstNode {name:'Steven'})", params );

// Then nothing should've failed
}

@Test
public void shouldRunWithCollectionAsParameter() throws Throwable
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import org.junit.Test;
import org.junit.rules.ExpectedException;

import java.util.Map;

import org.neo4j.driver.v1.Record;
import org.neo4j.driver.v1.StatementResult;
import org.neo4j.driver.v1.Transaction;
import org.neo4j.driver.v1.Value;
Expand Down Expand Up @@ -164,4 +167,48 @@ public void shouldHandleFailureAfterClosingTransaction()
session.run("CREAT (n) RETURN n").consume();
}

@SuppressWarnings( "ConstantConditions" )
@Test
public void shouldHandleNullRecordParameters() throws Throwable
{
// When
try ( Transaction tx = session.beginTransaction() )
{
Record params = null;
tx.run( "CREATE (n:FirstNode)", params );
tx.success();
}

// Then it wasn't the end of the world as we know it
}

@SuppressWarnings( "ConstantConditions" )
@Test
public void shouldHandleNullValueParameters() throws Throwable
{
// When
try ( Transaction tx = session.beginTransaction() )
{
Value params = null;
tx.run( "CREATE (n:FirstNode)", params );
tx.success();
}

// Then it wasn't the end of the world as we know it
}

@SuppressWarnings( "ConstantConditions" )
@Test
public void shouldHandleNullMapParameters() throws Throwable
{
// When
try ( Transaction tx = session.beginTransaction() )
{
Map<String, Object> params = null;
tx.run( "CREATE (n:FirstNode)", params );
tx.success();
}

// Then it wasn't the end of the world as we know it
}
}