Search in sources :

Example 1 with QueryBasedIntSuccessPayload

use of org.eclipse.sirius.components.collaborative.dto.QueryBasedIntSuccessPayload 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 2 with QueryBasedIntSuccessPayload

use of org.eclipse.sirius.components.collaborative.dto.QueryBasedIntSuccessPayload 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 3 with QueryBasedIntSuccessPayload

use of org.eclipse.sirius.components.collaborative.dto.QueryBasedIntSuccessPayload 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 4 with QueryBasedIntSuccessPayload

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

the class EMFQueryService method execute.

@Override
public IPayload execute(IEditingContext editingContext, QueryBasedIntInput input) {
    Result result = this.executeQuery(editingContext, input.getQuery(), input.getVariables());
    OptionalInt optionalInt = result.asInt();
    if (optionalInt.isPresent()) {
        return new QueryBasedIntSuccessPayload(input.getId(), optionalInt.getAsInt());
    } else {
        return new ErrorPayload(input.getId(), EVALUATION_ERROR_MESSAGE + result.getStatus());
    }
}
Also used : QueryBasedIntSuccessPayload(org.eclipse.sirius.components.collaborative.dto.QueryBasedIntSuccessPayload) ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) OptionalInt(java.util.OptionalInt) Result(org.eclipse.sirius.components.interpreter.Result)

Aggregations

QueryBasedIntSuccessPayload (org.eclipse.sirius.components.collaborative.dto.QueryBasedIntSuccessPayload)4 IQueryService (org.eclipse.sirius.components.collaborative.api.IQueryService)3 QueryBasedIntInput (org.eclipse.sirius.components.collaborative.dto.QueryBasedIntInput)3 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)3 IPayload (org.eclipse.sirius.components.core.api.IPayload)3 Test (org.junit.jupiter.api.Test)3 EPackage (org.eclipse.emf.ecore.EPackage)2 IEditingContextEPackageService (org.eclipse.sirius.components.emf.services.IEditingContextEPackageService)2 OptionalInt (java.util.OptionalInt)1 ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)1 ErrorPayload (org.eclipse.sirius.components.core.api.ErrorPayload)1 Result (org.eclipse.sirius.components.interpreter.Result)1