-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathJRedisGraphErrorTest.java
195 lines (161 loc) · 6.3 KB
/
JRedisGraphErrorTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package com.redislabs.redisgraph.exceptions;
import com.redislabs.redisgraph.RedisGraphContext;
import com.redislabs.redisgraph.RedisGraphContextGenerator;
import com.redislabs.redisgraph.impl.api.RedisGraph;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
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})"));
}
@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());
}
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());
}
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());
}
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() {
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"));
}
// 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() {
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(){
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(){
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() {
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"));
}
// 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"));
}
}
}