use of reactor.core.publisher.Sinks.One in project sirius-components by eclipse-sirius.
the class EditCheckboxEventHandlerTests method testCheckboxEdition.
@Test
public void testCheckboxEdition() {
// $NON-NLS-1$
String id = "Checkbox id";
var input = new EditCheckboxInput(UUID.randomUUID(), UUID.randomUUID().toString(), FORM_ID, id, true);
AtomicBoolean hasBeenExecuted = new AtomicBoolean();
Function<Boolean, IStatus> newValueHandler = newValue -> {
hasBeenExecuted.set(true);
return new Success();
};
// @formatter:off
Checkbox checkbox = Checkbox.newCheckbox(id).label(// $NON-NLS-1$
"label").newValueHandler(newValueHandler).diagnostics(List.of()).build();
Group group = // $NON-NLS-1$
Group.newGroup("groupId").label(// $NON-NLS-1$
"group label").widgets(List.of(checkbox)).build();
Page page = // $NON-NLS-1$
Page.newPage("pageId").label(// $NON-NLS-1$
"page label").groups(List.of(group)).build();
Form form = Form.newForm(FORM_ID).targetObjectId(// $NON-NLS-1$
"targetObjectId").descriptionId(UUID.randomUUID()).label(// $NON-NLS-1$
"form label").pages(List.of(page)).build();
// @formatter:on
IFormQueryService formQueryService = new IFormQueryService.NoOp() {
@Override
public Optional<AbstractWidget> findWidget(Form form, String widgetId) {
return Optional.of(checkbox);
}
};
EditCheckboxEventHandler handler = new EditCheckboxEventHandler(formQueryService, new ICollaborativeFormMessageService.NoOp(), new SimpleMeterRegistry());
assertThat(handler.canHandle(input)).isTrue();
Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
One<IPayload> payloadSink = Sinks.one();
handler.handle(payloadSink, changeDescriptionSink, form, input);
ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.SEMANTIC_CHANGE);
IPayload payload = payloadSink.asMono().block();
assertThat(payload).isInstanceOf(EditCheckboxSuccessPayload.class);
assertThat(hasBeenExecuted.get()).isTrue();
}
use of reactor.core.publisher.Sinks.One in project sirius-components by eclipse-sirius.
the class EditRadioEventHandlerTests method testRadioEdition.
@Test
public void testRadioEdition() {
// $NON-NLS-1$
String id = "Radio id";
// $NON-NLS-1$
var input = new EditRadioInput(UUID.randomUUID(), UUID.randomUUID().toString(), FORM_ID, id, "optionId");
AtomicBoolean hasBeenExecuted = new AtomicBoolean();
Function<String, IStatus> newValueHandler = newValue -> {
hasBeenExecuted.set(true);
return new Success();
};
// @formatter:off
RadioOption option = // $NON-NLS-1$
RadioOption.newRadioOption("optionId").label(// $NON-NLS-1$
"Option label").selected(false).build();
Radio radio = Radio.newRadio(id).label(// $NON-NLS-1$
"label").newValueHandler(newValueHandler).options(List.of(option)).diagnostics(List.of()).build();
Group group = // $NON-NLS-1$
Group.newGroup("groupId").label(// $NON-NLS-1$
"group label").widgets(List.of(radio)).build();
Page page = // $NON-NLS-1$
Page.newPage("pageId").label(// $NON-NLS-1$
"page label").groups(List.of(group)).build();
Form form = Form.newForm(FORM_ID).targetObjectId(// $NON-NLS-1$
"targetObjectId").descriptionId(UUID.randomUUID()).label(// $NON-NLS-1$
"form label").pages(List.of(page)).build();
// @formatter:on
IFormQueryService formQueryService = new IFormQueryService.NoOp() {
@Override
public Optional<AbstractWidget> findWidget(Form form, String widgetId) {
return Optional.of(radio);
}
};
EditRadioEventHandler handler = new EditRadioEventHandler(formQueryService, new ICollaborativeFormMessageService.NoOp(), new SimpleMeterRegistry());
assertThat(handler.canHandle(input)).isTrue();
Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
One<IPayload> payloadSink = Sinks.one();
handler.handle(payloadSink, changeDescriptionSink, form, input);
ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.SEMANTIC_CHANGE);
IPayload payload = payloadSink.asMono().block();
assertThat(payload).isInstanceOf(EditRadioSuccessPayload.class);
assertThat(hasBeenExecuted.get()).isTrue();
}
Aggregations