forked from eclipse-sirius/sirius-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug: eclipse-sirius#4192 Signed-off-by: Michaël Charfadi <[email protected]>
- Loading branch information
Showing
4 changed files
with
280 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
...gcontext/migration/participants/TreeDescriptionIconURLExpressionMigrationParticipant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 CEA LIST. | ||
* 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.sirius.web.application.editingcontext.migration.participants; | ||
|
||
import org.eclipse.emf.ecore.EClass; | ||
import org.eclipse.emf.ecore.EStructuralFeature; | ||
|
||
import org.eclipse.sirius.components.emf.migration.api.IMigrationParticipant; | ||
import org.eclipse.sirius.components.view.tree.TreePackage; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* MigrationParticipant that update the iconURLExpression of a TreeDescription to treeItemIconExpression. | ||
* | ||
* @author mcharfadi | ||
*/ | ||
@Service | ||
public class TreeDescriptionIconURLExpressionMigrationParticipant implements IMigrationParticipant { | ||
|
||
public static final String FEATURE_TO_MIGRATE = "iconURLExpression"; | ||
private static final String PARTICIPANT_VERSION = "2024.11.1-202412041104"; | ||
|
||
@Override | ||
public String getVersion() { | ||
return PARTICIPANT_VERSION; | ||
} | ||
|
||
@Override | ||
public EStructuralFeature getEStructuralFeature(EClass eClass, String eStructuralFeatureName) { | ||
var newFeature = eClass.getEStructuralFeature(eStructuralFeatureName); | ||
if (eClass.getName().equals("TreeDescription") && eStructuralFeatureName.equals(FEATURE_TO_MIGRATE)) { | ||
newFeature = TreePackage.eINSTANCE.getTreeDescription_TreeItemIconExpression(); | ||
} | ||
return newFeature; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...ius/web/services/migration/TreeDescriptionIconURLExpressionMigrationParticipantTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 CEA LIST. | ||
* 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.sirius.web.services.migration; | ||
|
||
import org.eclipse.sirius.components.core.api.IEditingContext; | ||
import org.eclipse.sirius.components.core.api.IEditingContextSearchService; | ||
import org.eclipse.sirius.components.view.diagram.DiagramDescription; | ||
import org.eclipse.sirius.components.view.diagram.HeaderSeparatorDisplayMode; | ||
import org.eclipse.sirius.components.view.tree.TreeDescription; | ||
import org.eclipse.sirius.web.AbstractIntegrationTests; | ||
import org.eclipse.sirius.web.application.editingcontext.EditingContext; | ||
import org.eclipse.sirius.web.data.MigrationIdentifiers; | ||
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 static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* Integration tests of TreeDescriptionIconURLExpressionMigrationParticipant. | ||
* | ||
* @author mcharfadi | ||
*/ | ||
@Transactional | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
public class TreeDescriptionIconURLExpressionMigrationParticipantTests extends AbstractIntegrationTests { | ||
|
||
@Autowired | ||
private IEditingContextSearchService editingContextSearchService; | ||
|
||
@Test | ||
@DisplayName("Given a project with an old model, TreeDescriptionIconURLExpressionMigrationParticipant migrates the model correctly") | ||
@Sql(scripts = { "/scripts/migration.sql" }, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) | ||
@Sql(scripts = { "/scripts/cleanup.sql" }, executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD, config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED)) | ||
public void givenAnOldModelMigrationParticipantCanBeContributedToUpdateTheModel() { | ||
var optionalEditingContext = this.editingContextSearchService.findById(MigrationIdentifiers.MIGRATION_TREE_DESCRIPTION_ICON_URL_STUDIO); | ||
assertThat(optionalEditingContext).isPresent(); | ||
this.testIsMigrationSuccessful(optionalEditingContext.get()); | ||
} | ||
|
||
private void testIsMigrationSuccessful(IEditingContext editingContext) { | ||
if (editingContext instanceof EditingContext siriusWebEditingContext) { | ||
var optionalTreeDescription = siriusWebEditingContext.getViews().stream().flatMap(view -> view.getDescriptions().stream()) | ||
.filter(representationDescription -> representationDescription.getName().equals(MigrationIdentifiers.MIGRATION_TREE_DESCRIPTION_ICON_URL_STUDIO_DOCUMENT_NAME)) | ||
.findFirst(); | ||
assertThat(optionalTreeDescription).isPresent(); | ||
assertThat(optionalTreeDescription.get()).isInstanceOf(TreeDescription.class); | ||
optionalTreeDescription.ifPresent(representationDescription -> { | ||
if (representationDescription instanceof TreeDescription treeDescription) { | ||
assertThat(treeDescription.getTreeItemIconExpression()).isEqualTo("iconUrl"); | ||
|
||
} | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters