use of org.kie.workbench.common.dmn.client.graph.DMNGraphUtils 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.client.graph.DMNGraphUtils in project kie-wb-common by kiegroup.
the class DecisionTableGridTest method setup.
@Before
@SuppressWarnings("unchecked")
public void setup() {
when(sessionManager.getCurrentSession()).thenReturn(session);
when(session.getGridPanel()).thenReturn(gridPanel);
when(session.getGridLayer()).thenReturn(gridLayer);
when(session.getCellEditorControls()).thenReturn(cellEditorControls);
this.definition = new DecisionTableEditorDefinition(definitionUtils, sessionManager, sessionCommandManager, canvasCommandFactory, editorSelectedEvent, refreshFormPropertiesEvent, domainObjectSelectionEvent, listSelector, translationService, hitPolicyEditor, headerEditors, new DecisionTableEditorDefinitionEnricher(sessionManager, new DMNGraphUtils(sessionManager, dmnDiagramUtils, dmnDiagramsSession), itemDefinitionUtils), readOnlyProvider);
expression = definition.getModelClass();
definition.enrich(Optional.empty(), hasExpression, expression);
when(session.getCanvasHandler()).thenReturn(canvasHandler);
when(canvasHandler.getGraphExecutionContext()).thenReturn(graphCommandContext);
when(parentGridWidget.getModel()).thenReturn(parentGridData);
when(parentGridData.getColumns()).thenReturn(Collections.singletonList(parentGridColumn));
parent = spy(new GridCellTuple(0, 0, parentGridWidget));
when(gridWidget.getModel()).thenReturn(new BaseGridData(false));
when(gridLayer.getDomElementContainer()).thenReturn(gridLayerDomElementContainer);
when(gridLayerDomElementContainer.iterator()).thenReturn(mock(Iterator.class));
when(gridLayer.getVisibleBounds()).thenReturn(new BaseBounds(0, 0, 1000, 2000));
when(gridLayer.getViewport()).thenReturn(viewport);
when(viewport.getTransform()).thenReturn(transform);
when(canvasHandler.getDiagram()).thenReturn(diagram);
when(diagram.getGraph()).thenReturn(graph);
when(graph.nodes()).thenReturn(Collections.singletonList(node));
when(canvasHandler.getGraphIndex()).thenReturn(index);
when(index.get(Mockito.<String>any())).thenReturn(element);
when(element.getContent()).thenReturn(mock(Definition.class));
when(definitionUtils.getNameIdentifier(any())).thenReturn("name");
when(canvasCommandFactory.updatePropertyValue(any(Element.class), Mockito.<String>any(), any())).thenReturn(updateElementPropertyCommand);
when(updateElementPropertyCommand.execute(canvasHandler)).thenReturn(CanvasCommandResultBuilder.SUCCESS);
when(headerEditors.get()).thenReturn(headerEditor);
when(gridBodyCellEditContext.getRelativeLocation()).thenReturn(Optional.empty());
doAnswer((i) -> i.getArguments()[0].toString()).when(translationService).format(Mockito.<String>any());
doAnswer((i) -> i.getArguments()[0].toString()).when(translationService).getTranslation(Mockito.<String>any());
}
use of org.kie.workbench.common.dmn.client.graph.DMNGraphUtils in project kie-wb-common by kiegroup.
the class BaseDecisionTableEditorDefinitionTest method setup.
@Before
@SuppressWarnings("unchecked")
public void setup() {
when(sessionManager.getCurrentSession()).thenReturn(session);
when(session.getGridPanel()).thenReturn(gridPanel);
when(session.getGridLayer()).thenReturn(gridLayer);
when(session.getCellEditorControls()).thenReturn(cellEditorControls);
when(session.getCanvasHandler()).thenReturn(canvasHandler);
this.definition = new DecisionTableEditorDefinition(definitionUtils, sessionManager, sessionCommandManager, canvasCommandFactory, editorSelectedEvent, refreshFormPropertiesEvent, domainObjectSelectionEvent, listSelector, translationService, hitPolicyEditor, headerEditors, new DecisionTableEditorDefinitionEnricher(sessionManager, new DMNGraphUtils(sessionManager, new DMNDiagramUtils(), dmnDiagramsSession), itemDefinitionUtils), readOnlyProvider);
when(session.getCanvasHandler()).thenReturn(canvasHandler);
when(canvasHandler.getDiagram()).thenReturn(diagram);
when(dmnDiagramsSession.getDRGDiagram()).thenReturn(diagram);
when(diagram.getGraph()).thenReturn(graph);
when(headerEditors.get()).thenReturn(headerEditor);
doAnswer((i) -> i.getArguments()[0].toString()).when(translationService).format(Mockito.<String>any());
doAnswer((i) -> i.getArguments()[0].toString()).when(translationService).getTranslation(Mockito.<String>any());
}
use of org.kie.workbench.common.dmn.client.graph.DMNGraphUtils in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenDecisionTypeRefIsStructureAndOneSubfieldIsStructure.
@Test
public void testModelEnrichmentWhenDecisionTypeRefIsStructureAndOneSubfieldIsStructure() {
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 tCompany = mockTCompanyStructure();
when(dmnGraphUtils.getModelDefinitions()).thenReturn(definitions);
when(definitions.getItemDefinition()).thenReturn(Collections.singletonList(tCompany));
when(hasExpression.asDMNModelInstrumentedBase()).thenReturn(decision);
when(decision.getVariable()).thenReturn(informationItemPrimary);
when(informationItemPrimary.getTypeRef()).thenReturn(new QName("", TYPE_COMPANY));
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("address", outputClause1.getName());
assertEquals(ANY.asQName(), outputClause1.getTypeRef());
assertEquals("name", outputClause2.getName());
assertEquals(STRING.asQName(), outputClause2.getTypeRef());
}
use of org.kie.workbench.common.dmn.client.graph.DMNGraphUtils in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenDecisionTypeRefIsStructureWithNoFields.
@Test
public void testModelEnrichmentWhenDecisionTypeRefIsStructureWithNoFields() {
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 = mock(ItemDefinition.class);
final QName tPersonTypeRef = new QName("", TYPE_PERSON);
when(tPerson.getName()).thenReturn(new Name(TYPE_PERSON));
when(tPerson.getTypeRef()).thenReturn(tPersonTypeRef);
when(tPerson.getItemComponent()).thenReturn(emptyList());
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(tPersonTypeRef);
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(1);
final OutputClause outputClause = outputClauses.get(0);
assertEquals(DEFAULT_OUTPUT_NAME, outputClause.getName());
assertEquals(tPersonTypeRef, outputClause.getTypeRef());
}
Aggregations