Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EMF Compare -- Compare two model instances
EMF Compare -- Compare two model instances [message #420873] Tue, 15 July 2008 13:02 Go to next message
Thomas Rheker is currently offline Thomas RhekerFriend
Messages: 8
Registered: July 2009
Junior Member
This is a multi-part message in MIME format.
--------------090708060606080405060907
Content-Type: text/plain; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit

Hi,

for a research project I am trying to automatically compare two
resources containing instances of the same meta model. These are the
input and output of a bidirectional transformation and should be the
same. The problem is to test them for equality in a junit test.

My current approach does not work as expected, it looks as the following
code snippet:
>>>snip>>>
Resource compareInstance1 = loadEMFInstanceFromFile(emfInput);
Resource compareInstance2 = loadEMFInstanceFromFile(emfOutput);

MatchModel match = null;
IMatchEngine matchEngine = new GenericMatchEngine();
try {
Map compareOptions = new HashMap();
match = matchEngine.resourceMatch(compareInstance1,
compareInstance2, compareOptions);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
IDiffEngine diffEngine = new GenericDiffEngine();
DiffModel diff = diffEngine.doDiff(match);
<<<snap<<<

For two exactly identical files the comparison still returns a DiffModel
containing an Addition.

If I compare the files by hand in the Eclipse GUI, Compare states that
there are no differences, as is the case. See the attached files for the
compared models and the meta model.

What am I doing wrong? Also, is there an easy way to check two models
for semantic equality, which is all I need for my tests right now?

Greetings,
Thomas Rheker

--------------090708060606080405060907
Content-Type: text/xml;
name="Complex.ecore"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="Complex.ecore"

<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="test"
nsURI="http://de.upb.dmm.emf2groove.test" nsPrefix="de.upb.dmm.emf2groove">
<eClassifiers xsi:type="ecore:EClass" name="AbstractClassA" abstract="true">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="aBoolean" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"
defaultValueLiteral="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="ClassB" eSuperTypes="#//AbstractClassA">
<eStructuralFeatures xsi:type="ecore:EReference" name="b" eType="#//subpackage/ClassB"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="aByte" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EByte"
defaultValueLiteral="1"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="aDouble" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EDouble"
defaultValueLiteral="1.2"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="aDerivedValue" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EDouble"
defaultValueLiteral="1" derived="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="ClassOperation">
<eOperations name="Operation"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="a" eType="#//subpackage/ClassA"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EEnum" name="Enumeration">
<eLiterals name="EnumA" literal="EnumA"/>
<eLiterals name="EnumB" value="1"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Container">
<eStructuralFeatures xsi:type="ecore:EReference" name="AContainment" upperBound="-1"
eType="#//AbstractClassA" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="BContainment" upperBound="-1"
eType="#//ClassB" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="CContainment" upperBound="-1"
eType="#//ClassOperation" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="SubAContainment" upperBound="-1"
eType="#//subpackage/ClassA" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="SubBContainment" upperBound="-1"
eType="#//subpackage/ClassB" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="EnumContainment" upperBound="-1"
eType="#//ClassEnum" containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="ClassEnum">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="Enumeration" eType="#//Enumeration"/>
</eClassifiers>
<eSubpackages name="subpackage" nsURI="http://de.upb.dmm.emf2groove.test.subpackage"
nsPrefix="de.upb.dmm.emf2groove.test">
<eClassifiers xsi:type="ecore:EClass" name="ClassA"/>
<eClassifiers xsi:type="ecore:EClass" name="ClassB"/>
</eSubpackages>
</ecore:EPackage>

--------------090708060606080405060907
Content-Type: text/xml;
name="enumerations.test"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="enumerations.test"

<?xml version="1.0" encoding="UTF-8"?>
<de.upb.dmm.emf2groove:Container xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:de.upb.dmm.emf2groove="http://de.upb.dmm.emf2groove.test">
<EnumContainment Enumeration="EnumB"/>
<EnumContainment/>
<EnumContainment/>
</de.upb.dmm.emf2groove:Container>

--------------090708060606080405060907
Content-Type: text/xml;
name="transformed enumerations.test"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="transformed enumerations.test"

<?xml version="1.0" encoding="UTF-8"?>
<de.upb.dmm.emf2groove:Container xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:de.upb.dmm.emf2groove="http://de.upb.dmm.emf2groove.test">
<EnumContainment Enumeration="EnumB"/>
<EnumContainment/>
<EnumContainment/>
</de.upb.dmm.emf2groove:Container>

--------------090708060606080405060907--
Re: EMF Compare -- Compare two model instances [message #420879 is a reply to message #420873] Tue, 15 July 2008 13:53 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------040802080501030202000305
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Thomas,

Please use the EMFT newsgroup for questions about compare. I've added
it to the "to" list of the reply, so no need to repost.


Thomas Rheker wrote:
> Hi,
>
> for a research project I am trying to automatically compare two
> resources containing instances of the same meta model. These are the
> input and output of a bidirectional transformation and should be the
> same. The problem is to test them for equality in a junit test.
>
> My current approach does not work as expected, it looks as the following
> code snippet:
>
>>>> snip>>>
>>>>
> Resource compareInstance1 = loadEMFInstanceFromFile(emfInput);
> Resource compareInstance2 = loadEMFInstanceFromFile(emfOutput);
>
> MatchModel match = null;
> IMatchEngine matchEngine = new GenericMatchEngine();
> try {
> Map compareOptions = new HashMap();
> match = matchEngine.resourceMatch(compareInstance1,
> compareInstance2, compareOptions);
> } catch (InterruptedException e1) {
> e1.printStackTrace();
> }
> IDiffEngine diffEngine = new GenericDiffEngine();
> DiffModel diff = diffEngine.doDiff(match);
> <<<snap<<<
>
> For two exactly identical files the comparison still returns a DiffModel
> containing an Addition.
>
> If I compare the files by hand in the Eclipse GUI, Compare states that
> there are no differences, as is the case. See the attached files for the
> compared models and the meta model.
>
> What am I doing wrong? Also, is there an easy way to check two models
> for semantic equality, which is all I need for my tests right now?
>
> Greetings,
> Thomas Rheker
>

--------------040802080501030202000305
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Thomas,<br>
<br>
Please use the EMFT newsgroup for questions about compare.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF Compare -- Compare two model instances [message #420986 is a reply to message #420879] Sat, 19 July 2008 10:24 Go to previous message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------050006020802040709080702
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 8bit

Thomas,

This snippet seems fine as is. Are you sure the two models you're
comparing by code are the same as those you compare from the GUI? If so,
did you check that all the compare options are set to their default
value when comparing from GUI (Window => Preferences => EMF Compare)?
You'll need to set them programmatically if needed (see
org.eclipse.emf.compare.util.MatchOptions).

As a side note, you shouldn't use the GenericMatchEngine and
GenericDiffEngine directly.
org.eclipse.emf.compare.match.service.MatchService and
org.eclipse.emf.compare.diff.service.DiffService both provide the
necessary API.

Cheers,

Laurent Goubet
Obeo

Ed Merks a
Previous Topic:Problem in Loading EMF Model
Next Topic:[CDO] handling conflicts
Goto Forum:
  


Current Time: Fri Apr 26 00:11:29 GMT 2024

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

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

Back to the top