Search in sources :

Example 1 with IRepresentationDescriptionSearchService

use of org.eclipse.sirius.components.core.api.IRepresentationDescriptionSearchService in project sirius-components by eclipse-sirius.

the class CreateDiagramEventHandlerTests method testDiagramCreation.

@Test
public void testDiagramCreation() {
    IRepresentationDescriptionSearchService representationDescriptionSearchService = new IRepresentationDescriptionSearchService.NoOp() {

        @Override
        public Optional<IRepresentationDescription> findById(IEditingContext editingContext, UUID id) {
            // @formatter:off
            DiagramDescription diagramDescription = DiagramDescription.newDiagramDescription(UUID.randomUUID()).label(// $NON-NLS-1$
            "label").canCreatePredicate(variableManager -> Boolean.TRUE).edgeDescriptions(new ArrayList<>()).labelProvider(// $NON-NLS-1$
            variableManager -> "label").toolSections(List.of()).nodeDescriptions(new ArrayList<>()).targetObjectIdProvider(// $NON-NLS-1$
            variableManager -> "targetObjectId").dropHandler(// $NON-NLS-1$
            variableManager -> new Failure("")).build();
            return Optional.of(diagramDescription);
        }
    };
    AtomicBoolean hasBeenCalled = new AtomicBoolean();
    IDiagramCreationService diagramCreationService = new IDiagramCreationService.NoOp() {

        @Override
        public Diagram create(String label, Object targetObject, DiagramDescription diagramDescription, IEditingContext editingContext) {
            hasBeenCalled.set(true);
            return new TestDiagramBuilder().getDiagram(UUID.randomUUID().toString());
        }
    };
    IObjectService objectService = new IObjectService.NoOp() {

        @Override
        public Optional<Object> getObject(IEditingContext editingContext, String objectId) {
            return Optional.of(new Object());
        }
    };
    CreateDiagramEventHandler handler = new CreateDiagramEventHandler(representationDescriptionSearchService, new IRepresentationPersistenceService.NoOp(), diagramCreationService, objectService, new ICollaborativeDiagramMessageService.NoOp(), new SimpleMeterRegistry());
    // $NON-NLS-1$//$NON-NLS-2$
    var input = new CreateRepresentationInput(UUID.randomUUID(), UUID.randomUUID().toString(), UUID.randomUUID(), "objectId", "representationName");
    assertThat(handler.canHandle(null, input)).isTrue();
    Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
    One<IPayload> payloadSink = Sinks.one();
    IEditingContext editingContext = () -> UUID.randomUUID().toString();
    handler.handle(payloadSink, changeDescriptionSink, editingContext, input);
    assertThat(hasBeenCalled.get()).isTrue();
    ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
    assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.REPRESENTATION_CREATION);
    IPayload payload = payloadSink.asMono().block();
    assertThat(payload).isInstanceOf(CreateRepresentationSuccessPayload.class);
}
Also used : Sinks(reactor.core.publisher.Sinks) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) TestDiagramBuilder(org.eclipse.sirius.components.diagrams.tests.TestDiagramBuilder) IRepresentationPersistenceService(org.eclipse.sirius.components.collaborative.api.IRepresentationPersistenceService) IObjectService(org.eclipse.sirius.components.core.api.IObjectService) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) One(reactor.core.publisher.Sinks.One) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DiagramDescription(org.eclipse.sirius.components.diagrams.description.DiagramDescription) CreateRepresentationSuccessPayload(org.eclipse.sirius.components.collaborative.dto.CreateRepresentationSuccessPayload) ArrayList(java.util.ArrayList) Diagram(org.eclipse.sirius.components.diagrams.Diagram) ICollaborativeDiagramMessageService(org.eclipse.sirius.components.collaborative.diagrams.messages.ICollaborativeDiagramMessageService) ChangeKind(org.eclipse.sirius.components.collaborative.api.ChangeKind) Failure(org.eclipse.sirius.components.representations.Failure) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) IRepresentationDescriptionSearchService(org.eclipse.sirius.components.core.api.IRepresentationDescriptionSearchService) UUID(java.util.UUID) IDiagramCreationService(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramCreationService) Test(org.junit.jupiter.api.Test) List(java.util.List) IPayload(org.eclipse.sirius.components.core.api.IPayload) CreateRepresentationInput(org.eclipse.sirius.components.collaborative.dto.CreateRepresentationInput) Many(reactor.core.publisher.Sinks.Many) Optional(java.util.Optional) IRepresentationDescription(org.eclipse.sirius.components.representations.IRepresentationDescription) ArrayList(java.util.ArrayList) IRepresentationDescriptionSearchService(org.eclipse.sirius.components.core.api.IRepresentationDescriptionSearchService) IRepresentationDescription(org.eclipse.sirius.components.representations.IRepresentationDescription) IPayload(org.eclipse.sirius.components.core.api.IPayload) 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) UUID(java.util.UUID) Failure(org.eclipse.sirius.components.representations.Failure) IRepresentationPersistenceService(org.eclipse.sirius.components.collaborative.api.IRepresentationPersistenceService) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) DiagramDescription(org.eclipse.sirius.components.diagrams.description.DiagramDescription) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CreateRepresentationInput(org.eclipse.sirius.components.collaborative.dto.CreateRepresentationInput) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) IObjectService(org.eclipse.sirius.components.core.api.IObjectService) IDiagramCreationService(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramCreationService) Test(org.junit.jupiter.api.Test)

Example 2 with IRepresentationDescriptionSearchService

use of org.eclipse.sirius.components.core.api.IRepresentationDescriptionSearchService in project sirius-components by eclipse-sirius.

the class DynamicDiagramsTests method render.

private Diagram render(DiagramDescription diagramDescription, Object target) {
    // Wrap into a View, as expected by ViewConverter
    View view = ViewFactory.eINSTANCE.createView();
    view.getDescriptions().add(diagramDescription);
    var viewConverter = new ViewConverter(new IObjectService.NoOp(), new IEditService.NoOp(), List.of());
    List<IRepresentationDescription> conversionResult = viewConverter.convert(view, List.of(EcorePackage.eINSTANCE));
    assertThat(conversionResult).hasSize(1);
    assertThat(conversionResult.get(0)).isInstanceOf(org.eclipse.sirius.components.diagrams.description.DiagramDescription.class);
    org.eclipse.sirius.components.diagrams.description.DiagramDescription convertedDiagramDescription = (org.eclipse.sirius.components.diagrams.description.DiagramDescription) conversionResult.get(0);
    IRepresentationDescriptionSearchService representationDescriptionSearchService = new IRepresentationDescriptionSearchService.NoOp() {

        @Override
        public Optional<IRepresentationDescription> findById(IEditingContext editingContext, UUID representationDescriptionId) {
            return Optional.of(convertedDiagramDescription);
        }
    };
    IObjectService objectService = new IObjectService.NoOp();
    ILayoutService layoutService = new ILayoutService.NoOp();
    MeterRegistry meterRegistry = new SimpleMeterRegistry();
    var diagramCreationService = new DiagramCreationService(representationDescriptionSearchService, new IRepresentationPersistenceService.NoOp(), objectService, layoutService, meterRegistry);
    IEditingContext editinContext = new IEditingContext.NoOp();
    // $NON-NLS-1$
    return diagramCreationService.create("Test Diagram", target, convertedDiagramDescription, editinContext);
}
Also used : IRepresentationDescriptionSearchService(org.eclipse.sirius.components.core.api.IRepresentationDescriptionSearchService) IRepresentationDescription(org.eclipse.sirius.components.representations.IRepresentationDescription) DiagramCreationService(org.eclipse.sirius.components.collaborative.diagrams.DiagramCreationService) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) IEditService(org.eclipse.sirius.components.core.api.IEditService) ILayoutService(org.eclipse.sirius.components.diagrams.layout.api.ILayoutService) UUID(java.util.UUID) IRepresentationPersistenceService(org.eclipse.sirius.components.collaborative.api.IRepresentationPersistenceService) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) View(org.eclipse.sirius.components.view.View) DiagramDescription(org.eclipse.sirius.components.view.DiagramDescription) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) IObjectService(org.eclipse.sirius.components.core.api.IObjectService)

Aggregations

SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)2 UUID (java.util.UUID)2 IRepresentationPersistenceService (org.eclipse.sirius.components.collaborative.api.IRepresentationPersistenceService)2 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)2 IObjectService (org.eclipse.sirius.components.core.api.IObjectService)2 IRepresentationDescriptionSearchService (org.eclipse.sirius.components.core.api.IRepresentationDescriptionSearchService)2 IRepresentationDescription (org.eclipse.sirius.components.representations.IRepresentationDescription)2 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)1 ChangeKind (org.eclipse.sirius.components.collaborative.api.ChangeKind)1 DiagramCreationService (org.eclipse.sirius.components.collaborative.diagrams.DiagramCreationService)1 IDiagramCreationService (org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramCreationService)1 ICollaborativeDiagramMessageService (org.eclipse.sirius.components.collaborative.diagrams.messages.ICollaborativeDiagramMessageService)1 CreateRepresentationInput (org.eclipse.sirius.components.collaborative.dto.CreateRepresentationInput)1 CreateRepresentationSuccessPayload (org.eclipse.sirius.components.collaborative.dto.CreateRepresentationSuccessPayload)1