[1088] | 1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany |
---|
| 2 | // |
---|
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
---|
| 4 | // you may not use this file except in compliance with the License. |
---|
| 5 | // You may obtain a copy of the License at |
---|
| 6 | // |
---|
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
---|
| 8 | // |
---|
| 9 | // Unless required by applicable law or agreed to in writing, software |
---|
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
---|
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
| 12 | // See the License for the specific language governing permissions and |
---|
| 13 | // limitations under the License. |
---|
| 14 | |
---|
| 15 | package de.ugoe.cs.autoquest.eventcore.guimodel; |
---|
| 16 | |
---|
| 17 | import static org.junit.Assert.*; |
---|
| 18 | |
---|
| 19 | import java.util.ArrayList; |
---|
[1280] | 20 | import java.util.Arrays; |
---|
[1088] | 21 | import java.util.List; |
---|
| 22 | |
---|
| 23 | import org.junit.Test; |
---|
| 24 | |
---|
| 25 | /** |
---|
| 26 | * |
---|
| 27 | * @author Patrick Harms |
---|
| 28 | */ |
---|
| 29 | public class GUIModelTest { |
---|
| 30 | |
---|
| 31 | /** |
---|
| 32 | * |
---|
| 33 | */ |
---|
| 34 | private IGUIElementFactory guiElementFactory = new TestGUIElementFactory(); |
---|
| 35 | |
---|
| 36 | /** |
---|
| 37 | * |
---|
| 38 | */ |
---|
| 39 | @Test |
---|
| 40 | public void test_PathIntegration_01() throws Exception { |
---|
| 41 | GUIModel model = new GUIModel(); |
---|
| 42 | |
---|
| 43 | List<IGUIElementSpec> guiElementPath = new ArrayList<IGUIElementSpec>(); |
---|
| 44 | guiElementPath.add(new TestGUIElementSpec("guiElem1")); |
---|
| 45 | |
---|
| 46 | IGUIElement element = model.integratePath(guiElementPath, guiElementFactory); |
---|
| 47 | |
---|
| 48 | assertTrue(element instanceof TestGUIElement); |
---|
| 49 | assertEquals(guiElementPath.get(0), element.getSpecification()); |
---|
| 50 | assertNull(element.getParent()); |
---|
| 51 | |
---|
| 52 | assertNotNull(model.getRootElements()); |
---|
| 53 | assertEquals(1, model.getRootElements().size()); |
---|
| 54 | assertEquals(element, model.getRootElements().get(0)); |
---|
| 55 | |
---|
| 56 | assertNotNull(model.getChildren(element)); |
---|
| 57 | assertTrue(model.getChildren(element).isEmpty()); |
---|
| 58 | |
---|
| 59 | assertNull(model.getParent(element)); |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | /** |
---|
| 63 | * |
---|
| 64 | */ |
---|
| 65 | @Test |
---|
| 66 | public void test_PathIntegration_02() throws Exception { |
---|
| 67 | GUIModel model = new GUIModel(); |
---|
| 68 | |
---|
| 69 | List<IGUIElementSpec> guiElementPath = new ArrayList<IGUIElementSpec>(); |
---|
| 70 | for (int i = 0; i < 5; i++) { |
---|
| 71 | guiElementPath.add(new TestGUIElementSpec("guiElem" + i)); |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | IGUIElement element = model.integratePath(guiElementPath, guiElementFactory); |
---|
| 75 | |
---|
| 76 | for (int i = 4; i >= 0; i--) { |
---|
| 77 | assertTrue(element instanceof TestGUIElement); |
---|
| 78 | assertEquals(guiElementPath.get(i), element.getSpecification()); |
---|
| 79 | |
---|
| 80 | assertNotNull(model.getChildren(element)); |
---|
| 81 | |
---|
| 82 | if (i == 4) { |
---|
| 83 | assertTrue(model.getChildren(element).isEmpty()); |
---|
| 84 | } |
---|
| 85 | else { |
---|
| 86 | assertEquals(1, model.getChildren(element).size()); |
---|
| 87 | assertEquals(guiElementPath.get(i + 1), |
---|
| 88 | model.getChildren(element).get(0).getSpecification()); |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | element = element.getParent(); |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | assertNull(element); |
---|
| 95 | |
---|
| 96 | assertNotNull(model.getRootElements()); |
---|
| 97 | assertEquals(1, model.getRootElements().size()); |
---|
| 98 | assertNotNull(model.getRootElements().get(0)); |
---|
| 99 | assertEquals(guiElementPath.get(0), model.getRootElements().get(0).getSpecification()); |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | /** |
---|
| 103 | * |
---|
| 104 | */ |
---|
| 105 | @Test |
---|
| 106 | public void test_PathIntegration_03() throws Exception { |
---|
| 107 | GUIModel model = new GUIModel(); |
---|
| 108 | |
---|
| 109 | for (int i = 0; i < 20; i++) { |
---|
| 110 | List<IGUIElementSpec> guiElementPath = new ArrayList<IGUIElementSpec>(); |
---|
| 111 | |
---|
| 112 | for (int j = 0; j < 5; j++) { |
---|
| 113 | guiElementPath.add(new TestGUIElementSpec("guiElem_" + i + "_" + j)); |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | IGUIElement element = model.integratePath(guiElementPath, guiElementFactory); |
---|
| 117 | |
---|
| 118 | for (int j = 4; j >= 0; j--) { |
---|
| 119 | assertTrue(element instanceof TestGUIElement); |
---|
| 120 | assertEquals(guiElementPath.get(j), element.getSpecification()); |
---|
| 121 | |
---|
| 122 | assertNotNull(model.getChildren(element)); |
---|
| 123 | |
---|
| 124 | if (j == 4) { |
---|
| 125 | assertTrue(model.getChildren(element).isEmpty()); |
---|
| 126 | } |
---|
| 127 | else { |
---|
| 128 | assertEquals(1, model.getChildren(element).size()); |
---|
| 129 | assertEquals(guiElementPath.get(j + 1), |
---|
| 130 | model.getChildren(element).get(0).getSpecification()); |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | element = element.getParent(); |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | assertNull(element); |
---|
| 137 | |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | assertNotNull(model.getRootElements()); |
---|
| 141 | assertEquals(20, model.getRootElements().size()); |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | /** |
---|
| 145 | * |
---|
| 146 | */ |
---|
| 147 | @Test |
---|
| 148 | public void test_PathIntegration_04() throws Exception { |
---|
| 149 | GUIModel model = new GUIModel(); |
---|
| 150 | |
---|
| 151 | List<IGUIElementSpec> guiElementPath = new ArrayList<IGUIElementSpec>(); |
---|
| 152 | guiElementPath.add(new TestGUIElementSpec("guiElem1")); |
---|
| 153 | |
---|
| 154 | IGUIElement element1 = model.integratePath(guiElementPath, guiElementFactory); |
---|
| 155 | |
---|
| 156 | guiElementPath = new ArrayList<IGUIElementSpec>(); |
---|
| 157 | guiElementPath.add(new TestGUIElementSpec("guiElem1")); |
---|
| 158 | |
---|
| 159 | IGUIElement element2 = model.integratePath(guiElementPath, guiElementFactory); |
---|
| 160 | |
---|
| 161 | assertSame(element1, element2); |
---|
| 162 | } |
---|
| 163 | |
---|
| 164 | /** |
---|
| 165 | * |
---|
| 166 | */ |
---|
| 167 | @Test |
---|
| 168 | public void test_PathIntegration_05() throws Exception { |
---|
| 169 | GUIModel model = new GUIModel(); |
---|
| 170 | |
---|
| 171 | List<IGUIElementSpec> guiElementPath = new ArrayList<IGUIElementSpec>(); |
---|
| 172 | for (int i = 0; i < 5; i++) { |
---|
| 173 | guiElementPath.add(new TestGUIElementSpec("guiElem" + i)); |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | IGUIElement element1 = model.integratePath(guiElementPath, guiElementFactory); |
---|
| 177 | |
---|
| 178 | guiElementPath = new ArrayList<IGUIElementSpec>(); |
---|
| 179 | for (int i = 0; i < 5; i++) { |
---|
| 180 | guiElementPath.add(new TestGUIElementSpec("guiElem" + i)); |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | IGUIElement element2 = model.integratePath(guiElementPath, guiElementFactory); |
---|
| 184 | |
---|
| 185 | assertSame(element1, element2); |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | /** |
---|
| 189 | * |
---|
| 190 | */ |
---|
| 191 | @Test |
---|
| 192 | public void test_PathIntegration_06() throws Exception { |
---|
| 193 | GUIModel model = new GUIModel(); |
---|
| 194 | |
---|
| 195 | List<IGUIElementSpec> guiElementPath = new ArrayList<IGUIElementSpec>(); |
---|
| 196 | guiElementPath.add(new TestGUIElementSpec("guiElem1")); |
---|
| 197 | guiElementPath.add(new TestGUIElementSpec("guiElem2")); |
---|
| 198 | guiElementPath.add(new TestGUIElementSpec("guiElem3")); |
---|
| 199 | guiElementPath.add(new TestGUIElementSpec("guiElem4")); |
---|
| 200 | |
---|
| 201 | IGUIElement element1 = model.integratePath(guiElementPath, guiElementFactory); |
---|
| 202 | |
---|
| 203 | guiElementPath.remove(2); |
---|
| 204 | guiElementPath.remove(2); |
---|
| 205 | |
---|
| 206 | guiElementPath.add(new TestGUIElementSpec("guiElem5")); |
---|
| 207 | guiElementPath.add(new TestGUIElementSpec("guiElem6")); |
---|
| 208 | |
---|
| 209 | IGUIElement element2 = model.integratePath(guiElementPath, guiElementFactory); |
---|
| 210 | |
---|
| 211 | assertFalse(element1.equals(element2)); |
---|
| 212 | |
---|
| 213 | element1 = element1.getParent(); |
---|
| 214 | assertFalse(element1.equals(element2)); |
---|
| 215 | |
---|
| 216 | element2 = element2.getParent(); |
---|
| 217 | assertFalse(element1.equals(element2)); |
---|
| 218 | |
---|
| 219 | element1 = element1.getParent(); |
---|
| 220 | assertFalse(element1.equals(element2)); |
---|
| 221 | |
---|
| 222 | element2 = element2.getParent(); |
---|
| 223 | assertSame(element1, element2); |
---|
| 224 | } |
---|
| 225 | |
---|
| 226 | /** |
---|
| 227 | * |
---|
| 228 | */ |
---|
| 229 | @Test |
---|
| 230 | public void test_CondenseModel_01() throws Exception { |
---|
| 231 | GUIModel model = new GUIModel(); |
---|
| 232 | |
---|
| 233 | for (int i = 0; i < 20; i++) { |
---|
| 234 | List<IGUIElementSpec> guiElementPath = new ArrayList<IGUIElementSpec>(); |
---|
| 235 | |
---|
| 236 | for (int j = 0; j < 5; j++) { |
---|
| 237 | guiElementPath.add(new TestGUIElementSpec("guiElem_" + i + "_" + j, "spec_" + j)); |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | model.integratePath(guiElementPath, guiElementFactory); |
---|
| 241 | } |
---|
| 242 | |
---|
| 243 | assertNotNull(model.getRootElements()); |
---|
| 244 | assertEquals(20, model.getRootElements().size()); |
---|
| 245 | |
---|
| 246 | model.condenseModel(); |
---|
| 247 | |
---|
| 248 | assertNotNull(model.getRootElements()); |
---|
| 249 | assertEquals(1, model.getRootElements().size()); |
---|
| 250 | |
---|
| 251 | IGUIElement element = model.getRootElements().get(0); |
---|
| 252 | |
---|
| 253 | for (int i = 0; i < 5; i++) { |
---|
| 254 | assertNotNull(element); |
---|
| 255 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
| 256 | assertTrue(((TestGUIElementSpec) element.getSpecification()).id.endsWith("_" + i)); |
---|
| 257 | |
---|
| 258 | if (i < 4) { |
---|
| 259 | assertNotNull(model.getChildren(element)); |
---|
| 260 | assertEquals(1, model.getChildren(element).size()); |
---|
| 261 | element = model.getChildren(element).get(0); |
---|
| 262 | } |
---|
| 263 | else { |
---|
| 264 | assertNotNull(model.getChildren(element)); |
---|
| 265 | assertEquals(0, model.getChildren(element).size()); |
---|
| 266 | } |
---|
| 267 | } |
---|
| 268 | } |
---|
| 269 | |
---|
| 270 | /** |
---|
| 271 | * |
---|
| 272 | */ |
---|
| 273 | @Test |
---|
| 274 | public void test_CondenseModel_02() throws Exception { |
---|
| 275 | GUIModel model = new GUIModel(); |
---|
| 276 | |
---|
| 277 | List<IGUIElementSpec> guiElementPath = new ArrayList<IGUIElementSpec>(); |
---|
| 278 | for (int j = 0; j < 3; j++) { |
---|
| 279 | guiElementPath.add(new TestGUIElementSpec("guiElem_" + j)); |
---|
| 280 | } |
---|
| 281 | |
---|
| 282 | for (int i = 0; i < 20; i++) { |
---|
| 283 | for (int j = 3; j < 5; j++) { |
---|
| 284 | guiElementPath.add(new TestGUIElementSpec("guiElem_" + i + "_" + j, "spec_" + j)); |
---|
| 285 | } |
---|
| 286 | |
---|
| 287 | model.integratePath(guiElementPath, guiElementFactory); |
---|
| 288 | |
---|
| 289 | for (int j = 3; j < 5; j++) { |
---|
| 290 | guiElementPath.remove(3); |
---|
| 291 | } |
---|
| 292 | } |
---|
| 293 | |
---|
| 294 | assertNotNull(model.getRootElements()); |
---|
| 295 | assertEquals(1, model.getRootElements().size()); |
---|
| 296 | |
---|
| 297 | IGUIElement element = model.getRootElements().get(0); |
---|
| 298 | |
---|
| 299 | for (int i = 0; i < 3; i++) { |
---|
| 300 | assertNotNull(element); |
---|
| 301 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
| 302 | assertEquals("guiElem_" + i, ((TestGUIElementSpec) element.getSpecification()).id); |
---|
| 303 | |
---|
| 304 | if (i < 2) { |
---|
| 305 | assertNotNull(model.getChildren(element)); |
---|
| 306 | assertEquals(1, model.getChildren(element).size()); |
---|
| 307 | element = model.getChildren(element).get(0); |
---|
| 308 | } |
---|
| 309 | else { |
---|
| 310 | assertNotNull(model.getChildren(element)); |
---|
| 311 | assertEquals(20, model.getChildren(element).size()); |
---|
| 312 | } |
---|
| 313 | } |
---|
| 314 | |
---|
| 315 | model.condenseModel(); |
---|
| 316 | |
---|
| 317 | assertNotNull(model.getRootElements()); |
---|
| 318 | assertEquals(1, model.getRootElements().size()); |
---|
| 319 | |
---|
| 320 | element = model.getRootElements().get(0); |
---|
| 321 | |
---|
| 322 | for (int i = 0; i < 5; i++) { |
---|
| 323 | assertNotNull(element); |
---|
| 324 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
| 325 | assertTrue(((TestGUIElementSpec) element.getSpecification()).id.endsWith("_" + i)); |
---|
| 326 | |
---|
| 327 | if (i < 4) { |
---|
| 328 | assertNotNull(model.getChildren(element)); |
---|
| 329 | assertEquals(1, model.getChildren(element).size()); |
---|
| 330 | element = model.getChildren(element).get(0); |
---|
| 331 | } |
---|
| 332 | else { |
---|
| 333 | assertNotNull(model.getChildren(element)); |
---|
| 334 | assertEquals(0, model.getChildren(element).size()); |
---|
| 335 | } |
---|
| 336 | } |
---|
| 337 | } |
---|
| 338 | |
---|
| 339 | /** |
---|
| 340 | * |
---|
| 341 | */ |
---|
| 342 | @Test |
---|
[1280] | 343 | public void test_GroupGUIElements_01() throws Exception { |
---|
| 344 | GUIModel model = new GUIModel(); |
---|
| 345 | |
---|
| 346 | List<IGUIElementSpec> guiElementPath = new ArrayList<IGUIElementSpec>(); |
---|
| 347 | guiElementPath.add(new TestGUIElementSpec("guiElem1")); |
---|
| 348 | guiElementPath.add(new TestGUIElementSpec("guiElem2")); |
---|
| 349 | guiElementPath.add(new TestGUIElementSpec("guiElem3")); |
---|
| 350 | guiElementPath.add(new TestGUIElementSpec("guiElem4")); |
---|
| 351 | |
---|
| 352 | model.integratePath(guiElementPath, guiElementFactory); |
---|
| 353 | |
---|
| 354 | guiElementPath.remove(2); |
---|
| 355 | guiElementPath.remove(2); |
---|
| 356 | |
---|
| 357 | guiElementPath.add(new TestGUIElementSpec("guiElem5")); |
---|
| 358 | guiElementPath.add(new TestGUIElementSpec("guiElem6")); |
---|
| 359 | |
---|
| 360 | model.integratePath(guiElementPath, guiElementFactory); |
---|
| 361 | |
---|
| 362 | guiElementPath.remove(3); |
---|
| 363 | |
---|
| 364 | guiElementPath.add(new TestGUIElementSpec("guiElem7")); |
---|
| 365 | guiElementPath.add(new TestGUIElementSpec("guiElem8")); |
---|
| 366 | |
---|
| 367 | model.integratePath(guiElementPath, guiElementFactory); |
---|
| 368 | |
---|
| 369 | guiElementPath.remove(1); |
---|
| 370 | guiElementPath.remove(1); |
---|
| 371 | guiElementPath.remove(1); |
---|
| 372 | guiElementPath.remove(1); |
---|
| 373 | |
---|
| 374 | guiElementPath.add(new TestGUIElementSpec("guiElem9")); |
---|
| 375 | guiElementPath.add(new TestGUIElementSpec("guiElem10")); |
---|
| 376 | |
---|
| 377 | model.integratePath(guiElementPath, guiElementFactory); |
---|
| 378 | |
---|
| 379 | // the model created is |
---|
| 380 | // guiElem1 |
---|
| 381 | // |-- guiElem2 |
---|
| 382 | // | |-- guiElem3 |
---|
| 383 | // | | \-- guiElem4 |
---|
| 384 | // | | |
---|
| 385 | // | \-- guiElem5 |
---|
| 386 | // | |-- guiElem6 |
---|
| 387 | // | \-- guiElem7 |
---|
| 388 | // | \-- guiElem8 |
---|
| 389 | // \-- guiElem9 |
---|
| 390 | // \-- guiElem10 |
---|
| 391 | |
---|
| 392 | assertNotNull(model.getRootElements()); |
---|
| 393 | assertEquals(1, model.getRootElements().size()); |
---|
| 394 | |
---|
| 395 | IGUIElement guiElem1 = model.getRootElements().get(0); |
---|
| 396 | |
---|
| 397 | assertEquals(2, model.getChildren(guiElem1).size()); |
---|
| 398 | IGUIElement guiElem2 = model.getChildren(guiElem1).get(0); |
---|
| 399 | IGUIElement guiElem9 = model.getChildren(guiElem1).get(1); |
---|
| 400 | |
---|
| 401 | model.groupGUIElements(Arrays.asList(guiElem2, guiElem9), "newGroup"); |
---|
| 402 | |
---|
| 403 | assertEquals(1, model.getChildren(guiElem1).size()); |
---|
| 404 | IGUIElement group = model.getChildren(guiElem1).get(0); |
---|
| 405 | |
---|
| 406 | assertEquals(2, model.getChildren(group).size()); |
---|
| 407 | assertEquals(guiElem2, model.getChildren(group).get(0)); |
---|
| 408 | assertEquals(guiElem9, model.getChildren(group).get(1)); |
---|
[1386] | 409 | |
---|
| 410 | assertEquals(group, guiElem2.getParent()); |
---|
| 411 | assertEquals(group, guiElem9.getParent()); |
---|
[1280] | 412 | } |
---|
| 413 | |
---|
| 414 | /** |
---|
| 415 | * |
---|
| 416 | */ |
---|
| 417 | @Test |
---|
| 418 | public void test_GroupGUIElements_02() throws Exception { |
---|
| 419 | GUIModel model = new GUIModel(); |
---|
| 420 | |
---|
| 421 | List<IGUIElementSpec> guiElementPath = new ArrayList<IGUIElementSpec>(); |
---|
| 422 | guiElementPath.add(new TestGUIElementSpec("guiElem1")); |
---|
| 423 | guiElementPath.add(new TestGUIElementSpec("guiElem2")); |
---|
| 424 | guiElementPath.add(new TestGUIElementSpec("guiElem3")); |
---|
| 425 | guiElementPath.add(new TestGUIElementSpec("guiElem4")); |
---|
| 426 | |
---|
| 427 | model.integratePath(guiElementPath, guiElementFactory); |
---|
| 428 | |
---|
| 429 | guiElementPath.remove(2); |
---|
| 430 | guiElementPath.remove(2); |
---|
| 431 | |
---|
| 432 | guiElementPath.add(new TestGUIElementSpec("guiElem5")); |
---|
| 433 | guiElementPath.add(new TestGUIElementSpec("guiElem6")); |
---|
| 434 | |
---|
| 435 | model.integratePath(guiElementPath, guiElementFactory); |
---|
| 436 | |
---|
| 437 | guiElementPath.remove(3); |
---|
| 438 | |
---|
| 439 | guiElementPath.add(new TestGUIElementSpec("guiElem7")); |
---|
| 440 | guiElementPath.add(new TestGUIElementSpec("guiElem8")); |
---|
| 441 | |
---|
| 442 | model.integratePath(guiElementPath, guiElementFactory); |
---|
| 443 | |
---|
| 444 | guiElementPath.remove(1); |
---|
| 445 | guiElementPath.remove(1); |
---|
| 446 | guiElementPath.remove(1); |
---|
| 447 | guiElementPath.remove(1); |
---|
| 448 | |
---|
| 449 | guiElementPath.add(new TestGUIElementSpec("guiElem9")); |
---|
| 450 | guiElementPath.add(new TestGUIElementSpec("guiElem10")); |
---|
| 451 | |
---|
| 452 | model.integratePath(guiElementPath, guiElementFactory); |
---|
| 453 | |
---|
| 454 | // the model created is |
---|
| 455 | // guiElem1 |
---|
| 456 | // |-- guiElem2 |
---|
| 457 | // | |-- guiElem3 |
---|
| 458 | // | | \-- guiElem4 |
---|
| 459 | // | | |
---|
| 460 | // | \-- guiElem5 |
---|
| 461 | // | |-- guiElem6 |
---|
| 462 | // | \-- guiElem7 |
---|
| 463 | // | \-- guiElem8 |
---|
| 464 | // \-- guiElem9 |
---|
| 465 | // \-- guiElem10 |
---|
| 466 | |
---|
| 467 | assertNotNull(model.getRootElements()); |
---|
| 468 | assertEquals(1, model.getRootElements().size()); |
---|
| 469 | |
---|
| 470 | IGUIElement guiElem1 = model.getRootElements().get(0); |
---|
| 471 | IGUIElement guiElem2 = model.getChildren(guiElem1).get(0); |
---|
| 472 | |
---|
| 473 | assertEquals(2, model.getChildren(guiElem2).size()); |
---|
| 474 | IGUIElement guiElem3 = model.getChildren(guiElem2).get(0); |
---|
| 475 | IGUIElement guiElem5 = model.getChildren(guiElem2).get(1); |
---|
| 476 | |
---|
| 477 | model.groupGUIElements(Arrays.asList(guiElem3, guiElem5), "newGroup"); |
---|
| 478 | |
---|
| 479 | assertEquals(1, model.getChildren(guiElem2).size()); |
---|
| 480 | IGUIElement group = model.getChildren(guiElem2).get(0); |
---|
| 481 | |
---|
| 482 | assertEquals(2, model.getChildren(group).size()); |
---|
| 483 | assertEquals(guiElem3, model.getChildren(group).get(0)); |
---|
| 484 | assertEquals(guiElem5, model.getChildren(group).get(1)); |
---|
[1386] | 485 | |
---|
| 486 | assertEquals(group, guiElem3.getParent()); |
---|
| 487 | assertEquals(group, guiElem5.getParent()); |
---|
[1280] | 488 | } |
---|
| 489 | |
---|
| 490 | /** |
---|
| 491 | * |
---|
| 492 | */ |
---|
| 493 | @Test |
---|
| 494 | public void test_GroupGUIElements_03() throws Exception { |
---|
| 495 | GUIModel model = new GUIModel(); |
---|
| 496 | |
---|
| 497 | List<IGUIElementSpec> guiElementPath = new ArrayList<IGUIElementSpec>(); |
---|
| 498 | guiElementPath.add(new TestGUIElementSpec("guiElem1")); |
---|
| 499 | guiElementPath.add(new TestGUIElementSpec("guiElem2")); |
---|
| 500 | guiElementPath.add(new TestGUIElementSpec("guiElem3")); |
---|
| 501 | guiElementPath.add(new TestGUIElementSpec("guiElem4")); |
---|
| 502 | |
---|
| 503 | model.integratePath(guiElementPath, guiElementFactory); |
---|
| 504 | |
---|
| 505 | guiElementPath.remove(2); |
---|
| 506 | guiElementPath.remove(2); |
---|
| 507 | |
---|
| 508 | guiElementPath.add(new TestGUIElementSpec("guiElem5")); |
---|
| 509 | guiElementPath.add(new TestGUIElementSpec("guiElem6")); |
---|
| 510 | |
---|
| 511 | model.integratePath(guiElementPath, guiElementFactory); |
---|
| 512 | |
---|
| 513 | guiElementPath.remove(3); |
---|
| 514 | |
---|
| 515 | guiElementPath.add(new TestGUIElementSpec("guiElem7")); |
---|
| 516 | guiElementPath.add(new TestGUIElementSpec("guiElem8")); |
---|
| 517 | |
---|
| 518 | model.integratePath(guiElementPath, guiElementFactory); |
---|
| 519 | |
---|
| 520 | guiElementPath.remove(1); |
---|
| 521 | guiElementPath.remove(1); |
---|
| 522 | guiElementPath.remove(1); |
---|
| 523 | guiElementPath.remove(1); |
---|
| 524 | |
---|
| 525 | guiElementPath.add(new TestGUIElementSpec("guiElem9")); |
---|
| 526 | guiElementPath.add(new TestGUIElementSpec("guiElem10")); |
---|
| 527 | |
---|
| 528 | model.integratePath(guiElementPath, guiElementFactory); |
---|
| 529 | |
---|
| 530 | // the model created is |
---|
| 531 | // guiElem1 |
---|
| 532 | // |-- guiElem2 |
---|
| 533 | // | |-- guiElem3 |
---|
| 534 | // | | \-- guiElem4 |
---|
| 535 | // | | |
---|
| 536 | // | \-- guiElem5 |
---|
| 537 | // | |-- guiElem6 |
---|
| 538 | // | \-- guiElem7 |
---|
| 539 | // | \-- guiElem8 |
---|
| 540 | // \-- guiElem9 |
---|
| 541 | // \-- guiElem10 |
---|
| 542 | |
---|
| 543 | assertNotNull(model.getRootElements()); |
---|
| 544 | assertEquals(1, model.getRootElements().size()); |
---|
| 545 | |
---|
| 546 | IGUIElement guiElem1 = model.getRootElements().get(0); |
---|
| 547 | IGUIElement guiElem2 = model.getChildren(guiElem1).get(0); |
---|
| 548 | IGUIElement guiElem3 = model.getChildren(guiElem2).get(0); |
---|
| 549 | |
---|
| 550 | assertEquals(1, model.getChildren(guiElem3).size()); |
---|
| 551 | IGUIElement guiElem4 = model.getChildren(guiElem3).get(0); |
---|
| 552 | |
---|
| 553 | model.groupGUIElements(Arrays.asList(guiElem4), "newGroup"); |
---|
| 554 | |
---|
| 555 | assertEquals(1, model.getChildren(guiElem3).size()); |
---|
| 556 | IGUIElement group = model.getChildren(guiElem3).get(0); |
---|
| 557 | |
---|
| 558 | assertEquals(1, model.getChildren(group).size()); |
---|
| 559 | assertEquals(guiElem4, model.getChildren(group).get(0)); |
---|
[1386] | 560 | |
---|
| 561 | assertEquals(group, guiElem4.getParent()); |
---|
[1280] | 562 | } |
---|
| 563 | |
---|
| 564 | /** |
---|
| 565 | * |
---|
| 566 | */ |
---|
| 567 | @Test(expected = java.lang.IllegalArgumentException.class) |
---|
| 568 | public void test_GroupGUIElements_04() throws Exception { |
---|
| 569 | GUIModel model = new GUIModel(); |
---|
| 570 | |
---|
| 571 | List<IGUIElementSpec> guiElementPath = new ArrayList<IGUIElementSpec>(); |
---|
| 572 | guiElementPath.add(new TestGUIElementSpec("guiElem1")); |
---|
| 573 | guiElementPath.add(new TestGUIElementSpec("guiElem2")); |
---|
| 574 | guiElementPath.add(new TestGUIElementSpec("guiElem3")); |
---|
| 575 | guiElementPath.add(new TestGUIElementSpec("guiElem4")); |
---|
| 576 | |
---|
| 577 | model.integratePath(guiElementPath, guiElementFactory); |
---|
| 578 | |
---|
| 579 | guiElementPath.remove(2); |
---|
| 580 | guiElementPath.remove(2); |
---|
| 581 | |
---|
| 582 | guiElementPath.add(new TestGUIElementSpec("guiElem5")); |
---|
| 583 | guiElementPath.add(new TestGUIElementSpec("guiElem6")); |
---|
| 584 | |
---|
| 585 | model.integratePath(guiElementPath, guiElementFactory); |
---|
| 586 | |
---|
| 587 | guiElementPath.remove(3); |
---|
| 588 | |
---|
| 589 | guiElementPath.add(new TestGUIElementSpec("guiElem7")); |
---|
| 590 | guiElementPath.add(new TestGUIElementSpec("guiElem8")); |
---|
| 591 | |
---|
| 592 | model.integratePath(guiElementPath, guiElementFactory); |
---|
| 593 | |
---|
| 594 | guiElementPath.remove(1); |
---|
| 595 | guiElementPath.remove(1); |
---|
| 596 | guiElementPath.remove(1); |
---|
| 597 | guiElementPath.remove(1); |
---|
| 598 | |
---|
| 599 | guiElementPath.add(new TestGUIElementSpec("guiElem9")); |
---|
| 600 | guiElementPath.add(new TestGUIElementSpec("guiElem10")); |
---|
| 601 | |
---|
| 602 | model.integratePath(guiElementPath, guiElementFactory); |
---|
| 603 | |
---|
| 604 | // the model created is |
---|
| 605 | // guiElem1 |
---|
| 606 | // |-- guiElem2 |
---|
| 607 | // | |-- guiElem3 |
---|
| 608 | // | | \-- guiElem4 |
---|
| 609 | // | | |
---|
| 610 | // | \-- guiElem5 |
---|
| 611 | // | |-- guiElem6 |
---|
| 612 | // | \-- guiElem7 |
---|
| 613 | // | \-- guiElem8 |
---|
| 614 | // \-- guiElem9 |
---|
| 615 | // \-- guiElem10 |
---|
| 616 | |
---|
| 617 | assertNotNull(model.getRootElements()); |
---|
| 618 | assertEquals(1, model.getRootElements().size()); |
---|
| 619 | |
---|
| 620 | IGUIElement guiElem1 = model.getRootElements().get(0); |
---|
| 621 | IGUIElement guiElem2 = model.getChildren(guiElem1).get(0); |
---|
| 622 | IGUIElement guiElem3 = model.getChildren(guiElem2).get(0); |
---|
| 623 | IGUIElement guiElem5 = model.getChildren(guiElem2).get(1); |
---|
| 624 | |
---|
| 625 | assertEquals(1, model.getChildren(guiElem3).size()); |
---|
| 626 | IGUIElement guiElem4 = model.getChildren(guiElem3).get(0); |
---|
| 627 | |
---|
| 628 | assertEquals(2, model.getChildren(guiElem5).size()); |
---|
| 629 | IGUIElement guiElem6 = model.getChildren(guiElem5).get(0); |
---|
| 630 | |
---|
| 631 | model.groupGUIElements(Arrays.asList(guiElem4, guiElem6), "newGroup"); |
---|
| 632 | } |
---|
| 633 | |
---|
| 634 | /** |
---|
| 635 | * |
---|
| 636 | */ |
---|
| 637 | @Test |
---|
[1088] | 638 | public void test_Traverser_01() throws Exception { |
---|
| 639 | GUIModel model = new GUIModel(); |
---|
| 640 | |
---|
| 641 | List<IGUIElementSpec> guiElementPath = new ArrayList<IGUIElementSpec>(); |
---|
| 642 | guiElementPath.add(new TestGUIElementSpec("guiElem1")); |
---|
| 643 | guiElementPath.add(new TestGUIElementSpec("guiElem2")); |
---|
| 644 | guiElementPath.add(new TestGUIElementSpec("guiElem3")); |
---|
| 645 | guiElementPath.add(new TestGUIElementSpec("guiElem4")); |
---|
| 646 | |
---|
| 647 | model.integratePath(guiElementPath, guiElementFactory); |
---|
| 648 | |
---|
| 649 | guiElementPath.remove(2); |
---|
| 650 | guiElementPath.remove(2); |
---|
| 651 | |
---|
| 652 | guiElementPath.add(new TestGUIElementSpec("guiElem5")); |
---|
| 653 | guiElementPath.add(new TestGUIElementSpec("guiElem6")); |
---|
| 654 | |
---|
| 655 | model.integratePath(guiElementPath, guiElementFactory); |
---|
| 656 | |
---|
| 657 | guiElementPath.remove(3); |
---|
| 658 | |
---|
| 659 | guiElementPath.add(new TestGUIElementSpec("guiElem7")); |
---|
| 660 | guiElementPath.add(new TestGUIElementSpec("guiElem8")); |
---|
| 661 | |
---|
| 662 | model.integratePath(guiElementPath, guiElementFactory); |
---|
| 663 | |
---|
| 664 | guiElementPath.remove(1); |
---|
| 665 | guiElementPath.remove(1); |
---|
| 666 | guiElementPath.remove(1); |
---|
| 667 | guiElementPath.remove(1); |
---|
| 668 | |
---|
| 669 | guiElementPath.add(new TestGUIElementSpec("guiElem9")); |
---|
| 670 | guiElementPath.add(new TestGUIElementSpec("guiElem10")); |
---|
| 671 | |
---|
| 672 | model.integratePath(guiElementPath, guiElementFactory); |
---|
| 673 | |
---|
| 674 | // the model created is |
---|
| 675 | // guiElem1 |
---|
| 676 | // |-- guiElem2 |
---|
| 677 | // | |-- guiElem3 |
---|
| 678 | // | | \-- guiElem4 |
---|
| 679 | // | | |
---|
| 680 | // | \-- guiElem5 |
---|
| 681 | // | |-- guiElem6 |
---|
| 682 | // | \-- guiElem7 |
---|
| 683 | // | \-- guiElem8 |
---|
| 684 | // \-- guiElem9 |
---|
| 685 | // \-- guiElem10 |
---|
| 686 | |
---|
| 687 | GUIModel.Traverser traverser = model.getTraverser(); |
---|
| 688 | assertNotNull(traverser); |
---|
| 689 | assertTrue(traverser.hasFirstChild()); |
---|
| 690 | assertFalse(traverser.hasNextSibling()); |
---|
| 691 | assertNull(traverser.parent()); |
---|
| 692 | |
---|
| 693 | // guiElem1 |
---|
| 694 | IGUIElement element = traverser.firstChild(); |
---|
| 695 | assertNotNull(element); |
---|
| 696 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
| 697 | assertEquals("guiElem1", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
| 698 | assertTrue(traverser.hasFirstChild()); |
---|
| 699 | assertFalse(traverser.hasNextSibling()); |
---|
| 700 | assertNull(traverser.nextSibling()); |
---|
| 701 | |
---|
| 702 | // guiElem2 |
---|
| 703 | element = traverser.firstChild(); |
---|
| 704 | assertNotNull(element); |
---|
| 705 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
| 706 | assertEquals("guiElem2", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
| 707 | assertTrue(traverser.hasFirstChild()); |
---|
| 708 | assertTrue(traverser.hasNextSibling()); |
---|
| 709 | |
---|
| 710 | // guiElem3 |
---|
| 711 | element = traverser.firstChild(); |
---|
| 712 | assertNotNull(element); |
---|
| 713 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
| 714 | assertEquals("guiElem3", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
| 715 | assertTrue(traverser.hasFirstChild()); |
---|
| 716 | assertTrue(traverser.hasNextSibling()); |
---|
| 717 | |
---|
| 718 | // guiElem4 |
---|
| 719 | element = traverser.firstChild(); |
---|
| 720 | assertNotNull(element); |
---|
| 721 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
| 722 | assertEquals("guiElem4", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
| 723 | assertFalse(traverser.hasFirstChild()); |
---|
| 724 | assertNull(traverser.firstChild()); |
---|
| 725 | assertFalse(traverser.hasNextSibling()); |
---|
| 726 | assertNull(traverser.nextSibling()); |
---|
| 727 | |
---|
| 728 | // guiElem3 |
---|
| 729 | element = traverser.parent(); |
---|
| 730 | assertNotNull(element); |
---|
| 731 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
| 732 | assertEquals("guiElem3", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
| 733 | assertTrue(traverser.hasFirstChild()); |
---|
| 734 | assertTrue(traverser.hasNextSibling()); |
---|
| 735 | |
---|
| 736 | // guiElem5 |
---|
| 737 | element = traverser.nextSibling(); |
---|
| 738 | assertNotNull(element); |
---|
| 739 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
| 740 | assertEquals("guiElem5", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
| 741 | assertTrue(traverser.hasFirstChild()); |
---|
| 742 | assertFalse(traverser.hasNextSibling()); |
---|
| 743 | assertNull(traverser.nextSibling()); |
---|
| 744 | |
---|
| 745 | // guiElem6 |
---|
| 746 | element = traverser.firstChild(); |
---|
| 747 | assertNotNull(element); |
---|
| 748 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
| 749 | assertEquals("guiElem6", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
| 750 | assertFalse(traverser.hasFirstChild()); |
---|
| 751 | assertNull(traverser.firstChild()); |
---|
| 752 | assertTrue(traverser.hasNextSibling()); |
---|
| 753 | |
---|
| 754 | // guiElem7 |
---|
| 755 | element = traverser.nextSibling(); |
---|
| 756 | assertNotNull(element); |
---|
| 757 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
| 758 | assertEquals("guiElem7", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
| 759 | assertTrue(traverser.hasFirstChild()); |
---|
| 760 | assertFalse(traverser.hasNextSibling()); |
---|
| 761 | assertNull(traverser.nextSibling()); |
---|
| 762 | |
---|
| 763 | // guiElem8 |
---|
| 764 | element = traverser.firstChild(); |
---|
| 765 | assertNotNull(element); |
---|
| 766 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
| 767 | assertEquals("guiElem8", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
| 768 | assertFalse(traverser.hasFirstChild()); |
---|
| 769 | assertNull(traverser.firstChild()); |
---|
| 770 | assertFalse(traverser.hasNextSibling()); |
---|
| 771 | assertNull(traverser.nextSibling()); |
---|
| 772 | |
---|
| 773 | // guiElem7 |
---|
| 774 | element = traverser.parent(); |
---|
| 775 | assertNotNull(element); |
---|
| 776 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
| 777 | assertEquals("guiElem7", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
| 778 | assertTrue(traverser.hasFirstChild()); |
---|
| 779 | assertFalse(traverser.hasNextSibling()); |
---|
| 780 | assertNull(traverser.nextSibling()); |
---|
| 781 | |
---|
| 782 | // guiElem5 |
---|
| 783 | element = traverser.parent(); |
---|
| 784 | assertNotNull(element); |
---|
| 785 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
| 786 | assertEquals("guiElem5", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
| 787 | assertTrue(traverser.hasFirstChild()); |
---|
| 788 | assertFalse(traverser.hasNextSibling()); |
---|
| 789 | assertNull(traverser.nextSibling()); |
---|
| 790 | |
---|
| 791 | // guiElem2 |
---|
| 792 | element = traverser.parent(); |
---|
| 793 | assertNotNull(element); |
---|
| 794 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
| 795 | assertEquals("guiElem2", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
| 796 | assertTrue(traverser.hasFirstChild()); |
---|
| 797 | assertTrue(traverser.hasNextSibling()); |
---|
| 798 | |
---|
| 799 | // guiElem9 |
---|
| 800 | element = traverser.nextSibling(); |
---|
| 801 | assertNotNull(element); |
---|
| 802 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
| 803 | assertEquals("guiElem9", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
| 804 | assertTrue(traverser.hasFirstChild()); |
---|
| 805 | assertFalse(traverser.hasNextSibling()); |
---|
| 806 | assertNull(traverser.nextSibling()); |
---|
| 807 | |
---|
| 808 | // guiElem10 |
---|
| 809 | element = traverser.firstChild(); |
---|
| 810 | assertNotNull(element); |
---|
| 811 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
| 812 | assertEquals("guiElem10", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
| 813 | assertFalse(traverser.hasFirstChild()); |
---|
| 814 | assertNull(traverser.firstChild()); |
---|
| 815 | assertFalse(traverser.hasNextSibling()); |
---|
| 816 | assertNull(traverser.nextSibling()); |
---|
| 817 | |
---|
| 818 | // guiElem9 |
---|
| 819 | element = traverser.parent(); |
---|
| 820 | assertNotNull(element); |
---|
| 821 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
| 822 | assertEquals("guiElem9", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
| 823 | assertTrue(traverser.hasFirstChild()); |
---|
| 824 | assertFalse(traverser.hasNextSibling()); |
---|
| 825 | assertNull(traverser.nextSibling()); |
---|
| 826 | |
---|
| 827 | // guiElem1 |
---|
| 828 | element = traverser.parent(); |
---|
| 829 | assertNotNull(element); |
---|
| 830 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
| 831 | assertEquals("guiElem1", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
| 832 | assertTrue(traverser.hasFirstChild()); |
---|
| 833 | assertFalse(traverser.hasNextSibling()); |
---|
| 834 | assertNull(traverser.nextSibling()); |
---|
| 835 | |
---|
| 836 | assertNull(traverser.parent()); |
---|
| 837 | } |
---|
| 838 | |
---|
| 839 | /** |
---|
| 840 | * |
---|
| 841 | */ |
---|
| 842 | @Test |
---|
| 843 | public void test_Traverser_02() throws Exception { |
---|
| 844 | GUIModel model = new GUIModel(); |
---|
| 845 | |
---|
| 846 | List<IGUIElementSpec> guiElementPath = new ArrayList<IGUIElementSpec>(); |
---|
| 847 | guiElementPath.add(new TestGUIElementSpec("guiElem1")); |
---|
| 848 | guiElementPath.add(new TestGUIElementSpec("guiElem2")); |
---|
| 849 | guiElementPath.add(new TestGUIElementSpec("guiElem3")); |
---|
| 850 | guiElementPath.add(new TestGUIElementSpec("guiElem4")); |
---|
| 851 | |
---|
| 852 | model.integratePath(guiElementPath, guiElementFactory); |
---|
| 853 | |
---|
| 854 | guiElementPath.remove(2); |
---|
| 855 | guiElementPath.remove(2); |
---|
| 856 | |
---|
| 857 | guiElementPath.add(new TestGUIElementSpec("guiElem5")); |
---|
| 858 | guiElementPath.add(new TestGUIElementSpec("guiElem6")); |
---|
| 859 | |
---|
| 860 | IGUIElement target = model.integratePath(guiElementPath, guiElementFactory); |
---|
| 861 | |
---|
| 862 | guiElementPath.remove(3); |
---|
| 863 | |
---|
| 864 | guiElementPath.add(new TestGUIElementSpec("guiElem7")); |
---|
| 865 | guiElementPath.add(new TestGUIElementSpec("guiElem8")); |
---|
| 866 | |
---|
| 867 | model.integratePath(guiElementPath, guiElementFactory); |
---|
| 868 | |
---|
| 869 | guiElementPath.remove(1); |
---|
| 870 | guiElementPath.remove(1); |
---|
| 871 | guiElementPath.remove(1); |
---|
| 872 | guiElementPath.remove(1); |
---|
| 873 | |
---|
| 874 | guiElementPath.add(new TestGUIElementSpec("guiElem9")); |
---|
| 875 | guiElementPath.add(new TestGUIElementSpec("guiElem10")); |
---|
| 876 | |
---|
| 877 | model.integratePath(guiElementPath, guiElementFactory); |
---|
| 878 | |
---|
| 879 | // the model created is |
---|
| 880 | // guiElem1 |
---|
| 881 | // |-- guiElem2 |
---|
| 882 | // | |-- guiElem3 |
---|
| 883 | // | | \-- guiElem4 |
---|
| 884 | // | | |
---|
| 885 | // | \-- guiElem5 |
---|
| 886 | // | |-- guiElem6 |
---|
| 887 | // | \-- guiElem7 |
---|
| 888 | // | \-- guiElem8 |
---|
| 889 | // \-- guiElem9 |
---|
| 890 | // \-- guiElem10 |
---|
| 891 | |
---|
| 892 | GUIModel.Traverser traverser = model.getTraverser(target); |
---|
| 893 | assertNotNull(traverser); |
---|
| 894 | assertFalse(traverser.hasFirstChild()); |
---|
| 895 | assertNull(traverser.firstChild()); |
---|
| 896 | assertTrue(traverser.hasNextSibling()); |
---|
| 897 | |
---|
| 898 | // guiElem7 |
---|
| 899 | IGUIElement element = traverser.nextSibling(); |
---|
| 900 | assertNotNull(element); |
---|
| 901 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
| 902 | assertEquals("guiElem7", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
| 903 | assertTrue(traverser.hasFirstChild()); |
---|
| 904 | assertFalse(traverser.hasNextSibling()); |
---|
| 905 | assertNull(traverser.nextSibling()); |
---|
| 906 | |
---|
| 907 | // guiElem8 |
---|
| 908 | element = traverser.firstChild(); |
---|
| 909 | assertNotNull(element); |
---|
| 910 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
| 911 | assertEquals("guiElem8", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
| 912 | assertFalse(traverser.hasFirstChild()); |
---|
| 913 | assertNull(traverser.firstChild()); |
---|
| 914 | assertFalse(traverser.hasNextSibling()); |
---|
| 915 | assertNull(traverser.nextSibling()); |
---|
| 916 | |
---|
| 917 | // guiElem7 |
---|
| 918 | element = traverser.parent(); |
---|
| 919 | assertNotNull(element); |
---|
| 920 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
| 921 | assertEquals("guiElem7", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
| 922 | assertTrue(traverser.hasFirstChild()); |
---|
| 923 | assertFalse(traverser.hasNextSibling()); |
---|
| 924 | assertNull(traverser.nextSibling()); |
---|
| 925 | |
---|
| 926 | // guiElem5 |
---|
| 927 | element = traverser.parent(); |
---|
| 928 | assertNotNull(element); |
---|
| 929 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
| 930 | assertEquals("guiElem5", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
| 931 | assertTrue(traverser.hasFirstChild()); |
---|
| 932 | assertFalse(traverser.hasNextSibling()); |
---|
| 933 | assertNull(traverser.nextSibling()); |
---|
| 934 | |
---|
| 935 | // guiElem2 |
---|
| 936 | element = traverser.parent(); |
---|
| 937 | assertNotNull(element); |
---|
| 938 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
| 939 | assertEquals("guiElem2", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
| 940 | assertTrue(traverser.hasFirstChild()); |
---|
| 941 | assertTrue(traverser.hasNextSibling()); |
---|
| 942 | |
---|
| 943 | // guiElem9 |
---|
| 944 | element = traverser.nextSibling(); |
---|
| 945 | assertNotNull(element); |
---|
| 946 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
| 947 | assertEquals("guiElem9", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
| 948 | assertTrue(traverser.hasFirstChild()); |
---|
| 949 | assertFalse(traverser.hasNextSibling()); |
---|
| 950 | assertNull(traverser.nextSibling()); |
---|
| 951 | |
---|
| 952 | // guiElem10 |
---|
| 953 | element = traverser.firstChild(); |
---|
| 954 | assertNotNull(element); |
---|
| 955 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
| 956 | assertEquals("guiElem10", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
| 957 | assertFalse(traverser.hasFirstChild()); |
---|
| 958 | assertNull(traverser.firstChild()); |
---|
| 959 | assertFalse(traverser.hasNextSibling()); |
---|
| 960 | assertNull(traverser.nextSibling()); |
---|
| 961 | |
---|
| 962 | // guiElem9 |
---|
| 963 | element = traverser.parent(); |
---|
| 964 | assertNotNull(element); |
---|
| 965 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
| 966 | assertEquals("guiElem9", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
| 967 | assertTrue(traverser.hasFirstChild()); |
---|
| 968 | assertFalse(traverser.hasNextSibling()); |
---|
| 969 | assertNull(traverser.nextSibling()); |
---|
| 970 | |
---|
| 971 | // guiElem1 |
---|
| 972 | element = traverser.parent(); |
---|
| 973 | assertNotNull(element); |
---|
| 974 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
| 975 | assertEquals("guiElem1", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
| 976 | assertTrue(traverser.hasFirstChild()); |
---|
| 977 | assertFalse(traverser.hasNextSibling()); |
---|
| 978 | assertNull(traverser.nextSibling()); |
---|
| 979 | |
---|
| 980 | assertNull(traverser.parent()); |
---|
| 981 | } |
---|
| 982 | |
---|
| 983 | /** |
---|
| 984 | * |
---|
| 985 | * @author Patrick Harms |
---|
| 986 | */ |
---|
| 987 | private class TestGUIElementFactory implements IGUIElementFactory { |
---|
| 988 | |
---|
| 989 | /* (non-Javadoc) |
---|
| 990 | * @see IGUIElementFactory#instantiateGUIElement(IGUIElementSpec, IGUIElement) |
---|
| 991 | */ |
---|
| 992 | @Override |
---|
| 993 | public IGUIElement instantiateGUIElement(IGUIElementSpec specification, IGUIElement parent) |
---|
| 994 | throws GUIModelConfigurationException |
---|
| 995 | { |
---|
| 996 | assertTrue(specification instanceof TestGUIElementSpec); |
---|
| 997 | |
---|
| 998 | return new TestGUIElement((TestGUIElementSpec) specification, parent); |
---|
| 999 | } |
---|
| 1000 | |
---|
| 1001 | } |
---|
| 1002 | |
---|
| 1003 | /** |
---|
| 1004 | * |
---|
| 1005 | * @author Patrick Harms |
---|
| 1006 | */ |
---|
| 1007 | private class TestGUIElementSpec implements IGUIElementSpec { |
---|
| 1008 | |
---|
| 1009 | /** */ |
---|
| 1010 | private static final long serialVersionUID = 1L; |
---|
| 1011 | |
---|
| 1012 | /** */ |
---|
| 1013 | private String id; |
---|
| 1014 | |
---|
| 1015 | /** */ |
---|
| 1016 | private String similarityId; |
---|
| 1017 | |
---|
| 1018 | /** |
---|
| 1019 | * |
---|
| 1020 | */ |
---|
| 1021 | public TestGUIElementSpec(String id) { |
---|
| 1022 | this(id, ""); |
---|
| 1023 | } |
---|
| 1024 | |
---|
| 1025 | /** |
---|
| 1026 | * |
---|
| 1027 | */ |
---|
| 1028 | public TestGUIElementSpec(String id, String similarityId) { |
---|
| 1029 | this.id = id; |
---|
| 1030 | this.similarityId = similarityId; |
---|
| 1031 | assertNotNull(id); |
---|
| 1032 | assertNotNull(similarityId); |
---|
| 1033 | } |
---|
| 1034 | |
---|
| 1035 | /* (non-Javadoc) |
---|
| 1036 | * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getType() |
---|
| 1037 | */ |
---|
| 1038 | @Override |
---|
| 1039 | public String getType() { |
---|
| 1040 | return "TestGUIElement"; |
---|
| 1041 | } |
---|
| 1042 | |
---|
| 1043 | /* (non-Javadoc) |
---|
| 1044 | * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getTypeHierarchy() |
---|
| 1045 | */ |
---|
| 1046 | @Override |
---|
| 1047 | public String[] getTypeHierarchy() { |
---|
| 1048 | return new String[] { "TestGUIElement" }; |
---|
| 1049 | } |
---|
| 1050 | |
---|
| 1051 | /* (non-Javadoc) |
---|
| 1052 | * @see IGUIElementSpec#getSimilarity(IGUIElementSpec) |
---|
| 1053 | */ |
---|
| 1054 | @Override |
---|
| 1055 | public boolean getSimilarity(IGUIElementSpec other) { |
---|
| 1056 | return (other instanceof TestGUIElementSpec ? |
---|
| 1057 | ((TestGUIElementSpec) other).similarityId.equals(similarityId) : false); |
---|
| 1058 | } |
---|
| 1059 | |
---|
| 1060 | /* (non-Javadoc) |
---|
| 1061 | * @see java.lang.Object#equals(java.lang.Object) |
---|
| 1062 | */ |
---|
| 1063 | @Override |
---|
| 1064 | public boolean equals(Object other) { |
---|
| 1065 | return (other instanceof TestGUIElementSpec ? |
---|
| 1066 | ((TestGUIElementSpec) other).id.equals(id) : false); |
---|
| 1067 | } |
---|
| 1068 | |
---|
| 1069 | } |
---|
| 1070 | |
---|
| 1071 | /** |
---|
| 1072 | * |
---|
| 1073 | * @author Patrick Harms |
---|
| 1074 | */ |
---|
| 1075 | public class TestGUIElement extends AbstractDefaultGUIElement implements IGUIElement { |
---|
| 1076 | |
---|
| 1077 | /** */ |
---|
| 1078 | private static final long serialVersionUID = 1L; |
---|
| 1079 | |
---|
| 1080 | /** |
---|
| 1081 | * |
---|
| 1082 | */ |
---|
| 1083 | public TestGUIElement(TestGUIElementSpec specification, IGUIElement parent) { |
---|
| 1084 | super(specification, parent); |
---|
| 1085 | } |
---|
| 1086 | |
---|
| 1087 | /* (non-Javadoc) |
---|
| 1088 | * @see de.ugoe.cs.autoquest.eventcore.IEventTarget#getPlatform() |
---|
| 1089 | */ |
---|
| 1090 | @Override |
---|
| 1091 | public String getPlatform() { |
---|
| 1092 | return "TEST"; |
---|
| 1093 | } |
---|
| 1094 | |
---|
| 1095 | /* (non-Javadoc) |
---|
| 1096 | * @see de.ugoe.cs.autoquest.eventcore.IEventTarget#getStringIdentifier() |
---|
| 1097 | */ |
---|
| 1098 | @Override |
---|
| 1099 | public String getStringIdentifier() { |
---|
| 1100 | return ((TestGUIElementSpec) super.getSpecification()).id; |
---|
| 1101 | } |
---|
| 1102 | |
---|
| 1103 | /* (non-Javadoc) |
---|
| 1104 | * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#updateSpecification(de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec) |
---|
| 1105 | */ |
---|
| 1106 | @Override |
---|
| 1107 | public void updateSpecification(IGUIElementSpec furtherSpec) { |
---|
| 1108 | // do nothing |
---|
| 1109 | } |
---|
| 1110 | |
---|
| 1111 | } |
---|
| 1112 | |
---|
| 1113 | } |
---|