Skip to content

Commit fc06860

Browse files
committed
Merge pull request #127 from neo4j/1.0-tck-tests
1.0 tck tests
2 parents 45cf932 + c52af42 commit fc06860

File tree

6 files changed

+279
-443
lines changed

6 files changed

+279
-443
lines changed

driver/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@
8282
<version>1.2.4</version>
8383
<scope>test</scope>
8484
</dependency>
85+
<dependency>
86+
<groupId>com.fasterxml.jackson.core</groupId>
87+
<artifactId>jackson-databind</artifactId>
88+
<version>2.6.0</version>
89+
<scope>test</scope>
90+
</dependency>
8591
</dependencies>
8692

8793
<build>

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

Lines changed: 7 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
import java.util.ArrayList;
2727
import java.util.Collection;
28-
import java.util.HashMap;
2928
import java.util.List;
3029
import java.util.Map;
3130

@@ -35,44 +34,40 @@
3534
import org.neo4j.driver.v1.tck.tck.util.runners.MappedParametersRunner;
3635
import org.neo4j.driver.v1.tck.tck.util.runners.StringRunner;
3736

38-
import static org.junit.Assert.assertEquals;
3937
import static org.junit.Assert.assertTrue;
4038
import static org.neo4j.driver.v1.tck.DriverComplianceIT.session;
41-
import static org.neo4j.driver.v1.tck.Environment.mappedTypes;
4239
import static org.neo4j.driver.v1.tck.Environment.runners;
43-
import static org.neo4j.driver.v1.tck.tck.util.ResultParser.getParametersFromListOfKeysAndValues;
4440
import static org.neo4j.driver.v1.tck.tck.util.ResultParser.parseExpected;
4541
import static org.neo4j.driver.v1.tck.tck.util.ResultParser.parseGiven;
46-
import static org.neo4j.driver.v1.tck.tck.util.Types.getType;
4742

4843

4944
public class CypherComplianceSteps
5045
{
51-
@Given( "^init: (.*);$" )
46+
@Given( "^init: (.*)$" )
5247
public void init_( String statement ) throws Throwable
5348
{
5449
session.run( statement );
5550
}
5651

57-
@When( "^running: (.*);$" )
52+
@When( "^running: (.*)$" )
5853
public void running_( String statement ) throws Throwable
5954
{
6055
runners.add( new StringRunner( statement ).runCypherStatement() );
6156
}
6257

6358

64-
@When( "^running parametrized: (.*);$" )
59+
@When( "^running parametrized: (.*)$" )
6560
public void running_param_bar_match_a_r_b_where_r_foo_param_return_b( String statement, DataTable stringParam )
6661
throws Throwable
6762
{
6863
List<String> keys = stringParam.topCells();
6964
List<String> values = stringParam.diffableRows().get( 1 ).convertedRow;
70-
Map<String, Value> params = getParametersFromListOfKeysAndValues( keys, values );
65+
Map<String, Value> params = parseExpected( values, keys );
7166
runners.add( new MappedParametersRunner( statement, params ).runCypherStatement() );
7267
}
7368

74-
@Then( "^result should be ([^\"]*)\\(s\\)$" )
75-
public void result_should_be_a_type_containing(String type, DataTable table) throws Throwable
69+
@Then( "^result:$" )
70+
public void result(DataTable table) throws Throwable
7671
{
7772
for( CypherStatementRunner runner : runners)
7873
{
@@ -86,54 +81,13 @@ public void result_should_be_a_type_containing(String type, DataTable table) thr
8681
assertTrue( keys.size() == rc.record().keys().size() );
8782
assertTrue( keys.containsAll( rc.record().keys() ) );
8883
given.add( parseGiven( rc.record().asMap() ) );
89-
expected.add( parseExpected( table.diffableRows().get( i + 1 ).convertedRow, keys, getType( type ) ) );
84+
expected.add( parseExpected( table.diffableRows().get( i + 1 ).convertedRow, keys ) );
9085
i++;
9186
}
92-
assertTrue( expected.size() > 0 );
93-
assertTrue( expected.iterator().next().size() > 0 );
94-
assertTrue( equalRecords( expected, given) );
95-
}
96-
}
97-
98-
@Then( "^result should be mixed:" )
99-
public void result_should_be_mixed( DataTable table ) throws Throwable
100-
{
101-
for( CypherStatementRunner runner : runners)
102-
{
103-
ResultCursor rc = runner.result();
104-
List<String> keys = table.topCells();
105-
Collection<Map> given = new ArrayList<>( );
106-
Collection<Map> expected = new ArrayList<>( );
107-
int i = 0;
108-
while ( rc.next() )
109-
{
110-
assertTrue( keys.size() == rc.record().keys().size() );
111-
assertTrue( keys.containsAll( rc.record().keys() ) );
112-
Map<String,Value> tmpGiven = new HashMap<>( );
113-
for ( String key : keys )
114-
{
115-
tmpGiven.put( key, parseGiven( rc.record().asMap().get( key ) ) );
116-
}
117-
given.add( tmpGiven );
118-
expected.add( parseExpected( table.diffableRows().get( i + 1 ).convertedRow, keys, mappedTypes ) );
119-
i++;
120-
}
121-
assertTrue( expected.size() > 0 );
122-
assertTrue( expected.iterator().next().size() > 0 );
12387
assertTrue( equalRecords( expected, given ) );
12488
}
12589
}
12690

127-
@Then( "^result should be empty$" )
128-
public void result_should_be_empty(DataTable table) throws Throwable
129-
{
130-
for (CypherStatementRunner runner : runners)
131-
{
132-
assertEquals( runner.result().list().size(), 0 );
133-
}
134-
135-
}
136-
13791
private boolean equalRecords( Collection<Map> one, Collection<Map> other )
13892
{
13993
if (one.size() != other.size() )
@@ -159,16 +113,4 @@ private boolean equalRecords( Collection<Map> one, Collection<Map> other )
159113
return other.size() == 0;
160114

161115
}
162-
163-
@Then( "^result should map to types:$" )
164-
public void result_should_map_to_types(DataTable table) throws Throwable
165-
{
166-
List<String> keys = table.topCells();
167-
List<String> values = table.diffableRows().get( 1 ).convertedRow;
168-
mappedTypes = new HashMap<>( );
169-
for (int i = 0; i < keys.size(); i++)
170-
{
171-
mappedTypes.put( keys.get( i ), getType( values.get( i ) ) );
172-
}
173-
}
174116
}

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

Lines changed: 51 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@
3535
import org.neo4j.driver.v1.Statement;
3636
import org.neo4j.driver.v1.Value;
3737
import org.neo4j.driver.v1.Values;
38+
import org.neo4j.driver.v1.tck.tck.util.Types;
3839
import org.neo4j.driver.v1.tck.tck.util.runners.CypherStatementRunner;
3940
import org.neo4j.driver.v1.tck.tck.util.runners.MappedParametersRunner;
4041
import org.neo4j.driver.v1.tck.tck.util.runners.StatementRunner;
4142
import org.neo4j.driver.v1.tck.tck.util.runners.StringRunner;
4243

43-
import static java.lang.String.valueOf;
4444
import static java.util.Collections.singletonMap;
4545
import static org.hamcrest.core.IsEqual.equalTo;
4646
import static org.junit.Assert.assertThat;
@@ -53,6 +53,10 @@
5353
import static org.neo4j.driver.v1.tck.Environment.runners;
5454
import static org.neo4j.driver.v1.tck.Environment.statementRunner;
5555
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;
5660
import static org.neo4j.driver.v1.tck.tck.util.Types.Type;
5761
import static org.neo4j.driver.v1.tck.tck.util.Types.getType;
5862

@@ -68,11 +72,11 @@ public void A_running_database() throws Throwable
6872
}
6973
}
7074

71-
@Given( "^a value ([^\"]*) of type ([^\"]*)$" )
72-
public void a_value_of_Type( String value, String type )
75+
@Given( "^a value (.*)$" )
76+
public void a_value( String value )
7377
throws Throwable
7478
{
75-
expectedJavaValue = getType( type ).getJavaValue( value );
79+
expectedJavaValue = getJavaValue( value );
7680
expectedBoltValue = Values.value( expectedJavaValue );
7781
}
7882

@@ -97,13 +101,6 @@ public void a_Map_of_size_and_type_Type( long size, String type ) throws Throwab
97101
expectedBoltValue = Values.value( expectedJavaValue );
98102
}
99103

100-
@Given( "^a list value ([^\"]*) of type ([^\"]*)$" )
101-
public void a_list_value_of_Type( String value, String type ) throws Throwable
102-
{
103-
expectedJavaValue = getType( type ).getJavaArrayList( getListFromString( value ) );
104-
expectedBoltValue = Values.value( expectedJavaValue );
105-
}
106-
107104
@And( "^the expected result is a bolt \"([^\"]*)\" of \"([^\"]*)\"$" )
108105
public void the_expected_result_is_a_of( String type, String value ) throws Throwable
109106
{
@@ -114,7 +111,7 @@ public void the_expected_result_is_a_of( String type, String value ) throws Thro
114111
@When( "^the driver asks the server to echo this value back$" )
115112
public void the_driver_asks_the_server_to_echo_this_value_back() throws Throwable
116113
{
117-
stringRunner = new StringRunner( "RETURN " + boltValueAsCypherString( expectedBoltValue ) );
114+
stringRunner = new StringRunner( "RETURN " + expectedBoltValue.toString() );
118115
mappedParametersRunner = new MappedParametersRunner( "RETURN {input}", "input", expectedBoltValue );
119116
statementRunner = new StatementRunner(
120117
new Statement( "RETURN {input}", singletonMap( "input", expectedBoltValue ) ) );
@@ -145,69 +142,40 @@ public void the_driver_asks_the_server_to_echo_this_map_back() throws Throwable
145142
the_driver_asks_the_server_to_echo_this_value_back();
146143
}
147144

148-
@When( "^adding a table of lists to the list L$" )
149-
public void adding_a_table_of_lists_to_the_list_of_objects( DataTable table ) throws Throwable
150-
{
151-
Map<String,String> map = table.asMap( String.class, String.class );
152-
for ( String type : map.keySet() )
153-
{
154-
listOfObjects.add( getType( type ).getJavaArrayList( getListFromString( map.get( type ) ) ) );
155-
}
156-
}
157-
158-
@When( "^adding a table of values to the list L$" )
159-
public void adding_a_table_of_values_to_the_list_of_objects( DataTable table ) throws Throwable
145+
@Given( "^a list containing$" )
146+
public void a_list_containing( List<String> table ) throws Throwable
160147
{
161-
Map<String,String> map = table.asMap( String.class, String.class );
162-
for ( String type : map.keySet() )
148+
List<String> content = table.subList( 1, table.size() - 1 );
149+
for ( String value : content )
163150
{
164-
listOfObjects.add( getType( type ).getJavaValue( map.get( type ) ) );
151+
listOfObjects.add( getJavaValue( value ) );
165152
}
166153
}
167154

168-
@When( "^adding a table of lists to the map M$" )
169-
public void adding_a_table_of_lists_to_the_map_of_objects( DataTable table ) throws Throwable
155+
@And( "^adding this list to itself$" )
156+
public void adding_this_list_to_itself() throws Throwable
170157
{
171-
Map<String,String> map = table.asMap( String.class, String.class );
172-
for ( String type : map.keySet() )
173-
{
174-
mapOfObjects.put( "a" + valueOf( mapOfObjects.size() ), getType( type ).getJavaArrayList(
175-
getListFromString( map.get( type ) ) ) );
176-
}
158+
listOfObjects.add( new ArrayList<>( listOfObjects ) );
177159
}
178160

179-
@When( "^adding a table of values to the map M$" )
180-
public void adding_a_table_of_values_to_the_map_of_objects( DataTable table ) throws Throwable
161+
@Given( "^a map containing$" )
162+
public void a_map_containing( DataTable table ) throws Throwable
181163
{
182164
Map<String,String> map = table.asMap( String.class, String.class );
183-
for ( String type : map.keySet() )
165+
for ( String key : map.keySet() )
184166
{
185-
mapOfObjects.put( "a" + valueOf( mapOfObjects.size() ), getType( type ).getJavaValue( map.get( type ) ) );
167+
if ( !key.equals( "key" ) )
168+
{
169+
mapOfObjects.put( (String) Type.String.getJavaValue( key ), getJavaValue( map.get( key ) ) );
170+
}
186171
}
187172
}
188173

189-
@When( "^adding a copy of map M to map M$" )
190-
public void adding_map_of_objects_to_map_of_objects() throws Throwable
191-
{
192-
mapOfObjects.put( "a" + valueOf( mapOfObjects.size() ), new HashMap<>( mapOfObjects ) );
193-
}
194-
195-
@When( "^adding map M to list L$" )
196-
public void adding_map_of_objects_to_list_of_objects() throws Throwable
197-
{
198-
listOfObjects.add( mapOfObjects );
199-
}
200-
201-
@And( "^an empty map M$" )
202-
public void a_map_of_objects() throws Throwable
174+
@And( "^adding this map to itself with key \"([^\"]*)\"$" )
175+
public void adding_this_map_to_itself_with_key( String key ) throws Throwable
203176
{
204-
mapOfObjects = new HashMap<>();
205-
}
206-
207-
@And( "^an empty list L$" )
208-
public void a_list_of_objects() throws Throwable
209-
{
210-
listOfObjects = new ArrayList<>();
177+
mapOfObjects.put( key, new HashMap<>( mapOfObjects ) );
178+
expectedJavaValue = mapOfObjects;
211179
}
212180

213181
@Then( "^the value given in the result should be the same as what was sent" )
@@ -225,6 +193,27 @@ public void result_should_be_equal_to_a_single_Type_of_Input() throws Throwable
225193
}
226194
}
227195

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+
228217
public String getRandomString( long size )
229218
{
230219
StringBuilder stringBuilder = new StringBuilder();
@@ -242,7 +231,7 @@ public List<Object> getListOfRandomsOfTypes( Type type, long size )
242231
List<Object> list = new ArrayList<>();
243232
while ( size-- > 0 )
244233
{
245-
list.add( type.getRandomValue( ) );
234+
list.add( type.getRandomValue() );
246235
}
247236
return list;
248237
}
@@ -257,20 +246,10 @@ public Map<String,Object> getMapOfRandomsOfTypes( Type type, long size )
257246
return map;
258247
}
259248

260-
public String boltValueAsCypherString( Value value )
261-
{
262-
return value.toString();
263-
}
264-
265-
public String[] getListFromString( String str )
266-
{
267-
return str.replaceAll( "\\[", "" )
268-
.replaceAll( "\\]", "" )
269-
.split( "," );
270-
}
271249

272250
public boolean databaseRunning()
273251
{
274252
return session() != null;
275253
}
254+
276255
}

0 commit comments

Comments
 (0)