Skip to content

Commit 67b400c

Browse files
committed
Merge pull request #134 from neo4j/1.0-tck-tests
1.0 tck tests - ResultSummary API and Equality
2 parents a705924 + 845cc77 commit 67b400c

16 files changed

+684
-129
lines changed

driver/src/test/java/org/neo4j/driver/v1/tck/CypherComplianceSteps.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.List;
2929
import java.util.Map;
3030

31+
import org.neo4j.driver.v1.Session;
3132
import org.neo4j.driver.v1.Record;
3233
import org.neo4j.driver.v1.StatementResult;
3334
import org.neo4j.driver.v1.Value;
@@ -36,8 +37,8 @@
3637
import org.neo4j.driver.v1.tck.tck.util.runners.StringRunner;
3738

3839
import static org.junit.Assert.assertTrue;
40+
import static org.neo4j.driver.v1.tck.Environment.driver;
3941
import static org.neo4j.driver.v1.Values.ofValue;
40-
import static org.neo4j.driver.v1.tck.DriverComplianceIT.session;
4142
import static org.neo4j.driver.v1.tck.Environment.runners;
4243
import static org.neo4j.driver.v1.tck.tck.util.ResultParser.parseExpected;
4344
import static org.neo4j.driver.v1.tck.tck.util.ResultParser.parseGiven;
@@ -48,7 +49,10 @@ public class CypherComplianceSteps
4849
@Given( "^init: (.*)$" )
4950
public void init_( String statement ) throws Throwable
5051
{
51-
session.run( statement );
52+
try ( Session session = driver.session())
53+
{
54+
session.run( statement );
55+
}
5256
}
5357

5458
@When( "^running: (.*)$" )

driver/src/test/java/org/neo4j/driver/v1/tck/DriverComplianceIT.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222
import org.junit.ClassRule;
2323
import org.junit.runner.RunWith;
2424

25+
import java.io.File;
2526
import java.io.IOException;
2627

27-
import org.neo4j.driver.v1.util.TestNeo4jSession;
28+
import org.neo4j.driver.v1.util.Neo4jSettings;
29+
import org.neo4j.driver.v1.util.TestNeo4j;
2830

2931
/**
3032
* The base class to run all cucumber tests
@@ -34,14 +36,20 @@
3436
public class DriverComplianceIT
3537
{
3638
@ClassRule
37-
public static TestNeo4jSession session = new TestNeo4jSession();
39+
public static TestNeo4j neo4j = new TestNeo4j();
3840

3941
public DriverComplianceIT() throws IOException
4042
{
4143
}
4244

43-
public static TestNeo4jSession session()
45+
public static void updateEncryptionKeyAndCert( File key, File cert ) throws Exception
4446
{
45-
return session;
47+
neo4j.restartServerOnEmptyDatabase(
48+
Neo4jSettings.DEFAULT.usingEncryptionKeyAndCert( key, cert ) );
49+
}
50+
51+
public static void useDefaultEncryptionKeyAndCert() throws Exception
52+
{
53+
neo4j.restartServerOnEmptyDatabase( Neo4jSettings.DEFAULT );
4654
}
4755
}

driver/src/test/java/org/neo4j/driver/v1/tck/DriverComplianceSteps.java

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,18 @@
3232
import java.util.Random;
3333

3434
import org.neo4j.driver.v1.Record;
35+
import org.neo4j.driver.v1.Session;
3536
import org.neo4j.driver.v1.Statement;
3637
import org.neo4j.driver.v1.Value;
3738
import org.neo4j.driver.v1.Values;
38-
import org.neo4j.driver.v1.tck.tck.util.Types;
3939
import org.neo4j.driver.v1.tck.tck.util.runners.CypherStatementRunner;
40-
import org.neo4j.driver.v1.tck.tck.util.runners.MappedParametersRunner;
4140
import org.neo4j.driver.v1.tck.tck.util.runners.StatementRunner;
4241
import org.neo4j.driver.v1.tck.tck.util.runners.StringRunner;
4342

4443
import static org.hamcrest.core.IsEqual.equalTo;
4544
import static org.junit.Assert.assertThat;
45+
import static org.neo4j.driver.v1.tck.Environment.driver;
4646
import static org.neo4j.driver.v1.Values.parameters;
47-
import static org.neo4j.driver.v1.tck.DriverComplianceIT.session;
4847
import static org.neo4j.driver.v1.tck.Environment.expectedBoltValue;
4948
import static org.neo4j.driver.v1.tck.Environment.expectedJavaValue;
5049
import static org.neo4j.driver.v1.tck.Environment.listOfObjects;
@@ -53,12 +52,10 @@
5352
import static org.neo4j.driver.v1.tck.Environment.runners;
5453
import static org.neo4j.driver.v1.tck.Environment.statementRunner;
5554
import static org.neo4j.driver.v1.tck.Environment.stringRunner;
56-
import static org.neo4j.driver.v1.tck.tck.util.ResultParser.getList;
57-
import static org.neo4j.driver.v1.tck.tck.util.ResultParser.getMapOfObjects;
58-
import static org.neo4j.driver.v1.tck.tck.util.ResultParser.isList;
59-
import static org.neo4j.driver.v1.tck.tck.util.ResultParser.isMap;
55+
import static org.neo4j.driver.v1.tck.tck.util.ResultParser.getJavaValueIntAsLong;
6056
import static org.neo4j.driver.v1.tck.tck.util.Types.Type;
6157
import static org.neo4j.driver.v1.tck.tck.util.Types.getType;
58+
import static org.neo4j.driver.v1.tck.tck.util.runners.MappedParametersRunner.createParameterRunner;
6259

6360

6461
public class DriverComplianceSteps
@@ -73,10 +70,9 @@ public void A_running_database() throws Throwable
7370
}
7471

7572
@Given( "^a value (.*)$" )
76-
public void a_value( String value )
77-
throws Throwable
73+
public void a_value( String value ) throws Throwable
7874
{
79-
expectedJavaValue = getJavaValue( value );
75+
expectedJavaValue = getJavaValueIntAsLong( value );
8076
expectedBoltValue = Values.value( expectedJavaValue );
8177
}
8278

@@ -112,7 +108,7 @@ public void the_expected_result_is_a_of( String type, String value ) throws Thro
112108
public void the_driver_asks_the_server_to_echo_this_value_back() throws Throwable
113109
{
114110
stringRunner = new StringRunner( "RETURN " + expectedBoltValue.toString() );
115-
mappedParametersRunner = new MappedParametersRunner( "RETURN {input}", "input", expectedBoltValue );
111+
mappedParametersRunner = createParameterRunner( "RETURN {input}", "input", expectedBoltValue );
116112
statementRunner = new StatementRunner(
117113
new Statement( "RETURN {input}", parameters( "input", expectedBoltValue ) ) );
118114

@@ -143,12 +139,12 @@ public void the_driver_asks_the_server_to_echo_this_map_back() throws Throwable
143139
}
144140

145141
@Given( "^a list containing$" )
146-
public void a_list_containing( List<String> table ) throws Throwable
142+
public static void a_list_containing( List<String> table ) throws Throwable
147143
{
148144
List<String> content = table.subList( 1, table.size() - 1 );
149145
for ( String value : content )
150146
{
151-
listOfObjects.add( getJavaValue( value ) );
147+
listOfObjects.add( getJavaValueIntAsLong( value ) );
152148
}
153149
}
154150

@@ -159,14 +155,14 @@ public void adding_this_list_to_itself() throws Throwable
159155
}
160156

161157
@Given( "^a map containing$" )
162-
public void a_map_containing( DataTable table ) throws Throwable
158+
public static void a_map_containing( DataTable table ) throws Throwable
163159
{
164160
Map<String,String> map = table.asMap( String.class, String.class );
165161
for ( String key : map.keySet() )
166162
{
167163
if ( !key.equals( "key" ) )
168164
{
169-
mapOfObjects.put( (String) Type.String.getJavaValue( key ), getJavaValue( map.get( key ) ) );
165+
mapOfObjects.put( (String) Type.String.getJavaValue( key ), getJavaValueIntAsLong( map.get( key ) ) );
170166
}
171167
}
172168
}
@@ -193,27 +189,6 @@ public void result_should_be_equal_to_a_single_Type_of_Input() throws Throwable
193189
}
194190
}
195191

196-
public Object getJavaValue( String value )
197-
{
198-
if ( isList( value ) )
199-
{
200-
ArrayList<Object> values = new ArrayList<>();
201-
for ( String val : getList( value ) )
202-
{
203-
values.add( Types.asObject( val ) );
204-
}
205-
return values;
206-
}
207-
else if ( isMap( value ) )
208-
{
209-
return getMapOfObjects( value );
210-
}
211-
else
212-
{
213-
return Types.asObject( value );
214-
}
215-
}
216-
217192
public String getRandomString( long size )
218193
{
219194
StringBuilder stringBuilder = new StringBuilder();
@@ -249,7 +224,10 @@ public Map<String,Object> getMapOfRandomsOfTypes( Type type, long size )
249224

250225
public boolean databaseRunning()
251226
{
252-
return session() != null;
253-
}
254227

228+
try ( Session session = driver.session())
229+
{
230+
return session.run( "RETURN 1" ).single().get( 0 ).asInt() == 1;
231+
}
232+
}
255233
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/**
2+
* Copyright (c) 2002-2016 "Neo Technology,"
3+
* Network Engine for Objects in Lund AB [http://neotechnology.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
package org.neo4j.driver.v1.tck;
20+
21+
import cucumber.api.java.en.And;
22+
import cucumber.api.java.en.Then;
23+
24+
import java.util.Collection;
25+
import java.util.HashMap;
26+
import java.util.Iterator;
27+
28+
import org.neo4j.driver.v1.Record;
29+
import org.neo4j.driver.v1.Session;
30+
import org.neo4j.driver.v1.Value;
31+
32+
import static org.hamcrest.CoreMatchers.equalTo;
33+
import static org.hamcrest.CoreMatchers.not;
34+
import static org.junit.Assert.assertThat;
35+
import static org.junit.Assert.assertTrue;
36+
import static org.neo4j.driver.v1.tck.Environment.driver;
37+
38+
public class DriverEqualitySteps
39+
{
40+
HashMap<String,Value> savedValues = new HashMap<>();
41+
42+
@And( "^`(.*)` is single value result of: (.*)$" )
43+
public void valueIsSingleValueResultOfMATCHNLabelRETURNN( String key, String statement ) throws Throwable
44+
{
45+
try ( Session session = driver.session())
46+
{
47+
Record r = session.run( statement ).single();
48+
assertThat( r.size(), equalTo( 1 ) );
49+
savedValues.put( key, r.get( 0 ) );
50+
}
51+
}
52+
53+
54+
@Then( "^saved values should all equal$" )
55+
public void savedValuesShouldAllEqual() throws Throwable
56+
{
57+
assertTrue( savedValues.values().size() > 1 );
58+
Collection values = savedValues.values();
59+
Iterator<Value> itr = values.iterator();
60+
Value v = itr.next();
61+
while ( itr.hasNext() )
62+
{
63+
assertThat( v, equalTo( itr.next() ) );
64+
}
65+
}
66+
67+
@Then( "^none of the saved values should be equal$" )
68+
public void noneOfTheSavedValuesShouldBeEqual() throws Throwable
69+
{
70+
assertTrue( savedValues.values().size() > 1 );
71+
Collection values = savedValues.values();
72+
Iterator<Value> itr = values.iterator();
73+
Value v = itr.next();
74+
while ( itr.hasNext() )
75+
{
76+
assertThat( v, not(equalTo( itr.next() ) ) );
77+
}
78+
}
79+
}

0 commit comments

Comments
 (0)