Browse Source

Fixed tests and patched broken transformation_add with empty signature

Yentl Van Tendeloo 7 years ago
parent
commit
7780de252c

+ 24 - 21
bootstrap/core_algorithm.alc

@@ -1064,29 +1064,32 @@ String function cmd_model_move(source : String, target : String):
 	source_id = get_entry_id(source)
 	if (source_id != ""):
 		if (allow_write(current_user_id, source_id)):
-			// Create folders on path to the target
-			if (element_neq(create_folders(current_user_id, get_foldername(target), False), read_root())):
-				if (allow_write(current_user_id, get_entry_id(get_foldername(target)))):
-					// Change location, first the name
-					instantiate_attribute(core, source_id, "name", target)
-
-					// Now the folder links
-					Element links
-					links = allIncomingAssociationInstances(core, source_id, "contains")
-					while (set_len(links) > 0):
-						model_delete_element(core, set_pop(links))
-					instantiate_link(core, "contains", "", get_entry_id(get_foldername(target)), source_id)
-
-					// Flush caches
-					dict_add(caches["models"], target, caches["models"][source])
-					dict_delete(caches["models"], source)
-
-					// Done
-					return "Success"!
+			if (get_entry_id(target) == ""):
+				// Create folders on path to the target
+				if (element_neq(create_folders(current_user_id, get_foldername(target), False), read_root())):
+					if (allow_write(current_user_id, get_entry_id(get_foldername(target)))):
+						// Change location, first the name
+						instantiate_attribute(core, source_id, "name", target)
+
+						// Now the folder links
+						Element links
+						links = allIncomingAssociationInstances(core, source_id, "contains")
+						while (set_len(links) > 0):
+							model_delete_element(core, set_pop(links))
+						instantiate_link(core, "contains", "", get_entry_id(get_foldername(target)), source_id)
+
+						// Flush caches
+						dict_add(caches["models"], target, caches["models"][source])
+						dict_delete(caches["models"], source)
+
+						// Done
+						return "Success"!
+					else:
+						return "Write permission denied to: " + target!
 				else:
 					return "Write permission denied to: " + target!
 			else:
-				return "Write permission denied to: " + target!
+				return "Location exists: " + target!
 		else:
 			return "Write permission denied to: " + source!
 	else:
@@ -1965,7 +1968,7 @@ String function transformation_add(source_models : Element, target_models : Elem
 			link = instantiate_link(core, "transformOutput", "", model_id, target[key])
 			instantiate_attribute(core, link, "name", key)
 			
-		return "Success"!
+	return "Success"!
 
 String function cmd_transformation_add_MT(source_models : Element, target_models : Element, operation_name : String):
 	// Add a model transformation model

+ 1 - 32
unit/test_all.py

@@ -398,13 +398,6 @@ class TestModelverse(unittest.TestCase):
         assert {'__id': "A", "__type": "Class", "abstract": None, "constraint": {"AL": ""}, "lower_cardinality": None, "upper_cardinality": None, "name": "A"} in lst
         assert {'__id': "B", "__type": "Class", "abstract": True, "constraint": {"AL": ""}, "lower_cardinality": None, "upper_cardinality": None, "name": "B"} in lst
 
-        try:
-            # Cannot upload model to occupied location
-            model_add("users/user/test/a", "formalisms/SimpleClassDiagrams")
-            self.fail()
-        except ModelExists:
-            assert model_list_full("users/user/test") == set([("a", "user", "nobody", "200"), ("b", "user", "nobody", "200")])
-
         try:
             # Cannot upload model to unwritable location at root
             model_add("z", "formalisms/SimpleClassDiagrams")
@@ -484,13 +477,12 @@ class TestModelverse(unittest.TestCase):
         assert model_move("users/user/test/b", "users/user/test/a") == None
         assert model_list_full("users/user/test") == set([("a", "user", "nobody", "222")])
 
-        # Test move if destination exists
         model_add("users/user/test/b", "formalisms/SimpleClassDiagrams")
         assert model_list_full("users/user/test") == set([("a", "user", "nobody", "222"), ("b", "user", "nobody", "200")])
         try:
             model_move("users/user/test/a", "users/user/test/b")
             self.fail()
-        except ModelExists:
+        except LocationExists:
             pass
         assert model_list_full("users/user/test") == set([("a", "user", "nobody", "222"), ("b", "user", "nobody", "200")])
 
@@ -4161,13 +4153,6 @@ class TestModelverse(unittest.TestCase):
         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_MANUAL({}, {}, "users/user/test/c")
-        except ModelExists:
-            assert sig == transformation_signature("users/user/test/c")
-
         # Source metamodel is folder
         try:
             transformation_add_MANUAL({"MODEL_A": "users"}, {"MODEL_B": "formalisms/SimpleClassDiagrams"}, "users/user/test/p")
@@ -4307,14 +4292,6 @@ class TestModelverse(unittest.TestCase):
         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)
-            self.fail()
-        except ModelExists:
-            assert sig == transformation_signature("users/user/test/c")
-
         # Compilation error
         try:
             transformation_add_AL({}, {}, "users/user/test/o", "adfadf")
@@ -4465,14 +4442,6 @@ class TestModelverse(unittest.TestCase):
         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_MT({"MODEL_A": "users/user/test/A"}, {}, "users/user/test/c", default_function)
-            self.fail()
-        except ModelExists:
-            assert sig == transformation_signature("users/user/test/c")
-
         # Compilation error
         try:
             transformation_add_MT({"MODEL_A": "users/user/test/A"}, {}, "users/user/test/o", "adfa")

+ 2 - 2
wrappers/classes/modelverse.xml

@@ -1497,9 +1497,9 @@
                         </raise>
                     </transition>
 
-                    <transition cond="self.expect_response_partial('Model exists: ', pop=False)" target="../wait_for_action/history">
+                    <transition cond="self.expect_response_partial('Location exists: ', pop=False)" target="../wait_for_action/history">
                         <raise event="exception">
-                            <parameter expr="'ModelExists'"/>
+                            <parameter expr="'LocationExists'"/>
                             <parameter expr="self.split_response(self.responses.pop(0))[0]"/>
                         </raise>
                     </transition>

+ 1 - 1
wrappers/modelverse.py

@@ -105,7 +105,7 @@ class AttributeExists(ExistsError):
 class ElementExists(ExistsError):
     pass
 
-class ModelExists(ExistsError):
+class LocationExists(ExistsError):
     pass
 
 class FolderExists(ExistsError):

+ 2 - 2
wrappers/modelverse_SCCD.py

@@ -2429,10 +2429,10 @@ class Modelverse(RuntimeClassBase):
         return self.expect_response_partial('User exists: ', pop=False)
     
     def _initialized_behaviour_operations_16_exec(self, parameters):
-        self.raiseInternalEvent(Event("exception", None, ['ModelExists', self.split_response(self.responses.pop(0))[0]]))
+        self.raiseInternalEvent(Event("exception", None, ['LocationExists', self.split_response(self.responses.pop(0))[0]]))
     
     def _initialized_behaviour_operations_16_guard(self, parameters):
-        return self.expect_response_partial('Model exists: ', pop=False)
+        return self.expect_response_partial('Location exists: ', pop=False)
     
     def _initialized_behaviour_operations_17_exec(self, parameters):
         self.raiseInternalEvent(Event("exception", None, ['GroupExists', self.split_response(self.responses.pop(0))[0]]))

+ 0 - 42
wrappers/test_SCCD.py

@@ -1,42 +0,0 @@
-import sys
-sys.path.append("wrappers")
-from modelverse import *
-from sccd.runtime.statecharts_core import Event
-
-init()
-login("admin", "admin")
-
-# Assume that we don't change the SCCD MM
-try:
-    model_add("formalisms/SCCD", "formalisms/SimpleClassDiagrams", open("models/SCCD.mvc", 'r').read())
-except ModelExists:
-    pass
-
-try:
-    model_add("formalisms/SCCD_Trace", "formalisms/SimpleClassDiagrams", open("models/SCCD_Trace.mvc", 'r').read())
-except ModelExists:
-    pass
-
-# Update the model of the traffic light
-if "my_SCCD" in [i[0] for i in model_list("models")]:
-    model_delete("models/my_SCCD")
-model_add("models/my_SCCD", "formalisms/SCCD", open("models/dynamic_trafficlight.mvc", 'r').read())
-
-# Add SCCD execution semantics
-transformation_add_AL({"SCCD": "formalisms/SCCD"}, {"trace": "formalisms/SCCD_Trace"}, "models/SCCD_execute", open("models/SCCD_execute.alc", 'r').read())
-
-import poll_print
-ctrl = poll_print.Controller(keep_running=False)
-
-thrd = threading.Thread(target=ctrl.start)
-thrd.daemon = True
-thrd.start()
-
-transformation_execute_AL("models/SCCD_execute", {"SCCD": "models/my_SCCD"}, {"trace": "models/my_trace"}, statechart=(ctrl, "inp", "outp"))
-
-import select
-while thrd.is_alive():
-    if select.select([sys.stdin], [], [], 0.1)[0]:
-        ctrl.addInput(Event("raw_inp", "user_inp", [sys.stdin.readline().strip()]))
-
-thrd.join()