Skip to content

Commit

Permalink
#68 Update derivation test
Browse files Browse the repository at this point in the history
Adapt test to test failures on comparing description fields containing
references to images local to the project.

Add image reference to library project for derivation test.

Change-Id: I0000000000000000000000000000000000000000
Signed-off-by: Arnaud Dieumegard <arnaud.dieumegard@obeo.fr>
  • Loading branch information
arnauddieumegard authored and minhtutonthat committed Jun 9, 2022
1 parent 57d4dcd commit 1e67141
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Require-Bundle: org.polarsys.capella.filtering.tools,
org.polarsys.capella.core.commandline.core,
org.polarsys.capella.filtering.commandline,
org.polarsys.capella.core.commandline.core.ui,
org.polarsys.capella.core.data.migration
org.polarsys.capella.core.data.migration,
org.polarsys.capella.core.data.gen
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Export-Package: org.polarsys.capella.filtering.tests.ju.tests.derivation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
name="Operational Entities"/>
</ownedArchitectures>
<ownedArchitectures xsi:type="org.polarsys.capella.core.data.ctx:SystemAnalysis"
id="658115dd-d6d0-4ae4-9277-ed21299db21a" name="System Analysis">
id="658115dd-d6d0-4ae4-9277-ed21299db21a" name="System Analysis" description="&lt;p>This description contains an image to an external lib &lt;img src=&quot;sysmodel/ressources/uml.jpg&quot; />&lt;/p>&#xD;&#xA;">
<ownedFunctionPkg xsi:type="org.polarsys.capella.core.data.ctx:SystemFunctionPkg"
id="466a4dc1-eb0a-4c31-be9b-95cc8b025bd2" name="System Functions">
<ownedSystemFunctions xsi:type="org.polarsys.capella.core.data.ctx:SystemFunction"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
name="Operational Entities"/>
</ownedArchitectures>
<ownedArchitectures xsi:type="org.polarsys.capella.core.data.ctx:SystemAnalysis"
id="658115dd-d6d0-4ae4-9277-ed21299db21a" name="System Analysis">
id="658115dd-d6d0-4ae4-9277-ed21299db21a" name="System Analysis" description="&lt;p>This description contains an image to an external lib &lt;img src=&quot;sysmodel/ressources/uml.jpg&quot; />&lt;/p>&#xD;&#xA;">
<ownedFunctionPkg xsi:type="org.polarsys.capella.core.data.ctx:SystemFunctionPkg"
id="466a4dc1-eb0a-4c31-be9b-95cc8b025bd2" name="System Functions">
<ownedSystemFunctions xsi:type="org.polarsys.capella.core.data.ctx:SystemFunction"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
name="Operational Entities"/>
</ownedArchitectures>
<ownedArchitectures xsi:type="org.polarsys.capella.core.data.ctx:SystemAnalysis"
id="658115dd-d6d0-4ae4-9277-ed21299db21a" name="System Analysis">
id="658115dd-d6d0-4ae4-9277-ed21299db21a" name="System Analysis" description="&lt;p>This description contains an image to an external lib &lt;img src=&quot;sysmodel/ressources/uml.jpg&quot; />&lt;/p>&#xD;&#xA;">
<ownedFunctionPkg xsi:type="org.polarsys.capella.core.data.ctx:SystemFunctionPkg"
id="466a4dc1-eb0a-4c31-be9b-95cc8b025bd2" name="System Functions">
<ownedSystemFunctions xsi:type="org.polarsys.capella.core.data.ctx:SystemFunction"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
Expand All @@ -31,18 +33,23 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.emf.common.util.WrappedException;
import org.eclipse.emf.diffmerge.api.scopes.IEditableModelScope;
import org.eclipse.emf.diffmerge.diffdata.impl.EComparisonImpl;
import org.eclipse.emf.diffmerge.generic.api.IComparison;
import org.eclipse.emf.diffmerge.generic.api.scopes.ITreeDataScope;
import org.eclipse.emf.diffmerge.impl.policies.DefaultDiffPolicy;
import org.eclipse.emf.diffmerge.impl.policies.DefaultMatchPolicy;
import org.eclipse.emf.diffmerge.impl.scopes.FragmentedModelScope;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
import org.eclipse.sirius.business.api.helper.SiriusUtil;
import org.eclipse.sirius.business.api.image.ImageManager;
import org.eclipse.sirius.business.api.session.Session;
import org.polarsys.capella.core.data.capellacore.CapellaElement;
import org.polarsys.capella.core.data.capellacore.CapellacorePackage;
import org.polarsys.capella.core.data.capellamodeller.Project;
import org.polarsys.capella.filtering.AbstractFilteringResult;
import org.polarsys.capella.filtering.FilteringCriterionSet;
Expand All @@ -67,6 +74,9 @@ public class DerivationTest extends BasicTestCase {
Session session = null;
IProject project = null;
AbstractFilteringResult currentFilteringResult = null;

String derivedProjectName;
IProject expectedResultProject;

private String modelId;

Expand Down Expand Up @@ -124,11 +134,11 @@ private void performDerivationAndCheck(String inputModelName) throws Exception {
this.currentFilteringResult = filterResult;
System.err.println("=== currentFilteringResult: " + currentFilteringResult);

IProject expectedResultProject = IResourceHelpers.getEclipseProjectInWorkspace(filterResult.getName());
expectedResultProject = IResourceHelpers.getEclipseProjectInWorkspace(filterResult.getName());

// Create derived project
IWorkspace workspace = ResourcesPlugin.getWorkspace();
String derivedProjectName = filterResult.getName();
derivedProjectName = filterResult.getName();
IProject derivedProject = workspace.getRoot().getProject(derivedProjectName);
derivedProject.create(progressMonitor);
derivedProject.open(progressMonitor);
Expand Down Expand Up @@ -227,6 +237,55 @@ public Object getMatchID(EObject element, ITreeDataScope<EObject> scope) {
return super.getMatchID(element, scope);
}
}

/**
* Specific Diff Policy to ensure diffs between images links in description fields are not taken into account.</br>
* In order to do so, take the description of CapellaElements, and replace the name of the expected results project by
* the name of the derived project name.
*/
private class TestCaseDiffPolicy extends DefaultDiffPolicy {

private String derivedProjectName;
private String expectedResultProjectName;
private static final String QUOTE = "\"";

public TestCaseDiffPolicy(String derivedProjectName, String expectedResultProjectName) {
this.derivedProjectName = derivedProjectName;
this.expectedResultProjectName = expectedResultProjectName;
}

@Override
public boolean considerEqual(Object value1_p, Object value2_p, Object attribute_p, ITreeDataScope<EObject> scope_p) {
if (attribute_p.equals(CapellacorePackage.Literals.CAPELLA_ELEMENT__DESCRIPTION)) {
// Replace image paths to ensure diff is correct
// Adapted from /org.polarsys.capella.core.sirius.ui/src/org/polarsys/capella/core/sirius/ui/refactoring/WorkspaceImagePathChange.java
String textWithOriginalImagePaths = (String) value1_p;
String textWithUpdatedImagePaths = (String) value2_p;
Pattern pattern = Pattern.compile(ImageManager.HTML_IMAGE_PATH_PATTERN);
Matcher matcher = pattern.matcher(textWithOriginalImagePaths);

while (matcher.find()) {
String originalPath = matcher.group(1);
if (!originalPath.startsWith("/")) {
String newPath = originalPath;
Path path = new Path(originalPath);
String segment = path.segment(0);
if (derivedProjectName.equals(segment)) {
newPath = originalPath.replace(derivedProjectName, expectedResultProjectName);
}
if (!newPath.equals(originalPath)) {
// Use quote as start and end character to be sure to replace the path as a whole and not only a
// part of the path
textWithOriginalImagePaths = textWithOriginalImagePaths.replace(QUOTE + originalPath + QUOTE,
QUOTE + newPath + QUOTE);
}
}
}
return textWithOriginalImagePaths.equals(textWithUpdatedImagePaths);
}
return super.considerEqual(value1_p, value2_p, attribute_p, scope_p);
}
}

/**
* Return the first IFile under resource tree starting at 'root' that has a given extension. Returns null if no
Expand Down Expand Up @@ -285,7 +344,7 @@ public void checkSemanticResourcesAreEqual(Resource expectedResource, Resource d

// Compare
IComparison comparison = new EComparisonImpl(targetScope, referenceScope);
comparison.compute(new TestCaseMatchPolicy(), null, null, progressMonitor);
comparison.compute(new TestCaseMatchPolicy(), new TestCaseDiffPolicy(derivedProjectName, project.getName() + "_" + derivedProjectName), null, progressMonitor);

// Check if differences
if (comparison.getNbDifferences() != 0) {
Expand Down

0 comments on commit 1e67141

Please sign in to comment.