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>