You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ActionManagerTest.java 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (c) 2006-2011 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.actions;
  23. import com.dmdirc.actions.interfaces.ActionType;
  24. import com.dmdirc.config.IdentityManager;
  25. import java.io.File;
  26. import java.util.ArrayList;
  27. import org.junit.AfterClass;
  28. import org.junit.BeforeClass;
  29. import org.junit.Test;
  30. import static org.junit.Assert.*;
  31. public class ActionManagerTest {
  32. @BeforeClass
  33. public static void setUpClass() throws Exception {
  34. IdentityManager.load();
  35. ActionManager.getActionManager().initialise();
  36. ActionManager.getActionManager().loadUserActions();
  37. tearDownClass();
  38. }
  39. @AfterClass
  40. public static void tearDownClass() throws Exception {
  41. if (ActionManager.getActionManager().getGroupsMap().containsKey("unit-test")) {
  42. ActionManager.getActionManager().deleteGroup("unit-test");
  43. }
  44. if (ActionManager.getActionManager().getGroupsMap().containsKey("unit-test-two")) {
  45. ActionManager.getActionManager().deleteGroup("unit-test-two");
  46. }
  47. }
  48. @Test
  49. public void testMakeGroup() {
  50. ActionManager.getActionManager().createGroup("unit-test");
  51. assertTrue("makeGroup must create the group directory",
  52. new File(ActionManager.getDirectory() + "unit-test").isDirectory());
  53. }
  54. @Test
  55. public void testGetGroup() {
  56. final ActionGroup group = ActionManager.getActionManager().getOrCreateGroup("unit-test");
  57. assertEquals("getGroup must return an ActionGroup with the right name",
  58. "unit-test", group.getName());
  59. }
  60. @Test
  61. public void testRenameGroup() {
  62. ActionManager.getActionManager().changeGroupName("unit-test", "unit-test-two");
  63. assertFalse("renameGroup must unlink the old directory",
  64. new File(ActionManager.getDirectory() + "unit-test").isDirectory());
  65. assertTrue("renameGroup must create the target directory",
  66. new File(ActionManager.getDirectory() + "unit-test-two").isDirectory());
  67. }
  68. @Test
  69. public void testRenameGroupWithAction() {
  70. final Action action = new Action("unit-test-two", "test1", new ActionType[0],
  71. new String[0], new ArrayList<ActionCondition>(), null);
  72. assertSame("Creating a new action must add it to the correct group",
  73. action, ActionManager.getActionManager().getOrCreateGroup("unit-test-two").get(0));
  74. ActionManager.getActionManager().changeGroupName("unit-test-two", "unit-test");
  75. assertFalse("renameGroup must unlink the old directory",
  76. new File(ActionManager.getDirectory() + "unit-test-two").isDirectory());
  77. assertTrue("renameGroup must create the target directory",
  78. new File(ActionManager.getDirectory() + "unit-test").isDirectory());
  79. assertSame("renameGroup must move actions to new group",
  80. action, ActionManager.getActionManager().getOrCreateGroup("unit-test").get(0));
  81. assertEquals("renameGroup must remove actions from old group",
  82. 0, ActionManager.getActionManager().getOrCreateGroup("unit-test-two").size());
  83. }
  84. @Test
  85. public void testRemoveGroup() {
  86. ActionManager.getActionManager().deleteGroup("unit-test");
  87. assertFalse("removeGroup must unlink directory",
  88. new File(ActionManager.getDirectory() + "unit-test").isDirectory());
  89. ActionManager.getActionManager().saveAllActions();
  90. assertFalse("saveActions must not restore removed groups",
  91. new File(ActionManager.getDirectory() + "unit-test").isDirectory());
  92. }
  93. }