use of org.kie.workbench.common.dmn.api.definition.model.Definitions in project kie-wb-common by kiegroup.
the class DMNDiagramUtilsTest method testGetDefinitionsWithConnectedNodes.
@Test
public void testGetDefinitionsWithConnectedNodes() {
final Decision definition1 = new Decision();
final DMNDiagram definition2 = new DMNDiagram();
final Node<View, Edge> node1 = newNode(definition1);
final Node<View, Edge> node2 = newNode(definition2);
final Edge<View, Node> edge = new EdgeImpl<>(UUID.uuid());
node1.getInEdges().add(edge);
node2.getOutEdges().add(edge);
edge.setSourceNode(node2);
edge.setTargetNode(node1);
graph.addNode(node1);
graph.addNode(node2);
final Definitions definitions = utils.getDefinitions(diagram);
assertNotNull(definitions);
assertEquals(definition2.getDefinitions(), definitions);
}
use of org.kie.workbench.common.dmn.api.definition.model.Definitions in project kie-wb-common by kiegroup.
the class DRDContextMenuServiceTest method testAddToNewDRD.
@Test
public void testAddToNewDRD() {
final Collection<Node<? extends Definition<?>, Edge>> nodes = mock(Collection.class);
final Definitions definitions = mock(Definitions.class);
final Diagram drgDiagram = mock(Diagram.class);
final List<DMNDiagramElement> diagramElements = mock(List.class);
when(dmnDiagramsSession.getDRGDiagram()).thenReturn(drgDiagram);
when(dmnDiagramUtils.getDefinitions(drgDiagram)).thenReturn(definitions);
when(definitions.getDiagramElements()).thenReturn(diagramElements);
drdContextMenuService.addToNewDRD(nodes);
verify(diagramElements, times(1)).add(Mockito.<DMNDiagramElement>any());
verify(dmnDiagramsSession, times(1)).add(Mockito.<DMNDiagramElement>any(), Mockito.<Diagram>any());
verify(selectedEvent, times(1)).fire(Mockito.<DMNDiagramSelected>any());
}
use of org.kie.workbench.common.dmn.api.definition.model.Definitions 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.Definitions in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenTopLevelDecisionTableWithInputDataAndComplexCustomType.
@Test
@SuppressWarnings("unchecked")
public void testModelEnrichmentWhenTopLevelDecisionTableWithInputDataAndComplexCustomType() {
setupGraphWithDiagram();
setupGraphWithInputData();
final Definitions definitions = diagram.getDefinitions();
final String complexItemDefinitionName = "tSmurf";
final String complexItemDefinitionPart1Name = "tDateOfBirth";
final String complexItemDefinitionPart2Name = "tIsBlue";
final QName complexItemDefinitionPart1TypeRef = new QName(QName.NULL_NS_URI, BuiltInType.DATE.getName());
final QName complexItemDefinitionPart2TypeRef = new QName(QName.NULL_NS_URI, BuiltInType.BOOLEAN.getName());
final ItemDefinition complexItemDefinition = new ItemDefinition();
complexItemDefinition.setName(new Name(complexItemDefinitionName));
complexItemDefinition.getItemComponent().add(new ItemDefinition() {
{
setName(new Name(complexItemDefinitionPart1Name));
setTypeRef(complexItemDefinitionPart1TypeRef);
}
});
complexItemDefinition.getItemComponent().add(new ItemDefinition() {
{
setName(new Name(complexItemDefinitionPart2Name));
setTypeRef(complexItemDefinitionPart2TypeRef);
}
});
definitions.getItemDefinition().add(complexItemDefinition);
final QName inputData1TypeRef = new QName(QName.NULL_NS_URI, complexItemDefinitionName);
inputData1.getVariable().setTypeRef(inputData1TypeRef);
final Optional<DecisionTable> oModel = definition.getModelClass();
definition.enrich(Optional.of(NODE_UUID), decision, oModel);
final DecisionTable model = oModel.get();
assertBasicEnrichment(model);
final List<InputClause> input = model.getInput();
assertThat(input.size()).isEqualTo(3);
assertThat(input.get(0).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
assertThat(input.get(0).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_2);
assertThat(input.get(0).getInputExpression().getTypeRef()).isEqualTo(INPUT_DATA_QNAME_2);
assertThat(input.get(1).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
assertThat(input.get(1).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_1 + "." + complexItemDefinitionPart1Name);
assertThat(input.get(1).getInputExpression().getTypeRef()).isEqualTo(complexItemDefinitionPart1TypeRef);
assertThat(input.get(2).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
assertThat(input.get(2).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_1 + "." + complexItemDefinitionPart2Name);
assertThat(input.get(2).getInputExpression().getTypeRef()).isEqualTo(complexItemDefinitionPart2TypeRef);
assertStandardOutputClauseEnrichment(model);
assertStandardDecisionRuleEnrichment(model);
assertParentHierarchyEnrichment(model);
}
use of org.kie.workbench.common.dmn.api.definition.model.Definitions 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());
}
Aggregations