use of org.kie.workbench.common.stunner.core.diagram.Metadata in project kie-wb-common by kiegroup.
the class ClientFactoryServicesTest method testNewDiagramLocal.
@Test
@SuppressWarnings("unchecked")
public void testNewDiagramLocal() {
String id = "id1";
String name = "name1";
ServiceCallback<Diagram> callback = mock(ServiceCallback.class);
Diagram def = mock(Diagram.class);
when(clientFactoryManager.newDiagram(eq(name), eq(id), any(Metadata.class))).thenReturn(def);
tested.newDiagram(name, id, metadata, callback);
verify(callback, times(1)).onSuccess(eq(def));
verify(clientFactoryManager, times(1)).newDiagram(eq(name), eq(id), eq(metadata));
verify(clientFactoryManager, times(0)).newDiagram(anyString(), any(Class.class), any(Metadata.class));
verify(factoryService, times(0)).newDiagram(anyString(), anyString(), any(Metadata.class));
verify(factoryService, times(0)).newDiagram(anyString(), any(Class.class), any(Metadata.class));
}
use of org.kie.workbench.common.stunner.core.diagram.Metadata in project kie-wb-common by kiegroup.
the class ClientFactoryServicesTest method testNewDiagramByTpeRemote.
@Test
@SuppressWarnings("unchecked")
public void testNewDiagramByTpeRemote() {
String name = "name1";
ServiceCallback<Diagram> callback = mock(ServiceCallback.class);
Diagram def = mock(Diagram.class);
when(clientFactoryManager.newDiagram(eq(name), eq(MyType.class), any(Metadata.class))).thenReturn(null);
when(factoryService.newDiagram(eq(name), eq(MyType.class), any(Metadata.class))).thenReturn(def);
tested.newDiagram(name, MyType.class, metadata, callback);
verify(callback, times(1)).onSuccess(eq(def));
verify(clientFactoryManager, times(0)).newDiagram(anyString(), anyString(), any(Metadata.class));
verify(clientFactoryManager, times(1)).newDiagram(anyString(), eq(MyType.class), any(Metadata.class));
verify(factoryService, times(0)).newDiagram(anyString(), anyString(), any(Metadata.class));
verify(factoryService, times(1)).newDiagram(anyString(), any(Class.class), any(Metadata.class));
}
use of org.kie.workbench.common.stunner.core.diagram.Metadata in project kie-wb-common by kiegroup.
the class WorkItemDefinitionMetadataRegistryTest method testLoad.
@Test
@SuppressWarnings("unchecked")
public void testLoad() {
Path path = mock(Path.class);
Metadata metadata = mock(Metadata.class);
Command callback = mock(Command.class);
when(metadata.getRoot()).thenReturn(path);
tested.load(metadata, callback);
verify(workItemsByPathSupplier, times(1)).accept(eq(path), any(Consumer.class));
}
use of org.kie.workbench.common.stunner.core.diagram.Metadata in project kie-wb-common by kiegroup.
the class SessionDiagramEditorScreen method newDiagram.
private void newDiagram(final String uuid, final String title, final String definitionSetId, final String shapeSetId, final Command callback) {
BusyPopup.showMessage("Loading");
final Metadata metadata = buildMetadata(definitionSetId, shapeSetId, title);
clientFactoryServices.newDiagram(uuid, definitionSetId, metadata, new ServiceCallback<Diagram>() {
@Override
public void onSuccess(final Diagram diagram) {
final Metadata metadata = diagram.getMetadata();
metadata.setShapeSetId(shapeSetId);
metadata.setTitle(title);
openDiagram(diagram, callback);
}
@Override
public void onError(final ClientRuntimeError error) {
showError(error);
callback.execute();
}
});
}
use of org.kie.workbench.common.stunner.core.diagram.Metadata 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) throws Throwable {
ServiceCallback<Node<View<Object>, Edge>> callback = (ServiceCallback<Node<View<Object>, Edge>>) (invocationOnMock.getArguments()[2]);
view = new ViewImpl<>(new Object(), new BoundsImpl(new BoundImpl(0.0, 0.0), new BoundImpl(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("Object");
when(rulesAdapter.getRuleSet(any())).thenReturn(mock(RuleSet.class));
when(adapters.forDefinition()).thenReturn(definitionAdapter);
when(adapters.forRules()).thenReturn(rulesAdapter);
when(clientDefinitionManager.adapters()).thenReturn(adapters);
when(clientDefinitionManager.definitionSets()).thenReturn(mock(TypeDefinitionSetRegistry.class));
when(canvasCommandFactory.addNode(any(Node.class), anyString())).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(anyString())).thenReturn(shapeSet);
when(shapeManager.getDefaultShapeSet(anyString())).thenReturn(shapeSet);
tested = new ObserverBuilderControl(clientDefinitionManager, clientFactoryServices, graphUtils, ruleManager, canvasCommandFactory, graphBoundsIndexer, canvasLayoutUtils, mock(Event.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(graphContent.getBounds()).thenReturn(new BoundsImpl(new BoundImpl(10d, 10d), new BoundImpl(100d, 100d)));
when(graph.getContent()).thenReturn(graphContent);
when(index.getGraph()).thenReturn(graph);
when(graphIndexBuilder.build(any(Graph.class))).thenReturn(index);
canvasHandler = new CanvasHandlerImpl(clientDefinitionManager, canvasCommandFactory, clientFactoryServices, ruleManager, graphUtils, graphIndexBuilder, shapeManager, mock(TextPropertyProviderFactory.class), mock(Event.class), null, null, null);
canvasHandler.handle(mock(AbstractCanvas.class));
canvasHandler.draw(diagram, mock(ParameterizedCommand.class));
when(diagram.getGraph()).thenReturn(graph);
when(graph.nodes()).thenReturn(Collections.emptyList());
CanvasCommandManager commandManager = mock(CanvasCommandManager.class);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
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);
tested.enable(canvasHandler);
tested.setCommandManagerProvider(commandManagerProvider);
}
Aggregations