Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*******************************************************************************
* Copyright (c) 2026 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/

package org.eclipse.syson.application.data;

/**
* Project data for the "ControlNodesInDiagramsMigrationTest" project.
*
* @author Jerome Gout
*/
public class ControlNodesInDiagramsMigrationTestProjectData {

public static final String SCRIPT_PATH = "/scripts/database-content/ControlNodesInDiagrams.sql";

public static final String EDITING_CONTEXT_ID = "0587c01d-3b19-483b-a882-8dac04caf36d";

/**
* Ids of graphical elements.
*/
public static final class GraphicalIds {

public static final String AFV_DIAGRAM_ID = "da056bd0-daf8-4dae-b171-bff0344a9aa1";

public static final String AFV_DECISION_DEC_NODE_ID = "7881822d-b37d-3d82-9066-db0933a04c2a";

public static final String AFV_FORK_FOR_NODE_ID = "bb0a308c-7aad-3334-9c22-ee030fd0ee57";

public static final String AFV_JOIN_JOI_NODE_ID = "01ad3207-6bf3-3e68-9c39-4838859f9f63";

public static final String AFV_MERGE_MER_NODE_ID = "dcb67d1a-45e6-3d0c-9f72-2f2857e0b990";

public static final String AVF_ACTION_ACT_NODE_ID = "36b62773-91f0-308d-9d89-f02394e5a902";

public static final String AVF_ACTION_ACT_NODE_ID_2 = "e0ff2f36-1ecf-3546-aff4-d1319470bf55";

public static final String GV_DIAGRAM_ID = "ed4fd9a8-d28a-4289-9f5d-d913c8f05fc7";

public static final String DECISION_NODE_DEC_NODE_ID = "fd687edb-6df5-300f-9293-eface179e04e";

public static final String FORK_NODE_FOR_NODE_ID = "dd4e1b79-9fe7-30c3-9654-81331715843d";

public static final String JOIN_NODE_JOI_NODE_ID = "98a83e02-7ba8-3c64-b624-570353d10187";

public static final String MERGE_NODE_MER_NODE_ID = "acdcbacd-a914-3e8d-a4de-80dc873b9661";

public static final String ROOT_ACT_EDGE_ID = "e2712b10-a422-3a0a-832b-94f86a5dfb0a";

public static final String ROOT_ACT_NODE_ID = "c14e500e-1d29-3ef4-adc7-388dbe1cc829";

public static final String ROOT_ACT_NODE_ID_2 = "da560fc0-ad03-347f-b9fa-35ba895786c8";

public static final String START_NODE_ID = "2831f45f-b0de-3ce7-bc42-3b66e247da68";

public static final String DONE_NODE_ID = "e2ec47ac-8a86-3773-b1f2-234822645444";

public static final String SUB_ACT_NODE_ID = "c7e90ac1-8f57-3ea9-8bc4-7fb983fb57a6";

}

/**
* Ids for the semantic elements.
*/
public static final class SemanticIds {

public static final String NAMESPACE_NAM_ID = "aa604d06-c6d3-42f3-8fac-7913e933e15e";

public static final String PACKAGE1_PAC_ID = "b13a41b4-432a-42f4-9037-a81e79b94365";

public static final String AFV_VIE_ID = "105dcb5b-73ed-470d-9aa4-3bedaa7389e5";

public static final String AFV_DECISION_DEC_ID = "9ec724f5-e43f-445c-b03a-592bd292301f";

public static final String AFV_FORK_FOR_ID = "632936b3-d382-4ca0-9995-6ee0c07f3921";

public static final String AFV_JOIN_JOI_ID = "1a9f0c73-0a26-4035-ae16-4fe802dbbf27";

public static final String AFV_MERGE_MER_ID = "7d4511fa-2b43-4ebf-87c5-a7b574ae6b25";

public static final String AFV_ROOT_ACT_ID = "d3ff6f21-7617-4b85-8fb4-47cee729df47";

public static final String AVF_ACTION_ACT_ID = "eb7ee773-59c3-4e03-8b39-c642554784b0";

public static final String DECISION_NODE_DEC_ID = "3645c2c8-0e59-449f-bc1f-675e0a4fe43d";

public static final String FORK_NODE_FOR_ID = "bb96d220-9dc5-4fe5-beb1-a097b5b486b8";

public static final String GV_VIE_ID = "942a41ca-51a9-42a9-9b8f-0e6847f790c5";

public static final String JOIN_NODE_JOI_ID = "ba0418a4-efb7-4ef2-b4fc-7cb3668007ea";

public static final String MERGE_NODE_MER_ID = "c431fcd0-6543-41bf-bba2-9d3ea59bce12";

public static final String ROOT_ACT_ID = "609678ac-2335-410b-9dba-722503ecbbdd";

public static final String SUB_ACT_ID = "f2d5cb3f-1900-4b11-bc84-cae6ac42dd6e";

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
/*******************************************************************************
* Copyright (c) 2026 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/

package org.eclipse.syson.application.migration;

import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.sirius.components.diagrams.tests.DiagramEventPayloadConsumer.assertRefreshedDiagramThat;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.time.Duration;
import java.util.UUID;
import java.util.function.Consumer;

import org.eclipse.sirius.components.collaborative.diagrams.dto.DiagramEventInput;
import org.eclipse.sirius.components.collaborative.diagrams.dto.DiagramRefreshedEventPayload;
import org.eclipse.sirius.components.diagrams.ViewModifier;
import org.eclipse.sirius.web.tests.services.api.IGivenInitialServerState;
import org.eclipse.syson.AbstractIntegrationTests;
import org.eclipse.syson.GivenSysONServer;
import org.eclipse.syson.application.controller.editingcontext.checkers.SemanticCheckerService;
import org.eclipse.syson.application.data.ControlNodesInDiagramsMigrationTestProjectData;
import org.eclipse.syson.services.diagrams.api.IGivenDiagramSubscription;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;

import reactor.core.publisher.Flux;
import reactor.test.StepVerifier;

/**
* Test that old diagrams (GV and AFV) with control nodes (Decision, Fork, Join, Merge) open with the same visual content as before.
* Due to the addition of new mappings for control nodes at the diagram level, when opening existing diagrams containing control nodes,
* we want the top-level control nodes to remain hidden, as they were before.
*
* @author Jerome Gout
*/
@Transactional
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class ControlNodesInDiagramsMigrationTest extends AbstractIntegrationTests {

@Autowired
private IGivenInitialServerState givenInitialServerState;

@Autowired
private IGivenDiagramSubscription givenDiagramSubscription;

private SemanticCheckerService semanticCheckerService;

private Flux<DiagramRefreshedEventPayload> givenSubscriptionToGVDiagram() {
var diagramEventInput = new DiagramEventInput(UUID.randomUUID(), ControlNodesInDiagramsMigrationTestProjectData.EDITING_CONTEXT_ID, ControlNodesInDiagramsMigrationTestProjectData.GraphicalIds.GV_DIAGRAM_ID);
return this.givenDiagramSubscription.subscribe(diagramEventInput);
}

private Flux<DiagramRefreshedEventPayload> givenSubscriptionToAFVDiagram() {
var diagramEventInput = new DiagramEventInput(UUID.randomUUID(), ControlNodesInDiagramsMigrationTestProjectData.EDITING_CONTEXT_ID, ControlNodesInDiagramsMigrationTestProjectData.GraphicalIds.AFV_DIAGRAM_ID);
return this.givenDiagramSubscription.subscribe(diagramEventInput);
}

@BeforeEach
public void setUp() {
this.givenInitialServerState.initialize();
}

@DisplayName("GIVEN a project with a GV diagram containing control nodes, WHEN the model is loaded, THEN new extra control nodes are hidden")
@GivenSysONServer({ ControlNodesInDiagramsMigrationTestProjectData.SCRIPT_PATH })
@Test
public void givenAProjectWithAGVDiagramContainingControlNodesWhenTheModelIsLoadedThenNewExtraControlNodesAreHidden() {
var flux = this.givenSubscriptionToGVDiagram();

Consumer<Object> initialDiagramContentConsumer = assertRefreshedDiagramThat(diagram -> {
// the diagram background contains 6 nodes, a visible root action, a sub action which is hidden and 4 hidden control nodes
var rootNodes = diagram.getNodes();
assertEquals(6, rootNodes.size());
var rootActionNode = rootNodes.stream()
.filter(node -> ControlNodesInDiagramsMigrationTestProjectData.SemanticIds.ROOT_ACT_ID.equals(node.getTargetObjectId()))
.findFirst();
var subActionNode = rootNodes.stream()
.filter(node -> ControlNodesInDiagramsMigrationTestProjectData.SemanticIds.SUB_ACT_ID.equals(node.getTargetObjectId()))
.findFirst();
var subDecisionNode = rootNodes.stream()
.filter(node -> ControlNodesInDiagramsMigrationTestProjectData.SemanticIds.DECISION_NODE_DEC_ID.equals(node.getTargetObjectId()))
.findFirst();
var subForkNode = rootNodes.stream()
.filter(node -> ControlNodesInDiagramsMigrationTestProjectData.SemanticIds.FORK_NODE_FOR_ID.equals(node.getTargetObjectId()))
.findFirst();
var subJoinNode = rootNodes.stream()
.filter(node -> ControlNodesInDiagramsMigrationTestProjectData.SemanticIds.JOIN_NODE_JOI_ID.equals(node.getTargetObjectId()))
.findFirst();
var subMergeNode = rootNodes.stream()
.filter(node -> ControlNodesInDiagramsMigrationTestProjectData.SemanticIds.MERGE_NODE_MER_ID.equals(node.getTargetObjectId()))
.findFirst();
assertThat(rootActionNode).isPresent();
assertThat(rootActionNode.get().getState()).isEqualTo(ViewModifier.Normal);
assertThat(subActionNode).isPresent();
assertThat(subActionNode.get().getState()).isEqualTo(ViewModifier.Hidden);
assertThat(subDecisionNode).isPresent();
assertThat(subDecisionNode.get().getState()).isEqualTo(ViewModifier.Hidden);
assertThat(subForkNode).isPresent();
assertThat(subForkNode.get().getState()).isEqualTo(ViewModifier.Hidden);
assertThat(subJoinNode).isPresent();
assertThat(subJoinNode.get().getState()).isEqualTo(ViewModifier.Hidden);
assertThat(subMergeNode).isPresent();
assertThat(subMergeNode.get().getState()).isEqualTo(ViewModifier.Hidden);
});

StepVerifier.create(flux)
.consumeNextWith(initialDiagramContentConsumer)
.thenCancel()
.verify(Duration.ofSeconds(10));

}

@DisplayName("GIVEN a project with a AFV diagram containing control nodes, WHEN the model is loaded, THEN new extra control nodes are hidden")
@GivenSysONServer({ ControlNodesInDiagramsMigrationTestProjectData.SCRIPT_PATH })
@Test
public void givenAProjectWithAAFVDiagramContainingControlNodesWhenTheModelIsLoadedThenNewExtraControlNodesAreHidden() {
var flux = this.givenSubscriptionToAFVDiagram();

Consumer<Object> initialDiagramContentConsumer = assertRefreshedDiagramThat(diagram -> {
// the AFV diagram background contains 5 nodes, a visible root action and 4 control nodes which must be hidden
var rootNodes = diagram.getNodes();
assertEquals(5, rootNodes.size());
var avfActionNode = rootNodes.stream()
.filter(node -> ControlNodesInDiagramsMigrationTestProjectData.SemanticIds.AVF_ACTION_ACT_ID.equals(node.getTargetObjectId()))
.findFirst();
var afvDecisionNode = rootNodes.stream()
.filter(node -> ControlNodesInDiagramsMigrationTestProjectData.SemanticIds.AFV_DECISION_DEC_ID.equals(node.getTargetObjectId()))
.findFirst();
var afvForkNode = rootNodes.stream()
.filter(node -> ControlNodesInDiagramsMigrationTestProjectData.SemanticIds.AFV_FORK_FOR_ID.equals(node.getTargetObjectId()))
.findFirst();
var afvJoinNode = rootNodes.stream()
.filter(node -> ControlNodesInDiagramsMigrationTestProjectData.SemanticIds.AFV_JOIN_JOI_ID.equals(node.getTargetObjectId()))
.findFirst();
var afvMergeNode = rootNodes.stream()
.filter(node -> ControlNodesInDiagramsMigrationTestProjectData.SemanticIds.AFV_MERGE_MER_ID.equals(node.getTargetObjectId()))
.findFirst();
assertThat(avfActionNode).isPresent();
assertThat(avfActionNode.get().getState()).isEqualTo(ViewModifier.Normal);
assertThat(afvDecisionNode).isPresent();
assertThat(afvDecisionNode.get().getState()).isEqualTo(ViewModifier.Hidden);
assertThat(afvForkNode).isPresent();
assertThat(afvForkNode.get().getState()).isEqualTo(ViewModifier.Hidden);
assertThat(afvJoinNode).isPresent();
assertThat(afvJoinNode.get().getState()).isEqualTo(ViewModifier.Hidden);
assertThat(afvMergeNode).isPresent();
assertThat(afvMergeNode.get().getState()).isEqualTo(ViewModifier.Hidden);
});

StepVerifier.create(flux)
.consumeNextWith(initialDiagramContentConsumer)
.thenCancel()
.verify(Duration.ofSeconds(10));

}

}
Loading
Loading