use of org.kie.kogito.tracing.typedvalue.CollectionValue in project kogito-apps by kiegroup.
the class ConversionUtilsTest method toFeatureTypedValue.
@Test
void toFeatureTypedValue() {
Feature name = ConversionUtils.toFeature("name", new UnitValue("number", new DoubleNode(10d)));
assertNotNull(name);
assertEquals("name", name.getName());
assertEquals(Type.NUMBER, name.getType());
assertEquals(10d, name.getValue().getUnderlyingObject());
assertTrue(name.isConstrained());
assertTrue(name.getDomain().isEmpty());
Feature name1 = ConversionUtils.toFeature("name1", new StructureValue("complex", singletonMap("key", new UnitValue("string1", new TextNode("stringValue")))));
assertNotNull(name1);
assertTrue(name1.isConstrained());
assertTrue(name1.getDomain().isEmpty());
assertEquals("name1", name1.getName());
assertEquals(Type.COMPOSITE, name1.getType());
assertTrue(name1.getValue().getUnderlyingObject() instanceof List);
@SuppressWarnings("unchecked") List<Feature> features = (List<Feature>) name1.getValue().getUnderlyingObject();
assertEquals(1, features.size());
assertEquals(Type.TEXT, features.get(0).getType());
assertEquals("stringValue", features.get(0).getValue().getUnderlyingObject());
List<TypedValue> values = List.of(new UnitValue("number", new DoubleNode(0d)), new UnitValue("number", new DoubleNode(1d)));
Feature collectionFeature = ConversionUtils.toFeature("name", new CollectionValue("list", values));
assertNotNull(collectionFeature);
assertEquals("name", collectionFeature.getName());
assertEquals(Type.COMPOSITE, collectionFeature.getType());
assertTrue(collectionFeature.getValue().getUnderlyingObject() instanceof List);
@SuppressWarnings("unchecked") List<Feature> objects = (List<Feature>) collectionFeature.getValue().getUnderlyingObject();
assertEquals(2, objects.size());
for (Feature f : objects) {
assertNotNull(f);
assertNotNull(f.getName());
assertNotNull(f.getType());
assertEquals(Type.NUMBER, f.getType());
assertNotNull(f.getValue());
}
}
use of org.kie.kogito.tracing.typedvalue.CollectionValue in project kogito-apps by kiegroup.
the class ConversionUtilsTest method testNestedCollection.
@Test
void testNestedCollection() {
Collection<TypedValue> depthTwoOne = new ArrayList<>(2);
depthTwoOne.add(new StructureValue("complex", singletonMap("key", new UnitValue("string1", new TextNode("value one")))));
depthTwoOne.add(new StructureValue("complex", singletonMap("key", new UnitValue("string1", new TextNode("value two")))));
Collection<TypedValue> depthTwoTwo = new ArrayList<>(2);
depthTwoTwo.add(new StructureValue("complex", singletonMap("key", new UnitValue("string1", new TextNode("value three")))));
depthTwoTwo.add(new StructureValue("complex", singletonMap("key", new UnitValue("string1", new TextNode("value four")))));
CollectionValue depthOneLeft = new CollectionValue("list", depthTwoOne);
CollectionValue depthOneRight = new CollectionValue("list", depthTwoTwo);
Collection<TypedValue> depthOne = new ArrayList<>(2);
depthOne.add(depthOneLeft);
depthOne.add(depthOneRight);
CollectionValue value = new CollectionValue("list", depthOne);
Feature collectionFeature = ConversionUtils.toFeature("name", value);
assertNotNull(collectionFeature);
assertEquals("name", collectionFeature.getName());
assertEquals(Type.COMPOSITE, collectionFeature.getType());
assertTrue(collectionFeature.getValue().getUnderlyingObject() instanceof List);
@SuppressWarnings("unchecked") List<Feature> deepFeatures = (List<Feature>) collectionFeature.getValue().getUnderlyingObject();
assertEquals(2, deepFeatures.size());
for (Feature f : deepFeatures) {
assertNotNull(f);
assertNotNull(f.getName());
assertNotNull(f.getType());
assertEquals(Type.COMPOSITE, f.getType());
assertNotNull(f.getValue());
List<Feature> nestedOneValues = (List<Feature>) f.getValue().getUnderlyingObject();
for (Feature nestedOneValue : nestedOneValues) {
assertNotNull(nestedOneValue);
assertNotNull(nestedOneValue.getName());
assertNotNull(nestedOneValue.getType());
assertEquals(Type.COMPOSITE, nestedOneValue.getType());
assertNotNull(nestedOneValue.getValue());
List<Feature> nestedTwoValues = (List<Feature>) nestedOneValue.getValue().getUnderlyingObject();
for (Feature nestedTwoValue : nestedTwoValues) {
assertNotNull(nestedTwoValue);
assertNotNull(nestedTwoValue.getName());
assertNotNull(nestedTwoValue.getType());
assertEquals(Type.TEXT, nestedTwoValue.getType());
assertNotNull(nestedTwoValue.getValue());
assertTrue(nestedTwoValue.getValue().asString().contains("value"));
}
}
}
}
Aggregations