|
| 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.general.view; |
| 14 | + |
| 15 | +import java.time.Duration; |
| 16 | +import java.util.ArrayList; |
| 17 | +import java.util.List; |
| 18 | +import java.util.UUID; |
| 19 | +import java.util.concurrent.atomic.AtomicReference; |
| 20 | + |
| 21 | +import org.eclipse.sirius.components.collaborative.diagrams.dto.DiagramEventInput; |
| 22 | +import org.eclipse.sirius.components.collaborative.diagrams.dto.DiagramRefreshedEventPayload; |
| 23 | +import org.eclipse.sirius.components.collaborative.diagrams.dto.ToolVariable; |
| 24 | +import org.eclipse.sirius.components.collaborative.diagrams.dto.ToolVariableType; |
| 25 | +import org.eclipse.sirius.components.diagrams.Diagram; |
| 26 | +import org.eclipse.sirius.components.view.emf.diagram.IDiagramIdProvider; |
| 27 | +import org.eclipse.sirius.web.tests.services.api.IGivenInitialServerState; |
| 28 | +import org.eclipse.syson.AbstractIntegrationTests; |
| 29 | +import org.eclipse.syson.SysONTestsProperties; |
| 30 | +import org.eclipse.syson.application.controllers.diagrams.checkers.CheckDiagramElementCount; |
| 31 | +import org.eclipse.syson.application.controllers.diagrams.checkers.DiagramCheckerService; |
| 32 | +import org.eclipse.syson.application.controllers.diagrams.checkers.IDiagramChecker; |
| 33 | +import org.eclipse.syson.application.controllers.diagrams.testers.NodeCreationTester; |
| 34 | +import org.eclipse.syson.application.data.GeneralViewWithTopNodesTestProjectData; |
| 35 | +import org.eclipse.syson.application.data.SysONRepresentationDescriptionIdentifiers; |
| 36 | +import org.eclipse.syson.diagram.general.view.GVDescriptionNameGenerator; |
| 37 | +import org.eclipse.syson.services.diagrams.DiagramComparator; |
| 38 | +import org.eclipse.syson.services.diagrams.DiagramDescriptionIdProvider; |
| 39 | +import org.eclipse.syson.services.diagrams.api.IGivenDiagramDescription; |
| 40 | +import org.eclipse.syson.services.diagrams.api.IGivenDiagramReference; |
| 41 | +import org.eclipse.syson.services.diagrams.api.IGivenDiagramSubscription; |
| 42 | +import org.eclipse.syson.sysml.ActionDefinition; |
| 43 | +import org.eclipse.syson.sysml.SysmlPackage; |
| 44 | +import org.eclipse.syson.util.IDescriptionNameGenerator; |
| 45 | +import org.junit.jupiter.api.AfterEach; |
| 46 | +import org.junit.jupiter.api.BeforeEach; |
| 47 | +import org.junit.jupiter.api.DisplayName; |
| 48 | +import org.junit.jupiter.api.Test; |
| 49 | +import org.springframework.beans.factory.annotation.Autowired; |
| 50 | +import org.springframework.boot.test.context.SpringBootTest; |
| 51 | +import org.springframework.test.context.jdbc.Sql; |
| 52 | +import org.springframework.test.context.jdbc.SqlConfig; |
| 53 | +import org.springframework.transaction.annotation.Transactional; |
| 54 | + |
| 55 | +import reactor.test.StepVerifier; |
| 56 | + |
| 57 | +/** |
| 58 | + * Tests the {@link ActionDefinition} inherited features behavior with parameters compartment. |
| 59 | + * |
| 60 | + * @author fbarbin |
| 61 | + */ |
| 62 | +@Transactional |
| 63 | +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = { SysONTestsProperties.NO_DEFAULT_LIBRARIES_PROPERTY }) |
| 64 | +public class GVActionDefinitionParameterTests extends AbstractIntegrationTests { |
| 65 | + |
| 66 | + |
| 67 | + private final IDescriptionNameGenerator descriptionNameGenerator = new GVDescriptionNameGenerator(); |
| 68 | + |
| 69 | + @Autowired |
| 70 | + private IGivenInitialServerState givenInitialServerState; |
| 71 | + |
| 72 | + @Autowired |
| 73 | + private IGivenDiagramReference givenDiagram; |
| 74 | + |
| 75 | + @Autowired |
| 76 | + private IGivenDiagramDescription givenDiagramDescription; |
| 77 | + |
| 78 | + @Autowired |
| 79 | + private IGivenDiagramSubscription givenDiagramSubscription; |
| 80 | + |
| 81 | + @Autowired |
| 82 | + private IDiagramIdProvider diagramIdProvider; |
| 83 | + |
| 84 | + @Autowired |
| 85 | + private NodeCreationTester nodeCreationTester; |
| 86 | + |
| 87 | + @Autowired |
| 88 | + private DiagramComparator diagramComparator; |
| 89 | + |
| 90 | + private DiagramDescriptionIdProvider diagramDescriptionIdProvider; |
| 91 | + |
| 92 | + private DiagramCheckerService diagramCheckerService; |
| 93 | + |
| 94 | + private StepVerifier.Step<DiagramRefreshedEventPayload> verifier; |
| 95 | + |
| 96 | + private AtomicReference<Diagram> diagram; |
| 97 | + |
| 98 | + @BeforeEach |
| 99 | + public void setUp() { |
| 100 | + this.givenInitialServerState.initialize(); |
| 101 | + var diagramEventInput = new DiagramEventInput(UUID.randomUUID(), |
| 102 | + GeneralViewWithTopNodesTestProjectData.EDITING_CONTEXT_ID, |
| 103 | + GeneralViewWithTopNodesTestProjectData.GraphicalIds.DIAGRAM_ID); |
| 104 | + var flux = this.givenDiagramSubscription.subscribe(diagramEventInput); |
| 105 | + this.verifier = StepVerifier.create(flux); |
| 106 | + this.diagram = this.givenDiagram.getDiagram(this.verifier); |
| 107 | + var diagramDescription = this.givenDiagramDescription.getDiagramDescription(GeneralViewWithTopNodesTestProjectData.EDITING_CONTEXT_ID, |
| 108 | + SysONRepresentationDescriptionIdentifiers.GENERAL_VIEW_DIAGRAM_DESCRIPTION_ID); |
| 109 | + this.diagramDescriptionIdProvider = new DiagramDescriptionIdProvider(diagramDescription, this.diagramIdProvider); |
| 110 | + this.diagramCheckerService = new DiagramCheckerService(this.diagramComparator, this.descriptionNameGenerator); |
| 111 | + } |
| 112 | + |
| 113 | + @AfterEach |
| 114 | + public void tearDown() { |
| 115 | + if (this.verifier != null) { |
| 116 | + this.verifier.thenCancel() |
| 117 | + .verify(Duration.ofSeconds(10)); |
| 118 | + } |
| 119 | + } |
| 120 | + |
| 121 | + @DisplayName("Given a SysML Project with an ActionDefinition that generalizes a UseCaseDefinition, when creating a subject in the UseCaseDefinition, then it should not be displayed in the ActionDefinition parameters compartment") |
| 122 | + @Sql(scripts = { GeneralViewWithTopNodesTestProjectData.SCRIPT_PATH }, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) |
| 123 | + @Sql(scripts = { "/scripts/cleanup.sql" }, executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD, config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED)) |
| 124 | + @Test |
| 125 | + public void checkActionDefinitionInParameter() { |
| 126 | + this.checkItemParameterOnActionDefinition("In"); |
| 127 | + } |
| 128 | + |
| 129 | + private void checkItemParameterOnActionDefinition(String kind) { |
| 130 | + List<ToolVariable> variables = new ArrayList<>(); |
| 131 | + variables.add(new ToolVariable("selectedObject", GeneralViewWithTopNodesTestProjectData.SemanticIds.PART_USAGE_ID, ToolVariableType.OBJECT_ID)); |
| 132 | + |
| 133 | + String creationToolId = this.diagramDescriptionIdProvider.getNodeCreationToolId(this.descriptionNameGenerator.getNodeName(SysmlPackage.eINSTANCE.getUseCaseDefinition()), "New Subject"); |
| 134 | + this.verifier.then(() -> this.nodeCreationTester.createNode(GeneralViewWithTopNodesTestProjectData.EDITING_CONTEXT_ID, this.diagram, "UseCaseDefinition", creationToolId, variables)); |
| 135 | + |
| 136 | + IDiagramChecker diagramChecker = (initialDiagram, newDiagram) -> { |
| 137 | + new CheckDiagramElementCount(this.diagramComparator) |
| 138 | + .hasNewBorderNodeCount(0) |
| 139 | + .hasNewNodeCount(1) // Only one subject in the UseCaseDefinition subjects compartment. |
| 140 | + .hasNewEdgeCount(0) |
| 141 | + .check(initialDiagram, newDiagram); |
| 142 | + |
| 143 | + }; |
| 144 | + |
| 145 | + this.diagramCheckerService.checkDiagram(diagramChecker, this.diagram, this.verifier); |
| 146 | + } |
| 147 | +} |
0 commit comments