EMF Compare: DifferenceKind is ADD and DELETE instead of CHANGE. Why?

558 Views Asked by At

Below are 2 versions of my emf instance docs. As you can see the only thing that changed is the value of 'productCode' value from KAF to Changed. But compare is treating this as two changes ADD and DELETE. Not sure why?

Version 1

<billableSystemEvent eventType="1" description="Application Processed">
        <billableProductCode productCode="KAF"/>
</billableSystemEvent>

Version 2

<billableSystemEvent eventType="1" description="Application Processed">
        <billableProductCode productCode="Changed"/>
</billableSystemEvent>

public Comparison compare()
{
    // Load the two input models
    ResourceSet resourceSet1 = new ResourceSetImpl();
    ResourceSet resourceSet2 = new ResourceSetImpl();
    String xmi1 = "src/test/java/com/equifax/ic/provisioning/service/v1.xmi";
    String xmi2 = "src/test/java/com/equifax/ic/provisioning/service/v2.xmi";
    load(xmi1, resourceSet1);
    load(xmi2, resourceSet2);

    // Configure EMF Compare
    EMFCompare comparator = EMFCompare.builder().build();

    // Compare the two models
    IComparisonScope scope = EMFCompare.createDefaultScope(resourceSet1, resourceSet2);
    return comparator.compare(scope);
}

@Test
public void testCompare()
{
    Comparison comparison = compare();
    List<Diff> differences = comparison.getDifferences();

    for(Diff d: differences)
    {
        System.err.println("d.getKind(): "+d.getKind());
        System.err.println("d.getMatch(): " + d.getMatch());
        System.err.println("State: " + d.getState());
    }

    assertSame(Integer.valueOf(12), Integer.valueOf(differences.size()));
}

Output

d.getKind(): ADD
d.getMatch(): MatchSpec{left=BillableSystemEvent@1b5340c Application Processed, right=BillableSystemEvent@16c163f Application Processed, origin=<null>, #differences=2, #submatches=2}
State: UNRESOLVED

d.getKind(): DELETE
d.getMatch(): MatchSpec{left=BillableSystemEvent@1b5340c Application Processed, right=BillableSystemEvent@16c163f Application Processed, origin=<null>, #differences=2, #submatches=2}
State: UNRESOLVED
1

There are 1 best solutions below

0
On

Our wiki is far from complete, but the description of the Diff elements should be complete enough to describe what "Add", "Delete" or "Changed" mean to EMF Compare.

Other than that, what you print here is not enough to tell what's really happening. Your System.out would be more useful if you printed "d.toString()" itself... or at least d.getValue() (if instanceof ReferenceChange or ReferenceChange).

Here, I'll answer with no knowledge of your model, I hope I am not making wrong assumptions about it (particularly, what are "billableProductCode" and its "productCode").

I am pretty sure though that billableSystemEvent.billableProductCode is a multi-valued attribute. In such cases, elements that are not "equal" with each other will be considered not to match. "KAF" is not equal to "Changed", and thus we consider that the two values don't match, which results in two differences : "KAF" has been deleted, and "Changed" has been added.

Note that this is a simplification: we do not use Object#equals(Object) here, but IEqualityHelper#matchingValues(Object, Object).

If "billableProductCode" had been a single-valued attribute, we would have detected that "KAF" had changed to "Changed".