PraktikumHolonsTestObjectController.java 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. package tests;
  2. import static org.junit.Assert.assertTrue;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5. import classes.AbstractCanvasObject;
  6. import classes.HolonObject;
  7. import ui.controller.CanvasController;
  8. import ui.controller.CategoryController;
  9. import ui.controller.MultiPurposeController;
  10. import ui.controller.ObjectController;
  11. import ui.model.Model;
  12. /**
  13. * Tests for the ObjectController.
  14. *
  15. * @author Gruppe14
  16. */
  17. public class PraktikumHolonsTestObjectController {
  18. protected PraktikumHolonsAdapter adapter;
  19. protected Model model;
  20. protected MultiPurposeController mp;
  21. protected CategoryController cg;
  22. protected CanvasController cvs;
  23. protected ObjectController controller;
  24. /**
  25. * Setup for the Tests.
  26. */
  27. @Before
  28. public void setUp() {
  29. adapter = new PraktikumHolonsAdapter();
  30. model = new Model();
  31. mp = new MultiPurposeController(model);
  32. cg = new CategoryController(model, mp);
  33. cvs = new CanvasController(model, mp);
  34. controller = new ObjectController(model, mp);
  35. }
  36. /**
  37. * Tests for the Initial HolonElements.
  38. */
  39. @Test
  40. public void testInitialHolonElements() {
  41. assertTrue("Number of Elements does not Match",
  42. ((HolonObject) mp.searchCatObj(mp.searchCat("Energy"), "Power Plant")).getElements().size() == 1);
  43. // assertTrue("Element does not Match",
  44. // mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Energy"), "Power Plant"), "Power").getEleName()
  45. // .equals("Power"));
  46. // assertTrue("Element does not Match",
  47. // mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Energy"), "Power Plant"), "Power").getEleName()
  48. // .equals("Power"));
  49. // assertTrue("Total Energy does not Match",
  50. // mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "PC")
  51. // .getTotalEnergy() == -750);
  52. // assertTrue("Non-Existant Element is Found",
  53. // mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "") == null);
  54. }
  55. /**
  56. * Tests for adding and Deleting in Categories.
  57. */
  58. @Test
  59. public void testAddingAndDeletingInCategory() {
  60. controller.addNewElementIntoCategoryObject("Building", "House", "A", 1, -10);
  61. for (int i = 2; i < 27; i++) {
  62. controller.addNewElementIntoCategoryObject("Building", "House", adapter.generate(i), i, -10);
  63. // n(n+1) / 2
  64. assertTrue("Number of Elements does not Match",
  65. ((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House")).getElements().size() == 6 + i);
  66. }
  67. // controller.deleteElementInCategory("Building", "House", "B");
  68. // controller.deleteElementInCategory("Building", "House", "D");
  69. // controller.deleteElementInCategory("Building", "House", "F");
  70. // controller.deleteElementInCategory("Building", "House", "G");
  71. // controller.deleteElementInCategory("Building", "House", "H");
  72. // controller.deleteElementInCategory("Building", "House", "I");
  73. // controller.deleteElementInCategory("Building", "House", "Z");
  74. // controller.deleteElementInCategory("Building", "House", "TV");
  75. // assertTrue("Element:B was Found",
  76. // mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "B") == null);
  77. // assertTrue("Element:D was Found",
  78. // mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "D") == null);
  79. // assertTrue("Element:F was Found",
  80. // mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "F") == null);
  81. // assertTrue("Element:G was Found",
  82. // mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "G") == null);
  83. // assertTrue("Element:H was Found",
  84. // mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "H") == null);
  85. // assertTrue("Element:I was Found",
  86. // mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "I") == null);
  87. // assertTrue("Element:Z was Found",
  88. // mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "Z") == null);
  89. // assertTrue("Element:TV was Found",
  90. // mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "TV") == null);
  91. }
  92. /**
  93. * Tests for Adding and Deleting Objects on the Canvas.
  94. */
  95. @Test
  96. public void testAddingAndDeletingInCanvas() {
  97. for (int i = 0; i < 100; i++) {
  98. cvs.addNewObject(new HolonObject(mp.searchCatObj(mp.searchCat("Building"), "House")));
  99. }
  100. // for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
  101. // for (int i = 0; i < 27; i++) {
  102. // controller.addNewElementIntoCanvasObject(cps.getId(), adapter.generate(i), 1, -100);
  103. // assertTrue("Element:" + adapter.generate(i) + " was not Created",
  104. // mp.searchEle((HolonObject) mp.searchByID(cps.getId()), adapter.generate(i)) != null);
  105. // }
  106. // assertTrue("Element:B was not Found", mp.searchEle((HolonObject) mp.searchByID(cps.getId()), "B") != null);
  107. // assertTrue("Element:D was not Found", mp.searchEle((HolonObject) mp.searchByID(cps.getId()), "D") != null);
  108. // assertTrue("Element:F was not Found", mp.searchEle((HolonObject) mp.searchByID(cps.getId()), "F") != null);
  109. // assertTrue("Element:G was not Found", mp.searchEle((HolonObject) mp.searchByID(cps.getId()), "G") != null);
  110. // assertTrue("Element:H was not Found", mp.searchEle((HolonObject) mp.searchByID(cps.getId()), "H") != null);
  111. // assertTrue("Element:I was not Found", mp.searchEle((HolonObject) mp.searchByID(cps.getId()), "I") != null);
  112. // assertTrue("Element:B was not Found", mp.searchEle((HolonObject) mp.searchByID(cps.getId()), "B") != null);
  113. // }
  114. for (AbstractCanvasObject cps : model.getObjectsOnCanvas()) {
  115. int size = model.getSelectedCpsObjects().size();
  116. controller.addSelectedObject(cps);
  117. assertTrue("Size does not Match", model.getSelectedCpsObjects().size() == size + 1);
  118. }
  119. for (AbstractCanvasObject cps : model.getObjectsOnCanvas()) {
  120. System.out.println(model.getSelectedCpsObjects().size());
  121. int size = model.getSelectedCpsObjects().size();
  122. controller.deleteSelectedObject(cps);
  123. assertTrue("Size does not Match", model.getSelectedCpsObjects().size() == size - 1);
  124. assertTrue("Object was not unselected", !model.getSelectedCpsObjects().contains(cps));
  125. }
  126. }
  127. }