use of org.kie.workbench.common.dmn.api.definition.model.Expression in project kie-wb-common by kiegroup.
the class ExpressionContainerGridTest method testGetBaseExpressionGrid.
@Test
public void testGetBaseExpressionGrid() {
final Optional<BaseExpressionGrid<? extends Expression, ? extends GridData, ? extends BaseUIModelMapper>> expectedBaseExpressionGrid = Optional.of(mock(LiteralExpressionGrid.class));
final ExpressionCellValue value = mock(ExpressionCellValue.class);
final GridCell<?> cell = new BaseGridCell<>(value);
final Supplier<GridCell<?>> cellSupplier = () -> cell;
when(value.getValue()).thenReturn(expectedBaseExpressionGrid);
grid.getModel().setCell(0, 0, cellSupplier);
assertEquals(expectedBaseExpressionGrid, grid.getBaseExpressionGrid());
}
use of org.kie.workbench.common.dmn.api.definition.model.Expression in project kie-wb-common by kiegroup.
the class ExpressionEditorColumnTest method setUp.
@Before
public void setUp() {
gridData = new BaseGridData();
widget = new BaseGrid<Expression>(gridLayer, gridData, renderer, sessionManager, sessionCommandManager, canvasCommandFactory, refreshFormPropertiesEvent, domainObjectSelectionEvent, cellEditorControls, translationService) {
};
column = new ExpressionEditorColumn(gridLayer, new BaseHeaderMetaData("column header"), ExpressionEditorColumn.DEFAULT_WIDTH, widget);
}
use of org.kie.workbench.common.dmn.api.definition.model.Expression in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method test_wrong_context.
@Test
@SuppressWarnings("unchecked")
public void test_wrong_context() throws IOException {
// DROOLS-2217
final ErrorsAndDMNModelAsSerialized result = roundTripUnmarshalMarshalThenUnmarshalDMNexpectingErrors(this.getClass().getResourceAsStream("/wrong_context.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 expression.
assertTrue(result.hasErrors());
// identify the error message for context-entry "ciao":
DMNMessage m0 = (DMNMessage) result.messages.get(0);
assertTrue("expected a message identifying the problem on a context entry for 'ciao'", // DROOLS-3152 please notice FEEL reporting indeed an empty expression.
m0.getMessage().startsWith("Error compiling FEEL expression '' for name "));
org.kie.dmn.model.api.Decision d0 = (org.kie.dmn.model.api.Decision) result.definitions.getDrgElement().stream().filter(d -> d.getId().equals("_653b3426-933a-4050-9568-ab2a66b43c36")).findFirst().get();
// the identified DMN Decision is composed of a DMN Context where the first context-entry value is a literal expression missing text (text is null).
org.kie.dmn.model.api.Context d0c = (org.kie.dmn.model.api.Context) d0.getExpression();
org.kie.dmn.model.api.Expression contextEntryValue = d0c.getContextEntry().get(0).getExpression();
assertTrue(contextEntryValue instanceof org.kie.dmn.model.api.LiteralExpression);
// DROOLS-3152
assertEquals("", ((org.kie.dmn.model.api.LiteralExpression) contextEntryValue).getText());
// -- Stunner side.
DMNMarshallerStandalone m = getDMNMarshaller();
Graph<?, ?> g = m.unmarshall(createMetadata(), this.getClass().getResourceAsStream("/wrong_context.dmn"));
Node<?, ?> decisionNode = g.getNode("_653b3426-933a-4050-9568-ab2a66b43c36");
assertNodeContentDefinitionIs(decisionNode, Decision.class);
View<Decision> view = ((View<Decision>) decisionNode.getContent());
// the identified DMN Decision is composed of a DMN Context where the first context-entry has missing Expression.
Context expression = (Context) view.getDefinition().getExpression();
// DROOLS-3116 empty Literal Expression is preserved
assertNotNull(expression.getContextEntry().get(0).getExpression());
assertEquals(LiteralExpression.class, expression.getContextEntry().get(0).getExpression().getClass());
LiteralExpression le = (LiteralExpression) expression.getContextEntry().get(0).getExpression();
// DROOLS-3152
assertEquals("", le.getText().getValue());
}
use of org.kie.workbench.common.dmn.api.definition.model.Expression in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method checkDecisionWithContextWithDefaultResult.
private void checkDecisionWithContextWithDefaultResult(Graph<?, Node<?, ?>> g) {
Node<?, ?> decisionNode = g.getNode("_30810b88-8416-4c02-8ed1-8c19b7606243");
assertNodeContentDefinitionIs(decisionNode, Decision.class);
Context context = (Context) ((Decision) ((View<?>) decisionNode.getContent()).getDefinition()).getExpression();
InformationItem defaultResultVariable = context.getContextEntry().get(1).getVariable();
assertNull("Default result variable", defaultResultVariable);
Expression defaultResultExpression = context.getContextEntry().get(1).getExpression();
assertNotNull("Default result expression", defaultResultExpression);
assertEquals("defaultResultExpression's parent-parent is contextNode", "_0f38d114-5d6e-40dd-aa9c-9f031f9b0571", ((DMNElement) (defaultResultExpression).getParent().getParent()).getId().getValue());
}
use of org.kie.workbench.common.dmn.api.definition.model.Expression in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method checkDecisionWithContext.
@SuppressWarnings("unchecked")
private void checkDecisionWithContext(Graph<?, Node<?, ?>> g) {
Node<?, ?> decisionNode = g.getNode("_30810b88-8416-4c02-8ed1-8c19b7606243");
assertNodeContentDefinitionIs(decisionNode, Decision.class);
Node<?, ?> rootNode = DMNMarshallerStandalone.findDMNDiagramRoot((Graph) g);
assertNotNull(rootNode);
assertRootNodeConnectedTo(rootNode, decisionNode);
assertEquals("decisionNode parent is Definitions DMN root", "_153e2b47-3bd2-4db0-828c-db3fce0b3199", ((DMNElement) ((Decision) ((View<?>) decisionNode.getContent()).getDefinition()).getParent()).getId().getValue());
Context context = (Context) ((Decision) ((View<?>) decisionNode.getContent()).getDefinition()).getExpression();
assertEquals("contextNode's parent is decisionNode", "_30810b88-8416-4c02-8ed1-8c19b7606243", ((DMNElement) context.getParent()).getId().getValue());
Expression literalExpression1 = context.getContextEntry().get(0).getExpression();
assertEquals("literalExpression1's parent-parent is contextNode", "_0f38d114-5d6e-40dd-aa9c-9f031f9b0571", ((DMNElement) (literalExpression1).getParent().getParent()).getId().getValue());
Expression literalExpression2 = context.getContextEntry().get(1).getExpression();
assertEquals("literalExpression2's parent-parent is contextNode", "_0f38d114-5d6e-40dd-aa9c-9f031f9b0571", ((DMNElement) (literalExpression2).getParent().getParent()).getId().getValue());
}
Aggregations