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);
}
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());
}
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());
}
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());
}
}
Aggregations