Sfoglia il codice sorgente

Add running transformation and checking constraint.

Bentley James Oakes 7 anni fa
parent
commit
35d7e28faf
2 ha cambiato i file con 35 aggiunte e 105 eliminazioni
  1. 23 99
      tests/06_transformation_test.js
  2. 12 6
      tests/model_building_utils.js

+ 23 - 99
tests/06_transformation_test.js

@@ -20,7 +20,7 @@ module.exports = {
         test_utils.login(client);
     },
 
-    'Compile Pattern MM' : function (client) {
+    'Compile Pattern MM': function (client) {
 
         let folder_name = "autotest";
         let model_name = "autotest.metamodel";
@@ -121,7 +121,7 @@ module.exports = {
         let LHS_div = "#\\2f Formalisms\\2f __Transformations__\\2f TransformationRule\\2f TransformationRule\\2e defaultIcons\\2f LHSIcon\\2f ";
         ele_map["LHS"] = model_building_utils.create_class(client, 150, 200, 0, LHS_div);
 
-         client.waitForElementPresent(RHS_btn, 2000, "RHS button").click(RHS_btn);
+        client.waitForElementPresent(RHS_btn, 2000, "RHS button").click(RHS_btn);
         let RHS_div = "#\\2f Formalisms\\2f __Transformations__\\2f TransformationRule\\2f TransformationRule\\2e defaultIcons\\2f RHSIcon\\2f ";
         ele_map["RHS"] = model_building_utils.create_class(client, 650, 200, 1, RHS_div);
 
@@ -160,7 +160,7 @@ module.exports = {
         let LHS_div = "#\\2f Formalisms\\2f __Transformations__\\2f TransformationRule\\2f TransformationRule\\2e defaultIcons\\2f LHSIcon\\2f ";
         ele_map["LHS"] = model_building_utils.create_class(client, 150, 200, 0, LHS_div);
 
-         client.waitForElementPresent(RHS_btn, 2000, "RHS button").click(RHS_btn);
+        client.waitForElementPresent(RHS_btn, 2000, "RHS button").click(RHS_btn);
         let RHS_div = "#\\2f Formalisms\\2f __Transformations__\\2f TransformationRule\\2f TransformationRule\\2e defaultIcons\\2f RHSIcon\\2f ";
         ele_map["RHS"] = model_building_utils.create_class(client, 650, 200, 1, RHS_div);
 
@@ -197,11 +197,11 @@ module.exports = {
         //BUILD ASSOCS
         client.pause(300);
         model_building_utils.create_assoc(client,
-            ele_map["A_lhs"]  + " > text:nth-child(1)", ele_map["B_lhs"]  + " > text:nth-child(1)", "", 0);
+            ele_map["A_lhs"] + " > text:nth-child(1)", ele_map["B_lhs"] + " > text:nth-child(1)", "", 0);
 
         client.pause(300);
         model_building_utils.create_assoc(client,
-            ele_map["A_rhs"]  + " > text:nth-child(1)", ele_map["B_rhs"]  + " > text:nth-child(1)", "", 0);
+            ele_map["A_rhs"] + " > text:nth-child(1)", ele_map["B_rhs"] + " > text:nth-child(1)", "", 0);
 
         let test_field = "#tr_test > td:nth-child(2) > textarea";
         let attrs = {};
@@ -211,108 +211,32 @@ module.exports = {
         model_building_utils.save_model(client, "autotest", "R_2_ARule.model");
     },
 
-    'Create Rule 1': function (client) {
-
-        test_utils.load_toolbar(client, rule_toolbars);
-
-        // BUILD LHS AND RHS
-        let LHS_btn = "#\\2f Formalisms\\2f __Transformations__\\2f TransformationRule\\2f TransformationRule\\2e defaultIcons\\2e metamodel\\2f LHSIcon";
-        let RHS_btn = "#\\2f Formalisms\\2f __Transformations__\\2f TransformationRule\\2f TransformationRule\\2e defaultIcons\\2e metamodel\\2f RHSIcon";
-
-        let ele_map = {};
-
-        client.waitForElementPresent(LHS_btn, 2000, "LHS button").click(LHS_btn);
-        let LHS_div = "#\\2f Formalisms\\2f __Transformations__\\2f TransformationRule\\2f TransformationRule\\2e defaultIcons\\2f LHSIcon\\2f ";
-        ele_map["LHS"] = model_building_utils.create_class(client, 150, 200, 0, LHS_div);
-
-         client.waitForElementPresent(RHS_btn, 2000, "RHS button").click(RHS_btn);
-        let RHS_div = "#\\2f Formalisms\\2f __Transformations__\\2f TransformationRule\\2f TransformationRule\\2e defaultIcons\\2f RHSIcon\\2f ";
-        ele_map["RHS"] = model_building_utils.create_class(client, 650, 200, 1, RHS_div);
-
-        model_building_utils.click_off(client);
-
-        //BUILD ELEMENTS INSIDE
-        let c_btn = "#\\2f autotest\\2f autotest\\2e defaultIcons\\2e pattern\\2e metamodel\\2f __pClassCIcon";
-        let d_btn = "#\\2f autotest\\2f autotest\\2e defaultIcons\\2e pattern\\2e metamodel\\2f __pClassDIcon";
-
-        client.waitForElementPresent(c_btn, 2000, "C button").click(c_btn);
-        let c_div = "#\\2f autotest\\2f autotest\\2e defaultIcons\\2e pattern\\2f __pClassCIcon\\2f ";
-        ele_map["C"] = model_building_utils.create_class(client, 50, 200, 2, c_div);
-
-        client.waitForElementPresent(d_btn, 2000, "D button").click(d_btn);
-        let d_div = "#\\2f autotest\\2f autotest\\2e defaultIcons\\2e pattern\\2f __pClassDIcon\\2f ";
-        ele_map["D"] = model_building_utils.create_class(client, 50, 400, 3, d_div);
-
-        model_building_utils.move_element(client, ele_map["C"] + " > text:nth-child(1)", ele_map["LHS"], [50, 50], [50, 50]);
-        model_building_utils.move_element(client, ele_map["D"] + " > text:nth-child(1)", ele_map["RHS"], [50, 50], [50, 50]);
-
-
-        model_building_utils.save_model(client, "autotest", "R_1_FRule.model");
-    },
-
-    'Create Rule 2': function (client) {
-
-        test_utils.load_toolbar(client, rule_toolbars);
-
-        // BUILD LHS AND RHS
-        let LHS_btn = "#\\2f Formalisms\\2f __Transformations__\\2f TransformationRule\\2f TransformationRule\\2e defaultIcons\\2e metamodel\\2f LHSIcon";
-        let RHS_btn = "#\\2f Formalisms\\2f __Transformations__\\2f TransformationRule\\2f TransformationRule\\2e defaultIcons\\2e metamodel\\2f RHSIcon";
+    'Execute Transformation': function (client) {
+        model_building_utils.load_model(client, "autotest", "autotest_instance.model");
 
-        let ele_map = {};
+        model_building_utils.compile_model(client, "transform", "autotest", "T_autotest.model");
 
-        client.waitForElementPresent(LHS_btn, 2000, "LHS button").click(LHS_btn);
-        let LHS_div = "#\\2f Formalisms\\2f __Transformations__\\2f TransformationRule\\2f TransformationRule\\2e defaultIcons\\2f LHSIcon\\2f ";
-        ele_map["LHS"] = model_building_utils.create_class(client, 150, 200, 0, LHS_div);
+        let run_button = "#\\2f Toolbars\\2f TransformationController\\2f TransformationController\\2e buttons\\2e model\\2f play";
 
-         client.waitForElementPresent(RHS_btn, 2000, "RHS button").click(RHS_btn);
-        let RHS_div = "#\\2f Formalisms\\2f __Transformations__\\2f TransformationRule\\2f TransformationRule\\2e defaultIcons\\2f RHSIcon\\2f ";
-        ele_map["RHS"] = model_building_utils.create_class(client, 650, 200, 1, RHS_div);
+        client.click(run_button);
 
-        model_building_utils.click_off(client);
+        let created_D_1 = "#\\2f autotest\\2f autotest\\2e defaultIcons\\2f ClassDIcon\\2f 15\\2e instance";
+        let created_D_2 = "#\\2f autotest\\2f autotest\\2e defaultIcons\\2f ClassDIcon\\2f 15\\2e instance";
+        client.waitForElementPresent(created_D_1, 5000, "First D element created");
+        client.waitForElementPresent(created_D_2, 5000, "Second D element created");
 
-        //BUILD ELEMENTS INSIDE
-        let a_btn = "#\\2f autotest\\2f autotest\\2e defaultIcons\\2e pattern\\2e metamodel\\2f __pClassAIcon";
-        let a_div = "#\\2f autotest\\2f autotest\\2e defaultIcons\\2e pattern\\2f __pClassAIcon\\2f ";
+        //TODO:Test for A element's attribute
 
-        //BUILD A
-        client.waitForElementPresent(a_btn, 2000, "A button").click(a_btn);
-        ele_map["A_lhs"] = model_building_utils.create_class(client, 50, 200, 2, a_div);
-        ele_map["A_rhs"] = model_building_utils.create_class(client, 50, 400, 3, a_div);
-
-        model_building_utils.move_element(client, ele_map["A_lhs"] + " > text:nth-child(1)", ele_map["LHS"], [50, 50], [50, 20]);
-        model_building_utils.move_element(client, ele_map["A_rhs"] + " > text:nth-child(1)", ele_map["RHS"], [50, 50], [50, 20]);
+        //CHECK CONSTRAINT
+        let verify_btn = "#\\/Toolbars\\/MainMenu\\/MainMenu\\.buttons\\.model\\/validateM";
+        let dialog_btn = "#dialog_btn";
 
+        client.pause(500);
 
-        model_building_utils.click_off(client);
-
-        let b_btn = "#\\2f autotest\\2f autotest\\2e defaultIcons\\2e pattern\\2e metamodel\\2f __pClassBIcon";
-        let b_div = "#\\2f autotest\\2f autotest\\2e defaultIcons\\2e pattern\\2f __pClassBIcon\\2f ";
-
-        //BUILD B
-        client.waitForElementPresent(b_btn, 2000, "B button").click(b_btn);
-        ele_map["B_lhs"] = model_building_utils.create_class(client, 50, 200, 6, b_div);
-        ele_map["B_rhs"] = model_building_utils.create_class(client, 50, 400, 7, b_div);
-
-        model_building_utils.move_element(client, ele_map["B_lhs"] + " > text:nth-child(1)", ele_map["LHS"], [50, 50], [50, 70]);
-        model_building_utils.move_element(client, ele_map["B_rhs"] + " > text:nth-child(1)", ele_map["RHS"], [50, 50], [50, 70]);
-
-        model_building_utils.click_off(client);
-
-        //BUILD ASSOCS
-        client.pause(300);
-        model_building_utils.create_assoc(client,
-            ele_map["A_lhs"]  + " > text:nth-child(1)", ele_map["B_lhs"]  + " > text:nth-child(1)", "", 0);
-
-        client.pause(300);
-        model_building_utils.create_assoc(client,
-            ele_map["A_rhs"]  + " > text:nth-child(1)", ele_map["B_rhs"]  + " > text:nth-child(1)", "", 0);
-
-        let test_field = "#tr_test > td:nth-child(2) > textarea";
-        let attrs = {};
-        attrs[test_field] = "result = \"bonjour world!\"";
-        model_building_utils.set_attribs(client, 3, attrs, a_div, " > text:nth-child(1)", [5, 5]);
-
-        model_building_utils.save_model(client, "autotest", "R_2_ARule.model");
+        client.waitForElementPresent(verify_btn, 2000, "Find verify button")
+            .click(verify_btn).pause(500)
+            .waitForElementPresent(dialog_btn, 2000, "Constraint violation")
+            .click(dialog_btn);
     },
 
     after: function (client) {

+ 12 - 6
tests/model_building_utils.js

@@ -17,6 +17,10 @@ function get_assoc_div(num) {
     return get_element_div("AssociationLink", num) + " > text:nth-child(1)";
 }
 
+function fix_selector(name) {
+    return name.replace(".", "\\.");
+}
+
 function create_class(client, x, y, i, element_type) {
 
     let class_div = "";
@@ -72,7 +76,7 @@ function create_assoc(client, start_div, end_div, relation_div, offset) {
 
 }
 
-function move_element(client, from_div, to_div, from_offset, to_offset){
+function move_element(client, from_div, to_div, from_offset, to_offset) {
 
     this.click_off(client);
     this.move_to_element_ratio(client, from_div, from_offset[0], from_offset[1]);
@@ -91,13 +95,13 @@ function set_attribs(client, num, attrs, element_type, div_suffix, offset) {
         element_div = this.get_class_div(num);
     }
 
-    if (div_suffix != undefined){
+    if (div_suffix != undefined) {
         element_div += div_suffix;
     }
 
     this.click_off(client);
 
-    if (offset == undefined){
+    if (offset == undefined) {
         offset = [50, 50];
     }
 
@@ -162,7 +166,7 @@ function load_model(client, folder_name, model_name) {
     let folder_name_div = "#" + folder_name;
     client.click(folder_name_div);
 
-    client.click("#" + model_name)
+    client.click("#" + fix_selector(model_name))
         .pause(200)
         .click("#dialog_btn");
 
@@ -223,6 +227,8 @@ function compile_model(client, compile_type, folder_name, model_name) {
         button = "#\\2f Toolbars\\2f CompileMenu\\2f CompileMenu\\2e buttons\\2e model\\2f compileToCSMM";
     } else if (button_name == "pattern") {
         button = "#\\2f Toolbars\\2f CompileMenu\\2f CompileMenu\\2e buttons\\2e model\\2f compileToPatternMM";
+    } else if (button_name == "transform") {
+        button = "#\\2f Toolbars\\2f TransformationController\\2f TransformationController\\2e buttons\\2e model\\2f load";
     }
 
     client.waitForElementPresent(button, 1000, "Looking for " + button_name + " button")
@@ -241,12 +247,12 @@ function compile_model(client, compile_type, folder_name, model_name) {
     });
 
     let new_file_text = "#new_file";
-    let model_div = "#" + model_name.replace(".", "\\.");
+    let model_div = "#" + fix_selector(model_name);
     client.element('css selector', model_div, function (result) {
 
             if (result.status == -1) {
                 //don't create new file with pattern compilation
-                if (button_name == "pattern") {
+                if (button_name == "pattern" || button_name == "transform") {
                     client.assert.ok(false, "File found: " + model_name);
                 }