rgen 0.5.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. data/CHANGELOG +28 -0
  2. data/Rakefile +3 -4
  3. data/lib/ea_support/uml13_ea_metamodel.rb +3 -3
  4. data/lib/ea_support/uml13_ea_to_uml13.rb +33 -2
  5. data/lib/ea_support/uml13_to_uml13_ea.rb +7 -0
  6. data/lib/mmgen/mm_ext/ecore_mmgen_ext.rb +4 -4
  7. data/lib/mmgen/templates/metamodel_generator.tpl +143 -143
  8. data/lib/rgen/ecore/ecore.rb +11 -1
  9. data/lib/rgen/ecore/ecore_interface.rb +47 -0
  10. data/lib/rgen/ecore/ecore_to_ruby.rb +166 -0
  11. data/lib/rgen/ecore/{ecore_transformer.rb → ruby_to_ecore.rb} +11 -11
  12. data/lib/rgen/environment.rb +15 -2
  13. data/lib/rgen/fragment/dump_file_cache.rb +63 -0
  14. data/lib/rgen/fragment/fragmented_model.rb +139 -0
  15. data/lib/rgen/fragment/model_fragment.rb +268 -0
  16. data/lib/rgen/instantiator/abstract_xml_instantiator.rb +44 -72
  17. data/lib/rgen/instantiator/default_xml_instantiator.rb +2 -2
  18. data/lib/rgen/instantiator/ecore_xml_instantiator.rb +16 -1
  19. data/lib/rgen/instantiator/json_instantiator.rb +16 -2
  20. data/lib/rgen/instantiator/nodebased_xml_instantiator.rb +118 -138
  21. data/lib/rgen/instantiator/qualified_name_resolver.rb +5 -1
  22. data/lib/rgen/instantiator/reference_resolver.rb +126 -24
  23. data/lib/rgen/instantiator/xmi11_instantiator.rb +6 -2
  24. data/lib/rgen/metamodel_builder.rb +18 -6
  25. data/lib/rgen/metamodel_builder/builder_extensions.rb +431 -407
  26. data/lib/rgen/metamodel_builder/builder_runtime.rb +8 -8
  27. data/lib/rgen/metamodel_builder/constant_order_helper.rb +4 -4
  28. data/lib/rgen/metamodel_builder/data_types.rb +5 -1
  29. data/lib/rgen/metamodel_builder/intermediate/feature.rb +167 -0
  30. data/lib/rgen/metamodel_builder/module_extension.rb +2 -2
  31. data/lib/rgen/model_builder.rb +10 -5
  32. data/lib/rgen/model_builder/builder_context.rb +17 -1
  33. data/lib/rgen/serializer/opposite_reference_filter.rb +18 -0
  34. data/lib/rgen/serializer/qualified_name_provider.rb +45 -0
  35. data/lib/rgen/template_language/template_container.rb +3 -1
  36. data/lib/rgen/{auto_class_creator.rb → util/auto_class_creator.rb} +6 -1
  37. data/lib/rgen/util/cached_glob.rb +67 -0
  38. data/lib/rgen/util/file_cache_map.rb +104 -0
  39. data/lib/rgen/util/file_change_detector.rb +78 -0
  40. data/lib/rgen/{method_delegation.rb → util/method_delegation.rb} +18 -3
  41. data/lib/rgen/{model_comparator.rb → util/model_comparator.rb} +17 -5
  42. data/lib/rgen/{model_comparator_base.rb → util/model_comparator_base.rb} +6 -1
  43. data/lib/rgen/{model_dumper.rb → util/model_dumper.rb} +6 -1
  44. data/lib/rgen/{name_helper.rb → util/name_helper.rb} +6 -1
  45. data/lib/rgen/util/pattern_matcher.rb +329 -0
  46. data/lib/transformers/uml13_to_ecore.rb +103 -60
  47. data/test/ecore_self_test.rb +43 -42
  48. data/test/json_test.rb +15 -0
  49. data/test/metamodel_builder_test.rb +361 -206
  50. data/test/metamodel_from_ecore_test.rb +45 -0
  51. data/test/metamodel_order_test.rb +10 -4
  52. data/test/metamodel_roundtrip_test.rb +2 -2
  53. data/test/metamodel_roundtrip_test/TestModel_Regenerated.rb +1 -1
  54. data/test/metamodel_roundtrip_test/houseMetamodel_Regenerated.ecore +50 -50
  55. data/test/method_delegation_test.rb +9 -9
  56. data/test/model_builder/ecore_internal.rb +19 -9
  57. data/test/model_builder/serializer_test.rb +1 -1
  58. data/test/reference_resolver_test.rb +79 -12
  59. data/test/rgen_test.rb +2 -0
  60. data/test/template_language_test.rb +7 -0
  61. data/test/template_language_test/templates/callback_indent_test/a.tpl +12 -0
  62. data/test/template_language_test/templates/callback_indent_test/b.tpl +5 -0
  63. data/test/testmodel/ea_testmodel_regenerated.xml +588 -583
  64. data/test/transformer_test.rb +3 -3
  65. data/test/util/file_cache_map_test.rb +91 -0
  66. data/test/util/file_cache_map_test/testdir/fileA +1 -0
  67. data/test/util_test.rb +4 -0
  68. data/test/xml_instantiator_test.rb +139 -135
  69. metadata +49 -104
  70. data/lib/rgen/ecore/ecore_instantiator.rb +0 -31
  71. data/lib/rgen/metamodel_builder/metamodel_description.rb +0 -232
  72. data/redist/xmlscan/ChangeLog +0 -1301
  73. data/redist/xmlscan/README +0 -34
  74. data/redist/xmlscan/THANKS +0 -11
  75. data/redist/xmlscan/doc/changes.html +0 -74
  76. data/redist/xmlscan/doc/changes.rd +0 -80
  77. data/redist/xmlscan/doc/en/conformance.html +0 -136
  78. data/redist/xmlscan/doc/en/conformance.rd +0 -152
  79. data/redist/xmlscan/doc/en/manual.html +0 -356
  80. data/redist/xmlscan/doc/en/manual.rd +0 -402
  81. data/redist/xmlscan/doc/ja/conformance.ja.html +0 -118
  82. data/redist/xmlscan/doc/ja/conformance.ja.rd +0 -134
  83. data/redist/xmlscan/doc/ja/manual.ja.html +0 -325
  84. data/redist/xmlscan/doc/ja/manual.ja.rd +0 -370
  85. data/redist/xmlscan/doc/src/Makefile +0 -41
  86. data/redist/xmlscan/doc/src/conformance.rd.src +0 -256
  87. data/redist/xmlscan/doc/src/langsplit.rb +0 -110
  88. data/redist/xmlscan/doc/src/manual.rd.src +0 -614
  89. data/redist/xmlscan/install.rb +0 -41
  90. data/redist/xmlscan/lib/xmlscan/encoding.rb +0 -311
  91. data/redist/xmlscan/lib/xmlscan/htmlscan.rb +0 -289
  92. data/redist/xmlscan/lib/xmlscan/namespace.rb +0 -352
  93. data/redist/xmlscan/lib/xmlscan/parser.rb +0 -299
  94. data/redist/xmlscan/lib/xmlscan/scanner.rb +0 -1109
  95. data/redist/xmlscan/lib/xmlscan/version.rb +0 -22
  96. data/redist/xmlscan/lib/xmlscan/visitor.rb +0 -158
  97. data/redist/xmlscan/lib/xmlscan/xmlchar.rb +0 -441
  98. data/redist/xmlscan/memo/CONFORMANCE +0 -1249
  99. data/redist/xmlscan/memo/PRODUCTIONS +0 -195
  100. data/redist/xmlscan/memo/contentspec.ry +0 -335
  101. data/redist/xmlscan/samples/chibixml.rb +0 -105
  102. data/redist/xmlscan/samples/getxmlchar.rb +0 -122
  103. data/redist/xmlscan/samples/rexml.rb +0 -159
  104. data/redist/xmlscan/samples/xmlbench.rb +0 -88
  105. data/redist/xmlscan/samples/xmlbench/parser/chibixml.rb +0 -22
  106. data/redist/xmlscan/samples/xmlbench/parser/nqxml.rb +0 -29
  107. data/redist/xmlscan/samples/xmlbench/parser/rexml.rb +0 -62
  108. data/redist/xmlscan/samples/xmlbench/parser/xmlparser.rb +0 -22
  109. data/redist/xmlscan/samples/xmlbench/parser/xmlscan-0.0.10.rb +0 -62
  110. data/redist/xmlscan/samples/xmlbench/parser/xmlscan-chibixml.rb +0 -22
  111. data/redist/xmlscan/samples/xmlbench/parser/xmlscan-rexml.rb +0 -22
  112. data/redist/xmlscan/samples/xmlbench/parser/xmlscan.rb +0 -99
  113. data/redist/xmlscan/samples/xmlbench/xmlbench-lib.rb +0 -116
  114. data/redist/xmlscan/samples/xmlconftest.rb +0 -200
  115. data/redist/xmlscan/test.rb +0 -7
  116. data/redist/xmlscan/tests/deftestcase.rb +0 -73
  117. data/redist/xmlscan/tests/runtest.rb +0 -47
  118. data/redist/xmlscan/tests/testall.rb +0 -14
  119. data/redist/xmlscan/tests/testencoding.rb +0 -438
  120. data/redist/xmlscan/tests/testhtmlscan.rb +0 -752
  121. data/redist/xmlscan/tests/testnamespace.rb +0 -457
  122. data/redist/xmlscan/tests/testparser.rb +0 -591
  123. data/redist/xmlscan/tests/testscanner.rb +0 -1749
  124. data/redist/xmlscan/tests/testxmlchar.rb +0 -143
  125. data/redist/xmlscan/tests/visitor.rb +0 -34
@@ -4,71 +4,114 @@ require 'rgen/ecore/ecore'
4
4
  require 'rgen/array_extensions'
5
5
 
6
6
  class UML13ToECore < RGen::Transformer
7
- include RGen::ECore
7
+ include RGen::ECore
8
8
 
9
- def transform
10
- trans(:class => UML13::Class)
11
- end
9
+ # Options:
10
+ #
11
+ # :reference_filter:
12
+ # a proc which receives an AssociationEnd or a Dependency and should return
13
+ # true or false, depending on if a referece should be created for it or not
14
+ #
15
+ def initialize(*args)
16
+ options = {}
17
+ if args.last.is_a?(Hash)
18
+ options = args.pop
19
+ end
20
+ @reference_filter = options[:reference_filter] || proc do |e|
21
+ if e.is_a?(UML13::AssociationEnd)
22
+ otherEnd = e.association.connection.find{|ae| ae != e}
23
+ otherEnd.name && otherEnd.name.size > 0
24
+ else
25
+ false
26
+ end
27
+ end
28
+ super(*args)
29
+ end
12
30
 
13
- transform UML13::Model, :to => EPackage do
14
- trans(ownedClassOrPackage)
15
- { :name => name && name.strip }
16
- end
17
-
18
- transform UML13::Package, :to => EPackage do
19
- trans(ownedClassOrPackage)
20
- { :name => name && name.strip,
21
- :eSuperPackage => trans(namespace.is_a?(UML13::Package) ? namespace : nil) }
22
- end
23
-
24
- method :ownedClassOrPackage do
25
- ownedElement.select{|e| e.is_a?(UML13::Package) || e.is_a?(UML13::Class)}
26
- end
27
-
28
- transform UML13::Class, :to => EClass do
29
- { :name => name && name.strip,
30
- :ePackage => trans(namespace.is_a?(UML13::Package) ? namespace : nil),
31
- :eStructuralFeatures => trans(feature.select{|f| f.is_a?(UML13::Attribute)} + associationEnd),
32
- :eOperations => trans(feature.select{|f| f.is_a?(UML13::Operation)}),
33
- :eSuperTypes => trans(generalization.parent + clientDependency.select{|d| d.stereotype.name == "implements"}.supplier),
31
+ def transform
32
+ trans(:class => UML13::Class)
33
+ end
34
+
35
+ transform UML13::Model, :to => EPackage do
36
+ trans(ownedClassOrPackage)
37
+ { :name => name && name.strip }
38
+ end
39
+
40
+ transform UML13::Package, :to => EPackage do
41
+ trans(ownedClassOrPackage)
42
+ { :name => name && name.strip,
43
+ :eSuperPackage => trans(namespace.is_a?(UML13::Package) ? namespace : nil) }
44
+ end
45
+
46
+ method :ownedClassOrPackage do
47
+ ownedElement.select{|e| e.is_a?(UML13::Package) || e.is_a?(UML13::Class)}
48
+ end
49
+
50
+ transform UML13::Class, :to => EClass do
51
+ { :name => name && name.strip,
52
+ :abstract => isAbstract,
53
+ :ePackage => trans(namespace.is_a?(UML13::Package) ? namespace : nil),
54
+ :eStructuralFeatures => trans(feature.select{|f| f.is_a?(UML13::Attribute)} +
55
+ associationEnd + clientDependency),
56
+ :eOperations => trans(feature.select{|f| f.is_a?(UML13::Operation)}),
57
+ :eSuperTypes => trans(generalization.parent + clientDependency.select{|d| d.stereotype && d.stereotype.name == "implements"}.supplier),
34
58
  :eAnnotations => createAnnotations(taggedValue) }
35
- end
59
+ end
60
+
61
+ transform UML13::Interface, :to => EClass do
62
+ { :name => name && name.strip,
63
+ :abstract => isAbstract,
64
+ :ePackage => trans(namespace.is_a?(UML13::Package) ? namespace : nil),
65
+ :eStructuralFeatures => trans(feature.select{|f| f.is_a?(UML13::Attribute)} + associationEnd),
66
+ :eOperations => trans(feature.select{|f| f.is_a?(UML13::Operation)}),
67
+ :eSuperTypes => trans(generalization.parent)}
68
+ end
36
69
 
37
- transform UML13::Interface, :to => EClass do
38
- { :name => name && name.strip,
39
- :ePackage => trans(namespace.is_a?(UML13::Package) ? namespace : nil),
40
- :eStructuralFeatures => trans(feature.select{|f| f.is_a?(UML13::Attribute)} + associationEnd),
41
- :eOperations => trans(feature.select{|f| f.is_a?(UML13::Operation)}),
42
- :eSuperTypes => trans(generalization.parent)}
43
- end
70
+ transform UML13::Attribute, :to => EAttribute do
71
+ { :name => name && name.strip, :eType => trans(getType),
72
+ :lowerBound => (multiplicity && multiplicity.range.first.lower &&
73
+ multiplicity.range.first.lower.to_i) || 0,
74
+ :upperBound => (multiplicity && multiplicity.range.first.upper &&
75
+ multiplicity.range.first.upper.gsub('*','-1').to_i) || 1,
76
+ :eAnnotations => createAnnotations(taggedValue) }
77
+ end
44
78
 
45
- transform UML13::Attribute, :to => EAttribute do
46
- typemap = { "string" => EString, "boolean" => EBoolean, "int" => EInt, "float" => EFloat }
47
- { :name => name && name.strip, :eType => getType && typemap[getType.name && getType.name.downcase],
79
+ transform UML13::DataType, :to => EDataType do
80
+ { :name => name && name.strip,
81
+ :ePackage => trans(namespace.is_a?(UML13::Package) ? namespace : nil),
48
82
  :eAnnotations => createAnnotations(taggedValue) }
49
- end
50
-
51
- transform UML13::Operation, :to => EOperation do
52
- { :name => name && name.strip }
53
- end
54
-
55
- transform UML13::AssociationEnd, :to => EReference, :if => :isReference do
56
- otherEnd = association.connection.find{|ae| ae != @current_object}
57
- { :eType => trans(otherEnd.type),
58
- :name => otherEnd.name && otherEnd.name.strip,
59
- :eOpposite => trans(otherEnd),
60
- :lowerBound => (otherEnd.multiplicity && otherEnd.multiplicity.range.first.lower &&
83
+ end
84
+
85
+ transform UML13::Operation, :to => EOperation do
86
+ { :name => name && name.strip }
87
+ end
88
+
89
+ transform UML13::AssociationEnd, :to => EReference, :if => :isReference do
90
+ otherEnd = association.connection.find{|ae| ae != @current_object}
91
+ { :eType => trans(otherEnd.type),
92
+ :name => otherEnd.name && otherEnd.name.strip,
93
+ :eOpposite => trans(otherEnd),
94
+ :lowerBound => (otherEnd.multiplicity && otherEnd.multiplicity.range.first.lower &&
61
95
  otherEnd.multiplicity.range.first.lower.to_i) || 0,
62
- :upperBound => (otherEnd.multiplicity && otherEnd.multiplicity.range.first.upper &&
96
+ :upperBound => (otherEnd.multiplicity && otherEnd.multiplicity.range.first.upper &&
63
97
  otherEnd.multiplicity.range.first.upper.gsub('*','-1').to_i) || 1,
64
- :containment => (aggregation == :composite),
98
+ :containment => (aggregation == :composite),
65
99
  :eAnnotations => createAnnotations(association.taggedValue) }
66
- end
67
-
68
- method :isReference do
69
- otherEnd = association.connection.find{|ae| ae != @current_object}
70
- otherEnd.name && otherEnd.name.size > 0
71
- end
100
+ end
101
+
102
+ transform UML13::Dependency, :to => EReference, :if => :isReference do
103
+ { :eType => trans(supplier.first),
104
+ :name => name,
105
+ :lowerBound => 0,
106
+ :upperBound => 1,
107
+ :containment => false,
108
+ :eAnnotations => createAnnotations(taggedValue)
109
+ }
110
+ end
111
+
112
+ method :isReference do
113
+ @reference_filter.call(@current_object)
114
+ end
72
115
 
73
116
  def createAnnotations(taggedValues)
74
117
  if taggedValues.size > 0
@@ -78,7 +121,7 @@ class UML13ToECore < RGen::Transformer
78
121
  end
79
122
  end
80
123
 
81
- transform UML13::TaggedValue, :to => EStringToStringMapEntry do
82
- { :key => tag, :value => value}
83
- end
84
- end
124
+ transform UML13::TaggedValue, :to => EStringToStringMapEntry do
125
+ { :key => tag, :value => value}
126
+ end
127
+ end
@@ -5,49 +5,50 @@ require 'rgen/ecore/ecore'
5
5
  require 'rgen/array_extensions'
6
6
 
7
7
  class ECoreSelfTest < Test::Unit::TestCase
8
- include RGen::ECore
9
-
10
- def test_simple
11
- assert_equal \
12
- %w(lowerBound ordered unique upperBound many required eType).sort,
13
- ETypedElement.ecore.eStructuralFeatures.name.sort
14
-
15
- assert_equal \
16
- EClassifier.ecore,
17
- ETypedElement.ecore.eStructuralFeatures.find{|f| f.name=="eType"}.eType
18
- assert_equal %w(ENamedElement), ETypedElement.ecore.eSuperTypes.name
8
+ include RGen::ECore
9
+
10
+ def test_simple
11
+ assert_equal \
12
+ %w(lowerBound ordered unique upperBound many required eType).sort,
13
+ ETypedElement.ecore.eStructuralFeatures.name.sort
14
+
15
+ assert_equal \
16
+ EClassifier.ecore,
17
+ ETypedElement.ecore.eStructuralFeatures.find{|f| f.name=="eType"}.eType
18
+ assert_equal %w(ENamedElement), ETypedElement.ecore.eSuperTypes.name
19
19
 
20
- assert_equal \
21
- EModelElement.ecore,
22
- EModelElement.ecore.eStructuralFeatures.find{|f| f.name=="eAnnotations"}.eOpposite.eType
20
+ assert_equal \
21
+ EModelElement.ecore,
22
+ EModelElement.ecore.eStructuralFeatures.find{|f| f.name=="eAnnotations"}.eOpposite.eType
23
23
 
24
- assert_equal \
25
- %w(eType),
26
- ETypedElement.ecore.eReferences.name
27
-
28
- assert_equal \
29
- %w(lowerBound ordered unique upperBound many required).sort,
30
- ETypedElement.ecore.eAttributes.name.sort
31
-
32
- assert RGen::ECore.ecore.is_a?(EPackage)
33
- assert_equal "ECore", RGen::ECore.ecore.name
34
- assert_equal "RGen", RGen::ECore.ecore.eSuperPackage.name
35
- assert_equal %w(ECore), RGen.ecore.eSubpackages.name
36
- assert_equal\
37
- %w(EObject EModelElement EAnnotation ENamedElement ETypedElement
38
- EStructuralFeature EAttribute EClassifier EDataType EEnum EEnumLiteral EFactory
39
- EOperation EPackage EParameter EReference EStringToStringMapEntry EClass).sort,
40
- RGen::ECore.ecore.eClassifiers.name.sort
41
-
42
- assert_equal "false", EAttribute.ecore.eAllAttributes.
43
- find{|a|a.name == "derived"}.defaultValueLiteral
44
- assert_equal false, EAttribute.ecore.eAllAttributes.
45
- find{|a|a.name == "derived"}.defaultValue
24
+ assert_equal \
25
+ %w(eType),
26
+ ETypedElement.ecore.eReferences.name
27
+
28
+ assert_equal \
29
+ %w(lowerBound ordered unique upperBound many required).sort,
30
+ ETypedElement.ecore.eAttributes.name.sort
31
+
32
+ assert RGen::ECore.ecore.is_a?(EPackage)
33
+ assert_equal "ECore", RGen::ECore.ecore.name
34
+ assert_equal "RGen", RGen::ECore.ecore.eSuperPackage.name
35
+ assert_equal %w(ECore), RGen.ecore.eSubpackages.name
36
+ assert_equal\
37
+ %w(EObject EModelElement EAnnotation ENamedElement ETypedElement
38
+ EStructuralFeature EAttribute EClassifier EDataType EEnum EEnumLiteral EFactory
39
+ EOperation EPackage EParameter EReference EStringToStringMapEntry EClass
40
+ ETypeArgument EGenericType).sort,
41
+ RGen::ECore.ecore.eClassifiers.name.sort
42
+
43
+ assert_equal "false", EAttribute.ecore.eAllAttributes.
44
+ find{|a|a.name == "derived"}.defaultValueLiteral
45
+ assert_equal false, EAttribute.ecore.eAllAttributes.
46
+ find{|a|a.name == "derived"}.defaultValue
46
47
 
47
- assert_nil EAttribute.ecore.eAllAttributes.
48
- find{|a|a.name == "defaultValueLiteral"}.defaultValueLiteral
49
- assert_nil EAttribute.ecore.eAllAttributes.
50
- find{|a|a.name == "defaultValueLiteral"}.defaultValue
48
+ assert_nil EAttribute.ecore.eAllAttributes.
49
+ find{|a|a.name == "defaultValueLiteral"}.defaultValueLiteral
50
+ assert_nil EAttribute.ecore.eAllAttributes.
51
+ find{|a|a.name == "defaultValueLiteral"}.defaultValue
51
52
 
52
- end
53
- end
53
+ end
54
+ end
@@ -14,6 +14,7 @@ class JsonTest < Test::Unit::TestCase
14
14
  has_attr 'text', String
15
15
  has_attr 'integer', Integer
16
16
  has_attr 'float', Float
17
+ has_one 'other', TestNode
17
18
  contains_many 'childs', TestNode, 'parent'
18
19
  end
19
20
  end
@@ -152,5 +153,19 @@ class JsonTest < Test::Unit::TestCase
152
153
  inst.instantiate(%q({ "_class": "Data2", "data2": "something" }))
153
154
  end
154
155
  end
156
+
157
+ def test_json_instantiator_references
158
+ env = RGen::Environment.new
159
+ inst = RGen::Instantiator::JsonInstantiator.new(env, TestMM, :nameAttribute => "text")
160
+ inst.instantiate(%q([
161
+ { "_class": "TestNode", "text": "A", "childs": [
162
+ { "_class": "TestNode", "text": "B" } ]},
163
+ { "_class": "TestNode", "text": "C", "other": "/A/B"}]
164
+ ))
165
+ nodeA = env.find(:class => TestMM::TestNode, :text => "A").first
166
+ nodeC = env.find(:class => TestMM::TestNode, :text => "C").first
167
+ assert_equal 1, nodeA.childs.size
168
+ assert_equal nodeA.childs[0], nodeC.other
169
+ end
155
170
  end
156
171
 
@@ -6,18 +6,150 @@ require 'rgen/array_extensions'
6
6
 
7
7
  class MetamodelBuilderTest < Test::Unit::TestCase
8
8
 
9
- class SimpleClass < RGen::MetamodelBuilder::MMBase
10
- KindType = RGen::MetamodelBuilder::DataTypes::Enum.new([:simple, :extended])
11
- has_attr 'name' # default is String
12
- has_attr 'stringWithDefault', String, :defaultValueLiteral => "xtest"
13
- has_attr 'anything', Object
14
- has_attr 'allowed', RGen::MetamodelBuilder::DataTypes::Boolean
15
- has_attr 'kind', KindType
16
- has_attr 'kindWithDefault', KindType, :defaultValueLiteral => "extended"
9
+ module TestMetamodel
10
+ extend RGen::MetamodelBuilder::ModuleExtension
11
+
12
+ class SimpleClass < RGen::MetamodelBuilder::MMBase
13
+ KindType = RGen::MetamodelBuilder::DataTypes::Enum.new([:simple, :extended])
14
+ has_attr 'name' # default is String
15
+ has_attr 'stringWithDefault', String, :defaultValueLiteral => "xtest"
16
+ has_attr 'integerWithDefault', Integer, :defaultValueLiteral => "123"
17
+ has_attr 'floatWithDefault', Float, :defaultValueLiteral => "0.123"
18
+ has_attr 'boolWithDefault', Boolean, :defaultValueLiteral => "true"
19
+ has_attr 'anything', Object
20
+ has_attr 'allowed', RGen::MetamodelBuilder::DataTypes::Boolean
21
+ has_attr 'kind', KindType
22
+ has_attr 'kindWithDefault', KindType, :defaultValueLiteral => "extended"
23
+ end
24
+
25
+ class ManyAttrClass < RGen::MetamodelBuilder::MMBase
26
+ has_many_attr 'literals', String
27
+ has_many_attr 'bools', Boolean
28
+ has_many_attr 'integers', Integer
29
+ has_many_attr 'enums', RGen::MetamodelBuilder::DataTypes::Enum.new([:a, :b, :c])
30
+ has_many_attr 'limitTest', Integer, :upperBound => 2
31
+ end
32
+
33
+ class ClassA < RGen::MetamodelBuilder::MMBase
34
+ # metamodel accessors must work independent of the ==() method
35
+ module ClassModule
36
+ def ==(o)
37
+ o.is_a?(ClassA)
38
+ end
39
+ end
40
+ end
41
+
42
+ class ClassB < RGen::MetamodelBuilder::MMBase
43
+ end
44
+
45
+ class ClassC < RGen::MetamodelBuilder::MMBase
46
+ end
47
+
48
+ class HasOneTestClass < RGen::MetamodelBuilder::MMBase
49
+ has_one 'classA', ClassA
50
+ has_one 'classB', ClassB
51
+ end
52
+
53
+ class HasManyTestClass < RGen::MetamodelBuilder::MMBase
54
+ has_many 'classA', ClassA
55
+ end
56
+
57
+ class OneClass < RGen::MetamodelBuilder::MMBase
58
+ end
59
+ class ManyClass < RGen::MetamodelBuilder::MMBase
60
+ end
61
+ OneClass.one_to_many 'manyClasses', ManyClass, 'oneClass', :upperBound => 5
62
+
63
+ class AClassMM < RGen::MetamodelBuilder::MMBase
64
+ end
65
+ class BClassMM < RGen::MetamodelBuilder::MMBase
66
+ end
67
+ AClassMM.many_to_many 'bClasses', BClassMM, 'aClasses'
68
+
69
+ module SomePackage
70
+ extend RGen::MetamodelBuilder::ModuleExtension
71
+
72
+ class ClassA < RGen::MetamodelBuilder::MMBase
73
+ end
74
+
75
+ module SubPackage
76
+ extend RGen::MetamodelBuilder::ModuleExtension
77
+
78
+ class ClassB < RGen::MetamodelBuilder::MMBase
79
+ end
80
+ end
81
+ end
82
+
83
+ class OneClass2 < RGen::MetamodelBuilder::MMBase
84
+ end
85
+ class ManyClass2 < RGen::MetamodelBuilder::MMBase
86
+ end
87
+ ManyClass2.many_to_one 'oneClass', OneClass2, 'manyClasses'
88
+
89
+ class AClassOO < RGen::MetamodelBuilder::MMBase
90
+ end
91
+ class BClassOO < RGen::MetamodelBuilder::MMBase
92
+ end
93
+ AClassOO.one_to_one 'bClass', BClassOO, 'aClass'
94
+
95
+ class SomeSuperClass < RGen::MetamodelBuilder::MMBase
96
+ has_attr "name"
97
+ has_many "classAs", ClassA
98
+ end
99
+
100
+ class SomeSubClass < SomeSuperClass
101
+ has_attr "subname"
102
+ has_many "classBs", ClassB
103
+ end
104
+
105
+ class OtherSubClass < SomeSuperClass
106
+ has_attr "othersubname"
107
+ has_many "classCs", ClassC
108
+ end
109
+
110
+ class SubSubClass < RGen::MetamodelBuilder::MMMultiple(SomeSubClass, OtherSubClass)
111
+ has_attr "subsubname"
112
+ end
113
+
114
+ module AnnotatedModule
115
+ extend RGen::MetamodelBuilder::ModuleExtension
116
+
117
+ annotation "moduletag" => "modulevalue"
118
+
119
+ class AnnotatedClass < RGen::MetamodelBuilder::MMBase
120
+ annotation "sometag" => "somevalue", "othertag" => "othervalue"
121
+ annotation :source => "rgen/test", :details => {"thirdtag" => "thirdvalue"}
122
+
123
+ has_attr "boolAttr", Boolean do
124
+ annotation "attrtag" => "attrval"
125
+ annotation :source => "rgen/test2", :details => {"attrtag2" => "attrvalue2", "attrtag3" => "attrvalue3"}
126
+ end
127
+
128
+ has_many "others", AnnotatedClass do
129
+ annotation "reftag" => "refval"
130
+ annotation :source => "rgen/test3", :details => {"reftag2" => "refvalue2", "reftag3" => "refvalue3"}
131
+ end
132
+
133
+ many_to_many "m2m", AnnotatedClass, "m2mback" do
134
+ annotation "m2mtag" => "m2mval"
135
+ opposite_annotation "opposite_m2mtag" => "opposite_m2mval"
136
+ end
137
+ end
138
+
139
+ end
140
+
141
+ class AbstractClass < RGen::MetamodelBuilder::MMBase
142
+ abstract
143
+ end
144
+
17
145
  end
18
-
146
+
147
+ def mm
148
+ TestMetamodel
149
+ end
150
+
19
151
  def test_has_attr
20
- sc = SimpleClass.new
152
+ sc = mm::SimpleClass.new
21
153
 
22
154
  assert_respond_to sc, :name
23
155
  assert_respond_to sc, :name=
@@ -28,10 +160,13 @@ class MetamodelBuilderTest < Test::Unit::TestCase
28
160
  assert_raise StandardError do
29
161
  sc.name = 5
30
162
  end
31
- assert_equal "EString", SimpleClass.ecore.eAttributes.find{|a| a.name=="name"}.eType.name
163
+ assert_equal "EString", mm::SimpleClass.ecore.eAttributes.find{|a| a.name=="name"}.eType.name
32
164
 
33
165
  assert_equal "xtest", sc.stringWithDefault
34
166
  assert_equal :extended, sc.kindWithDefault
167
+ assert_equal 123, sc.integerWithDefault
168
+ assert_equal 0.123, sc.floatWithDefault
169
+ assert_equal true, sc.boolWithDefault
35
170
 
36
171
  sc.anything = :asymbol
37
172
  assert_equal :asymbol, sc.anything
@@ -52,7 +187,7 @@ class MetamodelBuilderTest < Test::Unit::TestCase
52
187
  assert_raise StandardError do
53
188
  sc.allowed = "a string"
54
189
  end
55
- assert_equal "EBoolean", SimpleClass.ecore.eAttributes.find{|a| a.name=="allowed"}.eType.name
190
+ assert_equal "EBoolean", mm::SimpleClass.ecore.eAttributes.find{|a| a.name=="allowed"}.eType.name
56
191
 
57
192
  assert_respond_to sc, :kind
58
193
  assert_respond_to sc, :kind=
@@ -69,20 +204,12 @@ class MetamodelBuilderTest < Test::Unit::TestCase
69
204
  sc.kind = "a string"
70
205
  end
71
206
 
72
- enum = SimpleClass.ecore.eAttributes.find{|a| a.name=="kind"}.eType
207
+ enum = mm::SimpleClass.ecore.eAttributes.find{|a| a.name=="kind"}.eType
73
208
  assert_equal ["extended", "simple"], enum.eLiterals.name.sort
74
209
  end
75
210
 
76
- class ManyAttrClass < RGen::MetamodelBuilder::MMBase
77
- has_many_attr 'literals', String
78
- has_many_attr 'bools', Boolean
79
- has_many_attr 'integers', Integer
80
- has_many_attr 'enums', RGen::MetamodelBuilder::DataTypes::Enum.new([:a, :b, :c])
81
- has_many_attr 'limitTest', Integer, :upperBound => 2
82
- end
83
-
84
211
  def test_many_attr
85
- o = ManyAttrClass.new
212
+ o = mm::ManyAttrClass.new
86
213
 
87
214
  assert_respond_to o, :literals
88
215
  assert_respond_to o, :addLiterals
@@ -102,13 +229,13 @@ class MetamodelBuilderTest < Test::Unit::TestCase
102
229
  assert_equal ["a", "b", "b"], o.literals
103
230
  # but the same string object "a" can only occur once
104
231
  o.addLiterals(o.literals.first)
105
- assert_equal ["a", "b", "b"], o.literals
232
+ assert_equal ["a", "b", "b", "a"], o.literals
106
233
  # removing works by object identity, so providing a new string won't delete an existing one
107
234
  o.removeLiterals("a")
108
- assert_equal ["a", "b", "b"], o.literals
235
+ assert_equal ["a", "b", "b", "a"], o.literals
109
236
  theA = o.literals.first
110
237
  o.removeLiterals(theA)
111
- assert_equal ["b", "b"], o.literals
238
+ assert_equal ["b", "b", "a"], o.literals
112
239
  # removing something which is not present has no effect
113
240
  o.removeLiterals(theA)
114
241
  assert_equal ["b", "b"], o.literals
@@ -120,54 +247,42 @@ class MetamodelBuilderTest < Test::Unit::TestCase
120
247
  # setting multiple elements at a time
121
248
  o.literals = ["a", "b", "c"]
122
249
  assert_equal ["a", "b", "c"], o.literals
123
- # can only take arrays
250
+ # can only take enumerables
124
251
  assert_raise(StandardError) do
125
- o.literals = "a"
252
+ o.literals = 1
126
253
  end
127
254
 
128
255
  o.bools = [true, false, true, false]
129
- assert_equal [true, false], o.bools
256
+ assert_equal [true, false, true, false], o.bools
130
257
 
131
258
  o.integers = [1, 2, 2, 3, 3]
132
- assert_equal [1, 2, 3], o.integers
259
+ assert_equal [1, 2, 2, 3, 3], o.integers
133
260
 
134
261
  o.enums = [:a, :a, :b, :c, :c]
135
- assert_equal [:a, :b, :c], o.enums
262
+ assert_equal [:a, :a, :b, :c, :c], o.enums
136
263
 
137
- lit = ManyAttrClass.ecore.eAttributes.find{|a| a.name == "literals"}
264
+ lit = mm::ManyAttrClass.ecore.eAttributes.find{|a| a.name == "literals"}
138
265
  assert lit.is_a?(RGen::ECore::EAttribute)
139
266
  assert lit.many
140
267
 
141
- lim = ManyAttrClass.ecore.eAttributes.find{|a| a.name == "limitTest"}
268
+ lim = mm::ManyAttrClass.ecore.eAttributes.find{|a| a.name == "limitTest"}
142
269
  assert lit.many
143
270
  assert_equal 2, lim.upperBound
144
271
  end
145
272
 
146
- class ClassA < RGen::MetamodelBuilder::MMBase
147
- # metamodel accessors must work independent of the ==() method
148
- module ClassModule
149
- def ==(o)
150
- o.is_a?(ClassA)
151
- end
152
- end
153
- end
154
-
155
- class ClassB < RGen::MetamodelBuilder::MMBase
156
- end
157
-
158
- class ClassC < RGen::MetamodelBuilder::MMBase
159
- end
160
-
161
- class HasOneTestClass < RGen::MetamodelBuilder::MMBase
162
- has_one 'classA', ClassA
163
- has_one 'classB', ClassB
273
+ def test_many_attr_insert
274
+ o = mm::ManyAttrClass.new
275
+ o.addLiterals("a")
276
+ o.addLiterals("b", 0)
277
+ o.addLiterals("c", 1)
278
+ assert_equal ["b", "c", "a"], o.literals
164
279
  end
165
-
280
+
166
281
  def test_has_one
167
- sc = HasOneTestClass.new
282
+ sc = mm::HasOneTestClass.new
168
283
  assert_respond_to sc, :classA
169
284
  assert_respond_to sc, :classA=
170
- ca = ClassA.new
285
+ ca = mm::ClassA.new
171
286
  sc.classA = ca
172
287
  assert_equal ca, sc.classA
173
288
  sc.classA = nil
@@ -175,7 +290,7 @@ class MetamodelBuilderTest < Test::Unit::TestCase
175
290
 
176
291
  assert_respond_to sc, :classB
177
292
  assert_respond_to sc, :classB=
178
- cb = ClassB.new
293
+ cb = mm::ClassB.new
179
294
  sc.classB = cb
180
295
  assert_equal cb, sc.classB
181
296
 
@@ -183,22 +298,18 @@ class MetamodelBuilderTest < Test::Unit::TestCase
183
298
  sc.classB = ca
184
299
  end
185
300
 
186
- assert_equal [], ClassA.ecore.eReferences
187
- assert_equal [], ClassB.ecore.eReferences
188
- assert_equal ["classA", "classB"].sort, HasOneTestClass.ecore.eReferences.name.sort
189
- assert_equal [], HasOneTestClass.ecore.eReferences.select { |a| a.many == true }
190
- assert_equal [], HasOneTestClass.ecore.eAttributes
191
- end
192
-
193
- class HasManyTestClass < RGen::MetamodelBuilder::MMBase
194
- has_many 'classA', ClassA
301
+ assert_equal [], mm::ClassA.ecore.eReferences
302
+ assert_equal [], mm::ClassB.ecore.eReferences
303
+ assert_equal ["classA", "classB"].sort, mm::HasOneTestClass.ecore.eReferences.name.sort
304
+ assert_equal [], mm::HasOneTestClass.ecore.eReferences.select { |a| a.many == true }
305
+ assert_equal [], mm::HasOneTestClass.ecore.eAttributes
195
306
  end
196
307
 
197
308
  def test_has_many
198
- o = HasManyTestClass.new
199
- ca1 = ClassA.new
200
- ca2 = ClassA.new
201
- ca3 = ClassA.new
309
+ o = mm::HasManyTestClass.new
310
+ ca1 = mm::ClassA.new
311
+ ca2 = mm::ClassA.new
312
+ ca3 = mm::ClassA.new
202
313
  o.addClassA(ca1)
203
314
  o.addClassA(ca2)
204
315
  assert_equal [ca1, ca2], o.classA
@@ -210,24 +321,33 @@ class MetamodelBuilderTest < Test::Unit::TestCase
210
321
  o.removeClassA(ca2)
211
322
  assert_equal [ca1], o.classA
212
323
  assert_raise StandardError do
213
- o.addClassA(ClassB.new)
324
+ o.addClassA(mm::ClassB.new)
214
325
  end
215
- assert_equal [], HasManyTestClass.ecore.eReferences.select{|r| r.many == false}
216
- assert_equal ["classA"], HasManyTestClass.ecore.eReferences.select{|r| r.many == true}.name
326
+ assert_equal [], mm::HasManyTestClass.ecore.eReferences.select{|r| r.many == false}
327
+ assert_equal ["classA"], mm::HasManyTestClass.ecore.eReferences.select{|r| r.many == true}.name
217
328
  end
218
-
219
- class OneClass < RGen::MetamodelBuilder::MMBase
220
- end
221
- class ManyClass < RGen::MetamodelBuilder::MMBase
329
+
330
+ def test_has_many_insert
331
+ o = mm::HasManyTestClass.new
332
+ ca1 = mm::ClassA.new
333
+ ca2 = mm::ClassA.new
334
+ ca3 = mm::ClassA.new
335
+ ca4 = mm::ClassA.new
336
+ ca5 = mm::ClassA.new
337
+ o.addClassA(ca1)
338
+ o.addClassA(ca2)
339
+ o.addClassA(ca3,0)
340
+ o.addClassA(ca4,1)
341
+ o.addGeneric("classA",ca5,2)
342
+ assert_equal [ca3, ca4, ca5, ca1, ca2], o.classA
222
343
  end
223
- OneClass.one_to_many 'manyClasses', ManyClass, 'oneClass', :upperBound => 5
224
344
 
225
345
  def test_one_to_many
226
- oc = OneClass.new
346
+ oc = mm::OneClass.new
227
347
  assert_respond_to oc, :manyClasses
228
348
  assert oc.manyClasses.empty?
229
349
 
230
- mc = ManyClass.new
350
+ mc = mm::ManyClass.new
231
351
  assert_respond_to mc, :oneClass
232
352
  assert_respond_to mc, :oneClass=
233
353
  assert_nil mc.oneClass
@@ -252,17 +372,17 @@ class MetamodelBuilderTest < Test::Unit::TestCase
252
372
  assert !oc.manyClasses.include?(mc)
253
373
  assert_equal nil, mc.oneClass
254
374
 
255
- assert_equal [], OneClass.ecore.eReferences.select{|r| r.many == false}
256
- assert_equal ["manyClasses"], OneClass.ecore.eReferences.select{|r| r.many == true}.name
257
- assert_equal 5, OneClass.ecore.eReferences.find{|r| r.many == true}.upperBound
258
- assert_equal ["oneClass"], ManyClass.ecore.eReferences.select{|r| r.many == false}.name
259
- assert_equal [], ManyClass.ecore.eReferences.select{|r| r.many == true}
375
+ assert_equal [], mm::OneClass.ecore.eReferences.select{|r| r.many == false}
376
+ assert_equal ["manyClasses"], mm::OneClass.ecore.eReferences.select{|r| r.many == true}.name
377
+ assert_equal 5, mm::OneClass.ecore.eReferences.find{|r| r.many == true}.upperBound
378
+ assert_equal ["oneClass"], mm::ManyClass.ecore.eReferences.select{|r| r.many == false}.name
379
+ assert_equal [], mm::ManyClass.ecore.eReferences.select{|r| r.many == true}
260
380
  end
261
381
 
262
382
  def test_one_to_many_replace1
263
- oc1 = OneClass.new
264
- oc2 = OneClass.new
265
- mc = ManyClass.new
383
+ oc1 = mm::OneClass.new
384
+ oc2 = mm::OneClass.new
385
+ mc = mm::ManyClass.new
266
386
 
267
387
  oc1.manyClasses = [mc]
268
388
  assert_equal [mc], oc1.manyClasses
@@ -276,9 +396,9 @@ class MetamodelBuilderTest < Test::Unit::TestCase
276
396
  end
277
397
 
278
398
  def test_one_to_many_replace2
279
- oc = OneClass.new
280
- mc1 = ManyClass.new
281
- mc2 = ManyClass.new
399
+ oc = mm::OneClass.new
400
+ mc1 = mm::ManyClass.new
401
+ mc2 = mm::ManyClass.new
282
402
 
283
403
  mc1.oneClass = oc
284
404
  assert_equal [mc1], oc.manyClasses
@@ -291,18 +411,24 @@ class MetamodelBuilderTest < Test::Unit::TestCase
291
411
  assert_equal oc, mc2.oneClass
292
412
  end
293
413
 
294
- class OneClass2 < RGen::MetamodelBuilder::MMBase
295
- end
296
- class ManyClass2 < RGen::MetamodelBuilder::MMBase
414
+ def test_one_to_many_insert
415
+ oc = mm::OneClass.new
416
+ mc1 = mm::ManyClass.new
417
+ mc2 = mm::ManyClass.new
418
+
419
+ oc.addManyClasses(mc1, 0)
420
+ oc.addManyClasses(mc2, 0)
421
+ assert_equal [mc2, mc1], oc.manyClasses
422
+ assert_equal oc, mc1.oneClass
423
+ assert_equal oc, mc2.oneClass
297
424
  end
298
- ManyClass2.many_to_one 'oneClass', OneClass2, 'manyClasses'
299
-
425
+
300
426
  def test_one_to_many2
301
- oc = OneClass2.new
427
+ oc = mm::OneClass2.new
302
428
  assert_respond_to oc, :manyClasses
303
429
  assert oc.manyClasses.empty?
304
430
 
305
- mc = ManyClass2.new
431
+ mc = mm::ManyClass2.new
306
432
  assert_respond_to mc, :oneClass
307
433
  assert_respond_to mc, :oneClass=
308
434
  assert_nil mc.oneClass
@@ -327,25 +453,19 @@ class MetamodelBuilderTest < Test::Unit::TestCase
327
453
  assert !oc.manyClasses.include?(mc)
328
454
  assert_equal nil, mc.oneClass
329
455
 
330
- assert_equal [], OneClass2.ecore.eReferences.select{|r| r.many == false}
331
- assert_equal ["manyClasses"], OneClass2.ecore.eReferences.select{|r| r.many == true}.name
332
- assert_equal ["oneClass"], ManyClass2.ecore.eReferences.select{|r| r.many == false}.name
333
- assert_equal [], ManyClass2.ecore.eReferences.select{|r| r.many == true}
334
- end
335
-
336
- class AClassOO < RGen::MetamodelBuilder::MMBase
337
- end
338
- class BClassOO < RGen::MetamodelBuilder::MMBase
456
+ assert_equal [], mm::OneClass2.ecore.eReferences.select{|r| r.many == false}
457
+ assert_equal ["manyClasses"], mm::OneClass2.ecore.eReferences.select{|r| r.many == true}.name
458
+ assert_equal ["oneClass"], mm::ManyClass2.ecore.eReferences.select{|r| r.many == false}.name
459
+ assert_equal [], mm::ManyClass2.ecore.eReferences.select{|r| r.many == true}
339
460
  end
340
- AClassOO.one_to_one 'bClass', BClassOO, 'aClass'
341
461
 
342
462
  def test_one_to_one
343
- ac = AClassOO.new
463
+ ac = mm::AClassOO.new
344
464
  assert_respond_to ac, :bClass
345
465
  assert_respond_to ac, :bClass=
346
466
  assert_nil ac.bClass
347
467
 
348
- bc = BClassOO.new
468
+ bc = mm::BClassOO.new
349
469
  assert_respond_to bc, :aClass
350
470
  assert_respond_to bc, :aClass=
351
471
  assert_nil bc.aClass
@@ -370,16 +490,16 @@ class MetamodelBuilderTest < Test::Unit::TestCase
370
490
  assert_equal nil, ac.bClass
371
491
  assert_equal nil, bc.aClass
372
492
 
373
- assert_equal ["bClass"], AClassOO.ecore.eReferences.select{|r| r.many == false}.name
374
- assert_equal [], AClassOO.ecore.eReferences.select{|r| r.many == true}
375
- assert_equal ["aClass"], BClassOO.ecore.eReferences.select{|r| r.many == false}.name
376
- assert_equal [], BClassOO.ecore.eReferences.select{|r| r.many == true}
493
+ assert_equal ["bClass"], mm::AClassOO.ecore.eReferences.select{|r| r.many == false}.name
494
+ assert_equal [], mm::AClassOO.ecore.eReferences.select{|r| r.many == true}
495
+ assert_equal ["aClass"], mm::BClassOO.ecore.eReferences.select{|r| r.many == false}.name
496
+ assert_equal [], mm::BClassOO.ecore.eReferences.select{|r| r.many == true}
377
497
  end
378
498
 
379
499
  def test_one_to_one_replace
380
- a = AClassOO.new
381
- b1 = BClassOO.new
382
- b2 = BClassOO.new
500
+ a = mm::AClassOO.new
501
+ b1 = mm::BClassOO.new
502
+ b2 = mm::BClassOO.new
383
503
 
384
504
  a.bClass = b1
385
505
  assert_equal b1, a.bClass
@@ -392,19 +512,13 @@ class MetamodelBuilderTest < Test::Unit::TestCase
392
512
  assert_equal a, b2.aClass
393
513
  end
394
514
 
395
- class AClassMM < RGen::MetamodelBuilder::MMBase
396
- end
397
- class BClassMM < RGen::MetamodelBuilder::MMBase
398
- end
399
- AClassMM.many_to_many 'bClasses', BClassMM, 'aClasses'
400
-
401
515
  def test_many_to_many
402
516
 
403
- ac = AClassMM.new
517
+ ac = mm::AClassMM.new
404
518
  assert_respond_to ac, :bClasses
405
519
  assert ac.bClasses.empty?
406
520
 
407
- bc = BClassMM.new
521
+ bc = mm::BClassMM.new
408
522
  assert_respond_to bc, :aClasses
409
523
  assert bc.aClasses.empty?
410
524
 
@@ -438,69 +552,50 @@ class MetamodelBuilderTest < Test::Unit::TestCase
438
552
  assert !ac.bClasses.include?(bc)
439
553
  assert !bc.aClasses.include?(ac)
440
554
 
441
- assert_equal [], AClassMM.ecore.eReferences.select{|r| r.many == false}
442
- assert_equal ["bClasses"], AClassMM.ecore.eReferences.select{|r| r.many == true}.name
443
- assert_equal [], BClassMM.ecore.eReferences.select{|r| r.many == false}
444
- assert_equal ["aClasses"], BClassMM.ecore.eReferences.select{|r| r.many == true}.name
445
- end
446
-
447
- class SomeSuperClass < RGen::MetamodelBuilder::MMBase
448
- has_attr "name"
449
- has_many "classAs", ClassA
450
- end
451
-
452
- class SomeSubClass < SomeSuperClass
453
- has_attr "subname"
454
- has_many "classBs", ClassB
455
- end
456
-
457
- class OtherSubClass < SomeSuperClass
458
- has_attr "othersubname"
459
- has_many "classCs", ClassC
555
+ assert_equal [], mm::AClassMM.ecore.eReferences.select{|r| r.many == false}
556
+ assert_equal ["bClasses"], mm::AClassMM.ecore.eReferences.select{|r| r.many == true}.name
557
+ assert_equal [], mm::BClassMM.ecore.eReferences.select{|r| r.many == false}
558
+ assert_equal ["aClasses"], mm::BClassMM.ecore.eReferences.select{|r| r.many == true}.name
460
559
  end
461
560
 
462
- def test_inheritance
463
- assert_equal ["name"], SomeSuperClass.ecore.eAllAttributes.name
464
- assert_equal ["classAs"], SomeSuperClass.ecore.eAllReferences.name
465
- assert_equal ["name", "subname"], SomeSubClass.ecore.eAllAttributes.name.sort
466
- assert_equal ["classAs", "classBs"], SomeSubClass.ecore.eAllReferences.name.sort
467
- assert_equal ["name", "othersubname"], OtherSubClass.ecore.eAllAttributes.name.sort
468
- assert_equal ["classAs", "classCs"], OtherSubClass.ecore.eAllReferences.name.sort
469
- end
470
-
471
- module AnnotatedModule
472
- extend RGen::MetamodelBuilder::ModuleExtension
561
+ def test_many_to_many_insert
562
+ ac1 = mm::AClassMM.new
563
+ ac2 = mm::AClassMM.new
564
+ bc1= mm::BClassMM.new
565
+ bc2= mm::BClassMM.new
473
566
 
474
- annotation "moduletag" => "modulevalue"
475
-
476
- class AnnotatedClass < RGen::MetamodelBuilder::MMBase
477
- annotation "sometag" => "somevalue", "othertag" => "othervalue"
478
- annotation :source => "rgen/test", :details => {"thirdtag" => "thirdvalue"}
479
-
480
- has_attr "boolAttr", Boolean do
481
- annotation "attrtag" => "attrval"
482
- annotation :source => "rgen/test2", :details => {"attrtag2" => "attrvalue2", "attrtag3" => "attrvalue3"}
483
- end
484
-
485
- has_many "others", AnnotatedClass do
486
- annotation "reftag" => "refval"
487
- annotation :source => "rgen/test3", :details => {"reftag2" => "refvalue2", "reftag3" => "refvalue3"}
488
- end
567
+ ac1.addBClasses(bc1)
568
+ ac1.addBClasses(bc2, 0)
569
+ ac2.addBClasses(bc1)
570
+ ac2.addBClasses(bc2, 0)
489
571
 
490
- many_to_many "m2m", AnnotatedClass, "m2mback" do
491
- annotation "m2mtag" => "m2mval"
492
- opposite_annotation "opposite_m2mtag" => "opposite_m2mval"
493
- end
494
- end
495
-
572
+ assert_equal [bc2, bc1], ac1.bClasses
573
+ assert_equal [bc2, bc1], ac2.bClasses
574
+ assert_equal [ac1, ac2], bc1.aClasses
575
+ assert_equal [ac1, ac2], bc2.aClasses
576
+ end
577
+
578
+ def test_inheritance
579
+ assert_equal ["name"], mm::SomeSuperClass.ecore.eAllAttributes.name
580
+ assert_equal ["classAs"], mm::SomeSuperClass.ecore.eAllReferences.name
581
+ assert_equal ["name", "subname"], mm::SomeSubClass.ecore.eAllAttributes.name.sort
582
+ assert_equal ["classAs", "classBs"], mm::SomeSubClass.ecore.eAllReferences.name.sort
583
+ assert_equal ["name", "othersubname"], mm::OtherSubClass.ecore.eAllAttributes.name.sort
584
+ assert_equal ["classAs", "classCs"], mm::OtherSubClass.ecore.eAllReferences.name.sort
585
+ assert mm::SomeSubClass.new.is_a?(mm::SomeSuperClass)
586
+ assert_equal ["name", "othersubname", "subname", "subsubname"], mm::SubSubClass.ecore.eAllAttributes.name.sort
587
+ assert_equal ["classAs", "classBs", "classCs"], mm::SubSubClass.ecore.eAllReferences.name.sort
588
+ assert mm::SubSubClass.new.is_a?(mm::SomeSuperClass)
589
+ assert mm::SubSubClass.new.is_a?(mm::SomeSubClass)
590
+ assert mm::SubSubClass.new.is_a?(mm::OtherSubClass)
496
591
  end
497
592
 
498
593
  def test_annotations
499
- assert_equal 1, AnnotatedModule.ecore.eAnnotations.size
500
- anno = AnnotatedModule.ecore.eAnnotations.first
594
+ assert_equal 1, mm::AnnotatedModule.ecore.eAnnotations.size
595
+ anno = mm::AnnotatedModule.ecore.eAnnotations.first
501
596
  checkAnnotation(anno, nil, {"moduletag" => "modulevalue"})
502
597
 
503
- eClass = AnnotatedModule::AnnotatedClass.ecore
598
+ eClass = mm::AnnotatedModule::AnnotatedClass.ecore
504
599
  assert_equal 2, eClass.eAnnotations.size
505
600
  anno = eClass.eAnnotations.find{|a| a.source == "rgen/test"}
506
601
  checkAnnotation(anno, "rgen/test", {"thirdtag" => "thirdvalue"})
@@ -542,25 +637,11 @@ class MetamodelBuilderTest < Test::Unit::TestCase
542
637
  end
543
638
  end
544
639
 
545
- module SomePackage
546
- extend RGen::MetamodelBuilder::ModuleExtension
547
-
548
- class ClassA < RGen::MetamodelBuilder::MMBase
549
- end
550
-
551
- module SubPackage
552
- extend RGen::MetamodelBuilder::ModuleExtension
553
-
554
- class ClassB < RGen::MetamodelBuilder::MMBase
555
- end
556
- end
557
- end
558
-
559
640
  def test_ecore_identity
560
- subPackage = SomePackage::SubPackage.ecore
561
- assert_equal subPackage.eClassifiers.first.object_id, SomePackage::SubPackage::ClassB.ecore.object_id
641
+ subPackage = mm::SomePackage::SubPackage.ecore
642
+ assert_equal subPackage.eClassifiers.first.object_id, mm::SomePackage::SubPackage::ClassB.ecore.object_id
562
643
 
563
- somePackage = SomePackage.ecore
644
+ somePackage = mm::SomePackage.ecore
564
645
  assert_equal somePackage.eSubpackages.first.object_id, subPackage.object_id
565
646
  end
566
647
 
@@ -569,14 +650,18 @@ class MetamodelBuilderTest < Test::Unit::TestCase
569
650
  assert_equal "test", p.targetIdentifier
570
651
  p.targetIdentifier = 123
571
652
  assert_equal 123, p.targetIdentifier
653
+ p.data = "additional info"
654
+ assert_equal "additional info", p.data
655
+ q = RGen::MetamodelBuilder::MMProxy.new("ident", "data")
656
+ assert_equal "data", q.data
572
657
  end
573
658
 
574
659
  def test_proxies_has_one
575
- e = HasOneTestClass.new
660
+ e = mm::HasOneTestClass.new
576
661
  proxy = RGen::MetamodelBuilder::MMProxy.new
577
662
  e.classA = proxy
578
663
  assert_equal proxy, e.classA
579
- a = ClassA.new
664
+ a = mm::ClassA.new
580
665
  # displace proxy
581
666
  e.classA = a
582
667
  assert_equal a, e.classA
@@ -586,7 +671,7 @@ class MetamodelBuilderTest < Test::Unit::TestCase
586
671
  end
587
672
 
588
673
  def test_proxies_has_many
589
- e = HasManyTestClass.new
674
+ e = mm::HasManyTestClass.new
590
675
  proxy = RGen::MetamodelBuilder::MMProxy.new
591
676
  e.addClassA(proxy)
592
677
  assert_equal [proxy], e.classA
@@ -606,8 +691,8 @@ class MetamodelBuilderTest < Test::Unit::TestCase
606
691
  end
607
692
 
608
693
  def test_proxies_one_to_one
609
- ea = AClassOO.new
610
- eb = BClassOO.new
694
+ ea = mm::AClassOO.new
695
+ eb = mm::BClassOO.new
611
696
  proxy1 = RGen::MetamodelBuilder::MMProxy.new
612
697
  proxy2 = RGen::MetamodelBuilder::MMProxy.new
613
698
  ea.bClass = proxy1
@@ -625,8 +710,8 @@ class MetamodelBuilderTest < Test::Unit::TestCase
625
710
  end
626
711
 
627
712
  def test_proxies_one_to_many
628
- eo = OneClass.new
629
- em = ManyClass.new
713
+ eo = mm::OneClass.new
714
+ em = mm::ManyClass.new
630
715
  proxy1 = RGen::MetamodelBuilder::MMProxy.new
631
716
  proxy2 = RGen::MetamodelBuilder::MMProxy.new
632
717
  eo.addManyClasses(proxy1)
@@ -652,8 +737,8 @@ class MetamodelBuilderTest < Test::Unit::TestCase
652
737
  end
653
738
 
654
739
  def test_proxies_many_to_many
655
- e1 = AClassMM.new
656
- e2 = BClassMM.new
740
+ e1 = mm::AClassMM.new
741
+ e2 = mm::BClassMM.new
657
742
  proxy1 = RGen::MetamodelBuilder::MMProxy.new
658
743
  proxy2 = RGen::MetamodelBuilder::MMProxy.new
659
744
  e1.addBClasses(proxy1)
@@ -670,10 +755,10 @@ class MetamodelBuilderTest < Test::Unit::TestCase
670
755
  end
671
756
 
672
757
  def test_genericAccess
673
- e1 = OneClass.new
674
- e2 = ManyClass.new
675
- e3 = OneClass.new
676
- e4 = ManyClass.new
758
+ e1 = mm::OneClass.new
759
+ e2 = mm::ManyClass.new
760
+ e3 = mm::OneClass.new
761
+ e4 = mm::ManyClass.new
677
762
  # use on "many" feature
678
763
  e1.setOrAddGeneric("manyClasses", e2)
679
764
  assert_equal [e2], e1.manyClasses
@@ -688,4 +773,74 @@ class MetamodelBuilderTest < Test::Unit::TestCase
688
773
  assert_equal [], e4.getGenericAsArray("oneClass")
689
774
  end
690
775
 
776
+ def test_abstract
777
+ assert_raise StandardError do
778
+ mm::AbstractClass.new
779
+ end
780
+ end
781
+
782
+ module BadDefaultValueLiteralContainer
783
+ Test1 = proc do
784
+ class BadClass < RGen::MetamodelBuilder::MMBase
785
+ has_attr 'integerWithDefault', Integer, :defaultValueLiteral => "1.1"
786
+ end
787
+ end
788
+ Test2 = proc do
789
+ class BadClass < RGen::MetamodelBuilder::MMBase
790
+ has_attr 'integerWithDefault', Integer, :defaultValueLiteral => "x"
791
+ end
792
+ end
793
+ Test3 = proc do
794
+ class BadClass < RGen::MetamodelBuilder::MMBase
795
+ has_attr 'boolWithDefault', Boolean, :defaultValueLiteral => "1"
796
+ end
797
+ end
798
+ Test4 = proc do
799
+ class BadClass < RGen::MetamodelBuilder::MMBase
800
+ has_attr 'floatWithDefault', Float, :defaultValueLiteral => "1"
801
+ end
802
+ end
803
+ Test5 = proc do
804
+ class BadClass < RGen::MetamodelBuilder::MMBase
805
+ has_attr 'floatWithDefault', Float, :defaultValueLiteral => "true"
806
+ end
807
+ end
808
+ Test6 = proc do
809
+ class BadClass < RGen::MetamodelBuilder::MMBase
810
+ kindType = RGen::MetamodelBuilder::DataTypes::Enum.new([:simple, :extended])
811
+ has_attr 'enumWithDefault', kindType, :defaultValueLiteral => "xxx"
812
+ end
813
+ end
814
+ Test7 = proc do
815
+ class BadClass < RGen::MetamodelBuilder::MMBase
816
+ kindType = RGen::MetamodelBuilder::DataTypes::Enum.new([:simple, :extended])
817
+ has_attr 'enumWithDefault', kindType, :defaultValueLiteral => "7"
818
+ end
819
+ end
820
+ end
821
+
822
+ def test_bad_default_value_literal
823
+ assert_raise StandardError do
824
+ BadDefaultValueLiteralContainer::Test1.call
825
+ end
826
+ assert_raise StandardError do
827
+ BadDefaultValueLiteralContainer::Test2.call
828
+ end
829
+ assert_raise StandardError do
830
+ BadDefaultValueLiteralContainer::Test3.call
831
+ end
832
+ assert_raise StandardError do
833
+ BadDefaultValueLiteralContainer::Test4.call
834
+ end
835
+ assert_raise StandardError do
836
+ BadDefaultValueLiteralContainer::Test5.call
837
+ end
838
+ assert_raise StandardError do
839
+ BadDefaultValueLiteralContainer::Test6.call
840
+ end
841
+ assert_raise StandardError do
842
+ BadDefaultValueLiteralContainer::Test7.call
843
+ end
844
+ end
845
+
691
846
  end