use of org.kie.workbench.common.dmn.api.definition.model.Decision in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method checkDecisionExpression.
private static void checkDecisionExpression(final Graph<?, Node<View, ?>> unmarshalledGraph, final Expression expression) {
final Node<View, ?> decisionNode = nodeOfDefinition(unmarshalledGraph.nodes().iterator(), Decision.class);
final Expression decisionNodeExpression = ((Decision) DefinitionUtils.getElementDefinition(decisionNode)).getExpression();
// The process of marshalling an Expression that has been programmatically instantiated (vs created in the UI)
// leads to the _source_ Expression ComponentWidths being initialised. Therefore to ensure a like-for-like equality
// comparison ensure the unmarshalled _target_ Expression has had it's ComponentWidths initialised too.
decisionNodeExpression.getComponentWidths();
((Context) decisionNodeExpression).getContextEntry().get(0).getExpression().getComponentWidths();
assertThat(decisionNodeExpression).isEqualTo(expression);
}
use of org.kie.workbench.common.dmn.api.definition.model.Decision in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method test_wrong_decision.
@Test
@SuppressWarnings("unchecked")
public void test_wrong_decision() throws IOException {
// DROOLS-3116 empty Literal Expression to be preserved
final ErrorsAndDMNModelAsSerialized result = roundTripUnmarshalMarshalThenUnmarshalDMNexpectingErrors(this.getClass().getResourceAsStream("/wrong_decision.dmn"));
// although the DMN file is schema valid but is not a valid-DMN (a context-entry value is a literal expression missing text, which is null)
// DROOLS-3152: once roundtripped through the Stunner marshaller it will receive an empty text. (empty expression, but a LiteralExpression with an empty text child xml element)
// this will still naturally throw some error because unable to FEEL-parse/compile an empty epression.
assertTrue(result.hasErrors());
// identify the error message for the Decision with a Literal Expression decision logic missing the actual expression text.
DMNMessage m0 = (DMNMessage) result.messages.get(0);
assertTrue("expected a message identifying the problem on the literalExpression of 'my decision'", m0.getSourceId().equals("_36dd163c-4862-4308-92bf-40a998b24e39"));
org.kie.dmn.model.api.Decision d0 = (org.kie.dmn.model.api.Decision) result.definitions.getDrgElement().stream().filter(d -> d.getId().equals("_cce32679-9395-444d-a4bf-96af8ee727a0")).findFirst().get();
// the identified DMN Decision is composed a literal expression missing text (text is null).
org.kie.dmn.model.api.Expression d0le = d0.getExpression();
assertTrue(d0le instanceof org.kie.dmn.model.api.LiteralExpression);
// DROOLS-3152
assertEquals("", ((org.kie.dmn.model.api.LiteralExpression) d0le).getText());
// -- Stunner side.
DMNMarshallerStandalone m = getDMNMarshaller();
Graph<?, ?> g = m.unmarshall(createMetadata(), this.getClass().getResourceAsStream("/wrong_decision.dmn"));
Node<?, ?> decisionNode = g.getNode("_cce32679-9395-444d-a4bf-96af8ee727a0");
assertNodeContentDefinitionIs(decisionNode, Decision.class);
View<Decision> view = ((View<Decision>) decisionNode.getContent());
// the identified DMN Decision is composed a literal expression missing text (text is null).
Expression expression = view.getDefinition().getExpression();
// DROOLS-3116 empty Literal Expression is preserved
assertNotNull(expression);
assertEquals(LiteralExpression.class, expression.getClass());
LiteralExpression le = (LiteralExpression) expression;
// DROOLS-3152
assertEquals("", le.getText().getValue());
}
use of org.kie.workbench.common.dmn.api.definition.model.Decision in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method test_function_java_WB_model.
@Test
public void test_function_java_WB_model() throws IOException {
final DMNMarshallerStandalone m = getDMNMarshaller();
@SuppressWarnings("unchecked") final Graph<?, Node<?, ?>> g = m.unmarshall(createMetadata(), this.getClass().getResourceAsStream("/DROOLS-2372.dmn"));
final Stream<Node<?, ?>> stream = StreamSupport.stream(Spliterators.spliteratorUnknownSize(g.nodes().iterator(), Spliterator.ORDERED), false);
final Optional<Decision> wbDecision = stream.filter(n -> n.getContent() instanceof ViewImpl).map(n -> (ViewImpl) n.getContent()).filter(n -> n.getDefinition() instanceof Decision).map(n -> (Decision) n.getDefinition()).findFirst();
wbDecision.ifPresent(d -> {
assertTrue(d.getExpression() instanceof FunctionDefinition);
final FunctionDefinition wbFunction = (FunctionDefinition) d.getExpression();
// This is what the WB expects
assertEquals(FunctionDefinition.Kind.JAVA, wbFunction.getKind());
});
final DMNRuntime runtime = roundTripUnmarshalMarshalThenUnmarshalDMN(this.getClass().getResourceAsStream("/DROOLS-2372.dmn"));
final DMNModel dmnModel = runtime.getModels().get(0);
final BusinessKnowledgeModelNode bkmNode = dmnModel.getBusinessKnowledgeModels().iterator().next();
final org.kie.dmn.model.api.FunctionDefinition dmnFunction = bkmNode.getBusinessKnowledModel().getEncapsulatedLogic();
assertEquals(FunctionKind.JAVA, dmnFunction.getKind());
}
use of org.kie.workbench.common.dmn.api.definition.model.Decision in project kie-wb-common by kiegroup.
the class PointUtilsTest method testConvertToAbsoluteBoundsWhenChild.
@Test
public void testConvertToAbsoluteBoundsWhenChild() {
final Node<View, Edge> parent = new NodeImpl<>(UUID.uuid());
final View parentView = new ViewImpl<>(new Decision(), Bounds.create(100, 200, 1000, 2000));
parent.setContent(parentView);
final Node<View, Edge> child = new NodeImpl<>(UUID.uuid());
final View childView = new ViewImpl<>(new Decision(), Bounds.create(10, 20, 50, 60));
child.setContent(childView);
final Edge<Child, Node> edge = new EdgeImpl<>(UUID.uuid());
edge.setContent(new Child());
edge.setSourceNode(parent);
edge.setTargetNode(child);
parent.getOutEdges().add(edge);
child.getInEdges().add(edge);
PointUtils.convertToAbsoluteBounds(child);
final Bound ulBound = child.getContent().getBounds().getUpperLeft();
final Bound lrBound = child.getContent().getBounds().getLowerRight();
assertThat(ulBound.getX()).isEqualTo(110);
assertThat(ulBound.getY()).isEqualTo(220);
assertThat(lrBound.getX()).isEqualTo(150);
assertThat(lrBound.getY()).isEqualTo(260);
}
use of org.kie.workbench.common.dmn.api.definition.model.Decision in project kie-wb-common by kiegroup.
the class PointUtilsTest method testConvertToRelativeBoundsWhenNotChild.
@Test
public void testConvertToRelativeBoundsWhenNotChild() {
final Node<View, ?> node = new NodeImpl<>(UUID.uuid());
final View nodeView = new ViewImpl<>(new Decision(), Bounds.create(10, 20, 50, 60));
node.setContent(nodeView);
PointUtils.convertToRelativeBounds(node);
final Bound ulBound = node.getContent().getBounds().getUpperLeft();
final Bound lrBound = node.getContent().getBounds().getLowerRight();
assertThat(ulBound.getX()).isEqualTo(10);
assertThat(ulBound.getY()).isEqualTo(20);
assertThat(lrBound.getX()).isEqualTo(50);
assertThat(lrBound.getY()).isEqualTo(60);
}
Aggregations