|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (c) 2025 Obeo. |
| 3 | + * This program and the accompanying materials |
| 4 | + * are made available under the terms of the Eclipse Public License v2.0 |
| 5 | + * which accompanies this distribution, and is available at |
| 6 | + * https://www.eclipse.org/legal/epl-2.0/ |
| 7 | + * |
| 8 | + * SPDX-License-Identifier: EPL-2.0 |
| 9 | + * |
| 10 | + * Contributors: |
| 11 | + * Obeo - initial API and implementation |
| 12 | + *******************************************************************************/ |
| 13 | +package org.eclipse.syson.application.controllers.diagrams.compartments; |
| 14 | + |
| 15 | +import static org.assertj.core.api.Assertions.assertThat; |
| 16 | +import static org.eclipse.sirius.components.diagrams.tests.DiagramEventPayloadConsumer.assertRefreshedDiagramThat; |
| 17 | + |
| 18 | +import java.time.Duration; |
| 19 | +import java.util.UUID; |
| 20 | +import java.util.concurrent.atomic.AtomicReference; |
| 21 | +import java.util.function.Consumer; |
| 22 | + |
| 23 | +import org.eclipse.sirius.components.collaborative.diagrams.dto.DiagramEventInput; |
| 24 | +import org.eclipse.sirius.components.collaborative.diagrams.dto.DiagramRefreshedEventPayload; |
| 25 | +import org.eclipse.sirius.components.diagrams.Diagram; |
| 26 | +import org.eclipse.sirius.components.diagrams.ViewModifier; |
| 27 | +import org.eclipse.sirius.components.diagrams.tests.navigation.DiagramNavigator; |
| 28 | +import org.eclipse.sirius.components.view.emf.diagram.IDiagramIdProvider; |
| 29 | +import org.eclipse.sirius.web.tests.services.api.IGivenInitialServerState; |
| 30 | +import org.eclipse.syson.AbstractIntegrationTests; |
| 31 | +import org.eclipse.syson.application.controllers.diagrams.testers.ToolTester; |
| 32 | +import org.eclipse.syson.application.data.GeneralViewWithTopNodesTestProjectData; |
| 33 | +import org.eclipse.syson.services.diagrams.DiagramDescriptionIdProvider; |
| 34 | +import org.eclipse.syson.services.diagrams.api.IGivenDiagramDescription; |
| 35 | +import org.eclipse.syson.services.diagrams.api.IGivenDiagramSubscription; |
| 36 | +import org.eclipse.syson.standard.diagrams.view.SDVDescriptionNameGenerator; |
| 37 | +import org.eclipse.syson.sysml.SysmlPackage; |
| 38 | +import org.eclipse.syson.util.IDescriptionNameGenerator; |
| 39 | +import org.eclipse.syson.util.SysONRepresentationDescriptionIdentifiers; |
| 40 | +import org.junit.jupiter.api.BeforeEach; |
| 41 | +import org.junit.jupiter.api.DisplayName; |
| 42 | +import org.junit.jupiter.api.Test; |
| 43 | +import org.springframework.beans.factory.annotation.Autowired; |
| 44 | +import org.springframework.boot.test.context.SpringBootTest; |
| 45 | +import org.springframework.test.context.jdbc.Sql; |
| 46 | +import org.springframework.test.context.jdbc.SqlConfig; |
| 47 | +import org.springframework.transaction.annotation.Transactional; |
| 48 | + |
| 49 | +import reactor.core.publisher.Flux; |
| 50 | +import reactor.test.StepVerifier; |
| 51 | + |
| 52 | +/** |
| 53 | + * Tests the Start Action inside the General View diagram. |
| 54 | + * |
| 55 | + * @author arichard |
| 56 | + */ |
| 57 | +@Transactional |
| 58 | +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) |
| 59 | +public class StartActionTests extends AbstractIntegrationTests { |
| 60 | + |
| 61 | + public static final String START_ACTION_USAGE_ID = "9a0d2905-0f9c-5bb4-af74-9780d6db1817"; |
| 62 | + |
| 63 | + @Autowired |
| 64 | + private IGivenInitialServerState givenInitialServerState; |
| 65 | + |
| 66 | + @Autowired |
| 67 | + private IGivenDiagramSubscription givenDiagramSubscription; |
| 68 | + |
| 69 | + @Autowired |
| 70 | + private IGivenDiagramDescription givenDiagramDescription; |
| 71 | + |
| 72 | + @Autowired |
| 73 | + private IDiagramIdProvider diagramIdProvider; |
| 74 | + |
| 75 | + @Autowired |
| 76 | + private ToolTester nodeCreationTester; |
| 77 | + |
| 78 | + private final IDescriptionNameGenerator descriptionNameGenerator = new SDVDescriptionNameGenerator(); |
| 79 | + |
| 80 | + private Flux<DiagramRefreshedEventPayload> givenSubscriptionToDiagram() { |
| 81 | + var diagramEventInput = new DiagramEventInput(UUID.randomUUID(), |
| 82 | + GeneralViewWithTopNodesTestProjectData.EDITING_CONTEXT_ID, |
| 83 | + GeneralViewWithTopNodesTestProjectData.GraphicalIds.DIAGRAM_ID); |
| 84 | + var flux = this.givenDiagramSubscription.subscribe(diagramEventInput); |
| 85 | + return flux; |
| 86 | + } |
| 87 | + |
| 88 | + @BeforeEach |
| 89 | + public void beforeEach() { |
| 90 | + this.givenInitialServerState.initialize(); |
| 91 | + } |
| 92 | + |
| 93 | + @DisplayName("GIVEN an ActionUsage action1, WHEN using the 'New Start Action' tool is executed on action1, THEN the action flow compartment of action1 is revealed.") |
| 94 | + @Sql(scripts = { GeneralViewWithTopNodesTestProjectData.SCRIPT_PATH }, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, |
| 95 | + config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED)) |
| 96 | + @Sql(scripts = { "/scripts/cleanup.sql" }, executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD, config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED)) |
| 97 | + @Test |
| 98 | + public void addStartNode() { |
| 99 | + var flux = this.givenSubscriptionToDiagram(); |
| 100 | + |
| 101 | + var diagramDescription = this.givenDiagramDescription.getDiagramDescription(GeneralViewWithTopNodesTestProjectData.EDITING_CONTEXT_ID, |
| 102 | + SysONRepresentationDescriptionIdentifiers.GENERAL_VIEW_DIAGRAM_DESCRIPTION_ID); |
| 103 | + var diagramDescriptionIdProvider = new DiagramDescriptionIdProvider(diagramDescription, this.diagramIdProvider); |
| 104 | + |
| 105 | + var toolId = diagramDescriptionIdProvider.getNodeCreationToolId(this.descriptionNameGenerator.getNodeName(SysmlPackage.eINSTANCE.getActionUsage()), |
| 106 | + "New Start Action"); |
| 107 | + assertThat(toolId).as("The tool 'New Start Action' should exist on ActionUsage").isNotNull(); |
| 108 | + |
| 109 | + var diagram = new AtomicReference<Diagram>(); |
| 110 | + |
| 111 | + Consumer<Object> initialDiagramContentConsumer = assertRefreshedDiagramThat(diag -> { |
| 112 | + diagram.set(diag); |
| 113 | + var actionFlowCompartmentNode = new DiagramNavigator(diag).nodeWithLabel("\u00ABref action\u00BB\naction").childNodeWithLabel("action flow").getNode(); |
| 114 | + assertThat(actionFlowCompartmentNode.getState()).isEqualTo(ViewModifier.Hidden); |
| 115 | + }); |
| 116 | + |
| 117 | + Runnable invokeTool = () -> { |
| 118 | + this.nodeCreationTester.invokeTool(GeneralViewWithTopNodesTestProjectData.EDITING_CONTEXT_ID, diagram, "action", toolId); |
| 119 | + }; |
| 120 | + |
| 121 | + Consumer<Object> updatedDiagramConsumer = assertRefreshedDiagramThat(diag -> { |
| 122 | + var actionFlowCompartmentNode = new DiagramNavigator(diag).nodeWithLabel("\u00ABref action\u00BB\naction").childNodeWithLabel("action flow").getNode(); |
| 123 | + assertThat(actionFlowCompartmentNode.getState()).isEqualTo(ViewModifier.Normal); |
| 124 | + var startNode = new DiagramNavigator(diag).nodeWithLabel("\u00ABref action\u00BB\naction").childNodeWithLabel("action flow").childNodeWithTargetObjectId(START_ACTION_USAGE_ID).getNode(); |
| 125 | + assertThat(startNode).isNotNull(); |
| 126 | + |
| 127 | + }); |
| 128 | + |
| 129 | + StepVerifier.create(flux) |
| 130 | + .consumeNextWith(initialDiagramContentConsumer) |
| 131 | + .then(invokeTool) |
| 132 | + .consumeNextWith(updatedDiagramConsumer) |
| 133 | + .thenCancel() |
| 134 | + .verify(Duration.ofSeconds(100)); |
| 135 | + } |
| 136 | +} |
0 commit comments