Skip to content

Commit c14484e

Browse files
author
DvirDukhan
committed
moved exception testing to different file. added context connection testing.
1 parent 7f54c56 commit c14484e

File tree

2 files changed

+129
-26
lines changed

2 files changed

+129
-26
lines changed

src/test/java/com/redislabs/redisgraph/RedisGraphAPITest.java

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@
2020
import com.redislabs.redisgraph.Statistics.Label;
2121

2222
import static com.redislabs.redisgraph.Header.ResultSetColumnTypes.*;
23-
import com.redislabs.redisgraph.exceptions.JRedisGraphCompileTimeError;
24-
import com.redislabs.redisgraph.exceptions.JRedisGraphRunTimeError;
25-
import org.junit.Rule;
26-
import org.junit.rules.ExpectedException;
27-
import redis.clients.jedis.exceptions.JedisDataException;
2823

2924
public class RedisGraphAPITest {
3025
private RedisGraphContextGenerator api;
@@ -589,10 +584,6 @@ public void testMultiExec(){
589584
Assert.assertEquals(Arrays.asList("n"), record.keys());
590585
Assert.assertEquals(expectedNode, record.getValue("n"));
591586

592-
// Graph delete
593-
Assert.assertTrue(((String)results.get(6)).startsWith("Graph removed"));
594-
595-
596587
Assert.assertEquals(ResultSetImpl.class, results.get(7).getClass());
597588
resultSet = (ResultSet) results.get(7);
598589

@@ -887,21 +878,4 @@ record = resultSet.next();
887878

888879
}
889880

890-
@Rule
891-
public ExpectedException exceptionRule = ExpectedException.none();
892-
893-
@Test
894-
public void testErrorReporting() {
895-
Assert.assertNotNull(api.query("social", "CREATE (:person{mixed_prop: 'strval'}), (:person{mixed_prop: 50})"));
896-
897-
exceptionRule.expect(JRedisGraphCompileTimeError.class);
898-
exceptionRule.expectMessage("Type mismatch: expected String but was Integer");
899-
900-
// Issue a query that causes a compile-time error
901-
api.query("social", "RETURN toUpper(5)");
902-
903-
exceptionRule.expect(JRedisGraphRunTimeError.class);
904-
// Issue a query that causes a run-time error
905-
api.query("social", "MATCH (p:person) RETURN toUpper(p.mixed_prop)");
906-
}
907881
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
package com.redislabs.redisgraph.exceptions;
2+
3+
import com.redislabs.redisgraph.RedisGraphContext;
4+
import com.redislabs.redisgraph.RedisGraphContextGenerator;
5+
import com.redislabs.redisgraph.impl.api.RedisGraph;
6+
import org.junit.After;
7+
import org.junit.Assert;
8+
import org.junit.Before;
9+
import org.junit.Rule;
10+
import org.junit.Test;
11+
import org.junit.rules.ExpectedException;
12+
13+
14+
public class JRedisGraphErrorTest {
15+
16+
private RedisGraphContextGenerator api;
17+
18+
@Before
19+
public void createApi(){
20+
api = new RedisGraph();
21+
Assert.assertNotNull(api.query("social", "CREATE (:person{mixed_prop: 'strval'}), (:person{mixed_prop: 50})"));
22+
}
23+
@After
24+
public void deleteGraph() {
25+
26+
api.deleteGraph("social");
27+
api.close();
28+
}
29+
30+
@Rule
31+
public ExpectedException exceptionRule = ExpectedException.none();
32+
33+
@Test
34+
public void testSyntaxErrorReporting() {
35+
exceptionRule.expect(JRedisGraphCompileTimeError.class);
36+
exceptionRule.expectMessage("Type mismatch: expected String but was Integer");
37+
38+
// Issue a query that causes a compile-time error
39+
api.query("social", "RETURN toUpper(5)");
40+
41+
}
42+
43+
@Test
44+
public void testRuntimeErrorReporting() {
45+
exceptionRule.expect(JRedisGraphRunTimeError.class);
46+
exceptionRule.expectMessage("Type mismatch: expected String but was Integer");
47+
48+
// Issue a query that causes a run-time error
49+
api.query("social", "MATCH (p:person) RETURN toUpper(p.mixed_prop)");
50+
}
51+
52+
@Test
53+
public void testExceptionFlow() {
54+
55+
try {
56+
// Issue a query that causes a compile-time error
57+
api.query("social", "RETURN toUpper(5)");
58+
}
59+
catch (Exception e) {
60+
Assert.assertEquals(JRedisGraphCompileTimeError.class, e.getClass());
61+
Assert.assertTrue( e.getMessage().contains("Type mismatch: expected String but was Integer"));
62+
}
63+
64+
// On general api usage, user should get a new connection
65+
66+
try {
67+
// Issue a query that causes a compile-time error
68+
api.query("social", "MATCH (p:person) RETURN toUpper(p.mixed_prop)");
69+
}
70+
catch (Exception e) {
71+
Assert.assertEquals(JRedisGraphRunTimeError.class, e.getClass());
72+
Assert.assertTrue( e.getMessage().contains("Type mismatch: expected String but was Integer"));
73+
}
74+
75+
}
76+
77+
78+
@Test
79+
public void testContextSyntaxErrorReporting() {
80+
exceptionRule.expect(JRedisGraphCompileTimeError.class);
81+
exceptionRule.expectMessage("Type mismatch: expected String but was Integer");
82+
RedisGraphContext c = api.getContext();
83+
84+
// Issue a query that causes a compile-time error
85+
c.query("social", "RETURN toUpper(5)");
86+
87+
}
88+
89+
@Test
90+
public void testContextRuntimeErrorReporting() {
91+
exceptionRule.expect(JRedisGraphRunTimeError.class);
92+
exceptionRule.expectMessage("Type mismatch: expected String but was Integer");
93+
94+
RedisGraphContext c = api.getContext();
95+
// Issue a query that causes a run-time error
96+
c.query("social", "MATCH (p:person) RETURN toUpper(p.mixed_prop)");
97+
}
98+
99+
100+
101+
102+
@Test
103+
public void testContextExceptionFlow() {
104+
105+
RedisGraphContext c = api.getContext();
106+
try {
107+
// Issue a query that causes a compile-time error
108+
c.query("social", "RETURN toUpper(5)");
109+
}
110+
catch (Exception e) {
111+
Assert.assertEquals(JRedisGraphCompileTimeError.class, e.getClass());
112+
Assert.assertTrue( e.getMessage().contains("Type mismatch: expected String but was Integer"));
113+
}
114+
115+
// On contexted api usage, connection should stay open
116+
117+
try {
118+
// Issue a query that causes a compile-time error
119+
c.query("social", "MATCH (p:person) RETURN toUpper(p.mixed_prop)");
120+
}
121+
catch (Exception e) {
122+
Assert.assertEquals(JRedisGraphRunTimeError.class, e.getClass());
123+
Assert.assertTrue( e.getMessage().contains("Type mismatch: expected String but was Integer"));
124+
}
125+
126+
}
127+
128+
129+
}

0 commit comments

Comments
 (0)