3535import org .neo4j .driver .v1 .Statement ;
3636import org .neo4j .driver .v1 .Value ;
3737import org .neo4j .driver .v1 .Values ;
38+ import org .neo4j .driver .v1 .tck .tck .util .Types ;
3839import org .neo4j .driver .v1 .tck .tck .util .runners .CypherStatementRunner ;
3940import org .neo4j .driver .v1 .tck .tck .util .runners .MappedParametersRunner ;
4041import org .neo4j .driver .v1 .tck .tck .util .runners .StatementRunner ;
4142import org .neo4j .driver .v1 .tck .tck .util .runners .StringRunner ;
4243
43- import static java .lang .String .valueOf ;
4444import static java .util .Collections .singletonMap ;
4545import static org .hamcrest .core .IsEqual .equalTo ;
4646import static org .junit .Assert .assertThat ;
5353import static org .neo4j .driver .v1 .tck .Environment .runners ;
5454import static org .neo4j .driver .v1 .tck .Environment .statementRunner ;
5555import 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 ;
5660import static org .neo4j .driver .v1 .tck .tck .util .Types .Type ;
5761import 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