use of org.kie.workbench.common.dmn.api.definition.model.Decision in project kie-wb-common by kiegroup.
the class ExpressionEditorTest method setUp.
@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
this.decision = new Decision();
this.expressionGridCache = new ExpressionGridCacheImpl();
this.definitions = new Definitions();
this.definitions.setName(new Name(DRG_NAME));
testedEditor = spy(new ExpressionEditor(view, decisionNavigator, dmnGraphUtils, dmnDiagramsSession, drdNameChanger));
testedEditor.bind(dmnSession);
when(session.getCanvasControl(eq(ExpressionGridCache.class))).thenReturn(expressionGridCache);
when(dmnGraphUtils.getModelDefinitions()).thenReturn(definitions);
when(dmnDiagramsSession.getCurrentDMNDiagramElement()).thenReturn(Optional.of(dmnDiagramElement));
}
use of org.kie.workbench.common.dmn.api.definition.model.Decision in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenDecisionTypeRefIsStructureWithMultipleFields.
@Test
public void testModelEnrichmentWhenDecisionTypeRefIsStructureWithMultipleFields() {
final DMNGraphUtils dmnGraphUtils = mock(DMNGraphUtils.class);
final Definitions definitions = mock(Definitions.class);
final HasExpression hasExpression = mock(HasExpression.class);
final Decision decision = mock(Decision.class);
final InformationItemPrimary informationItemPrimary = mock(InformationItemPrimary.class);
final ItemDefinition tPerson = mockTPersonStructure();
when(dmnGraphUtils.getModelDefinitions()).thenReturn(definitions);
when(definitions.getItemDefinition()).thenReturn(Collections.singletonList(tPerson));
when(hasExpression.asDMNModelInstrumentedBase()).thenReturn(decision);
when(decision.getVariable()).thenReturn(informationItemPrimary);
when(informationItemPrimary.getTypeRef()).thenReturn(new QName("", TYPE_PERSON));
final DecisionTableEditorDefinitionEnricher enricher = new DecisionTableEditorDefinitionEnricher(null, dmnGraphUtils, itemDefinitionUtils);
final Optional<DecisionTable> oModel = definition.getModelClass();
final DecisionTable model = oModel.get();
enricher.buildOutputClausesByDataType(hasExpression, model, new DecisionRule());
final List<OutputClause> outputClauses = model.getOutput();
assertThat(outputClauses.size()).isEqualTo(2);
final OutputClause outputClause1 = outputClauses.get(0);
final OutputClause outputClause2 = outputClauses.get(1);
assertEquals("age", outputClause1.getName());
assertEquals(NUMBER.asQName(), outputClause1.getTypeRef());
assertEquals("name", outputClause2.getName());
assertEquals(STRING.asQName(), outputClause2.getTypeRef());
}
use of org.kie.workbench.common.dmn.api.definition.model.Decision in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinitionEnricherTest method setup.
@Before
public void setup() {
super.setup();
this.diagram = new DMNDiagram();
this.inputData1 = new InputData();
this.inputData2 = new InputData();
this.decision1 = new Decision();
}
use of org.kie.workbench.common.dmn.api.definition.model.Decision in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method connectTwoNodes.
@SuppressWarnings("unchecked")
private Diagram<Graph, Metadata> connectTwoNodes(final org.kie.workbench.common.stunner.core.graph.content.Bounds bounds, final String decisionNode1UUID, final String decisionNode2UUID, final String edgeUUID, final MagnetConnection edgeSourceConnection, final MagnetConnection edgeTargetConnection, final Consumer<MagnetConnection> sourceMagnetConsumer, final Consumer<MagnetConnection> targetMagnetConsumer) {
final DiagramImpl diagram = createDiagram();
final Graph<DefinitionSet, Node> graph = mock(Graph.class);
final Node<View, Edge> diagramNode = mock(Node.class);
final View diagramView = mock(View.class);
final DMNDiagram dmnDiagram = new DMNDiagram();
when(diagramNode.getContent()).thenReturn(diagramView);
when(diagramView.getDefinition()).thenReturn(dmnDiagram);
final Node<View, Edge> decisionNode1 = mock(Node.class);
final View decisionView1 = mock(View.class);
final Decision decision1 = new Decision();
decision1.getId().setValue(decisionNode1UUID);
when(decisionNode1.getContent()).thenReturn(decisionView1);
when(decisionView1.getDefinition()).thenReturn(decision1);
when(decisionView1.getBounds()).thenReturn(bounds);
final Node<View, Edge> decisionNode2 = mock(Node.class);
final View decisionView2 = mock(View.class);
final Decision decision2 = new Decision();
decision2.getId().setValue(decisionNode2UUID);
when(decisionNode2.getContent()).thenReturn(decisionView2);
when(decisionView2.getDefinition()).thenReturn(decision2);
when(decisionView2.getBounds()).thenReturn(bounds);
final Edge edge = mock(Edge.class);
final ViewConnector edgeView = mock(ViewConnector.class);
Optional edgeSourceConnectionOptional = Optional.empty();
if (edgeSourceConnection != null) {
edgeSourceConnectionOptional = Optional.of(edgeSourceConnection);
}
Optional edgeTargetConnectionOptional = Optional.empty();
if (edgeTargetConnection != null) {
edgeTargetConnectionOptional = Optional.of(edgeTargetConnection);
}
when(edge.getUUID()).thenReturn(edgeUUID);
when(edge.getContent()).thenReturn(edgeView);
when(edgeView.getSourceConnection()).thenReturn(edgeSourceConnectionOptional);
when(edgeView.getTargetConnection()).thenReturn(edgeTargetConnectionOptional);
when(edgeView.getControlPoints()).thenReturn(new ControlPoint[] {});
when(decisionNode1.getOutEdges()).thenReturn(Collections.singletonList(edge));
when(decisionNode2.getInEdges()).thenReturn(Collections.singletonList(edge));
when(edge.getSourceNode()).thenReturn(decisionNode1);
when(edge.getTargetNode()).thenReturn(decisionNode2);
sourceMagnetConsumer.accept(edgeSourceConnection);
targetMagnetConsumer.accept(edgeTargetConnection);
doReturn(asList(diagramNode, decisionNode1, decisionNode2)).when(graph).nodes();
diagram.setGraph(graph);
return diagram;
}
use of org.kie.workbench.common.dmn.api.definition.model.Decision 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());
}
Aggregations