use of org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl in project kie-wb-common by kiegroup.
the class CaseManagementCanvasHandlerTest method makeNode.
@SuppressWarnings("unchecked")
private Node<View<BPMNViewDefinition>, Edge> makeNode(final String uuid, final AbstractElementShape shape) {
final Node<View<BPMNViewDefinition>, Edge> node = new NodeImpl<>(uuid);
node.setContent(new ViewImpl(shape.getShapeDefinition(), new BoundsImpl(new BoundImpl(0.0, 0.0), new BoundImpl(10.0, 20.0))));
when(canvas.getShape(eq(uuid))).thenReturn(shape);
when(clientDefinitionManager.adapters()).thenReturn(adapterManager);
when(adapterManager.forDefinition()).thenReturn(definitionAdapter);
when(adapterManager.forProperty()).thenReturn(propertyAdapter);
when(definitionAdapter.getMetaProperty(eq(PropertyMetaTypes.NAME), anyObject())).thenReturn(PropertyMetaTypes.NAME);
when(propertyAdapter.getValue(eq(PropertyMetaTypes.NAME))).thenReturn("name");
return node;
}
use of org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl 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.stunner.core.graph.content.view.ViewImpl 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.stunner.core.graph.content.view.ViewImpl in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method test_function_java_WB_model.
@Test
public void test_function_java_WB_model() throws IOException {
final DMNMarshallerStandalone m = getDMNMarshaller();
@SuppressWarnings("unchecked") final Graph<?, Node<?, ?>> g = m.unmarshall(createMetadata(), this.getClass().getResourceAsStream("/DROOLS-2372.dmn"));
final Stream<Node<?, ?>> stream = StreamSupport.stream(Spliterators.spliteratorUnknownSize(g.nodes().iterator(), Spliterator.ORDERED), false);
final Optional<Decision> wbDecision = stream.filter(n -> n.getContent() instanceof ViewImpl).map(n -> (ViewImpl) n.getContent()).filter(n -> n.getDefinition() instanceof Decision).map(n -> (Decision) n.getDefinition()).findFirst();
wbDecision.ifPresent(d -> {
assertTrue(d.getExpression() instanceof FunctionDefinition);
final FunctionDefinition wbFunction = (FunctionDefinition) d.getExpression();
// This is what the WB expects
assertEquals(FunctionDefinition.Kind.JAVA, wbFunction.getKind());
});
final DMNRuntime runtime = roundTripUnmarshalMarshalThenUnmarshalDMN(this.getClass().getResourceAsStream("/DROOLS-2372.dmn"));
final DMNModel dmnModel = runtime.getModels().get(0);
final BusinessKnowledgeModelNode bkmNode = dmnModel.getBusinessKnowledgeModels().iterator().next();
final org.kie.dmn.model.api.FunctionDefinition dmnFunction = bkmNode.getBusinessKnowledModel().getEncapsulatedLogic();
assertEquals(FunctionKind.JAVA, dmnFunction.getKind());
}
use of org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl in project kie-wb-common by kiegroup.
the class BusinessKnowledgeModelConverterTest method testWBFromDMN.
@Test
@SuppressWarnings("unchecked")
public void testWBFromDMN() {
final Node<View<BusinessKnowledgeModel>, ?> factoryNode = new NodeImpl<>(UUID.uuid());
final View<BusinessKnowledgeModel> view = new ViewImpl<>(new BusinessKnowledgeModel(), Bounds.create());
factoryNode.setContent(view);
when(factoryManager.newElement(Mockito.<String>any(), eq(getDefinitionId(BusinessKnowledgeModel.class)))).thenReturn(element);
when(element.asNode()).thenReturn(factoryNode);
final org.kie.dmn.model.api.BusinessKnowledgeModel dmn = new TBusinessKnowledgeModel();
final org.kie.dmn.model.api.LiteralExpression literalExpression = new TLiteralExpression();
final org.kie.dmn.model.api.InformationItem informationItem = new TInformationItem();
final org.kie.dmn.model.api.FunctionDefinition functionDefinition = new TFunctionDefinition();
literalExpression.setId(EXPRESSION_UUID);
functionDefinition.setExpression(literalExpression);
functionDefinition.setId(FUNCTION_DEFINITION_UUID);
dmn.setId(DECISION_UUID);
dmn.setName(DECISION_NAME);
dmn.setDescription(DECISION_DESCRIPTION);
dmn.setVariable(informationItem);
dmn.setEncapsulatedLogic(functionDefinition);
final Node<View<BusinessKnowledgeModel>, ?> node = converter.nodeFromDMN(dmn, hasComponentWidthsConsumer);
final BusinessKnowledgeModel wb = (BusinessKnowledgeModel) DefinitionUtils.getElementDefinition(node);
assertThat(wb).isNotNull();
assertThat(wb.getId()).isNotNull();
assertThat(wb.getId().getValue()).isEqualTo(DECISION_UUID);
assertThat(wb.getName()).isNotNull();
assertThat(wb.getName().getValue()).isEqualTo(DECISION_NAME);
assertThat(wb.getDescription()).isNotNull();
assertThat(wb.getDescription().getValue()).isEqualTo(DECISION_DESCRIPTION);
assertThat(wb.getVariable()).isNotNull();
assertThat(wb.getVariable().getName().getValue()).isEqualTo(DECISION_NAME);
assertThat(wb.getEncapsulatedLogic()).isNotNull();
assertThat(wb.getEncapsulatedLogic().getExpression()).isNotNull();
assertThat(wb.getEncapsulatedLogic().getExpression().getId().getValue()).isEqualTo(EXPRESSION_UUID);
verify(hasComponentWidthsConsumer).accept(eq(EXPRESSION_UUID), hasComponentWidthsCaptor.capture());
final HasComponentWidths hasComponentWidths0 = hasComponentWidthsCaptor.getValue();
assertThat(hasComponentWidths0).isNotNull();
assertThat(hasComponentWidths0).isEqualTo(wb.getEncapsulatedLogic().getExpression());
verify(hasComponentWidthsConsumer).accept(eq(FUNCTION_DEFINITION_UUID), hasComponentWidthsCaptor.capture());
final HasComponentWidths hasComponentWidths1 = hasComponentWidthsCaptor.getValue();
assertThat(hasComponentWidths1).isNotNull();
assertThat(hasComponentWidths1).isEqualTo(wb.getEncapsulatedLogic());
}
Aggregations