concrete 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +32 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +87 -0
- data/concrete/basic_inline_editor.js +73 -0
- data/concrete/clipboard.js +72 -0
- data/concrete/concrete.js +58 -0
- data/concrete/constraint_checker.js +297 -0
- data/concrete/editor.js +964 -0
- data/concrete/element_extension.js +68 -0
- data/concrete/external_identifier_provider.js +112 -0
- data/concrete/helper.js +63 -0
- data/concrete/identifier_provider.js +168 -0
- data/concrete/inline_editor.js +55 -0
- data/concrete/metamodel_provider.js +171 -0
- data/concrete/model_interface.js +429 -0
- data/concrete/scroller.js +106 -0
- data/concrete/selector.js +302 -0
- data/concrete/template_provider.js +141 -0
- data/concrete/ui/abstract_dialog.js +80 -0
- data/concrete/ui/concrete_ui.js +28 -0
- data/concrete/ui/create_module_dialog.js +55 -0
- data/concrete/ui/images/close.png +0 -0
- data/concrete/ui/images/document-new.png +0 -0
- data/concrete/ui/images/document-save.png +0 -0
- data/concrete/ui/images/edit-find-replace.png +0 -0
- data/concrete/ui/images/emblem-symbolic-link.png +0 -0
- data/concrete/ui/images/help-browser.png +0 -0
- data/concrete/ui/images/minus_11px.png +0 -0
- data/concrete/ui/images/plus_11px.png +0 -0
- data/concrete/ui/images/preferences-system.png +0 -0
- data/concrete/ui/images/process-stop.png +0 -0
- data/concrete/ui/images/system-search.png +0 -0
- data/concrete/ui/layout_manager.js +54 -0
- data/concrete/ui/module_browser.js +88 -0
- data/concrete/ui/module_editor.js +217 -0
- data/concrete/ui/open_element_dialog.js +90 -0
- data/concrete/ui/preferences_dialog.js +75 -0
- data/concrete/ui/proceed_dialog.js +52 -0
- data/concrete/ui/search_replace_dialog.js +323 -0
- data/concrete/ui/style.css +296 -0
- data/concrete/ui/toolbar.js +74 -0
- data/concrete/ui/workbench.js +165 -0
- data/doc/concrete_developers_guide.html +1054 -0
- data/doc/concrete_developers_guide.txt +502 -0
- data/doc/concrete_users_guide.html +694 -0
- data/doc/concrete_users_guide.txt +223 -0
- data/example/formula_editor/example_data/example1.json +11 -0
- data/example/formula_editor/formula_editor.html +83 -0
- data/example/formula_editor/sqrt_horz.png +0 -0
- data/example/formula_editor/sqrt_vert.png +0 -0
- data/example/formula_editor/style.css +31 -0
- data/example/metamodel_editor/edit.rb +54 -0
- data/example/metamodel_editor/example_data/formula_metamodel.json +18 -0
- data/example/metamodel_editor/example_data/meta_metamodel.json +22 -0
- data/example/metamodel_editor/example_data/statemachine_metamodel.json +32 -0
- data/example/metamodel_editor/metamodel_editor.html +120 -0
- data/example/metamodel_editor/metamodel_editor2.html +135 -0
- data/example/metamodel_editor/metamodel_editor3.html +151 -0
- data/example/metamodel_editor/style.css +8 -0
- data/example/metamodel_editor/style2.css +19 -0
- data/example/metamodel_editor/style3.css +35 -0
- data/example/minimal_editor/minimal_editor.html +43 -0
- data/example/statemachine_editor/example_data/example1.json +11 -0
- data/example/statemachine_editor/state_background.png +0 -0
- data/example/statemachine_editor/statemachine_editor0.html +55 -0
- data/example/statemachine_editor/statemachine_editor1.html +62 -0
- data/example/statemachine_editor/statemachine_editor2.html +103 -0
- data/example/statemachine_editor/style0.css +8 -0
- data/example/statemachine_editor/style1.css +32 -0
- data/example/statemachine_editor/style2.css +43 -0
- data/example/themes/cobalt.css +176 -0
- data/example/themes/dialog-error.png +0 -0
- data/example/themes/dialog-information.png +0 -0
- data/example/themes/dialog-warning.png +0 -0
- data/example/themes/dots_12px.png +0 -0
- data/example/themes/fold_button_dots_when_hidden.css +18 -0
- data/example/themes/fold_button_plus_minus.css +21 -0
- data/example/themes/fold_button_plus_when_hidden.css +18 -0
- data/example/themes/light_blue.css +177 -0
- data/example/themes/minus_11px.png +0 -0
- data/example/themes/minus_13px.png +0 -0
- data/example/themes/minus_9px.png +0 -0
- data/example/themes/plus_11px.png +0 -0
- data/example/themes/plus_13px.png +0 -0
- data/example/themes/plus_9px.png +0 -0
- data/example/themes/white.css +177 -0
- data/lib/concrete/concrete_syntax_provider.rb +63 -0
- data/lib/concrete/config.rb +36 -0
- data/lib/concrete/file_cache_map.rb +88 -0
- data/lib/concrete/index_builder.rb +108 -0
- data/lib/concrete/metamodel/concrete_mmm.rb +45 -0
- data/lib/concrete/metamodel/ecore_to_concrete.rb +80 -0
- data/lib/concrete/server.rb +92 -0
- data/lib/concrete/util/logger.rb +24 -0
- data/lib/concrete/util/string_writer.rb +17 -0
- data/lib/concrete/working_set.rb +41 -0
- data/rakefile +33 -0
- data/redist/prototype.js +4320 -0
- data/redist/scriptaculous/builder.js +136 -0
- data/redist/scriptaculous/controls.js +991 -0
- data/redist/scriptaculous/dragdrop.js +975 -0
- data/redist/scriptaculous/effects.js +1130 -0
- data/redist/scriptaculous/scriptaculous.js +60 -0
- data/redist/scriptaculous/slider.js +275 -0
- data/redist/scriptaculous/sound.js +55 -0
- data/redist/scriptaculous/unittest.js +568 -0
- data/test/concrete_test.rb +5 -0
- data/test/file_cache_map_test.rb +90 -0
- data/test/file_cache_map_test/testdir/fileA +1 -0
- data/test/index_builder_test.rb +68 -0
- data/test/index_builder_test/ecore_index.js +85 -0
- data/test/index_builder_test/ecore_index_expected.js +85 -0
- data/test/integration/external_elements_test.html +114 -0
- data/test/metamodel_test.rb +40 -0
- data/test/metamodel_test/concrete_mmm_expected.js +19 -0
- data/test/metamodel_test/concrete_mmm_generated.js +19 -0
- data/test/metamodel_test/concrete_mmm_regenerated.js +19 -0
- data/test/unit/external_identifier_provider_test.html +138 -0
- data/test/unit/identifier_provider_test.html +269 -0
- data/test/unit/metamodel_provider_test.html +318 -0
- data/test/unit/model_interface_test.html +257 -0
- data/test/unit/template_provider_test.html +171 -0
- data/test/unit/test.css +90 -0
- data/test/working_set_test.rb +54 -0
- data/test/working_set_test/file1.txt +0 -0
- data/test/working_set_test/file2 +0 -0
- data/test/working_set_test/subdir/file3.xml +0 -0
- metadata +201 -0
@@ -0,0 +1,318 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>Concrete Unit test file</title>
|
4
|
+
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
5
|
+
<script src="../../redist/prototype.js" type="text/javascript"></script>
|
6
|
+
<script src="../../redist/scriptaculous/unittest.js" type="text/javascript"></script>
|
7
|
+
<script type="text/javascript" language="javascript" charset="utf-8">
|
8
|
+
// <![CDATA[
|
9
|
+
var Concrete = {}
|
10
|
+
// ]]>
|
11
|
+
</script>
|
12
|
+
<script src="../../concrete/metamodel_provider.js" type="text/javascript"></script>
|
13
|
+
<link rel="stylesheet" href="test.css" type="text/css" />
|
14
|
+
</head>
|
15
|
+
<body>
|
16
|
+
<h1>Concrete Unit test file</h1>
|
17
|
+
<p>
|
18
|
+
Tests for metamodel_provider_test.js
|
19
|
+
</p>
|
20
|
+
|
21
|
+
<!-- Log output -->
|
22
|
+
<div id="testlog"> </div>
|
23
|
+
|
24
|
+
<div id="metamodel1" style="display: none">
|
25
|
+
[
|
26
|
+
{_class: "Enum", name: "Enum1", literals: ["a", "b"]},
|
27
|
+
{_class: "Class", name: "ClassA", features: [
|
28
|
+
{_class: "Feature", name: "feat1", kind: "attribute"},
|
29
|
+
{_class: "Feature", name: "feat2", kind: "reference"},
|
30
|
+
{_class: "Feature", name: "feat3", kind: "containment"},
|
31
|
+
{_class: "Feature", name: "feat4", kind: "attribute", type: "Enum1"}
|
32
|
+
]},
|
33
|
+
{_class: "Class", name: "ClassB",abstract: true, features: [
|
34
|
+
{_class: "Feature", name: "feat1"},
|
35
|
+
]},
|
36
|
+
{_class: "Class", name: "ClassC", features: [
|
37
|
+
]},
|
38
|
+
{_class: "Class", name: "ClassD"}
|
39
|
+
]
|
40
|
+
</div>
|
41
|
+
|
42
|
+
<div id="metamodel2" style="display: none">
|
43
|
+
[
|
44
|
+
{_class: "Class", name: "ClassA", features: [{_class: "Feature", name: "feat", kind: "reference"}]},
|
45
|
+
{_class: "Class", name: "ClassB", superTypes: ["ClassA"]},
|
46
|
+
{_class: "Class", name: "ClassC", superTypes: ["ClassA", "ClassB"]},
|
47
|
+
{_class: "Class", name: "ClassD", superTypes: ["ClassB"]}
|
48
|
+
]
|
49
|
+
</div>
|
50
|
+
|
51
|
+
<div id="metamodel3" style="display: none">
|
52
|
+
[
|
53
|
+
{_class: "Class", name: "ClassA"},
|
54
|
+
{_class: "Class", name: "ClassB", features: [
|
55
|
+
{_class: "Feature", name: "feat1", kind: "reference", type: "ClassA"},
|
56
|
+
{_class: "Feature", name: "feat2", kind: "containment", type: "ClassA"}
|
57
|
+
]}
|
58
|
+
]
|
59
|
+
</div>
|
60
|
+
|
61
|
+
<div id="metamodel4" style="display: none">
|
62
|
+
[
|
63
|
+
{_class: "Class", name: "ClassA"},
|
64
|
+
{_class: "Class", name: "ClassB", features: [
|
65
|
+
{_class: "Feature", name: "feat1", kind: "reference", type: "ClassC"},
|
66
|
+
]}
|
67
|
+
]
|
68
|
+
</div>
|
69
|
+
|
70
|
+
<div id="metamodel5" style="display: none">
|
71
|
+
[
|
72
|
+
{_class: "Class", name: "ClassA"},
|
73
|
+
{_class: "Class", name: "ClassB", superTypes: ["ClassC"]}
|
74
|
+
]
|
75
|
+
</div>
|
76
|
+
|
77
|
+
<div id="metamodel6" style="display: none">
|
78
|
+
[
|
79
|
+
{_class: "Class", name: "ClassA", features: [
|
80
|
+
{_class: "Feature", name: "feat1", kind: "attribute", upperLimit: 2},
|
81
|
+
{_class: "Feature", name: "feat2", kind: "reference", upperLimit: 3},
|
82
|
+
{_class: "Feature", name: "feat3", kind: "containment", upperLimit: 4}
|
83
|
+
]}
|
84
|
+
]
|
85
|
+
</div>
|
86
|
+
|
87
|
+
<!-- Tests follow -->
|
88
|
+
<script type="text/javascript" language="javascript" charset="utf-8">
|
89
|
+
// <![CDATA[
|
90
|
+
|
91
|
+
new Test.Unit.Runner({
|
92
|
+
|
93
|
+
setup: function() {
|
94
|
+
},
|
95
|
+
|
96
|
+
testBasics: function() { with(this) {
|
97
|
+
var provider = new Concrete.MetamodelProvider($('metamodel1').textContent.evalJSON());
|
98
|
+
var classes = provider.metaclasses;
|
99
|
+
|
100
|
+
assertEqual(4, classes.size());
|
101
|
+
|
102
|
+
// ClassA
|
103
|
+
assertEqual("ClassA", classes[0].name)
|
104
|
+
assertEqual(4, classes[0].features.size())
|
105
|
+
assert(provider.metaclassesByName["ClassA"] == classes[0])
|
106
|
+
// Default superTypes
|
107
|
+
assertEqual(1, classes[0].superTypes.size())
|
108
|
+
var rootClass = classes[0].superTypes[0]
|
109
|
+
assertEqual("_Root", rootClass.name)
|
110
|
+
// Default subTypes
|
111
|
+
assertEqual(0, classes[0].subTypes.size())
|
112
|
+
assertEqual(0, classes[0].allSubTypes().size())
|
113
|
+
// Default abstract
|
114
|
+
assertEqual(false, classes[0].abstract)
|
115
|
+
|
116
|
+
assertEqual("feat1", classes[0].features[0].name)
|
117
|
+
assert(classes[0].features[0].isAttribute())
|
118
|
+
assert(classes[0].features[0].containingClass == classes[0])
|
119
|
+
// Default type
|
120
|
+
assertEqual("String", classes[0].features[0].type.name)
|
121
|
+
// Default upperLimit
|
122
|
+
assertEqual(1, classes[0].features[0].upperLimit);
|
123
|
+
|
124
|
+
assertEqual("feat2", classes[0].features[1].name)
|
125
|
+
assert(classes[0].features[1].isReference())
|
126
|
+
assert(classes[0].features[1].containingClass == classes[0])
|
127
|
+
// Default type
|
128
|
+
assert(classes[0].features[1].type == rootClass)
|
129
|
+
// Default upperLimit
|
130
|
+
assertEqual(1, classes[0].features[1].upperLimit);
|
131
|
+
|
132
|
+
assertEqual("feat3", classes[0].features[2].name)
|
133
|
+
assert(classes[0].features[2].isContainment())
|
134
|
+
assert(classes[0].features[2].containingClass == classes[0])
|
135
|
+
// Default type
|
136
|
+
assert(classes[0].features[2].type == rootClass)
|
137
|
+
// Default upperLimit
|
138
|
+
assertEqual(-1, classes[0].features[2].upperLimit);
|
139
|
+
|
140
|
+
assertEqual("feat4", classes[0].features[3].name)
|
141
|
+
|
142
|
+
// ClassB
|
143
|
+
assertEqual("ClassB", classes[1].name)
|
144
|
+
assertEqual(1, classes[1].features.size())
|
145
|
+
assertEqual("feat1", classes[1].features[0].name)
|
146
|
+
assertEqual("String", classes[1].features[0].type.name)
|
147
|
+
assert(classes[1].features[0].isAttribute())
|
148
|
+
assert(classes[1].features[0].containingClass == classes[1])
|
149
|
+
assertEqual(true, classes[1].abstract)
|
150
|
+
|
151
|
+
// ClassC
|
152
|
+
assertEqual(0, classes[2].features.size())
|
153
|
+
assert(provider.metaclassesByName["ClassC"] == classes[2])
|
154
|
+
|
155
|
+
// ClassD
|
156
|
+
assertEqual(0, classes[3].features.size())
|
157
|
+
assert(provider.metaclassesByName["ClassD"] == classes[3])
|
158
|
+
}},
|
159
|
+
|
160
|
+
testGeneralization: function() { with(this) {
|
161
|
+
var provider = new Concrete.MetamodelProvider($('metamodel2').textContent.evalJSON());
|
162
|
+
var classes = provider.metaclasses;
|
163
|
+
|
164
|
+
var classA = classes[0]
|
165
|
+
var classB = classes[1]
|
166
|
+
var classC = classes[2]
|
167
|
+
var classD = classes[3]
|
168
|
+
|
169
|
+
var rootClass = classA.features[0].type
|
170
|
+
assertEqual(4, rootClass.subTypes.size());
|
171
|
+
assertEqual(classA, rootClass.subTypes[0]);
|
172
|
+
assertEqual(classB, rootClass.subTypes[1]);
|
173
|
+
assertEqual(classC, rootClass.subTypes[2]);
|
174
|
+
assertEqual(classD, rootClass.subTypes[3]);
|
175
|
+
|
176
|
+
// ClassA
|
177
|
+
assertEqual(1, classA.superTypes.size());
|
178
|
+
assertEqual(rootClass, classA.superTypes[0]);
|
179
|
+
assertEqual(1, classA.allSuperTypes().size());
|
180
|
+
assertEqual(rootClass, classA.allSuperTypes()[0]);
|
181
|
+
assertEqual(2, classA.subTypes.size());
|
182
|
+
assertEqual(classB, classA.subTypes[0]);
|
183
|
+
assertEqual(classC, classA.subTypes[1]);
|
184
|
+
assertEqual(3, classA.allSubTypes().size());
|
185
|
+
assertEqual(classB, classA.allSubTypes()[0]);
|
186
|
+
assertEqual(classC, classA.allSubTypes()[1]);
|
187
|
+
assertEqual(classD, classA.allSubTypes()[2]);
|
188
|
+
|
189
|
+
// ClassB
|
190
|
+
assertEqual(2, classB.superTypes.size());
|
191
|
+
assertEqual(rootClass, classB.superTypes[0])
|
192
|
+
assertEqual(classA, classB.superTypes[1])
|
193
|
+
assertEqual(2, classB.allSuperTypes().size());
|
194
|
+
assertEqual(rootClass, classB.allSuperTypes()[0])
|
195
|
+
assertEqual(classA, classB.allSuperTypes()[1])
|
196
|
+
assertEqual(2, classB.subTypes.size());
|
197
|
+
assertEqual(classC, classB.subTypes[0]);
|
198
|
+
assertEqual(classD, classB.subTypes[1]);
|
199
|
+
assertEqual(2, classB.allSubTypes().size());
|
200
|
+
assertEqual(classC, classB.allSubTypes()[0]);
|
201
|
+
assertEqual(classD, classB.allSubTypes()[1]);
|
202
|
+
// features
|
203
|
+
assertEqual(1, classB.allFeatures().size());
|
204
|
+
assertEqual("feat", classB.allFeatures()[0].name);
|
205
|
+
|
206
|
+
|
207
|
+
// ClassC
|
208
|
+
assertEqual(3, classC.superTypes.size());
|
209
|
+
assertEqual(rootClass, classC.superTypes[0])
|
210
|
+
assertEqual(classA, classC.superTypes[1])
|
211
|
+
assertEqual(classB, classC.superTypes[2])
|
212
|
+
assertEqual(3, classC.allSuperTypes().size());
|
213
|
+
assertEqual(rootClass, classC.allSuperTypes()[0])
|
214
|
+
assertEqual(classA, classC.allSuperTypes()[1])
|
215
|
+
assertEqual(classB, classC.allSuperTypes()[2])
|
216
|
+
assertEqual(0, classC.subTypes.size());
|
217
|
+
assertEqual(0, classD.allSubTypes().size());
|
218
|
+
|
219
|
+
// ClassD
|
220
|
+
assertEqual(2, classD.superTypes.size());
|
221
|
+
assertEqual(rootClass, classD.superTypes[0])
|
222
|
+
assertEqual(classB, classD.superTypes[1])
|
223
|
+
assertEqual(3, classD.allSuperTypes().size());
|
224
|
+
assertEqual(rootClass, classD.allSuperTypes()[0])
|
225
|
+
assertEqual(classA, classD.allSuperTypes()[1])
|
226
|
+
assertEqual(classB, classD.allSuperTypes()[2])
|
227
|
+
assertEqual(0, classD.subTypes.size());
|
228
|
+
assertEqual(0, classD.allSubTypes().size());
|
229
|
+
}},
|
230
|
+
|
231
|
+
testGeneralizationUnresolved: function() { with(this) {
|
232
|
+
assertRaise("Error", function() {
|
233
|
+
new Concrete.MetamodelProvider($('metamodel5').textContent.evalJSON());
|
234
|
+
})
|
235
|
+
}},
|
236
|
+
|
237
|
+
testReference: function() { with(this) {
|
238
|
+
var provider = new Concrete.MetamodelProvider($('metamodel3').textContent.evalJSON());
|
239
|
+
var classes = provider.metaclasses;
|
240
|
+
|
241
|
+
var classA = classes[0]
|
242
|
+
var classB = classes[1]
|
243
|
+
|
244
|
+
assertEqual(classA, classB.features[0].type)
|
245
|
+
assertEqual(classA, classB.features[1].type)
|
246
|
+
}},
|
247
|
+
|
248
|
+
testLimits: function() { with(this) {
|
249
|
+
var provider = new Concrete.MetamodelProvider($('metamodel6').textContent.evalJSON());
|
250
|
+
var classes = provider.metaclasses;
|
251
|
+
|
252
|
+
// ClassA
|
253
|
+
assertEqual("ClassA", classes[0].name);
|
254
|
+
assertEqual(2, classes[0].features[0].upperLimit);
|
255
|
+
assertEqual(3, classes[0].features[1].upperLimit);
|
256
|
+
assertEqual(4, classes[0].features[2].upperLimit);
|
257
|
+
}},
|
258
|
+
|
259
|
+
testReferenceUnresolved: function() { with(this) {
|
260
|
+
assertRaise("Error", function() {
|
261
|
+
new Concrete.MetamodelProvider($('metamodel4').textContent.evalJSON());
|
262
|
+
})
|
263
|
+
}},
|
264
|
+
|
265
|
+
testNoClassName: function() { with(this) {
|
266
|
+
assertRaise("Error", function() {
|
267
|
+
new Concrete.MetamodelProvider("[{}]".evalJSON());
|
268
|
+
});
|
269
|
+
}},
|
270
|
+
|
271
|
+
testAmbiguousClassName: function() { with(this) {
|
272
|
+
assertRaise("Error", function() {
|
273
|
+
new Concrete.MetamodelProvider("[{name: 'A'}, {name: 'A'}]".evalJSON());
|
274
|
+
});
|
275
|
+
}},
|
276
|
+
|
277
|
+
testInvalidClassProperties: function() { with(this) {
|
278
|
+
assertRaise("Error", function() {
|
279
|
+
new Concrete.MetamodelProvider("[{name: 'A', wrongProp: 1}]".evalJSON());
|
280
|
+
});
|
281
|
+
}},
|
282
|
+
|
283
|
+
testNoFeatureName: function() { with(this) {
|
284
|
+
assertRaise("Error", function() {
|
285
|
+
new Concrete.MetamodelProvider("[{name: 'A', features: [{}]}]".evalJSON());
|
286
|
+
});
|
287
|
+
}},
|
288
|
+
|
289
|
+
testAmbiguousFeatureName: function() { with(this) {
|
290
|
+
assertRaise("Error", function() {
|
291
|
+
new Concrete.MetamodelProvider("[{name: 'A', features: [{name: 'B'}, {name: 'B'}]}]".evalJSON());
|
292
|
+
});
|
293
|
+
}},
|
294
|
+
|
295
|
+
testInvalidFeatureProperties: function() { with(this) {
|
296
|
+
assertRaise("Error", function() {
|
297
|
+
new Concrete.MetamodelProvider("[{name: 'A', features: [{name: 'f1', wrongProp: 1}]}]".evalJSON());
|
298
|
+
});
|
299
|
+
assertRaise("Error", function() {
|
300
|
+
new Concrete.MetamodelProvider("[{name: 'A', features: [{name: 'f1', kind: 'wrong'}]}]".evalJSON());
|
301
|
+
});
|
302
|
+
}},
|
303
|
+
|
304
|
+
testInvalidAttributeType: function() { with(this) {
|
305
|
+
assertRaise("Error", function() {
|
306
|
+
new Concrete.MetamodelProvider("[{name: 'A', features: [{name: 'f1', type: 'Strng'}]}]".evalJSON());
|
307
|
+
});
|
308
|
+
}},
|
309
|
+
|
310
|
+
testEmptyMM: function() { with(this) {
|
311
|
+
var provider = new Concrete.MetamodelProvider("[]".evalJSON());
|
312
|
+
assertEqual(0, provider.metaclasses.size());
|
313
|
+
}}
|
314
|
+
})
|
315
|
+
// ]]>
|
316
|
+
</script>
|
317
|
+
</body>
|
318
|
+
</html>
|
@@ -0,0 +1,257 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>Concrete Unit test file</title>
|
4
|
+
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
5
|
+
<script src="../../redist/prototype.js" type="text/javascript"></script>
|
6
|
+
<script src="../../redist/scriptaculous/unittest.js" type="text/javascript"></script>
|
7
|
+
<script type="text/javascript" language="javascript" charset="utf-8">
|
8
|
+
// <![CDATA[
|
9
|
+
var Concrete = {}
|
10
|
+
// ]]>
|
11
|
+
</script>
|
12
|
+
<script src="../../concrete/helper.js" type="text/javascript"></script>
|
13
|
+
<script src="../../concrete/metamodel_provider.js" type="text/javascript"></script>
|
14
|
+
<script src="../../concrete/element_extension.js" type="text/javascript"></script>
|
15
|
+
<script src="../../concrete/template_provider.js" type="text/javascript"></script>
|
16
|
+
<script src="../../concrete/identifier_provider.js" type="text/javascript"></script>
|
17
|
+
<script src="../../concrete/model_interface.js" type="text/javascript"></script>
|
18
|
+
<link rel="stylesheet" href="test.css" type="text/css" />
|
19
|
+
<style type="text/css" media="screen">
|
20
|
+
/* <![CDATA[ */
|
21
|
+
.ct_containment { margin-left: 20px; }
|
22
|
+
/* ]]> */
|
23
|
+
</style>
|
24
|
+
</head>
|
25
|
+
<body>
|
26
|
+
<h1>Concrete Unit test file</h1>
|
27
|
+
<p>
|
28
|
+
Tests for model_interface.js
|
29
|
+
</p>
|
30
|
+
|
31
|
+
<!-- Log output -->
|
32
|
+
<div id="testlog"> </div>
|
33
|
+
|
34
|
+
<div id="statemachineMetamodel" style="display: none">
|
35
|
+
[
|
36
|
+
{_class: "Class", name: "Statemachine", features: [
|
37
|
+
{_class: "Feature", name: "name", kind: "attribute", type: "String"},
|
38
|
+
{_class: "Feature", name: "states", kind: "containment", type: "State"},
|
39
|
+
{_class: "Feature", name: "transitions", kind: "containment", type: "Transition"}
|
40
|
+
]},
|
41
|
+
{_class: "Class", name: "State", abstract: true, features: [
|
42
|
+
{_class: "Feature", name: "name", kind: "attribute", type: "String"}
|
43
|
+
]},
|
44
|
+
{_class: "Class", name: "SimpleState", superTypes: ["State"]},
|
45
|
+
{_class: "Class", name: "CompositeState", superTypes: ["State"], features: [
|
46
|
+
{_class: "Feature", name: "subStates", kind: "containment", type: "State"}
|
47
|
+
]},
|
48
|
+
{_class: "Class", name: "Transition", features: [
|
49
|
+
{_class: "Feature", name: "sourceState", kind: "reference", type: "State"},
|
50
|
+
{_class: "Feature", name: "targetState", kind: "reference", type: "State"}
|
51
|
+
]}
|
52
|
+
]
|
53
|
+
</div>
|
54
|
+
|
55
|
+
<div id="testModel" style="display: none">
|
56
|
+
{_class: "Statemachine", name: "M1",
|
57
|
+
states: [
|
58
|
+
{_class: "SimpleState", name: "S1"},
|
59
|
+
{_class: "CompositeState", name: "S2", subStates: [
|
60
|
+
{_class: "SimpleState", name: "S21"},
|
61
|
+
{_class: "SimpleState", name: "S22"}
|
62
|
+
]}
|
63
|
+
],
|
64
|
+
transitions: [
|
65
|
+
{_class: "Transition", sourceState: "S2/S21", targetState: "S2/S22"}
|
66
|
+
]
|
67
|
+
}
|
68
|
+
</div>
|
69
|
+
|
70
|
+
<div id="genericTemplates" style="display: none">
|
71
|
+
</div>
|
72
|
+
|
73
|
+
<div id="modelroot" class="ct_root">
|
74
|
+
</div>
|
75
|
+
|
76
|
+
<!-- Tests follow -->
|
77
|
+
<script type="text/javascript" language="javascript" charset="utf-8">
|
78
|
+
// <![CDATA[
|
79
|
+
|
80
|
+
new Test.Unit.Runner({
|
81
|
+
|
82
|
+
setup: function() {
|
83
|
+
$('modelroot').innerHTML = "";
|
84
|
+
$('genericTemplates').innerHTML = "";
|
85
|
+
},
|
86
|
+
|
87
|
+
testCreateElement: function() { with(this) {
|
88
|
+
var root = $('modelroot');
|
89
|
+
var mi = createModelInterface(root);
|
90
|
+
var ip = createIdentifierProvider(mi);
|
91
|
+
mi.createElement(root, "bottom", $('testModel').textContent.evalJSON());
|
92
|
+
mi.createElement(root.childElements()[0], "after", {_class: "Statemachine", name: "M2"});
|
93
|
+
mi.createElement(root.childElements()[1], "before", {_class: "Statemachine"});
|
94
|
+
// currently, abstract classes can be instantiated
|
95
|
+
mi.createElement(root, "bottom", {_class: "Statemachine", name: "M3", states: [{_class: "State", name: "S1"}]});
|
96
|
+
var elements = mi.elements();
|
97
|
+
|
98
|
+
assertEqual(10, elements.size());
|
99
|
+
assertEqual("/M1", ip.getIdentifier(elements[0]));
|
100
|
+
assertEqual("/M1/S1", ip.getIdentifier(elements[1]));
|
101
|
+
assertEqual("/M1/S2", ip.getIdentifier(elements[2]));
|
102
|
+
assertEqual("/M1/S2/S21", ip.getIdentifier(elements[3]));
|
103
|
+
assertEqual("/M1/S2/S22", ip.getIdentifier(elements[4]));
|
104
|
+
assertEqual(undefined, ip.getIdentifier(elements[5]));
|
105
|
+
assertEqual(undefined, ip.getIdentifier(elements[6]));
|
106
|
+
assertEqual("/M2", ip.getIdentifier(elements[7]));
|
107
|
+
assertEqual("/M3", ip.getIdentifier(elements[8]));
|
108
|
+
assertEqual("/M3/S1", ip.getIdentifier(elements[9]));
|
109
|
+
|
110
|
+
mi.createElement(ip.getElement("/M1/S2/S21"), "before", {_class: "CompositeState", name: "S20", subStates: [{_class: "SimpleState", name: "S201"}]});
|
111
|
+
var elements = mi.elements();
|
112
|
+
assertEqual(12, elements.size());
|
113
|
+
assertEqual("/M1/S2/S20", ip.getIdentifier(elements[3]));
|
114
|
+
assertEqual("/M1/S2/S20/S201", ip.getIdentifier(elements[4]));
|
115
|
+
assertEqual("/M1/S2/S21", ip.getIdentifier(elements[5]));
|
116
|
+
}},
|
117
|
+
|
118
|
+
testRemoveElement: function() { with(this) {
|
119
|
+
var root = $('modelroot');
|
120
|
+
var mi = createModelInterface(root);
|
121
|
+
var ip = createIdentifierProvider(mi);
|
122
|
+
mi.createElement(root, "bottom", $('testModel').textContent.evalJSON());
|
123
|
+
mi.createElement(root, "bottom", {_class: "Statemachine", name: "M2"});
|
124
|
+
|
125
|
+
assertEqual(7, mi.elements().size());
|
126
|
+
assertEqual("/M1", ip.getIdentifier(mi.elements()[0]));
|
127
|
+
assertEqual("/M1/S1", ip.getIdentifier(mi.elements()[1]));
|
128
|
+
assertEqual("/M1/S2", ip.getIdentifier(mi.elements()[2]));
|
129
|
+
assertEqual(mi.elements()[0], ip.getElement("/M1"));
|
130
|
+
assertEqual(mi.elements()[1], ip.getElement("/M1/S1"));
|
131
|
+
assertEqual(mi.elements()[2], ip.getElement("/M1/S2"));
|
132
|
+
|
133
|
+
mi.removeElement(mi.elements()[2]);
|
134
|
+
assertEqual(4, mi.elements().size());
|
135
|
+
assertEqual(undefined, ip.getElement("/M1/S2"));
|
136
|
+
|
137
|
+
mi.removeElement(root.childElements()[0]);
|
138
|
+
assertEqual(1, mi.elements().size());
|
139
|
+
assertEqual(undefined, ip.getElement("/M1"));
|
140
|
+
assertEqual(undefined, ip.getElement("/M1/S1"));
|
141
|
+
assertEqual("/M2", ip.getIdentifier(mi.elements()[0]));
|
142
|
+
|
143
|
+
mi.removeElement(root.childElements()[0]);
|
144
|
+
assertEqual(0, mi.elements().size());
|
145
|
+
assertEqual("", root.innerHTML);
|
146
|
+
}},
|
147
|
+
|
148
|
+
testCreateValue: function() { with(this) {
|
149
|
+
var root = $('modelroot');
|
150
|
+
var mi = createModelInterface(root);
|
151
|
+
var ip = createIdentifierProvider(mi);
|
152
|
+
mi.createElement(root, "bottom", {_class: "SimpleState"});
|
153
|
+
assertEqual(1, mi.elements().size());
|
154
|
+
var s1 = mi.elements()[0];
|
155
|
+
mi.createValue(s1.down(".ct_slot"), "bottom", "S1");
|
156
|
+
assertEqual(s1, ip.getElement("/S1"));
|
157
|
+
mi.createElement(root, "bottom", {_class: "Transition"});
|
158
|
+
var tr = mi.elements()[1];
|
159
|
+
mi.createValue(tr.down(".ct_slot"), "bottom", "/test/ref1");
|
160
|
+
mi.createValue(tr.down(".ct_slot").down(), "before", "/test/ref2");
|
161
|
+
mi.createValue(tr.down(".ct_slot").down(), "after", "/test/ref3");
|
162
|
+
assertEqual('{"_class": "Transition", "sourceState": ["/test/ref2", "/test/ref3", "/test/ref1"]}', Object.toJSON(mi.extractModel(tr)));
|
163
|
+
}},
|
164
|
+
|
165
|
+
testChangeValue: function() { with(this) {
|
166
|
+
var root = $('modelroot');
|
167
|
+
var mi = createModelInterface(root);
|
168
|
+
var ip = createIdentifierProvider(mi);
|
169
|
+
mi.createElement(root, "bottom", {_class: "SimpleState", name: "S1"});
|
170
|
+
var s1 = mi.elements()[0];
|
171
|
+
assertEqual(s1, ip.getElement("/S1"));
|
172
|
+
mi.changeValue(s1.down(".ct_value"), "S2");
|
173
|
+
assertEqual(undefined, ip.getElement("/S1"));
|
174
|
+
assertEqual(s1, ip.getElement("/S2"));
|
175
|
+
mi.changeValue(s1.down(".ct_value"), "");
|
176
|
+
assertEqual(undefined, ip.getElement("/S1"));
|
177
|
+
assertEqual(undefined, ip.getElement("/S2"));
|
178
|
+
assertEqual(undefined, ip.getIdentifier(s1));
|
179
|
+
|
180
|
+
mi.createElement(root, "bottom", {_class: "Transition", sourceState: ["/test/ref1", "/test/ref2"]});
|
181
|
+
var tr = mi.elements()[1];
|
182
|
+
mi.changeValue(tr.down(".ct_slot").down(), "xxx");
|
183
|
+
assertEqual('{"_class": "Transition", "sourceState": ["xxx", "/test/ref2"]}', Object.toJSON(mi.extractModel(tr)));
|
184
|
+
}},
|
185
|
+
|
186
|
+
testRemoveValue: function() { with(this) {
|
187
|
+
var root = $('modelroot');
|
188
|
+
var mi = createModelInterface(root);
|
189
|
+
var ip = createIdentifierProvider(mi);
|
190
|
+
mi.createElement(root, "bottom", {_class: "SimpleState", name: "S1"});
|
191
|
+
var s1 = mi.elements()[0];
|
192
|
+
assertEqual(s1, ip.getElement("/S1"));
|
193
|
+
mi.removeValue(s1.down(".ct_value"));
|
194
|
+
assertEqual(undefined, ip.getElement("/S2"));
|
195
|
+
mi.createElement(root, "bottom", {_class: "Transition", sourceState: ["/test/ref1", "/test/ref2"]});
|
196
|
+
var tr = mi.elements()[1];
|
197
|
+
mi.removeValue(tr.down(".ct_slot").down());
|
198
|
+
assertEqual('{"_class": "Transition", "sourceState": "/test/ref2"}', Object.toJSON(mi.extractModel(tr)));
|
199
|
+
}},
|
200
|
+
|
201
|
+
testExtractRoundtrip: function() { with(this) {
|
202
|
+
var root = $('modelroot');
|
203
|
+
var mi = createModelInterface(root);
|
204
|
+
|
205
|
+
mi.createElement(root, "bottom", $('testModel').textContent.evalJSON());
|
206
|
+
var rootContent = root.innerHTML;
|
207
|
+
|
208
|
+
var model = mi.extractModel(root.childElements()[0]);
|
209
|
+
mi.removeElement(root.childElements()[0]);
|
210
|
+
assertEqual("", root.innerHTML);
|
211
|
+
|
212
|
+
mi.createElement(root, "bottom", model);
|
213
|
+
assertEqual(rootContent, root.innerHTML);
|
214
|
+
}},
|
215
|
+
|
216
|
+
testNextElement: function() { with(this) {
|
217
|
+
var root = $('modelroot');
|
218
|
+
var mi = createModelInterface(root);
|
219
|
+
|
220
|
+
mi.createElement(root, "bottom", $('testModel').textContent.evalJSON());
|
221
|
+
|
222
|
+
var check = function(stack) {
|
223
|
+
var element = root.childElements().first();
|
224
|
+
assertEqual("M1", element.featureValues("name")[0]);
|
225
|
+
element = Concrete.ModelInterface.Helper.nextElement(element, stack);
|
226
|
+
assertEqual("S1", element.featureValues("name")[0]);
|
227
|
+
element = Concrete.ModelInterface.Helper.nextElement(element, stack);
|
228
|
+
assertEqual("S2", element.featureValues("name")[0]);
|
229
|
+
element = Concrete.ModelInterface.Helper.nextElement(element, stack);
|
230
|
+
assertEqual("S21", element.featureValues("name")[0]);
|
231
|
+
element = Concrete.ModelInterface.Helper.nextElement(element, stack);
|
232
|
+
assertEqual("S22", element.featureValues("name")[0]);
|
233
|
+
element = Concrete.ModelInterface.Helper.nextElement(element, stack);
|
234
|
+
assertEqual("S2/S21", element.featureValues("sourceState")[0]);
|
235
|
+
element = Concrete.ModelInterface.Helper.nextElement(element, stack);
|
236
|
+
assert(element == false);
|
237
|
+
}
|
238
|
+
check(undefined);
|
239
|
+
check([]);
|
240
|
+
}}
|
241
|
+
})
|
242
|
+
|
243
|
+
function createModelInterface(root) {
|
244
|
+
var mp = new Concrete.MetamodelProvider($('statemachineMetamodel').textContent.evalJSON());
|
245
|
+
var tp = new Concrete.TemplateProvider($('genericTemplates'));
|
246
|
+
return new Concrete.ModelInterface(root, tp, mp);
|
247
|
+
}
|
248
|
+
|
249
|
+
function createIdentifierProvider(modelInterface) {
|
250
|
+
var ip = new Concrete.QualifiedNameBasedIdentifierProvider({nameAttribute: "name", separator: "/", leadingSeparator: true});
|
251
|
+
modelInterface.addModelChangeListener(ip);
|
252
|
+
return ip;
|
253
|
+
}
|
254
|
+
// ]]>
|
255
|
+
</script>
|
256
|
+
</body>
|
257
|
+
</html>
|