Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

LoggingPluginTest.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Copyright (c) 2006-2010 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.addons.logging;
  23. import com.dmdirc.Channel;
  24. import com.dmdirc.Main;
  25. import com.dmdirc.Server;
  26. import com.dmdirc.Query;
  27. import com.dmdirc.actions.CoreActionType;
  28. import com.dmdirc.config.IdentityManager;
  29. import com.dmdirc.harness.TestLoggingPlugin;
  30. import com.dmdirc.parser.irc.IRCChannelInfo;
  31. import com.dmdirc.addons.ui_dummy.DummyController;
  32. import com.dmdirc.parser.irc.IRCParser;
  33. import com.dmdirc.util.ConfigFile;
  34. import java.net.URI;
  35. import java.util.Map;
  36. import org.junit.BeforeClass;
  37. import org.junit.Test;
  38. import static org.junit.Assert.*;
  39. public class LoggingPluginTest {
  40. private static Server server;
  41. private static Channel channel;
  42. private static Query query;
  43. private static TestLoggingPlugin lp;
  44. @BeforeClass
  45. public static void setUp() throws Exception {
  46. Main.setUI(new DummyController());
  47. IdentityManager.load();
  48. server = new Server(new URI("irc-test://255.255.255.255"),
  49. IdentityManager.getProfiles().get(0));
  50. server.connect();
  51. channel = new Channel(server, new IRCChannelInfo((IRCParser) server.getParser(), "#test"));
  52. query = new Query(server, "foo!bar@baz");
  53. final ConfigFile file = new ConfigFile(LoggingPlugin.class
  54. .getResourceAsStream("plugin.config"));
  55. file.read();
  56. for (Map.Entry<String, String> entry : file.getKeyDomain("defaults").entrySet()) {
  57. IdentityManager.getAddonIdentity().setOption("temp-plugin-logging",
  58. entry.getKey(), entry.getValue());
  59. }
  60. lp = new TestLoggingPlugin();
  61. lp.setDomain("temp-plugin-logging");
  62. lp.domainUpdated();
  63. lp.onLoad();
  64. }
  65. @Test
  66. public void testChannelOpened() {
  67. lp.processEvent(CoreActionType.CHANNEL_OPENED, new StringBuffer(),
  68. channel);
  69. assertTrue(lp.lines.containsKey("#test"));
  70. assertEquals(2, lp.lines.get("#test").size());
  71. assertTrue(lp.lines.get("#test").get(1).isEmpty());
  72. assertTrue(lp.lines.get("#test").get(0).indexOf("opened") > -1);
  73. lp.lines.clear();
  74. }
  75. @Test
  76. public void testChannelClosed() {
  77. lp.processEvent(CoreActionType.CHANNEL_CLOSED, new StringBuffer(),
  78. channel);
  79. assertTrue(lp.lines.containsKey("#test"));
  80. assertEquals(1, lp.lines.get("#test").size());
  81. assertTrue(lp.lines.get("#test").get(0).indexOf("closed") > -1);
  82. lp.lines.clear();
  83. }
  84. @Test
  85. public void testQueryOpened() {
  86. lp.processEvent(CoreActionType.QUERY_OPENED, new StringBuffer(),
  87. query);
  88. assertTrue(lp.lines.containsKey("foo!bar@baz"));
  89. assertEquals(3, lp.lines.get("foo!bar@baz").size());
  90. assertTrue(lp.lines.get("foo!bar@baz").get(2).isEmpty());
  91. assertTrue(lp.lines.get("foo!bar@baz").get(1).indexOf("foo!bar@baz") > -1);
  92. assertTrue(lp.lines.get("foo!bar@baz").get(0).indexOf("opened") > -1);
  93. lp.lines.clear();
  94. }
  95. @Test
  96. public void testQueryClosed() {
  97. lp.processEvent(CoreActionType.QUERY_CLOSED, new StringBuffer(),
  98. query);
  99. assertTrue(lp.lines.containsKey("foo!bar@baz"));
  100. assertEquals(1, lp.lines.get("foo!bar@baz").size());
  101. assertTrue(lp.lines.get("foo!bar@baz").get(0).indexOf("closed") > -1);
  102. lp.lines.clear();
  103. }
  104. }