35
35
import org .neo4j .driver .v1 .Statement ;
36
36
import org .neo4j .driver .v1 .Value ;
37
37
import org .neo4j .driver .v1 .Values ;
38
+ import org .neo4j .driver .v1 .tck .tck .util .Types ;
38
39
import org .neo4j .driver .v1 .tck .tck .util .runners .CypherStatementRunner ;
39
40
import org .neo4j .driver .v1 .tck .tck .util .runners .MappedParametersRunner ;
40
41
import org .neo4j .driver .v1 .tck .tck .util .runners .StatementRunner ;
41
42
import org .neo4j .driver .v1 .tck .tck .util .runners .StringRunner ;
42
43
43
- import static java .lang .String .valueOf ;
44
44
import static java .util .Collections .singletonMap ;
45
45
import static org .hamcrest .core .IsEqual .equalTo ;
46
46
import static org .junit .Assert .assertThat ;
53
53
import static org .neo4j .driver .v1 .tck .Environment .runners ;
54
54
import static org .neo4j .driver .v1 .tck .Environment .statementRunner ;
55
55
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 ;
56
60
import static org .neo4j .driver .v1 .tck .tck .util .Types .Type ;
57
61
import static org .neo4j .driver .v1 .tck .tck .util .Types .getType ;
58
62
@@ -68,11 +72,11 @@ public void A_running_database() throws Throwable
68
72
}
69
73
}
70
74
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 )
73
77
throws Throwable
74
78
{
75
- expectedJavaValue = getType ( type ). getJavaValue ( value );
79
+ expectedJavaValue = getJavaValue ( value );
76
80
expectedBoltValue = Values .value ( expectedJavaValue );
77
81
}
78
82
@@ -97,13 +101,6 @@ public void a_Map_of_size_and_type_Type( long size, String type ) throws Throwab
97
101
expectedBoltValue = Values .value ( expectedJavaValue );
98
102
}
99
103
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
-
107
104
@ And ( "^the expected result is a bolt \" ([^\" ]*)\" of \" ([^\" ]*)\" $" )
108
105
public void the_expected_result_is_a_of ( String type , String value ) throws Throwable
109
106
{
@@ -114,7 +111,7 @@ public void the_expected_result_is_a_of( String type, String value ) throws Thro
114
111
@ When ( "^the driver asks the server to echo this value back$" )
115
112
public void the_driver_asks_the_server_to_echo_this_value_back () throws Throwable
116
113
{
117
- stringRunner = new StringRunner ( "RETURN " + boltValueAsCypherString ( expectedBoltValue ) );
114
+ stringRunner = new StringRunner ( "RETURN " + expectedBoltValue . toString ( ) );
118
115
mappedParametersRunner = new MappedParametersRunner ( "RETURN {input}" , "input" , expectedBoltValue );
119
116
statementRunner = new StatementRunner (
120
117
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
145
142
the_driver_asks_the_server_to_echo_this_value_back ();
146
143
}
147
144
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
160
147
{
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 )
163
150
{
164
- listOfObjects .add ( getType ( type ). getJavaValue ( map . get ( type ) ) );
151
+ listOfObjects .add ( getJavaValue ( value ) );
165
152
}
166
153
}
167
154
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
170
157
{
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 ) );
177
159
}
178
160
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
181
163
{
182
164
Map <String ,String > map = table .asMap ( String .class , String .class );
183
- for ( String type : map .keySet () )
165
+ for ( String key : map .keySet () )
184
166
{
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
+ }
186
171
}
187
172
}
188
173
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
203
176
{
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 ;
211
179
}
212
180
213
181
@ 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
225
193
}
226
194
}
227
195
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
+
228
217
public String getRandomString ( long size )
229
218
{
230
219
StringBuilder stringBuilder = new StringBuilder ();
@@ -242,7 +231,7 @@ public List<Object> getListOfRandomsOfTypes( Type type, long size )
242
231
List <Object > list = new ArrayList <>();
243
232
while ( size -- > 0 )
244
233
{
245
- list .add ( type .getRandomValue ( ) );
234
+ list .add ( type .getRandomValue () );
246
235
}
247
236
return list ;
248
237
}
@@ -257,20 +246,10 @@ public Map<String,Object> getMapOfRandomsOfTypes( Type type, long size )
257
246
return map ;
258
247
}
259
248
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
- }
271
249
272
250
public boolean databaseRunning ()
273
251
{
274
252
return session () != null ;
275
253
}
254
+
276
255
}
0 commit comments