Search in sources :

Example 1 with QueryBasedIntInput

use of org.eclipse.sirius.components.collaborative.dto.QueryBasedIntInput in project sirius-components by eclipse-sirius.

the class QueryBasedIntEventHandlerTests method handle.

private void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IQueryService queryService) {
    QueryBasedIntEventHandler queryBasedIntEventHandler = new QueryBasedIntEventHandler(new ICollaborativeMessageService.NoOp(), new SimpleMeterRegistry(), queryService);
    // $NON-NLS-1$
    IInput input = new QueryBasedIntInput(UUID.randomUUID(), "", Map.of());
    assertThat(queryBasedIntEventHandler.canHandle(new IEditingContext.NoOp(), input)).isTrue();
    IEditingContext editingContext = () -> UUID.randomUUID().toString();
    queryBasedIntEventHandler.handle(payloadSink, changeDescriptionSink, editingContext, input);
}
Also used : QueryBasedIntInput(org.eclipse.sirius.components.collaborative.dto.QueryBasedIntInput) ICollaborativeMessageService(org.eclipse.sirius.components.collaborative.messages.ICollaborativeMessageService) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) IInput(org.eclipse.sirius.components.core.api.IInput)

Example 2 with QueryBasedIntInput

use of org.eclipse.sirius.components.collaborative.dto.QueryBasedIntInput in project sirius-components by eclipse-sirius.

the class QueryBasedIntEventHandlerTests method testQueryBasedInt.

@Test
public void testQueryBasedInt() {
    IQueryService queryService = new IQueryService.NoOp() {

        @Override
        public IPayload execute(IEditingContext editingContext, QueryBasedIntInput input) {
            return new QueryBasedIntSuccessPayload(UUID.randomUUID(), EXPECTED_RESULT_10);
        }
    };
    Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
    One<IPayload> payloadSink = Sinks.one();
    this.handle(payloadSink, changeDescriptionSink, queryService);
    ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
    assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.NOTHING);
    IPayload payload = payloadSink.asMono().block();
    assertThat(payload).isInstanceOf(QueryBasedIntSuccessPayload.class);
    assertThat(((QueryBasedIntSuccessPayload) payload).getResult()).isEqualTo(EXPECTED_RESULT_10);
}
Also used : QueryBasedIntInput(org.eclipse.sirius.components.collaborative.dto.QueryBasedIntInput) QueryBasedIntSuccessPayload(org.eclipse.sirius.components.collaborative.dto.QueryBasedIntSuccessPayload) IQueryService(org.eclipse.sirius.components.collaborative.api.IQueryService) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) IPayload(org.eclipse.sirius.components.core.api.IPayload) Test(org.junit.jupiter.api.Test)

Example 3 with QueryBasedIntInput

use of org.eclipse.sirius.components.collaborative.dto.QueryBasedIntInput in project sirius-components by eclipse-sirius.

the class EMFQueryServiceTests method testEMFQueryServiceContents.

@Test
public void testEMFQueryServiceContents() {
    IEditingContext editingContext = this.createEditingContext();
    IEditingContextEPackageService editingContextEPackageService = new IEditingContextEPackageService() {

        @Override
        public List<EPackage> getEPackages(String editingContextId) {
            return List.of(EcorePackage.eINSTANCE);
        }
    };
    IQueryService queryService = new EMFQueryService(editingContextEPackageService, List.of());
    // $NON-NLS-1$
    QueryBasedIntInput input = new QueryBasedIntInput(UUID.randomUUID(), "aql:editingContext.contents()->size()", Map.of());
    IPayload payload = queryService.execute(editingContext, input);
    assertTrue(payload instanceof QueryBasedIntSuccessPayload);
    assertEquals(2, ((QueryBasedIntSuccessPayload) payload).getResult());
}
Also used : QueryBasedIntInput(org.eclipse.sirius.components.collaborative.dto.QueryBasedIntInput) QueryBasedIntSuccessPayload(org.eclipse.sirius.components.collaborative.dto.QueryBasedIntSuccessPayload) IQueryService(org.eclipse.sirius.components.collaborative.api.IQueryService) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) IEditingContextEPackageService(org.eclipse.sirius.components.emf.services.IEditingContextEPackageService) EPackage(org.eclipse.emf.ecore.EPackage) IPayload(org.eclipse.sirius.components.core.api.IPayload) Test(org.junit.jupiter.api.Test)

Example 4 with QueryBasedIntInput

use of org.eclipse.sirius.components.collaborative.dto.QueryBasedIntInput in project sirius-components by eclipse-sirius.

the class EMFQueryServiceTests method testEMFQueryServiceAllContents.

@Test
public void testEMFQueryServiceAllContents() {
    IEditingContext editingContext = this.createEditingContext();
    IEditingContextEPackageService editingContextEPackageService = new IEditingContextEPackageService() {

        @Override
        public List<EPackage> getEPackages(String editingContextId) {
            return List.of(EcorePackage.eINSTANCE);
        }
    };
    IQueryService queryService = new EMFQueryService(editingContextEPackageService, List.of());
    // $NON-NLS-1$
    QueryBasedIntInput input = new QueryBasedIntInput(UUID.randomUUID(), "aql:editingContext.allContents()->size()", Map.of());
    IPayload payload = queryService.execute(editingContext, input);
    assertTrue(payload instanceof QueryBasedIntSuccessPayload);
    assertEquals(8, ((QueryBasedIntSuccessPayload) payload).getResult());
}
Also used : QueryBasedIntInput(org.eclipse.sirius.components.collaborative.dto.QueryBasedIntInput) QueryBasedIntSuccessPayload(org.eclipse.sirius.components.collaborative.dto.QueryBasedIntSuccessPayload) IQueryService(org.eclipse.sirius.components.collaborative.api.IQueryService) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) IEditingContextEPackageService(org.eclipse.sirius.components.emf.services.IEditingContextEPackageService) EPackage(org.eclipse.emf.ecore.EPackage) IPayload(org.eclipse.sirius.components.core.api.IPayload) Test(org.junit.jupiter.api.Test)

Example 5 with QueryBasedIntInput

use of org.eclipse.sirius.components.collaborative.dto.QueryBasedIntInput in project sirius-components by eclipse-sirius.

the class QueryBasedIntEventHandlerTests method testQueryBasedIntFailed.

@Test
public void testQueryBasedIntFailed() {
    IQueryService queryService = new IQueryService.NoOp() {

        @Override
        public IPayload execute(IEditingContext editingContext, QueryBasedIntInput input) {
            // $NON-NLS-1$
            return new ErrorPayload(UUID.randomUUID(), "An error occured");
        }
    };
    Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
    One<IPayload> payloadSink = Sinks.one();
    this.handle(payloadSink, changeDescriptionSink, queryService);
    ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
    assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.NOTHING);
    IPayload payload = payloadSink.asMono().block();
    assertThat(payload).isInstanceOf(ErrorPayload.class);
}
Also used : QueryBasedIntInput(org.eclipse.sirius.components.collaborative.dto.QueryBasedIntInput) ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) IQueryService(org.eclipse.sirius.components.collaborative.api.IQueryService) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) IPayload(org.eclipse.sirius.components.core.api.IPayload) Test(org.junit.jupiter.api.Test)

Aggregations

QueryBasedIntInput (org.eclipse.sirius.components.collaborative.dto.QueryBasedIntInput)6 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)5 IPayload (org.eclipse.sirius.components.core.api.IPayload)5 IQueryService (org.eclipse.sirius.components.collaborative.api.IQueryService)4 Test (org.junit.jupiter.api.Test)4 ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)3 QueryBasedIntSuccessPayload (org.eclipse.sirius.components.collaborative.dto.QueryBasedIntSuccessPayload)3 EPackage (org.eclipse.emf.ecore.EPackage)2 ErrorPayload (org.eclipse.sirius.components.core.api.ErrorPayload)2 IEditingContextEPackageService (org.eclipse.sirius.components.emf.services.IEditingContextEPackageService)2 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)1 ICollaborativeMessageService (org.eclipse.sirius.components.collaborative.messages.ICollaborativeMessageService)1 IInput (org.eclipse.sirius.components.core.api.IInput)1