Module: Testmodel::ECoreModelChecker

Includes:
RGen::ECore
Included in:
EAInstantiatorTest
Defined in:
lib/puppet/vendor/rgen/test/testmodel/ecore_model_checker.rb

Overview

Checks the ECore model elements created by transformation from the UML Class model elements from the example model

Constant Summary

Constants included from RGen::ECore

RGen::ECore::EBoolean, RGen::ECore::EFloat, RGen::ECore::EInt, RGen::ECore::EJavaClass, RGen::ECore::EJavaObject, RGen::ECore::ELong, RGen::ECore::ERubyClass, RGen::ECore::ERubyObject, RGen::ECore::EString

Instance Method Summary collapse

Methods included from RGen::MetamodelBuilder::ModuleExtension

#_annotations, #_constantOrder, #annotation, extended, #final_method, #method_added

Methods included from RGen::ECore::ECoreInterface

#_set_ecore_internal, clear_ecore_cache, #ecore

Instance Method Details

#checkECoreModel(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/puppet/vendor/rgen/test/testmodel/ecore_model_checker.rb', line 11

def checkECoreModel(env)
          
  # check main package

  mainPackage = env.elements.select {|e| e.is_a? EPackage and e.name == "HouseMetamodel"}.first
  assert_not_nil mainPackage
  
  # check Rooms package

  assert mainPackage.eSubpackages.is_a?(Array)
  assert_equal 1, mainPackage.eSubpackages.size
  assert mainPackage.eSubpackages[0].is_a?(EPackage)
  roomsPackage = mainPackage.eSubpackages[0]
  assert_equal "Rooms", roomsPackage.name
  
  # check main package classes

  assert mainPackage.eClassifiers.is_a?(Array)
  assert_equal 4, mainPackage.eClassifiers.size
  assert mainPackage.eClassifiers.all?{|c| c.is_a?(EClass)}
  houseClass = mainPackage.eClassifiers.select{|c| c.name == "House"}.first
  personClass = mainPackage.eClassifiers.select{|c| c.name == "Person"}.first
  meetingPlaceClass = mainPackage.eClassifiers.select{|c| c.name == "MeetingPlace"}.first
  cookingPlaceInterface = mainPackage.eClassifiers.select{|c| c.name == "CookingPlace"}.first
  assert_not_nil houseClass
  assert_not_nil personClass
  assert_not_nil meetingPlaceClass
  assert_not_nil cookingPlaceInterface

  # check Rooms package classes

  assert roomsPackage.eClassifiers.is_a?(Array)
  assert_equal 3, roomsPackage.eClassifiers.size
  assert roomsPackage.eClassifiers.all?{|c| c.is_a?(EClass)}
  roomClass = roomsPackage.eClassifiers.select{|c| c.name == "Room"}.first
  kitchenClass = roomsPackage.eClassifiers.select{|c| c.name == "Kitchen"}.first
  bathroomClass = roomsPackage.eClassifiers.select{|c| c.name == "Bathroom"}.first
  assert_not_nil roomClass
  assert_not_nil kitchenClass
  assert_not_nil bathroomClass
  
  # check Room inheritance

  assert kitchenClass.eSuperTypes.is_a?(Array)
  assert_equal 3, kitchenClass.eSuperTypes.size
  assert_equal roomClass.object_id, kitchenClass.eSuperTypes.select{|c| c.name == "Room"}.first.object_id
  assert_equal meetingPlaceClass.object_id, kitchenClass.eSuperTypes.select{|c| c.name == "MeetingPlace"}.first.object_id
  assert_equal cookingPlaceInterface.object_id, kitchenClass.eSuperTypes.select{|c| c.name == "CookingPlace"}.first.object_id
  assert bathroomClass.eSuperTypes.is_a?(Array)
  assert_equal 1, bathroomClass.eSuperTypes.size
  assert_equal roomClass.object_id, bathroomClass.eSuperTypes[0].object_id

  # check House-Room "part of" association

  assert houseClass.eAllContainments.eType.is_a?(Array)
  assert_equal 1, houseClass.eAllContainments.eType.size
  roomRef = houseClass.eAllContainments.first
  assert_equal roomClass.object_id, roomRef.eType.object_id
  assert_equal "room", roomRef.name
  assert_equal 1, roomRef.lowerBound
  assert_equal(-1, roomRef.upperBound)
  assert_not_nil roomRef.eOpposite
  assert_equal houseClass.object_id, roomRef.eOpposite.eType.object_id
  
  partOfRefs = roomClass.eReferences.select{|r| r.eOpposite && r.eOpposite.containment}
  assert_equal 1, partOfRefs.size
  assert_equal houseClass.object_id, partOfRefs.first.eType.object_id
  assert_equal "house", partOfRefs.first.name
  assert_equal roomRef.object_id, partOfRefs.first.eOpposite.object_id
      
  # check House OUT associations

  assert houseClass.eReferences.is_a?(Array)
  assert_equal 3, houseClass.eReferences.size
  bathRef = houseClass.eReferences.find {|e| e.name == "bathroom"}
  kitchenRef = houseClass.eReferences.find {|e| e.name == "kitchen"}
  roomRef = houseClass.eReferences.find {|e| e.name == "room"}
  assert_not_nil bathRef
  assert_nil bathRef.eOpposite
  assert_not_nil kitchenRef
  assert_not_nil roomRef
  assert_equal 1, kitchenRef.lowerBound
  assert_equal 1, kitchenRef.upperBound
  assert_equal 1, roomRef.lowerBound
  assert_equal(-1, roomRef.upperBound)
  
  # check House IN associations

       houseInRefs = env.find(:class => EReference, :eType => houseClass)
  assert_equal 3, houseInRefs.size
  homeEnd = houseInRefs.find{|e| e.name == "home"}
  assert_not_nil homeEnd
  assert_equal 0, homeEnd.lowerBound
  assert_equal(-1, homeEnd.upperBound)
  
end