|
17 | 17 | import static org.eclipse.sirius.components.diagrams.tests.assertions.DiagramAssertions.assertThat; |
18 | 18 | import static org.eclipse.sirius.components.diagrams.tests.assertions.DiagramInstanceOfAssertFactories.EDGE_STYLE; |
19 | 19 |
|
| 20 | +import com.jayway.jsonpath.JsonPath; |
| 21 | + |
20 | 22 | import java.time.Duration; |
| 23 | +import java.util.List; |
21 | 24 | import java.util.UUID; |
22 | 25 | import java.util.concurrent.atomic.AtomicReference; |
23 | 26 | import java.util.function.Consumer; |
24 | 27 |
|
25 | 28 | import org.eclipse.sirius.components.collaborative.diagrams.dto.DiagramEventInput; |
26 | 29 | import org.eclipse.sirius.components.collaborative.diagrams.dto.DiagramRefreshedEventPayload; |
| 30 | +import org.eclipse.sirius.components.collaborative.diagrams.dto.EditLabelInput; |
| 31 | +import org.eclipse.sirius.components.collaborative.diagrams.dto.EditLabelSuccessPayload; |
| 32 | +import org.eclipse.sirius.components.collaborative.diagrams.dto.InvokeSingleClickOnDiagramElementToolInput; |
| 33 | +import org.eclipse.sirius.components.collaborative.diagrams.dto.InvokeSingleClickOnDiagramElementToolSuccessPayload; |
| 34 | +import org.eclipse.sirius.components.collaborative.diagrams.dto.ToolVariable; |
| 35 | +import org.eclipse.sirius.components.collaborative.diagrams.dto.ToolVariableType; |
27 | 36 | import org.eclipse.sirius.components.core.api.IIdentityService; |
28 | 37 | import org.eclipse.sirius.components.core.api.IObjectSearchService; |
29 | 38 | import org.eclipse.sirius.components.diagrams.ArrowStyle; |
30 | 39 | import org.eclipse.sirius.components.diagrams.Diagram; |
31 | 40 | import org.eclipse.sirius.components.diagrams.Edge; |
32 | 41 | import org.eclipse.sirius.components.diagrams.events.ReconnectEdgeKind; |
33 | 42 | import org.eclipse.sirius.components.diagrams.tests.assertions.DiagramAssertions; |
| 43 | +import org.eclipse.sirius.components.diagrams.tests.graphql.EditLabelMutationRunner; |
| 44 | +import org.eclipse.sirius.components.diagrams.tests.graphql.InvokeSingleClickOnDiagramElementToolMutationRunner; |
| 45 | +import org.eclipse.sirius.components.diagrams.tests.navigation.DiagramNavigator; |
| 46 | +import org.eclipse.sirius.components.graphql.tests.ExecuteEditingContextFunctionSuccessPayload; |
34 | 47 | import org.eclipse.sirius.components.view.emf.diagram.IDiagramIdProvider; |
35 | 48 | import org.eclipse.sirius.web.tests.services.api.IGivenInitialServerState; |
36 | 49 | import org.eclipse.syson.AbstractIntegrationTests; |
|
40 | 53 | import org.eclipse.syson.application.controllers.diagrams.testers.EdgeCreationTester; |
41 | 54 | import org.eclipse.syson.application.controllers.diagrams.testers.EdgeReconnectionTester; |
42 | 55 | import org.eclipse.syson.application.data.GeneralViewFlowConnectionItemUsagesProjectData; |
| 56 | +import org.eclipse.syson.application.data.GeneralViewFlowUsageProjectData; |
43 | 57 | import org.eclipse.syson.services.SemanticRunnableFactory; |
44 | 58 | import org.eclipse.syson.services.diagrams.DiagramComparator; |
45 | 59 | import org.eclipse.syson.services.diagrams.DiagramDescriptionIdProvider; |
46 | 60 | import org.eclipse.syson.services.diagrams.api.IGivenDiagramDescription; |
47 | 61 | import org.eclipse.syson.services.diagrams.api.IGivenDiagramSubscription; |
48 | 62 | import org.eclipse.syson.standard.diagrams.view.SDVDescriptionNameGenerator; |
| 63 | +import org.eclipse.syson.sysml.ConnectionUsage; |
| 64 | +import org.eclipse.syson.sysml.FeatureTyping; |
| 65 | +import org.eclipse.syson.sysml.FlowEnd; |
49 | 66 | import org.eclipse.syson.sysml.FlowUsage; |
| 67 | +import org.eclipse.syson.sysml.PayloadFeature; |
50 | 68 | import org.eclipse.syson.sysml.SysmlPackage; |
51 | 69 | import org.eclipse.syson.util.IDescriptionNameGenerator; |
52 | 70 | import org.eclipse.syson.util.SysONRepresentationDescriptionIdentifiers; |
@@ -86,6 +104,12 @@ public class GVFlowUsageTests extends AbstractIntegrationTests { |
86 | 104 | @Autowired |
87 | 105 | private EdgeCreationTester edgeCreationTester; |
88 | 106 |
|
| 107 | + @Autowired |
| 108 | + private EditLabelMutationRunner editLabelMutationRunner; |
| 109 | + |
| 110 | + @Autowired |
| 111 | + private InvokeSingleClickOnDiagramElementToolMutationRunner invokeSingleClickOnDiagramElementToolMutationRunner; |
| 112 | + |
89 | 113 | @Autowired |
90 | 114 | private DiagramComparator diagramComparator; |
91 | 115 |
|
@@ -297,4 +321,115 @@ public void reconnectFlowUsageSource() { |
297 | 321 | .verify(Duration.ofSeconds(10)); |
298 | 322 | } |
299 | 323 |
|
| 324 | + @Test |
| 325 | + @DisplayName("GIVEN a connection WHEN we create a flow usage in it THEN the flow is correctly setup") |
| 326 | + @GivenSysONServer({ GeneralViewFlowUsageProjectData.SCRIPT_PATH }) |
| 327 | + public void createFlowUsageInConnection() { |
| 328 | + var diagramEventInput = new DiagramEventInput(UUID.randomUUID(), |
| 329 | + GeneralViewFlowUsageProjectData.EDITING_CONTEXT_ID, |
| 330 | + GeneralViewFlowUsageProjectData.GraphicalIds.DIAGRAM_ID); |
| 331 | + |
| 332 | + var flux = this.givenDiagramSubscription.subscribe(diagramEventInput); |
| 333 | + |
| 334 | + var diagramId = new AtomicReference<String>(); |
| 335 | + var connectionEdgeId = new AtomicReference<String>(); |
| 336 | + var connectionEdgeLabelId = new AtomicReference<String>(); |
| 337 | + |
| 338 | + var diagramDescription = this.givenDiagramDescription.getDiagramDescription(GeneralViewFlowUsageProjectData.EDITING_CONTEXT_ID, |
| 339 | + SysONRepresentationDescriptionIdentifiers.GENERAL_VIEW_DIAGRAM_DESCRIPTION_ID); |
| 340 | + var diagramDescriptionIdProvider = new DiagramDescriptionIdProvider(diagramDescription, this.diagramIdProvider); |
| 341 | + String flowCreationToolId = diagramDescriptionIdProvider.getNodeCreationToolIdOnEdge(this.descriptionNameGenerator.getEdgeName(SysmlPackage.eINSTANCE.getConnectionUsage()), "New Flow"); |
| 342 | + |
| 343 | + Consumer<Object> initialDiagramContentConsumer = assertRefreshedDiagramThat(diagram -> { |
| 344 | + diagramId.set(diagram.getId()); |
| 345 | + var connectionEdge = new DiagramNavigator(diagram).edgeWithId(GeneralViewFlowUsageProjectData.GraphicalIds.CONNECTION_EDGE_ID).getEdge(); |
| 346 | + connectionEdgeId.set(connectionEdge.getId()); |
| 347 | + connectionEdgeLabelId.set(connectionEdge.getCenterLabel().id()); |
| 348 | + }); |
| 349 | + |
| 350 | + Runnable renameAndTypeTheConnection = () -> { |
| 351 | + var input = new EditLabelInput(UUID.randomUUID(), GeneralViewFlowUsageProjectData.EDITING_CONTEXT_ID, diagramId.get(), connectionEdgeLabelId.get(), "cable : HDMICable"); |
| 352 | + var result = this.editLabelMutationRunner.run(input); |
| 353 | + |
| 354 | + String typename = JsonPath.read(result.data(), "$.data.editLabel.__typename"); |
| 355 | + assertThat(typename).isEqualTo(EditLabelSuccessPayload.class.getSimpleName()); |
| 356 | + List<String> messages = JsonPath.read(result.data(), "$.data.editLabel.messages[*].body"); |
| 357 | + assertThat(messages).hasSize(0); |
| 358 | + }; |
| 359 | + |
| 360 | + Consumer<Object> validateLabelEditResult = assertRefreshedDiagramThat(diagram -> { |
| 361 | + var edge = new DiagramNavigator(diagram).edgeWithId(connectionEdgeId.get()).getEdge(); |
| 362 | + DiagramAssertions.assertThat(edge.getCenterLabel()).hasText("cable : HDMICable"); |
| 363 | + }); |
| 364 | + |
| 365 | + Runnable validateSemanticEffectOfLabelEdit = this.semanticRunnableFactory.createRunnable(GeneralViewFlowUsageProjectData.EDITING_CONTEXT_ID, |
| 366 | + (editingContext, executeEditingContextFunctionInput) -> { |
| 367 | + var optionalConnection = this.objectSearchService.getObject(editingContext, GeneralViewFlowUsageProjectData.SemanticIds.CONNECT_ID); |
| 368 | + assertThat(optionalConnection).containsInstanceOf(ConnectionUsage.class); |
| 369 | + ConnectionUsage connection = (ConnectionUsage) optionalConnection.get(); |
| 370 | + assertThat(connection.getType()).hasSize(1); |
| 371 | + var connectionType = connection.getType().get(0); |
| 372 | + var connectionTypeId = this.identityService.getId(connectionType); |
| 373 | + assertThat(connectionTypeId).isEqualTo(GeneralViewFlowUsageProjectData.SemanticIds.HDMI_CABLE_ID); |
| 374 | + return new ExecuteEditingContextFunctionSuccessPayload(executeEditingContextFunctionInput.id(), true); |
| 375 | + }); |
| 376 | + |
| 377 | + Runnable createFlowUsageOnConnection = () -> { |
| 378 | + var selectedObjectVariable = new ToolVariable("selectedObject", GeneralViewFlowUsageProjectData.SemanticIds.VIDEO_SIGNAL_ID, ToolVariableType.OBJECT_ID); |
| 379 | + var input = new InvokeSingleClickOnDiagramElementToolInput(UUID.randomUUID(), GeneralViewFlowUsageProjectData.EDITING_CONTEXT_ID, diagramId.get(), List.of(connectionEdgeId.get()), |
| 380 | + flowCreationToolId, 0, 0, |
| 381 | + List.of(selectedObjectVariable)); |
| 382 | + var result = this.invokeSingleClickOnDiagramElementToolMutationRunner.run(input); |
| 383 | + String typename = JsonPath.read(result.data(), "$.data.invokeSingleClickOnDiagramElementTool.__typename"); |
| 384 | + assertThat(typename).isEqualTo(InvokeSingleClickOnDiagramElementToolSuccessPayload.class.getSimpleName()); |
| 385 | + List<String> messages = JsonPath.read(result.data(), "$.data.invokeSingleClickOnDiagramElementTool.messages[*].body"); |
| 386 | + assertThat(messages).hasSize(0); |
| 387 | + }; |
| 388 | + |
| 389 | + Consumer<Object> validateEffectOnLabel = assertRefreshedDiagramThat(diagram -> { |
| 390 | + var edge = new DiagramNavigator(diagram).edgeWithId(connectionEdgeId.get()).getEdge(); |
| 391 | + DiagramAssertions.assertThat(edge.getCenterLabel()).hasText("cable : HDMICable \u25b6 Flow"); |
| 392 | + }); |
| 393 | + |
| 394 | + Runnable validateSemanticEffectOfFlowCreation = this.semanticRunnableFactory.createRunnable(GeneralViewFlowUsageProjectData.EDITING_CONTEXT_ID, |
| 395 | + (editingContext, executeEditingContextFunctionInput) -> { |
| 396 | + var optionalConnection = this.objectSearchService.getObject(editingContext, GeneralViewFlowUsageProjectData.SemanticIds.CONNECT_ID); |
| 397 | + assertThat(optionalConnection).containsInstanceOf(ConnectionUsage.class); |
| 398 | + ConnectionUsage connection = (ConnectionUsage) optionalConnection.get(); |
| 399 | + // The flow usage has been created |
| 400 | + var optionalFlowUsage = connection.getOwnedFeature().stream().filter(FlowUsage.class::isInstance).map(FlowUsage.class::cast).findFirst(); |
| 401 | + assertThat(optionalFlowUsage).isPresent(); |
| 402 | + var flowUsage = optionalFlowUsage.get(); |
| 403 | + |
| 404 | + // The flow has a FeatureMembership with a PayloadFeature typed by "Video Signal" (the passed |
| 405 | + // payload) |
| 406 | + var optionalPayloadFeature = flowUsage.getOwnedFeature().stream().filter(PayloadFeature.class::isInstance).map(PayloadFeature.class::cast).findFirst(); |
| 407 | + assertThat(optionalPayloadFeature).isPresent(); |
| 408 | + var payloadFeature = optionalPayloadFeature.get(); |
| 409 | + var payloadType = ((FeatureTyping) payloadFeature.getOwnedRelationship().get(0)).getType(); |
| 410 | + assertThat(this.identityService.getId(payloadType)).isEqualTo(GeneralViewFlowUsageProjectData.SemanticIds.VIDEO_SIGNAL_ID); |
| 411 | + |
| 412 | + // The flow has two FlowEnds: one redefining HDMICable::inputSide, the other HDMICable::outputSide |
| 413 | + var flowEnds = flowUsage.getOwnedFeature().stream().filter(FlowEnd.class::isInstance).map(FlowEnd.class::cast).toList(); |
| 414 | + assertThat(flowEnds).hasSize(2); |
| 415 | + var sourceEnd = flowEnds.get(0); |
| 416 | + assertThat(sourceEnd.getOwnedFeature().get(0).getOwnedRedefinition().get(0).getRedefinedFeature().getQualifiedName()).isEqualTo("Package1::HDMICable::inputSide"); |
| 417 | + var targetEnd = flowEnds.get(1); |
| 418 | + assertThat(targetEnd.getOwnedFeature().get(0).getOwnedRedefinition().get(0).getRedefinedFeature().getQualifiedName()).isEqualTo("Package1::HDMICable::outputSide"); |
| 419 | + return new ExecuteEditingContextFunctionSuccessPayload(executeEditingContextFunctionInput.id(), true); |
| 420 | + }); |
| 421 | + |
| 422 | + StepVerifier.create(flux) |
| 423 | + .consumeNextWith(initialDiagramContentConsumer) |
| 424 | + .then(renameAndTypeTheConnection) |
| 425 | + .consumeNextWith(validateLabelEditResult) |
| 426 | + .then(validateSemanticEffectOfLabelEdit) |
| 427 | + .then(createFlowUsageOnConnection) |
| 428 | + .consumeNextWith(validateEffectOnLabel) |
| 429 | + .then(validateSemanticEffectOfFlowCreation) |
| 430 | + .thenCancel() |
| 431 | + .verify(Duration.ofSeconds(10_000)); |
| 432 | + } |
| 433 | + |
300 | 434 | } |
| 435 | +; |
0 commit comments