Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

increase code coverage #90

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public ResultSet build(Object o) {
* @return response with result set with the procedure data
*/
public Response<ResultSet> callProcedure(String graphId, String procedure){
return callProcedure(graphId, procedure, Utils.DUMMY_LIST, Utils.DUMMY_MAP);
return callProcedure(graphId, procedure, Utils.DUMMY_LIST);
}

/**
Expand All @@ -106,7 +106,7 @@ public Response<ResultSet> callProcedure(String graphId, String procedure){
* @param args procedure arguments
* @return response with result set with the procedure data
*/
public Response<ResultSet> callProcedure(String graphId, String procedure, List<String> args ){
public Response<ResultSet> callProcedure(String graphId, String procedure, List<String> args){
return callProcedure(graphId, procedure, args, Utils.DUMMY_MAP);
}

Expand Down
27 changes: 24 additions & 3 deletions src/test/java/com/redislabs/redisgraph/RedisGraphAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -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());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this to a different unit test file. break every functionality to test case

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());
Comment on lines +75 to +81
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you use juint 5 for assertThrows?
https://www.baeldung.com/junit-assert-exception

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are not using Junit 5

}

@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"));
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down