Skip to content

Commit a455e77

Browse files
committed
Updated util methods
1 parent aef5c15 commit a455e77

File tree

2 files changed

+46
-10
lines changed

2 files changed

+46
-10
lines changed

driver/src/test/java/org/neo4j/driver/v1/tck/tck/util/ResultParser.java

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
/**
22
* Copyright (c) 2002-2016 "Neo Technology,"
33
* Network Engine for Objects in Lund AB [http://neotechnology.com]
4-
*
4+
* <p>
55
* This file is part of Neo4j.
6-
*
6+
* <p>
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
99
* You may obtain a copy of the License at
10-
*
11-
* http://www.apache.org/licenses/LICENSE-2.0
12-
*
10+
* <p>
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
* <p>
1313
* Unless required by applicable law or agreed to in writing, software
1414
* distributed under the License is distributed on an "AS IS" BASIS,
1515
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -195,7 +195,7 @@ private static Collection<String> getLabels( String input )
195195

196196
private static Map<String,Value> getProperties( String input )
197197
{
198-
Map<String,Object> result = getMapOfObjects( input );
198+
Map<String,Object> result = getMapOfObjects( input, false );
199199
HashMap<String,Value> properties = new HashMap<>();
200200
for ( String key : result.keySet() )
201201
{
@@ -298,6 +298,38 @@ else if ( TYPE_SYSTEM.PATH().isTypeOf( input ) )
298298
}
299299
}
300300

301+
public static Object getJavaValueIntAsLong( String value )
302+
{
303+
return getJavaValue( value, false );
304+
}
305+
306+
public static Object getJavaValueNormalInts( String value )
307+
{
308+
return getJavaValue( value, true );
309+
310+
}
311+
312+
private static Object getJavaValue( String value, boolean normalInts )
313+
{
314+
if ( isList( value ) )
315+
{
316+
ArrayList<Object> values = new ArrayList<>();
317+
for ( String val : getList( value ) )
318+
{
319+
values.add( Types.asObject( val ) );
320+
}
321+
return values;
322+
}
323+
else if ( isMap( value ) )
324+
{
325+
return getMapOfObjects( value, normalInts );
326+
}
327+
else
328+
{
329+
return Types.asObject( value );
330+
}
331+
}
332+
301333
public static Map<String,Value> parseExpected( Collection<String> input, List<String> keys )
302334
{
303335
assertEquals( keys.size(), input.size() );
@@ -332,7 +364,7 @@ public static String[] getList( String resultValue )
332364
return resultValue.substring( 1, resultValue.length() - 1 ).split( ", " );
333365
}
334366

335-
public static Map<String,Object> getMapOfObjects( String input )
367+
public static Map<String,Object> getMapOfObjects( String input, boolean normalInts )
336368
{
337369
Map<String,Object> properties = new HashMap<>();
338370
int i1 = input.indexOf( "{" );
@@ -344,8 +376,8 @@ public static Map<String,Object> getMapOfObjects( String input )
344376
input = input.substring( i1, i2 + 1 );
345377
try
346378
{
347-
ObjectMapper mapper = new ObjectMapper( );
348-
mapper.configure( DeserializationFeature.USE_LONG_FOR_INTS, true );
379+
ObjectMapper mapper = new ObjectMapper();
380+
mapper.configure( DeserializationFeature.USE_LONG_FOR_INTS, !normalInts );
349381
properties = mapper.readValue( input, HashMap.class );
350382
}
351383
catch ( IOException e )

driver/src/test/java/org/neo4j/driver/v1/tck/tck/util/Types.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,17 @@ public static Type getType( String stringType )
3838
throw new IllegalArgumentException( format( "There is no type: %s", stringType ) );
3939
}
4040

41-
public static Object asObject(String object)
41+
public static Object asObject( String object )
4242
{
4343
return getTypeFromStringConstellation( object ).getJavaValue( object );
4444
}
4545

4646
public static Type getTypeFromStringConstellation( String object )
4747
{
48+
if ( object.length() == 0 )
49+
{
50+
throw new IllegalArgumentException( "Cannot find matching type for expression: " + object );
51+
}
4852
if ( object.startsWith( "[:" ) && object.endsWith( "]" ) )
4953
{
5054
return Type.Relationship;

0 commit comments

Comments
 (0)