use of org.kie.workbench.common.dmn.api.definition.model.ContextEntry 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.ContextEntry in project kie-wb-common by kiegroup.
the class PMMLIncludedModelHandlerTest method makeTopLevelPMMLFunctionDefinition.
private FunctionDefinition makeTopLevelPMMLFunctionDefinition(final String documentName, final String modelName) {
final FunctionDefinition function = new FunctionDefinition();
function.setKind(FunctionDefinition.Kind.PMML);
final Context functionExpression = new Context();
function.setExpression(functionExpression);
final ContextEntry functionContextEntry1 = new ContextEntry();
final InformationItem functionContextEntry1Variable = new InformationItem();
final LiteralExpressionPMMLDocument functionContextEntry1Value = new LiteralExpressionPMMLDocument();
functionContextEntry1Variable.getName().setValue(LiteralExpressionPMMLDocument.VARIABLE_DOCUMENT);
functionContextEntry1.setVariable(functionContextEntry1Variable);
functionContextEntry1Value.getText().setValue("\"" + documentName + "\"");
functionContextEntry1.setExpression(functionContextEntry1Value);
final ContextEntry functionContextEntry2 = new ContextEntry();
final InformationItem functionContextEntry2Variable = new InformationItem();
final LiteralExpressionPMMLDocumentModel functionContextEntry2Value = new LiteralExpressionPMMLDocumentModel();
functionContextEntry2Variable.getName().setValue(LiteralExpressionPMMLDocumentModel.VARIABLE_MODEL);
functionContextEntry2.setVariable(functionContextEntry2Variable);
functionContextEntry2Value.getText().setValue("\"" + modelName + "\"");
functionContextEntry2.setExpression(functionContextEntry2Value);
functionExpression.getContextEntry().add(functionContextEntry1);
functionExpression.getContextEntry().add(functionContextEntry2);
return function;
}
use of org.kie.workbench.common.dmn.api.definition.model.ContextEntry in project kie-wb-common by kiegroup.
the class PMMLIncludedModelHandlerTest method makeNestedLiteralExpression.
private Context makeNestedLiteralExpression() {
final Context context = new Context();
final ContextEntry contextEntry = new ContextEntry();
final InformationItem variable = new InformationItem();
variable.getName().setValue("variable");
contextEntry.setVariable(variable);
contextEntry.setExpression(new LiteralExpression());
context.getContextEntry().add(contextEntry);
return context;
}
use of org.kie.workbench.common.dmn.api.definition.model.ContextEntry in project kie-wb-common by kiegroup.
the class PMMLIncludedModelHandlerTest method assertNestedLiteralExpression.
private void assertNestedLiteralExpression(final Decision decision) {
assertThat(decision.getExpression()).isInstanceOf(Context.class);
final Context context = (Context) decision.getExpression();
assertThat(context.getContextEntry()).hasSize(1);
final ContextEntry contextEntry = context.getContextEntry().get(0);
assertThat(contextEntry.getExpression()).isInstanceOf(LiteralExpression.class);
assertThat(((LiteralExpression) contextEntry.getExpression()).getText().getValue()).isEmpty();
}
use of org.kie.workbench.common.dmn.api.definition.model.ContextEntry in project kie-wb-common by kiegroup.
the class PMMLIncludedModelHandlerTest method assertNestedFunctionDefinition.
private void assertNestedFunctionDefinition(final BusinessKnowledgeModel bkm, final String expectedDocumentValue, final String expectedModelValue) {
final FunctionDefinition function = bkm.getEncapsulatedLogic();
assertThat(function.getExpression()).isInstanceOf(Context.class);
final Context context = (Context) function.getExpression();
assertThat(context.getContextEntry()).hasSize(1);
final ContextEntry contextEntry = context.getContextEntry().get(0);
assertThat(contextEntry.getExpression()).isInstanceOf(FunctionDefinition.class);
assertPMMLContextDefinition((FunctionDefinition) contextEntry.getExpression(), expectedDocumentValue, expectedModelValue);
}
Aggregations