Search in sources :

Example 1 with TestDiagramDescriptionBuilder

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

the class RenameDiagramEventHandlerTests method testRenameRepresentation.

@Test
public void testRenameRepresentation() {
    String projectId = UUID.randomUUID().toString();
    String representationId = UUID.randomUUID().toString();
    UUID targetObjectId = UUID.randomUUID();
    DiagramDescription diagramDescription = new TestDiagramDescriptionBuilder().getDiagramDescription(UUID.randomUUID(), List.of(), List.of(), List.of());
    // @formatter:off
    Diagram diagram = Diagram.newDiagram(representationId).label(OLD_LABEL).descriptionId(diagramDescription.getId()).targetObjectId(targetObjectId.toString()).size(Size.of(10, 10)).position(Position.at(0, 0)).nodes(Collections.emptyList()).edges(Collections.emptyList()).build();
    // @formatter:on
    IRepresentationSearchService representationSearchService = new IRepresentationSearchService() {

        @Override
        public <T extends IRepresentation> Optional<T> findById(IEditingContext editingContext, String representationId, Class<T> representationClass) {
            return Optional.of(diagram).map(representationClass::cast);
        }
    };
    RenameDiagramEventHandler handler = new RenameDiagramEventHandler(representationSearchService, new IRepresentationPersistenceService.NoOp(), new ICollaborativeDiagramMessageService.NoOp(), new SimpleMeterRegistry());
    var input = new RenameDiagramInput(UUID.randomUUID(), projectId, representationId, NEW_LABEL);
    assertThat(handler.canHandle(input)).isTrue();
    Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
    One<IPayload> payloadSink = Sinks.one();
    handler.handle(payloadSink, changeDescriptionSink, new IEditingContext.NoOp(), new IDiagramContext.NoOp(), input);
    ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
    assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.REPRESENTATION_RENAMING);
    IPayload payload = payloadSink.asMono().block();
    assertThat(payload).isInstanceOf(RenameRepresentationSuccessPayload.class);
    assertThat(((RenameRepresentationSuccessPayload) payload).getRepresentation().getLabel()).isEqualTo(NEW_LABEL);
}
Also used : TestDiagramDescriptionBuilder(org.eclipse.sirius.components.diagrams.tests.TestDiagramDescriptionBuilder) IPayload(org.eclipse.sirius.components.core.api.IPayload) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) ICollaborativeDiagramMessageService(org.eclipse.sirius.components.collaborative.diagrams.messages.ICollaborativeDiagramMessageService) UUID(java.util.UUID) IRepresentationPersistenceService(org.eclipse.sirius.components.collaborative.api.IRepresentationPersistenceService) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) IRepresentationSearchService(org.eclipse.sirius.components.collaborative.api.IRepresentationSearchService) DiagramDescription(org.eclipse.sirius.components.diagrams.description.DiagramDescription) IRepresentation(org.eclipse.sirius.components.representations.IRepresentation) Diagram(org.eclipse.sirius.components.diagrams.Diagram) RenameDiagramInput(org.eclipse.sirius.components.collaborative.diagrams.dto.RenameDiagramInput) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) IDiagramContext(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext) Test(org.junit.jupiter.api.Test)

Aggregations

SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)1 UUID (java.util.UUID)1 ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)1 IRepresentationPersistenceService (org.eclipse.sirius.components.collaborative.api.IRepresentationPersistenceService)1 IRepresentationSearchService (org.eclipse.sirius.components.collaborative.api.IRepresentationSearchService)1 IDiagramContext (org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext)1 RenameDiagramInput (org.eclipse.sirius.components.collaborative.diagrams.dto.RenameDiagramInput)1 ICollaborativeDiagramMessageService (org.eclipse.sirius.components.collaborative.diagrams.messages.ICollaborativeDiagramMessageService)1 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)1 IPayload (org.eclipse.sirius.components.core.api.IPayload)1 Diagram (org.eclipse.sirius.components.diagrams.Diagram)1 DiagramDescription (org.eclipse.sirius.components.diagrams.description.DiagramDescription)1 TestDiagramDescriptionBuilder (org.eclipse.sirius.components.diagrams.tests.TestDiagramDescriptionBuilder)1 IRepresentation (org.eclipse.sirius.components.representations.IRepresentation)1 Test (org.junit.jupiter.api.Test)1