05_creating_dsl.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. let test_utils = require('./test_utils');
  2. let model_building_utils = require('./model_building_utils');
  3. let user = "./users/testuser/";
  4. function get_all_attrs() {
  5. return "[\n" +
  6. " {\n" +
  7. " \"name\": \"int\",\n" +
  8. " \"type\": \"int\",\n" +
  9. " \"default\": 0\n" +
  10. " },\n" +
  11. " {\n" +
  12. " \"name\": \"string\",\n" +
  13. " \"type\": \"string\",\n" +
  14. " \"default\": \"hello\"\n" +
  15. " },\n" +
  16. " {\n" +
  17. " \"name\": \"float\",\n" +
  18. " \"type\": \"float\",\n" +
  19. " \"default\": 0\n" +
  20. " },\n" +
  21. " {\n" +
  22. " \"name\": \"boolean\",\n" +
  23. " \"type\": \"boolean\",\n" +
  24. " \"default\": true\n" +
  25. " },\n" +
  26. " {\n" +
  27. " \"name\": \"code\",\n" +
  28. " \"type\": \"code\",\n" +
  29. " \"default\": \"\"\n" +
  30. " },\n" +
  31. " {\n" +
  32. " \"name\": \"file_html\",\n" +
  33. " \"type\": \"file<*.html>\",\n" +
  34. " \"default\": \"\"\n" +
  35. " },\n" +
  36. " {\n" +
  37. " \"name\": \"map_int_string\",\n" +
  38. " \"type\": \"map<int,string>\"\n" +
  39. " },\n" +
  40. " {\n" +
  41. " \"name\": \"list_int\",\n" +
  42. " \"type\": \"lis<int>\",\n" +
  43. " \"default\": [\n" +
  44. " 1,\n" +
  45. " 2\n" +
  46. " ]\n" +
  47. " },\n" +
  48. " {\n" +
  49. " \"name\": \"enum\",\n" +
  50. " \"type\": \"ENUM(Red,Green,Blue)\"\n" +
  51. " },\n" +
  52. " {\n" +
  53. " \"name\": \"enum2\",\n" +
  54. " \"type\": \"ENUM(Four,Five,Six,Seven)\"\n" +
  55. " }\n" +
  56. "]";
  57. }
  58. function get_all_attrs2() {
  59. return "[\n" +
  60. " {\n" +
  61. " \"name\": \"name\",\n" +
  62. " \"type\": \"string\",\n" +
  63. " \"default\": \"test\"\n" +
  64. " },\n" +
  65. " {\n" +
  66. " \"name\": \"\",\n" +
  67. " \"type\": \"\",\n" +
  68. " \"default\": \"\"\n" +
  69. " }\n" +
  70. "]";
  71. }
  72. module.exports = {
  73. beforeEach: function (client, done) {
  74. client.url('http://localhost:8124/atompm').pause(300).maximizeWindow(done);
  75. },
  76. 'Login': function (client) {
  77. test_utils.login(client);
  78. },
  79. 'Create AS model': function (client) {
  80. let filename = '/Formalisms/__LanguageSyntax__/SimpleClassDiagram/SimpleClassDiagram.umlIcons.metamodel';
  81. test_utils.load_toolbar(client, [filename]);
  82. let classIcon = "#\\/Formalisms\\/__LanguageSyntax__\\/SimpleClassDiagram\\/SimpleClassDiagram\\.umlIcons\\.metamodel\\/ClassIcon";
  83. client.waitForElementPresent(classIcon, 2000, "Check for class icon...");
  84. client.click(classIcon);
  85. let canvas = "#div_canvas";
  86. client.waitForElementPresent(canvas, 1000, "Checking for canvas...");
  87. let test_folder = "autotest";
  88. let name_field = "#tr_name > td:nth-child(2) > textarea";
  89. let num_elements = 0;
  90. //BUILD CLASSES
  91. let start_x = 50;
  92. let x_diff = 350;
  93. let x_coords = [start_x, start_x + x_diff, start_x + 2 * x_diff];
  94. let start_y = 200;
  95. let y_diff = 150;
  96. let y_coords = [start_y, start_y + y_diff, start_y + 2 * y_diff];
  97. let num_classes = x_coords.length * y_coords.length;
  98. num_elements = model_building_utils.create_classes(client, x_coords, y_coords, num_elements);
  99. // SET NAMES FOR CLASSES
  100. for (let i = 0; i < num_classes; i++) {
  101. let class_name = "Class" + String.fromCharCode(65 + i);
  102. let attrs = {};
  103. attrs[name_field] = class_name;
  104. model_building_utils.set_attribs(client, i, attrs);
  105. }
  106. // SET ATTRIBUTES
  107. let class_div = model_building_utils.get_class_div(0);
  108. let attrib_field = "#tr_attributes > td:nth-child(2) > textarea";
  109. client.moveToElement(class_div, 10, 10)
  110. .mouseButtonClick('middle')
  111. .waitForElementPresent("#dialog_btn", 1000, "Editing menu opens")
  112. .clearValue(attrib_field)
  113. .setValue(attrib_field, get_all_attrs())
  114. .click("#dialog_btn")
  115. .waitForElementNotPresent("#dialog_btn", 1000, "Editing menu closes")
  116. .moveToElement(canvas, 0, 100)
  117. .mouseButtonClick('left')
  118. .pause(1000)
  119. ;
  120. let abstract_class = 4;
  121. let class_div2 = model_building_utils.get_class_div(abstract_class);
  122. let attrib_field2 = "#tr_attributes > td:nth-child(2) > textarea";
  123. let checkbox = "#tr_abstract > td:nth-child(2) > input[type=\"checkbox\"]";
  124. client.moveToElement(class_div2, 10, 10)
  125. .mouseButtonClick('middle')
  126. .waitForElementPresent("#dialog_btn", 1000, "Editing menu opens")
  127. .clearValue(attrib_field2)
  128. .setValue(attrib_field2, get_all_attrs2())
  129. .moveToElement(checkbox, 0, 0)
  130. .mouseButtonClick('left')
  131. .click("#dialog_btn")
  132. .waitForElementNotPresent("#dialog_btn", 1000, "Editing menu closes")
  133. .moveToElement(canvas, 0, 100)
  134. .mouseButtonClick('left')
  135. .pause(1000)
  136. ;
  137. //CREATE INHERITANCE
  138. let inheri_classes = [
  139. [abstract_class, abstract_class + 1],
  140. [abstract_class, abstract_class + 3]];
  141. for (let inheri_set of inheri_classes) {
  142. let sup = model_building_utils.get_class_div(inheri_set[0]);
  143. let sub = model_building_utils.get_class_div(inheri_set[1]);
  144. let inheri_relation = "#div_dialog_0 > select > option:nth-child(2)";
  145. //tiny offset to not hit other arrows
  146. let offset = 2 * inheri_set[1];
  147. client
  148. .moveToElement(sub, 50, 50)
  149. .mouseButtonDown('right')
  150. .moveToElement(sup, 50 + offset, 50 + offset)
  151. .mouseButtonUp('right')
  152. .pause(500)
  153. .click(inheri_relation)
  154. .waitForElementPresent("#dialog_btn", 1000, "Inheri menu opens")
  155. .click("#dialog_btn")
  156. .pause(500)
  157. .waitForElementNotPresent("#dialog_btn", 1000, "Inheri menu closes")
  158. .moveToElement(canvas, 0, 100)
  159. .mouseButtonClick('left')
  160. .pause(500)
  161. ;
  162. num_elements++;
  163. }
  164. //SET ASSOCS
  165. let assocs = [
  166. //from, to, name, isContain, out_card, in_card
  167. [0, 1, "testAssoc", false, null, null],
  168. [2, 3, "oneToOne", false,
  169. [{
  170. "dir": "out",
  171. "type": "oneToOne",
  172. "min": "1",
  173. "max": "1"
  174. }],
  175. [{
  176. "dir": "in",
  177. "type": "oneToOne",
  178. "min": "1",
  179. "max": "1"
  180. }]
  181. ],
  182. [4, 5, "ManyToOne", false,
  183. null,
  184. [{
  185. "dir": "in",
  186. "type": "ManyToOne",
  187. "min": "0",
  188. "max": "1"
  189. }]
  190. ],
  191. [6, 7, "Containment", true,
  192. null, null
  193. ],
  194. [8, 8, "self", false,
  195. null, null
  196. ]
  197. ];
  198. client.pause(500);
  199. let assoc_num = 0;
  200. for (let assoc of assocs) {
  201. let from_ele = model_building_utils.get_class_div(assoc[0]);
  202. let to_ele = model_building_utils.get_class_div(assoc[1]);
  203. let name = assoc[2];
  204. let isContain = assoc[3];
  205. let out_card = assoc[4];
  206. let in_card = assoc[5];
  207. let cardinality_field = "#tr_cardinalities > td:nth-child(2) > textarea";
  208. let assoc_div = model_building_utils.get_assoc_div(num_elements);
  209. assoc_num++;
  210. num_elements++;
  211. let assoc_relation = "#div_dialog_0 > select > option:nth-child(1)";
  212. //tiny offset to not hit other arrows
  213. let offset = 2 * assoc[0] + 2 * assoc[1];
  214. client
  215. .moveToElement(from_ele, 20, 20)
  216. .mouseButtonDown('right')
  217. .moveToElement(to_ele, 20 + offset, 20 + offset)
  218. .mouseButtonUp('right')
  219. .pause(500)
  220. .click(assoc_relation)
  221. .waitForElementPresent("#dialog_btn", 1000, "Assoc menu opens")
  222. .click("#dialog_btn")
  223. .pause(500)
  224. .waitForElementNotPresent("#dialog_btn", 1000, "Assoc menu closes")
  225. .moveToElement(canvas, 0, 100)
  226. .mouseButtonClick('left')
  227. .pause(500)
  228. .waitForElementPresent(assoc_div, 1000, "Assoc name present: " + assoc_div);
  229. if (out_card) {
  230. client
  231. .moveToElement(from_ele, 10, 10)
  232. .mouseButtonClick('middle')
  233. .waitForElementPresent("#dialog_btn", 1000, "Out card menu opens")
  234. .clearValue(cardinality_field)
  235. .setValue(cardinality_field, JSON.stringify(out_card))
  236. .click("#dialog_btn")
  237. .waitForElementNotPresent("#dialog_btn", 1000, "Out card menu closes")
  238. .moveToElement(canvas, 0, 100)
  239. .mouseButtonClick('left')
  240. .pause(500);
  241. }
  242. if (in_card) {
  243. client
  244. .moveToElement(to_ele, 10, 10)
  245. .mouseButtonClick('middle')
  246. .waitForElementPresent("#dialog_btn", 1000, "Out card menu opens")
  247. .clearValue(cardinality_field)
  248. .setValue(cardinality_field, JSON.stringify(in_card))
  249. .click("#dialog_btn")
  250. .waitForElementNotPresent("#dialog_btn", 1000, "Out card menu closes")
  251. .moveToElement(canvas, 0, 100)
  252. .mouseButtonClick('left')
  253. .pause(500);
  254. }
  255. client.getElementSize(assoc_div, function (result) {
  256. model_building_utils.move_to_element_ratio(client, assoc_div, 50, 50)
  257. client.mouseButtonClick('middle')
  258. .waitForElementPresent("#dialog_btn", 1000, "Editing assoc name opens")
  259. .clearValue(name_field)
  260. .setValue(name_field, name);
  261. if (isContain) {
  262. let contain_opt = "#tr_linktype > td:nth-child(2) > select > option:nth-child(2)";
  263. client
  264. .moveToElement(contain_opt, 0, 0)
  265. .mouseButtonClick('left');
  266. }
  267. client
  268. .click("#dialog_btn")
  269. .waitForElementNotPresent("#dialog_btn", 1000, "Editing assoc name closes")
  270. .moveToElement(canvas, 0, 100)
  271. .mouseButtonClick('left')
  272. .pause(500);
  273. })
  274. ;
  275. }
  276. //CREATE CONSTRAINT
  277. let constraint_div = model_building_utils.get_element_div("GlobalConstraintIcon", num_elements);
  278. let constraintIcon = "#\\2f Formalisms\\2f __LanguageSyntax__\\2f SimpleClassDiagram\\2f SimpleClassDiagram\\2e umlIcons\\2e metamodel\\2f GlobalConstraintIcon";
  279. client.waitForElementPresent(constraintIcon, 2000, "Check for constraint icon...");
  280. client.click(constraintIcon);
  281. client
  282. .moveToElement(canvas, 100, 150)
  283. .mouseButtonClick('right')
  284. .pause(500)
  285. .waitForElementPresent(constraint_div, 500, "Created class: " + constraint_div);
  286. let pre_create_opt = "#tr_event > td:nth-child(2) > select > option:nth-child(2)";
  287. let code_field = "#tr_code > td:nth-child(2) > textarea";
  288. let constraint_code = "let C_classes = getAllNodes(['Formalisms/__LanguageSyntax__/SimpleClassDiagram/SimpleClassDiagram/umlIcons/ClassIcon']);\n" +
  289. "C_classes.length <= 2;";
  290. client
  291. .moveToElement(constraint_div, 10, 10)
  292. .mouseButtonClick('middle')
  293. .waitForElementPresent("#dialog_btn", 1000, "Constraint menu opens")
  294. .clearValue(name_field)
  295. .setValue(name_field, "max-two-instances")
  296. .moveToElement(pre_create_opt, 0, 0)
  297. .mouseButtonClick('left')
  298. .clearValue(code_field)
  299. .setValue(code_field, constraint_code)
  300. .click("#dialog_btn")
  301. .waitForElementNotPresent("#dialog_btn", 1000, "Constraint menu closes")
  302. .moveToElement(canvas, 0, 100)
  303. .mouseButtonClick('left')
  304. .pause(1000);
  305. //SAVE MODEL
  306. let save_button = "#\\2f Toolbars\\2f MainMenu\\2f MainMenu\\2e buttons\\2e model\\2f saveModel";
  307. let new_file_text = "#new_file";
  308. let model_name = "autotest.model";
  309. client.waitForElementPresent(save_button, 1000, "Looking for save button")
  310. .click(save_button)
  311. .waitForElementPresent("#dialog_btn", 1000, "Save menu opens");
  312. let test_folder_div = "#" + test_folder;
  313. client.element('css selector', test_folder_div, function (result) {
  314. if (result.status == -1) {
  315. let new_folder_btn = "#new_folder";
  316. client.click(new_folder_btn)
  317. .setAlertText(test_folder)
  318. .acceptAlert();
  319. }
  320. client.click(test_folder_div);
  321. client.element('css selector', "#" + model_name, function (result) {
  322. if (result.status == -1) {
  323. client.click(new_file_text)
  324. .clearValue(new_file_text)
  325. .setValue(new_file_text, model_name)
  326. .click("#dialog_btn");
  327. } else {
  328. client.click("#" + model_name)
  329. .click("#dialog_btn");
  330. }
  331. client.waitForElementNotPresent("#dialog_btn", 1000, "Save menu closes");
  332. }
  333. );
  334. }
  335. );
  336. //COMPILE TO ASMM
  337. let ASMM_button = "#\\2f Toolbars\\2f CompileMenu\\2f CompileMenu\\2e buttons\\2e model\\2f compileToASMM";
  338. client.waitForElementPresent(ASMM_button, 1000, "Looking for ASMM button")
  339. .click(ASMM_button)
  340. .waitForElementPresent("#dialog_btn", 2000, "ASMM menu opens");
  341. client.element('css selector', test_folder_div, function (result) {
  342. if (result.status != -1) {
  343. client.click(test_folder_div);
  344. }
  345. });
  346. let metamodel_name = "autotest.metamodel";
  347. client.element('css selector', "#" + metamodel_name, function (result) {
  348. if (result.status == -1) {
  349. client.click(new_file_text)
  350. .clearValue(new_file_text)
  351. .setValue(new_file_text, metamodel_name)
  352. .click("#dialog_btn");
  353. } else {
  354. client.click("#" + metamodel_name)
  355. .click("#dialog_btn");
  356. }
  357. client.waitForElementNotPresent("#dialog_btn", 2000, "ASMM menu closes");
  358. }
  359. );
  360. client.pause(500);
  361. },
  362. 'Create CS model': function (client) {
  363. let filename = '/Formalisms/__LanguageSyntax__/ConcreteSyntax/ConcreteSyntax.defaultIcons.metamodel';
  364. test_utils.load_toolbar(client, [filename]);
  365. let classIcon = "#\\/Formalisms\\/__LanguageSyntax__\\/ConcreteSyntax\\/ConcreteSyntax\\.defaultIcons\\.metamodel\\/IconIcon";
  366. client.waitForElementPresent(classIcon, 2000, "Check for class icon...");
  367. client.click(classIcon);
  368. let canvas = "#div_canvas";
  369. client.waitForElementPresent(canvas, 1000, "Checking for canvas...");
  370. let test_folder = "autotest";
  371. let name_field = "#tr_typename > td:nth-child(2) > textarea";
  372. let num_elements = 0;
  373. //BUILD CLASSES
  374. let icon_type = "#\\/Formalisms\\/__LanguageSyntax__\\/ConcreteSyntax\\/ConcreteSyntax\\.defaultIcons\\/IconIcon\\/";
  375. let start_x = 50;
  376. let x_diff = 350;
  377. let x_coords = [start_x];//, start_x + x_diff];//, start_x + 2 * x_diff];
  378. let start_y = 200;
  379. let y_diff = 200;
  380. let y_coords = [start_y];//, start_y + y_diff];//, start_y + 2 * y_diff];
  381. let num_classes = x_coords.length * y_coords.length;
  382. num_elements = model_building_utils.create_classes(client, x_coords, y_coords, num_elements, icon_type);
  383. // SET NAMES FOR CLASSES
  384. for (let i = 0; i < num_classes; i++) {
  385. let class_name = "Class" + String.fromCharCode(65 + i) + "Icon";
  386. let attrs = {};
  387. attrs[name_field] = class_name;
  388. model_building_utils.set_attribs(client, i, attrs, icon_type);
  389. }
  390. // BUILD TEXT FOR ICONS
  391. let textIcon = "#\\/Formalisms\\/__LanguageSyntax__\\/ConcreteSyntax\\/ConcreteSyntax\\.defaultIcons\\.metamodel\\/TextIcon";
  392. let textType = "#\\/Formalisms\\/__LanguageSyntax__\\/ConcreteSyntax\\/ConcreteSyntax\\.defaultIcons\\/TextIcon\\/";
  393. let textContent_field = "#tr_textContent > td:nth-child(2) > textarea";
  394. client.waitForElementPresent(textIcon, 2000, "Check for text icon...");
  395. client.click(textIcon);
  396. for (let i = 0; i < num_classes; i++) {
  397. let text = "Class" + String.fromCharCode(65 + i);
  398. let textDiv = model_building_utils.build_div(textType, num_elements);
  399. let iconDiv = model_building_utils.build_div(icon_type, i);
  400. let attrs = {};
  401. attrs[textContent_field] = text;
  402. client
  403. .pause(300)
  404. .moveToElement(canvas, 20, 200)
  405. .mouseButtonClick('right')
  406. .pause(500)
  407. .waitForElementPresent(textDiv, 500, "Created text: " + textDiv);
  408. model_building_utils.set_attribs(client, num_elements, attrs, textType);
  409. client.moveToElement(textDiv, 10, 10)
  410. .mouseButtonClick('left')
  411. .pause(300)
  412. .mouseButtonDown('left');
  413. model_building_utils.move_to_element_ratio(client, iconDiv, 50, 10);
  414. client.mouseButtonUp('left');
  415. num_elements++;
  416. client.pause(2000);
  417. }
  418. },
  419. after: function (client) {
  420. client.end();
  421. },
  422. };