|
| 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 static org.assertj.core.api.Assertions.assertThat; |
| 16 | +import static org.eclipse.sirius.components.diagrams.tests.DiagramEventPayloadConsumer.assertRefreshedDiagramThat; |
| 17 | + |
| 18 | +import com.jayway.jsonpath.JsonPath; |
| 19 | + |
| 20 | +import java.time.Duration; |
| 21 | +import java.util.UUID; |
| 22 | +import java.util.concurrent.atomic.AtomicReference; |
| 23 | +import java.util.function.Consumer; |
| 24 | + |
| 25 | +import org.eclipse.sirius.components.collaborative.diagrams.dto.DiagramEventInput; |
| 26 | +import org.eclipse.sirius.components.collaborative.diagrams.dto.DiagramRefreshedEventPayload; |
| 27 | +import org.eclipse.sirius.components.diagrams.tests.navigation.DiagramNavigator; |
| 28 | +import org.eclipse.sirius.web.tests.services.api.IGivenInitialServerState; |
| 29 | +import org.eclipse.syson.AbstractIntegrationTests; |
| 30 | +import org.eclipse.syson.application.controllers.diagrams.graphql.ShowDiagramsInheritedMembersMutationRunner; |
| 31 | +import org.eclipse.syson.application.data.GeneralViewInheritedPortTestProjectData; |
| 32 | +import org.eclipse.syson.diagram.common.view.services.dto.ShowDiagramsInheritedMembersInput; |
| 33 | +import org.eclipse.syson.diagram.common.view.services.dto.ShowDiagramsInheritedMembersSuccessPayload; |
| 34 | +import org.eclipse.syson.services.diagrams.api.IGivenDiagramSubscription; |
| 35 | +import org.junit.jupiter.api.BeforeEach; |
| 36 | +import org.junit.jupiter.api.DisplayName; |
| 37 | +import org.junit.jupiter.api.Test; |
| 38 | +import org.springframework.beans.factory.annotation.Autowired; |
| 39 | +import org.springframework.boot.test.context.SpringBootTest; |
| 40 | +import org.springframework.test.context.jdbc.Sql; |
| 41 | +import org.springframework.test.context.jdbc.SqlConfig; |
| 42 | +import org.springframework.transaction.annotation.Transactional; |
| 43 | + |
| 44 | +import reactor.core.publisher.Flux; |
| 45 | +import reactor.test.StepVerifier; |
| 46 | + |
| 47 | +/** |
| 48 | + * Tests the display of inherited ports inside the General View diagram. |
| 49 | + * |
| 50 | + * @author frouene |
| 51 | + */ |
| 52 | +@Transactional |
| 53 | +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) |
| 54 | +public class GVInheritedPortTests extends AbstractIntegrationTests { |
| 55 | + |
| 56 | + @Autowired |
| 57 | + private IGivenInitialServerState givenInitialServerState; |
| 58 | + |
| 59 | + @Autowired |
| 60 | + private IGivenDiagramSubscription givenDiagramSubscription; |
| 61 | + |
| 62 | + @Autowired |
| 63 | + private ShowDiagramsInheritedMembersMutationRunner showDiagramsInheritedMembersMutationRunner; |
| 64 | + |
| 65 | + private Flux<DiagramRefreshedEventPayload> givenSubscriptionToDiagram() { |
| 66 | + var diagramEventInput = new DiagramEventInput(UUID.randomUUID(), |
| 67 | + GeneralViewInheritedPortTestProjectData.EDITING_CONTEXT_ID, |
| 68 | + GeneralViewInheritedPortTestProjectData.GraphicalIds.DIAGRAM_ID); |
| 69 | + return this.givenDiagramSubscription.subscribe(diagramEventInput); |
| 70 | + } |
| 71 | + |
| 72 | + @BeforeEach |
| 73 | + public void beforeEach() { |
| 74 | + this.givenInitialServerState.initialize(); |
| 75 | + } |
| 76 | + |
| 77 | + @DisplayName("GIVEN a diagram with some inherited port, WHEN show inherited members filter is uncheck, THEN inherited ports are not displayed") |
| 78 | + @Sql(scripts = { GeneralViewInheritedPortTestProjectData.SCRIPT_PATH }, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, |
| 79 | + config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED)) |
| 80 | + @Sql(scripts = { "/scripts/cleanup.sql" }, executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD, config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED)) |
| 81 | + @Test |
| 82 | + public void checkInheritedPortsVisibility() { |
| 83 | + var flux = this.givenSubscriptionToDiagram(); |
| 84 | + |
| 85 | + var diagramId = new AtomicReference<String>(); |
| 86 | + |
| 87 | + Consumer<Object> initialDiagramContentConsumer = assertRefreshedDiagramThat(diagram -> { |
| 88 | + diagramId.set(diagram.getId()); |
| 89 | + var part2Node = new DiagramNavigator(diagram).nodeWithLabel("«part»\npart2").getNode(); |
| 90 | + assertThat(part2Node.getBorderNodes()).hasSize(1); |
| 91 | + assertThat(part2Node.getBorderNodes()).allMatch(node -> node.getOutsideLabels().get(0).text().equals("port1")); |
| 92 | + var v1Node = new DiagramNavigator(diagram).nodeWithLabel("«part»\nv1 : Vehicle").getNode(); |
| 93 | + assertThat(v1Node.getBorderNodes()).hasSize(1); |
| 94 | + assertThat(v1Node.getBorderNodes()).allMatch(node -> node.getOutsideLabels().get(0).text().equals("^fuelInPort : FuelPort")); |
| 95 | + }); |
| 96 | + |
| 97 | + Runnable uncheckShowInheritedMembersFilter = () -> { |
| 98 | + var input = new ShowDiagramsInheritedMembersInput( |
| 99 | + UUID.randomUUID(), |
| 100 | + GeneralViewInheritedPortTestProjectData.EDITING_CONTEXT_ID, |
| 101 | + diagramId.get(), |
| 102 | + false); |
| 103 | + var result = this.showDiagramsInheritedMembersMutationRunner.run(input); |
| 104 | + String typename = JsonPath.read(result, "$.data.showDiagramsInheritedMembers.__typename"); |
| 105 | + assertThat(typename).isEqualTo(ShowDiagramsInheritedMembersSuccessPayload.class.getSimpleName()); |
| 106 | + }; |
| 107 | + |
| 108 | + Consumer<Object> updatedDiagramContentConsumerAfterInheritedVisibilityChange = assertRefreshedDiagramThat(diagram -> { |
| 109 | + var part2Node = new DiagramNavigator(diagram).nodeWithLabel("«part»\npart2").getNode(); |
| 110 | + assertThat(part2Node.getBorderNodes()).hasSize(1); |
| 111 | + var v1Node = new DiagramNavigator(diagram).nodeWithLabel("«part»\nv1 : Vehicle").getNode(); |
| 112 | + assertThat(v1Node.getBorderNodes()).hasSize(0); |
| 113 | + }); |
| 114 | + |
| 115 | + StepVerifier.create(flux) |
| 116 | + .consumeNextWith(initialDiagramContentConsumer) |
| 117 | + .then(uncheckShowInheritedMembersFilter) |
| 118 | + .consumeNextWith(updatedDiagramContentConsumerAfterInheritedVisibilityChange) |
| 119 | + .thenCancel() |
| 120 | + .verify(Duration.ofSeconds(10)); |
| 121 | + } |
| 122 | +} |
0 commit comments