rgen 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. data/CHANGELOG +20 -1
  2. data/MIT-LICENSE +1 -1
  3. data/README +12 -9
  4. data/lib/instantiators/ea_instantiator.rb +36 -0
  5. data/lib/metamodels/uml13_metamodel.rb +559 -0
  6. data/lib/metamodels/uml13_metamodel_ext.rb +26 -0
  7. data/lib/mmgen/metamodel_generator.rb +5 -5
  8. data/lib/mmgen/mm_ext/ecore_ext.rb +95 -0
  9. data/lib/mmgen/mmgen.rb +6 -4
  10. data/lib/mmgen/templates/annotations.tpl +37 -0
  11. data/lib/mmgen/templates/metamodel_generator.tpl +171 -0
  12. data/lib/rgen/ecore/ecore.rb +190 -0
  13. data/lib/rgen/ecore/ecore_instantiator.rb +25 -0
  14. data/lib/rgen/ecore/ecore_transformer.rb +85 -0
  15. data/lib/rgen/environment.rb +9 -24
  16. data/lib/rgen/find_helper.rb +68 -0
  17. data/lib/rgen/{instantiator.rb → instantiator/abstract_instantiator.rb} +6 -2
  18. data/lib/rgen/instantiator/abstract_xml_instantiator.rb +59 -0
  19. data/lib/rgen/instantiator/default_xml_instantiator.rb +117 -0
  20. data/lib/rgen/instantiator/ecore_xml_instantiator.rb +144 -0
  21. data/lib/rgen/instantiator/nodebased_xml_instantiator.rb +157 -0
  22. data/lib/rgen/instantiator/xmi11_instantiator.rb +164 -0
  23. data/lib/rgen/metamodel_builder.rb +103 -9
  24. data/lib/rgen/metamodel_builder/build_helper.rb +26 -4
  25. data/lib/rgen/metamodel_builder/builder_extensions.rb +285 -88
  26. data/lib/rgen/metamodel_builder/builder_runtime.rb +7 -1
  27. data/lib/rgen/metamodel_builder/data_types.rb +67 -0
  28. data/lib/rgen/metamodel_builder/intermediate/annotation.rb +30 -0
  29. data/lib/rgen/metamodel_builder/metamodel_description.rb +232 -0
  30. data/lib/rgen/metamodel_builder/mm_multiple.rb +23 -0
  31. data/lib/rgen/metamodel_builder/module_extension.rb +33 -0
  32. data/lib/rgen/model_comparator.rb +56 -0
  33. data/lib/rgen/model_dumper.rb +5 -5
  34. data/lib/rgen/name_helper.rb +17 -1
  35. data/lib/rgen/template_language.rb +148 -28
  36. data/lib/rgen/template_language/directory_template_container.rb +56 -38
  37. data/lib/rgen/template_language/output_handler.rb +93 -77
  38. data/lib/rgen/template_language/template_container.rb +186 -143
  39. data/lib/rgen/transformer.rb +19 -14
  40. data/lib/transformers/uml13_to_ecore.rb +75 -0
  41. data/redist/xmlscan/ChangeLog +1301 -0
  42. data/redist/xmlscan/README +34 -0
  43. data/redist/xmlscan/THANKS +11 -0
  44. data/redist/xmlscan/doc/changes.html +74 -0
  45. data/redist/xmlscan/doc/changes.rd +80 -0
  46. data/redist/xmlscan/doc/en/conformance.html +136 -0
  47. data/redist/xmlscan/doc/en/conformance.rd +152 -0
  48. data/redist/xmlscan/doc/en/manual.html +356 -0
  49. data/redist/xmlscan/doc/en/manual.rd +402 -0
  50. data/redist/xmlscan/doc/ja/conformance.ja.html +118 -0
  51. data/redist/xmlscan/doc/ja/conformance.ja.rd +134 -0
  52. data/redist/xmlscan/doc/ja/manual.ja.html +325 -0
  53. data/redist/xmlscan/doc/ja/manual.ja.rd +370 -0
  54. data/redist/xmlscan/doc/src/Makefile +41 -0
  55. data/redist/xmlscan/doc/src/conformance.rd.src +256 -0
  56. data/redist/xmlscan/doc/src/langsplit.rb +110 -0
  57. data/redist/xmlscan/doc/src/manual.rd.src +614 -0
  58. data/redist/xmlscan/install.rb +41 -0
  59. data/redist/xmlscan/lib/xmlscan/encoding.rb +311 -0
  60. data/redist/xmlscan/lib/xmlscan/htmlscan.rb +289 -0
  61. data/redist/xmlscan/lib/xmlscan/namespace.rb +352 -0
  62. data/redist/xmlscan/lib/xmlscan/parser.rb +299 -0
  63. data/redist/xmlscan/lib/xmlscan/scanner.rb +1109 -0
  64. data/redist/xmlscan/lib/xmlscan/version.rb +22 -0
  65. data/redist/xmlscan/lib/xmlscan/visitor.rb +158 -0
  66. data/redist/xmlscan/lib/xmlscan/xmlchar.rb +441 -0
  67. data/redist/xmlscan/memo/CONFORMANCE +1249 -0
  68. data/redist/xmlscan/memo/PRODUCTIONS +195 -0
  69. data/redist/xmlscan/memo/contentspec.ry +335 -0
  70. data/redist/xmlscan/samples/chibixml.rb +105 -0
  71. data/redist/xmlscan/samples/getxmlchar.rb +122 -0
  72. data/redist/xmlscan/samples/rexml.rb +159 -0
  73. data/redist/xmlscan/samples/xmlbench.rb +88 -0
  74. data/redist/xmlscan/samples/xmlbench/parser/chibixml.rb +22 -0
  75. data/redist/xmlscan/samples/xmlbench/parser/nqxml.rb +29 -0
  76. data/redist/xmlscan/samples/xmlbench/parser/rexml.rb +62 -0
  77. data/redist/xmlscan/samples/xmlbench/parser/xmlparser.rb +22 -0
  78. data/redist/xmlscan/samples/xmlbench/parser/xmlscan-0.0.10.rb +62 -0
  79. data/redist/xmlscan/samples/xmlbench/parser/xmlscan-chibixml.rb +22 -0
  80. data/redist/xmlscan/samples/xmlbench/parser/xmlscan-rexml.rb +22 -0
  81. data/redist/xmlscan/samples/xmlbench/parser/xmlscan.rb +99 -0
  82. data/redist/xmlscan/samples/xmlbench/xmlbench-lib.rb +116 -0
  83. data/redist/xmlscan/samples/xmlconftest.rb +200 -0
  84. data/redist/xmlscan/test.rb +7 -0
  85. data/redist/xmlscan/tests/deftestcase.rb +73 -0
  86. data/redist/xmlscan/tests/runtest.rb +47 -0
  87. data/redist/xmlscan/tests/testall.rb +14 -0
  88. data/redist/xmlscan/tests/testencoding.rb +438 -0
  89. data/redist/xmlscan/tests/testhtmlscan.rb +752 -0
  90. data/redist/xmlscan/tests/testnamespace.rb +457 -0
  91. data/redist/xmlscan/tests/testparser.rb +591 -0
  92. data/redist/xmlscan/tests/testscanner.rb +1749 -0
  93. data/redist/xmlscan/tests/testxmlchar.rb +143 -0
  94. data/redist/xmlscan/tests/visitor.rb +34 -0
  95. data/test/array_extensions_test.rb +2 -2
  96. data/test/ea_instantiator_test.rb +41 -0
  97. data/test/ecore_self_test.rb +53 -0
  98. data/test/environment_test.rb +11 -6
  99. data/test/metamodel_builder_test.rb +404 -245
  100. data/test/metamodel_roundtrip_test.rb +52 -0
  101. data/test/metamodel_roundtrip_test/TestModel.rb +65 -0
  102. data/test/metamodel_roundtrip_test/TestModel_Regenerated.rb +64 -0
  103. data/test/metamodel_roundtrip_test/houseMetamodel.ecore +32 -0
  104. data/test/metamodel_roundtrip_test/houseMetamodel_from_ecore.rb +39 -0
  105. data/test/rgen_test.rb +3 -3
  106. data/test/template_language_test.rb +65 -39
  107. data/test/template_language_test/expected_result.txt +24 -3
  108. data/test/template_language_test/templates/code/array.tpl +11 -0
  109. data/test/template_language_test/templates/content/author.tpl +7 -0
  110. data/test/template_language_test/templates/content/chapter.tpl +1 -1
  111. data/test/template_language_test/templates/root.tpl +17 -8
  112. data/test/template_language_test/testout.txt +24 -3
  113. data/test/testmodel/class_model_checker.rb +119 -0
  114. data/test/{xmi_instantiator_test/testmodel.eap → testmodel/ea_testmodel.eap} +0 -0
  115. data/test/{xmi_instantiator_test/testmodel.xml → testmodel/ea_testmodel.xml} +81 -14
  116. data/test/testmodel/ea_testmodel_partial.xml +317 -0
  117. data/test/testmodel/ecore_model_checker.rb +101 -0
  118. data/test/testmodel/manual_testmodel.xml +22 -0
  119. data/test/testmodel/object_model_checker.rb +67 -0
  120. data/test/transformer_test.rb +18 -10
  121. data/test/xml_instantiator_test.rb +81 -8
  122. data/test/xml_instantiator_test/simple_ecore_model_checker.rb +94 -0
  123. data/test/xml_instantiator_test/simple_xmi_ecore_instantiator.rb +53 -0
  124. data/test/xml_instantiator_test/simple_xmi_metamodel.rb +49 -0
  125. data/test/xml_instantiator_test/simple_xmi_to_ecore.rb +75 -0
  126. metadata +126 -28
  127. data/lib/ea/xmi_class_instantiator.rb +0 -46
  128. data/lib/ea/xmi_helper.rb +0 -26
  129. data/lib/ea/xmi_metamodel.rb +0 -34
  130. data/lib/ea/xmi_object_instantiator.rb +0 -46
  131. data/lib/ea/xmi_to_classmodel.rb +0 -78
  132. data/lib/ea/xmi_to_objectmodel.rb +0 -92
  133. data/lib/mmgen/mm_ext/uml_classmodel_ext.rb +0 -71
  134. data/lib/mmgen/templates/uml_classmodel.tpl +0 -63
  135. data/lib/rgen/xml_instantiator.rb +0 -132
  136. data/lib/uml/objectmodel_instantiator.rb +0 -53
  137. data/lib/uml/uml_classmodel.rb +0 -92
  138. data/lib/uml/uml_objectmodel.rb +0 -65
  139. data/test/metamodel_generator_test.rb +0 -44
  140. data/test/metamodel_generator_test/TestModel.rb +0 -40
  141. data/test/metamodel_generator_test/expected_result.txt +0 -40
  142. data/test/xmi_class_instantiator_test.rb +0 -24
  143. data/test/xmi_instantiator_test/class_model_checker.rb +0 -97
  144. data/test/xmi_object_instantiator_test.rb +0 -65
  145. data/test/xml_instantiator_test/testmodel.xml +0 -7
@@ -0,0 +1,101 @@
1
+ require 'rgen/ecore/ecore'
2
+
3
+ module Testmodel
4
+
5
+ # Checks the ECore model elements created by transformation from the
6
+ # UML Class model elements from the example model
7
+ #
8
+ module ECoreModelChecker
9
+ include RGen::ECore
10
+
11
+ def checkECoreModel(env)
12
+
13
+ # check main package
14
+ mainPackage = env.elements.select {|e| e.is_a? EPackage and e.name == "HouseMetamodel"}.first
15
+ assert_not_nil mainPackage
16
+
17
+ # check Rooms package
18
+ assert mainPackage.eSubpackages.is_a?(Array)
19
+ assert_equal 1, mainPackage.eSubpackages.size
20
+ assert mainPackage.eSubpackages[0].is_a?(EPackage)
21
+ roomsPackage = mainPackage.eSubpackages[0]
22
+ assert_equal "Rooms", roomsPackage.name
23
+
24
+ # check main package classes
25
+ assert mainPackage.eClassifiers.is_a?(Array)
26
+ assert_equal 4, mainPackage.eClassifiers.size
27
+ assert mainPackage.eClassifiers.all?{|c| c.is_a?(EClass)}
28
+ houseClass = mainPackage.eClassifiers.select{|c| c.name == "House"}.first
29
+ personClass = mainPackage.eClassifiers.select{|c| c.name == "Person"}.first
30
+ meetingPlaceClass = mainPackage.eClassifiers.select{|c| c.name == "MeetingPlace"}.first
31
+ cookingPlaceInterface = mainPackage.eClassifiers.select{|c| c.name == "CookingPlace"}.first
32
+ assert_not_nil houseClass
33
+ assert_not_nil personClass
34
+ assert_not_nil meetingPlaceClass
35
+ assert_not_nil cookingPlaceInterface
36
+
37
+ # check Rooms package classes
38
+ assert roomsPackage.eClassifiers.is_a?(Array)
39
+ assert_equal 3, roomsPackage.eClassifiers.size
40
+ assert roomsPackage.eClassifiers.all?{|c| c.is_a?(EClass)}
41
+ roomClass = roomsPackage.eClassifiers.select{|c| c.name == "Room"}.first
42
+ kitchenClass = roomsPackage.eClassifiers.select{|c| c.name == "Kitchen"}.first
43
+ bathroomClass = roomsPackage.eClassifiers.select{|c| c.name == "Bathroom"}.first
44
+ assert_not_nil roomClass
45
+ assert_not_nil kitchenClass
46
+ assert_not_nil bathroomClass
47
+
48
+ # check Room inheritance
49
+ assert kitchenClass.eSuperTypes.is_a?(Array)
50
+ assert_equal 3, kitchenClass.eSuperTypes.size
51
+ assert_equal roomClass.object_id, kitchenClass.eSuperTypes.select{|c| c.name == "Room"}.first.object_id
52
+ assert_equal meetingPlaceClass.object_id, kitchenClass.eSuperTypes.select{|c| c.name == "MeetingPlace"}.first.object_id
53
+ assert_equal cookingPlaceInterface.object_id, kitchenClass.eSuperTypes.select{|c| c.name == "CookingPlace"}.first.object_id
54
+ assert bathroomClass.eSuperTypes.is_a?(Array)
55
+ assert_equal 1, bathroomClass.eSuperTypes.size
56
+ assert_equal roomClass.object_id, bathroomClass.eSuperTypes[0].object_id
57
+
58
+ # check House-Room "part of" association
59
+ assert houseClass.eAllContainments.eType.is_a?(Array)
60
+ assert_equal 1, houseClass.eAllContainments.eType.size
61
+ roomRef = houseClass.eAllContainments.first
62
+ assert_equal roomClass.object_id, roomRef.eType.object_id
63
+ assert_equal "room", roomRef.name
64
+ assert_equal 1, roomRef.lowerBound
65
+ assert_equal(-1, roomRef.upperBound)
66
+ assert_not_nil roomRef.eOpposite
67
+ assert_equal houseClass.object_id, roomRef.eOpposite.eType.object_id
68
+
69
+ partOfRefs = roomClass.eReferences.select{|r| r.eOpposite && r.eOpposite.containment}
70
+ assert_equal 1, partOfRefs.size
71
+ assert_equal houseClass.object_id, partOfRefs.first.eType.object_id
72
+ assert_equal "house", partOfRefs.first.name
73
+ assert_equal roomRef.object_id, partOfRefs.first.eOpposite.object_id
74
+
75
+ # check House OUT associations
76
+ assert houseClass.eReferences.is_a?(Array)
77
+ assert_equal 3, houseClass.eReferences.size
78
+ bathRef = houseClass.eReferences.find {|e| e.name == "bathroom"}
79
+ kitchenRef = houseClass.eReferences.find {|e| e.name == "kitchen"}
80
+ roomRef = houseClass.eReferences.find {|e| e.name == "room"}
81
+ assert_not_nil bathRef
82
+ assert_nil bathRef.eOpposite
83
+ assert_not_nil kitchenRef
84
+ assert_not_nil roomRef
85
+ assert_equal 1, kitchenRef.lowerBound
86
+ assert_equal 1, kitchenRef.upperBound
87
+ assert_equal 1, roomRef.lowerBound
88
+ assert_equal(-1, roomRef.upperBound)
89
+
90
+ # check House IN associations
91
+ houseInRefs = env.find(:class => EReference, :eType => houseClass)
92
+ assert_equal 3, houseInRefs.size
93
+ homeEnd = houseInRefs.find{|e| e.name == "home"}
94
+ assert_not_nil homeEnd
95
+ assert_equal 0, homeEnd.lowerBound
96
+ assert_equal(-1, homeEnd.upperBound)
97
+
98
+ end
99
+ end
100
+
101
+ end
@@ -0,0 +1,22 @@
1
+ <TestModel xmlns:MNS="testmodel.org/myNamespace" >
2
+ <MNS:House>
3
+ before kitchen
4
+ <MNS:Room id="1" name="Kitchen" />
5
+ after kitchen
6
+ <MNS:Room id="2" name="TomsRoom">within toms room</MNS:Room>
7
+ after toms room
8
+ </MNS:House>
9
+ <Person name="Tom" room="2">
10
+ <Parents>
11
+ <Person name="Kate">
12
+ <Parents>
13
+ <Person name="Maria" />
14
+ <Person name="Will" />
15
+ </Parents>
16
+ </Person>
17
+ </Parents>
18
+ </Person>
19
+ <MULTI-PART-NAME>
20
+ <INSIDE_MULTI_PART/>
21
+ </MULTI-PART-NAME>
22
+ </TestModel>
@@ -0,0 +1,67 @@
1
+ require 'metamodels/uml13_metamodel'
2
+ require 'metamodels/uml13_metamodel_ext'
3
+
4
+ module Testmodel
5
+
6
+ # Checks the UML Object model elements from the example model
7
+ #
8
+ module ObjectModelChecker
9
+
10
+ # convenient extension for this test only
11
+ module UML13::ClassifierRole::ClassModule
12
+ def classname
13
+ taggedValue.find{|tv| tv.tag == "classname"}.value
14
+ end
15
+ end
16
+
17
+ def checkObjectModel(envUML)
18
+
19
+ # check main package
20
+ mainPackage = envUML.find(:class => UML13::Package, :name => "HouseExampleModel").first
21
+ assert_not_nil mainPackage
22
+
23
+ eaRootCollaboration = mainPackage.ownedElement.find{|e| e.is_a?(UML13::Collaboration) && e.name == "Collaborations"}
24
+ assert_not_nil eaRootCollaboration
25
+
26
+ # check main package objects
27
+ objects = eaRootCollaboration.ownedElement.select{|e| e.is_a?(UML13::ClassifierRole)}
28
+ assert_equal 6, objects.size
29
+
30
+ someone = objects.find{|o| o.name == "Someone"}
31
+ assert_equal "Person", someone.classname
32
+
33
+ someonesHouse = objects.find{|o| o.name == "SomeonesHouse"}
34
+ assert_equal "House", someonesHouse.classname
35
+
36
+ greenRoom = objects.find{|o| o.name == "GreenRoom"}
37
+ assert_equal "Room", greenRoom.classname
38
+
39
+ yellowRoom = objects.find{|o| o.name == "YellowRoom"}
40
+ assert_equal "Room", yellowRoom.classname
41
+
42
+ hotRoom = objects.find{|o| o.name == "HotRoom"}
43
+ assert_equal "Kitchen", hotRoom.classname
44
+
45
+ wetRoom = objects.find{|o| o.name == "WetRoom"}
46
+ assert_equal "Bathroom", wetRoom.classname
47
+
48
+ # Someone to SomeonesHouse
49
+ assert someone.associationEnd.otherEnd.getType.is_a?(Array)
50
+ assert_equal 1, someone.associationEnd.otherEnd.getType.size
51
+ houseEnd = someone.associationEnd.otherEnd[0]
52
+ assert_equal someonesHouse.object_id, houseEnd.getType.object_id
53
+ assert_equal "home", houseEnd.name
54
+
55
+ # Someone to SomeonesHouse
56
+ assert someonesHouse.localCompositeEnd.otherEnd.is_a?(Array)
57
+ assert_equal 4, someonesHouse.localCompositeEnd.otherEnd.size
58
+ assert someonesHouse.localCompositeEnd.otherEnd.all?{|e| e.name == "room"}
59
+ assert_not_nil someonesHouse.localCompositeEnd.otherEnd.getType.find{|o| o == yellowRoom}
60
+ assert_not_nil someonesHouse.localCompositeEnd.otherEnd.getType.find{|o| o == greenRoom}
61
+ assert_not_nil someonesHouse.localCompositeEnd.otherEnd.getType.find{|o| o == hotRoom}
62
+ assert_not_nil someonesHouse.localCompositeEnd.otherEnd.getType.find{|o| o == wetRoom}
63
+
64
+ end
65
+ end
66
+
67
+ end
@@ -4,9 +4,10 @@ $:.unshift File.join(File.dirname(__FILE__),"..","test")
4
4
  require 'test/unit'
5
5
  require 'rgen/transformer'
6
6
  require 'rgen/environment'
7
- require 'uml/uml_classmodel'
8
- require 'ea/xmi_class_instantiator'
9
- require 'xmi_instantiator_test/class_model_checker'
7
+ require 'rgen/model_comparator'
8
+ require 'metamodels/uml13_metamodel'
9
+ require 'instantiators/ea_instantiator'
10
+ require 'testmodel/class_model_checker'
10
11
 
11
12
  class TransformerTest < Test::Unit::TestCase
12
13
 
@@ -179,25 +180,32 @@ class TransformerTest < Test::Unit::TestCase
179
180
  end
180
181
 
181
182
  class CopyTransformer < RGen::Transformer
182
- include UMLClassModel
183
+ include UML13
183
184
  def transform
184
- trans(:class => UMLPackage)
185
+ trans(:class => UML13::Package)
185
186
  end
186
- constants.each{|c| copy const_get(c) if c =~ /^UML/}
187
+ UML13.ecore.eClassifiers.each do |c|
188
+ copy c.instanceClass
189
+ end
187
190
  end
188
191
 
189
- MODEL_DIR = File.join(File.dirname(__FILE__),"xmi_instantiator_test")
192
+ MODEL_DIR = File.join(File.dirname(__FILE__),"testmodel")
190
193
 
191
- include ClassModelChecker
194
+ include Testmodel::ClassModelChecker
195
+ include RGen::ModelComparator
192
196
 
193
197
  def test_copyTransformer
194
198
  envIn = RGen::Environment.new
195
199
  envOut = RGen::Environment.new
196
- File.open(MODEL_DIR+"/testmodel.xml") { |f|
197
- XMIClassInstantiator.new.instantiateUMLClassModel(envIn, f.read)
200
+ File.open(MODEL_DIR+"/ea_testmodel.xml") { |f|
201
+ inst = EAInstantiator.new(envIn, EAInstantiator::ERROR)
202
+ inst.instantiate(f.read)
198
203
  }
199
204
  CopyTransformer.new(envIn, envOut).transform
200
205
  checkClassModel(envOut)
206
+ assert modelEqual?(
207
+ envIn.find(:class => UML13::Model).first,
208
+ envOut.find(:class => UML13::Model).first)
201
209
  end
202
210
 
203
211
  end
@@ -1,9 +1,11 @@
1
1
  $:.unshift File.join(File.dirname(__FILE__),"..","lib")
2
2
 
3
3
  require 'test/unit'
4
- require 'rgen/xml_instantiator'
4
+ require 'rgen/instantiator/default_xml_instantiator'
5
5
  require 'rgen/environment'
6
6
  require 'rgen/model_dumper'
7
+ require 'xml_instantiator_test/simple_xmi_ecore_instantiator'
8
+ require 'xml_instantiator_test/simple_ecore_model_checker'
7
9
 
8
10
  module EmptyMM
9
11
  end
@@ -18,14 +20,18 @@ end
18
20
 
19
21
  class XMLInstantiatorTest < Test::Unit::TestCase
20
22
 
21
- XML_DIR = File.join(File.dirname(__FILE__),"xml_instantiator_test")
23
+ XML_DIR = File.join(File.dirname(__FILE__),"testmodel")
22
24
 
23
25
  include RGen::ModelDumper
24
26
 
25
- class MyInstantiator < RGen::XMLInstantiator
27
+ class MyInstantiator < RGen::Instantiator::DefaultXMLInstantiator
26
28
 
27
29
  map_tag_ns "testmodel.org/myNamespace", DefaultMM::MNS
28
30
 
31
+ def class_name(str)
32
+ camelize(str)
33
+ end
34
+
29
35
  # resolve :type do
30
36
  # @env.find(:xmi_id => getType).first
31
37
  # end
@@ -34,10 +40,60 @@ class XMLInstantiatorTest < Test::Unit::TestCase
34
40
 
35
41
  end
36
42
 
43
+ class PruneTestInstantiator < RGen::Instantiator::NodebasedXMLInstantiator
44
+ attr_reader :max_depth
45
+
46
+ set_prune_level 2
47
+
48
+ def initialize(env)
49
+ super(env)
50
+ @max_depth = 0
51
+ end
52
+
53
+ def on_descent(node)
54
+ end
55
+
56
+ def on_ascent(node)
57
+ calc_max_depth(node, 0)
58
+ end
59
+
60
+ def calc_max_depth(node, offset)
61
+ if node.children.nil? || node.children.size == 0
62
+ @max_depth = offset if offset > @max_depth
63
+ else
64
+ node.children.each do |c|
65
+ calc_max_depth(c, offset+1)
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ module PruneTestMM
72
+ end
73
+
74
+ def test_pruning
75
+ env = RGen::Environment.new
76
+
77
+ # prune level 2 is set in the class body
78
+ inst = PruneTestInstantiator.new(env)
79
+ inst.instantiate_file(File.join(XML_DIR,"manual_testmodel.xml"))
80
+ assert_equal 2, inst.max_depth
81
+
82
+ PruneTestInstantiator.set_prune_level(0)
83
+ inst = PruneTestInstantiator.new(env)
84
+ inst.instantiate_file(File.join(XML_DIR,"manual_testmodel.xml"))
85
+ assert_equal 5, inst.max_depth
86
+
87
+ PruneTestInstantiator.set_prune_level(1)
88
+ inst = PruneTestInstantiator.new(env)
89
+ inst.instantiate_file(File.join(XML_DIR,"manual_testmodel.xml"))
90
+ assert_equal 1, inst.max_depth
91
+ end
92
+
37
93
  def test_custom
38
94
  env = RGen::Environment.new
39
95
  inst = MyInstantiator.new(env, DefaultMM, true)
40
- inst.instantiate_file(File.join(XML_DIR,"testmodel.xml"))
96
+ inst.instantiate_file(File.join(XML_DIR,"manual_testmodel.xml"))
41
97
 
42
98
  house = env.find(:class => DefaultMM::MNS::House).first
43
99
  assert_not_nil house
@@ -51,21 +107,27 @@ class XMLInstantiatorTest < Test::Unit::TestCase
51
107
  assert_not_nil tomsRoom
52
108
 
53
109
  persons = env.find(:class => DefaultMM::Person)
54
- assert_equal 1, persons.size
110
+ assert_equal 4, persons.size
55
111
  tom = persons.select{|p| p.name == "Tom"}.first
56
112
  assert_not_nil tom
57
113
 
58
114
  assert tom.personalRoom == tomsRoom
115
+
116
+ mpns = env.find(:class => DefaultMM::MultiPartName)
117
+ assert mpns.first.respond_to?("insideMultiPart")
59
118
  end
60
119
 
61
120
  def test_default
62
121
  env = RGen::Environment.new
63
- inst = RGen::XMLInstantiator.new(env, EmptyMM, true)
64
- inst.instantiate_file(File.join(XML_DIR,"testmodel.xml"))
122
+ inst = RGen::Instantiator::DefaultXMLInstantiator.new(env, EmptyMM, true)
123
+ inst.instantiate_file(File.join(XML_DIR,"manual_testmodel.xml"))
65
124
 
66
125
  house = env.find(:class => EmptyMM::MNS_House).first
67
126
  assert_not_nil house
68
127
  assert_equal 2, house.mNS_Room.size
128
+ assert_equal "before kitchen", house.chardata[0].strip
129
+ assert_equal "after kitchen", house.chardata[1].strip
130
+ assert_equal "after toms room", house.chardata[2].strip
69
131
 
70
132
  rooms = env.find(:class => EmptyMM::MNS_Room)
71
133
  assert_equal 2, rooms.size
@@ -73,11 +135,22 @@ class XMLInstantiatorTest < Test::Unit::TestCase
73
135
  rooms.each {|r| assert r.parent == house}
74
136
  tomsRoom = rooms.select{|r| r.name == "TomsRoom"}.first
75
137
  assert_not_nil tomsRoom
138
+ assert_equal "within toms room", tomsRoom.chardata[0]
76
139
 
77
140
  persons = env.find(:class => EmptyMM::Person)
78
- assert_equal 1, persons.size
141
+ assert_equal 4, persons.size
79
142
  tom = persons.select{|p| p.name == "Tom"}.first
80
143
  assert_not_nil tom
81
144
  end
145
+
146
+ include SimpleECoreModelChecker
82
147
 
148
+ def test_simle_xmi_ecore_instantiator
149
+ envECore = RGen::Environment.new
150
+ File.open(XML_DIR+"/ea_testmodel.xml") { |f|
151
+ SimpleXMIECoreInstantiator.new.instantiateECoreModel(envECore, f.read)
152
+ }
153
+ checkECoreModel(envECore)
154
+ end
155
+
83
156
  end
@@ -0,0 +1,94 @@
1
+ require 'rgen/ecore/ecore'
2
+
3
+ # This "light" version of the ECore model checker is used to check the
4
+ # model produced by the XMLInstantiatorTest only.
5
+ #
6
+ module SimpleECoreModelChecker
7
+ include RGen::ECore
8
+
9
+ def checkECoreModel(env)
10
+
11
+ # check main package
12
+ mainPackage = env.elements.select {|e| e.is_a? EPackage and e.name == "HouseMetamodel"}.first
13
+ assert_not_nil mainPackage
14
+
15
+ # check Rooms package
16
+ assert mainPackage.eSubpackages.is_a?(Array)
17
+ assert_equal 1, mainPackage.eSubpackages.size
18
+ assert mainPackage.eSubpackages[0].is_a?(EPackage)
19
+ roomsPackage = mainPackage.eSubpackages[0]
20
+ assert_equal "Rooms", roomsPackage.name
21
+
22
+ # check main package classes
23
+ assert mainPackage.eClassifiers.is_a?(Array)
24
+ assert_equal 3, mainPackage.eClassifiers.size
25
+ assert mainPackage.eClassifiers.all?{|c| c.is_a?(EClass)}
26
+ houseClass = mainPackage.eClassifiers.select{|c| c.name == "House"}.first
27
+ personClass = mainPackage.eClassifiers.select{|c| c.name == "Person"}.first
28
+ meetingPlaceClass = mainPackage.eClassifiers.select{|c| c.name == "MeetingPlace"}.first
29
+ assert_not_nil houseClass
30
+ assert_not_nil personClass
31
+ assert_not_nil meetingPlaceClass
32
+
33
+ # check Rooms package classes
34
+ assert roomsPackage.eClassifiers.is_a?(Array)
35
+ assert_equal 3, roomsPackage.eClassifiers.size
36
+ assert roomsPackage.eClassifiers.all?{|c| c.is_a?(EClass)}
37
+ roomClass = roomsPackage.eClassifiers.select{|c| c.name == "Room"}.first
38
+ kitchenClass = roomsPackage.eClassifiers.select{|c| c.name == "Kitchen"}.first
39
+ bathroomClass = roomsPackage.eClassifiers.select{|c| c.name == "Bathroom"}.first
40
+ assert_not_nil roomClass
41
+ assert_not_nil kitchenClass
42
+ assert_not_nil bathroomClass
43
+
44
+ # check Room inheritance
45
+ assert kitchenClass.eSuperTypes.is_a?(Array)
46
+ assert_equal 2, kitchenClass.eSuperTypes.size
47
+ assert_equal roomClass.object_id, kitchenClass.eSuperTypes.select{|c| c.name == "Room"}.first.object_id
48
+ assert_equal meetingPlaceClass.object_id, kitchenClass.eSuperTypes.select{|c| c.name == "MeetingPlace"}.first.object_id
49
+ assert bathroomClass.eSuperTypes.is_a?(Array)
50
+ assert_equal 1, bathroomClass.eSuperTypes.size
51
+ assert_equal roomClass.object_id, bathroomClass.eSuperTypes[0].object_id
52
+
53
+ # check House-Room "part of" association
54
+ assert houseClass.eAllContainments.eType.is_a?(Array)
55
+ assert_equal 1, houseClass.eAllContainments.eType.size
56
+ roomRef = houseClass.eAllContainments.first
57
+ assert_equal roomClass.object_id, roomRef.eType.object_id
58
+ assert_equal "room", roomRef.name
59
+ assert_equal 1, roomRef.lowerBound
60
+ assert_equal(-1, roomRef.upperBound)
61
+ assert_not_nil roomRef.eOpposite
62
+ assert_equal houseClass.object_id, roomRef.eOpposite.eType.object_id
63
+
64
+ partOfRefs = roomClass.eReferences.select{|r| r.eOpposite && r.eOpposite.containment}
65
+ assert_equal 1, partOfRefs.size
66
+ assert_equal houseClass.object_id, partOfRefs.first.eType.object_id
67
+ assert_equal "house", partOfRefs.first.name
68
+ assert_equal roomRef.object_id, partOfRefs.first.eOpposite.object_id
69
+
70
+ # check House OUT associations
71
+ assert houseClass.eReferences.is_a?(Array)
72
+ assert_equal 3, houseClass.eReferences.size
73
+ bathRef = houseClass.eReferences.find {|e| e.name == "bathroom"}
74
+ kitchenRef = houseClass.eReferences.find {|e| e.name == "kitchen"}
75
+ roomRef = houseClass.eReferences.find {|e| e.name == "room"}
76
+ assert_not_nil bathRef
77
+ assert_nil bathRef.eOpposite
78
+ assert_not_nil kitchenRef
79
+ assert_not_nil roomRef
80
+ assert_equal 1, kitchenRef.lowerBound
81
+ assert_equal 1, kitchenRef.upperBound
82
+ assert_equal 1, roomRef.lowerBound
83
+ assert_equal(-1, roomRef.upperBound)
84
+
85
+ # check House IN associations
86
+ houseInRefs = env.find(:class => EReference, :eType => houseClass)
87
+ assert_equal 3, houseInRefs.size
88
+ homeEnd = houseInRefs.find{|e| e.name == "home"}
89
+ assert_not_nil homeEnd
90
+ assert_equal 0, homeEnd.lowerBound
91
+ assert_equal(-1, homeEnd.upperBound)
92
+
93
+ end
94
+ end