use of org.eclipse.sirius.components.collaborative.dto.QueryBasedStringInput in project sirius-components by eclipse-sirius.
the class QueryBasedStringEventHandlerTests method handle.
private void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IQueryService queryService) {
QueryBasedStringEventHandler queryBasedStringEventHandler = new QueryBasedStringEventHandler(new ICollaborativeMessageService.NoOp(), new SimpleMeterRegistry(), queryService);
// $NON-NLS-1$
IInput input = new QueryBasedStringInput(UUID.randomUUID(), "", Map.of());
assertThat(queryBasedStringEventHandler.canHandle(new IEditingContext.NoOp(), input)).isTrue();
IEditingContext editingContext = () -> UUID.randomUUID().toString();
queryBasedStringEventHandler.handle(payloadSink, changeDescriptionSink, editingContext, input);
}
use of org.eclipse.sirius.components.collaborative.dto.QueryBasedStringInput in project sirius-components by eclipse-sirius.
the class QueryBasedStringEventHandler 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 QueryBasedStringInput) {
QueryBasedStringInput queryBasedStringInput = (QueryBasedStringInput) input;
payload = this.queryService.execute(editingContext, queryBasedStringInput);
}
payloadSink.tryEmitValue(payload);
ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, editingContext.getId(), input);
changeDescriptionSink.tryEmitNext(changeDescription);
}
use of org.eclipse.sirius.components.collaborative.dto.QueryBasedStringInput in project sirius-components by eclipse-sirius.
the class QueryBasedStringEventHandlerTests method testQueryBasedStringFailed.
@Test
public void testQueryBasedStringFailed() {
IQueryService queryService = new IQueryService.NoOp() {
@Override
public IPayload execute(IEditingContext editingContext, QueryBasedStringInput 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);
}
use of org.eclipse.sirius.components.collaborative.dto.QueryBasedStringInput in project sirius-components by eclipse-sirius.
the class QueryBasedStringEventHandlerTests method testQueryBasedString.
@Test
public void testQueryBasedString() {
IQueryService queryService = new IQueryService.NoOp() {
@Override
public IPayload execute(IEditingContext editingContext, QueryBasedStringInput input) {
return new QueryBasedStringSuccessPayload(UUID.randomUUID(), EXPECTED_RESULT);
}
};
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(QueryBasedStringSuccessPayload.class);
assertThat(((QueryBasedStringSuccessPayload) payload).getResult()).isEqualTo(EXPECTED_RESULT);
}
Aggregations