Skip to content

Commit a593f23

Browse files
committed
extends tests
1 parent 1f767e1 commit a593f23

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

src/main/java/com/redislabs/redisgraph/ResultSet.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.redislabs.redisgraph;
22

33
import java.util.Iterator;
4+
import java.util.List;
45

56
/**
67
* Hold a query result
@@ -11,4 +12,6 @@ public interface ResultSet extends Iterator<Record>{
1112
* @return statistics object
1213
*/
1314
Statistics getStatistics();
15+
16+
List<String> getHeader();
1417
}

src/main/java/com/redislabs/redisgraph/impl/ResultSetImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public ResultSetImpl(List<Object> resp) {
4646
}
4747
}
4848

49+
@Override
4950
public List<String> getHeader(){
5051
return header;
5152
}

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

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.redislabs.redisgraph;
22

3+
import java.util.Arrays;
4+
import java.util.NoSuchElementException;
5+
36
import org.junit.Assert;
47
import org.junit.Before;
58
import org.junit.Test;
@@ -17,16 +20,21 @@ public RedisGraphAPITest() {
1720
}
1821

1922
@Before
20-
public void deleteGraph() throws Exception{
23+
public void deleteGraph(){
2124
api.deleteGraph();
2225
}
2326

2427
@Test
25-
public void testCreateNode() throws Exception {
28+
public void testCreateNode(){
2629
// Create a node
2730
ResultSet result = api.query("CREATE ({name:'roi',age:32})");
2831
Assert.assertFalse(result.hasNext());
2932

33+
try {
34+
result.next();
35+
Assert.fail();
36+
}catch(NoSuchElementException e) {}
37+
3038
Assert.assertEquals(1, result.getStatistics().nodesCreated());
3139
Assert.assertNull(result.getStatistics().getStringValue(Label.NODES_DELETED));
3240
Assert.assertNull(result.getStatistics().getStringValue(Label.RELATIONSHIPS_CREATED));
@@ -36,7 +44,7 @@ public void testCreateNode() throws Exception {
3644
}
3745

3846
@Test
39-
public void testCreateLabeledNode() throws Exception {
47+
public void testCreateLabeledNode(){
4048
// Create a node with a label
4149
ResultSet result = api.query("CREATE (:human{name:'danny',age:12})");
4250
Assert.assertFalse(result.hasNext());
@@ -47,7 +55,7 @@ public void testCreateLabeledNode() throws Exception {
4755
}
4856

4957
@Test
50-
public void testConnectNodes() throws Exception {
58+
public void testConnectNodes(){
5159
// Create both source and destination nodes
5260
Assert.assertNotNull(api.query("CREATE (:person{name:'roi',age:32})"));
5361
Assert.assertNotNull(api.query("CREATE (:person{name:'amit',age:30})"));
@@ -64,7 +72,7 @@ public void testConnectNodes() throws Exception {
6472
}
6573

6674
@Test
67-
public void testIndex() throws Exception {
75+
public void testIndex(){
6876
// Create both source and destination nodes
6977
Assert.assertNotNull(api.query("CREATE (:person{name:'roi',age:32})"));
7078

@@ -80,7 +88,7 @@ public void testIndex() throws Exception {
8088

8189

8290
@Test
83-
public void testQuery() throws Exception {
91+
public void testQuery(){
8492

8593
// Create both source and destination nodes
8694
Assert.assertNotNull(api.query("CREATE (:qhuman{name:'roi',age:32})"));
@@ -92,6 +100,9 @@ public void testQuery() throws Exception {
92100
// Query
93101
ResultSet resultSet = api.query("MATCH (a:qhuman)-[knows]->(:qhuman) RETURN a");
94102

103+
Assert.assertEquals(Arrays.asList("a.age", "a.name"), resultSet.getHeader());
104+
Assert.assertEquals("[a.age, a.name]\n[[32.000000, roi]]\n" + resultSet.getStatistics(), resultSet.toString());
105+
95106
Assert.assertTrue(resultSet.hasNext());
96107
Assert.assertEquals(0, resultSet.getStatistics().nodesCreated());
97108
Assert.assertEquals(0, resultSet.getStatistics().propertiesSet());
@@ -100,8 +111,16 @@ public void testQuery() throws Exception {
100111
Assert.assertNotNull(resultSet.getStatistics().getStringValue(Label.QUERY_INTERNAL_EXECUTION_TIME));
101112

102113
Record record = resultSet.next();
114+
Assert.assertEquals( Arrays.asList("a.age", "a.name"), record.keys());
115+
Assert.assertEquals( Arrays.asList("32.000000", "roi"), record.values());
116+
Assert.assertTrue(record.containsKey("a.name"));
117+
Assert.assertEquals( 2, record.size());
118+
Assert.assertEquals( "[32.000000, roi]", record.toString());
119+
103120
Assert.assertEquals( "roi", record.getString(1));
104121
Assert.assertEquals( "32.000000", record.getString(0));
105-
122+
Assert.assertEquals( "roi", record.getString("a.name"));
123+
Assert.assertEquals( "32.000000", record.getString("a.age"));
124+
106125
}
107126
}

0 commit comments

Comments
 (0)