Skip to content

Commit 13a4cfd

Browse files
author
Zhen Li
committed
Adding error check of unsupported types
1 parent bee069a commit 13a4cfd

File tree

5 files changed

+54
-5
lines changed

5 files changed

+54
-5
lines changed

driver/src/main/java/org/neo4j/driver/v1/Values.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@
4949
import org.neo4j.driver.internal.value.LocalDateTimeValue;
5050
import org.neo4j.driver.internal.value.LocalTimeValue;
5151
import org.neo4j.driver.internal.value.MapValue;
52+
import org.neo4j.driver.internal.value.NodeValue;
5253
import org.neo4j.driver.internal.value.NullValue;
54+
import org.neo4j.driver.internal.value.PathValue;
5355
import org.neo4j.driver.internal.value.PointValue;
56+
import org.neo4j.driver.internal.value.RelationshipValue;
5457
import org.neo4j.driver.internal.value.StringValue;
5558
import org.neo4j.driver.internal.value.TimeValue;
5659
import org.neo4j.driver.v1.exceptions.ClientException;
@@ -91,6 +94,10 @@ public static Value value( Object value )
9194
{
9295
if ( value == null ) { return NullValue.NULL; }
9396

97+
if ( value instanceof NodeValue || value instanceof RelationshipValue || value instanceof PathValue )
98+
{
99+
throw new ClientException( "Unsupported param type " + ((AsValue) value).asValue().type().name() );
100+
}
94101
if ( value instanceof AsValue ) { return ((AsValue) value).asValue(); }
95102
if ( value instanceof Boolean ) { return value( (boolean) value ); }
96103
if ( value instanceof String ) { return value( (String) value ); }

driver/src/test/java/org/neo4j/driver/internal/ValuesTest.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
import org.neo4j.driver.internal.value.LocalDateTimeValue;
4747
import org.neo4j.driver.internal.value.LocalTimeValue;
4848
import org.neo4j.driver.internal.value.MapValue;
49+
import org.neo4j.driver.internal.value.NodeValue;
50+
import org.neo4j.driver.internal.value.PathValue;
51+
import org.neo4j.driver.internal.value.RelationshipValue;
4952
import org.neo4j.driver.internal.value.TimeValue;
5053
import org.neo4j.driver.v1.Value;
5154
import org.neo4j.driver.v1.Values;
@@ -60,6 +63,9 @@
6063
import static org.junit.Assert.assertEquals;
6164
import static org.junit.Assert.assertNotEquals;
6265
import static org.junit.Assert.assertThat;
66+
import static org.neo4j.driver.internal.value.NodeValueTest.emptyNodeValue;
67+
import static org.neo4j.driver.internal.value.PathValueTest.pathValue;
68+
import static org.neo4j.driver.internal.value.RelationshipValueTest.emptyRelationshipValue;
6369
import static org.neo4j.driver.v1.Values.isoDuration;
6470
import static org.neo4j.driver.v1.Values.ofDouble;
6571
import static org.neo4j.driver.v1.Values.ofFloat;
@@ -483,4 +489,40 @@ public void shouldCreateValueFromPoint3D()
483489
assertEquals( point3D, point3DValue2.asPoint() );
484490
assertEquals( point3DValue1, point3DValue2 );
485491
}
492+
493+
@Test
494+
public void shouldComplainAboutNodeType() throws Throwable
495+
{
496+
// Expect
497+
exception.expect( ClientException.class );
498+
exception.expectMessage( "Unsupported param type NODE" );
499+
500+
// When
501+
NodeValue node = emptyNodeValue();
502+
value( node );
503+
}
504+
505+
@Test
506+
public void shouldComplainAboutRelationshipType() throws Throwable
507+
{
508+
// Expect
509+
exception.expect( ClientException.class );
510+
exception.expectMessage( "Unsupported param type RELATIONSHIP" );
511+
512+
// When
513+
RelationshipValue rel = emptyRelationshipValue();
514+
value( rel );
515+
}
516+
517+
@Test
518+
public void shouldComplainAboutPathType() throws Throwable
519+
{
520+
// Expect
521+
exception.expect( ClientException.class );
522+
exception.expectMessage( "Unsupported param type PATH" );
523+
524+
// When
525+
PathValue path = pathValue();
526+
value( path );
527+
}
486528
}

driver/src/test/java/org/neo4j/driver/internal/value/NodeValueTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ public void shouldTypeAsNode()
7070
assertThat( value.typeConstructor(), equalTo( TypeConstructor.NODE ) );
7171
}
7272

73-
private NodeValue emptyNodeValue()
73+
public static NodeValue emptyNodeValue()
7474
{
7575
return new NodeValue( new InternalNode( 1234, singletonList( "User" ), new HashMap<String, Value>() ) );
7676
}
7777

78-
private NodeValue filledNodeValue()
78+
private static NodeValue filledNodeValue()
7979
{
8080
return new NodeValue( new InternalNode( 1234, singletonList( "User" ), singletonMap( "name", value( "Dodo" ) ) ) );
8181
}

driver/src/test/java/org/neo4j/driver/internal/value/PathValueTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void shouldHaveCorrectType() throws Throwable
5454
assertThat(pathValue().type(), equalTo( InternalTypeSystem.TYPE_SYSTEM.PATH() ));
5555
}
5656

57-
private PathValue pathValue()
57+
public static PathValue pathValue()
5858
{
5959
return new PathValue( new InternalPath( new InternalNode(42L), new InternalRelationship( 43L, 42L, 44L, "T" ), new InternalNode( 44L ) ) );
6060
}

driver/src/test/java/org/neo4j/driver/internal/value/RelationshipValueTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ public void shouldTypeAsRelationship()
6161
assertThat( value.typeConstructor(), equalTo( TypeConstructor.RELATIONSHIP ) );
6262
}
6363

64-
private RelationshipValue emptyRelationshipValue()
64+
public static RelationshipValue emptyRelationshipValue()
6565
{
6666
return new RelationshipValue( new InternalRelationship( 1234, 1, 2, "KNOWS" ) );
6767
}
6868

69-
private RelationshipValue filledRelationshipValue()
69+
private static RelationshipValue filledRelationshipValue()
7070
{
7171
return new RelationshipValue( new InternalRelationship( 1234, 1, 2, "KNOWS", singletonMap( "name", value( "Dodo" ) ) ) );
7272
}

0 commit comments

Comments
 (0)