|
1 | 1 | /* |
2 | | - * Copyright (C) 2017-2019 HERE Europe B.V. |
| 2 | + * Copyright (C) 2017-2025 HERE Europe B.V. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
20 | 20 | package com.here.xyz.hub.rest; |
21 | 21 |
|
22 | 22 | import static org.junit.Assert.assertEquals; |
| 23 | +import static org.junit.Assert.assertTrue; |
23 | 24 |
|
24 | 25 | import com.here.xyz.events.PropertiesQuery; |
25 | 26 | import com.here.xyz.events.PropertyQuery; |
@@ -69,7 +70,6 @@ public void parsePropertiesQuery() { |
69 | 70 | assertEquals(2, query.getValues().size()); |
70 | 71 | assertEquals("string", query.getValues().get(0)); |
71 | 72 | assertEquals("5", query.getValues().get(1)); |
72 | | - |
73 | 73 | } |
74 | 74 |
|
75 | 75 | @Test |
@@ -148,4 +148,93 @@ public void parsePropertiesQuerySpace() { |
148 | 148 | assertEquals(1, query.getValues().size()); |
149 | 149 | assertEquals(3L, query.getValues().get(0)); |
150 | 150 | } |
| 151 | + |
| 152 | + @Test |
| 153 | + public void parsePropertiesQueryJsonPath() { |
| 154 | + String URIquery = "p.jsonPath=$.properties.address.city"; |
| 155 | + PropertiesQuery pq = PropertiesQuery.fromString(URIquery, "", false); |
| 156 | + |
| 157 | + assertEquals("1 OR block is expected", 1, pq.size()); |
| 158 | + PropertyQueryList pql = pq.get(0); |
| 159 | + assertEquals("1 AND block is expected.", 1, pql.size()); |
| 160 | + |
| 161 | + PropertyQuery query = pql.stream() |
| 162 | + .filter(q -> q.getKey().equals("properties.jsonPath")) |
| 163 | + .findFirst() |
| 164 | + .get(); |
| 165 | + |
| 166 | + assertEquals(QueryOperation.EQUALS, query.getOperation()); |
| 167 | + assertEquals(1, query.getValues().size()); |
| 168 | + Object value = query.getValues().get(0); |
| 169 | + assertTrue("JSONPath value should be a String", value instanceof String); |
| 170 | + assertEquals("$.properties.address.city", value); |
| 171 | + } |
| 172 | + |
| 173 | + @Test |
| 174 | + public void parsePropertiesQueryJsonPathWithOtherFilters() { |
| 175 | + String URIquery = |
| 176 | + "p.jsonPath=$.properties.address.city" |
| 177 | + + "&p.a=3" |
| 178 | + + "&p.boolean=true" |
| 179 | + + "&f.createdAt>0"; |
| 180 | + |
| 181 | + PropertiesQuery pq = PropertiesQuery.fromString(URIquery, "", false); |
| 182 | + assertEquals("1 OR block is expected", 1, pq.size()); |
| 183 | + |
| 184 | + PropertyQueryList pql = pq.get(0); |
| 185 | + // 4 AND blocks: jsonPath, a, boolean, createdAt |
| 186 | + assertEquals("4 AND blocks are expected.", 4, pql.size()); |
| 187 | + |
| 188 | + // jsonPath |
| 189 | + PropertyQuery query = pql.stream() |
| 190 | + .filter(q -> q.getKey().equals("properties.jsonPath")) |
| 191 | + .findFirst() |
| 192 | + .get(); |
| 193 | + assertEquals(QueryOperation.EQUALS, query.getOperation()); |
| 194 | + assertEquals(1, query.getValues().size()); |
| 195 | + assertTrue(query.getValues().get(0) instanceof String); |
| 196 | + assertEquals("$.properties.address.city", query.getValues().get(0)); |
| 197 | + |
| 198 | + // properties.a (still parsed as number) |
| 199 | + query = pql.stream().filter(q -> q.getKey().equals("properties.a")).findFirst().get(); |
| 200 | + assertEquals(QueryOperation.EQUALS, query.getOperation()); |
| 201 | + assertEquals(1, query.getValues().size()); |
| 202 | + assertEquals(3L, query.getValues().get(0)); |
| 203 | + |
| 204 | + // properties.boolean (still parsed as boolean) |
| 205 | + query = pql.stream().filter(q -> q.getKey().equals("properties.boolean")).findFirst().get(); |
| 206 | + assertEquals(QueryOperation.EQUALS, query.getOperation()); |
| 207 | + assertEquals(1, query.getValues().size()); |
| 208 | + assertEquals(true, query.getValues().get(0)); |
| 209 | + |
| 210 | + // createdAt (mapped via SEARCH_KEY_REPLACEMENTS) |
| 211 | + query = pql.stream() |
| 212 | + .filter(q -> q.getKey().equals("properties.@ns:com:here:xyz.createdAt")) |
| 213 | + .findFirst() |
| 214 | + .get(); |
| 215 | + assertEquals(QueryOperation.GREATER_THAN, query.getOperation()); |
| 216 | + assertEquals(1, query.getValues().size()); |
| 217 | + assertEquals(0L, query.getValues().get(0)); |
| 218 | + } |
| 219 | + |
| 220 | + @Test |
| 221 | + public void parsePropertiesQuerySpaceJsonPath() { |
| 222 | + String URISpaceQuery = "a=1&b=2&contentUpatedAt=$.space.properties.version"; |
| 223 | + PropertiesQuery pq = PropertiesQuery.fromString(URISpaceQuery, "contentUpatedAt", true); |
| 224 | + |
| 225 | + assertEquals("1 OR block is expected", 1, pq.size()); |
| 226 | + PropertyQueryList pql = pq.get(0); |
| 227 | + assertEquals("1 AND block is expected.", 1, pql.size()); |
| 228 | + |
| 229 | + PropertyQuery query = pql.stream() |
| 230 | + .filter(q -> q.getKey().equals("contentUpatedAt")) |
| 231 | + .findFirst() |
| 232 | + .get(); |
| 233 | + |
| 234 | + assertEquals(QueryOperation.EQUALS, query.getOperation()); |
| 235 | + assertEquals(1, query.getValues().size()); |
| 236 | + Object value = query.getValues().get(0); |
| 237 | + assertTrue("JSONPath value should be a String", value instanceof String); |
| 238 | + assertEquals("$.space.properties.version", value); |
| 239 | + } |
151 | 240 | } |
0 commit comments