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