MoTeS Evaluation: UML2ER Case Study

This case study is based on a well-known transformation example, which generates an entity-relationship diagram from a UML class diagram.

MoTeS Evaluation: UML2ER Case Study

Original Model Transformation (ATL)

Tracts contracts

MoTeS contracts

Mutation Analysis: Results

Mutation U_M1

Mutation U_M2

Mutation U_M3

Eclipse Project

Original Model Transformation (ATL)

-- @nsURI ER=http://er

-- @nsURI SimpleUml=http://SimpleUML

module UML2ER;

create OUT : ER from IN : SimpleUml;

--R1

abstract rule NamedElement{

        from s : SimpleUml!NamedElement

        to t : ER!Element(name <- s.name)

}

--R2

rule Package extends NamedElement{

        from

                s: SimpleUml!Package

        to

                t: ER!ERModel (

                        entities <- s.ownedElements        

                )

}

--R3

rule Class extends NamedElement{

        from s: SimpleUml!Class

        to t: ER!EntityType (

                features <- s.ownedProperty

                )

}

--R4

abstract rule Property extends NamedElement{

        from s: SimpleUml!Property        

        to t: ER!Feature (

        )

}

--R5

rule Attributes extends Property{

        from s: SimpleUml!Property (not s.primitiveType.oclIsUndefined())

        to t: ER!Attribute (

                type <- s.primitiveType        

        )

}

--R6

abstract rule References extends Property{

        from s: SimpleUml!Property (not s.complexType.oclIsUndefined())

        to t: ER!Reference (

                        type <- s.complexType

        )

}

--R7

rule WeakReferences extends References{

        from s: SimpleUml!Property (not s.isContainment)

        to t: ER!WeakReference

}

--R8

rule StrongReferences extends References{

        from

                s: SimpleUml!Property (s.isContainment)

        to t: ER!StrongReference

}

Tracts contracts

These are the 10 Tracts define for this case study:

1) SRC_TRG Package2Model (U_Tr1)

Package.allInstances->forAll(p | ERModel.allInstances->one(e | p.name = e.name))

2) SRC_TRG Model contains for each class a corresponding entity (U_Tr2)

Package.allInstances->forAll(p | ERModel.allInstances->one(e | p.name = e.name and p.ownedElements

 ->forAll(class | e.entities->one(entity | entity.name = class.name))))

3) SRC_TRG Model contains for each class a corresponding entity which contains for each property a corresponding feature (U_Tr3)

Package.allInstances->forAll(p | ERModel.allInstances->one(e | p.name = e.name and p.ownedElements

  ->forAll(class | e.entities->one(entity | entity.name = class.name and class.ownedProperty

    ->forAll(prop | entity.features->forAll(f | f.name = prop.name))))))

4) SRC_TRG Amount of NamedElement instances equals amount of Element instances (U_Tr4)

NamedElement.allInstances-> size() = Element.allInstances->size()

5) SRC_TRG Amount of Package instances equals amount of ERModel instances (U_Tr5)

Package.allInstances->size() = ERModel.allInstances->size()

6) SRC_TRG Amount of Class instances equals amount of EntityType instances (U_Tr6)

Class.allInstances->size() = EntityType.allInstances->size()

7) SRC_TRG Amount of Property instances equals amount of Feature instances (U_Tr7)

Property.allInstances->size() <= Feature.allInstances->size()

8) SRC_TRG Nesting of Elements and generate for each attribute an attribute (U_Tr8)

Package.allInstances->forAll(p | ERModel.allInstances->one(e | p.name = e.name and p.ownedElements

  ->forAll(class | e.entities->one(entity | entity.name = class.name and class.ownedProperty

     ->forAll(prop | prop.primitiveType<> "" and (not prop.primitiveType.oclIsUndefined())

        implies entity.features-> select(f|f.oclIsTypeOf(Attribute)) -> one(f | f.name = prop.name))))))

9) SRC_TRG Nesting of Elements and generate for each non-containment reference a weak-reference (U_Tr9)

Package.allInstances->forAll(p | ERModel.allInstances->one(e | p.name = e.name and p.ownedElements

   ->forAll(class | e.entities->one(entity | entity.name = class.name and class.ownedProperty

      ->forAll(prop | prop.complexType <> null implies entity.features-> select(f|f.oclIsTypeOf(Reference))

         -> one(f | f.name = prop.name and not prop.isContainment implies f.oclIsTypeOf(WeakReference)))))))

10) SRC_TRG Nesting of Elements and generate for each containment reference a strong-reference (U_Tr10)

Package.allInstances->forAll(p | ERModel.allInstances->one(e | p.name = e.name and p.ownedElements

    ->forAll(class | e.entities->one(entity | entity.name = class.name and class.ownedProperty

      ->forAll(prop | prop.complexType <> null implies entity.features-> select(f|f.oclIsTypeOf(Reference))

        -> one(f | f.name = prop.name and prop.isContainment implies f.oclIsTypeOf(StrongReference)))))))

MoTeS contracts

These are the 5 MoTeS contracts define for this case study (Web version):

contract U_Mo1{

 input { (Package:i) }

 output { (ERModel:o) }

 detection: p1(i.name = o.name)

}

contract U_Mo2{

 input { (Class:i) }

 output { (EntityType:o) }

 detection: p1(i.name = o.name) and invoke(C1,i.immediateComposite,o.immediateComposite)

}

contract U_Mo3{

 input {

         (Property:i)

         exclusion: p1(i.primitiveType = "") or p2(i.primitiveType = null)

 }

 output { (Attribute:o) }

 detection: p1(i.name = o.name) and invoke(C2,i.immediateComposite,o.immediateComposite)

}  

contract U_Mo4{

 input {

         (Property:i)

         exclusion: p1(i.complexType = null) or p2(i.isContainment = true)         

 }

 output { (WeakReference:o) }

 detection: p1(i.name = o.name) and invoke(C2,i.immediateComposite,o.immediateComposite)

}  

contract U_Mo5{

 input {

         (Property:i)

         exclusion: p1(i.complexType = null) or p2(i.isContainment = false)         

 }

 output { (StrongReference:o) }

 detection: p1(i.name = o.name) and invoke(C2,i.immediateComposite,o.immediateComposite)

}  

Mutation Analysis: Results

We have applied different ATL mutations to the originally model transformation, one mutant at a time, and detailed the results obtained with MoTeS.

Mutation U_M1

Modification of the value feature of a Binding in R1. In this mutation, the attribute initialized in R1 has been modified. Concretely, now the value in the Binding is always set to “name” (see Listing below).

abstract rule NamedElement{ --R1

        from s : SimpleUml!NamedElement

        to t : ER!Element(name <- 'name')  -- Mutation 01: Binding modified

}

The following table summarizes the results obtained after running MoTeS:

Output

Input

TP

FP

TN

FN

Pr

Rc

Case

Cs

Rule

Res.

Acts.

ERModel

Package

0

1

0

1

0

0

C5

U_Mo1

U_R2

FN, FPout

Constrain Delete

EntityType

Class

0

4

0

4

0

0

C5

U_Mo2

U_R3

FN, FPout

Constrain

Delete

Attribute

Property

0

2

0

2

0

0

C5

U_Mo3

U_R5

FN, FPout

Constrain Delete

WeakReference

Property

0

2

0

2

0

0

C5

U_Mo4

U_R7

FN, FPout

Constrain Delete

StrongReference

Property

0

1

0

1

0

0

C5

U_Mo5

U_R8

FN, FPout

Constrain Delete

Mutation U_M2

Addition of an OutPatternElement with two Bindings in R3. In this situation, now two elements of type EntityType are created for each Class. The features assigned to the new EntityType are those of the super classes of the input Class. The new rule is shown in the listing below.

rule Class extends NamedElement{ --R3

        from s: SimpleUml!Class

        to t: ER!EntityType (

                features <- s.ownedProperty

                ),

           t2: ER!EntityType( -- Mutation 02: Added OutPatternElement and Bindings

               features <- s.superClasses -> collect (sc | sc.ownedProperties),

               name <- 'fromSuper'

            )

}

The following table summarizes the results obtained after running MoTeS:

Output

Input

TP

FP

TN

FN

Pr

Rc

Case

Cs

Rule

Res.

Acts.

ERModel

Package

1

0

0

0

100

100

C1

U_Mo1

U_R2

TP

No Action

EntityType

Class

4

4

0

0

50

100

C2

U_Mo2

U_R3

TP, FPout

Constrain

Attribute

Property

2

0

0

0

100

100

C1

U_Mo3

U_R5

TP

No Action

WeakReference

Property

2

0

0

0

100

100

C1

U_Mo4

U_R7

TP

No Action

StrongReference

Property

1

0

0

0

100

100

C1

U_Mo5

U_R8

TP

No Action

Mutation U_M3

Modification of a Filter in R8. In this mutation we have modified the Filter of the last rule. With this change, we make the application of this rule more restrictive, i.e., now less elements of type Property will fire the rule. In particular, we add to the previous constraint that the name of the Property has to begin with the character ‘s’. It is shown in the next Listing. We have made a small modification to this mutant in order to make the transformation fail, because it did not fail for the test model used (all the instances’ names start by the character ‘c’). The modification simply consists on swapping the character ‘c’ for ‘p’ in the last expression of the input filter.

rule StrongReferences extends References{ --R8

        From s: SimpleUml!Property (s.isContainment --- Mutation 03: Modified filter

                                    and not s.name.oclIsUndefined()

                                    and s.name.substring(1,1) = 'p')

        to t: ER!StrongReference

}

The following table summarizes the results obtained after running MoTeS:

Output

Input

TP

FP

TN

FN

Pr

Rc

Case

Cs

Rule

Res.

Acts.

ERModel

Package

1

0

0

0

100

100

C1

U_Mo1

U_R2

TP

No Action

EntityType

Class

4

0

0

0

100

100

C1

U_Mo2

U_R3

TP

No Action

Attribute

Property

2

0

0

0

100

100

C1

U_Mo3

U_R5

TP

No Action

WeakReference

Property

2

0

0

0

100

100

C1

U_Mo4

U_R7

TP

No Action

StrongReference

Property

0

0

0

1

NA

0

C7

U_Mo5

U_R8

FN

Relax (Create)

Mutation U_M4

Modification of the class feature in an OutPatternElement and deletion of a Binding in R5. This mutation consists of changing the class feature of the only OutPatternElement in R5. This way, instead of creating elements of type Attribute, elements of type WeakReference are created. The original Binding has also been deleted, since the attribute that it was initializing does not exist in elements of type WeakReference. The new rule is shown below.

rule Attributes extends Property{ --R5

        from s: SimpleUml!Property (not s.primitiveType.oclIsUndefined())

        to

        t: ER!WeakReference (        

                )

        

}

The following table summarizes the results obtained after running MoTeS:

Output

Input

TP

FP

TN

FN

Pr

Rc

Case

Cs

Rule

Res.

Acts.

ERModel

Package

1

0

0

0

100

100

C1

U_Mo1

U_R2

TP

No Action

EntityType

Class

4

0

0

0

100

100

C1

U_Mo2

U_R3

TP

No Action

Attribute

Property

0

0

0

2

NA

0

C7

U_Mo3

U_R5

FN

No Action

WeakReference

Property

2

0

0

0

50

100

C2

U_Mo4

U_R7

TP

No Action

0

2

0

0

U_R5

FP

Delete

Constrain

StrongReference

Property

1

0

0

1

100

100

C1

U_Mo5

U_R8

TP

No Action

Eclipse Project

The Eclipse project is available here: uml2er.zip

It is an ATL project with the following structure: