diff --git a/src/main/java/com/redislabs/redisgraph/impl/api/RedisGraphTransaction.java b/src/main/java/com/redislabs/redisgraph/impl/api/RedisGraphTransaction.java index 11fca09..4d0b4f1 100644 --- a/src/main/java/com/redislabs/redisgraph/impl/api/RedisGraphTransaction.java +++ b/src/main/java/com/redislabs/redisgraph/impl/api/RedisGraphTransaction.java @@ -96,7 +96,7 @@ public ResultSet build(Object o) { * @return response with result set with the procedure data */ public Response callProcedure(String graphId, String procedure){ - return callProcedure(graphId, procedure, Utils.DUMMY_LIST, Utils.DUMMY_MAP); + return callProcedure(graphId, procedure, Utils.DUMMY_LIST); } /** @@ -106,7 +106,7 @@ public Response callProcedure(String graphId, String procedure){ * @param args procedure arguments * @return response with result set with the procedure data */ - public Response callProcedure(String graphId, String procedure, List args ){ + public Response callProcedure(String graphId, String procedure, List args){ return callProcedure(graphId, procedure, args, Utils.DUMMY_MAP); } diff --git a/src/test/java/com/redislabs/redisgraph/RedisGraphAPITest.java b/src/test/java/com/redislabs/redisgraph/RedisGraphAPITest.java index 8570355..811db2d 100644 --- a/src/test/java/com/redislabs/redisgraph/RedisGraphAPITest.java +++ b/src/test/java/com/redislabs/redisgraph/RedisGraphAPITest.java @@ -2,6 +2,7 @@ import java.util.*; +import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -267,8 +268,8 @@ public void testRecord(){ Assert.assertEquals(0, resultSet.getStatistics().relationshipsCreated()); Assert.assertEquals(0, resultSet.getStatistics().relationshipsDeleted()); Assert.assertNotNull(resultSet.getStatistics().getStringValue(Label.QUERY_INTERNAL_EXECUTION_TIME)); - - + Assert.assertTrue(Pattern.matches("StatisticsImpl\\{statistics=\\{Cached execution=0, Query internal execution time=[0-9]*\\.[0-9]* milliseconds\\}\\}", resultSet.getStatistics().toString())); + Assert.assertEquals(1, resultSet.size()); Assert.assertTrue(resultSet.hasNext()); Record record = resultSet.next(); @@ -285,6 +286,9 @@ public void testRecord(){ Edge edge = record.getValue(1); Assert.assertNotNull(edge); Assert.assertEquals(expectedEdge, edge); + Assert.assertEquals(1, edge.getDestination()); + Assert.assertEquals(0, edge.getSource()); + Assert.assertEquals("knows", edge.getRelationshipType()); edge = record.getValue("r"); Assert.assertEquals(expectedEdge, edge); @@ -308,7 +312,24 @@ public void testRecord(){ Assert.assertEquals( 32L, ((Long)record.getValue("a.age")).longValue()); Assert.assertEquals( "roi", record.getString("a.name")); Assert.assertEquals( "32", record.getString("a.age")); - + + Assert.assertTrue( record.containsKey("a.name")); + Assert.assertFalse( record.containsKey("a.addr")); + Assert.assertEquals("Record{" + + "values=[Node{labels=[person], id=0, propertyMap={" + + "name=Property{name='name', value=roi}, " + + "boolValue=Property{name='boolValue', value=true}, " + + "doubleValue=Property{name='doubleValue', value=3.14}, " + + "nullValue=Property{name='nullValue', value=null}, " + + "age=Property{name='age', value=32}}}, " + + "Edge{relationshipType='knows', source=0, destination=1, id=0, " + + "propertyMap={boolValue=Property{name='boolValue', value=false}, " + + "place=Property{name='place', value=TLV}, " + + "doubleValue=Property{name='doubleValue', value=3.14}, " + + "nullValue=Property{name='nullValue', value=null}, " + + "since=Property{name='since', value=2000}}}, " + + "roi, 32, 3.14, true, null, TLV, 2000, 3.14, false, null]" + + "}", record.toString()); } diff --git a/src/test/java/com/redislabs/redisgraph/exceptions/JRedisGraphErrorTest.java b/src/test/java/com/redislabs/redisgraph/exceptions/JRedisGraphErrorTest.java index 443588c..7f57d41 100644 --- a/src/test/java/com/redislabs/redisgraph/exceptions/JRedisGraphErrorTest.java +++ b/src/test/java/com/redislabs/redisgraph/exceptions/JRedisGraphErrorTest.java @@ -6,136 +6,190 @@ import org.junit.After; import org.junit.Assert; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import java.util.HashMap; public class JRedisGraphErrorTest { - private RedisGraphContextGenerator api; - - @Before - public void createApi(){ - api = new RedisGraph(); - Assert.assertNotNull(api.query("social", "CREATE (:person{mixed_prop: 'strval'}), (:person{mixed_prop: 50})")); + private RedisGraphContextGenerator api; + + @Before + public void createApi(){ + api = new RedisGraph(); + Assert.assertNotNull(api.query("social", "CREATE (:person{mixed_prop: 'strval'}), (:person{mixed_prop: 50})")); + } + @After + public void deleteGraph() { + + api.deleteGraph("social"); + api.close(); + } + + @Test + public void testExceptions() { + try { + throw new JRedisGraphCompileTimeException("Test message 1"); + }catch (JRedisGraphCompileTimeException e) { + Assert.assertEquals( "Test message 1", e.getMessage()); } - @After - public void deleteGraph() { - api.deleteGraph("social"); - api.close(); + Exception cause = new IndexOutOfBoundsException("Index Error"); + try { + throw new JRedisGraphCompileTimeException("Test message 2", cause); + }catch (JRedisGraphCompileTimeException e) { + Assert.assertEquals( "Test message 2", e.getMessage()); + Assert.assertEquals( cause, e.getCause()); } - @Rule - public ExpectedException exceptionRule = ExpectedException.none(); - - @Test - public void testSyntaxErrorReporting() { - exceptionRule.expect(JRedisGraphCompileTimeException.class); - exceptionRule.expectMessage("Type mismatch: expected String but was Integer"); + try { + throw new JRedisGraphCompileTimeException(cause); + }catch (JRedisGraphCompileTimeException e) { + Assert.assertEquals( "java.lang.IndexOutOfBoundsException: Index Error", e.getMessage()); + Assert.assertEquals( cause, e.getCause()); + } + + try { + throw new JRedisGraphRunTimeException("Test message 3"); + }catch (JRedisGraphRunTimeException e) { + Assert.assertEquals( "Test message 3", e.getMessage()); + } - // Issue a query that causes a compile-time error - api.query("social", "RETURN toUpper(5)"); + try { + throw new JRedisGraphRunTimeException("Test message 4", cause); + }catch (JRedisGraphRunTimeException e) { + Assert.assertEquals( "Test message 4", e.getMessage()); + Assert.assertEquals( cause, e.getCause()); + } + try { + throw new JRedisGraphRunTimeException(cause); + }catch (JRedisGraphRunTimeException e) { + Assert.assertEquals( "java.lang.IndexOutOfBoundsException: Index Error", e.getMessage()); + Assert.assertEquals( cause, e.getCause()); + } + } + + @Test + public void testSyntaxErrorReporting() { + try { + // Issue a query that causes a compile-time error + api.query("social", "RETURN toUpper(5)"); + } catch (Exception e) { + Assert.assertEquals(JRedisGraphCompileTimeException.class, e.getClass()); + Assert.assertEquals( "redis.clients.jedis.exceptions.JedisDataException: Type mismatch: expected String but was Integer", e.getMessage()); } - @Test - public void testRuntimeErrorReporting() { - exceptionRule.expect(JRedisGraphRunTimeException.class); - exceptionRule.expectMessage("Type mismatch: expected String but was Integer"); + } - // Issue a query that causes a run-time error - api.query("social", "MATCH (p:person) RETURN toUpper(p.mixed_prop)"); + @Test + public void testRuntimeErrorReporting() { + try { + // Issue a query that causes a run-time error + api.query("social", "MATCH (p:person) RETURN toUpper(p.mixed_prop)"); + } catch (Exception e) { + Assert.assertEquals(JRedisGraphRunTimeException.class, e.getClass()); + Assert.assertEquals( "redis.clients.jedis.exceptions.JedisDataException: Type mismatch: expected String but was Integer", e.getMessage()); } + } - @Test - public void testExceptionFlow() { - try { - // Issue a query that causes a compile-time error - api.query("social", "RETURN toUpper(5)"); - } - catch (Exception e) { - Assert.assertEquals(JRedisGraphCompileTimeException.class, e.getClass()); - Assert.assertTrue( e.getMessage().contains("Type mismatch: expected String but was Integer")); - } + @Test + public void testExceptionFlow() { - // On general api usage, user should get a new connection + try { + // Issue a query that causes a compile-time error + api.query("social", "RETURN toUpper(5)"); + } + catch (Exception e) { + Assert.assertEquals(JRedisGraphCompileTimeException.class, e.getClass()); + Assert.assertTrue( e.getMessage().contains("Type mismatch: expected String but was Integer")); + } - try { - // Issue a query that causes a compile-time error - api.query("social", "MATCH (p:person) RETURN toUpper(p.mixed_prop)"); - } - catch (Exception e) { - Assert.assertEquals(JRedisGraphRunTimeException.class, e.getClass()); - Assert.assertTrue( e.getMessage().contains("Type mismatch: expected String but was Integer")); - } + // On general api usage, user should get a new connection + try { + // Issue a query that causes a compile-time error + api.query("social", "MATCH (p:person) RETURN toUpper(p.mixed_prop)"); + } + catch (Exception e) { + Assert.assertEquals(JRedisGraphRunTimeException.class, e.getClass()); + Assert.assertTrue( e.getMessage().contains("Type mismatch: expected String but was Integer")); } + } - @Test - public void testContextSyntaxErrorReporting() { - exceptionRule.expect(JRedisGraphCompileTimeException.class); - exceptionRule.expectMessage("Type mismatch: expected String but was Integer"); - RedisGraphContext c = api.getContext(); - - // Issue a query that causes a compile-time error - c.query("social", "RETURN toUpper(5)"); + @Test + public void testContextSyntaxErrorReporting() { + RedisGraphContext c = api.getContext(); + try { + // Issue a query that causes a compile-time error + c.query("social", "RETURN toUpper(5)"); + } catch (Exception e) { + Assert.assertEquals(JRedisGraphCompileTimeException.class, e.getClass()); + Assert.assertEquals( "redis.clients.jedis.exceptions.JedisDataException: Type mismatch: expected String but was Integer", e.getMessage()); } - - @Test - public void testMissingParametersSyntaxErrorReporting(){ - exceptionRule.expect(JRedisGraphRunTimeException.class); - exceptionRule.expectMessage("Missing parameters"); - api.query("social","RETURN $param"); + } + + @Test + public void testMissingParametersSyntaxErrorReporting(){ + try { + api.query("social","RETURN $param"); + } catch (Exception e) { + Assert.assertEquals(JRedisGraphRunTimeException.class, e.getClass()); + Assert.assertEquals( "redis.clients.jedis.exceptions.JedisDataException: Missing parameters", e.getMessage()); } - - @Test - public void testMissingParametersSyntaxErrorReporting2(){ - exceptionRule.expect(JRedisGraphRunTimeException.class); - exceptionRule.expectMessage("Missing parameters"); - api.query("social","RETURN $param", new HashMap<>()); + } + + @Test + public void testMissingParametersSyntaxErrorReporting2(){ + try { + api.query("social","RETURN $param", new HashMap<>()); + } catch (Exception e) { + Assert.assertEquals(JRedisGraphRunTimeException.class, e.getClass()); + Assert.assertEquals( "redis.clients.jedis.exceptions.JedisDataException: Missing parameters", e.getMessage()); } - - @Test - public void testContextRuntimeErrorReporting() { - exceptionRule.expect(JRedisGraphRunTimeException.class); - exceptionRule.expectMessage("Type mismatch: expected String but was Integer"); - - RedisGraphContext c = api.getContext(); - // Issue a query that causes a run-time error - c.query("social", "MATCH (p:person) RETURN toUpper(p.mixed_prop)"); + } + + @Test + public void testContextRuntimeErrorReporting() { + + RedisGraphContext c = api.getContext(); + try { + // Issue a query that causes a run-time error + c.query("social", "MATCH (p:person) RETURN toUpper(p.mixed_prop)"); + } catch (Exception e) { + Assert.assertEquals(JRedisGraphRunTimeException.class, e.getClass()); + Assert.assertEquals( "redis.clients.jedis.exceptions.JedisDataException: Type mismatch: expected String but was Integer", e.getMessage()); } + } - @Test - public void testContextExceptionFlow() { - - RedisGraphContext c = api.getContext(); - try { - // Issue a query that causes a compile-time error - c.query("social", "RETURN toUpper(5)"); - } - catch (Exception e) { - Assert.assertEquals(JRedisGraphCompileTimeException.class, e.getClass()); - Assert.assertTrue( e.getMessage().contains("Type mismatch: expected String but was Integer")); - } + @Test + public void testContextExceptionFlow() { - // On contexted api usage, connection should stay open + RedisGraphContext c = api.getContext(); + try { + // Issue a query that causes a compile-time error + c.query("social", "RETURN toUpper(5)"); + } + catch (Exception e) { + Assert.assertEquals(JRedisGraphCompileTimeException.class, e.getClass()); + Assert.assertTrue( e.getMessage().contains("Type mismatch: expected String but was Integer")); + } - try { - // Issue a query that causes a compile-time error - c.query("social", "MATCH (p:person) RETURN toUpper(p.mixed_prop)"); - } - catch (Exception e) { - Assert.assertEquals(JRedisGraphRunTimeException.class, e.getClass()); - Assert.assertTrue( e.getMessage().contains("Type mismatch: expected String but was Integer")); - } + // On contexted api usage, connection should stay open + try { + // Issue a query that causes a compile-time error + c.query("social", "MATCH (p:person) RETURN toUpper(p.mixed_prop)"); } + catch (Exception e) { + Assert.assertEquals(JRedisGraphRunTimeException.class, e.getClass()); + Assert.assertTrue( e.getMessage().contains("Type mismatch: expected String but was Integer")); + } + + } } diff --git a/src/test/java/com/redislabs/redisgraph/graph_entities/PathTest.java b/src/test/java/com/redislabs/redisgraph/graph_entities/PathTest.java index ee65e68..6056ccf 100644 --- a/src/test/java/com/redislabs/redisgraph/graph_entities/PathTest.java +++ b/src/test/java/com/redislabs/redisgraph/graph_entities/PathTest.java @@ -45,6 +45,8 @@ public void testEmptyPath(){ assertEquals(0, path.nodeCount()); assertThrows(IndexOutOfBoundsException.class, ()->path.getNode(0)); assertThrows(IndexOutOfBoundsException.class, ()->path.getEdge(0)); + + assertEquals("Path{nodes=[], edges=[]}", path.toString()); } @Test @@ -57,6 +59,8 @@ public void testSingleNodePath(){ assertEquals(n, path.firstNode()); assertEquals(n, path.lastNode()); assertEquals(n, path.getNode(0)); + + assertEquals("Path{nodes=[Node{labels=[], id=0, propertyMap={}}], edges=[]}", path.toString()); } @Test @@ -65,7 +69,7 @@ public void testRandomLengthPath(){ Path path = buildPath(nodeCount); assertEquals(buildNodeArray(nodeCount), path.getNodes()); assertEquals(buildEdgeArray(nodeCount-1), path.getEdges()); - assertDoesNotThrow(()->path.getEdge(0)); + assertDoesNotThrow(()->path.getEdge(0)); } @Test