Search in sources :

Example 36 with OutputClause

use of org.kie.workbench.common.dmn.api.definition.model.OutputClause in project kie-wb-common by kiegroup.

the class DecisionTableDefaultValueUtilitiesTest method testGetNewOutputClauseNameWithDeletion.

@Test
public void testGetNewOutputClauseNameWithDeletion() {
    final OutputClause outputClause1 = new OutputClause();
    dtable.getOutput().add(outputClause1);
    outputClause1.setName(DecisionTableDefaultValueUtilities.getNewOutputClauseName(dtable));
    assertThat(outputClause1.getName()).isEqualTo(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_PREFIX + "1");
    final OutputClause outputClause2 = new OutputClause();
    dtable.getOutput().add(outputClause2);
    outputClause2.setName(DecisionTableDefaultValueUtilities.getNewOutputClauseName(dtable));
    assertThat(outputClause2.getName()).isEqualTo(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_PREFIX + "2");
    dtable.getOutput().remove(outputClause1);
    final OutputClause outputClause3 = new OutputClause();
    dtable.getOutput().add(outputClause3);
    outputClause3.setName(DecisionTableDefaultValueUtilities.getNewOutputClauseName(dtable));
    assertThat(outputClause3.getName()).isEqualTo(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_PREFIX + "3");
}
Also used : OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) Test(org.junit.Test)

Example 37 with OutputClause

use of org.kie.workbench.common.dmn.api.definition.model.OutputClause in project kie-wb-common by kiegroup.

the class DecisionTableDefaultValueUtilitiesTest method testGetNewOutputClauseNameWithExistingOutputClauses.

@Test
public void testGetNewOutputClauseNameWithExistingOutputClauses() {
    final OutputClause outputClause1 = new OutputClause();
    dtable.getOutput().add(outputClause1);
    outputClause1.setName("output");
    final OutputClause outputClause2 = new OutputClause();
    dtable.getOutput().add(outputClause2);
    outputClause2.setName(DecisionTableDefaultValueUtilities.getNewOutputClauseName(dtable));
    assertThat(outputClause2.getName()).isEqualTo(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_PREFIX + "1");
}
Also used : OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) Test(org.junit.Test)

Example 38 with OutputClause

use of org.kie.workbench.common.dmn.api.definition.model.OutputClause 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());
}
Also used : InformationItemPrimary(org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) DMNGraphUtils(org.kie.workbench.common.dmn.client.graph.DMNGraphUtils) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) Test(org.junit.Test)

Example 39 with OutputClause

use of org.kie.workbench.common.dmn.api.definition.model.OutputClause in project kie-wb-common by kiegroup.

the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenParentIsContextEntry.

@Test
public void testModelEnrichmentWhenParentIsContextEntry() {
    final Decision decision = mock(Decision.class);
    final String name = "context-entry";
    final Context context = new Context();
    final ContextEntry contextEntry = new ContextEntry();
    context.getContextEntry().add(contextEntry);
    contextEntry.setVariable(new InformationItem(new Id(), new Description(), new Name(name), OUTPUT_DATA_QNAME));
    final Optional<DecisionTable> oModel = definition.getModelClass();
    oModel.get().setParent(contextEntry);
    contextEntry.setParent(context);
    context.setParent(decision);
    when(decision.asDMNModelInstrumentedBase()).thenReturn(contextEntry);
    definition.enrich(Optional.empty(), decision, oModel);
    final DecisionTable model = oModel.get();
    assertBasicEnrichment(model);
    assertStandardInputClauseEnrichment(model);
    final List<OutputClause> output = model.getOutput();
    assertThat(output.size()).isEqualTo(1);
    assertThat(output.get(0).getName()).isEqualTo(DEFAULT_OUTPUT_NAME);
    assertThat(output.get(0).getTypeRef()).isEqualTo(OUTPUT_DATA_QNAME);
    assertStandardDecisionRuleEnrichment(model);
    assertParentHierarchyEnrichment(model);
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.model.Context) OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Example 40 with OutputClause

use of org.kie.workbench.common.dmn.api.definition.model.OutputClause 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());
}
Also used : InformationItemPrimary(org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) DMNGraphUtils(org.kie.workbench.common.dmn.client.graph.DMNGraphUtils) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) Test(org.junit.Test)

Aggregations

OutputClause (org.kie.workbench.common.dmn.api.definition.model.OutputClause)40 Test (org.junit.Test)24 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)21 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)14 DecisionRule (org.kie.workbench.common.dmn.api.definition.model.DecisionRule)12 InputClause (org.kie.workbench.common.dmn.api.definition.model.InputClause)10 RuleAnnotationClause (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause)9 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)8 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)8 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)7 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)7 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)7 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)6 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)6 ContextEntry (org.kie.workbench.common.dmn.api.definition.model.ContextEntry)5 InformationItemPrimary (org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary)5 Before (org.junit.Before)4 TDecisionTable (org.kie.dmn.model.v1_2.TDecisionTable)4 TOutputClause (org.kie.dmn.model.v1_2.TOutputClause)4 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)4