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 @@ -28,6 +28,7 @@
import java.util.List;
import java.util.Map;

import org.neo4j.driver.v1.Session;
import org.neo4j.driver.v1.Record;
import org.neo4j.driver.v1.StatementResult;
import org.neo4j.driver.v1.Value;
Expand All @@ -36,8 +37,8 @@
import org.neo4j.driver.v1.tck.tck.util.runners.StringRunner;

import static org.junit.Assert.assertTrue;
import static org.neo4j.driver.v1.tck.Environment.driver;
import static org.neo4j.driver.v1.Values.ofValue;
import static org.neo4j.driver.v1.tck.DriverComplianceIT.session;
import static org.neo4j.driver.v1.tck.Environment.runners;
import static org.neo4j.driver.v1.tck.tck.util.ResultParser.parseExpected;
import static org.neo4j.driver.v1.tck.tck.util.ResultParser.parseGiven;
Expand All @@ -48,7 +49,10 @@ public class CypherComplianceSteps
@Given( "^init: (.*)$" )
public void init_( String statement ) throws Throwable
{
session.run( statement );
try ( Session session = driver.session())
{
session.run( statement );
}
}

@When( "^running: (.*)$" )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
import org.junit.ClassRule;
import org.junit.runner.RunWith;

import java.io.File;
import java.io.IOException;

import org.neo4j.driver.v1.util.TestNeo4jSession;
import org.neo4j.driver.v1.util.Neo4jSettings;
import org.neo4j.driver.v1.util.TestNeo4j;

/**
* The base class to run all cucumber tests
Expand All @@ -34,14 +36,20 @@
public class DriverComplianceIT
{
@ClassRule
public static TestNeo4jSession session = new TestNeo4jSession();
public static TestNeo4j neo4j = new TestNeo4j();

public DriverComplianceIT() throws IOException
{
}

public static TestNeo4jSession session()
public static void updateEncryptionKeyAndCert( File key, File cert ) throws Exception
{
return session;
neo4j.restartServerOnEmptyDatabase(
Neo4jSettings.DEFAULT.usingEncryptionKeyAndCert( key, cert ) );
}

public static void useDefaultEncryptionKeyAndCert() throws Exception
{
neo4j.restartServerOnEmptyDatabase( Neo4jSettings.DEFAULT );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,18 @@
import java.util.Random;

import org.neo4j.driver.v1.Record;
import org.neo4j.driver.v1.Session;
import org.neo4j.driver.v1.Statement;
import org.neo4j.driver.v1.Value;
import org.neo4j.driver.v1.Values;
import org.neo4j.driver.v1.tck.tck.util.Types;
import org.neo4j.driver.v1.tck.tck.util.runners.CypherStatementRunner;
import org.neo4j.driver.v1.tck.tck.util.runners.MappedParametersRunner;
import org.neo4j.driver.v1.tck.tck.util.runners.StatementRunner;
import org.neo4j.driver.v1.tck.tck.util.runners.StringRunner;

import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
import static org.neo4j.driver.v1.tck.Environment.driver;
import static org.neo4j.driver.v1.Values.parameters;
import static org.neo4j.driver.v1.tck.DriverComplianceIT.session;
import static org.neo4j.driver.v1.tck.Environment.expectedBoltValue;
import static org.neo4j.driver.v1.tck.Environment.expectedJavaValue;
import static org.neo4j.driver.v1.tck.Environment.listOfObjects;
Expand All @@ -53,12 +52,10 @@
import static org.neo4j.driver.v1.tck.Environment.runners;
import static org.neo4j.driver.v1.tck.Environment.statementRunner;
import static org.neo4j.driver.v1.tck.Environment.stringRunner;
import static org.neo4j.driver.v1.tck.tck.util.ResultParser.getList;
import static org.neo4j.driver.v1.tck.tck.util.ResultParser.getMapOfObjects;
import static org.neo4j.driver.v1.tck.tck.util.ResultParser.isList;
import static org.neo4j.driver.v1.tck.tck.util.ResultParser.isMap;
import static org.neo4j.driver.v1.tck.tck.util.ResultParser.getJavaValueIntAsLong;
import static org.neo4j.driver.v1.tck.tck.util.Types.Type;
import static org.neo4j.driver.v1.tck.tck.util.Types.getType;
import static org.neo4j.driver.v1.tck.tck.util.runners.MappedParametersRunner.createParameterRunner;


public class DriverComplianceSteps
Expand All @@ -73,10 +70,9 @@ public void A_running_database() throws Throwable
}

@Given( "^a value (.*)$" )
public void a_value( String value )
throws Throwable
public void a_value( String value ) throws Throwable
{
expectedJavaValue = getJavaValue( value );
expectedJavaValue = getJavaValueIntAsLong( value );
expectedBoltValue = Values.value( expectedJavaValue );
}

Expand Down Expand Up @@ -112,7 +108,7 @@ public void the_expected_result_is_a_of( String type, String value ) throws Thro
public void the_driver_asks_the_server_to_echo_this_value_back() throws Throwable
{
stringRunner = new StringRunner( "RETURN " + expectedBoltValue.toString() );
mappedParametersRunner = new MappedParametersRunner( "RETURN {input}", "input", expectedBoltValue );
mappedParametersRunner = createParameterRunner( "RETURN {input}", "input", expectedBoltValue );
statementRunner = new StatementRunner(
new Statement( "RETURN {input}", parameters( "input", expectedBoltValue ) ) );

Expand Down Expand Up @@ -143,12 +139,12 @@ public void the_driver_asks_the_server_to_echo_this_map_back() throws Throwable
}

@Given( "^a list containing$" )
public void a_list_containing( List<String> table ) throws Throwable
public static void a_list_containing( List<String> table ) throws Throwable
{
List<String> content = table.subList( 1, table.size() - 1 );
for ( String value : content )
{
listOfObjects.add( getJavaValue( value ) );
listOfObjects.add( getJavaValueIntAsLong( value ) );
}
}

Expand All @@ -159,14 +155,14 @@ public void adding_this_list_to_itself() throws Throwable
}

@Given( "^a map containing$" )
public void a_map_containing( DataTable table ) throws Throwable
public static void a_map_containing( DataTable table ) throws Throwable
{
Map<String,String> map = table.asMap( String.class, String.class );
for ( String key : map.keySet() )
{
if ( !key.equals( "key" ) )
{
mapOfObjects.put( (String) Type.String.getJavaValue( key ), getJavaValue( map.get( key ) ) );
mapOfObjects.put( (String) Type.String.getJavaValue( key ), getJavaValueIntAsLong( map.get( key ) ) );
}
}
}
Expand All @@ -193,27 +189,6 @@ public void result_should_be_equal_to_a_single_Type_of_Input() throws Throwable
}
}

public Object getJavaValue( String value )
{
if ( isList( value ) )
{
ArrayList<Object> values = new ArrayList<>();
for ( String val : getList( value ) )
{
values.add( Types.asObject( val ) );
}
return values;
}
else if ( isMap( value ) )
{
return getMapOfObjects( value );
}
else
{
return Types.asObject( value );
}
}

public String getRandomString( long size )
{
StringBuilder stringBuilder = new StringBuilder();
Expand Down Expand Up @@ -249,7 +224,10 @@ public Map<String,Object> getMapOfRandomsOfTypes( Type type, long size )

public boolean databaseRunning()
{
return session() != null;
}

try ( Session session = driver.session())
{
return session.run( "RETURN 1" ).single().get( 0 ).asInt() == 1;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* Copyright (c) 2002-2016 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.neo4j.driver.v1.tck;

import cucumber.api.java.en.And;
import cucumber.api.java.en.Then;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;

import org.neo4j.driver.v1.Record;
import org.neo4j.driver.v1.Session;
import org.neo4j.driver.v1.Value;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.neo4j.driver.v1.tck.Environment.driver;

public class DriverEqualitySteps
{
HashMap<String,Value> savedValues = new HashMap<>();

@And( "^`(.*)` is single value result of: (.*)$" )
public void valueIsSingleValueResultOfMATCHNLabelRETURNN( String key, String statement ) throws Throwable
{
try ( Session session = driver.session())
{
Record r = session.run( statement ).single();
assertThat( r.size(), equalTo( 1 ) );
savedValues.put( key, r.get( 0 ) );
}
}


@Then( "^saved values should all equal$" )
public void savedValuesShouldAllEqual() throws Throwable
{
assertTrue( savedValues.values().size() > 1 );
Collection values = savedValues.values();
Iterator<Value> itr = values.iterator();
Value v = itr.next();
while ( itr.hasNext() )
{
assertThat( v, equalTo( itr.next() ) );
}
}

@Then( "^none of the saved values should be equal$" )
public void noneOfTheSavedValuesShouldBeEqual() throws Throwable
{
assertTrue( savedValues.values().size() > 1 );
Collection values = savedValues.values();
Iterator<Value> itr = values.iterator();
Value v = itr.next();
while ( itr.hasNext() )
{
assertThat( v, not(equalTo( itr.next() ) ) );
}
}
}
Loading