Search in sources :

Example 6 with Context

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

the class PMMLFunctionEditorDefinitionTest method testModelEnrichment.

@Test
public void testModelEnrichment() {
    final Optional<Context> oModel = definition.getModelClass();
    definition.enrich(Optional.empty(), hasExpression, oModel);
    final Context model = oModel.get();
    assertEquals(2, model.getContextEntry().size());
    assertEquals(LiteralExpressionPMMLDocument.VARIABLE_DOCUMENT, model.getContextEntry().get(0).getVariable().getName().getValue());
    assertTrue(model.getContextEntry().get(0).getExpression() instanceof LiteralExpressionPMMLDocument);
    assertEquals(model, model.getContextEntry().get(0).getParent());
    assertEquals(LiteralExpressionPMMLDocumentModel.VARIABLE_MODEL, model.getContextEntry().get(1).getVariable().getName().getValue());
    assertTrue(model.getContextEntry().get(1).getExpression() instanceof LiteralExpressionPMMLDocumentModel);
    assertEquals(model, model.getContextEntry().get(1).getParent());
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.model.Context) LiteralExpressionPMMLDocumentModel(org.kie.workbench.common.dmn.api.definition.model.LiteralExpressionPMMLDocumentModel) LiteralExpressionPMMLDocument(org.kie.workbench.common.dmn.api.definition.model.LiteralExpressionPMMLDocument) Test(org.junit.Test)

Example 7 with Context

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

the class PMMLIncludedModelHandlerTest method assertNestedLiteralExpression.

private void assertNestedLiteralExpression(final BusinessKnowledgeModel bkm) {
    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(LiteralExpression.class);
    assertThat(((LiteralExpression) contextEntry.getExpression()).getText().getValue()).isEmpty();
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.model.Context) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry)

Example 8 with Context

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

the class PMMLIncludedModelHandlerTest method makeNestedPMMLFunctionDefinition.

private Context makeNestedPMMLFunctionDefinition(final String documentName, final String modelName) {
    final Context context = new Context();
    final ContextEntry contextEntry = new ContextEntry();
    final InformationItem variable = new InformationItem();
    variable.getName().setValue("variable");
    contextEntry.setVariable(variable);
    contextEntry.setExpression(makeTopLevelPMMLFunctionDefinition(documentName, modelName));
    context.getContextEntry().add(contextEntry);
    return context;
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.model.Context) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry)

Example 9 with Context

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

the class PMMLIncludedModelHandlerTest method assertNestedFunctionDefinition.

private void assertNestedFunctionDefinition(final Decision decision, final String expectedDocumentValue, final String expectedModelValue) {
    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(FunctionDefinition.class);
    assertPMMLContextDefinition((FunctionDefinition) contextEntry.getExpression(), expectedDocumentValue, expectedModelValue);
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.model.Context) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry)

Example 10 with Context

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

the class PMMLIncludedModelHandlerTest method assertPMMLContextDefinition.

private void assertPMMLContextDefinition(final FunctionDefinition function, final String expectedDocumentValue, final String expectedModelValue) {
    assertThat(function.getExpression()).isInstanceOf(Context.class);
    final Context context = (Context) function.getExpression();
    assertThat(context.getContextEntry().get(0).getExpression()).isInstanceOf(LiteralExpressionPMMLDocument.class);
    final LiteralExpressionPMMLDocument functionDocument = (LiteralExpressionPMMLDocument) context.getContextEntry().get(0).getExpression();
    assertThat(functionDocument.getText().getValue()).isEqualTo(wrap(expectedDocumentValue));
    assertThat(context.getContextEntry().get(1).getExpression()).isInstanceOf(LiteralExpressionPMMLDocumentModel.class);
    final LiteralExpressionPMMLDocumentModel functionDocumentModel = (LiteralExpressionPMMLDocumentModel) context.getContextEntry().get(1).getExpression();
    assertThat(functionDocumentModel.getText().getValue()).isEqualTo(wrap(expectedModelValue));
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.model.Context) LiteralExpressionPMMLDocumentModel(org.kie.workbench.common.dmn.api.definition.model.LiteralExpressionPMMLDocumentModel) LiteralExpressionPMMLDocument(org.kie.workbench.common.dmn.api.definition.model.LiteralExpressionPMMLDocument)

Aggregations

Context (org.kie.workbench.common.dmn.api.definition.model.Context)49 ContextEntry (org.kie.workbench.common.dmn.api.definition.model.ContextEntry)21 Test (org.junit.Test)20 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)15 InformationItem (org.kie.workbench.common.dmn.api.definition.model.InformationItem)13 FunctionDefinition (org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition)12 TContext (org.kie.dmn.model.v1_2.TContext)9 Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)8 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)7 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)7 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)7 NamespaceContext (javax.xml.namespace.NamespaceContext)6 Before (org.junit.Before)6 DMNContext (org.kie.dmn.api.core.DMNContext)6 HasComponentWidths (org.kie.workbench.common.dmn.api.definition.HasComponentWidths)5 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)5 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)5 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)5 View (org.kie.workbench.common.stunner.core.graph.content.view.View)5 ArrayList (java.util.ArrayList)4