use of org.eclipse.sirius.components.collaborative.dto.QueryBasedObjectInput in project sirius-components by eclipse-sirius.
the class QueryBasedObjectEventHandlerTests method testQueryBasedObjectFailed.
@Test
public void testQueryBasedObjectFailed() {
IQueryService queryService = new IQueryService.NoOp() {
@Override
public IPayload execute(IEditingContext editingContext, QueryBasedObjectInput 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.QueryBasedObjectInput in project sirius-components by eclipse-sirius.
the class EMFQueryServiceTests method testEMFQueryServiceGetObjectById.
@Test
public void testEMFQueryServiceGetObjectById() {
EditingContext 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());
// @formatter:off
EObject eObjectToRetrieve = editingContext.getDomain().getResourceSet().getResources().get(0).getContents().get(0);
Optional<IDAdapter> optionalIDAdapter = eObjectToRetrieve.eAdapters().stream().filter(IDAdapter.class::isInstance).map(IDAdapter.class::cast).findFirst();
// $NON-NLS-1$
String id = optionalIDAdapter.map(IDAdapter::getId).map(Object::toString).orElse("");
// @formatter:on
// $NON-NLS-1$ //$NON-NLS-2$
QueryBasedObjectInput input = new QueryBasedObjectInput(UUID.randomUUID(), "aql:editingContext.getObjectById('" + id + "')", Map.of());
IPayload payload = queryService.execute(editingContext, input);
assertTrue(payload instanceof QueryBasedObjectSuccessPayload);
assertEquals(eObjectToRetrieve, ((QueryBasedObjectSuccessPayload) payload).getResult());
// $NON-NLS-1$ //$NON-NLS-2$
input = new QueryBasedObjectInput(UUID.randomUUID(), "aql:editingContext.getObjectById('" + id + "wrong')", Map.of());
payload = queryService.execute(editingContext, input);
assertTrue(payload instanceof ErrorPayload);
}
use of org.eclipse.sirius.components.collaborative.dto.QueryBasedObjectInput in project sirius-components by eclipse-sirius.
the class QueryBasedObjectEventHandlerTests method handle.
private void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IQueryService queryService) {
QueryBasedObjectEventHandler queryBasedObjectEventHandler = new QueryBasedObjectEventHandler(new ICollaborativeMessageService.NoOp(), new SimpleMeterRegistry(), queryService);
// $NON-NLS-1$
IInput input = new QueryBasedObjectInput(UUID.randomUUID(), "", Map.of());
assertThat(queryBasedObjectEventHandler.canHandle(new IEditingContext.NoOp(), input)).isTrue();
IEditingContext editingContext = () -> UUID.randomUUID().toString();
queryBasedObjectEventHandler.handle(payloadSink, changeDescriptionSink, editingContext, input);
}
use of org.eclipse.sirius.components.collaborative.dto.QueryBasedObjectInput in project sirius-components by eclipse-sirius.
the class QueryBasedObjectEventHandlerTests method testQueryBasedObject.
@Test
public void testQueryBasedObject() {
IQueryService queryService = new IQueryService.NoOp() {
@Override
public IPayload execute(IEditingContext editingContext, QueryBasedObjectInput input) {
return new QueryBasedObjectSuccessPayload(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(QueryBasedObjectSuccessPayload.class);
assertThat(((QueryBasedObjectSuccessPayload) payload).getResult()).isEqualTo(EXPECTED_RESULT);
}
use of org.eclipse.sirius.components.collaborative.dto.QueryBasedObjectInput in project sirius-components by eclipse-sirius.
the class QueryBasedObjectEventHandler 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 QueryBasedObjectInput) {
QueryBasedObjectInput queryBasedObjectInput = (QueryBasedObjectInput) input;
payload = this.queryService.execute(editingContext, queryBasedObjectInput);
}
payloadSink.tryEmitValue(payload);
ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, editingContext.getId(), input);
changeDescriptionSink.tryEmitNext(changeDescription);
}
Aggregations