Clover icon

Magnolia REST Content Delivery 2.0-rc1

  1. Project Clover database Mon Oct 30 2017 16:36:57 CET
  2. Package info.magnolia.rest.delivery.jcr

File FilteringConditionTest.java

 

Code metrics

0
26
12
1
156
69
12
0.46
2.17
12
1

Classes

Class Line # Actions
FilteringConditionTest 44 26 0% 12 0
1.0100%
 

Contributing tests

This file is covered by 12 tests. .

Source view

1    /**
2    * This file Copyright (c) 2017 Magnolia International
3    * Ltd. (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10    * This file is distributed in the hope that it will be
11    * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12    * implied warranty of MERCHANTABILITY or FITNESS FOR A
13    * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14    * Redistribution, except as permitted by whichever of the GPL
15    * or MNA you select, is prohibited.
16    *
17    * 1. For the GPL license (GPL), you can redistribute and/or
18    * modify this file under the terms of the GNU General
19    * Public License, Version 3, as published by the Free Software
20    * Foundation. You should have received a copy of the GNU
21    * General Public License, Version 3 along with this program;
22    * if not, write to the Free Software Foundation, Inc., 51
23    * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24    *
25    * 2. For the Magnolia Network Agreement (MNA), this file
26    * and the accompanying materials are made available under the
27    * terms of the MNA which accompanies this distribution, and
28    * is available at http://www.magnolia-cms.com/mna.html
29    *
30    * Any modifications to this file must keep this entire header
31    * intact.
32    *
33    */
34    package info.magnolia.rest.delivery.jcr;
35   
36    import static info.magnolia.rest.delivery.jcr.FilteringCondition.JCR_OFFSET_DATE_TIME;
37    import static org.junit.Assert.assertEquals;
38   
39    import java.time.ZoneId;
40    import java.time.ZonedDateTime;
41   
42    import org.junit.Test;
43   
 
44    public class FilteringConditionTest {
 
45  1 toggle @Test
46    public void withStringValue() {
47    // WHEN
48  1 FilteringCondition filteringCondition = new FilteringCondition("title", "About");
49   
50    // THEN
51  1 assertEquals("[title] = 'About'", filteringCondition.asSqlString());
52    }
53   
 
54  1 toggle @Test
55    public void withNumberValue() {
56    // WHEN
57  1 FilteringCondition filteringCondition = new FilteringCondition("size", "123");
58   
59    // THEN
60  1 assertEquals("[size] = 123", filteringCondition.asSqlString());
61    }
62   
 
63  1 toggle @Test
64    public void withFloatingPointNumberValue() {
65    // WHEN
66  1 FilteringCondition filteringCondition = new FilteringCondition("price", "99.99");
67   
68    // THEN
69  1 assertEquals("[price] = 99.99", filteringCondition.asSqlString());
70    }
71   
 
72  1 toggle @Test
73    public void withBooleanValue() {
74    // WHEN
75  1 FilteringCondition filteringCondition = new FilteringCondition("available", "true");
76   
77    // THEN
78  1 assertEquals("[available] = 'true'", filteringCondition.asSqlString());
79    }
80   
 
81  1 toggle @Test
82    public void withDateTimeValue() {
83    // WHEN
84  1 FilteringCondition filteringCondition = new FilteringCondition("publishedDate", "2015-01-26T23:17:02.000+07:00");
85   
86    // THEN
87  1 assertEquals("[publishedDate] = CAST('2015-01-26T23:17:02.000+07:00' AS DATE)", filteringCondition.asSqlString());
88    }
89   
 
90  1 toggle @Test
91    public void withDateValue() {
92    // GIVEN
93  1 ZonedDateTime expectedDate = ZonedDateTime.of(2015, 1, 26, 0, 0, 0, 0, ZoneId.systemDefault());
94  1 String expectedDateString = JCR_OFFSET_DATE_TIME.format(expectedDate);
95   
96    // WHEN
97  1 FilteringCondition filteringCondition = new FilteringCondition("birthday", "2015-01-26");
98   
99    // THEN
100  1 assertEquals("[birthday] = CAST('" + expectedDateString + "' AS DATE)", filteringCondition.asSqlString());
101    }
102   
 
103  1 toggle @Test
104    public void withMultipleNumberValues() {
105    // WHEN
106  1 FilteringCondition filteringCondition = new FilteringCondition("size", "100|200");
107   
108    // THEN
109  1 assertEquals("[size] = 100 OR [size] = 200", filteringCondition.asSqlString());
110    }
111   
 
112  1 toggle @Test
113    public void withPathParam() {
114    // WHEN
115  1 FilteringCondition filteringCondition = new FilteringCondition("@ancestor", "/travel/about");
116   
117    // THEN
118  1 assertEquals("ISDESCENDANTNODE('/travel/about')", filteringCondition.asSqlString());
119    }
120   
 
121  1 toggle @Test
122    public void withNameParam() {
123    // WHEN
124  1 FilteringCondition filteringCondition = new FilteringCondition("@name", "travel");
125   
126    // THEN
127  1 assertEquals("LOWER(NAME(t)) = 'travel'", filteringCondition.asSqlString());
128    }
129   
 
130  1 toggle @Test
131    public void withNameParamAndValueIsNotActuallyANumber() {
132    // WHEN
133  1 FilteringCondition filteringCondition = new FilteringCondition("@name", "00");
134   
135    // THEN
136  1 assertEquals("LOWER(NAME(t)) = '00'", filteringCondition.asSqlString());
137    }
138   
 
139  1 toggle @Test
140    public void paramNameContainsOperator() {
141    // WHEN
142  1 FilteringCondition filteringCondition = new FilteringCondition("price[gte]", "100");
143   
144    // THEN
145  1 assertEquals("[price] >= 100", filteringCondition.asSqlString());
146    }
147   
 
148  1 toggle @Test
149    public void paramNameAndOperatorAndMultipleValues() {
150    // WHEN
151  1 FilteringCondition filteringCondition = new FilteringCondition("price[ne]", "100|200");
152   
153    // THEN
154  1 assertEquals("[price] != 100 OR [price] != 200", filteringCondition.asSqlString());
155    }
156    }