Skip to content

Commit

Permalink
KOGITO-4343: Fix JSONIX model generation with gwt 2.9
Browse files Browse the repository at this point in the history
  • Loading branch information
treblereel committed Mar 16, 2021
1 parent 5620ad0 commit 6cfce29
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.kie.workbench.common.dmn.client.marshaller.converters.KnowledgeSourceConverter;
import org.kie.workbench.common.dmn.client.marshaller.converters.TextAnnotationConverter;
import org.kie.workbench.common.dmn.client.marshaller.converters.dd.PointUtils;
import org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIPoint;
import org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.di.JSIDiagramElement;
import org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITAssociation;
import org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITBusinessKnowledgeModel;
Expand Down Expand Up @@ -505,17 +506,30 @@ protected void connect(final JSIDMNDiagram diagram,
dmnEdge.setDmnElementRef(new QName(namespaceURI,
uuid,
XMLConstants.DEFAULT_NS_PREFIX));
dmnEdge.addWaypoint(PointUtils.point2dToDMNDIPoint(sourcePoint));
dmnEdge.addWaypoint(point2dToDMNDIPoint(sourcePoint));
for (ControlPoint cp : connectionContent.getControlPoints()) {
dmnEdge.addWaypoint(PointUtils.point2dToDMNDIPoint(cp.getLocation()));
dmnEdge.addWaypoint(point2dToDMNDIPoint(cp.getLocation()));
}
dmnEdge.addWaypoint(PointUtils.point2dToDMNDIPoint(targetPoint));
dmnEdge.addWaypoint(point2dToDMNDIPoint(targetPoint));
dmnEdges.add(dmnEdge);
}
}
}
}

private JSIPoint point2dToDMNDIPoint(final Point2D point2d) {
final JSIPoint result = getPoint();
result.setX(point2d.getX());
result.setY(point2d.getY());
return result;
}

/** for testing */
protected JSIPoint getPoint() {
return JSIPoint.newInstance();
}

/** for testing */
protected JSIDMNEdge getDmnEdge() {
return JSIDMNEdge.newInstance();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.kie.workbench.common.dmn.api.definition.model.DRGElement;
import org.kie.workbench.common.dmn.api.definition.model.Definitions;
import org.kie.workbench.common.dmn.api.definition.model.Import;
import org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIPoint;
import org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITAuthorityRequirement;
import org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITBusinessKnowledgeModel;
import org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDRGElement;
Expand All @@ -35,8 +36,15 @@
import org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInformationRequirement;
import org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITKnowledgeRequirement;
import org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITKnowledgeSource;
import org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram;
import org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge;
import org.kie.workbench.common.stunner.core.graph.Edge;
import org.kie.workbench.common.stunner.core.graph.Node;
import org.kie.workbench.common.stunner.core.graph.content.definition.Definition;
import org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint;
import org.kie.workbench.common.stunner.core.graph.content.view.DiscreteConnection;
import org.kie.workbench.common.stunner.core.graph.content.view.View;
import org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector;
import org.mockito.invocation.InvocationOnMock;

import static java.util.Arrays.asList;
Expand Down Expand Up @@ -70,7 +78,7 @@ public void testMergeOrAddNodeToDefinitions() {
final JSITKnowledgeSource node5 = makeKnowledgeSource("id5");

final DMNMarshaller dmnMarshaller = spy(new DMNMarshaller());
final JSITDefinitions definitions = spy(JSITDefinitions.class);
final JSITDefinitions definitions = spy(mock(JSITDefinitions.class));
final List<JSITDRGElement> definitionsDRGElements = new ArrayList<>(asList(existingNode1, existingNode2, existingNode3));

final JSITAuthorityRequirement node1AuthorityRequirement = mock(JSITAuthorityRequirement.class);
Expand Down Expand Up @@ -175,7 +183,7 @@ public void testGetExistingNode() {
final JSITDecision definitionsDRGElement3 = makeDecision("id3");
final DMNMarshaller dmnMarshaller = new DMNMarshaller();

final JSITDefinitions definitions = spy(JSITDefinitions.class);
final JSITDefinitions definitions = spy(mock(JSITDefinitions.class));
final List<JSITDRGElement> definitionsDRGElements = new ArrayList<>(asList(definitionsDRGElement1, definitionsDRGElement2, definitionsDRGElement3));

doReturn(definitionsDRGElements).when(definitions).getDrgElement();
Expand Down Expand Up @@ -271,20 +279,85 @@ public void testWithIncludedModelsWhenNodeParentIsDefinitions() {
assertTrue(nodeDiagramImports.contains(import2));
}

@Test
public void testConnect() {
final DMNMarshaller dmnMarshaller = spy(new DMNMarshaller());
final JSIDMNDiagram diagram = mock(JSIDMNDiagram.class);
final List<String> dmnDiagramElementIds = mock(List.class);
final Definitions definitionsStunnerPojo = mock(Definitions.class);
final List<JSIDMNEdge> dmnEdges = new ArrayList<>();

final Node<?, ?> node = mock(Node.class);
final List inEdges = new ArrayList<>();
final Edge edge = mock(Edge.class);
final Node sourceNode = mock(Node.class);
final View sourceView = mock(View.class);
final ViewConnector viewConnector = mock(ViewConnector.class);
final DiscreteConnection sourceConnection = mock(DiscreteConnection.class);
final DiscreteConnection targetConnection = mock(DiscreteConnection.class);
final View<?> view = mock(View.class);

inEdges.add(edge);

doReturn(mock(JSIDMNEdge.class)).when(dmnMarshaller).getDmnEdge();
doReturn(mock(JSIPoint.class)).when(dmnMarshaller).getPoint();

when(edge.getSourceNode()).thenReturn(sourceNode);
when(sourceNode.getContent()).thenReturn(sourceView);

when(node.getInEdges()).thenReturn(inEdges);
when(edge.getContent()).thenReturn(viewConnector);
when(viewConnector.getControlPoints()).thenReturn(new ControlPoint[]{});
when(sourceConnection.isAuto()).thenReturn(true);
when(targetConnection.isAuto()).thenReturn(true);
when(diagram.getName()).thenReturn("dmnEdge");
when(definitionsStunnerPojo.getDefaultNamespace()).thenReturn("org.edge");

when(viewConnector.getSourceConnection()).thenReturn(Optional.of(sourceConnection));
when(viewConnector.getTargetConnection()).thenReturn(Optional.of(targetConnection));
dmnMarshaller.connect(diagram,
dmnDiagramElementIds,
definitionsStunnerPojo,
dmnEdges,
node,
view);

when(viewConnector.getSourceConnection()).thenReturn(Optional.empty());
when(viewConnector.getTargetConnection()).thenReturn(Optional.empty());
dmnMarshaller.connect(diagram,
dmnDiagramElementIds,
definitionsStunnerPojo,
dmnEdges,
node,
view);

when(viewConnector.getSourceConnection()).thenReturn(Optional.of(sourceConnection));
when(viewConnector.getTargetConnection()).thenReturn(Optional.empty());
dmnMarshaller.connect(diagram,
dmnDiagramElementIds,
definitionsStunnerPojo,
dmnEdges,
node,
view);

verify(sourceConnection).isAuto();
verify(targetConnection).isAuto();
}

private JSITDecision makeDecision(final String id) {
final JSITDecision decision = mock(JSITDecision.class);
JSITDecision decision = spy(mock(JSITDecision.class));
doReturn(id).when(decision).getId();
return decision;
}

private JSITBusinessKnowledgeModel makeBusinessKnowledgeModel(final String id) {
final JSITBusinessKnowledgeModel businessKnowledgeModel = spy(JSITBusinessKnowledgeModel.class);
final JSITBusinessKnowledgeModel businessKnowledgeModel = spy(mock(JSITBusinessKnowledgeModel.class));
doReturn(id).when(businessKnowledgeModel).getId();
return businessKnowledgeModel;
}

private JSITKnowledgeSource makeKnowledgeSource(final String id) {
final JSITKnowledgeSource knowledgeSource = spy(JSITKnowledgeSource.class);
final JSITKnowledgeSource knowledgeSource = spy(mock(JSITKnowledgeSource.class));
doReturn(id).when(knowledgeSource).getId();
return knowledgeSource;
}
Expand Down

0 comments on commit 6cfce29

Please sign in to comment.