06_transformation_test.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. //NOTE: REQUIRES DSL FROM PREVIOUS TEST
  2. let test_utils = require('./test_utils');
  3. let model_building_utils = require('./model_building_utils');
  4. let user = "./users/testuser/";
  5. let rule_toolbars = [
  6. "/Formalisms/__Transformations__/TransformationRule/TransformationRule.defaultIcons.metamodel",
  7. "/autotest/autotest.defaultIcons.pattern.metamodel"
  8. ];
  9. module.exports = {
  10. beforeEach: function (client, done) {
  11. client.url('http://localhost:8124/atompm').pause(300).maximizeWindow(done);
  12. },
  13. 'Login': function (client) {
  14. test_utils.login(client);
  15. },
  16. 'Compile Pattern MM': function (client) {
  17. let folder_name = "autotest";
  18. let model_name = "autotest.metamodel";
  19. model_building_utils.compile_model(client, "pattern", folder_name, model_name);
  20. },
  21. 'Create Transformation': function (client) {
  22. let trans_formalism = "/Formalisms/__Transformations__/Transformation/MoTif.defaultIcons.metamodel";
  23. test_utils.load_toolbar(client, [trans_formalism]);
  24. //BUILD ELEMENTS
  25. let x_coord = 300;
  26. let y_coords = [200, 320, 440, 560, 680];
  27. let btn_prefix = "#\\2f Formalisms\\2f __Transformations__\\2f Transformation\\2f MoTif\\2e defaultIcons\\2e metamodel\\2f ";
  28. let type_prefix = "#\\2f Formalisms\\2f __Transformations__\\2f Transformation\\2f MoTif\\2e defaultIcons\\2f ";
  29. let to_create = ["StartIcon", "FRuleIcon", "ARuleIcon", "EndSuccessIcon", "EndFailIcon"];
  30. let ele_map = {};
  31. let num_elements = 0;
  32. for (let ele of to_create) {
  33. client.waitForElementPresent(btn_prefix + ele, 2000, "Button present: " + btn_prefix + ele);
  34. client.click(btn_prefix + ele);
  35. let built_div = model_building_utils.create_class(client,
  36. x_coord, y_coords[num_elements], num_elements, type_prefix + ele + "\\2f ");
  37. ele_map[ele] = built_div;
  38. if (ele.includes("Rule")) {
  39. let rule_name = num_elements + "_" + ele.replace("Icon", "");
  40. let name_field = "#tr_name > td:nth-child(2) > textarea:nth-child(1)";
  41. let rule_field = "#tr_rule > td:nth-child(2) > textarea:nth-child(1)";
  42. let rule_prefix = "/autotest/R_";
  43. let attribs = {};
  44. attribs[name_field] = rule_name;
  45. attribs[rule_field] = rule_prefix + rule_name + ".model";
  46. model_building_utils.set_attribs(client, num_elements, attribs, type_prefix + ele + "\\2f ");
  47. }
  48. num_elements++;
  49. }
  50. let assocs = [
  51. [0, 1, ""],
  52. [1, 2, "success"],
  53. [2, 3, "success"],
  54. [1, 4, "fail"],
  55. [2, 4, "fail"]
  56. ];
  57. for (let assoc of assocs) {
  58. let start_ele = to_create[assoc[0]];
  59. let end_ele = to_create[assoc[1]];
  60. let start = ele_map[start_ele];
  61. let end = ele_map[end_ele];
  62. //TODO: Have path come from check/x mark
  63. let relation_div = "";
  64. if (assoc[2] == "success") {
  65. relation_div = "#choice_\\2f Formalisms\\2f __Transformations__\\2f Transformation\\2f MoTif\\2e defaultIcons\\2f success";
  66. //start += " > path:nth-child(3)";
  67. } else if (assoc[2] == "fail") {
  68. relation_div = "#choice_\\2f Formalisms\\2f __Transformations__\\2f Transformation\\2f MoTif\\2e defaultIcons\\2f fail";
  69. //start += " > path:nth-child(5)";
  70. }
  71. let offset = 5 * (assoc[0] + assoc[1]);
  72. model_building_utils.create_assoc(client, start, end, relation_div, offset);
  73. }
  74. model_building_utils.save_model(client, "autotest", "T_autotest.model");
  75. },
  76. 'Create Rule 1': function (client) {
  77. test_utils.load_toolbar(client, rule_toolbars);
  78. // BUILD LHS AND RHS
  79. let LHS_btn = "#\\2f Formalisms\\2f __Transformations__\\2f TransformationRule\\2f TransformationRule\\2e defaultIcons\\2e metamodel\\2f LHSIcon";
  80. let RHS_btn = "#\\2f Formalisms\\2f __Transformations__\\2f TransformationRule\\2f TransformationRule\\2e defaultIcons\\2e metamodel\\2f RHSIcon";
  81. let ele_map = {};
  82. client.waitForElementPresent(LHS_btn, 2000, "LHS button").click(LHS_btn);
  83. let LHS_div = "#\\2f Formalisms\\2f __Transformations__\\2f TransformationRule\\2f TransformationRule\\2e defaultIcons\\2f LHSIcon\\2f ";
  84. ele_map["LHS"] = model_building_utils.create_class(client, 150, 200, 0, LHS_div);
  85. client.waitForElementPresent(RHS_btn, 2000, "RHS button").click(RHS_btn);
  86. let RHS_div = "#\\2f Formalisms\\2f __Transformations__\\2f TransformationRule\\2f TransformationRule\\2e defaultIcons\\2f RHSIcon\\2f ";
  87. ele_map["RHS"] = model_building_utils.create_class(client, 650, 200, 1, RHS_div);
  88. model_building_utils.click_off(client);
  89. //BUILD ELEMENTS INSIDE
  90. let c_btn = "#\\2f autotest\\2f autotest\\2e defaultIcons\\2e pattern\\2e metamodel\\2f __pClassCIcon";
  91. let d_btn = "#\\2f autotest\\2f autotest\\2e defaultIcons\\2e pattern\\2e metamodel\\2f __pClassDIcon";
  92. client.waitForElementPresent(c_btn, 2000, "C button").click(c_btn);
  93. let c_div = "#\\2f autotest\\2f autotest\\2e defaultIcons\\2e pattern\\2f __pClassCIcon\\2f ";
  94. ele_map["C"] = model_building_utils.create_class(client, 50, 200, 2, c_div);
  95. client.waitForElementPresent(d_btn, 2000, "D button").click(d_btn);
  96. let d_div = "#\\2f autotest\\2f autotest\\2e defaultIcons\\2e pattern\\2f __pClassDIcon\\2f ";
  97. ele_map["D"] = model_building_utils.create_class(client, 50, 400, 3, d_div);
  98. model_building_utils.move_element(client, ele_map["C"] + " > text:nth-child(1)", ele_map["LHS"], [50, 50], [50, 50]);
  99. model_building_utils.move_element(client, ele_map["D"] + " > text:nth-child(1)", ele_map["RHS"], [50, 50], [50, 50]);
  100. model_building_utils.save_model(client, "autotest", "R_1_FRule.model");
  101. },
  102. 'Create Rule 2': function (client) {
  103. test_utils.load_toolbar(client, rule_toolbars);
  104. // BUILD LHS AND RHS
  105. let LHS_btn = "#\\2f Formalisms\\2f __Transformations__\\2f TransformationRule\\2f TransformationRule\\2e defaultIcons\\2e metamodel\\2f LHSIcon";
  106. let RHS_btn = "#\\2f Formalisms\\2f __Transformations__\\2f TransformationRule\\2f TransformationRule\\2e defaultIcons\\2e metamodel\\2f RHSIcon";
  107. let ele_map = {};
  108. client.waitForElementPresent(LHS_btn, 2000, "LHS button").click(LHS_btn);
  109. let LHS_div = "#\\2f Formalisms\\2f __Transformations__\\2f TransformationRule\\2f TransformationRule\\2e defaultIcons\\2f LHSIcon\\2f ";
  110. ele_map["LHS"] = model_building_utils.create_class(client, 150, 200, 0, LHS_div);
  111. client.waitForElementPresent(RHS_btn, 2000, "RHS button").click(RHS_btn);
  112. let RHS_div = "#\\2f Formalisms\\2f __Transformations__\\2f TransformationRule\\2f TransformationRule\\2e defaultIcons\\2f RHSIcon\\2f ";
  113. ele_map["RHS"] = model_building_utils.create_class(client, 650, 200, 1, RHS_div);
  114. model_building_utils.click_off(client);
  115. //BUILD ELEMENTS INSIDE
  116. let a_btn = "#\\2f autotest\\2f autotest\\2e defaultIcons\\2e pattern\\2e metamodel\\2f __pClassAIcon";
  117. let a_div = "#\\2f autotest\\2f autotest\\2e defaultIcons\\2e pattern\\2f __pClassAIcon\\2f ";
  118. //BUILD A
  119. client.waitForElementPresent(a_btn, 2000, "A button").click(a_btn);
  120. ele_map["A_lhs"] = model_building_utils.create_class(client, 50, 200, 2, a_div);
  121. ele_map["A_rhs"] = model_building_utils.create_class(client, 50, 400, 3, a_div);
  122. model_building_utils.move_element(client, ele_map["A_lhs"] + " > text:nth-child(1)", ele_map["LHS"], [50, 50], [50, 20]);
  123. model_building_utils.move_element(client, ele_map["A_rhs"] + " > text:nth-child(1)", ele_map["RHS"], [50, 50], [50, 20]);
  124. model_building_utils.click_off(client);
  125. let b_btn = "#\\2f autotest\\2f autotest\\2e defaultIcons\\2e pattern\\2e metamodel\\2f __pClassBIcon";
  126. let b_div = "#\\2f autotest\\2f autotest\\2e defaultIcons\\2e pattern\\2f __pClassBIcon\\2f ";
  127. //BUILD B
  128. client.waitForElementPresent(b_btn, 2000, "B button").click(b_btn);
  129. ele_map["B_lhs"] = model_building_utils.create_class(client, 50, 200, 6, b_div);
  130. ele_map["B_rhs"] = model_building_utils.create_class(client, 50, 400, 7, b_div);
  131. model_building_utils.move_element(client, ele_map["B_lhs"] + " > text:nth-child(1)", ele_map["LHS"], [50, 50], [50, 70]);
  132. model_building_utils.move_element(client, ele_map["B_rhs"] + " > text:nth-child(1)", ele_map["RHS"], [50, 50], [50, 70]);
  133. model_building_utils.click_off(client);
  134. //BUILD ASSOCS
  135. client.pause(300);
  136. model_building_utils.create_assoc(client,
  137. ele_map["A_lhs"] + " > text:nth-child(1)", ele_map["B_lhs"] + " > text:nth-child(1)", "", 0);
  138. client.pause(300);
  139. model_building_utils.create_assoc(client,
  140. ele_map["A_rhs"] + " > text:nth-child(1)", ele_map["B_rhs"] + " > text:nth-child(1)", "", 0);
  141. let test_field = "#tr_test > td:nth-child(2) > textarea";
  142. let attrs = {};
  143. attrs[test_field] = "result = \"bonjour world!\"";
  144. model_building_utils.set_attribs(client, 3, attrs, a_div, " > text:nth-child(1)", [5, 5]);
  145. model_building_utils.save_model(client, "autotest", "R_2_ARule.model");
  146. },
  147. 'Execute Transformation': function (client) {
  148. model_building_utils.load_model(client, "autotest", "autotest_instance.model");
  149. model_building_utils.compile_model(client, "transform", "autotest", "T_autotest.model");
  150. let run_button = "#\\2f Toolbars\\2f TransformationController\\2f TransformationController\\2e buttons\\2e model\\2f play";
  151. client.click(run_button);
  152. let created_D_1 = "#\\2f autotest\\2f autotest\\2e defaultIcons\\2f ClassDIcon\\2f 15\\2e instance";
  153. let created_D_2 = "#\\2f autotest\\2f autotest\\2e defaultIcons\\2f ClassDIcon\\2f 15\\2e instance";
  154. client.waitForElementPresent(created_D_1, 5000, "First D element created");
  155. client.waitForElementPresent(created_D_2, 5000, "Second D element created");
  156. //TODO:Test for A element's attribute
  157. //CHECK CONSTRAINT
  158. let verify_btn = "#\\/Toolbars\\/MainMenu\\/MainMenu\\.buttons\\.model\\/validateM";
  159. let dialog_btn = "#dialog_btn";
  160. client.pause(500);
  161. client.waitForElementPresent(verify_btn, 2000, "Find verify button")
  162. .click(verify_btn).pause(500)
  163. .waitForElementPresent(dialog_btn, 2000, "Constraint violation")
  164. .click(dialog_btn);
  165. },
  166. after: function (client) {
  167. client.end();
  168. },
  169. };