Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Models partially loaded with jUnit(Making jUnit tests on EMF Diff/Merge bridge but the imported model seems to be partially loaded)
Models partially loaded with jUnit [message #1861715] Mon, 30 October 2023 15:19 Go to next message
Clément Peyrou is currently offline Clément PeyrouFriend
Messages: 1
Registered: October 2023
Junior Member
Hi,
I have a plugin that import a Capella 5.2 model file using EMF Diff/Merge Bridge to transform Capella models into my app models.

I try to make jUnit 5 tests, but it's seem the Capella model is only partially loaded when the tests are performed.
In other hand, in my application, the Capella model is fully loaded.

The function component.getRepresentingParts() return an empty list with jUnit only, why ?

private void representingParts(AbstractType type) {
	if (type instanceof final PhysicalComponent component) {
		 component.getRepresentingParts();
	}
}


Here, the code I am using to read the Capella file.
In my jUnit test:

public static Project loadProject(final String path) {
	final ResourceSet resourceSet = new ResourceSetImpl();
	final Resource resource = resourceSet.getResource(URI.createURI(path), true);
	return resource.getContents().stream()
			.filter(Project.class::isInstance)
			.map(Project.class::cast)
			.findFirst()
			.orElseThrow();
}


In app:

private org.polarsys.capella.core.data.capellamodeller.Project loadCapellaProject() {
	final ResourceSet[] resourceSet = { new ResourceSetImpl() };
	final TransactionalEditingDomain editingDomain = new SiriusEditingDomainProvider()
			.createEditingDomain(resourceSet[0]);
	resourceSet[0] = editingDomain.getResourceSet();
	final Resource[] resource = new Resource[1];
	editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain) {
		@Override
		protected void doExecute() {
			resource[0] = resourceSet[0].getResource(
				URI.createFileURI(CapellaImport.this.capellaFile.toFile().getAbsolutePath()), true
			);
		}
	});
	return resource[0].getContents().stream()
		.filter(org.polarsys.capella.core.data.capellamodeller.Project.class::isInstance)
		.map(org.polarsys.capella.core.data.capellamodeller.Project.class::cast)
		.findFirst()
		.orElseThrow();
}


I suppose the resources reader is known because I'm importing "org.polarsys.capella.core.data-gen" plugin, containing:

<!--@generated-->
  <extension point="org.eclipse.emf.ecore.extension_parser">
      <!-- @generated CapellaModeller -->
      <parser class="org.polarsys.capella.core.data.capellamodeller.util.CapellamodellerResourceFactoryImpl" type="capella"/>
   </extension>





Re: Models partially loaded with jUnit [message #1861728 is a reply to message #1861715] Tue, 31 October 2023 09:06 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33143
Registered: July 2009
Senior Member
What is the value of path as passed to
URI.createURI(path)
Is that an absolute URI? Should it be
URI.createFileURI(new File(path).getAbsolutePath())


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Problem with interaction between list sorting and recording commands
Next Topic:Incomplete EPackage from ecore file
Goto Forum:
  


Current Time: Thu May 02 02:30:09 GMT 2024

Powered by FUDForum. Page generated in 0.03590 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top