Bladeren bron

Added test (and fixed bugs) for model_overwrite

Yentl Van Tendeloo 8 jaren geleden
bovenliggende
commit
604c9884e3
4 gewijzigde bestanden met toevoegingen van 155 en 14 verwijderingen
  1. 0 1
      bootstrap/metamodels.alc
  2. 9 9
      bootstrap/modelling.alc
  3. 6 4
      core/core_algorithm.alc
  4. 140 0
      integration/test_mvc.py

+ 0 - 1
bootstrap/metamodels.alc

@@ -146,7 +146,6 @@ Element function constraint_call(model : Element, name : String):
 		return "Expected physical action value"!
 
 Element function initialize_SCD(location : String):
-	log("INITIALIZE SCD AT " + location)
 	if (import_node(location) != read_root()):
 		return import_node(location)!
 

+ 9 - 9
bootstrap/modelling.alc

@@ -522,24 +522,24 @@ Element function construct_model_raw(metamodel : Element):
 	while (True):
 		command = input()
 		if (command == "add_node"):
-			model_add_node(global_models[input()], input())
+			model_add_node(model, input())
 		elif (command == "add_value"):
-			model_add_value(global_models[input()], input(), input())
+			model_add_value(model, input(), input())
 		elif (command == "add_edge"):
-			model_add_edge(global_models[input()], input(), input(), input())
+			model_add_edge(model, input(), input(), input())
 		elif (command == "exit"):
 			return model!
 		elif (command == "instantiate_node"):
-			instantiate_node(global_models[input()], input(), input())
+			instantiate_node(model, input(), input())
 		elif (command == "instantiate_attribute"):
-			instantiate_attribute(global_models[input()], input(), input(), input())
+			instantiate_attribute(model, input(), input(), input())
 		elif (command == "instantiate_attribute_ref"):
-			instantiate_attribute_ref(global_models[input()], input(), input(), input())
+			instantiate_attribute_ref(model, input(), input(), input())
 		elif (command == "instantiate_attribute_code"):
-			instantiate_attribute_code(global_models[input()], input(), input(), construct_function())
+			instantiate_attribute_code(model, input(), input(), construct_function())
 		elif (command == "instantiate_link"):
-			instantiate_link(global_models[input()], input(), input(), input(), input())
+			instantiate_link(model, input(), input(), input(), input())
 		elif (command == "add_constraint"):
-			add_constraint(global_models[input()], input(), construct_function())
+			add_constraint(model, input(), construct_function())
 		else:
 			log("Modelling error: did not understand command " + command)

+ 6 - 4
core/core_algorithm.alc

@@ -270,13 +270,12 @@ Void function model_create(model : Element, name : String, user_id : String, typ
 
 	return!
 
-Void function model_overwrite(model : Element, name : String):
+Void function model_overwrite(model : Element, model_id : String):
 	String location
-	String model_id
 
 	location = "/models/" + cast_id2s(model)
 	export_node(location, model)
-	model_id = get_model_id(name)
+	log("Got model ID: " + model_id)
 
 	// Change location in meta-data
 	unset_attribute(core, model_id, "location")
@@ -296,6 +295,7 @@ Void function user_function_skip_init(user_id : String):
 	while (do_continue):
 		output("Ready for command...")
 		cmd = input()
+		log("EXECED " + cmd)
 		if (cmd == "help"):
 			output("Model operations")
 			output("    model_add                       -- Add a new model")
@@ -504,7 +504,7 @@ Void function user_function_skip_init(user_id : String):
 
 			output("Which model to overwrite?")
 			model_id = get_model_id(input())
-			if (model_id == ""):
+			if (model_id != ""):
 				if (allow_write(user_id, model_id)):
 					if (allow_read(user_id, set_pop(followAssociation(core, model_id, "instanceOf")))):
 						output("Waiting for model constructors...")
@@ -1086,6 +1086,8 @@ Void function user_function_skip_init(user_id : String):
 			// Exit by actually removing the user and decoupling it from all of its models
 			// Restarting with the same user name will NOT grant you access to anything of the previous user with that same name
 			do_continue = False
+		else:
+			output("Unknown command: " + cmd)
 
 	// Delete user from Core Formalism
 	model_delete_element(core, user_id)

+ 140 - 0
integration/test_mvc.py

@@ -91,3 +91,143 @@ class TestModelverseCore(unittest.TestCase):
                      "  200  root admin    53   core : CoreFormalism"]),
             ],
             mode))
+
+    def test_po_model_empty_modify(self):
+        self.model_empty_modify("PO")
+
+    def model_empty_modify(self, mode):
+        self.assertTrue(run_file(all_files,
+            [ "root",
+                "model_add",
+                "SimpleClassDiagrams",
+                "Empty",
+                "exit",
+                "model_list",
+                "model_list_full",
+                "model_modify",
+                "Empty",
+                "instantiate",
+                "Class",
+                "A",
+                "exit",
+                "model_list_full",
+            ],
+            [   "Desired username for admin user?",
+                "Welcome to the Model Management Interface v2.0!",
+                "Use the 'help' command for a list of possible commands",
+                "Ready for command...",
+                "Creating new model!",
+                "Model type?",
+                "Model name?",
+                "Waiting for model constructors...",
+                "Model upload success!",
+                "Ready for command...",
+                set(["  SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  CoreFormalism : SimpleClassDiagrams",
+                     "  Empty : SimpleClassDiagrams",
+                     "  core : CoreFormalism"]),
+                "Ready for command...",
+                set(["  221  root admin    673   SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  221  root admin    86   CoreFormalism : SimpleClassDiagrams",
+                     "  200  root nobody    0   Empty : SimpleClassDiagrams",
+                     "  200  root admin    53   core : CoreFormalism"]),
+                "Ready for command...",
+                "Which model do you want to modify?",
+                "Model loaded, ready for commands!",
+                "Use 'help' command for a list of possible commands",
+                "Please give your command.",
+                "Type to instantiate?",
+                "Name of new element?",
+                "Instantiation successful!",
+                "Please give your command.",
+                "Ready for command...",
+                set(["  221  root admin    673   SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  221  root admin    86   CoreFormalism : SimpleClassDiagrams",
+                     "  200  root nobody    1   Empty : SimpleClassDiagrams",
+                     "  200  root admin    53   core : CoreFormalism"]),
+                "Ready for command...",
+            ],
+            mode))
+
+    def test_po_model_overwrite(self):
+        self.model_overwrite("PO")
+
+    def model_overwrite(self, mode):
+        self.assertTrue(run_file(all_files,
+            [ "root",
+                "model_add",
+                "SimpleClassDiagrams",
+                "Empty",
+                "exit",
+                "model_list_full",
+                "model_modify",
+                "Empty",
+                "instantiate",
+                "Class",
+                "A",
+                "exit",
+                "model_list_full",
+                "model_overwrite",
+                "Empty",
+                "instantiate_node",
+                "Class",
+                "B",
+                "instantiate_node",
+                "Class",
+                "C",
+                "exit",
+                "model_list_full",
+                "model_modify",
+                "Empty",
+                "list",
+                "exit",
+            ],
+            [   "Desired username for admin user?",
+                "Welcome to the Model Management Interface v2.0!",
+                "Use the 'help' command for a list of possible commands",
+                "Ready for command...",
+                "Creating new model!",
+                "Model type?",
+                "Model name?",
+                "Waiting for model constructors...",
+                "Model upload success!",
+                "Ready for command...",
+                set(["  221  root admin    673   SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  221  root admin    86   CoreFormalism : SimpleClassDiagrams",
+                     "  200  root nobody    0   Empty : SimpleClassDiagrams",
+                     "  200  root admin    53   core : CoreFormalism"]),
+                "Ready for command...",
+                "Which model do you want to modify?",
+                "Model loaded, ready for commands!",
+                "Use 'help' command for a list of possible commands",
+                "Please give your command.",
+                "Type to instantiate?",
+                "Name of new element?",
+                "Instantiation successful!",
+                "Please give your command.",
+                "Ready for command...",
+                set(["  221  root admin    673   SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  221  root admin    86   CoreFormalism : SimpleClassDiagrams",
+                     "  200  root nobody    1   Empty : SimpleClassDiagrams",
+                     "  200  root admin    53   core : CoreFormalism"]),
+                "Ready for command...",
+                "Which model to overwrite?",
+                "Waiting for model constructors...",
+                "Model overwrite success!",
+                "Ready for command...",
+                set(["  221  root admin    673   SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  221  root admin    86   CoreFormalism : SimpleClassDiagrams",
+                     "  200  root nobody    2   Empty : SimpleClassDiagrams",
+                     "  200  root admin    53   core : CoreFormalism"]),
+                "Ready for command...",
+                "Which model do you want to modify?",
+                "Model loaded, ready for commands!",
+                "Use 'help' command for a list of possible commands",
+                "Please give your command.",
+                "List of all elements:",
+                set(["  B : Class",
+                     "  C : Class"]),
+                "Please give your command.",
+                "Ready for command...",
+            ],
+            mode))