Skip to content

Commit 95b7e50

Browse files
author
restsql
committed
restSQL 0.8.3 adds SQL IN operator
1 parent 3e25306 commit 95b7e50

18 files changed

Lines changed: 291 additions & 28 deletions

src/org/restsql/core/NameValuePairTest.java

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
/* Copyright (c) restSQL Project Contributors. Licensed under MIT. */
22
package org.restsql.core;
33

4-
import static org.junit.Assert.*;
4+
import static org.junit.Assert.assertEquals;
5+
6+
import java.util.ArrayList;
7+
import java.util.List;
58

69
import org.junit.Test;
710
import org.restsql.core.NameValuePair.Operator;
@@ -10,7 +13,31 @@
1013
* @author Mark Sawers
1114
*/
1215
public class NameValuePairTest {
13-
16+
@Test
17+
public void testParseInValues_Unescaped() {
18+
List<String> list = new ArrayList<String>();
19+
list.add("hello");
20+
assertEquals(list, NameValuePair.parseInValues("(hello)"));
21+
list.add("goodbye");
22+
assertEquals(list, NameValuePair.parseInValues("(hello,goodbye)"));
23+
list.add("it's me again");
24+
assertEquals(list, NameValuePair.parseInValues("(hello,goodbye,it's me again)"));
25+
}
26+
27+
@Test
28+
public void testParseInValues_EscapedDelimiter() {
29+
List<String> list = new ArrayList<String>();
30+
list.add("hel,lo");
31+
assertEquals(list, NameValuePair.parseInValues("(,hel\\,lo)"));
32+
list.add("3");
33+
assertEquals(list, NameValuePair.parseInValues("(,hel\\,lo,3)"));
34+
list.add("goodby,e");
35+
assertEquals(list, NameValuePair.parseInValues("(,hel\\,lo,3,goodby\\,e)"));
36+
list.add("5");
37+
assertEquals(list, NameValuePair.parseInValues("(,hel\\,lo,3,goodby\\,e,5)"));
38+
assertEquals(list, NameValuePair.parseInValues("(,hel\\,lo,3,goodby\\,e,5)"));
39+
}
40+
1441
/**
1542
* Test method for {@link org.restsql.core.NameValuePair#parseOperatorFromValue(java.lang.String)}.
1643
*/
@@ -19,6 +46,9 @@ public void testParseOperatorFromValue() {
1946
assertEquals(Operator.Equals, NameValuePair.parseOperatorFromValue("hello"));
2047
assertEquals(Operator.Equals, NameValuePair.parseOperatorFromValue("\\hello"));
2148
assertEquals(Operator.Escaped, NameValuePair.parseOperatorFromValue("\\<hello"));
49+
assertEquals(Operator.Escaped, NameValuePair.parseOperatorFromValue("\\(hello"));
50+
assertEquals(Operator.Escaped, NameValuePair.parseOperatorFromValue("\\(hello)"));
51+
assertEquals(Operator.In, NameValuePair.parseOperatorFromValue("(hello)"));
2252
assertEquals(Operator.LessThan, NameValuePair.parseOperatorFromValue("<hello"));
2353
assertEquals(Operator.LessThanOrEqualTo, NameValuePair.parseOperatorFromValue("<=hello"));
2454
assertEquals(Operator.GreaterThan, NameValuePair.parseOperatorFromValue(">hello"));
@@ -32,6 +62,7 @@ public void testParseOperatorFromValue() {
3262
public void testStripOperatorFromValue() {
3363
assertEquals("<=hello", NameValuePair.stripOperatorFromValue(Operator.Equals, "<=hello"));
3464
assertEquals("<hello", NameValuePair.stripOperatorFromValue(Operator.Escaped, "\\<hello"));
65+
assertEquals("(hello", NameValuePair.stripOperatorFromValue(Operator.Escaped, "\\(hello"));
3566
assertEquals("hello", NameValuePair.stripOperatorFromValue(Operator.LessThan, "<hello"));
3667
assertEquals("hello", NameValuePair.stripOperatorFromValue(Operator.LessThanOrEqualTo, "<=hello"));
3768
assertEquals("hello", NameValuePair.stripOperatorFromValue(Operator.GreaterThan, ">hello"));
@@ -58,6 +89,20 @@ public void testNameValuePairStringString() {
5889
assertEquals("<hello", pair.getValue());
5990
assertEquals(Operator.Equals, pair.getOperator());
6091

92+
pair = new NameValuePair("param1", "\\(hello");
93+
assertEquals("param1", pair.getName());
94+
assertEquals("(hello", pair.getValue());
95+
assertEquals(Operator.Equals, pair.getOperator());
96+
97+
pair = new NameValuePair("param1", "(hello,goodbye)");
98+
assertEquals("param1", pair.getName());
99+
assertEquals("(hello,goodbye)", pair.getValue());
100+
assertEquals(Operator.In, pair.getOperator());
101+
List<String> list = new ArrayList<String>();
102+
list.add("hello");
103+
list.add("goodbye");
104+
assertEquals(list, pair.getInValues());
105+
61106
pair = new NameValuePair("param1", "<hello");
62107
assertEquals("param1", pair.getName());
63108
assertEquals("hello", pair.getValue());

src/org/restsql/core/impl/SqlResourceMetadataTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,13 +319,17 @@ public void testGetTables_SingleTableAliased() throws SqlResourceException {
319319
assertEquals("film_id", table.getPrimaryKeys().get(0).getColumnName());
320320

321321
// Columns
322-
assertEquals(3, table.getColumns().size());
322+
assertEquals(5, table.getColumns().size());
323323
AssertionHelper.assertColumnMetaData(table.getColumns(), 1, true, "sakila", "film", "film_id", "id",
324324
Types.SMALLINT);
325325
AssertionHelper.assertColumnMetaData(table.getColumns(), 2, false, "sakila", "film", "title",
326326
"title", Types.VARCHAR);
327327
AssertionHelper.assertColumnMetaData(table.getColumns(), 3, false, "sakila", "film", "release_year",
328328
"year", (getDatabaseType() == DatabaseType.PostgreSql) ? Types.INTEGER : Types.DATE);
329+
AssertionHelper.assertColumnMetaData(table.getColumns(), 4, false, "sakila", "film", "description",
330+
"description", (getDatabaseType() == DatabaseType.PostgreSql) ? Types.VARCHAR : Types.LONGVARCHAR);
331+
AssertionHelper.assertColumnMetaData(table.getColumns(), 5, false, "sakila", "film", "rating",
332+
"rating", (getDatabaseType() == DatabaseType.PostgreSql) ? Types.OTHER : Types.CHAR);
329333
}
330334

331335
@Test

src/resources/xml/service/testcase/CompOper/TestSelect_DateGreater.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<sql>INSERT INTO datetime (id, time, timestamp, date, datetime) VALUES (1001, '10:54:00', '2011-07-22 10:54:00', '2011-07-22', '2011-07-22 10:54:00')</sql>
77
<sql>INSERT INTO datetime (id, time, timestamp, date, datetime) VALUES (1002, '09:54:00', '2011-07-22 09:54:00', '2011-07-22', '2011-07-22 09:54:00')</sql>
88
</setup>
9-
<step name="execute">
9+
<step name="verify">
1010
<!-- find records with timestamp greater than '2011-07-22 10:00:00' -->
1111
<request method="GET" uri="res/DateTime?timestamp=%3E2011-07-22%2010:00:00" />
1212
<response>

src/resources/xml/service/testcase/CompOper/TestSelect_DateGreaterEqual.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<sql>INSERT INTO datetime (id, time, timestamp, date, datetime) VALUES (1001, '10:54:00', '2011-07-22 10:54:00', '2011-07-22', '2011-07-22 10:54:00')</sql>
77
<sql>INSERT INTO datetime (id, time, timestamp, date, datetime) VALUES (1002, '09:54:00', '2011-07-22 09:54:00', '2011-07-22', '2011-07-22 09:54:00')</sql>
88
</setup>
9-
<step name="execute">
9+
<step name="verify">
1010
<!-- find records with timestamp greater than or equal to '2011-07-22 10:54:00' -->
1111
<request method="GET" uri="res/DateTime?timestamp=%3E%3D2011-07-22%2010:54:00" />
1212
<response>

src/resources/xml/service/testcase/CompOper/TestSelect_Escaped.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
<sql>INSERT INTO film_rating (film_rating_id,film_id,stars) VALUES (2,5001,2)</sql>
1010
<sql>INSERT INTO film_rating (film_rating_id,film_id,stars) VALUES (3,5002,1)</sql>
1111
</setup>
12-
<step name="execute">
13-
<!-- find records with title matching '<THE DARKENING' -->
12+
<step name="verify">
13+
<!-- find records with title matching '<THE DARKENING' (encode as '\<THE DARKENING')-->
1414
<request method="GET" uri="res/FlatOneToOne?title=%5C%3CTHE%20DARKENING" />
1515
<response>
1616
<body>

src/resources/xml/service/testcase/CompOper/TestSelect_NumericGreater.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<sql>INSERT INTO film_rating (film_rating_id,film_id,stars) VALUES (2,5001,2)</sql>
1010
<sql>INSERT INTO film_rating (film_rating_id,film_id,stars) VALUES (3,5002,1)</sql>
1111
</setup>
12-
<step name="execute">
12+
<step name="verify">
1313
<!-- find records with stars greater than 2 -->
1414
<request method="GET" uri="res/FlatOneToOne?stars=%3E2" />
1515
<response>

src/resources/xml/service/testcase/CompOper/TestSelect_NumericGreaterEqual.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<sql>INSERT INTO film_rating (film_rating_id,film_id,stars) VALUES (2,5001,2)</sql>
1010
<sql>INSERT INTO film_rating (film_rating_id,film_id,stars) VALUES (3,5002,1)</sql>
1111
</setup>
12-
<step name="execute">
12+
<step name="verify">
1313
<!-- find records with stars greater or equal to than 2 -->
1414
<request method="GET" uri="res/FlatOneToOne?stars=%3E%3D2" />
1515
<response>

src/resources/xml/service/testcase/CompOper/TestSelect_NumericLess.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<sql>INSERT INTO film_rating (film_rating_id,film_id,stars) VALUES (2,5001,2)</sql>
1010
<sql>INSERT INTO film_rating (film_rating_id,film_id,stars) VALUES (3,5002,1)</sql>
1111
</setup>
12-
<step name="execute">
12+
<step name="verify">
1313
<!-- find records with stars less than 5 -->
1414
<request method="GET" uri="res/FlatOneToOne?stars=%3C5" />
1515
<response>

src/resources/xml/service/testcase/CompOper/TestSelect_NumericLessEqual.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<sql>INSERT INTO film_rating (film_rating_id,film_id,stars) VALUES (2,5001,2)</sql>
1010
<sql>INSERT INTO film_rating (film_rating_id,film_id,stars) VALUES (3,5002,1)</sql>
1111
</setup>
12-
<step name="execute">
12+
<step name="verify">
1313
<!-- find records with stars less than or equal to 1 -->
1414
<request method="GET" uri="res/FlatOneToOne?stars=%3C%3D1" />
1515
<response>

src/resources/xml/service/testcase/CompOper/TestSelect_NumericRange.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<sql>INSERT INTO film_rating (film_rating_id,film_id,stars) VALUES (2,5001,2)</sql>
1010
<sql>INSERT INTO film_rating (film_rating_id,film_id,stars) VALUES (3,5002,1)</sql>
1111
</setup>
12-
<step name="execute">
12+
<step name="verify">
1313
<!-- find records with stars between 2 and 3 inclusive -->
1414
<request method="GET" uri="res/FlatOneToOne?stars=%3E%3D2&amp;stars=%3C%3D3" />
1515
<response>

0 commit comments

Comments
 (0)