use of org.eclipse.sirius.web.services.api.projects.RenameProjectInput in project sirius-web by eclipse-sirius.
the class RenameProjectEventHandler method handle.
@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, IInput input) {
String message = this.messageService.invalidInput(input.getClass().getSimpleName(), RenameProjectInput.class.getSimpleName());
IPayload payload = new ErrorPayload(input.getId(), message);
ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, editingContext.getId(), input);
if (input instanceof RenameProjectInput) {
RenameProjectInput renameProjectInput = (RenameProjectInput) input;
Optional<Project> optionalProject = this.projectService.renameProject(renameProjectInput.getProjectId(), renameProjectInput.getNewName());
if (optionalProject.isPresent()) {
payload = new RenameProjectSuccessPayload(input.getId(), optionalProject.get());
changeDescription = new ChangeDescription(ChangeKind.PROJECT_RENAMING, editingContext.getId(), input);
}
}
payloadSink.tryEmitValue(payload);
changeDescriptionSink.tryEmitNext(changeDescription);
}
use of org.eclipse.sirius.web.services.api.projects.RenameProjectInput in project sirius-web by eclipse-sirius.
the class RenameProjectEventHandlerTests method testRenameProject.
@Test
public void testRenameProject() {
// $NON-NLS-1$ //$NON-NLS-2$
Project project = new Project(UUID.randomUUID(), "newName", new Profile(UUID.randomUUID(), "system"), Visibility.PUBLIC);
AtomicBoolean hasBeenCalled = new AtomicBoolean();
IProjectService projectService = new IProjectService.NoOp() {
@Override
public Optional<Project> renameProject(UUID projectId, String newName) {
hasBeenCalled.set(true);
return Optional.of(project);
}
};
RenameProjectEventHandler handler = new RenameProjectEventHandler(new NoOpServicesMessageService(), projectService);
// $NON-NLS-1$
var input = new RenameProjectInput(UUID.randomUUID(), UUID.randomUUID(), "newName");
IEditingContext editingContext = () -> UUID.randomUUID().toString();
Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
One<IPayload> payloadSink = Sinks.one();
assertThat(handler.canHandle(editingContext, input)).isTrue();
handler.handle(payloadSink, changeDescriptionSink, editingContext, input);
assertThat(hasBeenCalled.get()).isTrue();
ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.PROJECT_RENAMING);
IPayload payload = payloadSink.asMono().block();
assertThat(payload).isInstanceOf(RenameProjectSuccessPayload.class);
}
Aggregations