use of org.kie.workbench.common.dmn.api.definition.model.Decision in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method testStunnerConstellationButtonCausingPoint2DbeingNull.
/**
* DROOLS-3184: If the "connection source/target location is null" assume it's the centre of the shape.
* [source/target location is null] If the connection was created from the Toolbox (i.e. add a InputData and then the Decision from it using the Decision toolbox icon).
* <p>
* This test re-create by hard-code the behavior of the Stunner framework "Toolbox" by instrumenting API calls to achieve the same behavior.
*/
@SuppressWarnings("unchecked")
@Test
public void testStunnerConstellationButtonCausingPoint2DbeingNull() throws IOException {
final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer = (uuid, hcw) -> {
/*NOP*/
};
Diagram diagram = createDiagram();
Graph g = diagram.getGraph();
Node diagramRoot = DMNMarshallerStandalone.findDMNDiagramRoot(g);
testAugmentWithNSPrefixes(((DMNDiagram) ((View<?>) diagramRoot.getContent()).getDefinition()).getDefinitions());
org.kie.dmn.model.api.InputData dmnInputData = new TInputData();
dmnInputData.setId("inputDataID");
dmnInputData.setName(dmnInputData.getId());
Node inputDataNode = new InputDataConverter(api.getFactoryManager()).nodeFromDMN(dmnInputData, hasComponentWidthsConsumer);
org.kie.dmn.model.api.Decision dmnDecision = new TDecision();
dmnDecision.setId("decisionID");
dmnDecision.setName(dmnDecision.getId());
Node decisionNode = new DecisionConverter(api.getFactoryManager()).nodeFromDMN(dmnDecision, hasComponentWidthsConsumer);
g.addNode(inputDataNode);
g.addNode(decisionNode);
View content = (View) decisionNode.getContent();
content.setBounds(org.kie.workbench.common.stunner.core.graph.content.Bounds.create(200, 200, 300, 250));
final String irID = "irID";
Edge myEdge = api.getFactoryManager().newElement(irID, DMNMarshallerStandalone.INFO_REQ_ID).asEdge();
myEdge.setSourceNode(inputDataNode);
myEdge.setTargetNode(decisionNode);
inputDataNode.getOutEdges().add(myEdge);
decisionNode.getInEdges().add(myEdge);
ViewConnector connectionContent = (ViewConnector) myEdge.getContent();
// DROOLS-3184: If the "connection source/target location is null" assume it's the centre of the shape.
// keep Stunner behavior of constellation button
connectionContent.setSourceConnection(MagnetConnection.Builder.atCenter(inputDataNode).setLocation(null).setAuto(true));
connectionContent.setTargetConnection(MagnetConnection.Builder.atCenter(decisionNode).setLocation(null).setAuto(true));
DMNMarshallerStandalone.connectRootWithChild(diagramRoot, inputDataNode);
DMNMarshallerStandalone.connectRootWithChild(diagramRoot, decisionNode);
DMNMarshallerStandalone m = getDMNMarshaller();
String output = m.marshall(diagram);
LOG.debug(output);
Definitions dmnDefinitions = DMNMarshallerFactory.newDefaultMarshaller().unmarshal(output);
DMNEdge dmndiEdge = findEdgeByDMNI(dmnDefinitions.getDMNDI().getDMNDiagram().get(0), irID);
assertThat(dmndiEdge.getWaypoint()).hasSize(2);
Point wpSource = dmndiEdge.getWaypoint().get(0);
assertThat(wpSource.getX()).isEqualByComparingTo(50d);
assertThat(wpSource.getY()).isEqualByComparingTo(25d);
Point wpTarget = dmndiEdge.getWaypoint().get(1);
assertThat(wpTarget.getX()).isEqualByComparingTo(250d);
assertThat(wpTarget.getY()).isEqualByComparingTo(225d);
}
use of org.kie.workbench.common.dmn.api.definition.model.Decision in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method testGetDmnElementRefWithNamespace.
@Test
public void testGetDmnElementRefWithNamespace() {
final Decision drgElement = mock(Decision.class);
final View<? extends DMNElement> view = new ViewImpl<>(drgElement, null);
final Name drgElementName = mock(Name.class);
final Name importName = mock(Name.class);
final Id id = mock(Id.class);
final org.kie.workbench.common.dmn.api.definition.model.Definitions definitions = mock(org.kie.workbench.common.dmn.api.definition.model.Definitions.class);
final org.kie.workbench.common.dmn.api.definition.model.Import anImport = mock(org.kie.workbench.common.dmn.api.definition.model.Import.class);
final List<org.kie.workbench.common.dmn.api.definition.model.Import> imports = singletonList(anImport);
final String includedModelName = "includedModel";
final String namespaceName = "include1";
final String importNamespace = "://namespace";
final Map<String, String> nsContext = new HashMap<>();
when(importName.getValue()).thenReturn(includedModelName);
when(anImport.getName()).thenReturn(importName);
when(anImport.getNamespace()).thenReturn(importNamespace);
when(id.getValue()).thenReturn("0000-1111-2222");
when(drgElementName.getValue()).thenReturn(includedModelName + ".Decision");
when(drgElement.getId()).thenReturn(id);
when(drgElement.getName()).thenReturn(drgElementName);
when(drgElement.getParent()).thenReturn(definitions);
nsContext.put(namespaceName, importNamespace);
when(definitions.getImport()).thenReturn(imports);
when(definitions.getNsContext()).thenReturn(nsContext);
final String actual = getDmnElementRef(definitions, view).getLocalPart();
final String expected = "include1:0000-1111-2222";
assertEquals(expected, actual);
}
use of org.kie.workbench.common.dmn.api.definition.model.Decision in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method testGetDmnElementRefWithNamespaceWhenImportHasAnOddName.
@Test
public void testGetDmnElementRefWithNamespaceWhenImportHasAnOddName() {
final Decision drgElement = mock(Decision.class);
final View<? extends DMNElement> view = new ViewImpl<>(drgElement, null);
final Name drgElementName = mock(Name.class);
final Name importName = mock(Name.class);
final Id id = mock(Id.class);
final org.kie.workbench.common.dmn.api.definition.model.Definitions definitions = mock(org.kie.workbench.common.dmn.api.definition.model.Definitions.class);
final org.kie.workbench.common.dmn.api.definition.model.Import anImport = mock(org.kie.workbench.common.dmn.api.definition.model.Import.class);
final List<org.kie.workbench.common.dmn.api.definition.model.Import> imports = singletonList(anImport);
final String includedModelName = "d.i.v.i.";
final String namespaceName = "include1";
final String importNamespace = "://namespace";
final Map<String, String> nsContext = new HashMap<>();
when(importName.getValue()).thenReturn(includedModelName);
when(anImport.getName()).thenReturn(importName);
when(anImport.getNamespace()).thenReturn(importNamespace);
when(id.getValue()).thenReturn("0000-1111-2222");
when(drgElementName.getValue()).thenReturn(includedModelName + ".Decision");
when(drgElement.getId()).thenReturn(id);
when(drgElement.getName()).thenReturn(drgElementName);
when(drgElement.getParent()).thenReturn(definitions);
nsContext.put(namespaceName, importNamespace);
when(definitions.getImport()).thenReturn(imports);
when(definitions.getNsContext()).thenReturn(nsContext);
final String actual = getDmnElementRef(definitions, view).getLocalPart();
final String expected = "include1:0000-1111-2222";
assertEquals(expected, actual);
}
use of org.kie.workbench.common.dmn.api.definition.model.Decision in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method checkDecisionqa.
@SuppressWarnings("unchecked")
private void checkDecisionqa(Graph<?, Node<?, ?>> graph) {
Node<?, ?> decision = graph.getNode("_7052d0f6-ccee-462b-bd89-76afc3b6f67b");
assertNodeContentDefinitionIs(decision, Decision.class);
Decision decisionDefinition = ((View<Decision>) decision.getContent()).getDefinition();
assertEquals("hardcoded question", decisionDefinition.getName().getValue());
assertEquals("What is the codename?", decisionDefinition.getQuestion().getValue());
assertEquals("47.", decisionDefinition.getAllowedAnswers().getValue());
}
use of org.kie.workbench.common.dmn.api.definition.model.Decision in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method checkComponentWidths.
@SuppressWarnings("unchecked")
private void checkComponentWidths(Graph<?, Node<?, ?>> graph) {
final Node<?, ?> node = graph.getNode("_37883BDC-DB54-4925-B539-A0F19B1DDE41");
assertThat(node).isNotNull();
assertNodeContentDefinitionIs(node, Decision.class);
final Decision definition = ((View<Decision>) node.getContent()).getDefinition();
assertThat(definition.getExpression()).isNotNull();
final HasComponentWidths expression = definition.getExpression();
final List<Double> componentWidths = expression.getComponentWidths();
assertThat(componentWidths.size()).isEqualTo(expression.getRequiredComponentWidthCount());
assertThat(componentWidths.get(0)).isEqualTo(50.0);
assertThat(componentWidths.get(1)).isEqualTo(150.0);
assertThat(componentWidths.get(2)).isEqualTo(200.0);
assertThat(componentWidths.get(3)).isEqualTo(250.0);
}
Aggregations