Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

LoggingPluginTest.java 4.6KB

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