PraktikumHolonsTestCategoryController.java 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. package tests;
  2. import static org.junit.Assert.*;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5. import classes.HolonObject;
  6. import ui.controller.CategoryController;
  7. import ui.controller.Control;
  8. import ui.controller.MultiPurposeController;
  9. import ui.model.Model;
  10. /**
  11. * Tests for the CategoryController.
  12. *
  13. * @author Gruppe14
  14. */
  15. public class PraktikumHolonsTestCategoryController {
  16. protected PraktikumHolonsAdapter adapter;
  17. protected Model model;
  18. protected MultiPurposeController mp;
  19. protected CategoryController controller;
  20. /**
  21. * Setup for the Tests.
  22. */
  23. @Before
  24. public void setUp() {
  25. adapter = new PraktikumHolonsAdapter();
  26. model = new Model();
  27. mp = new MultiPurposeController(model);
  28. controller = new CategoryController(model, mp, new Control(model));
  29. }
  30. /**
  31. * tests for the Initial Categories.
  32. */
  33. @Test
  34. public void testInitialCategories() {
  35. assertTrue("Number of Categories is not 3", model.getCategories().size() == 3);
  36. assertTrue("Second Category is not Building", model.getCategories().get(1).getName().equals("Building"));
  37. assertTrue("Category Building is Empty", !model.getCategories().get(1).getObjects().isEmpty());
  38. assertEquals("Object is not a Power Plant", mp.searchCat("Energy").getObjects().get(0).getName(),
  39. "Power Plant");
  40. assertFalse("A Switch should not be a Holon Object",
  41. mp.searchCatObj(mp.searchCat("Component"), "Switch") instanceof HolonObject);
  42. }
  43. /**
  44. * Basic tests for adding new Categories.
  45. */
  46. @Test
  47. public void testAddingCategoriesMinimal() {
  48. controller.addNewCategory("University");
  49. controller.addNewCategory("Hospital");
  50. assertTrue("Number of Categories is not 5", model.getCategories().size() == 5);
  51. controller.addNewCategory("Energy");
  52. assertTrue("Number of Categories is not 6", model.getCategories().size() == 6);
  53. assertTrue("Name of the Duplicate: Energy was not changed to Energy_0",
  54. model.getCategories().get(5).getName().equals("Energy_0"));
  55. controller.addNewCategory("Energy");
  56. assertTrue("Number of Categories is not 7", model.getCategories().size() == 7);
  57. assertTrue("Name of the Duplicate: Energy was not changed to Energy_1",
  58. model.getCategories().get(6).getName().equals("Energy_1"));
  59. }
  60. /**
  61. * Basic tests for deleting Categories.
  62. */
  63. @Test
  64. public void testDeletingCategoriesMinimal() {
  65. assertTrue("Number of Categories is not 3", model.getCategories().size() == 3);
  66. assertTrue("2nd Category does not Match", model.getCategories().get(1).getName().equals("Building"));
  67. controller.deleteCategory("Building");
  68. assertTrue("Number of Categories is not 2", model.getCategories().size() == 2);
  69. assertTrue("Former 2nd Category was not deleted", model.getCategories().get(1).getName().equals("Component"));
  70. controller.deleteCategory("Energy");
  71. assertTrue("Number of Categories is not 1", model.getCategories().size() == 1);
  72. assertTrue("1st Category was not Component", model.getCategories().get(0).getName().equals("Component"));
  73. }
  74. /**
  75. * Extended tests for adding and deleting Categories.
  76. */
  77. @Test
  78. public void testAddingAndDeletingCategoriesExtended() {
  79. for (int i = 1; i <= 50; i++) {
  80. controller.addNewCategory(adapter.generate(i));
  81. assertTrue("Catagory:" + adapter.generate(i) + " was not added", model.getCategories().size() == i + 3);
  82. }
  83. assertEquals("Category does not match", model.getCategories().get(29).getName(), "AA");
  84. controller.deleteCategory("AA");
  85. assertTrue("Catagory:AA was not deleted", model.getCategories().size() == 52);
  86. assertEquals("Category does not match", model.getCategories().get(29).getName(), "AB");
  87. assertEquals("Category does not match", model.getCategories().get(30).getName(), "AC");
  88. controller.deleteCategory("AB");
  89. assertTrue("Catagory:AB was not deleted", model.getCategories().size() == 51);
  90. assertEquals("Category does not match", model.getCategories().get(29).getName(), "AC");
  91. controller.deleteCategory("AD");
  92. assertTrue("Catagory:AD was not deleted", model.getCategories().size() == 50);
  93. assertEquals("Category does not match", model.getCategories().get(29).getName(), "AC");
  94. assertEquals("Category does not match", model.getCategories().get(30).getName(), "AE");
  95. controller.deleteCategory("Energy");
  96. assertTrue("Catagory:Energy was not deleted", model.getCategories().size() == 49);
  97. for (int i = 1; i <= 10; i++) {
  98. controller.deleteCategory(adapter.generate(i));
  99. assertTrue("Catagory was not deleted", model.getCategories().size() == 49 - i);
  100. }
  101. assertEquals("Category does not match", model.getCategories().get(3).getName(), "L");
  102. }
  103. /**
  104. * Basic tests for adding and deleting Objects.
  105. */
  106. @Test
  107. public void testAddingAndDeletingObjectsMinimal() {
  108. controller.addNewHolonObject(mp.searchCat("Energy"), "Power Plant", null, "");
  109. controller.addNewHolonObject(mp.searchCat("Energy"), "Power Plant", null, "");
  110. controller.addNewHolonObject(mp.searchCat("Energy"), "Solar Plant", null, "");
  111. assertTrue("Number of Objects in Energy is not 4", mp.searchCat("Energy").getObjects().size() == 4);
  112. assertTrue("Number of Object-Indices in Energy is not 4", mp.searchCat("Energy").getObjIdx().size() == 4);
  113. assertTrue("Object was not renamed to \"Power Plant_0\" ",
  114. mp.searchCat("Energy").getObjects().get(1).getName().equals("Power Plant"));
  115. assertTrue("Object was not renamed to \"Power Plant_1\" ",
  116. mp.searchCat("Energy").getObjects().get(2).getName().equals("Power Plant"));
  117. assertTrue("3th Object was not \"Power Plant_1\"",
  118. mp.searchCat("Energy").getObjects().get(2).getName().equals("Power Plant"));
  119. controller.deleteObject("Energy", "Power Plant_1");
  120. assertTrue("3th Object was not deleted",
  121. mp.searchCat("Energy").getObjects().get(2).getName().equals("Solar Plant"));
  122. assertTrue("Number of Objects in Energy is not 3", mp.searchCat("Energy").getObjects().size() == 3);
  123. controller.addNewHolonObject(mp.searchCat("Energy"), "Solar Plant", null, "");
  124. assertTrue("Object was not renamed to \"Solar Plant_0\" ",
  125. mp.searchCat("Energy").getObjects().get(3).getName().equals("Solar Plant_0"));
  126. assertTrue("Number of Objects in Energy is not 4", mp.searchCat("Energy").getObjects().size() == 4);
  127. }
  128. /**
  129. * Extended tests for adding and deleting Objects.
  130. */
  131. @Test
  132. public void testAddingAndDeletingObjectsExtended() {
  133. for (int i = 1; i <= 25; i++) {
  134. controller.addNewHolonObject(mp.searchCat("Energy"), adapter.generate(i),null, null);
  135. //creating duplicates
  136. controller.addNewHolonObject(mp.searchCat("Energy"), adapter.generate(i),null, null);
  137. assertTrue("Objects were not added", mp.searchCat("Energy").getObjects().size() == i * 2 + 1);
  138. assertTrue("Object was not renamed to \"" + adapter.generate(i) + "_0\"", mp.searchCat("Energy")
  139. .getObjects().get(i * 2).getName().equals(adapter.generate(i) + "_0"));
  140. }
  141. //deleting the duplicates
  142. controller.deleteObject("Energy", "E_0");
  143. assertTrue("Object was not deleted", mp.searchCatObj(mp.searchCat("Energy"), "E_0") == null);
  144. controller.deleteObject("Energy", "F_0");
  145. assertTrue("Object was not deleted", mp.searchCatObj(mp.searchCat("Energy"), "F_0") == null);
  146. controller.deleteObject("Energy", "G_0");
  147. assertTrue("Object was not deleted", mp.searchCatObj(mp.searchCat("Energy"), "G_0") == null);
  148. controller.deleteObject("Energy", "H_0");
  149. assertTrue("Object was not deleted", mp.searchCatObj(mp.searchCat("Energy"), "H_0") == null);
  150. assertTrue("Number of Objects does not match", mp.searchCat("Energy").getObjects().size() == 47);
  151. }
  152. }