rgen 0.4.6 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +95 -83
- data/Rakefile +4 -3
- data/lib/ea_support/ea_support.rb +54 -0
- data/lib/ea_support/id_store.rb +32 -0
- data/lib/ea_support/uml13_ea_metamodel.rb +562 -0
- data/lib/ea_support/uml13_ea_metamodel_ext.rb +45 -0
- data/lib/ea_support/uml13_ea_metamodel_generator.rb +43 -0
- data/lib/ea_support/uml13_ea_to_uml13.rb +72 -0
- data/lib/ea_support/uml13_to_uml13_ea.rb +82 -0
- data/lib/rgen/ecore/ecore.rb +16 -2
- data/lib/rgen/ecore/ecore_builder_methods.rb +81 -0
- data/lib/rgen/ecore/ecore_instantiator.rb +5 -1
- data/lib/rgen/metamodel_builder/builder_extensions.rb +11 -3
- data/lib/rgen/metamodel_builder/module_extension2.rb +205 -0
- data/lib/rgen/method_delegation.rb +99 -0
- data/lib/rgen/model_builder.rb +27 -0
- data/lib/rgen/model_builder/builder_context.rb +318 -0
- data/lib/rgen/model_builder/model_serializer.rb +201 -0
- data/lib/rgen/model_builder/reference_resolver.rb +156 -0
- data/lib/rgen/template_language/directory_template_container.rb +6 -2
- data/lib/rgen/template_language/output_handler.rb +2 -4
- data/lib/rgen/template_language/template_container.rb +212 -195
- data/lib/rgen/transformer.rb +95 -4
- data/lib/transformers/ecore_to_uml13.rb +66 -0
- data/lib/transformers/uml13_to_ecore.rb +16 -7
- data/test/ea_instantiator_test.rb +8 -14
- data/test/ea_serializer_test.rb +3 -9
- data/test/ea_serializer_test/ea_testmodel_regenerated.xml +2 -2
- data/test/ea_serializer_test/ea_testmodel_regenerated_import.log +3 -0
- data/test/metamodel_roundtrip_test/TestModel_Regenerated.rb +19 -19
- data/test/metamodel_roundtrip_test/houseMetamodel_Regenerated.ecore +44 -44
- data/test/method_delegation_test.rb +178 -0
- data/test/model_builder/builder_context_test.rb +59 -0
- data/test/model_builder/builder_test.rb +284 -0
- data/test/model_builder/ecore_internal.rb +103 -0
- data/test/model_builder/ecore_original.rb +163 -0
- data/test/model_builder/ecore_original_regenerated.rb +163 -0
- data/test/model_builder/reference_resolver_test.rb +156 -0
- data/test/model_builder/serializer_test.rb +63 -0
- data/test/model_builder_test.rb +4 -0
- data/test/rgen_test.rb +2 -0
- data/test/template_language_test.rb +41 -1
- data/test/template_language_test/expected_result1.txt +1 -3
- data/test/template_language_test/templates/define_local_test/local.tpl +8 -0
- data/test/template_language_test/templates/define_local_test/test.tpl +8 -0
- data/test/template_language_test/templates/evaluate_test/test.tpl +7 -0
- data/test/template_language_test/templates/no_indent_test/no_indent.tpl +3 -0
- data/test/template_language_test/templates/no_indent_test/sub1/no_indent.tpl +3 -0
- data/test/template_language_test/templates/no_indent_test/test.tpl +24 -0
- data/test/template_language_test/templates/no_indent_test/test2.tpl +13 -0
- data/test/template_language_test/templates/no_indent_test/test3.tpl +10 -0
- data/test/template_language_test/templates/template_resolution_test/sub1.tpl +9 -0
- data/test/template_language_test/templates/template_resolution_test/sub1/sub1.tpl +3 -0
- data/test/template_language_test/templates/template_resolution_test/test.tpl +4 -0
- data/test/template_language_test/testout.txt +1 -3
- data/test/testmodel/ea_testmodel_import.log +1 -0
- data/test/testmodel/ea_testmodel_regenerated.xml +808 -0
- data/test/transformer_test.rb +3 -5
- metadata +52 -3
- data/lib/instantiators/ea_instantiator.rb +0 -39
@@ -0,0 +1,178 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__) + "/../lib"
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'rgen/method_delegation'
|
5
|
+
|
6
|
+
class MethodDelegationTest < Test::Unit::TestCase
|
7
|
+
include RGen
|
8
|
+
|
9
|
+
class TestDelegate
|
10
|
+
attr_accessor :mode, :callcount
|
11
|
+
def common_delegated(delegator)
|
12
|
+
@callcount ||= 0
|
13
|
+
@callcount += 1
|
14
|
+
case @mode
|
15
|
+
when :continue
|
16
|
+
throw :continue
|
17
|
+
when :delegatorId
|
18
|
+
delegator.object_id
|
19
|
+
when :return7
|
20
|
+
7
|
21
|
+
end
|
22
|
+
end
|
23
|
+
alias to_s_delegated common_delegated
|
24
|
+
alias methodInSingleton_delegated common_delegated
|
25
|
+
alias class_delegated common_delegated
|
26
|
+
alias artificialMethod_delegated common_delegated
|
27
|
+
end
|
28
|
+
|
29
|
+
class ConstPathElement < Module
|
30
|
+
def self.const_missing_delegated(delegator, const)
|
31
|
+
ConstPathElement.new(const)
|
32
|
+
end
|
33
|
+
def initialize(name, parent=nil)
|
34
|
+
@name = name.to_s
|
35
|
+
@parent = parent
|
36
|
+
end
|
37
|
+
def const_missing(const)
|
38
|
+
ConstPathElement.new(const, self)
|
39
|
+
end
|
40
|
+
def to_s
|
41
|
+
if @parent
|
42
|
+
@parent.to_s+"::"+@name
|
43
|
+
else
|
44
|
+
@name
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# missing: check with multiple params and block param
|
50
|
+
|
51
|
+
def test_method_defined_in_singleton
|
52
|
+
# delegator is an Array
|
53
|
+
delegator = []
|
54
|
+
# delegating method is a method defined in the singleton class
|
55
|
+
class << delegator
|
56
|
+
def methodInSingleton
|
57
|
+
"result from method in singleton"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
checkDelegation(delegator, "methodInSingleton", "result from method in singleton")
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_method_defined_in_class
|
64
|
+
# delegator is a String
|
65
|
+
delegator = "Delegator1"
|
66
|
+
checkDelegation(delegator, "to_s", "Delegator1")
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_method_defined_in_superclass
|
70
|
+
# delegator is an instance of a new anonymous class
|
71
|
+
delegator = Class.new.new
|
72
|
+
# delegating method is +object_id+ which is defined in the superclass
|
73
|
+
checkDelegation(delegator, "class", delegator.class)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_new_method
|
77
|
+
# delegator is an String
|
78
|
+
delegator = "Delegator2"
|
79
|
+
# delegating method is a new method which does not exist on String
|
80
|
+
checkDelegation(delegator, "artificialMethod", delegator.object_id, true)
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_const_missing
|
84
|
+
surroundingModule = Module.nesting.first
|
85
|
+
MethodDelegation.registerDelegate(ConstPathElement, surroundingModule, "const_missing")
|
86
|
+
|
87
|
+
assert_equal "SomeArbitraryConst", SomeArbitraryConst.to_s
|
88
|
+
assert_equal "AnotherConst::A::B::C", AnotherConst::A::B::C.to_s
|
89
|
+
|
90
|
+
MethodDelegation.unregisterDelegate(ConstPathElement, surroundingModule, "const_missing")
|
91
|
+
assert_raise NameError do
|
92
|
+
SomeArbitraryConst
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def checkDelegation(delegator, method, originalResult, newMethod=false)
|
97
|
+
delegate1 = TestDelegate.new
|
98
|
+
delegate2 = TestDelegate.new
|
99
|
+
|
100
|
+
MethodDelegation.registerDelegate(delegate1, delegator, method)
|
101
|
+
MethodDelegation.registerDelegate(delegate2, delegator, method)
|
102
|
+
|
103
|
+
assert delegator.respond_to?(:_methodDelegates)
|
104
|
+
if newMethod
|
105
|
+
assert !delegator.respond_to?("#{method}_delegate_original".to_sym)
|
106
|
+
else
|
107
|
+
assert delegator.respond_to?("#{method}_delegate_original".to_sym)
|
108
|
+
end
|
109
|
+
|
110
|
+
# check delegator parameter
|
111
|
+
delegate1.mode = :delegatorId
|
112
|
+
assert_equal delegator.object_id, delegator.send(method)
|
113
|
+
|
114
|
+
delegate1.callcount = 0
|
115
|
+
delegate2.callcount = 0
|
116
|
+
|
117
|
+
delegate1.mode = :return7
|
118
|
+
# delegate1 returns a value
|
119
|
+
assert_equal 7, delegator.send(method)
|
120
|
+
assert_equal 1, delegate1.callcount
|
121
|
+
# delegate2 is not called
|
122
|
+
assert_equal 0, delegate2.callcount
|
123
|
+
|
124
|
+
delegate1.mode = :nothing
|
125
|
+
# delegate1 just exits and thus returns nil
|
126
|
+
assert_equal nil, delegator.send(method)
|
127
|
+
assert_equal 2, delegate1.callcount
|
128
|
+
# delegate2 is not called
|
129
|
+
assert_equal 0, delegate2.callcount
|
130
|
+
|
131
|
+
delegate1.mode = :continue
|
132
|
+
delegate2.mode = :return7
|
133
|
+
# delegate1 is called but continues
|
134
|
+
# delegate2 returns a value
|
135
|
+
assert_equal 7, delegator.send(method)
|
136
|
+
assert_equal 3, delegate1.callcount
|
137
|
+
assert_equal 1, delegate2.callcount
|
138
|
+
|
139
|
+
delegate1.mode = :continue
|
140
|
+
delegate2.mode = :continue
|
141
|
+
# both delegates continue, the original method returns its value
|
142
|
+
checkCallOriginal(delegator, method, originalResult, newMethod)
|
143
|
+
# both delegates are called though
|
144
|
+
assert_equal 4, delegate1.callcount
|
145
|
+
assert_equal 2, delegate2.callcount
|
146
|
+
|
147
|
+
# calling unregister with a non existing method has no effect
|
148
|
+
MethodDelegation.unregisterDelegate(delegate1, delegator, "xxx")
|
149
|
+
MethodDelegation.unregisterDelegate(delegate1, delegator, method)
|
150
|
+
|
151
|
+
checkCallOriginal(delegator, method, originalResult, newMethod)
|
152
|
+
# delegate1 not called any more
|
153
|
+
assert_equal 4, delegate1.callcount
|
154
|
+
# delegate2 is still called
|
155
|
+
assert_equal 3, delegate2.callcount
|
156
|
+
|
157
|
+
MethodDelegation.unregisterDelegate(delegate2, delegator, method)
|
158
|
+
|
159
|
+
checkCallOriginal(delegator, method, originalResult, newMethod)
|
160
|
+
# both delegates not called any more
|
161
|
+
assert_equal 4, delegate1.callcount
|
162
|
+
assert_equal 3, delegate2.callcount
|
163
|
+
|
164
|
+
# after all delegates were unregistered, singleton class should be clean
|
165
|
+
assert !delegator.respond_to?(:_methodDelegates)
|
166
|
+
end
|
167
|
+
|
168
|
+
def checkCallOriginal(delegator, method, originalResult, newMethod)
|
169
|
+
if newMethod
|
170
|
+
assert_raise NoMethodError do
|
171
|
+
result = delegator.send(method)
|
172
|
+
end
|
173
|
+
else
|
174
|
+
result = delegator.send(method)
|
175
|
+
assert_equal originalResult, result
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)+"/../lib"
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'rgen/ecore/ecore'
|
5
|
+
require 'rgen/model_builder/builder_context'
|
6
|
+
|
7
|
+
class BuilderContextTest < Test::Unit::TestCase
|
8
|
+
|
9
|
+
module BuilderExtension1
|
10
|
+
module PackageA
|
11
|
+
def inPackAExt
|
12
|
+
3
|
13
|
+
end
|
14
|
+
module PackageB
|
15
|
+
def inPackBExt
|
16
|
+
5
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class BuilderContext
|
23
|
+
def inBuilderContext
|
24
|
+
7
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_extensionContainerFactory
|
29
|
+
aboveRoot = RGen::ECore::EPackage.new(:name => "AboveRoot")
|
30
|
+
root = RGen::ECore::EPackage.new(:name => "Root", :eSuperPackage => aboveRoot)
|
31
|
+
packageA = RGen::ECore::EPackage.new(:name => "PackageA", :eSuperPackage => root)
|
32
|
+
packageB = RGen::ECore::EPackage.new(:name => "PackageB", :eSuperPackage => packageA)
|
33
|
+
packageC = RGen::ECore::EPackage.new(:name => "PackageBC", :eSuperPackage => packageA)
|
34
|
+
|
35
|
+
factory = RGen::ModelBuilder::BuilderContext::ExtensionContainerFactory.new(root, BuilderExtension1, BuilderContext.new)
|
36
|
+
|
37
|
+
assert_equal BuilderExtension1::PackageA, factory.moduleForPackage(packageA)
|
38
|
+
|
39
|
+
packAExt = factory.extensionContainer(packageA)
|
40
|
+
assert packAExt.respond_to?(:inPackAExt)
|
41
|
+
assert !packAExt.respond_to?(:inPackBExt)
|
42
|
+
assert_equal 3, packAExt.inPackAExt
|
43
|
+
assert_equal 7, packAExt.inBuilderContext
|
44
|
+
|
45
|
+
assert_equal BuilderExtension1::PackageA::PackageB, factory.moduleForPackage(packageB)
|
46
|
+
|
47
|
+
packBExt = factory.extensionContainer(packageB)
|
48
|
+
assert !packBExt.respond_to?(:inPackAExt)
|
49
|
+
assert packBExt.respond_to?(:inPackBExt)
|
50
|
+
assert_equal 5, packBExt.inPackBExt
|
51
|
+
assert_equal 7, packBExt.inBuilderContext
|
52
|
+
|
53
|
+
assert_raise RuntimeError do
|
54
|
+
# aboveRoot is not contained within root
|
55
|
+
assert_nil factory.moduleForPackage(aboveRoot)
|
56
|
+
end
|
57
|
+
assert_nil factory.moduleForPackage(packageC)
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,284 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__) + "/../lib"
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'rgen/ecore/ecore'
|
5
|
+
require 'rgen/ecore/ecore_builder_methods'
|
6
|
+
require 'rgen/environment'
|
7
|
+
require 'rgen/model_builder'
|
8
|
+
|
9
|
+
class ModelBuilderTest < Test::Unit::TestCase
|
10
|
+
|
11
|
+
# a test metamodel used by the following tests
|
12
|
+
module StatemachineMetamodel
|
13
|
+
extend RGen::MetamodelBuilder::ModuleExtension
|
14
|
+
|
15
|
+
module Condition
|
16
|
+
extend RGen::MetamodelBuilder::ModuleExtension
|
17
|
+
|
18
|
+
class Condition < RGen::MetamodelBuilder::MMBase
|
19
|
+
end
|
20
|
+
|
21
|
+
module TimeCondition
|
22
|
+
extend RGen::MetamodelBuilder::ModuleExtension
|
23
|
+
|
24
|
+
class TimeCondition < Condition
|
25
|
+
has_attr 'timeout', Integer
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class Statemachine < RGen::MetamodelBuilder::MMBase
|
31
|
+
has_attr 'name'
|
32
|
+
end
|
33
|
+
|
34
|
+
class State < RGen::MetamodelBuilder::MMBase
|
35
|
+
has_attr 'name'
|
36
|
+
has_attr 'kind', RGen::MetamodelBuilder::DataTypes::Enum.new([:START])
|
37
|
+
end
|
38
|
+
|
39
|
+
class CompositeState < State
|
40
|
+
has_attr 'name'
|
41
|
+
contains_many 'state', State, 'compositeState'
|
42
|
+
end
|
43
|
+
|
44
|
+
class Transition < RGen::MetamodelBuilder::MMBase
|
45
|
+
many_to_one 'sourceState', State, 'outgoingTransition'
|
46
|
+
many_to_one 'targetState', State, 'incomingTransition'
|
47
|
+
has_many 'condition', Condition::Condition
|
48
|
+
end
|
49
|
+
|
50
|
+
Statemachine.contains_many 'state', State, 'statemachine'
|
51
|
+
Statemachine.contains_many 'transition', Transition, 'statemachine'
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_statemachine
|
55
|
+
result = RGen::ModelBuilder.build(StatemachineMetamodel) do
|
56
|
+
statemachine "Airconditioner" do
|
57
|
+
state "Off", :kind => :START
|
58
|
+
compositeState "On" do
|
59
|
+
state "Heating" do
|
60
|
+
transition :as => :outgoingTransition, :targetState => "Cooling",
|
61
|
+
:statemachine => "Airconditioner"
|
62
|
+
end
|
63
|
+
state "Cooling" do
|
64
|
+
end
|
65
|
+
end
|
66
|
+
transition :sourceState => "On.Cooling", :targetState => "On.Heating" do
|
67
|
+
_using Condition::TimeCondition do
|
68
|
+
timeCondition :as => :condition, :timeout => 100
|
69
|
+
end
|
70
|
+
Condition::TimeCondition.timeCondition :as => :condition, :timeout => 10
|
71
|
+
end
|
72
|
+
end
|
73
|
+
_using Condition do
|
74
|
+
statemachine "AirconExtension" do
|
75
|
+
s = state "StartState"
|
76
|
+
transition :sourceState => s, :targetState => "Airconditioner.Off"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
assert result.is_a?(Array)
|
82
|
+
assert_equal 2, result.size
|
83
|
+
|
84
|
+
sm1 = result[0]
|
85
|
+
assert sm1.is_a?(StatemachineMetamodel::Statemachine)
|
86
|
+
assert_equal "Airconditioner", sm1.name
|
87
|
+
|
88
|
+
assert_equal 2, sm1.state.size
|
89
|
+
offState = sm1.state[0]
|
90
|
+
assert offState.is_a?(StatemachineMetamodel::State)
|
91
|
+
assert_equal "Off", offState.name
|
92
|
+
assert_equal :START, offState.kind
|
93
|
+
|
94
|
+
onState = sm1.state[1]
|
95
|
+
assert onState.is_a?(StatemachineMetamodel::CompositeState)
|
96
|
+
assert_equal "On", onState.name
|
97
|
+
|
98
|
+
assert_equal 2, onState.state.size
|
99
|
+
hState = onState.state[0]
|
100
|
+
assert hState.is_a?(StatemachineMetamodel::State)
|
101
|
+
assert_equal "Heating", hState.name
|
102
|
+
|
103
|
+
cState = onState.state[1]
|
104
|
+
assert cState.is_a?(StatemachineMetamodel::State)
|
105
|
+
assert_equal "Cooling", cState.name
|
106
|
+
|
107
|
+
assert_equal 1, hState.outgoingTransition.size
|
108
|
+
hOutTrans = hState.outgoingTransition[0]
|
109
|
+
assert hOutTrans.is_a?(StatemachineMetamodel::Transition)
|
110
|
+
assert_equal cState, hOutTrans.targetState
|
111
|
+
assert_equal sm1, hOutTrans.statemachine
|
112
|
+
|
113
|
+
assert_equal 1, hState.incomingTransition.size
|
114
|
+
hInTrans = hState.incomingTransition[0]
|
115
|
+
assert hInTrans.is_a?(StatemachineMetamodel::Transition)
|
116
|
+
assert_equal cState, hInTrans.sourceState
|
117
|
+
assert_equal sm1, hInTrans.statemachine
|
118
|
+
|
119
|
+
assert_equal 2, hInTrans.condition.size
|
120
|
+
assert hInTrans.condition[0].is_a?(StatemachineMetamodel::Condition::TimeCondition::TimeCondition)
|
121
|
+
assert_equal 100, hInTrans.condition[0].timeout
|
122
|
+
assert hInTrans.condition[1].is_a?(StatemachineMetamodel::Condition::TimeCondition::TimeCondition)
|
123
|
+
assert_equal 10, hInTrans.condition[1].timeout
|
124
|
+
|
125
|
+
sm2 = result[1]
|
126
|
+
assert sm2.is_a?(StatemachineMetamodel::Statemachine)
|
127
|
+
assert_equal "AirconExtension", sm2.name
|
128
|
+
|
129
|
+
assert_equal 1, sm2.state.size
|
130
|
+
sState = sm2.state[0]
|
131
|
+
assert sState.is_a?(StatemachineMetamodel::State)
|
132
|
+
assert_equal "StartState", sState.name
|
133
|
+
|
134
|
+
assert_equal 1, sState.outgoingTransition.size
|
135
|
+
assert sState.outgoingTransition[0].is_a?(StatemachineMetamodel::Transition)
|
136
|
+
assert_equal offState, sState.outgoingTransition[0].targetState
|
137
|
+
assert_equal sm2, sState.outgoingTransition[0].statemachine
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_dynamic
|
141
|
+
numStates = 5
|
142
|
+
env = RGen::Environment.new
|
143
|
+
result = RGen::ModelBuilder.build(StatemachineMetamodel, env) do
|
144
|
+
sm = statemachine "SM#{numStates}" do
|
145
|
+
(1..numStates).each do |i|
|
146
|
+
state "State#{i}" do
|
147
|
+
transition :as => :outgoingTransition, :targetState => "State#{i < numStates ? i+1 : 1}",
|
148
|
+
:statemachine => sm
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
assert_equal 11, env.elements.size
|
154
|
+
assert_equal "SM5", result[0].name
|
155
|
+
state = result[0].state.first
|
156
|
+
assert_equal "State1", state.name
|
157
|
+
state = state.outgoingTransition.first.targetState
|
158
|
+
assert_equal "State2", state.name
|
159
|
+
state = state.outgoingTransition.first.targetState
|
160
|
+
assert_equal "State3", state.name
|
161
|
+
state = state.outgoingTransition.first.targetState
|
162
|
+
assert_equal "State4", state.name
|
163
|
+
state = state.outgoingTransition.first.targetState
|
164
|
+
assert_equal "State5", state.name
|
165
|
+
assert_equal result[0].state[0], state.outgoingTransition.first.targetState
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_multiref
|
169
|
+
result = RGen::ModelBuilder.build(StatemachineMetamodel) do
|
170
|
+
a = transition
|
171
|
+
transition "b"
|
172
|
+
transition "c"
|
173
|
+
state :outgoingTransition => [a, "b", "c"]
|
174
|
+
end
|
175
|
+
|
176
|
+
assert result[0].is_a?(StatemachineMetamodel::Transition)
|
177
|
+
assert result[1].is_a?(StatemachineMetamodel::Transition)
|
178
|
+
assert !result[1].respond_to?(:name)
|
179
|
+
assert result[2].is_a?(StatemachineMetamodel::Transition)
|
180
|
+
assert !result[2].respond_to?(:name)
|
181
|
+
state = result[3]
|
182
|
+
assert state.is_a?(StatemachineMetamodel::State)
|
183
|
+
assert_equal result[0], state.outgoingTransition[0]
|
184
|
+
assert_equal result[1], state.outgoingTransition[1]
|
185
|
+
assert_equal result[2], state.outgoingTransition[2]
|
186
|
+
end
|
187
|
+
|
188
|
+
module TestMetamodel
|
189
|
+
extend RGen::MetamodelBuilder::ModuleExtension
|
190
|
+
|
191
|
+
# these classes have no name
|
192
|
+
class TestA < RGen::MetamodelBuilder::MMBase
|
193
|
+
end
|
194
|
+
class TestB < RGen::MetamodelBuilder::MMBase
|
195
|
+
end
|
196
|
+
class TestC < RGen::MetamodelBuilder::MMBase
|
197
|
+
end
|
198
|
+
TestA.contains_many 'testB', TestB, 'testA'
|
199
|
+
TestC.has_one 'testB', TestB
|
200
|
+
end
|
201
|
+
|
202
|
+
def test_helper_names
|
203
|
+
result = RGen::ModelBuilder.build(TestMetamodel) do
|
204
|
+
testA "_a" do
|
205
|
+
testB "_b"
|
206
|
+
end
|
207
|
+
testC :testB => "_a._b"
|
208
|
+
end
|
209
|
+
assert result[0].is_a?(TestMetamodel::TestA)
|
210
|
+
assert result[1].is_a?(TestMetamodel::TestC)
|
211
|
+
assert_equal result[0].testB[0], result[1].testB
|
212
|
+
end
|
213
|
+
|
214
|
+
def test_ecore
|
215
|
+
result = RGen::ModelBuilder.build(RGen::ECore, nil, RGen::ECore::ECoreBuilderMethods) do
|
216
|
+
ePackage "TestPackage1" do
|
217
|
+
eClass "TestClass1" do
|
218
|
+
eAttribute "attr1", :eType => RGen::ECore::EString
|
219
|
+
eAttr "attr2", RGen::ECore::EInt
|
220
|
+
eBiRef "biRef1", "TestClass2", "testClass1"
|
221
|
+
contains_1toN 'testClass2', "TestClass2", "tc1Parent"
|
222
|
+
end
|
223
|
+
eClass "TestClass2" do
|
224
|
+
eRef "ref1", "TestClass1"
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
assert result.is_a?(Array)
|
230
|
+
assert_equal 1, result.size
|
231
|
+
p1 = result.first
|
232
|
+
|
233
|
+
assert p1.is_a?(RGen::ECore::EPackage)
|
234
|
+
assert_equal "TestPackage1", p1.name
|
235
|
+
|
236
|
+
# TestClass1
|
237
|
+
class1 = p1.eClassifiers.find{|c| c.name == "TestClass1"}
|
238
|
+
assert_not_nil class1
|
239
|
+
assert class1.is_a?(RGen::ECore::EClass)
|
240
|
+
|
241
|
+
# TestClass1.attr1
|
242
|
+
attr1 = class1.eAllAttributes.find{|a| a.name == "attr1"}
|
243
|
+
assert_not_nil attr1
|
244
|
+
assert_equal RGen::ECore::EString, attr1.eType
|
245
|
+
|
246
|
+
# TestClass1.attr2
|
247
|
+
attr2 = class1.eAllAttributes.find{|a| a.name == "attr2"}
|
248
|
+
assert_not_nil attr2
|
249
|
+
assert_equal RGen::ECore::EInt, attr2.eType
|
250
|
+
|
251
|
+
# TestClass2
|
252
|
+
class2 = p1.eClassifiers.find{|c| c.name == "TestClass2"}
|
253
|
+
assert_not_nil class2
|
254
|
+
assert class2.is_a?(RGen::ECore::EClass)
|
255
|
+
|
256
|
+
# TestClass2.ref1
|
257
|
+
ref1 = class2.eAllReferences.find{|a| a.name == "ref1"}
|
258
|
+
assert_not_nil ref1
|
259
|
+
assert_equal class1, ref1.eType
|
260
|
+
|
261
|
+
# TestClass1.biRef1
|
262
|
+
biRef1 = class1.eAllReferences.find{|r| r.name == "biRef1"}
|
263
|
+
assert_not_nil biRef1
|
264
|
+
assert_equal class2, biRef1.eType
|
265
|
+
biRef1Opp = class2.eAllReferences.find {|r| r.name == "testClass1"}
|
266
|
+
assert_not_nil biRef1Opp
|
267
|
+
assert_equal class1, biRef1Opp.eType
|
268
|
+
assert_equal biRef1Opp, biRef1.eOpposite
|
269
|
+
assert_equal biRef1, biRef1Opp.eOpposite
|
270
|
+
|
271
|
+
# TestClass1.testClass2
|
272
|
+
tc2Ref = class1.eAllReferences.find{|r| r.name == "testClass2"}
|
273
|
+
assert_not_nil tc2Ref
|
274
|
+
assert_equal class2, tc2Ref.eType
|
275
|
+
assert tc2Ref.containment
|
276
|
+
assert_equal -1, tc2Ref.upperBound
|
277
|
+
tc2RefOpp = class2.eAllReferences.find{|r| r.name == "tc1Parent"}
|
278
|
+
assert_not_nil tc2RefOpp
|
279
|
+
assert_equal class1, tc2RefOpp.eType
|
280
|
+
assert !tc2RefOpp.containment
|
281
|
+
assert_equal 1, tc2RefOpp.upperBound
|
282
|
+
end
|
283
|
+
|
284
|
+
end
|