Search in sources :

Example 1 with TestDiagramBuilder

use of org.eclipse.sirius.components.diagrams.tests.TestDiagramBuilder in project sirius-components by eclipse-sirius.

the class ChildModelOperationHandlerTests method testChildModelOperationWithoutSelection.

@Test
public void testChildModelOperationWithoutSelection() {
    CreateView createView = ToolFactory.eINSTANCE.createCreateView();
    // $NON-NLS-1$
    createView.setContainerViewExpression("");
    // $NON-NLS-1$
    createView.setVariableName("");
    createView.setMapping(DescriptionFactory.eINSTANCE.createNodeMapping());
    IObjectService objectService = new IObjectService.NoOp() {

        @Override
        public String getId(Object object) {
            // $NON-NLS-1$
            return "";
        }
    };
    IIdentifierProvider identifierProvider = new IIdentifierProvider.NoOp() {

        @Override
        public String getIdentifier(Object element) {
            // $NON-NLS-1$
            return UUID.nameUUIDFromBytes("node".getBytes()).toString();
        }
    };
    AQLInterpreter interpreter = new AQLInterpreter(List.of(), List.of()) {

        @Override
        public Result evaluateExpression(Map<String, Object> variables, String expressionBody) {
            // $NON-NLS-1$
            Object value = new TestDiagramBuilder().getDiagram("diagramId");
            return new Result(Optional.of(value), Status.OK);
        }
    };
    IStatus status = new ChildModelOperationHandler(List.of()).handle(objectService, new IRepresentationMetadataSearchService.NoOp(), identifierProvider, interpreter, Map.of(), List.of(createView));
    assertThat(status).isInstanceOf(Success.class);
    Success success = (Success) status;
    Object selectionParameter = success.getParameters().get(Success.NEW_SELECTION);
    assertThat(selectionParameter).isNull();
}
Also used : IIdentifierProvider(org.eclipse.sirius.components.compatibility.api.IIdentifierProvider) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) IStatus(org.eclipse.sirius.components.representations.IStatus) ChildModelOperationHandler(org.eclipse.sirius.components.emf.compatibility.modeloperations.ChildModelOperationHandler) CreateView(org.eclipse.sirius.diagram.description.tool.CreateView) Success(org.eclipse.sirius.components.representations.Success) Result(org.eclipse.sirius.components.interpreter.Result) TestDiagramBuilder(org.eclipse.sirius.components.diagrams.tests.TestDiagramBuilder) IRepresentationMetadataSearchService(org.eclipse.sirius.components.core.api.IRepresentationMetadataSearchService) IObjectService(org.eclipse.sirius.components.core.api.IObjectService) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 2 with TestDiagramBuilder

use of org.eclipse.sirius.components.diagrams.tests.TestDiagramBuilder in project sirius-components by eclipse-sirius.

the class DeleteFromDiagramEventHandlerTests method testEdgeSemanticDeletionFromDiagram.

@Test
public void testEdgeSemanticDeletionFromDiagram() {
    var handler = new DeleteFromDiagramEventHandler(this.objectService, this.diagramQueryService, this.diagramDescriptionService, this.representationDescriptionSearchService, new ICollaborativeDiagramMessageService.NoOp(), new SimpleMeterRegistry());
    var nodeIds = List.<String>of();
    var edgeIds = List.<String>of(EDGE_ID);
    // $NON-NLS-1$ //$NON-NLS-2$
    var input = new DeleteFromDiagramInput(UUID.randomUUID(), "editingContextId", "representationId", nodeIds, edgeIds, DeletionPolicy.SEMANTIC);
    One<IPayload> payloadSink = Sinks.one();
    Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
    assertThat(handler.canHandle(input)).isTrue();
    IDiagramContext diagramContext = new DiagramContext(new TestDiagramBuilder().getDiagram(UUID.randomUUID().toString()));
    handler.handle(payloadSink, changeDescriptionSink, new IEditingContext.NoOp(), diagramContext, input);
    ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
    assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.SEMANTIC_CHANGE);
    IPayload payload = payloadSink.asMono().block();
    assertThat(payload).isInstanceOf(DeleteFromDiagramSuccessPayload.class);
}
Also used : SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) IPayload(org.eclipse.sirius.components.core.api.IPayload) DeleteFromDiagramInput(org.eclipse.sirius.components.collaborative.diagrams.dto.DeleteFromDiagramInput) DiagramContext(org.eclipse.sirius.components.collaborative.diagrams.DiagramContext) IDiagramContext(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) TestDiagramBuilder(org.eclipse.sirius.components.diagrams.tests.TestDiagramBuilder) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) ICollaborativeDiagramMessageService(org.eclipse.sirius.components.collaborative.diagrams.messages.ICollaborativeDiagramMessageService) IDiagramContext(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext) Test(org.junit.jupiter.api.Test)

Example 3 with TestDiagramBuilder

use of org.eclipse.sirius.components.diagrams.tests.TestDiagramBuilder in project sirius-components by eclipse-sirius.

the class DeleteFromDiagramEventHandlerTests method testNodeSemanticDeletionFromDiagram.

@Test
public void testNodeSemanticDeletionFromDiagram() {
    var handler = new DeleteFromDiagramEventHandler(this.objectService, this.diagramQueryService, this.diagramDescriptionService, this.representationDescriptionSearchService, new ICollaborativeDiagramMessageService.NoOp(), new SimpleMeterRegistry());
    var nodeIds = List.of(NODE_ID);
    var edgeIds = List.<String>of();
    // $NON-NLS-1$ //$NON-NLS-2$
    var input = new DeleteFromDiagramInput(UUID.randomUUID(), "editingContextId", "representationId", nodeIds, edgeIds, DeletionPolicy.SEMANTIC);
    One<IPayload> payloadSink = Sinks.one();
    Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
    assertThat(handler.canHandle(input)).isTrue();
    IDiagramContext diagramContext = new DiagramContext(new TestDiagramBuilder().getDiagram(UUID.randomUUID().toString()));
    handler.handle(payloadSink, changeDescriptionSink, new IEditingContext.NoOp(), diagramContext, input);
    ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
    assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.SEMANTIC_CHANGE);
    IPayload payload = payloadSink.asMono().block();
    assertThat(payload).isInstanceOf(DeleteFromDiagramSuccessPayload.class);
}
Also used : SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) IPayload(org.eclipse.sirius.components.core.api.IPayload) DeleteFromDiagramInput(org.eclipse.sirius.components.collaborative.diagrams.dto.DeleteFromDiagramInput) DiagramContext(org.eclipse.sirius.components.collaborative.diagrams.DiagramContext) IDiagramContext(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) TestDiagramBuilder(org.eclipse.sirius.components.diagrams.tests.TestDiagramBuilder) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) ICollaborativeDiagramMessageService(org.eclipse.sirius.components.collaborative.diagrams.messages.ICollaborativeDiagramMessageService) IDiagramContext(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext) Test(org.junit.jupiter.api.Test)

Example 4 with TestDiagramBuilder

use of org.eclipse.sirius.components.diagrams.tests.TestDiagramBuilder in project sirius-components by eclipse-sirius.

the class NodeSizeProviderTests method createNodeLayoutData.

private NodeLayoutData createNodeLayoutData(Size size) {
    TestDiagramBuilder testDiagramBuilder = new TestDiagramBuilder();
    NodeLayoutData nodeLayoutData = new NodeLayoutData();
    nodeLayoutData.setId(UUID.randomUUID().toString());
    nodeLayoutData.setSize(size);
    nodeLayoutData.setNodeType(NodeType.NODE_RECTANGLE);
    nodeLayoutData.setStyle(testDiagramBuilder.getRectangularNodeStyle());
    return nodeLayoutData;
}
Also used : TestDiagramBuilder(org.eclipse.sirius.components.diagrams.tests.TestDiagramBuilder) NodeLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.NodeLayoutData)

Example 5 with TestDiagramBuilder

use of org.eclipse.sirius.components.diagrams.tests.TestDiagramBuilder in project sirius-components by eclipse-sirius.

the class DiagramConverterTests method testDiagramOneNodeAndOneBorderNode.

@Test
public void testDiagramOneNodeAndOneBorderNode() {
    ImageSizeProvider imageSizeProvider = new ImageSizeProvider();
    ELKDiagramConverter diagramConverter = new ELKDiagramConverter(this.textBoundsService, imageSizeProvider);
    // @formatter:off
    TestDiagramBuilder diagramBuilder = new TestDiagramBuilder();
    Node borderNode = Node.newNode(diagramBuilder.getNode(FIRST_NODE_ID)).style(diagramBuilder.getRectangularNodeStyle()).build();
    Node node = Node.newNode(diagramBuilder.getNode(SECOND_NODE_ID)).style(diagramBuilder.getImageNodeStyle()).borderNodes(List.of(borderNode)).build();
    Diagram diagram = Diagram.newDiagram(diagramBuilder.getDiagram(DIAGRAM_ID)).nodes(List.of(node)).build();
    // @formatter:on
    ELKConvertedDiagram convertedDiagram = diagramConverter.convert(diagram);
    ElkNode elkDiagram = convertedDiagram.getElkDiagram();
    assertThat(elkDiagram.getChildren().size()).isEqualTo(1);
    ElkNode elkNode = elkDiagram.getChildren().get(0);
    assertThat(elkNode.getPorts().size()).isEqualTo(1);
    ElkPort elkPort = elkNode.getPorts().get(0);
    assertThat(elkPort.getIdentifier()).isEqualTo(borderNode.getId().toString());
    imageSizeProvider.dispose();
}
Also used : ELKDiagramConverter(org.eclipse.sirius.components.diagrams.layout.ELKDiagramConverter) ELKConvertedDiagram(org.eclipse.sirius.components.diagrams.layout.ELKConvertedDiagram) ElkNode(org.eclipse.elk.graph.ElkNode) TestDiagramBuilder(org.eclipse.sirius.components.diagrams.tests.TestDiagramBuilder) ElkPort(org.eclipse.elk.graph.ElkPort) Node(org.eclipse.sirius.components.diagrams.Node) ElkNode(org.eclipse.elk.graph.ElkNode) ImageSizeProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.ImageSizeProvider) ELKConvertedDiagram(org.eclipse.sirius.components.diagrams.layout.ELKConvertedDiagram) Diagram(org.eclipse.sirius.components.diagrams.Diagram) Test(org.junit.jupiter.api.Test)

Aggregations

TestDiagramBuilder (org.eclipse.sirius.components.diagrams.tests.TestDiagramBuilder)12 Test (org.junit.jupiter.api.Test)11 Diagram (org.eclipse.sirius.components.diagrams.Diagram)7 ElkNode (org.eclipse.elk.graph.ElkNode)6 Node (org.eclipse.sirius.components.diagrams.Node)6 ELKConvertedDiagram (org.eclipse.sirius.components.diagrams.layout.ELKConvertedDiagram)6 ELKDiagramConverter (org.eclipse.sirius.components.diagrams.layout.ELKDiagramConverter)5 ImageSizeProvider (org.eclipse.sirius.components.diagrams.layout.incremental.provider.ImageSizeProvider)5 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)4 ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)4 ICollaborativeDiagramMessageService (org.eclipse.sirius.components.collaborative.diagrams.messages.ICollaborativeDiagramMessageService)4 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)4 IPayload (org.eclipse.sirius.components.core.api.IPayload)4 ElkEdge (org.eclipse.elk.graph.ElkEdge)3 DiagramContext (org.eclipse.sirius.components.collaborative.diagrams.DiagramContext)3 IDiagramContext (org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext)3 Edge (org.eclipse.sirius.components.diagrams.Edge)3 ElkGraphElement (org.eclipse.elk.graph.ElkGraphElement)2 ElkLabel (org.eclipse.elk.graph.ElkLabel)2 DeleteFromDiagramInput (org.eclipse.sirius.components.collaborative.diagrams.dto.DeleteFromDiagramInput)2