|
@@ -4464,15 +4464,238 @@ class TestModelverse(unittest.TestCase):
|
|
|
thrd.daemon = True
|
|
|
transformation_add_AL({"MODEL_A": "users/user/test/A"}, {"MODEL_B": "users/user/test/B"}, "users/user/test/i", code_SC)
|
|
|
thrd.start()
|
|
|
- print("STart exec")
|
|
|
transformation_execute_AL("users/user/test/i", {"MODEL_A": "users/user/test/a"}, {"MODEL_B": "users/user/test/bb"}, statechart=(ctrl, "inp", "outp"))
|
|
|
- print("EXEC OK")
|
|
|
+ thrd.join()
|
|
|
+
|
|
|
+ def test_op_transformation_execute_MT(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 a {}")
|
|
|
+ model_add("users/user/test/b", "users/user/test/B", "B b {}")
|
|
|
+
|
|
|
+ default_code_empty = """
|
|
|
+ Composite a {
|
|
|
+ {Contains} Success success {}
|
|
|
+ }
|
|
|
+ Initial (a, success) {}
|
|
|
+ """
|
|
|
+ default_code_true = """
|
|
|
+ Composite a {
|
|
|
+ {Contains} Success success {}
|
|
|
+ {Contains} Atomic b {
|
|
|
+ LHS {
|
|
|
+ Pre_MODEL_A/A {
|
|
|
+ label = "0"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ RHS {
|
|
|
+ Post_MODEL_A/A {
|
|
|
+ label = "0"
|
|
|
+ value_name = $
|
|
|
+ String function value(model : Element, name : String, mapping : Element):
|
|
|
+ return "CHANGED"!
|
|
|
+ $
|
|
|
+ }
|
|
|
+ Post_MODEL_B/B {
|
|
|
+ label = "1"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Initial (a, b) {}
|
|
|
+ OnSuccess (b, success) {}
|
|
|
+ OnFailure (b, success) {}
|
|
|
+ """
|
|
|
+ default_code_false = """
|
|
|
+ Composite a {
|
|
|
+ {Contains} Failure failure {}
|
|
|
+ {Contains} Atomic b {
|
|
|
+ LHS {
|
|
|
+ Pre_MODEL_A/A {
|
|
|
+ label = "0"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ RHS {
|
|
|
+ Post_MODEL_A/A {
|
|
|
+ label = "0"
|
|
|
+ value_name = $
|
|
|
+ String function value(model : Element, name : String, mapping : Element):
|
|
|
+ return "CHANGED"!
|
|
|
+ $
|
|
|
+ }
|
|
|
+ Post_MODEL_B/B {
|
|
|
+ label = "1"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Initial (a, b) {}
|
|
|
+ OnSuccess (b, failure) {}
|
|
|
+ OnFailure (b, failure) {}
|
|
|
+ """
|
|
|
+
|
|
|
+ # Add some activity to execute
|
|
|
+ try:
|
|
|
+ transformation_add_MT({}, {}, "users/user/test/c", default_code_true)
|
|
|
+ self.fail()
|
|
|
+ except EmptySignature:
|
|
|
+ assert "c" not in model_list("users/user/test")
|
|
|
+
|
|
|
+ # Now do the same, but with a model
|
|
|
+ transformation_add_MT({"MODEL_A": "users/user/test/A"}, {"MODEL_B": "users/user/test/B"}, "users/user/test/d", default_code_true)
|
|
|
+
|
|
|
+ transformation_execute_MT("users/user/test/d", {"MODEL_A": "users/user/test/a"}, {"MODEL_B": "users/user/test/aa"})
|
|
|
+
|
|
|
+ lst = element_list_nice("users/user/test/aa")
|
|
|
+ assert len(lst) == 1
|
|
|
+ assert lst[0]["__type"] == "B"
|
|
|
+ assert lst[0]["name"] == None
|
|
|
+ assert lst[0]["__id"].startswith("__")
|
|
|
+
|
|
|
+ # Original input model remains unchanged, as it is not an output model
|
|
|
+ lst = element_list_nice("users/user/test/a")
|
|
|
+ assert len(lst) == 1
|
|
|
+ assert lst[0]["__type"] == "A"
|
|
|
+ assert lst[0]["name"] == None
|
|
|
+ assert lst[0]["__id"] == "a"
|
|
|
+
|
|
|
+ # Execute activity with non-existing model (input)
|
|
|
+ try:
|
|
|
+ transformation_execute_MT("users/user/test/d", {"MODEL_A": "dfadf"}, {"MODEL_B": "users/user/test/f"})
|
|
|
+ self.fail()
|
|
|
+ except UnknownModel:
|
|
|
+ assert "f" not in model_list("users/user/test")
|
|
|
+
|
|
|
+ # Execute non-existing activity
|
|
|
+ try:
|
|
|
+ transformation_execute_MT("adfadf", {}, {"MODEL_B": "users/user/test/abc"})
|
|
|
+ self.fail()
|
|
|
+ except UnknownModel:
|
|
|
+ assert "abc" not in model_list("users/user/test")
|
|
|
+
|
|
|
+ # Unbound source model
|
|
|
+ try:
|
|
|
+ transformation_execute_MT("users/user/test/d", {}, {"MODEL_B": "users/user/test/f"})
|
|
|
+ self.fail()
|
|
|
+ except SourceModelNotBound:
|
|
|
+ pass
|
|
|
+
|
|
|
+ # Unknown source key
|
|
|
+ try:
|
|
|
+ transformation_execute_MT("users/user/test/d", {"ABC": "users/user/test/a", "MODEL_A": "users/user/test/a"}, {"MODEL_B": "users/user/test/f"})
|
|
|
+ self.fail()
|
|
|
+ except SourceModelNotBound:
|
|
|
+ pass
|
|
|
+
|
|
|
+ # Unknown target key
|
|
|
+ try:
|
|
|
+ transformation_execute_MT("users/user/test/d", {"MODEL_A": "users/user/test/a"}, {"DEF": "users/user/test/b"})
|
|
|
+ self.fail()
|
|
|
+ except TargetModelNotBound:
|
|
|
+ pass
|
|
|
+
|
|
|
+ # Read permissions denied source
|
|
|
+ try:
|
|
|
+ transformation_execute_MT("users/user/test/d", {"MODEL_A": "administration/core"}, {"MODEL_B": "users/user/test/f"})
|
|
|
+ self.fail()
|
|
|
+ except ReadPermissionDenied:
|
|
|
+ pass
|
|
|
+
|
|
|
+ # Execute permissions denied activity
|
|
|
+ try:
|
|
|
+ transformation_execute_MT("administration/core", {"MODEL_A": "administration/core"}, {"MODEL_B": "users/user/test/f"})
|
|
|
+ self.fail()
|
|
|
+ except ExecutePermissionDenied:
|
|
|
+ pass
|
|
|
+
|
|
|
+ # Write permissions denied target (folder)
|
|
|
+ try:
|
|
|
+ transformation_execute_MT("users/user/test/d", {"MODEL_A": "users/user/test/a"}, {"MODEL_B": "administration/abc"})
|
|
|
+ self.fail()
|
|
|
+ except WritePermissionDenied:
|
|
|
+ pass
|
|
|
+
|
|
|
+ # Write permissions denied target (model)
|
|
|
+ try:
|
|
|
+ transformation_execute_MT("users/user/test/d", {"MODEL_A": "users/user/test/a"}, {"MODEL_B": "administration/core"})
|
|
|
+ self.fail()
|
|
|
+ except WritePermissionDenied:
|
|
|
+ pass
|
|
|
+
|
|
|
+ # Execute activity with non-conforming input models
|
|
|
+ try:
|
|
|
+ transformation_execute_MT("users/user/test/d", {"MODEL_A": "users/user/test/b"}, {"MODEL_B": "users/user/test/f"})
|
|
|
+ self.fail()
|
|
|
+ except TypeMismatch:
|
|
|
+ assert "f" not in model_list("users/user/test")
|
|
|
+
|
|
|
+ # Execute activity with non-conforming output models that already exist
|
|
|
+ try:
|
|
|
+ transformation_execute_MT("users/user/test/d", {"MODEL_A": "users/user/test/b"}, {"MODEL_B": "users/user/test/d"})
|
|
|
+ self.fail()
|
|
|
+ except TypeMismatch:
|
|
|
+ assert element_list_nice("users/user/test/d") > 0
|
|
|
+
|
|
|
+ # Execute activity with colliding models, which means that it is copied
|
|
|
+ transformation_add_MT({"MODEL_A": "users/user/test/A"}, {"MODEL_A": "users/user/test/A"}, "users/user/test/f", default_code_empty)
|
|
|
+ transformation_execute_MT("users/user/test/f", {"MODEL_A": "users/user/test/a"}, {"MODEL_A": "users/user/test/aaa"})
|
|
|
+ assert len(element_list_nice("users/user/test/a")) == len(element_list_nice("users/user/test/aaa"))
|
|
|
+
|
|
|
+ # Make sure that models are not written when returning False
|
|
|
+ transformation_add_MT({"MODEL_A": "users/user/test/A"}, {"MODEL_B": "users/user/test/B"}, "users/user/test/h", default_code_false)
|
|
|
+ transformation_execute_MT("users/user/test/h", {"MODEL_A": "users/user/test/a"}, {"MODEL_B": "users/user/test/bb"})
|
|
|
+ assert "bb" not in model_list("users/user/test")
|
|
|
+
|
|
|
+ # Try out SC communication: requires back and forth computation
|
|
|
+ code_SC = """
|
|
|
+ include "primitives.alh"
|
|
|
+ include "io.alh"
|
|
|
+
|
|
|
+ Composite a {
|
|
|
+ {Contains} Success success {}
|
|
|
+ {Contains} Atomic b {
|
|
|
+ LHS {}
|
|
|
+ RHS {
|
|
|
+ action = $
|
|
|
+ Void function act(model : Element, mapping : Element):
|
|
|
+ output("init")
|
|
|
+ log("Init OK")
|
|
|
+ output(cast_integer(input()) + cast_integer(input()))
|
|
|
+ log("Sent out value")
|
|
|
+ return!
|
|
|
+ $
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Initial (a, b) {}
|
|
|
+ OnSuccess (b, success) {}
|
|
|
+ OnFailure (b, success) {}
|
|
|
+ """
|
|
|
+ import exec_MT
|
|
|
+ ctrl = exec_MT.Controller(keep_running=False)
|
|
|
+ thrd = threading.Thread(target=ctrl.start)
|
|
|
+ thrd.daemon = True
|
|
|
+ transformation_add_MT({"MODEL_A": "users/user/test/A"}, {"MODEL_B": "users/user/test/B"}, "users/user/test/i", code_SC)
|
|
|
+ thrd.start()
|
|
|
+ transformation_execute_MT("users/user/test/i", {"MODEL_A": "users/user/test/a"}, {"MODEL_B": "users/user/test/bb"}, statechart=(ctrl, "inp", "outp"))
|
|
|
thrd.join()
|
|
|
|
|
|
"""
|
|
|
def test_op_model_render(self):
|
|
|
def test_op_transformation_execute_MT(self):
|
|
|
- def test_op_transformation_execute_AL(self):
|
|
|
def test_op_transformation_signature(self):
|
|
|
def test_op_process_signature(self):
|
|
|
"""
|