Search in sources :

Example 1 with AdapterManager

use of org.kie.workbench.common.stunner.core.definition.adapter.AdapterManager in project kie-wb-common by kiegroup.

the class MigrationDiagramMarshallerTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() {
    definitionManager = mock(DefinitionManager.class);
    adapterManager = mock(AdapterManager.class);
    adapterRegistry = mock(AdapterRegistry.class);
    rulesManager = mock(RuleManager.class);
    cloneManager = mock(CloneManager.class);
    // Graph utils.
    when(definitionManager.adapters()).thenReturn(adapterManager);
    when(adapterManager.registry()).thenReturn(adapterRegistry);
    DefinitionUtils definitionUtils1 = new DefinitionUtils(definitionManager, applicationFactoryManager);
    testScopeModelFactory = new TestScopeModelFactory(new BPMNDefinitionSet.BPMNDefinitionSetBuilder().build());
    // Definition manager.
    final BackendDefinitionAdapter definitionAdapter = new BackendDefinitionAdapter(definitionUtils1);
    final BackendDefinitionSetAdapter definitionSetAdapter = new BackendDefinitionSetAdapter(definitionAdapter);
    final BackendPropertySetAdapter propertySetAdapter = new BackendPropertySetAdapter();
    final BackendPropertyAdapter propertyAdapter = new BackendPropertyAdapter();
    when(adapterManager.forDefinitionSet()).thenReturn(definitionSetAdapter);
    when(adapterManager.forDefinition()).thenReturn(definitionAdapter);
    when(adapterManager.forPropertySet()).thenReturn(propertySetAdapter);
    when(adapterManager.forProperty()).thenReturn(propertyAdapter);
    when(adapterRegistry.getDefinitionSetAdapter(any(Class.class))).thenReturn(definitionSetAdapter);
    when(adapterRegistry.getDefinitionAdapter(any(Class.class))).thenReturn(definitionAdapter);
    when(adapterRegistry.getPropertySetAdapter(any(Class.class))).thenReturn(propertySetAdapter);
    when(adapterRegistry.getPropertyAdapter(any(Class.class))).thenReturn(propertyAdapter);
    GraphCommandManager commandManager1 = new GraphCommandManagerImpl(null, null, null);
    GraphCommandFactory commandFactory1 = new GraphCommandFactory();
    connectionEdgeFactory = new EdgeFactoryImpl(definitionManager);
    viewNodeFactory = new NodeFactoryImpl(definitionUtils1);
    bpmnGraphFactory = new GraphFactoryImpl(definitionManager);
    doAnswer(invocationOnMock -> {
        String id = (String) invocationOnMock.getArguments()[0];
        return testScopeModelFactory.build(id);
    }).when(applicationFactoryManager).newDefinition(anyString());
    doAnswer(invocationOnMock -> {
        String uuid = (String) invocationOnMock.getArguments()[0];
        String id = (String) invocationOnMock.getArguments()[1];
        if (BPMNDefinitionSet.class.getName().equals(id)) {
            return bpmnGraphFactory.build(uuid, BPMN_DEF_SET_ID);
        }
        Object model = testScopeModelFactory.accepts(id) ? testScopeModelFactory.build(id) : null;
        if (null != model) {
            Class<? extends ElementFactory> element = BackendDefinitionAdapter.getGraphFactory(model.getClass());
            if (element.isAssignableFrom(NodeFactory.class)) {
                return viewNodeFactory.build(uuid, model);
            } else if (element.isAssignableFrom(EdgeFactory.class)) {
                return connectionEdgeFactory.build(uuid, model);
            }
        }
        return null;
    }).when(applicationFactoryManager).newElement(anyString(), anyString());
    doAnswer(invocationOnMock -> {
        String uuid = (String) invocationOnMock.getArguments()[0];
        Class type = (Class) invocationOnMock.getArguments()[1];
        String id = BindableAdapterUtils.getGenericClassName(type);
        if (BPMNDefinitionSet.class.equals(type)) {
            return bpmnGraphFactory.build(uuid, BPMN_DEF_SET_ID);
        }
        Object model = testScopeModelFactory.accepts(id) ? testScopeModelFactory.build(id) : null;
        if (null != model) {
            Class<? extends ElementFactory> element = BackendDefinitionAdapter.getGraphFactory(model.getClass());
            if (element.isAssignableFrom(NodeFactory.class)) {
                return viewNodeFactory.build(uuid, model);
            } else if (element.isAssignableFrom(EdgeFactory.class)) {
                return connectionEdgeFactory.build(uuid, model);
            }
        }
        return null;
    }).when(applicationFactoryManager).newElement(anyString(), any(Class.class));
    doAnswer(invocationOnMock -> {
        String uuid = (String) invocationOnMock.getArguments()[0];
        String defSetId = (String) invocationOnMock.getArguments()[1];
        final Graph graph = (Graph) applicationFactoryManager.newElement(uuid, defSetId);
        final DiagramImpl result = new DiagramImpl(uuid, new MetadataImpl.MetadataImplBuilder(defSetId).build());
        result.setGraph(graph);
        return result;
    }).when(applicationFactoryManager).newDiagram(anyString(), anyString(), any(Metadata.class));
    // Work items stuff.
    workItemDefinitionMockRegistry = new WorkItemDefinitionMockRegistry();
    // Bpmn 2 oryx stuff.
    Bpmn2OryxIdMappings oryxIdMappings = new Bpmn2OryxIdMappings(definitionManager, () -> workItemDefinitionMockRegistry);
    StringTypeSerializer stringTypeSerializer = new StringTypeSerializer();
    BooleanTypeSerializer booleanTypeSerializer = new BooleanTypeSerializer();
    ColorTypeSerializer colorTypeSerializer = new ColorTypeSerializer();
    DoubleTypeSerializer doubleTypeSerializer = new DoubleTypeSerializer();
    IntegerTypeSerializer integerTypeSerializer = new IntegerTypeSerializer();
    EnumTypeSerializer enumTypeSerializer = new EnumTypeSerializer(definitionUtils1);
    AssignmentsTypeSerializer assignmentsTypeSerializer = new AssignmentsTypeSerializer();
    VariablesTypeSerializer variablesTypeSerializer = new VariablesTypeSerializer();
    TimerSettingsTypeSerializer timerSettingsTypeSerializer = new TimerSettingsTypeSerializer();
    ScriptTypeTypeSerializer scriptTypeTypeSerializer = new ScriptTypeTypeSerializer();
    ScriptTypeListTypeSerializer scriptTypeListTypeSerializer = new ScriptTypeListTypeSerializer();
    TaskTypeSerializer taskTypeSerializer = new TaskTypeSerializer(definitionUtils1, enumTypeSerializer);
    List<Bpmn2OryxPropertySerializer<?>> propertySerializers = new LinkedList<>();
    propertySerializers.add(stringTypeSerializer);
    propertySerializers.add(booleanTypeSerializer);
    propertySerializers.add(colorTypeSerializer);
    propertySerializers.add(doubleTypeSerializer);
    propertySerializers.add(integerTypeSerializer);
    propertySerializers.add(enumTypeSerializer);
    propertySerializers.add(assignmentsTypeSerializer);
    propertySerializers.add(variablesTypeSerializer);
    propertySerializers.add(timerSettingsTypeSerializer);
    propertySerializers.add(scriptTypeTypeSerializer);
    propertySerializers.add(scriptTypeListTypeSerializer);
    propertySerializers.add(taskTypeSerializer);
    Bpmn2OryxPropertyManager oryxPropertyManager = new Bpmn2OryxPropertyManager(propertySerializers);
    Bpmn2OryxManager oryxManager = new Bpmn2OryxManager(oryxIdMappings, oryxPropertyManager);
    oryxManager.init();
    // Marshalling factories.
    BPMNGraphObjectBuilderFactory objectBuilderFactory = new BPMNGraphObjectBuilderFactory(definitionManager, oryxManager, () -> workItemDefinitionMockRegistry);
    taskMorphDefinition = new TaskTypeMorphDefinition();
    Collection<MorphDefinition> morphDefinitions = new ArrayList<MorphDefinition>() {

        {
            add(taskMorphDefinition);
        }
    };
    BackendBindableMorphAdapter<Object> morphAdapter = new BackendBindableMorphAdapter(definitionUtils1, applicationFactoryManager, cloneManager, morphDefinitions);
    when(adapterRegistry.getMorphAdapter(eq(UserTask.class))).thenReturn(morphAdapter);
    when(adapterRegistry.getMorphAdapter(eq(NoneTask.class))).thenReturn(morphAdapter);
    when(adapterRegistry.getMorphAdapter(eq(ScriptTask.class))).thenReturn(morphAdapter);
    when(adapterRegistry.getMorphAdapter(eq(BusinessRuleTask.class))).thenReturn(morphAdapter);
    GraphIndexBuilder<?> indexBuilder = new MapIndexBuilder();
    when(rulesManager.evaluate(any(RuleSet.class), any(RuleEvaluationContext.class))).thenReturn(new DefaultRuleViolations());
    // The work item definition registry.
    WorkItemDefinitionBackendRegistry widRegistry = mock(WorkItemDefinitionBackendRegistry.class);
    when(widRegistry.getRegistry()).thenReturn(workItemDefinitionMockRegistry);
    when(widRegistry.items()).thenReturn(workItemDefinitionMockRegistry.items());
    when(widRegistry.load(any(Metadata.class))).thenReturn(widRegistry);
    doAnswer(invocationOnMock -> workItemDefinitionMockRegistry.get((String) invocationOnMock.getArguments()[0])).when(widRegistry).get(anyString());
    // The tested BPMN marshaller.
    oldMarshaller = new BPMNDiagramMarshaller(new XMLEncoderDiagramMetadataMarshaller(), objectBuilderFactory, definitionManager, indexBuilder, oryxManager, applicationFactoryManager, rulesManager, commandManager1, commandFactory1, widRegistry);
    // Graph utils.
    when(definitionManager.adapters()).thenReturn(adapterManager);
    when(adapterManager.registry()).thenReturn(adapterRegistry);
    // initApplicationFactoryManagerAlt();
    when(rulesManager.evaluate(any(RuleSet.class), any(RuleEvaluationContext.class))).thenReturn(new DefaultRuleViolations());
    DefinitionUtils definitionUtils = new DefinitionUtils(definitionManager, applicationFactoryManager);
    TestScopeModelFactory testScopeModelFactory = new TestScopeModelFactory(new BPMNDefinitionSet.BPMNDefinitionSetBuilder().build());
    // Definition manager.
    mockAdapterManager(definitionAdapter, definitionSetAdapter, propertySetAdapter, propertyAdapter);
    mockAdapterRegistry(definitionAdapter, definitionSetAdapter, propertySetAdapter, propertyAdapter);
    applicationFactoryManager = new MockApplicationFactoryManager(definitionManager, new GraphFactoryImpl(definitionManager), testScopeModelFactory, new EdgeFactoryImpl(definitionManager), new NodeFactoryImpl(definitionUtils));
    GraphCommandManagerImpl commandManager = new GraphCommandManagerImpl(null, null, null);
    GraphCommandFactory commandFactory = new GraphCommandFactory();
    // The tested BPMN marshaller.
    newMarshaller = new BPMNDirectDiagramMarshaller(new XMLEncoderDiagramMetadataMarshaller(), definitionManager, rulesManager, applicationFactoryManager, commandFactory, commandManager);
}
Also used : BackendPropertyAdapter(org.kie.workbench.common.stunner.core.backend.definition.adapter.reflect.BackendPropertyAdapter) NodeFactoryImpl(org.kie.workbench.common.stunner.core.factory.impl.NodeFactoryImpl) BackendDefinitionAdapter(org.kie.workbench.common.stunner.core.backend.definition.adapter.reflect.BackendDefinitionAdapter) ArrayList(java.util.ArrayList) GraphFactoryImpl(org.kie.workbench.common.stunner.core.factory.impl.GraphFactoryImpl) Matchers.anyString(org.mockito.Matchers.anyString) AdapterRegistry(org.kie.workbench.common.stunner.core.registry.definition.AdapterRegistry) BackendBindableMorphAdapter(org.kie.workbench.common.stunner.core.backend.definition.adapter.bind.BackendBindableMorphAdapter) XMLEncoderDiagramMetadataMarshaller(org.kie.workbench.common.stunner.core.backend.service.XMLEncoderDiagramMetadataMarshaller) AdapterManager(org.kie.workbench.common.stunner.core.definition.adapter.AdapterManager) ScriptTypeListTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.ScriptTypeListTypeSerializer) BackendPropertySetAdapter(org.kie.workbench.common.stunner.core.backend.definition.adapter.reflect.BackendPropertySetAdapter) CloneManager(org.kie.workbench.common.stunner.core.definition.clone.CloneManager) Bpmn2OryxPropertyManager(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.Bpmn2OryxPropertyManager) RuleSet(org.kie.workbench.common.stunner.core.rule.RuleSet) MorphDefinition(org.kie.workbench.common.stunner.core.definition.morph.MorphDefinition) NoneTask(org.kie.workbench.common.stunner.bpmn.definition.NoneTask) GraphCommandManager(org.kie.workbench.common.stunner.core.graph.command.GraphCommandManager) LinkedList(java.util.LinkedList) GraphCommandFactory(org.kie.workbench.common.stunner.core.graph.command.impl.GraphCommandFactory) Bpmn2OryxPropertySerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.Bpmn2OryxPropertySerializer) Graph(org.kie.workbench.common.stunner.core.graph.Graph) ScriptTask(org.kie.workbench.common.stunner.bpmn.definition.ScriptTask) BPMNGraphObjectBuilderFactory(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.builder.BPMNGraphObjectBuilderFactory) EdgeFactoryImpl(org.kie.workbench.common.stunner.core.factory.impl.EdgeFactoryImpl) EdgeFactory(org.kie.workbench.common.stunner.core.factory.graph.EdgeFactory) TaskTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.TaskTypeSerializer) Bpmn2OryxManager(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.Bpmn2OryxManager) DoubleTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.DoubleTypeSerializer) ColorTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.ColorTypeSerializer) MapIndexBuilder(org.kie.workbench.common.stunner.core.graph.processing.index.map.MapIndexBuilder) BPMNDefinitionSet(org.kie.workbench.common.stunner.bpmn.BPMNDefinitionSet) WorkItemDefinitionBackendRegistry(org.kie.workbench.common.stunner.bpmn.backend.workitem.WorkItemDefinitionBackendRegistry) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) BusinessRuleTask(org.kie.workbench.common.stunner.bpmn.definition.BusinessRuleTask) Bpmn2OryxIdMappings(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.Bpmn2OryxIdMappings) ScriptTypeTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.ScriptTypeTypeSerializer) DefinitionManager(org.kie.workbench.common.stunner.core.api.DefinitionManager) TimerSettingsTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.TimerSettingsTypeSerializer) EnumTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.EnumTypeSerializer) BackendDefinitionSetAdapter(org.kie.workbench.common.stunner.core.backend.definition.adapter.reflect.BackendDefinitionSetAdapter) StringTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.StringTypeSerializer) DiagramImpl(org.kie.workbench.common.stunner.core.diagram.DiagramImpl) UserTask(org.kie.workbench.common.stunner.bpmn.definition.UserTask) GraphCommandManagerImpl(org.kie.workbench.common.stunner.core.graph.command.GraphCommandManagerImpl) TestScopeModelFactory(org.kie.workbench.common.stunner.backend.definition.factory.TestScopeModelFactory) IntegerTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.IntegerTypeSerializer) AssignmentsTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.AssignmentsTypeSerializer) VariablesTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.VariablesTypeSerializer) DefinitionUtils(org.kie.workbench.common.stunner.core.util.DefinitionUtils) BPMNDirectDiagramMarshaller(org.kie.workbench.common.stunner.bpmn.backend.BPMNDirectDiagramMarshaller) BPMNDiagramMarshaller(org.kie.workbench.common.stunner.bpmn.backend.BPMNDiagramMarshaller) RuleManager(org.kie.workbench.common.stunner.core.rule.RuleManager) BooleanTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.BooleanTypeSerializer) RuleEvaluationContext(org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) Before(org.junit.Before)

Example 2 with AdapterManager

use of org.kie.workbench.common.stunner.core.definition.adapter.AdapterManager in project kie-wb-common by kiegroup.

the class DecisionServiceMoveDividerControlTest method testRegisterDecisionServiceElementDragEnd.

@Test
@SuppressWarnings("unchecked")
public void testRegisterDecisionServiceElementDragEnd() {
    final DefinitionManager definitionManager = mock(DefinitionManager.class);
    final AdapterManager adapterManager = mock(AdapterManager.class);
    final AdapterRegistry adapterRegistry = mock(AdapterRegistry.class);
    final PropertyAdapter<Object, Object> propertyAdapter = mock(PropertyAdapter.class);
    final DefinitionAdapter<Object> definitionAdapter = mock(DefinitionAdapter.class);
    final DecisionServiceDividerLineY dividerLineY = new DecisionServiceDividerLineY();
    final Optional dividerYProperty = Optional.of(dividerLineY);
    final UpdateElementPropertyCommand updateElementPropertyCommand = mock(UpdateElementPropertyCommand.class);
    final DecisionService decisionService = mock(DecisionService.class);
    final DecisionServiceSVGShapeView decisionServiceShapeView = mock(DecisionServiceSVGShapeView.class);
    final DragEvent dragEvent = mock(DragEvent.class);
    when(canvasHandler.getDefinitionManager()).thenReturn(definitionManager);
    when(definitionManager.adapters()).thenReturn(adapterManager);
    when(adapterManager.registry()).thenReturn(adapterRegistry);
    when(adapterManager.forProperty()).thenReturn(propertyAdapter);
    when(adapterRegistry.getDefinitionAdapter(Mockito.<Class>any())).thenReturn(definitionAdapter);
    when(definitionAdapter.getProperty(decisionService, DIVIDER_Y_PROPERTY_ID)).thenReturn(dividerYProperty);
    when(propertyAdapter.getId(dividerLineY)).thenReturn(DIVIDER_Y_PROPERTY_ID);
    when(canvasCommandFactory.updatePropertyValue(eq(element), eq(DIVIDER_Y_PROPERTY_ID), Mockito.<Object>any())).thenReturn(updateElementPropertyCommand);
    when(definition.getDefinition()).thenReturn(decisionService);
    when(shape.getShapeView()).thenReturn(decisionServiceShapeView);
    control.register(element);
    verify(decisionServiceShapeView).addDividerDragHandler(dragHandlerCaptor.capture());
    when(decisionServiceShapeView.getDividerLineY()).thenReturn(DIVIDER_Y);
    final DragHandler dragHandler = dragHandlerCaptor.getValue();
    dragHandler.end(dragEvent);
    verify(canvasCommandFactory).updatePropertyValue(eq(element), eq(DIVIDER_Y_PROPERTY_ID), eq(DIVIDER_Y));
    verify(commandManager).execute(eq(canvasHandler), eq(updateElementPropertyCommand));
}
Also used : Optional(java.util.Optional) DragHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.DragHandler) AdapterRegistry(org.kie.workbench.common.stunner.core.registry.definition.AdapterRegistry) UpdateElementPropertyCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPropertyCommand) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) DragEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.DragEvent) DecisionServiceDividerLineY(org.kie.workbench.common.dmn.api.property.dmn.DecisionServiceDividerLineY) DefinitionManager(org.kie.workbench.common.stunner.core.api.DefinitionManager) AdapterManager(org.kie.workbench.common.stunner.core.definition.adapter.AdapterManager) DecisionServiceSVGShapeView(org.kie.workbench.common.dmn.client.shape.view.decisionservice.DecisionServiceSVGShapeView) Test(org.junit.Test)

Example 3 with AdapterManager

use of org.kie.workbench.common.stunner.core.definition.adapter.AdapterManager in project kie-wb-common by kiegroup.

the class DecisionNavigatorBaseItemFactoryTest method testGetTitle.

@Test
public void testGetTitle() {
    final DefinitionManager definitionManager = mock(DefinitionManager.class);
    final AdapterManager adapters = mock(AdapterManager.class);
    final View content = mock(View.class);
    final Object definition = mock(Object.class);
    final String expectedTitle = "title";
    when(definitionUtils.getDefinitionManager()).thenReturn(definitionManager);
    when(definitionManager.adapters()).thenReturn(adapters);
    when(adapters.forDefinition()).thenReturn(objectDefinitionAdapter);
    when(element.getContent()).thenReturn(content);
    when(content.getDefinition()).thenReturn(definition);
    when(objectDefinitionAdapter.getTitle(definition)).thenReturn(expectedTitle);
    final String actualTitle = factory.getTitle(element);
    assertEquals(expectedTitle, actualTitle);
}
Also used : DefinitionManager(org.kie.workbench.common.stunner.core.api.DefinitionManager) AdapterManager(org.kie.workbench.common.stunner.core.definition.adapter.AdapterManager) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Test(org.junit.Test)

Example 4 with AdapterManager

use of org.kie.workbench.common.stunner.core.definition.adapter.AdapterManager in project kie-wb-common by kiegroup.

the class StunnerTestingMockAPI method initInstances.

protected void initInstances() {
    definitionManager = mock(DefinitionManager.class);
    definitionSetRegistry = mock(TypeDefinitionSetRegistry.class);
    adapterManager = mock(AdapterManager.class);
    adapterRegistry = mock(AdapterRegistry.class);
    ruleManager = mock(RuleManager.class);
    initFactory();
    definitionUtils = spy(new DefinitionUtils(definitionManager, new DefaultDefinitionsCacheRegistry(factoryManager, adapterManager)));
    initAdapters();
}
Also used : DefinitionManager(org.kie.workbench.common.stunner.core.api.DefinitionManager) TypeDefinitionSetRegistry(org.kie.workbench.common.stunner.core.registry.definition.TypeDefinitionSetRegistry) AdapterManager(org.kie.workbench.common.stunner.core.definition.adapter.AdapterManager) DefinitionUtils(org.kie.workbench.common.stunner.core.util.DefinitionUtils) RuleManager(org.kie.workbench.common.stunner.core.rule.RuleManager) AdapterRegistry(org.kie.workbench.common.stunner.core.registry.definition.AdapterRegistry) DefaultDefinitionsCacheRegistry(org.kie.workbench.common.stunner.core.registry.impl.DefaultDefinitionsCacheRegistry)

Example 5 with AdapterManager

use of org.kie.workbench.common.stunner.core.definition.adapter.AdapterManager 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)

Aggregations

AdapterManager (org.kie.workbench.common.stunner.core.definition.adapter.AdapterManager)9 DefinitionManager (org.kie.workbench.common.stunner.core.api.DefinitionManager)7 AdapterRegistry (org.kie.workbench.common.stunner.core.registry.definition.AdapterRegistry)6 ArrayList (java.util.ArrayList)3 Before (org.junit.Before)3 Test (org.junit.Test)3 NoneTask (org.kie.workbench.common.stunner.bpmn.definition.NoneTask)3 UserTask (org.kie.workbench.common.stunner.bpmn.definition.UserTask)3 DefinitionUtils (org.kie.workbench.common.stunner.core.util.DefinitionUtils)3 LinkedList (java.util.LinkedList)2 TestScopeModelFactory (org.kie.workbench.common.stunner.backend.definition.factory.TestScopeModelFactory)2 BPMNDefinitionSet (org.kie.workbench.common.stunner.bpmn.BPMNDefinitionSet)2 BPMNDiagramMarshaller (org.kie.workbench.common.stunner.bpmn.backend.BPMNDiagramMarshaller)2 BPMNDirectDiagramMarshaller (org.kie.workbench.common.stunner.bpmn.backend.BPMNDirectDiagramMarshaller)2 BPMNGraphObjectBuilderFactory (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.builder.BPMNGraphObjectBuilderFactory)2 Bpmn2OryxIdMappings (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.Bpmn2OryxIdMappings)2 Bpmn2OryxManager (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.Bpmn2OryxManager)2 AssignmentsTypeSerializer (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.AssignmentsTypeSerializer)2 BooleanTypeSerializer (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.BooleanTypeSerializer)2 DefinitionAdapter (org.kie.workbench.common.stunner.core.definition.adapter.DefinitionAdapter)2