Bläddra i källkod

Add test for alter_context

Yentl Van Tendeloo 7 år sedan
förälder
incheckning
376913a7ba

+ 42 - 39
bootstrap/core_algorithm.alc

@@ -1160,7 +1160,7 @@ String function cmd_model_move(source : String, target : String):
 		else:
 			return "Write permission denied to: " + source!
 	else:
-		return "Location not found: " + source!
+		return "Model not found: " + source!
 
 String function cmd_model_add(type : String, name : String, code : String):
 	// Model addition operation, which uses model upload commands of the compiler
@@ -1199,7 +1199,7 @@ String function cmd_model_add(type : String, name : String, code : String):
 		else:
 			return "Read permission denied to: " + type!
 	else:
-		return "Location not found: " + type!
+		return "Model not found: " + type!
 
 String function cmd_process_execute(process : String, mapping : Element):
 	// Execute a process model until it reaches termination
@@ -1218,7 +1218,7 @@ String function cmd_process_execute(process : String, mapping : Element):
 		else:
 			return "Execute permission denied to: " + process!
 	else:
-		return "Location not found: " + process!
+		return "Model not found: " + process!
 
 String function cmd_process_signature(process : String):
 	// Execute a process model until it reaches termination
@@ -1247,7 +1247,7 @@ String function cmd_process_signature(process : String):
 		else:
 			return "Execute permission denied to model: " + process!
 	else:
-		return "Location not found: " + process!
+		return "Model not found: " + process!
 
 String function cmd_transformation_between(source_dict : String, target_dict : String):
 	Element result
@@ -1278,7 +1278,7 @@ String function cmd_transformation_between(source_dict : String, target_dict : S
 					// Correct tag, so make transformation a possibility
 					set_add(subresult, readAssociationSource(core, link))
 		else:
-			return "Location not found: " + mm!
+			return "Model not found: " + mm!
 
 		// Got a set of subresults now, which we use to find the overlap
 		result = set_overlap(result, subresult)
@@ -1299,7 +1299,7 @@ String function cmd_transformation_between(source_dict : String, target_dict : S
 					// Correct tag, so make transformation a possibility
 					set_add(subresult, readAssociationSource(core, link))
 		else:
-			return "Location not found: " + mm!
+			return "Model not found: " + mm!
 
 		// Got a set of subresults now, which we use to find the overlap
 		result = set_overlap(result, subresult)
@@ -1433,11 +1433,11 @@ String function cmd_model_render(model_name : String, mapper_name : String, rend
 				else:
 					return "Execute permission denied to: " + mapper_name!
 			else:
-				return "Location not found: " + mapper_name!
+				return "Model not found: " + mapper_name!
 		else:
 			return "Read permission denied to: " + model_name!
 	else:
-		return "Location not found: " + model_name!
+		return "Model not found: " + model_name!
 
 Boolean function do_spawn_modify(model_name : String, write : Boolean):
 	output("Please edit this model before sending next input: " + model_name)
@@ -1566,7 +1566,7 @@ String function cmd_transformation_execute(transformation_name : String, source_
 						else:
 							return "Read permission denied to: " + source_model_name!
 					else:
-						return "Location not found: " + source_model_name!
+						return "Model not found: " + source_model_name!
 
 				targets = allOutgoingAssociationInstances(core, transformation_id, "transformOutput")
 				outputs = dict_create()
@@ -1580,7 +1580,7 @@ String function cmd_transformation_execute(transformation_name : String, source_
 						if (get_entry_id(target_model_name) == ""):
 							// Doesn't exist yet, so we can easily create
 							if (get_entry_id(get_foldername(target_model_name)) == ""):
-								return "Location not found: " + get_foldername(target_model_name)!
+								return "Model not found: " + get_foldername(target_model_name)!
 							else:
 								if (allow_write(current_user_id, get_entry_id(get_foldername(target_model_name)))):
 									dict_add(output_map, assoc_name, full_name(readAssociationDestination(core, target)))
@@ -1604,7 +1604,7 @@ String function cmd_transformation_execute(transformation_name : String, source_
 		else:
 			return "Execute permission denied to: " + transformation_name!
 	else:
-		return "Location not found: " + transformation_name!
+		return "Model not found: " + transformation_name!
 
 String function cmd_verify(model_name : String, metamodel_name : String):
 	// Check whether a model conforms to its specification (with the selected type mapping)
@@ -1626,11 +1626,11 @@ String function cmd_verify(model_name : String, metamodel_name : String):
 				else:
 					return "Read permission denied to: " + metamodel_name!
 			else:
-				return "Location not found: " + metamodel_name!
+				return "Model not found: " + metamodel_name!
 		else:
 			return "Read permission denied to: " + model_name!
 	else:
-		return "Location not found: " + model_name!
+		return "Model not found: " + model_name!
 
 String function cmd_model_overwrite(model_name : String, metamodel_name : String):
 	// Overwrites an existing model without changing any metadata
@@ -1661,7 +1661,7 @@ String function cmd_model_overwrite(model_name : String, metamodel_name : String
 		else:
 			return "Write permission denied to: " + model_name!
 	else:
-		return "Location not found: " + model_name!
+		return "Model not found: " + model_name!
 
 String function cmd_model_modify(model_name : String, metamodel_name : String):
 	// Model modify operation, which uses the mini_modify.alc operations, though with extensions for access control
@@ -1672,23 +1672,26 @@ String function cmd_model_modify(model_name : String, metamodel_name : String):
 
 	if (model_id != ""):
 		if (allow_read(current_user_id, model_id)):
-			type_id = anAssociationDestination(core, model_id, "instanceOf")
-			if (allow_read(current_user_id, type_id)):
-				Element new_model
-				new_model = get_full_model(model_id, get_entry_id(metamodel_name))
-				if (element_eq(new_model, read_root())):
-					return "Conformance hierarchy unknown for: " + model_name!
-				modify(new_model, allow_write(current_user_id, model_id))
-				if (allow_write(current_user_id, model_id)):
-					// Overwrite the modified model
-					model_overwrite(new_model, model_id, get_entry_id(metamodel_name))
-				return "Success"!
+			type_id = get_entry_id(metamodel_name)
+			if (type_id != ""):
+				if (allow_read(current_user_id, type_id)):
+					Element new_model
+					new_model = get_full_model(model_id, type_id)
+					if (element_eq(new_model, read_root())):
+						return "Conformance hierarchy unknown for: " + model_name!
+					modify(new_model, allow_write(current_user_id, model_id))
+					if (allow_write(current_user_id, model_id)):
+						// Overwrite the modified model
+						model_overwrite(new_model, model_id, type_id)
+					return "Success"!
+				else:
+					return "Read permission denied to: " + full_name(type_id)!
 			else:
-				return string_join("Read permission denied to: ", full_name(type_id))!
+				return "Model not found: " + metamodel_name!
 		else:
 			return "Read permission denied to: " + model_name!
 	else:
-		return "Location not found: " + model_name!
+		return "Model not found: " + model_name!
 
 Void function model_delete(model_id : String):
 	if (read_type(core, model_id) == "Folder"):
@@ -1717,7 +1720,7 @@ String function cmd_model_delete(model_name : String):
 		else:
 			return "Write permission denied to: " + model_name!
 	else:
-		return "Location not found: " + model_name!
+		return "Model not found: " + model_name!
 
 String function cmd_model_list(location : String):
 	// List all models
@@ -1739,7 +1742,7 @@ String function cmd_model_list(location : String):
 		else:
 			return "Read permission denied to: " + location!
 	else:
-		return "Location not found: " + location!
+		return "Model not found: " + location!
 
 String function cmd_model_list_full(location : String):
 	// List all models with full info
@@ -1770,7 +1773,7 @@ String function cmd_model_list_full(location : String):
 		else:
 			return "Read permission denied to: " + location!
 	else:
-		return "Location not found: " + location!
+		return "Model not found: " + location!
 
 String function cmd_transformation_add_MANUAL(source_models : Element, target_models : Element, operation_name : String):
 	return transformation_add(source_models, target_models, operation_name, "manual")!
@@ -1826,7 +1829,7 @@ String function transformation_add(source_models : Element, target_models : Elem
 			else:
 				return "Read permission denied to: " + name!
 		else:
-			return "Location not found: " + name!
+			return "Model not found: " + name!
 
 	keys = dict_keys(target_models)
 	while (set_len(keys) > 0):
@@ -1852,7 +1855,7 @@ String function transformation_add(source_models : Element, target_models : Elem
 			else:
 				return "Read permission denied to: " + name!
 		else:
-			return "Location not found: " + name!
+			return "Model not found: " + name!
 
 	if (get_entry_id(operation_name) == ""):
 		// Write out a merged metamodel containing all these models: this is the MM for the manual operation
@@ -1972,7 +1975,7 @@ String function cmd_transformation_add_MT(source_models : Element, target_models
 			else:
 				return "Read permission denied to: " + name!
 		else:
-			return "Location not found: " + name!
+			return "Model not found: " + name!
 
 	keys = dict_keys(target_models)
 	while (set_len(keys) > 0):
@@ -2002,7 +2005,7 @@ String function cmd_transformation_add_MT(source_models : Element, target_models
 			else:
 				return "Read permission denied to: " + name!
 		else:
-			return "Location not found: " + name!
+			return "Model not found: " + name!
 
 	merged_formalism = model_fuse(to_ramify)
 	model_create(merged_formalism, "merged/" + operation_name, get_entry_id("formalisms/SimpleClassDiagrams"), "Model")
@@ -2091,7 +2094,7 @@ String function cmd_permission_modify(model_name : String, permissions : String)
 		else:
 			return "User permission denied to: " + model_name!
 	else:
-		return "Location not found: " + model_name!
+		return "Model not found: " + model_name!
 
 String function cmd_permission_owner(model_name : String, new_user_name : String):
 	String model_id
@@ -2110,7 +2113,7 @@ String function cmd_permission_owner(model_name : String, new_user_name : String
 		else:
 			return "User permission denied to: " + model_name!
 	else:
-		return "Location not found: " + model_name!
+		return "Model not found: " + model_name!
 
 String function cmd_permission_group(model_name : String, new_group_name : String):
 	String model_id
@@ -2129,7 +2132,7 @@ String function cmd_permission_group(model_name : String, new_group_name : Strin
 		else:
 			return "User permission denied to: " + model_name!
 	else:
-		return "Location not found: " + model_name!
+		return "Model not found: " + model_name!
 
 String function cmd_group_create(group_name : String):
 	// Create a new group and become its owner
@@ -2374,7 +2377,7 @@ String function cmd_transformation_signature(transformation_name : String):
 		else:
 			return "Model is not an operation: " + transformation_name!
 	else:
-		return "Location not found: " + transformation_name!
+		return "Model not found: " + transformation_name!
 
 String function cmd_model_types(model_name : String):
 	if (get_entry_id(model_name) != ""):
@@ -2393,7 +2396,7 @@ String function cmd_model_types(model_name : String):
 
 		return result!
 	else:
-		return "Location not found: " + model_name!
+		return "Model not found: " + model_name!
 	
 String function cmd_folder_create(folder_name : String):
 	if (get_entry_id(folder_name) == ""):

+ 43 - 5
unit/test_all.py

@@ -341,7 +341,7 @@ class TestModelverse(unittest.TestCase):
         try:
             model_move("users/user/test/z", "users/user/test/y")
             self.fail()
-        except UnknownLocation:
+        except UnknownModel:
             pass
 
         # Test if we can move a model we can't write to (i.e., not allowed to remove it)
@@ -370,7 +370,7 @@ class TestModelverse(unittest.TestCase):
         try:
             model_delete("users/user/test/a")
             self.fail()
-        except UnknownLocation:
+        except UnknownModel:
             pass
 
         # Test delete of non-writable models
@@ -460,7 +460,7 @@ class TestModelverse(unittest.TestCase):
         try:
             all_instances("users/user/test/b", "Class")
             self.fail()
-        except UnknownLocation:
+        except UnknownModel:
             pass
 
         model_add("users/user/test/b", "users/user/test/a", """
@@ -594,6 +594,46 @@ class TestModelverse(unittest.TestCase):
         except FolderExists:
             pass
 
+    def test_op_alter_context(self):
+        # Create a model that we will use
+        model_add("users/user/test/a", "formalisms/ProcessModel", """
+            Start start {}
+            Finish finish {}
+            """)
+
+        # List elements using default context, that of creation
+        lst = element_list_nice("users/user/test/a")
+        assert len(lst) == 2
+        assert {"__id": "start", "__type": "Start"} in lst
+        assert {"__id": "finish", "__type": "Finish"} in lst
+
+        # List elements using bottom context
+        alter_context("users/user/test/a", "formalisms/Bottom")
+        lst = element_list_nice("users/user/test/a")
+        assert len(lst) == 2
+        assert {"__id": "start", "__type": "Node"} in lst
+        assert {"__id": "finish", "__type": "Node"} in lst
+
+        # Switch back to default context
+        alter_context("users/user/test/a", "formalisms/ProcessModel")
+        lst = element_list_nice("users/user/test/a")
+        assert len(lst) == 2
+        assert {"__id": "start", "__type": "Start"} in lst
+        assert {"__id": "finish", "__type": "Finish"} in lst
+
+        # Switch to a non-existing context
+        alter_context("users/user/test/a", "non-existing")
+        try:
+            element_list_nice("users/user/test/a")
+            self.fail()
+        except UnknownModel:
+            pass
+
+        # Set context for an unknown model
+        # Note that this will only register locally, without communicating with the Modelverse
+        # as such, errors are not noticed until the element is accessed!
+        alter_context("non-existing", "formalisms/SimpleClassDiagrams")
+
     """
     def test_op_model_render(self):
     def test_op_transformation_between(self):
@@ -616,8 +656,6 @@ class TestModelverse(unittest.TestCase):
     def test_op_group_list(self):
     def test_op_conformance_delete(self):
     def test_op_conformance_add(self):
-    def test_op_folder_create(self):
-    def test_op_alter_context(self):
     def test_op_element_list(self):
     def test_op_element_list_nice(self):
     def test_op_types(self):

+ 5 - 5
wrappers/classes/modelverse.xml

@@ -1454,9 +1454,9 @@
                         </raise>
                     </transition>
 
-                    <transition cond="self.expect_response_partial('Location not found: ', pop=False)" target="../wait_for_action/history">
+                    <transition cond="self.expect_response_partial('Model not found: ', pop=False)" target="../wait_for_action/history">
                         <raise event="exception">
-                            <parameter expr="'UnknownLocation'"/>
+                            <parameter expr="'UnknownModel'"/>
                             <parameter expr="self.split_response(self.responses.pop(0))[0]"/>
                         </raise>
                     </transition>
@@ -2052,10 +2052,10 @@
                         <transition cond="self.expect_response('Model loaded, ready for commands!', pop=True)" target="../../wait_for_action/modelling/recognized/manual"/>
                     </state>
 
-                    <transition cond="self.expect_response_partial('Location not found: ', pop=False)" target="../wait_for_action/megamodelling">
+                    <transition cond="self.expect_response_partial('Model not found: ', pop=False)" target="../wait_for_action/megamodelling">
                         <raise event="exception">
-                            <parameter expr="'UnknownLocation'"/>
-                            <parameter expr="'No such location: ' + self.responses.pop(0)"/>
+                            <parameter expr="'UnknownModel'"/>
+                            <parameter expr="'No such model: ' + self.responses.pop(0)"/>
                         </raise>
                         <script>
                             self.actions.pop(0)

+ 2 - 2
wrappers/modelverse.py

@@ -33,10 +33,10 @@ class CompilationError(ModelverseException):
 class UnknownAttribute(UnknownIdentifier):
     pass
 
-class UnknownLocation(UnknownIdentifier):
+class UnknownElement(UnknownIdentifier):
     pass
 
-class UnknownElement(UnknownIdentifier):
+class UnknownModel(UnknownIdentifier):
     pass
 
 class ConnectionError(ModelverseException):

+ 4 - 4
wrappers/modelverse_SCCD.py

@@ -2259,10 +2259,10 @@ class Modelverse(RuntimeClassBase):
         return self.expect_response_partial('Element not found: ', pop=False)
     
     def _initialized_behaviour_operations_16_exec(self, parameters):
-        self.raiseInternalEvent(Event("exception", None, ['UnknownLocation', self.split_response(self.responses.pop(0))[0]]))
+        self.raiseInternalEvent(Event("exception", None, ['UnknownModel', self.split_response(self.responses.pop(0))[0]]))
     
     def _initialized_behaviour_operations_16_guard(self, parameters):
-        return self.expect_response_partial('Location not found: ', pop=False)
+        return self.expect_response_partial('Model not found: ', pop=False)
     
     def _initialized_behaviour_operations_17_exec(self, parameters):
         self.raiseInternalEvent(Event("exception", None, ['UnknownMetamodellingHierarchy', 'Metamodelling hierarchy could not be resolved or automatically inferred: there is no typing relation between your specified model and metamodel (%s)' % self.responses.pop(0)]))
@@ -2434,11 +2434,11 @@ class Modelverse(RuntimeClassBase):
         return self.expect_action('exit_save')
     
     def _initialized_behaviour_going_manual_0_exec(self, parameters):
-        self.raiseInternalEvent(Event("exception", None, ['UnknownLocation', 'No such location: ' + self.responses.pop(0)]))
+        self.raiseInternalEvent(Event("exception", None, ['UnknownModel', 'No such model: ' + self.responses.pop(0)]))
         self.actions.pop(0)
     
     def _initialized_behaviour_going_manual_0_guard(self, parameters):
-        return self.expect_response_partial('Location not found: ', pop=False)
+        return self.expect_response_partial('Model not found: ', pop=False)
     
     def _initialized_behaviour_going_manual_1_exec(self, parameters):
         self.raiseInternalEvent(Event("exception", None, ['ReadPermissionDenied', 'No permission to read model ' + self.responses.pop(0)]))