use of org.eclipse.sirius.components.core.api.IRepresentationDescriptionSearchService in project sirius-components by eclipse-sirius.
the class CreateDiagramEventHandlerTests method testDiagramCreation.
@Test
public void testDiagramCreation() {
IRepresentationDescriptionSearchService representationDescriptionSearchService = new IRepresentationDescriptionSearchService.NoOp() {
@Override
public Optional<IRepresentationDescription> findById(IEditingContext editingContext, UUID id) {
// @formatter:off
DiagramDescription diagramDescription = DiagramDescription.newDiagramDescription(UUID.randomUUID()).label(// $NON-NLS-1$
"label").canCreatePredicate(variableManager -> Boolean.TRUE).edgeDescriptions(new ArrayList<>()).labelProvider(// $NON-NLS-1$
variableManager -> "label").toolSections(List.of()).nodeDescriptions(new ArrayList<>()).targetObjectIdProvider(// $NON-NLS-1$
variableManager -> "targetObjectId").dropHandler(// $NON-NLS-1$
variableManager -> new Failure("")).build();
return Optional.of(diagramDescription);
}
};
AtomicBoolean hasBeenCalled = new AtomicBoolean();
IDiagramCreationService diagramCreationService = new IDiagramCreationService.NoOp() {
@Override
public Diagram create(String label, Object targetObject, DiagramDescription diagramDescription, IEditingContext editingContext) {
hasBeenCalled.set(true);
return new TestDiagramBuilder().getDiagram(UUID.randomUUID().toString());
}
};
IObjectService objectService = new IObjectService.NoOp() {
@Override
public Optional<Object> getObject(IEditingContext editingContext, String objectId) {
return Optional.of(new Object());
}
};
CreateDiagramEventHandler handler = new CreateDiagramEventHandler(representationDescriptionSearchService, new IRepresentationPersistenceService.NoOp(), diagramCreationService, objectService, new ICollaborativeDiagramMessageService.NoOp(), new SimpleMeterRegistry());
// $NON-NLS-1$//$NON-NLS-2$
var input = new CreateRepresentationInput(UUID.randomUUID(), UUID.randomUUID().toString(), UUID.randomUUID(), "objectId", "representationName");
assertThat(handler.canHandle(null, input)).isTrue();
Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
One<IPayload> payloadSink = Sinks.one();
IEditingContext editingContext = () -> UUID.randomUUID().toString();
handler.handle(payloadSink, changeDescriptionSink, editingContext, input);
assertThat(hasBeenCalled.get()).isTrue();
ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.REPRESENTATION_CREATION);
IPayload payload = payloadSink.asMono().block();
assertThat(payload).isInstanceOf(CreateRepresentationSuccessPayload.class);
}
use of org.eclipse.sirius.components.core.api.IRepresentationDescriptionSearchService in project sirius-components by eclipse-sirius.
the class DynamicDiagramsTests method render.
private Diagram render(DiagramDescription diagramDescription, Object target) {
// Wrap into a View, as expected by ViewConverter
View view = ViewFactory.eINSTANCE.createView();
view.getDescriptions().add(diagramDescription);
var viewConverter = new ViewConverter(new IObjectService.NoOp(), new IEditService.NoOp(), List.of());
List<IRepresentationDescription> conversionResult = viewConverter.convert(view, List.of(EcorePackage.eINSTANCE));
assertThat(conversionResult).hasSize(1);
assertThat(conversionResult.get(0)).isInstanceOf(org.eclipse.sirius.components.diagrams.description.DiagramDescription.class);
org.eclipse.sirius.components.diagrams.description.DiagramDescription convertedDiagramDescription = (org.eclipse.sirius.components.diagrams.description.DiagramDescription) conversionResult.get(0);
IRepresentationDescriptionSearchService representationDescriptionSearchService = new IRepresentationDescriptionSearchService.NoOp() {
@Override
public Optional<IRepresentationDescription> findById(IEditingContext editingContext, UUID representationDescriptionId) {
return Optional.of(convertedDiagramDescription);
}
};
IObjectService objectService = new IObjectService.NoOp();
ILayoutService layoutService = new ILayoutService.NoOp();
MeterRegistry meterRegistry = new SimpleMeterRegistry();
var diagramCreationService = new DiagramCreationService(representationDescriptionSearchService, new IRepresentationPersistenceService.NoOp(), objectService, layoutService, meterRegistry);
IEditingContext editinContext = new IEditingContext.NoOp();
// $NON-NLS-1$
return diagramCreationService.create("Test Diagram", target, convertedDiagramDescription, editinContext);
}
Aggregations