-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
147 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
kie-yard/kie-yard-core/src/test/java/org/kie/yard/core/MVELJSONTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.kie.yard.core; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class MVELJSONTest | ||
extends TestBase { | ||
|
||
private static final String FILE_NAME = "/mvel-json-dot-access.yml"; | ||
|
||
@Test | ||
public void testMVELManagesJSONMaps() throws Exception { | ||
final String CTX = """ | ||
{ | ||
"Work Address":true | ||
} | ||
"""; | ||
final Map<String, Object> output = evaluate(CTX, FILE_NAME); | ||
|
||
final Map mailingAddress = (Map) output.get("Mailing Address"); | ||
assertEquals("Work Street", mailingAddress.get("Street")); | ||
assertEquals(23, mailingAddress.get("Number")); | ||
|
||
final List deliveryItemNames = (List) output.get("Delivery Item Names"); | ||
assertEquals(3, deliveryItemNames.size()); | ||
assertTrue(deliveryItemNames.contains("Work Shoes")); | ||
assertTrue(deliveryItemNames.contains("Work Hat")); | ||
assertTrue(deliveryItemNames.contains("Work Shirt")); | ||
|
||
final Map JSONTest= (Map) output.get("JSON Test"); | ||
assertEquals("Best Company LTD", JSONTest.get("Company")); | ||
|
||
final Map mapTest = (Map) output.get("Map Test"); | ||
assertEquals("Hello", mapTest.get("Map")); | ||
} | ||
// TODO Validate two elements can not have the same name | ||
} |
57 changes: 57 additions & 0 deletions
57
kie-yard/kie-yard-core/src/test/resources/mvel-json-dot-access.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
specVersion: alpha | ||
kind: YaRD | ||
name: "Testing MVEL" | ||
inputs: | ||
- name: Work Address | ||
type: boolean | ||
elements: | ||
- name: JSON Test | ||
type: Decision | ||
logic: | ||
type: LiteralExpression | ||
expression: | | ||
'{ "Company": "Best Company LTD" }' | ||
- name: Map Test | ||
type: Decision | ||
logic: | ||
type: LiteralExpression | ||
expression: | | ||
[ "Map": "Hello" ] | ||
- name: Delivery Items | ||
type: Decision | ||
logic: | ||
type: DecisionTable | ||
hitPolicy: COLLECT | ||
inputs: [ 'Work Address'] | ||
rules: | ||
- when: [ true ] | ||
then: '{ "Item": { "Name": "Work Shoes" } }' | ||
- when: [ true ] | ||
then: '{ "Item": { "Name": "Work Hat" } }' | ||
- when: [ true ] | ||
then: '{ "Item": { "Name": "Work Shirt" } }' | ||
- when: [ false ] | ||
then: '{ "Item": { "Name": "Holiday Hat" } }' | ||
- name: Customer | ||
type: Decision | ||
logic: | ||
type: DecisionTable | ||
hitPolicy: ANY | ||
inputs: [ 'Work Address'] | ||
rules: | ||
- when: [ true ] | ||
then: '{ "Address": { "Street": "Work Street", "Number": 23 } }' | ||
- when: [ false ] | ||
then: '{ "Address": { "Street": "Free Time Path", "Number": 123 } }' | ||
- name: Mailing Address | ||
type: Decision | ||
logic: | ||
type: LiteralExpression | ||
expression: | | ||
Customer.Address | ||
- name: Delivery Item Names | ||
type: Decision | ||
logic: | ||
type: LiteralExpression | ||
expression: | | ||
( Item.Name in `Delivery Items` ) |