|
|
@@ -3781,7 +3781,7 @@ class TestModelverse(unittest.TestCase):
|
|
|
# Model mismatch (target)
|
|
|
assert transformation_between({"key_A": "users/user/test/A"}, {"key_B": "users/user/test/A"}) == set([])
|
|
|
|
|
|
- def test_op_transformation_MANUAL(self):
|
|
|
+ def test_op_transformation_add_MANUAL(self):
|
|
|
# Add models for transformation
|
|
|
model_add("users/user/test/A", "formalisms/SimpleClassDiagrams", """
|
|
|
SimpleAttribute String {}
|
|
|
@@ -3797,19 +3797,8 @@ class TestModelverse(unittest.TestCase):
|
|
|
name : String
|
|
|
}
|
|
|
""")
|
|
|
- model_add("users/user/test/a", "users/user/test/A", """
|
|
|
- A abc {
|
|
|
- name = "1"
|
|
|
- }
|
|
|
- A def {
|
|
|
- name = "2"
|
|
|
- }
|
|
|
- """)
|
|
|
- model_add("users/user/test/b", "users/user/test/B", """
|
|
|
- B {
|
|
|
- name = "3"
|
|
|
- }
|
|
|
- """)
|
|
|
+ model_add("users/user/test/a", "users/user/test/A", "A {}")
|
|
|
+ model_add("users/user/test/b", "users/user/test/B", "B {}")
|
|
|
|
|
|
# Add a transformation with normal signature
|
|
|
transformation_add_MANUAL({"MODEL_A": "users/user/test/A"}, {"MODEL_B": "users/user/test/B"}, "users/user/test/c")
|
|
|
@@ -3922,48 +3911,137 @@ class TestModelverse(unittest.TestCase):
|
|
|
except ModelExists:
|
|
|
assert sig == transformation_signature("users/user/test/c")
|
|
|
|
|
|
+ def test_op_transformation_add_AL(self):
|
|
|
+ # Add models for transformation
|
|
|
+ model_add("users/user/test/A", "formalisms/SimpleClassDiagrams", """
|
|
|
+ SimpleAttribute String {}
|
|
|
+ Class A {
|
|
|
+ name = "A"
|
|
|
+ name : String
|
|
|
+ }
|
|
|
+ """)
|
|
|
+ model_add("users/user/test/B", "formalisms/SimpleClassDiagrams", """
|
|
|
+ SimpleAttribute String {}
|
|
|
+ Class B {
|
|
|
+ name = "B"
|
|
|
+ name : String
|
|
|
+ }
|
|
|
+ """)
|
|
|
+ model_add("users/user/test/a", "users/user/test/A", "A {}")
|
|
|
+ model_add("users/user/test/b", "users/user/test/B", "B {}")
|
|
|
+
|
|
|
+ default_function = "Boolean function main(model : Element):\n\treturn True!"
|
|
|
+
|
|
|
+ # Add a transformation with normal signature
|
|
|
+ transformation_add_AL({"MODEL_A": "users/user/test/A"}, {"MODEL_B": "users/user/test/B"}, "users/user/test/c", default_function)
|
|
|
+
|
|
|
+ # Add a transformation with normal signature and merged metamodel changes
|
|
|
def operation(model):
|
|
|
- # Check if model correctly loaded with names rewritten
|
|
|
+ # Check if both are present
|
|
|
lst = element_list_nice(model)
|
|
|
- assert len(lst) == 2
|
|
|
- assert {"__id": "MODEL_A/abc", "__type": "MODEL_A/A", "name": "1"} in lst
|
|
|
- assert {"__id": "MODEL_A/def", "__type": "MODEL_A/A", "name": "2"} in lst
|
|
|
+ assert len(lst) == 6
|
|
|
+ assert {"__id": "MODEL_A/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
|
|
|
+ assert {"__id": "MODEL_A/A", "__type": "Class", "name": "A", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
|
|
|
+ assert {"__id": "MODEL_A/A_name", "__type": "AttributeLink", "__source": "MODEL_A/A", "__target": "MODEL_A/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
|
|
|
+ assert {"__id": "MODEL_B/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
|
|
|
+ assert {"__id": "MODEL_B/B", "__type": "Class", "name": "B", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
|
|
|
+ assert {"__id": "MODEL_B/B_name", "__type": "AttributeLink", "__source": "MODEL_B/B", "__target": "MODEL_B/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
|
|
|
|
|
|
- # Make some changes to MODEL_A and make a MODEL_B
|
|
|
- delete_element(model, "MODEL_A/abc")
|
|
|
+ # Do minor merge operation
|
|
|
+ instantiate(model, "Association", edge=("MODEL_A/A", "MODEL_B/B"), ID="trace")
|
|
|
|
|
|
+ # Check again
|
|
|
lst = element_list_nice(model)
|
|
|
- assert len(lst) == 1
|
|
|
- assert {"__id": "MODEL_A/def", "__type": "MODEL_A/A", "name": "2"} in lst
|
|
|
-
|
|
|
- instantiate(model, "MODEL_B/B", ID="test_value")
|
|
|
- attr_assign(model, "test_value", "name", "5")
|
|
|
+ assert len(lst) == 7
|
|
|
+ assert {"__id": "MODEL_A/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
|
|
|
+ assert {"__id": "MODEL_A/A", "__type": "Class", "name": "A", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
|
|
|
+ assert {"__id": "MODEL_A/A_name", "__type": "AttributeLink", "__source": "MODEL_A/A", "__target": "MODEL_A/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
|
|
|
+ assert {"__id": "MODEL_B/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
|
|
|
+ assert {"__id": "MODEL_B/B", "__type": "Class", "name": "B", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
|
|
|
+ assert {"__id": "MODEL_B/B_name", "__type": "AttributeLink", "__source": "MODEL_B/B", "__target": "MODEL_B/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
|
|
|
+ assert {"__id": "trace", "__type": "Association", "__source": "MODEL_A/A", "__target": "MODEL_B/B", "name": None, "source_lower_cardinality": None, "source_upper_cardinality": None, "target_lower_cardinality": None, "target_upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}, "lower_cardinality": None, "upper_cardinality": None} in lst
|
|
|
|
|
|
+ transformation_add_AL({"MODEL_A": "users/user/test/A"}, {"MODEL_B": "users/user/test/B"}, "users/user/test/d", default_function, operation)
|
|
|
+
|
|
|
+ def operation(model):
|
|
|
+ # Check if both are present
|
|
|
lst = element_list_nice(model)
|
|
|
- assert len(lst) == 2
|
|
|
- assert {"__id": "MODEL_A/def", "__type": "MODEL_A/A", "name": "2"} in lst
|
|
|
- assert {"__id": "test_value", "__type": "MODEL_B/B", "name": "5"} in lst
|
|
|
+ assert len(lst) == 6
|
|
|
+ assert {"__id": "MODEL_A/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
|
|
|
+ assert {"__id": "MODEL_A/A", "__type": "Class", "name": "A", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
|
|
|
+ assert {"__id": "MODEL_A/A_name", "__type": "AttributeLink", "__source": "MODEL_A/A", "__target": "MODEL_A/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
|
|
|
+ assert {"__id": "MODEL_B/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
|
|
|
+ assert {"__id": "MODEL_B/B", "__type": "Class", "name": "B", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
|
|
|
+ assert {"__id": "MODEL_B/B_name", "__type": "AttributeLink", "__source": "MODEL_B/B", "__target": "MODEL_B/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
|
|
|
|
|
|
- # Do operation with a callback
|
|
|
- transformation_execute_MANUAL("users/user/test/c", {"MODEL_A": "users/user/test/a"}, {"MODEL_B": "users/user/test/a_2"}, operation)
|
|
|
+ transformation_add_AL({"MODEL_A": "users/user/test/A", "MODEL_B": "users/user/test/B"}, {"MODEL_B": "users/user/test/B"}, "users/user/test/e", default_function, operation)
|
|
|
|
|
|
- # Check that users/user/test/a was NOT modified, as it was not part of the output signature
|
|
|
- lst = element_list_nice("users/user/test/a")
|
|
|
- assert len(lst) == 2
|
|
|
- assert {"__id": "abc", "__type": "A", "name": "1"} in lst
|
|
|
- assert {"__id": "def", "__type": "A", "name": "2"} in lst
|
|
|
+ try:
|
|
|
+ transformation_add_AL({"MODEL_A": "users/user/test/A", "MODEL_B": "users/user/test/B"}, {"MODEL_B": "users/user/test/A"}, "users/user/test/f", default_function)
|
|
|
+ self.fail()
|
|
|
+ except SignatureMismatch:
|
|
|
+ pass
|
|
|
|
|
|
- # And check that new model is created
|
|
|
- lst = element_list_nice("users/user/test/a_2")
|
|
|
- assert len(lst) == 1
|
|
|
- assert {"__id": "test_value", "__type": "B", "name": "5"} in lst
|
|
|
+ # Add a transformation with empty signature
|
|
|
+ transformation_add_AL({}, {}, "users/user/test/g", default_function)
|
|
|
|
|
|
- # Do the transformation again, now overwriting an existing model (of the correct type)
|
|
|
- transformation_execute_MANUAL("users/user/test/c", {"MODEL_A": "users/user/test/a"}, {"MODEL_B": "users/user/test/b"}, operation)
|
|
|
+ # Add a transformation with empty signature and a callback
|
|
|
+ try:
|
|
|
+ def operation(model):
|
|
|
+ pass
|
|
|
+ transformation_add_AL({}, {}, "users/user/test/h", default_function, operation)
|
|
|
+ self.fail()
|
|
|
+ except CallbackOnEmptySignature:
|
|
|
+ assert "h" not in model_list("users/user/test")
|
|
|
|
|
|
- lst = element_list_nice("users/user/test/b")
|
|
|
- assert len(lst) == 1
|
|
|
- assert {"__id": "test_value", "__type": "B", "name": "5"} in lst
|
|
|
+ # Add transformation with unknown metamodel in signature (input)
|
|
|
+ try:
|
|
|
+ transformation_add_AL({"MODEL_A": "adbdsf"}, {"MODEL_B": "users/user/test/A"}, "users/user/test/i", default_function)
|
|
|
+ self.fail()
|
|
|
+ except UnknownModel:
|
|
|
+ assert "i" not in model_list("users/user/test")
|
|
|
+
|
|
|
+ # Add transformation with unknown metamodel in signature (output)
|
|
|
+ try:
|
|
|
+ transformation_add_AL({"MODEL_A": "users/user/test/A"}, {"MODEL_B": "adfad"}, "users/user/test/j", default_function)
|
|
|
+ self.fail()
|
|
|
+ except UnknownModel:
|
|
|
+ assert "j" not in model_list("users/user/test")
|
|
|
+
|
|
|
+ # Add transformation with unreadable metamodel in signature (input)
|
|
|
+ try:
|
|
|
+ transformation_add_AL({"MODEL_A": "administration/core"}, {"MODEL_B": "users/user/test/B"}, "users/user/test/k", default_function)
|
|
|
+ self.fail()
|
|
|
+ except ReadPermissionDenied:
|
|
|
+ assert "k" not in model_list("users/user/test")
|
|
|
+
|
|
|
+ # Add transformation with unreadable metamodel in signature (output)
|
|
|
+ try:
|
|
|
+ transformation_add_AL({"MODEL_A": "users/user/test/A"}, {"MODEL_B": "administration/core"}, "users/user/test/l", default_function)
|
|
|
+ self.fail()
|
|
|
+ except ReadPermissionDenied:
|
|
|
+ assert "l" not in model_list("users/user/test")
|
|
|
+
|
|
|
+ # Try to use a non-RAMifiable metamodel in input
|
|
|
+ try:
|
|
|
+ transformation_add_AL({"MODEL_A": "users/user/test/a"}, {}, "users/user/test/m", default_function)
|
|
|
+ self.fail()
|
|
|
+ except UnknownM3:
|
|
|
+ assert "m" not in model_list("users/user/test")
|
|
|
+
|
|
|
+ # Try to use a non-RAMifiable metamodel in output
|
|
|
+ try:
|
|
|
+ transformation_add_AL({}, {"MODEL_A": "users/user/test/a"}, "users/user/test/n", default_function)
|
|
|
+ self.fail()
|
|
|
+ except UnknownM3:
|
|
|
+ assert "n" not in model_list("users/user/test")
|
|
|
+
|
|
|
+ # Try to create activity that already exists
|
|
|
+ sig = transformation_signature("users/user/test/c")
|
|
|
+ try:
|
|
|
+ transformation_add_AL({}, {}, "users/user/test/c", default_function)
|
|
|
+ except ModelExists:
|
|
|
+ assert sig == transformation_signature("users/user/test/c")
|
|
|
|
|
|
"""
|
|
|
def test_op_model_render(self):
|