Changeset 1336
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-plugin-html-test/src/test/java/de/ugoe/cs/autoquest/plugin/html/commands/CMDcondenseHTMLGUIModelTest.java
r1334 r1336 43 43 44 44 /** 45 * <p>46 * TODO comment47 * </p>48 *49 45 * @author Patrick Harms 50 46 */ … … 168 164 169 165 String[] assertionSpec = 170 { "/server/doc1/html/body/ group_common/div",166 { "/server/doc1/html/body/div", 171 167 "/server/doc1/html/body/group_doc1/div_1", 172 168 "/server/doc1/html/body/group_doc2/div_2" }; … … 207 203 208 204 String[] assertionSpec = 209 { "/server/doc1/html/body/div/group_doc1doc2doc3/group_doc1doc2/ group_common/div_1",210 "/server/doc1/html/body/div/group_doc1doc2doc3/group_doc1doc2/ group_common/div_2",205 { "/server/doc1/html/body/div/group_doc1doc2doc3/group_doc1doc2/div_1", 206 "/server/doc1/html/body/div/group_doc1doc2doc3/group_doc1doc2/div_2", 211 207 "/server/doc1/html/body/div/group_doc1doc2doc3/group_doc1doc2/group_doc1/div_3", 212 208 "/server/doc1/html/body/div/group_doc1doc2doc3/group_doc1doc2/group_doc1/div_5", 213 209 "/server/doc1/html/body/div/group_doc1doc2doc3/group_doc1doc2/group_doc2/div_7", 214 210 "/server/doc1/html/body/div/group_doc1doc2doc3/group_doc1doc2/group_doc2/div_8", 215 "/server/doc1/html/body/div/group_doc1doc2doc3/ group_common/div_6",211 "/server/doc1/html/body/div/group_doc1doc2doc3/div_6", 216 212 "/server/doc1/html/body/div/group_doc1doc5/div_4", 217 "/server/doc1/html/body/div/group_doc3doc5/ group_common/div_11",213 "/server/doc1/html/body/div/group_doc3doc5/div_11", 218 214 "/server/doc1/html/body/div/group_doc3doc5/group_doc3/div_9", 219 215 "/server/doc1/html/body/div/group_doc3doc5/group_doc3/div_10", … … 221 217 "/server/doc1/html/body/div/group_doc4/div_13" }; 222 218 223 guiModel.dump(System.out, "UTF-8"); 219 assertGUIModel(guiModel, assertionSpec); 220 } 221 222 /** 223 * 224 */ 225 @Test 226 public void test_condense_07() throws Exception { 227 String[] guiSpec = 228 { "/server/doc1/html/body/div/div_1/div_11", 229 "/server/doc2/html/body/div/div_2/div_21", 230 "/server/doc3/html/body/div/div_1/div_12" }; 231 232 GUIModel guiModel = generateGUIModel(guiSpec); 233 GlobalDataContainer.getInstance().addData("sequences_targets", guiModel); 234 235 executeCommand(); 236 237 String[] assertionSpec = 238 { "/server/doc1/html/body/div/group_doc1doc3/div_1/group_doc1/div_11", 239 "/server/doc1/html/body/div/group_doc1doc3/div_1/group_doc3/div_12", 240 "/server/doc1/html/body/div/group_doc2/div_2/div_21" }; 241 242 assertGUIModel(guiModel, assertionSpec); 243 } 244 245 /** 246 * 247 */ 248 @Test 249 public void test_condense_08() throws Exception { 250 String[] guiSpec = 251 { "/server/doc1/html/body/div/div_1/div_11/div_111", 252 "/server/doc1/html/body/div/div_2/div_21/div_211", 253 "/server/doc1/html/body/div/div_3/div_31", 254 "/server/doc2/html/body/div/div_1/div_11/div_111", 255 "/server/doc2/html/body/div/div_2/div_21/div_211", 256 "/server/doc2/html/body/div/div_3/div_31", 257 "/server/doc2/html/body/div/div_4/div_41", 258 "/server/doc3/html/body/div" }; 259 260 GUIModel guiModel = generateGUIModel(guiSpec); 261 GlobalDataContainer.getInstance().addData("sequences_targets", guiModel); 262 263 executeCommand(); 264 265 String[] assertionSpec = 266 { "/server/doc1/html/body/div/group_doc1doc2/div_1/div_11/div_111", 267 "/server/doc1/html/body/div/group_doc1doc2/div_2/div_21/div_211", 268 "/server/doc1/html/body/div/group_doc1doc2/div_3/div_31", 269 "/server/doc1/html/body/div/group_doc1doc2/group_doc2/div_4/div_41" }; 270 271 assertGUIModel(guiModel, assertionSpec); 272 } 273 274 /** 275 * 276 */ 277 @Test 278 public void test_condense_09() throws Exception { 279 String[] guiSpec = 280 { "/server/doc1/html/body/div/div_1/div_11/div_111", 281 "/server/doc1/html/body/div/div_2/div_21/div_211", 282 "/server/doc1/html/body/div/div_3/div_31", 283 "/server/doc2/html/body/div/div_1/div_12/div_121", 284 "/server/doc2/html/body/div/div_2/div_22/div_221", 285 "/server/doc2/html/body/div/div_3/div_31", 286 "/server/doc2/html/body/div/div_4/div_41", 287 "/server/doc3/html/body/div" }; 288 289 GUIModel guiModel = generateGUIModel(guiSpec); 290 GlobalDataContainer.getInstance().addData("sequences_targets", guiModel); 291 292 executeCommand(); 293 294 String[] assertionSpec = 295 { "/server/doc1/html/body/div/group_doc1doc2/div_1/group_doc1/div_11/div_111", 296 "/server/doc1/html/body/div/group_doc1doc2/div_1/group_doc2/div_12/div_121", 297 "/server/doc1/html/body/div/group_doc1doc2/div_2/group_doc1/div_21/div_211", 298 "/server/doc1/html/body/div/group_doc1doc2/div_2/group_doc2/div_22/div_221", 299 "/server/doc1/html/body/div/group_doc1doc2/div_3/div_31", 300 "/server/doc1/html/body/div/group_doc1doc2/group_doc2/div_4/div_41" }; 301 302 assertGUIModel(guiModel, assertionSpec); 303 } 304 305 /** 306 * 307 */ 308 @Test 309 public void test_condense_10() throws Exception { 310 String[] guiSpec = 311 { "/server/doc1/html/body/div/div_1/div_11/div_111", 312 "/server/doc1/html/body/div/div_2/div_21/div_211", 313 "/server/doc1/html/body/div/div_3/div_31/div_311", 314 "/server/doc1/html/body/div/div_4/div_41/div_411", 315 "/server/doc1/html/body/div/div_5/div_51/div_511", 316 "/server/doc2/html/body/div/div_2/div_21/div_211", 317 "/server/doc2/html/body/div/div_3/div_31/div_311", 318 "/server/doc2/html/body/div/div_4/div_41/div_411", 319 "/server/doc2/html/body/div/div_5/div_51/div_511", 320 "/server/doc3/html/body/div/div_3/div_31/div_311", 321 "/server/doc3/html/body/div/div_4/div_41/div_411", 322 "/server/doc3/html/body/div/div_5/div_51/div_511", 323 "/server/doc4/html/body/div/div_4/div_41/div_411", 324 "/server/doc4/html/body/div/div_5/div_51/div_511" }; 325 326 GUIModel guiModel = generateGUIModel(guiSpec); 327 GlobalDataContainer.getInstance().addData("sequences_targets", guiModel); 328 329 executeCommand(); 330 331 String[] assertionSpec = 332 { "/server/doc1/html/body/div/div_4/div_41/div_411", 333 "/server/doc1/html/body/div/div_5/div_51/div_511", 334 "/server/doc1/html/body/div/group_doc1doc2doc3/div_3/div_31/div_311", 335 "/server/doc1/html/body/div/group_doc1doc2doc3/group_doc1doc2/div_2/div_21/div_211", 336 "/server/doc1/html/body/div/group_doc1doc2doc3/group_doc1doc2/group_doc1/div_1/div_11/div_111" }; 337 224 338 assertGUIModel(guiModel, assertionSpec); 225 339 } -
trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/commands/CMDcondenseHTMLGUIModel.java
r1334 r1336 15 15 package de.ugoe.cs.autoquest.plugin.html.commands; 16 16 17 import java.io.PrintStream;18 17 import java.util.Arrays; 19 18 import java.util.Comparator; … … 74 73 * \-- html 75 74 * \-- body 76 * |-- group (common) 77 * | |-- div (id = menu) 78 * | | \-- ... 79 * | \-- div (id = footer) 80 * | \-- ... 75 * |-- div (id = menu) 76 * | \-- ... 81 77 * |-- group (document1) 82 78 * | \-- div (id = textcontent) … … 85 81 * | \-- div (id = imagecontent) 86 82 * | \-- ... 83 * \-- div (id = footer) 84 * \-- ... 87 85 * </pre> 88 86 * This now allows the menu and the footer to be treated as identical over several pages. … … 128 126 for (IGUIElement root : model.getRootElements()) { 129 127 if (root instanceof HTMLServer) { 130 mergeServer((HTMLServer) root, model); 128 try { 129 mergeServer((HTMLServer) root, model); 130 } 131 catch (Exception e) { 132 Console.printerrln("problems while condensing model of server " + root); 133 //e.printStackTrace(System.out); 134 break; 135 } 131 136 } 132 137 } … … 148 153 GUIElementsCluster rootCluster = getSimilarElementClusterHierarchy(server, model); 149 154 150 rootCluster.dump(System.out, "");151 152 Console.traceln(Level.FINE, " grouping GUI elements according to clusters");153 groupGUIElementsAccordingToClusters(rootCluster, model, "");155 //rootCluster.dump(System.out, ""); 156 157 Console.traceln(Level.FINE, "merging GUI elements in same clusters and creating groups"); 158 mergeGUIElementsAccordingToClusters(rootCluster, model, ""); 154 159 155 160 //model.dump(System.out, "UTF-8"); … … 176 181 177 182 List<IGUIElement> children = model.getChildren(server); 183 178 184 179 185 SimilarGUIElements similarGuiElements = new SimilarGUIElements(); … … 182 188 // when starting with the root, the cluster parent is the child itself, i.e. the 183 189 // document. We expect all documents to be similar. 190 184 191 similarGuiElements.add(new SimilarGUIElement(child, child)); 185 192 } … … 243 250 } 244 251 } 252 // else { 253 // // search for a default cluster to add all elements to, which have no children 254 // GUIElementsCluster defaultCluster = null; 255 // 256 // for (GUIElementsCluster candidate : parentCluster.childClusters) { 257 // if (candidate.similarChildrenGUIElements.size() == 0) { 258 // defaultCluster = candidate; 259 // break; 260 // } 261 // } 262 // 263 // if (defaultCluster == null) { 264 // defaultCluster = new GUIElementsCluster(); 265 // parentCluster.addChildCluster(defaultCluster); 266 // } 267 // 268 // defaultCluster.clusteredGUIElements.add(similarGuiElement); 269 // } 245 270 } 246 271 } … … 354 379 createClusterHierachies(subClusterToHandle); 355 380 356 GUIElementsCluster commonCluster = new GUIElementsCluster();381 /*GUIElementsCluster commonCluster = new GUIElementsCluster(); 357 382 //commonCluster.setClusteredGUIElements(subClusterToHandle.clusteredGUIElements); 358 383 commonCluster.similarChildrenGUIElements.addAll … … 360 385 361 386 subClusterToHandle.similarChildrenGUIElements.clear(); 362 subClusterToHandle.childClusters.add(0, commonCluster); 387 subClusterToHandle.childClusters.add(0, commonCluster);*/ 388 } 389 } 390 } 391 392 /** 393 * <p> 394 * called for each cluster to merge similar GUI elements depending on the clusters and to 395 * create GUI element groups if required. Calls itself recursively to be also applied on 396 * child clusters. 397 * </p> 398 * 399 * @param cluster the cluster of which the similar children shall be merged 400 * @param model the model to be adapted through the merge 401 */ 402 private void mergeGUIElementsAccordingToClusters(GUIElementsCluster cluster, 403 GUIModel model, 404 String indent) 405 { 406 //System.out.println(indent + "handling " + cluster); 407 408 for (SimilarGUIElements similarGUIElements : cluster.similarChildrenGUIElements) { 409 mergeGUIElements(similarGUIElements, model, indent + " "); 410 } 411 412 if (cluster.childClusters.size() > 0) { 413 //System.out.println(indent + " handling child clusters"); 414 415 for (GUIElementsCluster childCluster : cluster.childClusters) { 416 if (cluster.isDefault() || cluster.clusterParentsMatch(childCluster)) { 417 // for default cluster or children not creating subgroups, just traverse the 418 // cluster hierarchy 419 mergeGUIElementsAccordingToClusters(childCluster, model, indent + " "); 420 } 421 else { 422 createClusterGroup(childCluster, model, indent + " "); 423 } 363 424 } 364 425 } … … 380 441 381 442 while (similarGUIElements.size() > 1) { 382 System.out.println(indent + "merging " + mergeResult + " and " +383 similarGUIElements.get(1).similarGUIElement);443 //System.out.println(indent + "merging " + mergeResult + " and " + 444 // similarGUIElements.get(1).similarGUIElement); 384 445 mergeResult = model.mergeGUIElements 385 446 (mergeResult, similarGUIElements.remove(1).similarGUIElement, false); … … 396 457 * @param model the model to be used for creating the groups 397 458 */ 398 private void groupGUIElementsAccordingToClusters(GUIElementsCluster cluster, 399 GUIModel model, 400 String indent) 401 { 402 System.out.println(indent + "handling " + cluster); 403 459 private void createClusterGroup(GUIElementsCluster cluster, GUIModel model, String indent) { 460 //System.out.println(indent + "creating group for " + cluster); 461 404 462 List<IGUIElement> guiElementsToGroup = new LinkedList<IGUIElement>(); 405 463 … … 409 467 } 410 468 411 List<IGUIElement> subgroups = new LinkedList<IGUIElement>(); 412 413 414 System.out.println(indent + "iterating child clusters of " + cluster); 469 //System.out.println(indent + " iterating child clusters of " + cluster); 415 470 for (GUIElementsCluster childCluster : cluster.childClusters) { 416 groupGUIElementsAccordingToClusters(childCluster, model, indent + " "); 417 418 if (cluster.childClusters.size() > 1) { 419 List<IGUIElement> childGuiElemsToGroup = new LinkedList<IGUIElement>(); 420 421 for (SimilarGUIElements similarGUIElems : childCluster.similarChildrenGUIElements) { 422 childGuiElemsToGroup.addAll(similarGUIElems.toGUIElementList()); 423 } 424 425 for (GUIElementsCluster subsubcluster : childCluster.childClusters) { 426 if (subsubcluster.getGroup() != null) { 427 childGuiElemsToGroup.add(subsubcluster.getGroup()); 428 } 429 } 430 431 if (childGuiElemsToGroup.size() > 0) { 432 System.out.println(indent + " grouping: " + childGuiElemsToGroup); 433 IGUIElement group = model.groupGUIElements 434 (childGuiElemsToGroup, getGroupName(childCluster)); 435 System.out.println 436 (indent + " created group for " + childCluster + ": " + group); 437 438 if (group != null) { 439 childCluster.setGroup(group); 440 if (cluster.isSubCluster(childCluster)) { 441 subgroups.add(childCluster.getGroup()); 442 } 443 else { 444 subgroups.add(childCluster.getGroup().getParent()); 445 } 446 } 447 } 448 } 449 450 System.out.println(); 451 } 452 471 if (cluster.isDefault() || cluster.clusterParentsMatch(childCluster)) { 472 // for default cluster or children not creating subgroups, just traverse the 473 // cluster hierarchy 474 mergeGUIElementsAccordingToClusters(childCluster, model, indent + " "); 475 } 476 else { 477 createClusterGroup(childCluster, model, indent + " "); 478 } 479 480 if (childCluster.getGroup() != null) { 481 if (cluster.isSubCluster(childCluster)) { 482 guiElementsToGroup.add(childCluster.getGroup()); 483 } 484 else { 485 guiElementsToGroup.add(childCluster.getGroup().getParent()); 486 } 487 } 488 } 489 490 //System.out.println(indent + "grouping: " + guiElementsToGroup); 491 IGUIElement group = model.groupGUIElements(guiElementsToGroup, getGroupName(cluster)); 492 //System.out.println(indent + " created group for " + cluster + ": " + group); 493 494 cluster.setGroup(group); 453 495 } 454 496 … … 541 583 public String toString() { 542 584 return getName(); 585 } 586 587 /** 588 * <p> 589 * checks, if the main cluster parents, i.e., the documents of this and the provided cluster 590 * match 591 * </p> 592 * 593 * @param other the other cluster of which the main cluster parents shall be compared to 594 * this 595 * 596 * @return true if they match, false else 597 */ 598 private boolean clusterParentsMatch(GUIElementsCluster other) { 599 // cluster parent may already be merged and therefore equals --> use system identity 600 // hash code for uniqueness 601 Set<Integer> mainClusterParents1 = new HashSet<Integer>(); 602 for (SimilarGUIElement clusteredElem1 : clusteredGUIElements) { 603 mainClusterParents1.add(System.identityHashCode(clusteredElem1.mainClusterParent)); 604 } 605 606 Set<Integer> mainClusterParents2 = new HashSet<Integer>(); 607 for (SimilarGUIElement clusteredElem2 : other.clusteredGUIElements) { 608 mainClusterParents2.add(System.identityHashCode(clusteredElem2.mainClusterParent)); 609 } 610 611 return mainClusterParents1.equals(mainClusterParents2); 612 } 613 614 /** 615 * <p> 616 * returns true, if this cluster is a default cluster 617 * </p> 618 * 619 * @return 620 */ 621 public boolean isDefault() { 622 return clusteredGUIElements.size() <= 0; 543 623 } 544 624 … … 688 768 * </p> 689 769 */ 690 private void dump(PrintStream out, String indent) {691 out.print(indent);692 out.print(getName());693 out.println(" { ");694 695 if (clusteredGUIElements.size() > 0) {696 out.print(indent);697 out.println(" clustered GUIElements {");698 699 for (SimilarGUIElement clusteredGUIElement : clusteredGUIElements) {700 clusteredGUIElement.dump(out, indent + " ");701 }702 703 out.print(indent);704 out.println(" }");705 }706 707 if (similarChildrenGUIElements.size() > 0) {708 out.print(indent);709 out.println(" similar children {");710 711 for (SimilarGUIElements similarGuiElements : similarChildrenGUIElements) {712 similarGuiElements.dump(out, indent + " ");713 }714 715 out.print(indent);716 out.println(" }");717 }718 719 if (childClusters.size() > 0) {720 out.print(indent);721 out.println(" child clusters {");722 723 for (GUIElementsCluster childCluster : childClusters) {724 childCluster.dump(out, indent + " ");725 }726 727 out.print(indent);728 out.println(" }");729 }730 731 out.print(indent);732 out.println("}");733 }770 // private void dump(PrintStream out, String indent) { 771 // out.print(indent); 772 // out.print(getName()); 773 // out.println(" { "); 774 // 775 // if (clusteredGUIElements.size() > 0) { 776 // out.print(indent); 777 // out.println(" clustered GUIElements {"); 778 // 779 // for (SimilarGUIElement clusteredGUIElement : clusteredGUIElements) { 780 // clusteredGUIElement.dump(out, indent + " "); 781 // } 782 // 783 // out.print(indent); 784 // out.println(" }"); 785 // } 786 // 787 // if (similarChildrenGUIElements.size() > 0) { 788 // out.print(indent); 789 // out.println(" similar children {"); 790 // 791 // for (SimilarGUIElements similarGuiElements : similarChildrenGUIElements) { 792 // similarGuiElements.dump(out, indent + " "); 793 // } 794 // 795 // out.print(indent); 796 // out.println(" }"); 797 // } 798 // 799 // if (childClusters.size() > 0) { 800 // out.print(indent); 801 // out.println(" child clusters {"); 802 // 803 // for (GUIElementsCluster childCluster : childClusters) { 804 // childCluster.dump(out, indent + " "); 805 // } 806 // 807 // out.print(indent); 808 // out.println(" }"); 809 // } 810 // 811 // out.print(indent); 812 // out.println("}"); 813 // } 734 814 735 815 } … … 787 867 * </p> 788 868 */ 789 private void dump(PrintStream out, String indent) {790 out.print(indent);791 out.print("{ ");792 793 for (int i = 0; i < super.size(); i++) {794 if (i > 0) {795 out.print(", ");796 }797 out.print(super.get(i));798 }799 800 out.println(" }");801 }869 // private void dump(PrintStream out, String indent) { 870 // out.print(indent); 871 // out.print("{ "); 872 // 873 // for (int i = 0; i < super.size(); i++) { 874 // if (i > 0) { 875 // out.print(", "); 876 // } 877 // out.print(super.get(i)); 878 // } 879 // 880 // out.println(" }"); 881 // } 802 882 } 803 883 … … 839 919 * </p> 840 920 */ 841 private void dump(PrintStream out, String indent) {842 out.print(indent);843 out.println(this);844 }921 // private void dump(PrintStream out, String indent) { 922 // out.print(indent); 923 // out.println(this); 924 // } 845 925 846 926 /* (non-Javadoc)
Note: See TracChangeset
for help on using the changeset viewer.