Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

ActionTest.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
  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.util.ConfigFile;
  25. import com.dmdirc.util.InvalidConfigFileException;
  26. import com.dmdirc.util.TextFile;
  27. import java.io.File;
  28. import java.io.IOException;
  29. import java.util.ArrayList;
  30. import java.util.Arrays;
  31. import org.junit.Test;
  32. import static org.junit.Assert.*;
  33. public class ActionTest extends junit.framework.TestCase {
  34. private static Action action;
  35. @Test
  36. public void testSave() {
  37. action = new Action("unit-test", "test1", new ActionType[0],
  38. new String[0], new ArrayList<ActionCondition>(), null);
  39. assertTrue("Action constructor must create new file",
  40. new File(ActionManager.getDirectory() + "unit-test"
  41. + File.separator + "test1").isFile());
  42. }
  43. @Test
  44. public void testSetGroup() {
  45. action.setGroup("unit-test-two");
  46. assertFalse("setGroup must remove old file",
  47. new File(ActionManager.getDirectory() + "unit-test"
  48. + File.separator + "test1").isFile());
  49. assertTrue("setGroup must create new file",
  50. new File(ActionManager.getDirectory() + "unit-test-two"
  51. + File.separator + "test1").isFile());
  52. }
  53. @Test
  54. public void testSetName() {
  55. action.setName("test2");
  56. assertFalse("setName must remove old file",
  57. new File(ActionManager.getDirectory() + "unit-test-two"
  58. + File.separator + "test1").isFile());
  59. assertTrue("setName must create new file",
  60. new File(ActionManager.getDirectory() + "unit-test-two"
  61. + File.separator + "test2").isFile());
  62. }
  63. @Test
  64. public void testDelete() {
  65. action.delete();
  66. assertFalse("delete must remove file",
  67. new File(ActionManager.getDirectory() + "unit-test-two"
  68. + File.separator + "test2").isFile());
  69. }
  70. @Test
  71. public void testRead() throws IOException, InvalidConfigFileException {
  72. ActionManager.init();
  73. final Action action = new Action("unit-test", "doesn't_exist");
  74. action.config = new ConfigFile(new TextFile(getClass().getResourceAsStream("action1")));
  75. action.config.read();
  76. action.loadActionFromConfig();
  77. assertTrue(Arrays.equals(action.getTriggers(),
  78. new ActionType[]{CoreActionType.SERVER_AWAY}));
  79. assertEquals("(0&1)", action.getConditionTree().toString());
  80. assertTrue(Arrays.equals(action.getResponse(), new String[]{"/away"}));
  81. assertEquals(new ActionCondition(1, CoreActionComponent.STRING_LENGTH,
  82. CoreActionComparison.INT_EQUALS, "0"), action.getConditions().get(0));
  83. assertEquals(new ActionCondition("foo", CoreActionComparison.STRING_CONTAINS,
  84. "bar"), action.getConditions().get(1));
  85. }
  86. }