use of org.kie.workbench.common.dmn.api.definition.model.Context 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.Context in project kie-wb-common by kiegroup.
the class ContextPropertyConverterTest method testWBFromDMNWithDecisionAsParent.
@Test
public void testWBFromDMNWithDecisionAsParent() {
final org.kie.dmn.model.api.Context dmn = setupWBFromDMN(decision);
final Context wb = ContextPropertyConverter.wbFromDMN(dmn, hasComponentWidthsConsumer);
assertDefaultContextEntry(wb);
}
use of org.kie.workbench.common.dmn.api.definition.model.Context in project kie-wb-common by kiegroup.
the class ContextPropertyConverterTest method testWBFromDMNWithJavaFunctionDefinitionAsParent.
@Test
public void testWBFromDMNWithJavaFunctionDefinitionAsParent() {
when(functionDefinition.getKind()).thenReturn(FunctionKind.JAVA);
final org.kie.dmn.model.api.Context dmn = setupWBFromDMN(functionDefinition);
final Context wb = ContextPropertyConverter.wbFromDMN(dmn, hasComponentWidthsConsumer);
assertNoDefaultContextEntry(wb);
}
use of org.kie.workbench.common.dmn.api.definition.model.Context in project kie-wb-common by kiegroup.
the class ContextPropertyConverterTest method testDMNFromWBWithNoDefault.
@Test
public void testDMNFromWBWithNoDefault() {
final Context wb = setupDMNFromWB(Optional.empty());
// If no Expression has been defined for the _last_ (default) ContextEntry it should not be converted
final org.kie.dmn.model.api.Context dmn = ContextPropertyConverter.dmnFromWB(wb, componentWidthsConsumer);
assertThat(dmn).isNotNull();
assertThat(dmn.getContextEntry()).isNotNull();
assertThat(dmn.getContextEntry().size()).isEqualTo(1);
assertThat(dmn.getContextEntry().get(0)).isNotNull();
assertThat(dmn.getContextEntry().get(0).getExpression().getId()).isEqualTo(EXPRESSION_UUID);
verify(componentWidthsConsumer).accept(componentWidthsCaptor.capture());
final ComponentWidths componentWidths = componentWidthsCaptor.getValue();
assertThat(componentWidths).isNotNull();
assertThat(componentWidths.getDmnElementRef().getLocalPart()).isEqualTo(EXPRESSION_UUID);
assertThat(componentWidths.getWidths().size()).isEqualTo(literalExpression.getRequiredComponentWidthCount());
assertThat(componentWidths.getWidths().get(0)).isEqualTo(200.0);
}
use of org.kie.workbench.common.dmn.api.definition.model.Context in project kie-wb-common by kiegroup.
the class ContextPropertyConverterTest method testDMNFromWBWithDefault.
@Test
public void testDMNFromWBWithDefault() {
final LiteralExpression defaultExpression = new LiteralExpression();
defaultExpression.getId().setValue(DEFAULT_EXPRESSION_UUID);
defaultExpression.getComponentWidths().set(0, 100.0);
final Context wb = setupDMNFromWB(Optional.of(defaultExpression));
final org.kie.dmn.model.api.Context dmn = ContextPropertyConverter.dmnFromWB(wb, componentWidthsConsumer);
assertThat(dmn).isNotNull();
assertThat(dmn.getContextEntry()).isNotNull();
assertThat(dmn.getContextEntry().size()).isEqualTo(2);
assertThat(dmn.getContextEntry().get(0)).isNotNull();
assertThat(dmn.getContextEntry().get(0).getExpression().getId()).isEqualTo(EXPRESSION_UUID);
assertThat(dmn.getContextEntry().get(1)).isNotNull();
assertThat(dmn.getContextEntry().get(1).getExpression().getId()).isEqualTo(DEFAULT_EXPRESSION_UUID);
verify(componentWidthsConsumer, times(2)).accept(componentWidthsCaptor.capture());
final List<ComponentWidths> componentWidths = componentWidthsCaptor.getAllValues();
assertThat(componentWidths).isNotNull();
assertThat(componentWidths.size()).isEqualTo(2);
assertThat(componentWidths.get(0).getDmnElementRef().getLocalPart()).isEqualTo(EXPRESSION_UUID);
assertThat(componentWidths.get(0).getWidths().size()).isEqualTo(literalExpression.getRequiredComponentWidthCount());
assertThat(componentWidths.get(0).getWidths().get(0)).isEqualTo(200.0);
assertThat(componentWidths.get(1).getDmnElementRef().getLocalPart()).isEqualTo(DEFAULT_EXPRESSION_UUID);
assertThat(componentWidths.get(1).getWidths().size()).isEqualTo(defaultExpression.getRequiredComponentWidthCount());
assertThat(componentWidths.get(1).getWidths().get(0)).isEqualTo(100.0);
}
Aggregations