Skip to content

Commit c3dc41d

Browse files
committed
start adding FilterTranslator Tests
1 parent 596c350 commit c3dc41d

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
Copyright 2015 Red Hat, Inc. and/or its affiliates.
3+
4+
This file is part of lightblue.
5+
6+
This program is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
package com.redhat.lightblue.crud.ldap;
20+
21+
import static org.junit.Assert.assertEquals;
22+
23+
import org.junit.Test;
24+
25+
import com.redhat.lightblue.query.BinaryComparisonOperator;
26+
import com.redhat.lightblue.query.Value;
27+
import com.redhat.lightblue.query.ValueComparisonExpression;
28+
import com.redhat.lightblue.util.Path;
29+
import com.unboundid.ldap.sdk.Filter;
30+
31+
public class FilterTranslatorTest {
32+
33+
@Test
34+
public void testTranslate_ValueEquals(){
35+
ValueComparisonExpression query = new ValueComparisonExpression(
36+
new Path("somekey"), BinaryComparisonOperator._eq, new Value("somevalue"));
37+
38+
Filter filter = new FilterTranslator().translate(query);
39+
assertEquals("(somekey=somevalue)", filter.toString());
40+
}
41+
42+
@Test
43+
public void testTranslate_ValueNotEquals(){
44+
ValueComparisonExpression query = new ValueComparisonExpression(
45+
new Path("somekey"), BinaryComparisonOperator._neq, new Value("somevalue"));
46+
47+
Filter filter = new FilterTranslator().translate(query);
48+
assertEquals("(!(somekey=somevalue))", filter.toString());
49+
}
50+
51+
@Test
52+
public void testTranslate_ValueGTE(){
53+
ValueComparisonExpression query = new ValueComparisonExpression(
54+
new Path("somekey"), BinaryComparisonOperator._gte, new Value("somevalue"));
55+
56+
Filter filter = new FilterTranslator().translate(query);
57+
assertEquals("(somekey>=somevalue)", filter.toString());
58+
}
59+
60+
@Test
61+
public void testTranslate_ValueGT(){
62+
ValueComparisonExpression query = new ValueComparisonExpression(
63+
new Path("somekey"), BinaryComparisonOperator._gt, new Value("somevalue"));
64+
65+
Filter filter = new FilterTranslator().translate(query);
66+
assertEquals("(!(somekey<=somevalue))", filter.toString());
67+
}
68+
69+
@Test
70+
public void testTranslate_ValueLTE(){
71+
ValueComparisonExpression query = new ValueComparisonExpression(
72+
new Path("somekey"), BinaryComparisonOperator._lte, new Value("somevalue"));
73+
74+
Filter filter = new FilterTranslator().translate(query);
75+
assertEquals("(somekey<=somevalue)", filter.toString());
76+
}
77+
78+
@Test
79+
public void testTranslate_ValueLT(){
80+
ValueComparisonExpression query = new ValueComparisonExpression(
81+
new Path("somekey"), BinaryComparisonOperator._lt, new Value("somevalue"));
82+
83+
Filter filter = new FilterTranslator().translate(query);
84+
assertEquals("(!(somekey>=somevalue))", filter.toString());
85+
}
86+
87+
}

0 commit comments

Comments
 (0)