use of org.eclipse.sirius.components.diagrams.tests.TestDiagramDescriptionBuilder in project sirius-components by eclipse-sirius.
the class RenameDiagramEventHandlerTests method testRenameRepresentation.
@Test
public void testRenameRepresentation() {
String projectId = UUID.randomUUID().toString();
String representationId = UUID.randomUUID().toString();
UUID targetObjectId = UUID.randomUUID();
DiagramDescription diagramDescription = new TestDiagramDescriptionBuilder().getDiagramDescription(UUID.randomUUID(), List.of(), List.of(), List.of());
// @formatter:off
Diagram diagram = Diagram.newDiagram(representationId).label(OLD_LABEL).descriptionId(diagramDescription.getId()).targetObjectId(targetObjectId.toString()).size(Size.of(10, 10)).position(Position.at(0, 0)).nodes(Collections.emptyList()).edges(Collections.emptyList()).build();
// @formatter:on
IRepresentationSearchService representationSearchService = new IRepresentationSearchService() {
@Override
public <T extends IRepresentation> Optional<T> findById(IEditingContext editingContext, String representationId, Class<T> representationClass) {
return Optional.of(diagram).map(representationClass::cast);
}
};
RenameDiagramEventHandler handler = new RenameDiagramEventHandler(representationSearchService, new IRepresentationPersistenceService.NoOp(), new ICollaborativeDiagramMessageService.NoOp(), new SimpleMeterRegistry());
var input = new RenameDiagramInput(UUID.randomUUID(), projectId, representationId, NEW_LABEL);
assertThat(handler.canHandle(input)).isTrue();
Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
One<IPayload> payloadSink = Sinks.one();
handler.handle(payloadSink, changeDescriptionSink, new IEditingContext.NoOp(), new IDiagramContext.NoOp(), input);
ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.REPRESENTATION_RENAMING);
IPayload payload = payloadSink.asMono().block();
assertThat(payload).isInstanceOf(RenameRepresentationSuccessPayload.class);
assertThat(((RenameRepresentationSuccessPayload) payload).getRepresentation().getLabel()).isEqualTo(NEW_LABEL);
}
Aggregations