Search in sources :

Example 21 with ViewImpl

use of org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl in project kie-wb-common by kiegroup.

the class ObserverBuilderControlTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() throws Exception {
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocationOnMock) {
            ServiceCallback<Node<View<Object>, Edge>> callback = (ServiceCallback<Node<View<Object>, Edge>>) (invocationOnMock.getArguments()[2]);
            view = new ViewImpl<>(new Object(), Bounds.create(0.0, 0.0, 10.0, 20.0));
            Node<View<Object>, Edge> item = new NodeImpl<>("UUID");
            item.setContent(view);
            callback.onSuccess(item);
            return null;
        }
    }).when(clientFactoryServices).newElement(anyString(), anyString(), any(ServiceCallback.class));
    when(graphBoundsIndexer.setRootUUID(anyString())).thenReturn(graphBoundsIndexer);
    AdapterManager adapters = mock(AdapterManager.class);
    DefinitionAdapter definitionAdapter = mock(DefinitionAdapter.class);
    DefinitionSetRuleAdapter rulesAdapter = mock(DefinitionSetRuleAdapter.class);
    when(definitionAdapter.getId(any())).thenReturn(DefinitionId.build("Object"));
    when(rulesAdapter.getRuleSet(any())).thenReturn(mock(RuleSet.class));
    when(adapters.forDefinition()).thenReturn(definitionAdapter);
    when(adapters.forRules()).thenReturn(rulesAdapter);
    when(definitionAdapter.getId(DEF)).thenReturn(DefinitionId.build(DEF_ID));
    when(definitionAdapter.getLabels(DEF)).thenReturn(new String[0]);
    when(clientDefinitionManager.adapters()).thenReturn(adapters);
    when(clientDefinitionManager.definitionSets()).thenReturn(mock(TypeDefinitionSetRegistry.class));
    when(canvasCommandFactory.addNode(any(Node.class), any())).thenAnswer(new Answer<Command>() {

        @Override
        public Command answer(InvocationOnMock invocationOnMock) {
            Node node = (Node) invocationOnMock.getArguments()[0];
            String uid = (String) invocationOnMock.getArguments()[1];
            return new AddCanvasNodeCommand(node, uid);
        }
    });
    when(canvasCommandFactory.updatePosition(any(Node.class), any(Point2D.class))).thenAnswer(new Answer<Command>() {

        @Override
        public Command answer(InvocationOnMock invocationOnMock) {
            Node node = (Node) invocationOnMock.getArguments()[0];
            Point2D location = (Point2D) invocationOnMock.getArguments()[1];
            return new UpdateElementPositionCommand(node, location);
        }
    });
    when(canvasCommandFactory.draw()).thenReturn(mock(CanvasCommand.class));
    ShapeSet shapeSet = mock(ShapeSet.class);
    ShapeFactory shapeFactory = mock(ShapeFactory.class);
    when(shapeFactory.newShape(any())).thenReturn(mock(ElementShape.class));
    when(shapeSet.getShapeFactory()).thenReturn(shapeFactory);
    when(shapeManager.getShapeSet(any())).thenReturn(shapeSet);
    when(shapeManager.getDefaultShapeSet(any())).thenReturn(shapeSet);
    tested = new ObserverBuilderControl(clientDefinitionManager, clientFactoryServices, ruleManager, canvasCommandFactory, mock(ClientTranslationMessages.class), graphBoundsIndexer, mock(EventSourceMock.class));
    Diagram diagram = mock(Diagram.class);
    Metadata metadata = mock(Metadata.class);
    when(metadata.getCanvasRootUUID()).thenReturn("ID");
    when(diagram.getMetadata()).thenReturn(metadata);
    MutableIndex index = mock(MutableIndex.class);
    Graph graph = mock(Graph.class);
    DefinitionSet graphContent = mock(DefinitionSet.class);
    when(graph.getContent()).thenReturn(graphContent);
    when(index.getGraph()).thenReturn(graph);
    when(graphIndexBuilder.build(any(Graph.class))).thenReturn(index);
    when(diagram.getGraph()).thenReturn(graph);
    when(graph.nodes()).thenReturn(Collections.emptyList());
    CanvasCommandManager commandManager = mock(CanvasCommandManager.class);
    doAnswer(invocationOnMock -> {
        Command command = (Command) invocationOnMock.getArguments()[1];
        command.execute(invocationOnMock.getArguments()[0]);
        return null;
    }).when(commandManager).execute(any(), any(Command.class));
    when(commandManagerProvider.getCommandManager()).thenReturn(commandManager);
    canvas = mock(AbstractCanvas.class);
    canvasTransform = spy(new TransformImpl(new Point2D(0, 0), new Point2D(1, 1)));
    canvasView = mock(AbstractCanvas.CanvasView.class);
    canvasWidget = mock(Widget.class);
    canvasElement = mock(com.google.gwt.user.client.Element.class);
    document = mock(Document.class);
    when(canvas.getView()).thenReturn(canvasView);
    when(canvas.getTransform()).thenReturn(canvasTransform);
    when(canvasView.asWidget()).thenReturn(canvasWidget);
    when(canvasWidget.getElement()).thenReturn(canvasElement);
    when(canvasElement.getOwnerDocument()).thenReturn(document);
    canvasPanel = mock(CanvasPanel.class);
    when(canvasView.getPanel()).thenReturn(canvasPanel);
    canvasHandler = new CanvasHandlerImpl(clientDefinitionManager, canvasCommandFactory, ruleManager, graphUtils, graphIndexBuilder, shapeManager, mock(TextPropertyProviderFactory.class), mock(EventSourceMock.class), null, null, null);
    GraphCommandExecutionContext graphCommandExecutionContext = mock(GraphCommandExecutionContext.class);
    when(graphCommandExecutionContext.getGraphIndex()).thenReturn(index);
    canvasHandler.setGraphExecutionContext(() -> graphCommandExecutionContext);
    canvasHandler.handle(canvas);
    canvasHandler.draw(diagram, mock(ParameterizedCommand.class));
    tested.init(canvasHandler);
    tested.setCommandManagerProvider(commandManagerProvider);
}
Also used : TypeDefinitionSetRegistry(org.kie.workbench.common.stunner.core.registry.definition.TypeDefinitionSetRegistry) CanvasPanel(org.kie.workbench.common.stunner.core.client.canvas.CanvasPanel) Node(org.kie.workbench.common.stunner.core.graph.Node) ShapeSet(org.kie.workbench.common.stunner.core.client.ShapeSet) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) TransformImpl(org.kie.workbench.common.stunner.core.client.canvas.TransformImpl) Widget(com.google.gwt.user.client.ui.Widget) ShapeFactory(org.kie.workbench.common.stunner.core.client.shape.factory.ShapeFactory) ObserverBuilderControl(org.kie.workbench.common.stunner.core.client.canvas.controls.builder.impl.ObserverBuilderControl) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Document(com.google.gwt.dom.client.Document) DefinitionAdapter(org.kie.workbench.common.stunner.core.definition.adapter.DefinitionAdapter) ServiceCallback(org.kie.workbench.common.stunner.core.client.service.ServiceCallback) AdapterManager(org.kie.workbench.common.stunner.core.definition.adapter.AdapterManager) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) ElementShape(org.kie.workbench.common.stunner.core.client.shape.ElementShape) ViewImpl(org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) CanvasCommand(org.kie.workbench.common.stunner.core.client.command.CanvasCommand) RuleSet(org.kie.workbench.common.stunner.core.rule.RuleSet) MutableIndex(org.kie.workbench.common.stunner.core.graph.processing.index.MutableIndex) CanvasHandlerImpl(org.kie.workbench.common.stunner.core.client.canvas.CanvasHandlerImpl) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) Graph(org.kie.workbench.common.stunner.core.graph.Graph) CanvasCommand(org.kie.workbench.common.stunner.core.client.command.CanvasCommand) AddCanvasNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddCanvasNodeCommand) ParameterizedCommand(org.uberfire.mvp.ParameterizedCommand) UpdateElementPositionCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand) Command(org.kie.workbench.common.stunner.core.command.Command) AbstractCanvas(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas) InvocationOnMock(org.mockito.invocation.InvocationOnMock) CanvasCommandManager(org.kie.workbench.common.stunner.core.client.command.CanvasCommandManager) AddCanvasNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddCanvasNodeCommand) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) DefinitionSetRuleAdapter(org.kie.workbench.common.stunner.core.definition.adapter.DefinitionSetRuleAdapter) UpdateElementPositionCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand) Edge(org.kie.workbench.common.stunner.core.graph.Edge) ParameterizedCommand(org.uberfire.mvp.ParameterizedCommand) Before(org.junit.Before)

Example 22 with ViewImpl

use of org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl in project kie-wb-common by kiegroup.

the class WrapperUtilsTest method testGetDmnElementRefWithFakeNamespace.

@Test
public void testGetDmnElementRefWithFakeNamespace() {
    final Decision drgElement = mock(Decision.class);
    final View<? extends DMNElement> view = new ViewImpl<>(drgElement, null);
    final String defaultNamespace = "://default";
    final Name drgElementName = 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);
    when(id.getValue()).thenReturn("0000-1111-2222");
    when(drgElementName.getValue()).thenReturn("fakeNamespace.Decision");
    when(drgElement.getId()).thenReturn(id);
    when(drgElement.getName()).thenReturn(drgElementName);
    when(drgElement.getParent()).thenReturn(definitions);
    when(definitions.getImport()).thenReturn(emptyList());
    final QName actual = getDmnElementRef(definitions, view, defaultNamespace);
    assertEquals(defaultNamespace, actual.getNamespaceURI());
    assertEquals("0000-1111-2222", actual.getLocalPart());
    assertEquals("", actual.getPrefix());
}
Also used : QName(javax.xml.namespace.QName) ViewImpl(org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) QName(javax.xml.namespace.QName) Test(org.junit.Test)

Example 23 with ViewImpl

use of org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl in project kie-wb-common by kiegroup.

the class WrapperUtilsTest method testGetDmnElementRefWithoutNamespace.

@Test
public void testGetDmnElementRefWithoutNamespace() {
    final Decision drgElement = mock(Decision.class);
    final View<? extends DMNElement> view = new ViewImpl<>(drgElement, null);
    final String defaultNamespace = "://default";
    final Name drgElementName = 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);
    when(id.getValue()).thenReturn("0000-1111-2222");
    when(drgElementName.getValue()).thenReturn("Decision");
    when(drgElement.getId()).thenReturn(id);
    when(drgElement.getName()).thenReturn(drgElementName);
    when(drgElement.getParent()).thenReturn(definitions);
    when(definitions.getImport()).thenReturn(emptyList());
    final QName actual = getDmnElementRef(definitions, view, defaultNamespace);
    assertEquals(defaultNamespace, actual.getNamespaceURI());
    assertEquals("0000-1111-2222", actual.getLocalPart());
    assertEquals("", actual.getPrefix());
}
Also used : QName(javax.xml.namespace.QName) ViewImpl(org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) QName(javax.xml.namespace.QName) Test(org.junit.Test)

Example 24 with ViewImpl

use of org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl in project kie-wb-common by kiegroup.

the class WrapperUtilsTest 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 Import anImport = mock(Import.class);
    final List<Import> imports = singletonList(anImport);
    final String includedModelName = "includedModel";
    final String defaultNamespace = "://default";
    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 QName actual = getDmnElementRef(definitions, view, defaultNamespace);
    assertEquals(defaultNamespace, actual.getNamespaceURI());
    assertEquals("include1:0000-1111-2222", actual.getLocalPart());
    assertEquals("", actual.getPrefix());
}
Also used : Import(org.kie.workbench.common.dmn.api.definition.model.Import) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) QName(javax.xml.namespace.QName) ViewImpl(org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) Test(org.junit.Test)

Example 25 with ViewImpl

use of org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl in project kie-wb-common by kiegroup.

the class DMNDecisionServiceSVGShapeDefImplTest method testNewSizeHandler.

@Test
@SuppressWarnings("unchecked")
public void testNewSizeHandler() {
    final DecisionService decisionService = new DecisionService();
    final View<DecisionService> view = new ViewImpl<>(decisionService, Bounds.create(0, 0, DEFAULT_WIDTH, DEFAULT_HEIGHT));
    final SVGShapeView<?> shapeView = mock(SVGShapeView.class);
    final SizeHandler<DecisionService, SVGShapeView> handler = shapeDef.newSizeHandler();
    handler.handle(view, shapeView);
    verify(shapeView).setMinWidth(decisionService.getDimensionsSet().getMinimumWidth());
    verify(shapeView).setMaxWidth(decisionService.getDimensionsSet().getMaximumWidth());
    verify(shapeView).setMinHeight(decisionService.getDividerLineY().getValue() + GeneralRectangleDimensionsSet.DEFAULT_HEIGHT);
    verify(shapeView).setMaxHeight(decisionService.getDimensionsSet().getMaximumHeight());
}
Also used : ViewImpl(org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl) SVGShapeView(org.kie.workbench.common.stunner.svg.client.shape.view.SVGShapeView) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) Test(org.junit.Test)

Aggregations

ViewImpl (org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl)54 Test (org.junit.Test)40 View (org.kie.workbench.common.stunner.core.graph.content.view.View)35 NodeImpl (org.kie.workbench.common.stunner.core.graph.impl.NodeImpl)35 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)17 Edge (org.kie.workbench.common.stunner.core.graph.Edge)12 Before (org.junit.Before)11 Node (org.kie.workbench.common.stunner.core.graph.Node)10 QName (javax.xml.namespace.QName)9 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)9 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)9 ReusableSubprocess (org.kie.workbench.common.stunner.bpmn.definition.ReusableSubprocess)9 TDecision (org.kie.dmn.model.v1_2.TDecision)7 BaseReusableSubprocess (org.kie.workbench.common.stunner.bpmn.definition.BaseReusableSubprocess)7 HashMap (java.util.HashMap)6 AdHocSubProcessPropertyWriter (org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.properties.AdHocSubProcessPropertyWriter)6 CallActivityPropertyWriter (org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.properties.CallActivityPropertyWriter)6 PropertyWriter (org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.properties.PropertyWriter)6 SubProcessPropertyWriter (org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.properties.SubProcessPropertyWriter)6 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)6