-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1077] Fix explorer in case of non-sysml domain
Fix behavior of hasChildren management of syson explorer when handling model elements from non-sysml domains. It now falls back to SiriusWeb implementation when necessary. Bug: #1077 Signed-off-by: Didier Vojtisek <[email protected]>
- Loading branch information
Showing
5 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
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
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
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
108 changes: 108 additions & 0 deletions
108
.../java/org/eclipse/syson/tree/explorer/view/services/SysONDefaultExplorerServicesTest.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,108 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024, 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.tree.explorer.view.services; | ||
|
||
import org.eclipse.emf.common.command.BasicCommandStack; | ||
import org.eclipse.emf.ecore.*; | ||
import org.eclipse.emf.ecore.impl.EPackageRegistryImpl; | ||
import org.eclipse.emf.ecore.resource.ResourceSet; | ||
import org.eclipse.emf.ecore.util.ECrossReferenceAdapter; | ||
import org.eclipse.emf.ecore.util.EcoreAdapterFactory; | ||
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain; | ||
import org.eclipse.emf.edit.provider.ComposedAdapterFactory; | ||
import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory; | ||
import org.eclipse.sirius.components.collaborative.api.IRepresentationImageProvider; | ||
import org.eclipse.sirius.components.core.api.IContentService; | ||
import org.eclipse.sirius.components.core.api.IIdentityService; | ||
import org.eclipse.sirius.components.core.api.IObjectService; | ||
import org.eclipse.sirius.components.core.api.IURLParser; | ||
import org.eclipse.sirius.web.application.editingcontext.EditingContext; | ||
import org.eclipse.sirius.web.application.views.explorer.services.ExplorerServices; | ||
import org.eclipse.sirius.web.application.views.explorer.services.api.IExplorerServices; | ||
import org.eclipse.sirius.web.domain.boundedcontexts.representationdata.services.api.IRepresentationMetadataSearchService; | ||
import org.eclipse.syson.tree.explorer.view.services.api.ISysONExplorerFilterService; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
public class SysONDefaultExplorerServicesTest { | ||
|
||
private static EditingContext editingContext; | ||
|
||
private SysONDefaultExplorerServices sysONDefaultExplorerServices; | ||
|
||
@BeforeAll | ||
static void createEditingContext() { | ||
ComposedAdapterFactory composedAdapterFactory = new ComposedAdapterFactory(); | ||
composedAdapterFactory.addAdapterFactory(new EcoreAdapterFactory()); | ||
composedAdapterFactory.addAdapterFactory(new ReflectiveItemProviderAdapterFactory()); | ||
|
||
EPackage.Registry ePackageRegistry = new EPackageRegistryImpl(); | ||
ePackageRegistry.put(EcorePackage.eINSTANCE.getNsURI(), EcorePackage.eINSTANCE); | ||
|
||
AdapterFactoryEditingDomain editingDomain = new AdapterFactoryEditingDomain(composedAdapterFactory, new BasicCommandStack()); | ||
ResourceSet resourceSet = editingDomain.getResourceSet(); | ||
resourceSet.setPackageRegistry(ePackageRegistry); | ||
resourceSet.eAdapters().add(new ECrossReferenceAdapter()); | ||
editingContext = new EditingContext(UUID.randomUUID().toString(), editingDomain, Map.of(), List.of()); | ||
} | ||
|
||
@Test | ||
@DisplayName("hasChildren method can handle non sysml content") | ||
public void hasChildrenCanHandleNonSysmlContent() { | ||
this.createMockServicesForHasChildren(); | ||
|
||
EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage(); | ||
ePackage.setName("somePackage"); | ||
EClass c1 = EcoreFactory.eINSTANCE.createEClass(); | ||
ePackage.getEClassifiers().add(c1); | ||
EClass c2 = EcoreFactory.eINSTANCE.createEClass(); | ||
ePackage.getEClassifiers().add(c2); | ||
EAttribute c1_a1 = EcoreFactory.eINSTANCE.createEAttribute(); | ||
c1.getEStructuralFeatures().add(c1_a1); | ||
EAttribute c1_a2 = EcoreFactory.eINSTANCE.createEAttribute(); | ||
c1.getEStructuralFeatures().add(c1_a2); | ||
|
||
assertThat(sysONDefaultExplorerServices.hasChildren(ePackage, editingContext, List.of(), List.of())).isTrue(); | ||
assertThat(sysONDefaultExplorerServices.hasChildren(c1, editingContext, List.of(), List.of())).isTrue(); | ||
assertThat(sysONDefaultExplorerServices.hasChildren(c1_a1, editingContext, List.of(), List.of())).isFalse(); | ||
} | ||
|
||
/** | ||
* Create instances of services required to test hasChildren | ||
* Use mock instances for non required services | ||
*/ | ||
private void createMockServicesForHasChildren() { | ||
|
||
IIdentityService identityService = mock(IIdentityService.class); | ||
IContentService contentService = mock(IContentService.class); | ||
IRepresentationMetadataSearchService representationMetadataSearchService = mock(IRepresentationMetadataSearchService.class); | ||
|
||
IObjectService objectService = mock(IObjectService.class); | ||
IURLParser urlParser = mock(IURLParser.class); | ||
List<IRepresentationImageProvider> representationImageProviders = new ArrayList<>(); | ||
IExplorerServices explorerServices = new ExplorerServices(objectService, urlParser, representationImageProviders, representationMetadataSearchService); | ||
|
||
ISysONExplorerFilterService filterService = new SysONExplorerFilterService(); | ||
|
||
sysONDefaultExplorerServices = new SysONDefaultExplorerServices(identityService, contentService, representationMetadataSearchService, explorerServices, filterService); | ||
} | ||
} |
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