Browse Source

Work on building rules.

Bentley James Oakes 7 years ago
parent
commit
4814fb25d6
3 changed files with 232 additions and 98 deletions
  1. 35 17
      tests/05_creating_dsl.js
  2. 172 77
      tests/06_transformation_test.js
  3. 25 4
      tests/model_building_utils.js

+ 35 - 17
tests/05_creating_dsl.js

@@ -63,12 +63,17 @@ function get_all_attrs2() {
         "      \"name\": \"name\",\n" +
         "      \"type\": \"string\",\n" +
         "      \"default\": \"test\"\n" +
-        "   },\n" +
+        "   }" +
+        "]";
+}
+
+function get_all_attrs3() {
+    return "[\n" +
         "   {\n" +
-        "      \"name\": \"\",\n" +
-        "      \"type\": \"\",\n" +
-        "      \"default\": \"\"\n" +
-        "   }\n" +
+        "      \"name\": \"test\",\n" +
+        "      \"type\": \"string\",\n" +
+        "      \"default\": \"hello\"\n" +
+        "   }" +
         "]";
 }
 
@@ -156,9 +161,9 @@ module.exports = {
         }
 
         // SET ATTRIBUTES
-        let class_div = model_building_utils.get_class_div(0);
+        //TODO: Use modelbuildingutils.set_attribs
+        let class_div = model_building_utils.get_class_div(8);
         let attrib_field = "#tr_attributes > td:nth-child(2) > textarea";
-
         client.moveToElement(class_div, 10, 10)
             .mouseButtonClick('middle')
             .waitForElementPresent("#dialog_btn", 1000, "Editing menu opens")
@@ -168,26 +173,38 @@ module.exports = {
             .waitForElementNotPresent("#dialog_btn", 1000, "Editing menu closes")
             .moveToElement(canvas, 0, 100)
             .mouseButtonClick('left')
-            .pause(1000)
+            .pause(500)
+        ;
+
+        let class_div3 = model_building_utils.get_class_div(0);
+        client.moveToElement(class_div3, 10, 10)
+            .mouseButtonClick('middle')
+            .waitForElementPresent("#dialog_btn", 1000, "Editing menu opens")
+            .clearValue(attrib_field)
+            .setValue(attrib_field, get_all_attrs3())
+            .click("#dialog_btn")
+            .waitForElementNotPresent("#dialog_btn", 1000, "Editing menu closes")
+            .moveToElement(canvas, 0, 100)
+            .mouseButtonClick('left')
+            .pause(500)
         ;
 
 
         let abstract_class = 4;
         let class_div2 = model_building_utils.get_class_div(abstract_class);
-        let attrib_field2 = "#tr_attributes > td:nth-child(2) > textarea";
         let checkbox = "#tr_abstract > td:nth-child(2) > input[type=\"checkbox\"]";
         model_building_utils.move_to_element_ratio(client, class_div2, 50, 50);
         client.mouseButtonClick('middle')
             .waitForElementPresent("#dialog_btn", 1000, "Editing menu opens")
-            .clearValue(attrib_field2)
-            .setValue(attrib_field2, get_all_attrs2())
+            .clearValue(attrib_field)
+            .setValue(attrib_field, get_all_attrs2())
             .moveToElement(checkbox, 0, 0)
             .mouseButtonClick('left')
             .click("#dialog_btn")
             .waitForElementNotPresent("#dialog_btn", 1000, "Editing menu closes")
             .moveToElement(canvas, 0, 100)
             .mouseButtonClick('left')
-            .pause(1000)
+            .pause(500)
         ;
 
         //CREATE INHERITANCE
@@ -622,13 +639,13 @@ module.exports = {
                 model_building_utils.move_to_element_ratio(client, from_class_div, 20, 50);
                 client.mouseButtonDown('right');
                 model_building_utils.move_to_element_ratio(client, to_class_div, 80, 50);
-                client.mouseButtonUp('right').pause(2000);
+                client.mouseButtonUp('right').pause(300);
             } else {
                 model_building_utils.move_to_element_ratio(client, to_class_div, 30, 50);
-                client.mouseButtonClick('left').pause(500);
+                client.mouseButtonClick('left').pause(300);
                 client.mouseButtonDown('left');
                 model_building_utils.move_to_element_ratio(client, from_class_div, 50, 120);
-                client.mouseButtonUp('left').pause(2000);
+                client.mouseButtonUp('left').pause(300);
             }
 
             num_elements++;
@@ -665,7 +682,7 @@ module.exports = {
 
         //SET ATTRIBUTES
 
-        let AClass = "#\\/autotest\\/autotest\\.defaultIcons\\/ClassAIcon\\/";
+        let IClass = "#\\/autotest\\/autotest\\.defaultIcons\\/ClassIIcon\\/";
 
         let AAttribs = {};
         AAttribs['int'] = 123;
@@ -679,7 +696,8 @@ module.exports = {
             attribs[new_key] = value;
         }
         //TODO: Set other attribs
-        model_building_utils.set_attribs(client, 0, attribs, AClass);
+        let div_suffix = " > text";
+        model_building_utils.set_attribs(client, 7, attribs, IClass, div_suffix, [1, 1]);
 
 
         // VERIFY MODEL

+ 172 - 77
tests/06_transformation_test.js

@@ -4,6 +4,11 @@ let test_utils = require('./test_utils');
 let model_building_utils = require('./model_building_utils');
 let user = "./users/testuser/";
 
+let rule_toolbars = [
+    "/Formalisms/__Transformations__/TransformationRule/TransformationRule.defaultIcons.metamodel",
+    "/autotest/autotest.defaultIcons.pattern.metamodel"
+];
+
 module.exports = {
 
     beforeEach: function (client, done) {
@@ -21,88 +26,178 @@ module.exports = {
         let model_name = "autotest.metamodel";
         model_building_utils.compile_model(client, "pattern", folder_name, model_name);
     },
-
-    'Create Transformation': function (client) {
-
-        let trans_formalism = "/Formalisms/__Transformations__/Transformation/MoTif.defaultIcons.metamodel";
-
-        test_utils.load_toolbar(client, [trans_formalism]);
-
-
-        //BUILD ELEMENTS
-
-        let x_coord = 300;
-        let y_coords = [200, 320, 440, 560, 680];
-
-        let btn_prefix = "#\\2f Formalisms\\2f __Transformations__\\2f Transformation\\2f MoTif\\2e defaultIcons\\2e metamodel\\2f ";
-        let type_prefix = "#\\2f Formalisms\\2f __Transformations__\\2f Transformation\\2f MoTif\\2e defaultIcons\\2f ";
-
-        let to_create = ["StartIcon", "FRuleIcon", "ARuleIcon", "EndSuccessIcon", "EndFailIcon"];
+    //
+    // 'Create Transformation': function (client) {
+    //
+    //     let trans_formalism = "/Formalisms/__Transformations__/Transformation/MoTif.defaultIcons.metamodel";
+    //
+    //     test_utils.load_toolbar(client, [trans_formalism]);
+    //
+    //
+    //     //BUILD ELEMENTS
+    //
+    //     let x_coord = 300;
+    //     let y_coords = [200, 320, 440, 560, 680];
+    //
+    //     let btn_prefix = "#\\2f Formalisms\\2f __Transformations__\\2f Transformation\\2f MoTif\\2e defaultIcons\\2e metamodel\\2f ";
+    //     let type_prefix = "#\\2f Formalisms\\2f __Transformations__\\2f Transformation\\2f MoTif\\2e defaultIcons\\2f ";
+    //
+    //     let to_create = ["StartIcon", "FRuleIcon", "ARuleIcon", "EndSuccessIcon", "EndFailIcon"];
+    //
+    //     let ele_map = {};
+    //     let num_elements = 0;
+    //     for (let ele of to_create) {
+    //         client.waitForElementPresent(btn_prefix + ele, 2000, "Button present: " + btn_prefix + ele);
+    //         client.click(btn_prefix + ele);
+    //
+    //         let built_div = model_building_utils.create_class(client,
+    //             x_coord, y_coords[num_elements], num_elements, type_prefix + ele + "\\2f ");
+    //
+    //         ele_map[ele] = built_div;
+    //
+    //         if (ele.includes("Rule")) {
+    //             let rule_name = num_elements + "_" + ele.replace("Icon", "");
+    //             let name_field = "#tr_name > td:nth-child(2) > textarea:nth-child(1)";
+    //             let rule_field = "#tr_rule > td:nth-child(2) > textarea:nth-child(1)";
+    //             let rule_prefix = "/autotest/R_";
+    //
+    //
+    //             let attribs = {};
+    //             attribs[name_field] = rule_name;
+    //             attribs[rule_field] = rule_prefix + rule_name + ".model";
+    //             model_building_utils.set_attribs(client, num_elements, attribs, type_prefix + ele + "\\2f ");
+    //         }
+    //         num_elements++;
+    //     }
+    //
+    //     let assocs = [
+    //         [0, 1, ""],
+    //         [1, 2, "success"],
+    //         [2, 3, "success"],
+    //         [1, 4, "fail"],
+    //         [2, 4, "fail"]
+    //     ];
+    //
+    //
+    //     for (let assoc of assocs) {
+    //
+    //         let start_ele = to_create[assoc[0]];
+    //         let end_ele = to_create[assoc[1]];
+    //
+    //         let start = ele_map[start_ele];
+    //         let end = ele_map[end_ele];
+    //
+    //         //TODO: Have path come from check/x mark
+    //
+    //         let relation_div = "";
+    //         if (assoc[2] == "success") {
+    //             relation_div = "#choice_\\2f Formalisms\\2f __Transformations__\\2f Transformation\\2f MoTif\\2e defaultIcons\\2f success";
+    //             //start += " > path:nth-child(3)";
+    //         } else if (assoc[2] == "fail") {
+    //             relation_div = "#choice_\\2f Formalisms\\2f __Transformations__\\2f Transformation\\2f MoTif\\2e defaultIcons\\2f fail";
+    //             //start += " > path:nth-child(5)";
+    //         }
+    //
+    //         let offset = 5 * (assoc[0] + assoc[1]);
+    //         model_building_utils.create_assoc(client, start, end, relation_div, offset);
+    //     }
+    //
+    //
+    //     model_building_utils.save_model(client, "autotest", "T_autotest.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";
 
         let ele_map = {};
-        let num_elements = 0;
-        for (let ele of to_create) {
-            client.waitForElementPresent(btn_prefix + ele, 2000, "Button present: " + btn_prefix + ele);
-            client.click(btn_prefix + ele);
-
-            let built_div = model_building_utils.create_class(client,
-                x_coord, y_coords[num_elements], num_elements, type_prefix + ele + "\\2f ");
-
-            ele_map[ele] = built_div;
-
-            if (ele.includes("Rule")) {
-                let rule_name = num_elements + "_" + ele.replace("Icon", "");
-                let name_field = "#tr_name > td:nth-child(2) > textarea:nth-child(1)";
-                let rule_field = "#tr_rule > td:nth-child(2) > textarea:nth-child(1)";
-                let rule_prefix = "/autotest/R_";
-
-
-                let attribs = {};
-                attribs[name_field] = rule_name;
-                attribs[rule_field] = rule_prefix + rule_name + ".model";
-                model_building_utils.set_attribs(client, num_elements, attribs, type_prefix + ele + "\\2f ");
-            }
-            num_elements++;
-        }
-
-        let assocs = [
-            [0, 1, ""],
-            [1, 2, "success"],
-            [2, 3, "success"],
-            [1, 4, "fail"],
-            [2, 4, "fail"]
-        ];
-
-
-        for (let assoc of assocs) {
-
-            let start_ele = to_create[assoc[0]];
-            let end_ele = to_create[assoc[1]];
-
-            let start = ele_map[start_ele];
-            let end = ele_map[end_ele];
-
-            //TODO: Have path come from check/x mark
-
-            let relation_div = "";
-            if (assoc[2] == "success") {
-                relation_div = "#choice_\\2f Formalisms\\2f __Transformations__\\2f Transformation\\2f MoTif\\2e defaultIcons\\2f success";
-                //start += " > path:nth-child(3)";
-            } else if (assoc[2] == "fail") {
-                relation_div = "#choice_\\2f Formalisms\\2f __Transformations__\\2f Transformation\\2f MoTif\\2e defaultIcons\\2f fail";
-                //start += " > path:nth-child(5)";
-            }
-
-            let offset = 5 * (assoc[0] + assoc[1]);
-            model_building_utils.create_assoc(client, start, end, relation_div, offset);
-        }
-
-
-        model_building_utils.save_model(client, "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);
+
+         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 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 ";
+
+        //BUILD INSIDE LHS
+        client.waitForElementPresent(a_btn, 2000, "A button").click(a_btn);
+        ele_map["A_lhs_1"] = model_building_utils.create_class(client, 50, 200, 2, a_div);
+        ele_map["A_lhs_2"] = model_building_utils.create_class(client, 50, 400, 3, a_div);
+
+        model_building_utils.move_element(client, ele_map["A_lhs_1"] + " > text:nth-child(1)", ele_map["LHS"], [50, 50], [50, 20]);
+        model_building_utils.move_element(client, ele_map["A_lhs_2"] + " > text:nth-child(1)", ele_map["LHS"], [50, 50], [50, 70]);
+
+        // //BUILD INSIDE RHS
+        // ele_map["I_rhs_1"] = model_building_utils.create_class(client, 50, 200, 4, i_div);
+        // ele_map["I_rhs_2"] = model_building_utils.create_class(client, 50, 400, 5, i_div);
+        //
+        // model_building_utils.move_element(client, ele_map["I_rhs_1"] + " > text:nth-child(1)", ele_map["RHS"], [50, 50], [50, 20]);
+        // model_building_utils.move_element(client, ele_map["I_rhs_2"] + " > text:nth-child(1)", ele_map["RHS"], [50, 50], [50, 70]);
+        //
+        // //BUILD ASSOCS
+        // client.pause(300);
+        // model_building_utils.create_assoc(client,
+        //     ele_map["I_lhs_1"]  + " > text:nth-child(1)", ele_map["I_lhs_2"]  + " > text:nth-child(1)", "", 0);
+        //
+        // client.pause(300);
+        // model_building_utils.create_assoc(client,
+        //     ele_map["I_rhs_1"]  + " > text:nth-child(1)", ele_map["I_rhs_2"]  + " > text:nth-child(1)", "", 0);
+
+
+        model_building_utils.save_model(client, "autotest", "R_2_ARule.model");
     },
 
-
     after: function (client) {
         client.end();
     },

+ 25 - 4
tests/model_building_utils.js

@@ -51,6 +51,8 @@ function create_classes(client, x_coords, y_coords, curr_num_elements, element_t
 
 function create_assoc(client, start_div, end_div, relation_div, offset) {
 
+    this.click_off(client);
+
     this.move_to_element_ratio(client, start_div, 50 + offset, 50 + offset);
     client.mouseButtonDown('right');
     this.move_to_element_ratio(client, end_div, 50 + offset, 50 + offset);
@@ -70,7 +72,17 @@ function create_assoc(client, start_div, end_div, relation_div, offset) {
 
 }
 
-function set_attribs(client, num, attrs, element_type) {
+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]);
+    client.mouseButtonClick('left').pause(300);
+    client.mouseButtonDown('left');
+    this.move_to_element_ratio(client, to_div, to_offset[0], to_offset[1]);
+    client.mouseButtonUp('left').pause(300);
+}
+
+function set_attribs(client, num, attrs, element_type, div_suffix, offset) {
 
     let element_div = "";
     if (element_type != undefined) {
@@ -79,10 +91,18 @@ function set_attribs(client, num, attrs, element_type) {
         element_div = this.get_class_div(num);
     }
 
+    if (div_suffix != undefined){
+        element_div += div_suffix;
+    }
+
     this.click_off(client);
 
+    if (offset == undefined){
+        offset = [50, 50];
+    }
+
     client.waitForElementPresent(element_div, 1000, "Find element for attrib set: " + element_div);
-    this.move_to_element_ratio(client, element_div, 50, 50);
+    this.move_to_element_ratio(client, element_div, offset[0], offset[1]);
     client.mouseButtonClick('middle')
         .waitForElementPresent("#dialog_btn", 1000, "Editing menu opens");
 
@@ -261,7 +281,7 @@ function scroll_geometry_element(client, element, scrollAmount, scrollTimes) {
         }
     }, [element, scrollAmount, scrollTimes], null);
 
-    client.pause(1000);
+    client.pause(300);
 }
 
 
@@ -281,5 +301,6 @@ module.exports = {
     save_model,
     load_model,
     compile_model,
-    scroll_geometry_element
+    scroll_geometry_element,
+    move_element
 };