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");
}
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");
}
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());
}
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);
}
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());
}
Aggregations