Search in sources :

Example 11 with DiagramImpl

use of org.kie.workbench.common.stunner.core.diagram.DiagramImpl in project kie-wb-common by kiegroup.

the class DMNMarshallerTest method test_wrong_context.

@Test
public void test_wrong_context() throws IOException {
    // DROOLS-2217
    // SPECIAL CASE: to represent a partially edited DMN file.
    // consider a LiteralExpression with null text as missing expression altogether.
    final DMNRuntime runtime = roundTripUnmarshalMarshalThenUnmarshalDMN(this.getClass().getResourceAsStream("/wrong_context.dmn"));
    DMNModel dmnModel = runtime.getModels().get(0);
    // the DMN file is schema valid but is not a valid-DMN (a context-entry value is a literal expression missing text, which is null)
    assertTrue(dmnModel.hasErrors());
    // identify the error message for context-entry "ciao":
    DMNMessage m0 = dmnModel.getMessages(DMNMessage.Severity.ERROR).get(0);
    assertTrue("expected a message identifying the problem on a context entry for 'ciao'", m0.getMessage().startsWith("No expression defined for name 'ciao'"));
    DecisionNode d0 = dmnModel.getDecisionById("_653b3426-933a-4050-9568-ab2a66b43c36");
    // the identified DMN Decision is composed of a DMN Context where the first context-entry value is a literal expression missing text (text is null).
    org.kie.dmn.model.v1_1.Context d0c = (org.kie.dmn.model.v1_1.Context) d0.getDecision().getExpression();
    org.kie.dmn.model.v1_1.Expression contextEntryValue = d0c.getContextEntry().get(0).getExpression();
    assertTrue(contextEntryValue instanceof org.kie.dmn.model.v1_1.LiteralExpression);
    assertEquals(null, ((org.kie.dmn.model.v1_1.LiteralExpression) contextEntryValue).getText());
    // -- Stunner side.
    DMNMarshaller m = new DMNMarshaller(new XMLEncoderDiagramMetadataMarshaller(), applicationFactoryManager);
    Graph<?, ?> g = m.unmarshall(null, this.getClass().getResourceAsStream("/wrong_context.dmn"));
    DiagramImpl diagram = new DiagramImpl("", null);
    Node<?, ?> decisionNode = g.getNode("_653b3426-933a-4050-9568-ab2a66b43c36");
    assertNodeContentDefinitionIs(decisionNode, Decision.class);
    View<Decision> view = ((View<Decision>) decisionNode.getContent());
    // the identified DMN Decision is composed of a DMN Context where the first context-entry has missing Expression.
    Context expression = (Context) view.getDefinition().getExpression();
    assertEquals("a literalexpression with null text is threated as a missing expression altogether.", null, expression.getContextEntry().get(0).getExpression());
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.v1_1.Context) DMNContext(org.kie.dmn.api.core.DMNContext) DiagramImpl(org.kie.workbench.common.stunner.core.diagram.DiagramImpl) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) Decision(org.kie.workbench.common.dmn.api.definition.v1_1.Decision) DMNMessage(org.kie.dmn.api.core.DMNMessage) XMLEncoderDiagramMetadataMarshaller(org.kie.workbench.common.stunner.core.backend.service.XMLEncoderDiagramMetadataMarshaller) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Example 12 with DiagramImpl

use of org.kie.workbench.common.stunner.core.diagram.DiagramImpl in project kie-wb-common by kiegroup.

the class DMNMarshallerTest method test_diamond.

@Test
public void test_diamond() throws IOException {
    // round trip test
    roundTripUnmarshalThenMarshalUnmarshal(this.getClass().getResourceAsStream("/diamond.dmn"), this::checkDiamongGraph);
    // additionally, check the marshalled is still DMN executable as expected
    DMNMarshaller m = new DMNMarshaller(new XMLEncoderDiagramMetadataMarshaller(), applicationFactoryManager);
    Graph<?, ?> g = m.unmarshall(null, this.getClass().getResourceAsStream("/diamond.dmn"));
    DiagramImpl diagram = new DiagramImpl("", null);
    diagram.setGraph(g);
    String mString = m.marshall(diagram);
    final KieServices ks = KieServices.Factory.get();
    final KieContainer kieContainer = KieHelper.getKieContainer(ks.newReleaseId("org.kie", "dmn-test_diamond", "1.0"), ks.getResources().newByteArrayResource(mString.getBytes()).setTargetPath("src/main/resources/diamond.dmn"));
    final DMNRuntime runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
    Assert.assertNotNull(runtime);
    DMNModel diamondModel = runtime.getModel("http://www.trisotech.com/definitions/_8afa6c24-55c8-43cf-8a02-fdde7fc5d1f2", "three decisions in a diamond shape");
    DMNContext dmnContext = runtime.newContext();
    dmnContext.set("My Name", "John Doe");
    DMNResult dmnResult = runtime.evaluateAll(diamondModel, dmnContext);
    assertFalse(dmnResult.getMessages().toString(), dmnResult.hasErrors());
    DMNContext result = dmnResult.getContext();
    assertEquals("Hello, John Doe.", result.get("My Decision"));
    // additionally, check DMN DD/DI for version 1.1
    org.kie.dmn.api.marshalling.v1_1.DMNMarshaller dmnMarshaller = DMNMarshallerFactory.newMarshallerWithExtensions(Arrays.asList(new DDExtensionsRegister()));
    Definitions definitions = dmnMarshaller.unmarshal(mString);
    assertNotNull(definitions.getExtensionElements());
    assertNotNull(definitions.getExtensionElements().getAny());
    assertEquals(1, definitions.getExtensionElements().getAny().size());
    org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNDiagram ddRoot = (org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNDiagram) definitions.getExtensionElements().getAny().get(0);
    DMNShape myname = findShapeByDMNI(ddRoot, "_4cd17e52-6253-41d6-820d-5824bf5197f3");
    assertBounds(500, 500, 100, 50, myname.getBounds());
    assertColor(255, 255, 255, myname.getBgColor());
    assertColor(0, 0, 0, myname.getBorderColor());
    assertEquals(0.5, myname.getBorderSize().getValue(), 0);
    assertDMNStyle("Open Sans", 24, 1, 255, 0, 0, myname.getFontStyle());
    DMNShape prefix = findShapeByDMNI(ddRoot, "_e920f38a-293c-41b8-adb3-69d0dc184fab");
    assertBounds(300, 400, 100, 50, prefix.getBounds());
    assertColor(0, 253, 25, prefix.getBgColor());
    assertColor(253, 0, 0, prefix.getBorderColor());
    assertEquals(1, prefix.getBorderSize().getValue(), 0);
    assertDMNStyle("Times New Roman", 8, 2.5, 70, 60, 50, prefix.getFontStyle());
    DMNShape postfix = findShapeByDMNI(ddRoot, "_f49f9c34-29d5-4e72-91d2-f4f92117c8da");
    assertBounds(700, 400, 100, 50, postfix.getBounds());
    assertColor(247, 255, 0, postfix.getBgColor());
    assertColor(0, 51, 255, postfix.getBorderColor());
    assertEquals(2, postfix.getBorderSize().getValue(), 0);
    assertDMNStyle("Arial", 10, 1.5, 50, 60, 70, postfix.getFontStyle());
    DMNShape mydecision = findShapeByDMNI(ddRoot, "_9b061fc3-8109-42e2-9fe4-fc39c90b654e");
    assertBounds(487.5, 275, 125, 75, mydecision.getBounds());
    assertColor(255, 255, 255, mydecision.getBgColor());
    assertColor(0, 0, 0, mydecision.getBorderColor());
    assertEquals(0.5, mydecision.getBorderSize().getValue(), 0);
    assertDMNStyle("Monospaced", 32, 3.5, 55, 66, 77, mydecision.getFontStyle());
}
Also used : KieServices(org.kie.api.KieServices) Matchers.anyString(org.mockito.Matchers.anyString) DMNShape(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNShape) XMLEncoderDiagramMetadataMarshaller(org.kie.workbench.common.stunner.core.backend.service.XMLEncoderDiagramMetadataMarshaller) DMNModel(org.kie.dmn.api.core.DMNModel) KieContainer(org.kie.api.runtime.KieContainer) DMNDiagram(org.kie.workbench.common.dmn.api.definition.v1_1.DMNDiagram) DMNResult(org.kie.dmn.api.core.DMNResult) DiagramImpl(org.kie.workbench.common.stunner.core.diagram.DiagramImpl) Definitions(org.kie.dmn.model.v1_1.Definitions) DMNContext(org.kie.dmn.api.core.DMNContext) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DDExtensionsRegister(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DDExtensionsRegister) Test(org.junit.Test)

Example 13 with DiagramImpl

use of org.kie.workbench.common.stunner.core.diagram.DiagramImpl in project kie-wb-common by kiegroup.

the class DMNMarshallerTest method roundTripUnmarshalThenMarshalUnmarshal.

public void roundTripUnmarshalThenMarshalUnmarshal(InputStream dmnXmlInputStream, Consumer<Graph<?, Node<?, ?>>> checkGraphConsumer) throws IOException {
    DMNMarshaller m = new DMNMarshaller(new XMLEncoderDiagramMetadataMarshaller(), applicationFactoryManager);
    // first unmarshal from DMN XML to Stunner DMN Graph
    @SuppressWarnings("unchecked") Graph<?, Node<?, ?>> g = m.unmarshall(null, dmnXmlInputStream);
    checkGraphConsumer.accept(g);
    // round trip to Stunner DMN Graph back to DMN XML
    DiagramImpl diagram = new DiagramImpl("", null);
    diagram.setGraph(g);
    String mString = m.marshall(diagram);
    System.out.println(mString);
    // now unmarshal once more, from the marshalled just done above, back again to Stunner DMN Graph to complete check for round-trip
    @SuppressWarnings("unchecked") Graph<?, Node<?, ?>> g2 = m.unmarshall(null, new StringInputStream(mString));
    checkGraphConsumer.accept(g2);
}
Also used : StringInputStream(org.apache.tools.ant.filters.StringInputStream) XMLEncoderDiagramMetadataMarshaller(org.kie.workbench.common.stunner.core.backend.service.XMLEncoderDiagramMetadataMarshaller) DiagramImpl(org.kie.workbench.common.stunner.core.diagram.DiagramImpl) Node(org.kie.workbench.common.stunner.core.graph.Node) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) Matchers.anyString(org.mockito.Matchers.anyString)

Aggregations

DiagramImpl (org.kie.workbench.common.stunner.core.diagram.DiagramImpl)13 XMLEncoderDiagramMetadataMarshaller (org.kie.workbench.common.stunner.core.backend.service.XMLEncoderDiagramMetadataMarshaller)8 Matchers.anyString (org.mockito.Matchers.anyString)8 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)5 Graph (org.kie.workbench.common.stunner.core.graph.Graph)5 Node (org.kie.workbench.common.stunner.core.graph.Node)5 Before (org.junit.Before)4 BPMNDefinitionSet (org.kie.workbench.common.stunner.bpmn.BPMNDefinitionSet)4 ArrayList (java.util.ArrayList)3 LinkedList (java.util.LinkedList)3 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)3 DecisionNode (org.kie.dmn.api.core.ast.DecisionNode)3 TestScopeModelFactory (org.kie.workbench.common.stunner.backend.definition.factory.TestScopeModelFactory)3 BPMNDiagramMarshaller (org.kie.workbench.common.stunner.bpmn.backend.BPMNDiagramMarshaller)3 BPMNGraphObjectBuilderFactory (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.builder.BPMNGraphObjectBuilderFactory)3 Bpmn2OryxIdMappings (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.Bpmn2OryxIdMappings)3 Bpmn2OryxManager (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.Bpmn2OryxManager)3 AssignmentsTypeSerializer (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.AssignmentsTypeSerializer)3 BooleanTypeSerializer (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.BooleanTypeSerializer)3 Bpmn2OryxPropertyManager (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.Bpmn2OryxPropertyManager)3