PraktikumHolonsTestObjectController.java 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. package tests;
  2. import static org.junit.Assert.assertTrue;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5. import classes.AbstractCpsObject;
  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("Total Energy does not match", ((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"))
  65. .getCurrentEnergy() == -1800 + ((i * (i + 1)) / 2) * -10);
  66. assertTrue("Number of Elements does not Match",
  67. ((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House")).getElements().size() == 6 + i);
  68. }
  69. // controller.deleteElementInCategory("Building", "House", "B");
  70. // controller.deleteElementInCategory("Building", "House", "D");
  71. // controller.deleteElementInCategory("Building", "House", "F");
  72. // controller.deleteElementInCategory("Building", "House", "G");
  73. // controller.deleteElementInCategory("Building", "House", "H");
  74. // controller.deleteElementInCategory("Building", "House", "I");
  75. // controller.deleteElementInCategory("Building", "House", "Z");
  76. // controller.deleteElementInCategory("Building", "House", "TV");
  77. // assertTrue("Element:B was Found",
  78. // mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "B") == null);
  79. // assertTrue("Element:D was Found",
  80. // mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "D") == null);
  81. // assertTrue("Element:F was Found",
  82. // mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "F") == null);
  83. // assertTrue("Element:G was Found",
  84. // mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "G") == null);
  85. // assertTrue("Element:H was Found",
  86. // mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "H") == null);
  87. // assertTrue("Element:I was Found",
  88. // mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "I") == null);
  89. // assertTrue("Element:Z was Found",
  90. // mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "Z") == null);
  91. // assertTrue("Element:TV was Found",
  92. // mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "TV") == null);
  93. }
  94. /**
  95. * Tests for Adding and Deleting Objects on the Canvas.
  96. */
  97. @Test
  98. public void testAddingAndDeletingInCanvas() {
  99. for (int i = 0; i < 100; i++) {
  100. cvs.addNewObject(new HolonObject(mp.searchCatObj(mp.searchCat("Building"), "House")));
  101. }
  102. // for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
  103. // for (int i = 0; i < 27; i++) {
  104. // controller.addNewElementIntoCanvasObject(cps.getId(), adapter.generate(i), 1, -100);
  105. // assertTrue("Element:" + adapter.generate(i) + " was not Created",
  106. // mp.searchEle((HolonObject) mp.searchByID(cps.getId()), adapter.generate(i)) != null);
  107. // }
  108. // assertTrue("Element:B was not Found", mp.searchEle((HolonObject) mp.searchByID(cps.getId()), "B") != null);
  109. // assertTrue("Element:D was not Found", mp.searchEle((HolonObject) mp.searchByID(cps.getId()), "D") != null);
  110. // assertTrue("Element:F was not Found", mp.searchEle((HolonObject) mp.searchByID(cps.getId()), "F") != null);
  111. // assertTrue("Element:G was not Found", mp.searchEle((HolonObject) mp.searchByID(cps.getId()), "G") != null);
  112. // assertTrue("Element:H was not Found", mp.searchEle((HolonObject) mp.searchByID(cps.getId()), "H") != null);
  113. // assertTrue("Element:I was not Found", mp.searchEle((HolonObject) mp.searchByID(cps.getId()), "I") != null);
  114. // assertTrue("Element:B was not Found", mp.searchEle((HolonObject) mp.searchByID(cps.getId()), "B") != null);
  115. // }
  116. for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
  117. int size = model.getSelectedCpsObjects().size();
  118. controller.addSelectedObject(cps);
  119. assertTrue("Size does not Match", model.getSelectedCpsObjects().size() == size + 1);
  120. }
  121. for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
  122. System.out.println(model.getSelectedCpsObjects().size());
  123. int size = model.getSelectedCpsObjects().size();
  124. controller.deleteSelectedObject(cps);
  125. assertTrue("Size does not Match", model.getSelectedCpsObjects().size() == size - 1);
  126. assertTrue("Object was not unselected", !model.getSelectedCpsObjects().contains(cps));
  127. }
  128. }
  129. }