Skip to content
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

=== New features

- https://github.com/eclipse-syson/syson/issues/1581[#1581] [diagrams] Display inherited `PortUsages` as border nodes in diagrams

== v2025.10.0

=== Breaking changes
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*******************************************************************************
* Copyright (c) 2025 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.controllers.diagrams.general.view;

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

import com.jayway.jsonpath.JsonPath;

import java.time.Duration;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;
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.tests.navigation.DiagramNavigator;
import org.eclipse.sirius.web.tests.services.api.IGivenInitialServerState;
import org.eclipse.syson.AbstractIntegrationTests;
import org.eclipse.syson.application.controllers.diagrams.graphql.ShowDiagramsInheritedMembersMutationRunner;
import org.eclipse.syson.application.data.GeneralViewInheritedPortTestProjectData;
import org.eclipse.syson.diagram.common.view.services.dto.ShowDiagramsInheritedMembersInput;
import org.eclipse.syson.diagram.common.view.services.dto.ShowDiagramsInheritedMembersSuccessPayload;
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.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.SqlConfig;
import org.springframework.transaction.annotation.Transactional;

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

/**
* Tests the display of inherited ports inside the General View diagram.
*
* @author frouene
*/
@Transactional
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class GVInheritedPortTests extends AbstractIntegrationTests {

@Autowired
private IGivenInitialServerState givenInitialServerState;

@Autowired
private IGivenDiagramSubscription givenDiagramSubscription;

@Autowired
private ShowDiagramsInheritedMembersMutationRunner showDiagramsInheritedMembersMutationRunner;

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

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

@DisplayName("GIVEN a diagram with some inherited port, WHEN show inherited members filter is uncheck, THEN inherited ports are not displayed")
@Sql(scripts = { GeneralViewInheritedPortTestProjectData.SCRIPT_PATH }, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD,
config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED))
@Sql(scripts = { "/scripts/cleanup.sql" }, executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD, config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED))
@Test
public void checkInheritedPortsVisibility() {
var flux = this.givenSubscriptionToDiagram();

var diagramId = new AtomicReference<String>();

Consumer<Object> initialDiagramContentConsumer = assertRefreshedDiagramThat(diagram -> {
diagramId.set(diagram.getId());
var part2Node = new DiagramNavigator(diagram).nodeWithLabel("«part»\npart2").getNode();
assertThat(part2Node.getBorderNodes()).hasSize(1);
assertThat(part2Node.getBorderNodes()).allMatch(node -> node.getOutsideLabels().get(0).text().equals("port1"));
var v1Node = new DiagramNavigator(diagram).nodeWithLabel("«part»\nv1 : Vehicle").getNode();
assertThat(v1Node.getBorderNodes()).hasSize(1);
assertThat(v1Node.getBorderNodes()).allMatch(node -> node.getOutsideLabels().get(0).text().equals("^fuelInPort : FuelPort"));
});

Runnable uncheckShowInheritedMembersFilter = () -> {
var input = new ShowDiagramsInheritedMembersInput(
UUID.randomUUID(),
GeneralViewInheritedPortTestProjectData.EDITING_CONTEXT_ID,
diagramId.get(),
false);
var result = this.showDiagramsInheritedMembersMutationRunner.run(input);
String typename = JsonPath.read(result, "$.data.showDiagramsInheritedMembers.__typename");
assertThat(typename).isEqualTo(ShowDiagramsInheritedMembersSuccessPayload.class.getSimpleName());
};

Consumer<Object> updatedDiagramContentConsumerAfterInheritedVisibilityChange = assertRefreshedDiagramThat(diagram -> {
var part2Node = new DiagramNavigator(diagram).nodeWithLabel("«part»\npart2").getNode();
assertThat(part2Node.getBorderNodes()).hasSize(1);
var v1Node = new DiagramNavigator(diagram).nodeWithLabel("«part»\nv1 : Vehicle").getNode();
assertThat(v1Node.getBorderNodes()).hasSize(0);
});

StepVerifier.create(flux)
.consumeNextWith(initialDiagramContentConsumer)
.then(uncheckShowInheritedMembersFilter)
.consumeNextWith(updatedDiagramContentConsumerAfterInheritedVisibilityChange)
.thenCancel()
.verify(Duration.ofSeconds(10));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*******************************************************************************
* Copyright (c) 2025 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.controllers.diagrams.graphql;

import java.util.Objects;

import org.eclipse.sirius.components.core.api.IInput;
import org.eclipse.sirius.components.graphql.tests.api.IGraphQLRequestor;
import org.eclipse.sirius.components.graphql.tests.api.IMutationRunner;
import org.springframework.stereotype.Service;

/**
* Used to show diagram inherited members with the GraphQL API.
*
* @author frouene
*/
@Service
public class ShowDiagramsInheritedMembersMutationRunner implements IMutationRunner<IInput> {

private static final String SHOW_DIAGRAM_INHERITED_MEMBERS_MUTATION = """
mutation showDiagramsInheritedMembers($input: ShowDiagramsInheritedMembersInput!) {
showDiagramsInheritedMembers(input: $input) {
__typename
... on ShowDiagramsInheritedMembersSuccessPayload {
show
}
... on ErrorPayload {
message
}
}
}
""";

private final IGraphQLRequestor graphQLRequestor;

public ShowDiagramsInheritedMembersMutationRunner(IGraphQLRequestor graphQLRequestor) {
this.graphQLRequestor = Objects.requireNonNull(graphQLRequestor);
}

@Override
public String run(IInput input) {
return this.graphQLRequestor.execute(SHOW_DIAGRAM_INHERITED_MEMBERS_MUTATION, input);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*******************************************************************************
* Copyright (c) 2025 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;

/**
* Identifiers for "GeneralView-InheritedPort" project.
*
* @author frouene
*/
public class GeneralViewInheritedPortTestProjectData {

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

public static final String EDITING_CONTEXT_ID = "c3b348b0-548e-4bee-b039-925a0a9eece0";

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

public static final String DIAGRAM_ID = "d10ee99f-f2cf-4182-a614-e620e885f55f";

}

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

}

}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ protected String getBorderNodeName(String prefix, String type) {
return this.getName(prefix, "BorderNode", type);
}

protected String getInheritedBorderNodeName(String prefix, String type) {
return this.getName(prefix, "InheritedBorderNode", type);
}

protected String getCompartmentName(String prefix, String suffix) {
return this.getName(prefix, "Compartment", suffix);
}
Expand Down Expand Up @@ -175,6 +179,19 @@ public String getBorderNodeName(EClass eClass) {
return this.getBorderNodeName(this.getDiagramPrefix(), eClass.getName());
}

/**
* Returns the name of an inherited border {@link NodeDescription} starting with the diagram prefix and followed by the name of
* the given {@link EClass}.
*
* @param eClass
* the {@link EClass} used to compute the name of the border {@link NodeDescription}.
* @return a string starting with the diagram prefix and followed by the name of the given {@link EClass}
*/
@Override
public String getInheritedBorderNodeName(EClass eClass) {
return this.getInheritedBorderNodeName(this.getDiagramPrefix(), eClass.getName());
}

/**
* Returns the name of a compartment {@link NodeDescription} starting with the diagram prefix, followed by the name
* of the given {@link EClass} and the name of the given {@link EReference}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ default String getCreationToolName(EReference eReference) {
*/
String getBorderNodeName(EClass eClass);

/**
* Returns the name of an inherited border {@link NodeDescription} using the given {@link EClass}.
*
* @param eClass
* the {@link EClass} used to compute the name of the border {@link NodeDescription}.
* @return a string used to name an inherited border {@link NodeDescription}.
*/
String getInheritedBorderNodeName(EClass eClass);

/**
* Returns the name of a compartment {@link NodeDescription} using the given {@link EClass} and {@link EReference}.
*
Expand Down
Loading
Loading