use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.
the class DMNEditBusinessKnowledgeModelToolboxActionTest method testActionSetExpression.
@Test
public void testActionSetExpression() {
tested.onMouseClick(canvasHandler, E_UUID, mouseClickEvent);
final ArgumentCaptor<EditExpressionEvent> eventCaptor = ArgumentCaptor.forClass(EditExpressionEvent.class);
verify(editExpressionEvent, times(1)).fire(eventCaptor.capture());
final EditExpressionEvent editExprEvent = eventCaptor.getValue();
final HasExpression hasExpression = editExprEvent.getHasExpression();
Assertions.assertThatThrownBy(() -> hasExpression.setExpression(new DecisionTable())).isInstanceOf(UnsupportedOperationException.class).hasMessage("It is not possible to set the EncapsulatedLogic of a BusinessKnowledgeModel.");
}
use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.
the class DMNEditBusinessKnowledgeModelToolboxActionTest method testActionWhenIsReadOnlyDiagram.
@Test
public void testActionWhenIsReadOnlyDiagram() {
when(readOnlyProvider.isReadOnlyDiagram()).thenReturn(true);
final ToolboxAction<AbstractCanvasHandler> cascade = tested.onMouseClick(canvasHandler, E_UUID, mouseClickEvent);
assertEquals(tested, cascade);
final ArgumentCaptor<EditExpressionEvent> eventCaptor = ArgumentCaptor.forClass(EditExpressionEvent.class);
verify(editExpressionEvent, times(1)).fire(eventCaptor.capture());
final EditExpressionEvent editExprEvent = eventCaptor.getValue();
assertEquals(E_UUID, editExprEvent.getNodeUUID());
final HasExpression hasExpression = editExprEvent.getHasExpression();
assertEquals(bkm.getEncapsulatedLogic(), hasExpression.getExpression());
assertEquals(bkm, hasExpression.asDMNModelInstrumentedBase());
assertFalse(hasExpression.isClearSupported());
assertEquals(bkm, editExprEvent.getHasName().get());
assertEquals(session, editExprEvent.getSession());
assertTrue(editExprEvent.isOnlyVisualChangeAllowed());
}
use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.
the class DeleteListRowCommandTest method testGraphCommandExecuteRemoveMiddle.
@Test
public void testGraphCommandExecuteRemoveMiddle() {
uiModel.appendRow(new BaseGridRow());
uiModel.appendRow(new BaseGridRow());
final HasExpression firstRow = HasExpression.wrap(list, new LiteralExpression());
final HasExpression lastRow = HasExpression.wrap(list, new LiteralExpression());
list.getExpression().add(0, firstRow);
list.getExpression().add(lastRow);
makeCommand(1);
final Command<GraphCommandExecutionContext, RuleViolation> c = command.newGraphCommand(handler);
assertEquals(GraphCommandResultBuilder.SUCCESS, c.execute(gce));
assertEquals(2, list.getExpression().size());
assertEquals(firstRow, list.getExpression().get(0));
assertEquals(lastRow, list.getExpression().get(1));
}
use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.
the class ExpressionEditorViewImplTest method testSetExpressionDoesUpdateExpressionTypeTextWhenHasExpressionIsNotEmpty.
@Test
public void testSetExpressionDoesUpdateExpressionTypeTextWhenHasExpressionIsNotEmpty() {
final Expression expression = new LiteralExpression();
final Optional<HasName> hasName = Optional.empty();
when(hasExpression.getExpression()).thenReturn(expression);
view.setExpression(NODE_UUID, hasExpression, hasName, false);
verify(expressionType).setTextContent(eq(LITERAL_EXPRESSION_DEFINITION_NAME));
}
use of org.kie.workbench.common.dmn.api.definition.HasExpression 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());
}
Aggregations