Skip to content

Commit 8846aa2

Browse files
authored
Merge pull request #4752 from telefonicaid/feature/4751-tests-condition-jexlExpression-id-type
add test jexlExpression in condition using id and type (#4751)
2 parents ab08c36 + b20c238 commit 8846aa2

File tree

4 files changed

+285
-1
lines changed

4 files changed

+285
-1
lines changed

CHANGES_NEXT_RELEASE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Fix: Expose attribute metadata in the JEXL evaluation context for subscription conditions. (#4747)
1+
Fix: expose entity id/type and attribute metadata in the JEXL evaluation context for subscription conditions (#4747)

test/functionalTest/cases/4747_jexlexpression_in_subject_condition_with_metadata_in_jexl_context/jexl_expression_in_condintion_metadata_in_jexl_context_builtin.test renamed to test/functionalTest/cases/4747_jexlexpression_in_subject_condition_with_metadata_in_jexl_context/jexl_expression_in_condintion_with_metadata_in_jexl_context_builtin.test

File renamed without changes.

test/functionalTest/cases/4747_jexlexpression_in_subject_condition_with_metadata_in_jexl_context/jexl_expression_in_condintion_metadata_in_jexl_context_collision.test renamed to test/functionalTest/cases/4747_jexlexpression_in_subject_condition_with_metadata_in_jexl_context/jexl_expression_in_condintion_with_metadata_in_jexl_context_collision.test

File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,284 @@
1+
# Copyright 2025 Telefonica Investigacion y Desarrollo, S.A.U
2+
#
3+
# This file is part of Orion Context Broker.
4+
#
5+
# Orion Context Broker is free software: you can redistribute it and/or
6+
# modify it under the terms of the GNU Affero General Public License as
7+
# published by the Free Software Foundation, either version 3 of the
8+
# License, or (at your option) any later version.
9+
#
10+
# Orion Context Broker is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
13+
# General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU Affero General Public License
16+
# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/.
17+
#
18+
# For those usages not covered by this license please contact with
19+
# iot_support at tid dot es
20+
21+
# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh
22+
# JEXL_EXPR_FLAVOUR - to mark the test has to execute only when contextBroker includes jexl-expr flavour
23+
24+
--NAME--
25+
jexlExpression in condition using id and type
26+
27+
--SHELL-INIT--
28+
dbInit CB
29+
brokerStart CB
30+
accumulatorStart --pretty-print
31+
32+
--SHELL--
33+
34+
#
35+
# 01. Create subscription with jexlExpression: id=="E1" && type=="T"
36+
# 02. Create entity E1 (type T) with A=1
37+
# 03. Update entity E1 (type T) with A=4
38+
# 04. Create entity E2 (type T) with A=1
39+
# 05. Update entity E2 (type T) with A=4
40+
# 06. Create entity E1 (type T1) with A=1
41+
# 07. Update entity E1 (type T1) with A=4
42+
# 08. Dump accumulator: expect TWO notifications (steps 02 and 03, only for id=E1, type=T)
43+
#
44+
45+
46+
echo "01. Create subscription with jexlExpression: id=='E1' && type=='T'"
47+
echo "=================================================================="
48+
payload='{
49+
"subject": {
50+
"entities": [
51+
{
52+
"idPattern": ".*"
53+
}
54+
],
55+
"condition": {
56+
"attrs": [ ],
57+
"jexlExpression": "id==\"E1\" && type==\"T\""
58+
}
59+
},
60+
"notification": {
61+
"httpCustom": {
62+
"url": "http://127.0.0.1:'${LISTENER_PORT}'/notify"
63+
}
64+
}
65+
}'
66+
orionCurl --url /v2/subscriptions --payload "$payload"
67+
echo
68+
echo
69+
70+
71+
echo "02. Create entity E1 (type T) with A=1"
72+
echo "======================================"
73+
payload='{
74+
"id": "E1",
75+
"type": "T",
76+
"A": {
77+
"value": 1,
78+
"type": "Number"
79+
}
80+
}'
81+
orionCurl --url /v2/entities --payload "$payload"
82+
echo
83+
echo
84+
85+
86+
echo "03. Update entity E1 (type T) with A=4"
87+
echo "======================================"
88+
payload='{
89+
"A": {
90+
"value": 4,
91+
"type": "Number"
92+
}
93+
}'
94+
orionCurl --url /v2/entities/E1/attrs?type=T -X PATCH --payload "$payload"
95+
echo
96+
echo
97+
98+
99+
echo "04. Create entity E2 (type T) with A=1"
100+
echo "======================================"
101+
payload='{
102+
"id": "E2",
103+
"type": "T",
104+
"A": {
105+
"value": 1,
106+
"type": "Number"
107+
}
108+
}'
109+
orionCurl --url /v2/entities --payload "$payload"
110+
echo
111+
echo
112+
113+
114+
echo "05. Update entity E2 (type T) with A=4"
115+
echo "======================================"
116+
payload='{
117+
"A": {
118+
"value": 4,
119+
"type": "Number"
120+
}
121+
}'
122+
orionCurl --url /v2/entities/E2/attrs?type=T -X PATCH --payload "$payload"
123+
echo
124+
echo
125+
126+
127+
echo "06. Create entity E1 (type T1) with A=1"
128+
echo "======================================="
129+
payload='{
130+
"id": "E1",
131+
"type": "T1",
132+
"A": {
133+
"value": 1,
134+
"type": "Number"
135+
}
136+
}'
137+
orionCurl --url /v2/entities --payload "$payload"
138+
echo
139+
echo
140+
141+
142+
echo "07. Update entity E1 (type T1) with A=4"
143+
echo "======================================="
144+
payload='{
145+
"A": {
146+
"value": 4,
147+
"type": "Number"
148+
}
149+
}'
150+
orionCurl --url /v2/entities/E1/attrs?type=T1 -X PATCH --payload "$payload"
151+
echo
152+
echo
153+
154+
155+
echo "08. Dump accumulator: expect TWO notifications (steps 02 and 03, only for id=E1, type=T)"
156+
echo "========================================================================================"
157+
accumulatorDump
158+
echo
159+
echo
160+
161+
162+
--REGEXPECT--
163+
01. Create subscription with jexlExpression: id=='E1' && type=='T'
164+
==================================================================
165+
HTTP/1.1 201 Created
166+
Date: REGEX(.*)
167+
Fiware-Correlator: REGEX([0-9a-f\-]{36})
168+
Location: /v2/subscriptions/REGEX([0-9a-f]{24})
169+
Content-Length: 0
170+
171+
172+
173+
02. Create entity E1 (type T) with A=1
174+
======================================
175+
HTTP/1.1 201 Created
176+
Date: REGEX(.*)
177+
Fiware-Correlator: REGEX([0-9a-f\-]{36})
178+
Location: /v2/entities/E1?type=T
179+
Content-Length: 0
180+
181+
182+
183+
03. Update entity E1 (type T) with A=4
184+
======================================
185+
HTTP/1.1 204 No Content
186+
Date: REGEX(.*)
187+
Fiware-Correlator: REGEX([0-9a-f\-]{36})
188+
189+
190+
191+
04. Create entity E2 (type T) with A=1
192+
======================================
193+
HTTP/1.1 201 Created
194+
Date: REGEX(.*)
195+
Fiware-Correlator: REGEX([0-9a-f\-]{36})
196+
Location: /v2/entities/E2?type=T
197+
Content-Length: 0
198+
199+
200+
201+
05. Update entity E2 (type T) with A=4
202+
======================================
203+
HTTP/1.1 204 No Content
204+
Date: REGEX(.*)
205+
Fiware-Correlator: REGEX([0-9a-f\-]{36})
206+
207+
208+
209+
06. Create entity E1 (type T1) with A=1
210+
=======================================
211+
HTTP/1.1 201 Created
212+
Date: REGEX(.*)
213+
Fiware-Correlator: REGEX([0-9a-f\-]{36})
214+
Location: /v2/entities/E1?type=T1
215+
Content-Length: 0
216+
217+
218+
219+
07. Update entity E1 (type T1) with A=4
220+
=======================================
221+
HTTP/1.1 204 No Content
222+
Date: REGEX(.*)
223+
Fiware-Correlator: REGEX([0-9a-f\-]{36})
224+
225+
226+
227+
08. Dump accumulator: expect TWO notifications (steps 02 and 03, only for id=E1, type=T)
228+
========================================================================================
229+
POST http://127.0.0.1:REGEX(\d+)/notify
230+
Fiware-Servicepath: /
231+
Content-Length: 123
232+
User-Agent: orion/REGEX(\d+\.\d+\.\d+.*)
233+
Ngsiv2-Attrsformat: normalized
234+
Host: 127.0.0.1:REGEX(\d+)
235+
Accept: application/json
236+
Content-Type: application/json; charset=utf-8
237+
Fiware-Correlator: REGEX([0-9a-f\-]{36}); cbnotif=1
238+
239+
{
240+
"data": [
241+
{
242+
"A": {
243+
"metadata": {},
244+
"type": "Number",
245+
"value": 1
246+
},
247+
"id": "E1",
248+
"type": "T"
249+
}
250+
],
251+
"subscriptionId": "REGEX([0-9a-f]{24})"
252+
}
253+
=======================================
254+
POST http://127.0.0.1:REGEX(\d+)/notify
255+
Fiware-Servicepath: /
256+
Content-Length: 123
257+
User-Agent: orion/REGEX(\d+\.\d+\.\d+.*)
258+
Ngsiv2-Attrsformat: normalized
259+
Host: 127.0.0.1:REGEX(\d+)
260+
Accept: application/json
261+
Content-Type: application/json; charset=utf-8
262+
Fiware-Correlator: REGEX([0-9a-f\-]{36}); cbnotif=1
263+
264+
{
265+
"data": [
266+
{
267+
"A": {
268+
"metadata": {},
269+
"type": "Number",
270+
"value": 4
271+
},
272+
"id": "E1",
273+
"type": "T"
274+
}
275+
],
276+
"subscriptionId": "REGEX([0-9a-f]{24})"
277+
}
278+
=======================================
279+
280+
281+
--TEARDOWN--
282+
brokerStop CB
283+
dbDrop CB
284+
accumulatorStop

0 commit comments

Comments
 (0)