Search in sources :

Example 1 with QueryBasedBooleanInput

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

the class QueryBasedBooleanEventHandlerTests method testQueryBasedBooleanFailed.

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

        @Override
        public IPayload execute(IEditingContext editingContext, QueryBasedBooleanInput 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 : 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) QueryBasedBooleanInput(org.eclipse.sirius.components.collaborative.dto.QueryBasedBooleanInput) IPayload(org.eclipse.sirius.components.core.api.IPayload) Test(org.junit.jupiter.api.Test)

Example 2 with QueryBasedBooleanInput

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

the class QueryBasedBooleanEventHandler method handle.

@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, IInput input) {
    this.counter.increment();
    String message = this.messageService.invalidInput(input.getClass().getSimpleName(), QueryBasedStringInput.class.getSimpleName());
    IPayload payload = new ErrorPayload(input.getId(), message);
    if (input instanceof QueryBasedBooleanInput) {
        QueryBasedBooleanInput queryBasedBooleanInput = (QueryBasedBooleanInput) input;
        payload = this.queryService.execute(editingContext, queryBasedBooleanInput);
    }
    payloadSink.tryEmitValue(payload);
    ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, editingContext.getId(), input);
    changeDescriptionSink.tryEmitNext(changeDescription);
}
Also used : ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) QueryBasedStringInput(org.eclipse.sirius.components.collaborative.dto.QueryBasedStringInput) QueryBasedBooleanInput(org.eclipse.sirius.components.collaborative.dto.QueryBasedBooleanInput) IPayload(org.eclipse.sirius.components.core.api.IPayload)

Example 3 with QueryBasedBooleanInput

use of org.eclipse.sirius.components.collaborative.dto.QueryBasedBooleanInput 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)

Example 4 with QueryBasedBooleanInput

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

the class QueryBasedBooleanEventHandlerTests method handle.

private void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IQueryService queryService) {
    QueryBasedBooleanEventHandler queryBasedBooleanEventHandler = new QueryBasedBooleanEventHandler(new ICollaborativeMessageService.NoOp(), new SimpleMeterRegistry(), queryService);
    // $NON-NLS-1$
    IInput input = new QueryBasedBooleanInput(UUID.randomUUID(), "", Map.of());
    assertThat(queryBasedBooleanEventHandler.canHandle(new IEditingContext.NoOp(), input)).isTrue();
    IEditingContext editingContext = () -> UUID.randomUUID().toString();
    queryBasedBooleanEventHandler.handle(payloadSink, changeDescriptionSink, editingContext, input);
}
Also used : 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) QueryBasedBooleanInput(org.eclipse.sirius.components.collaborative.dto.QueryBasedBooleanInput)

Aggregations

QueryBasedBooleanInput (org.eclipse.sirius.components.collaborative.dto.QueryBasedBooleanInput)4 ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)3 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)3 IPayload (org.eclipse.sirius.components.core.api.IPayload)3 IQueryService (org.eclipse.sirius.components.collaborative.api.IQueryService)2 ErrorPayload (org.eclipse.sirius.components.core.api.ErrorPayload)2 Test (org.junit.jupiter.api.Test)2 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)1 QueryBasedBooleanSuccessPayload (org.eclipse.sirius.components.collaborative.dto.QueryBasedBooleanSuccessPayload)1 QueryBasedStringInput (org.eclipse.sirius.components.collaborative.dto.QueryBasedStringInput)1 ICollaborativeMessageService (org.eclipse.sirius.components.collaborative.messages.ICollaborativeMessageService)1 IInput (org.eclipse.sirius.components.core.api.IInput)1