use of org.kie.workbench.common.dmn.api.definition.model.LiteralExpression in project kie-wb-common by kiegroup.
the class ExpressionContainerGridTest method testSelectCellWithCoordinates.
@Test
public void testSelectCellWithCoordinates() {
final int uiRowIndex = 0;
final int uiColumnIndex = 1;
final LiteralExpression domainObject = mock(LiteralExpression.class);
when(hasExpression.asDMNModelInstrumentedBase()).thenReturn(domainObject);
grid.setExpression(NODE_UUID, hasExpression, Optional.of(hasName), false);
grid.selectCell(uiRowIndex, uiColumnIndex, false, true);
verify(gridLayer).select(eq(grid));
verify(domainObjectSelectionEvent).fire(domainObjectSelectionEventCaptor.capture());
final DomainObjectSelectionEvent domainObjectSelectionEvent = domainObjectSelectionEventCaptor.getValue();
assertThat(domainObjectSelectionEvent.getCanvasHandler()).isEqualTo(canvasHandler);
assertThat(domainObjectSelectionEvent.getDomainObject()).isEqualTo(domainObject);
verify(cellSelectionManager).selectCell(eq(uiRowIndex), eq(uiColumnIndex), eq(false), eq(true));
}
use of org.kie.workbench.common.dmn.api.definition.model.LiteralExpression 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.LiteralExpression in project kie-wb-common by kiegroup.
the class LiteralExpressionPropertyConverter method wbFromDMN.
public static LiteralExpression wbFromDMN(final org.kie.dmn.model.api.LiteralExpression dmn) {
if (dmn == null) {
return null;
}
final Id id = new Id(dmn.getId());
final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
final QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef(), dmn);
final Text text = new Text(dmn.getText() != null ? dmn.getText() : "");
final ExpressionLanguage expressionLanguage = ExpressionLanguagePropertyConverter.wbFromDMN(dmn.getExpressionLanguage());
final ImportedValues importedValues = ImportedValuesConverter.wbFromDMN(dmn.getImportedValues());
final LiteralExpression result = new LiteralExpression(id, description, typeRef, text, importedValues, expressionLanguage);
if (importedValues != null) {
importedValues.setParent(result);
}
return result;
}
use of org.kie.workbench.common.dmn.api.definition.model.LiteralExpression in project kie-wb-common by kiegroup.
the class FunctionEditorDefinitionTest method testModelEnrichment.
@Test
public void testModelEnrichment() {
final Optional<FunctionDefinition> oModel = definition.getModelClass();
definition.enrich(Optional.empty(), hasExpression, oModel);
final FunctionDefinition model = oModel.get();
assertEquals(FunctionDefinition.Kind.FEEL.code(), model.getKind().code());
assertTrue(model.getExpression() instanceof LiteralExpression);
}
use of org.kie.workbench.common.dmn.api.definition.model.LiteralExpression in project kie-wb-common by kiegroup.
the class ListEditorDefinitionTest method testModelEnrichment.
@Test
public void testModelEnrichment() {
final Optional<List> oModel = definition.getModelClass();
definition.enrich(Optional.empty(), hasExpression, oModel);
final List model = oModel.get();
assertNotNull(model.getExpression());
assertNotNull(model.getExpression().get(0).getExpression());
assertTrue(model.getExpression().get(0).getExpression() instanceof LiteralExpression);
assertEquals(model, model.getExpression().get(0).getExpression().getParent());
}
Aggregations