Search in sources :

Example 1 with QueryBasedBooleanSuccessPayload

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

the class EMFQueryService method execute.

@Override
public IPayload execute(IEditingContext editingContext, QueryBasedBooleanInput input) {
    Result result = this.executeQuery(editingContext, input.getQuery(), input.getVariables());
    Optional<Boolean> optionalBoolean = result.asBoolean();
    if (optionalBoolean.isPresent()) {
        return new QueryBasedBooleanSuccessPayload(input.getId(), optionalBoolean.get().booleanValue());
    } else {
        return new ErrorPayload(input.getId(), EVALUATION_ERROR_MESSAGE + result.getStatus());
    }
}
Also used : ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) QueryBasedBooleanSuccessPayload(org.eclipse.sirius.components.collaborative.dto.QueryBasedBooleanSuccessPayload) Result(org.eclipse.sirius.components.interpreter.Result)

Example 2 with QueryBasedBooleanSuccessPayload

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

the class QueryBasedBooleanEventHandlerTests method testQueryBasedBoolean.

@Test
public void testQueryBasedBoolean() {
    // The EMFQueryService implementation is already tested by another class.
    IQueryService queryService = new IQueryService.NoOp() {

        @Override
        public IPayload execute(IEditingContext editingContext, QueryBasedBooleanInput input) {
            return new QueryBasedBooleanSuccessPayload(UUID.randomUUID(), EXPECTED_RESULT_FALSE);
        }
    };
    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(QueryBasedBooleanSuccessPayload.class);
    assertThat(((QueryBasedBooleanSuccessPayload) payload).getResult()).isEqualTo(EXPECTED_RESULT_FALSE);
}
Also used : IQueryService(org.eclipse.sirius.components.collaborative.api.IQueryService) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) QueryBasedBooleanSuccessPayload(org.eclipse.sirius.components.collaborative.dto.QueryBasedBooleanSuccessPayload) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) QueryBasedBooleanInput(org.eclipse.sirius.components.collaborative.dto.QueryBasedBooleanInput) IPayload(org.eclipse.sirius.components.core.api.IPayload) Test(org.junit.jupiter.api.Test)

Aggregations

QueryBasedBooleanSuccessPayload (org.eclipse.sirius.components.collaborative.dto.QueryBasedBooleanSuccessPayload)2 ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)1 IQueryService (org.eclipse.sirius.components.collaborative.api.IQueryService)1 QueryBasedBooleanInput (org.eclipse.sirius.components.collaborative.dto.QueryBasedBooleanInput)1 ErrorPayload (org.eclipse.sirius.components.core.api.ErrorPayload)1 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)1 IPayload (org.eclipse.sirius.components.core.api.IPayload)1 Result (org.eclipse.sirius.components.interpreter.Result)1 Test (org.junit.jupiter.api.Test)1