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.

ServerTest.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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;
  23. import com.dmdirc.config.IdentityManager;
  24. import java.net.URI;
  25. import org.junit.BeforeClass;
  26. import org.junit.Test;
  27. import static org.junit.Assert.*;
  28. public class ServerTest {
  29. private static Server server;
  30. @BeforeClass
  31. public static void setUp() throws Exception {
  32. Main.extractCorePlugins("tabcompletion_");
  33. IdentityManager.load();
  34. server = new Server(new URI("irc-test://255.255.255.255"),
  35. IdentityManager.getCustomIdentities("profile").get(0));
  36. server.connect();
  37. }
  38. @Test
  39. public void testGetNetworkFromServerName() {
  40. final String[][] tests = {
  41. {"foo.com", "foo.com"},
  42. {"bar.foo.com", "foo.com"},
  43. {"irc.us.foo.com", "foo.com"},
  44. {"irc.foo.co.uk", "foo.co.uk"},
  45. {"com", "com"},
  46. {"localhost", "localhost"},
  47. {"foo.de", "foo.de"}
  48. };
  49. for (String[] test : tests) {
  50. assertEquals(test[1], Server.getNetworkFromServerName(test[0]));
  51. }
  52. }
  53. @Test
  54. public void testDuplicateInviteRemoval() {
  55. server.disconnect();
  56. server.addInvite(new Invite(server, "#chan1", "a!b@c"));
  57. server.addInvite(new Invite(server, "#chan1", "d!e@f"));
  58. assertEquals(1, server.getInvites().size());
  59. //assertEquals("d", server.getInvites().get(0).getSource()[0]);
  60. server.removeInvites("#chan1");
  61. }
  62. @Test
  63. public void testRemoveInvites() {
  64. server.disconnect();
  65. server.addInvite(new Invite(server, "#chan1", "a!b@c"));
  66. server.addInvite(new Invite(server, "#chan2", "d!e@f"));
  67. server.removeInvites("#chan1");
  68. assertEquals(1, server.getInvites().size());
  69. server.removeInvites("#chan2");
  70. assertEquals(0, server.getInvites().size());
  71. }
  72. @Test
  73. public void testRemoveInvitesOnSocketClosed() {
  74. server.reconnect();
  75. server.addInvite(new Invite(server, "#chan1", "a!b@c"));
  76. server.onSocketClosed();
  77. assertEquals(0, server.getInvites().size());
  78. }
  79. /* @Test
  80. public void testNumericActions() throws InterruptedException {
  81. final TestActionListener tal = new TestActionListener();
  82. server.disconnect();
  83. ActionManager.init();
  84. ActionManager.addListener(tal, CoreActionType.SERVER_NUMERIC);
  85. server.reconnect();
  86. Thread.sleep(1000); // Give the parser thread time to run + inject
  87. assertEquals(1, tal.events.keySet().size());
  88. assertTrue(tal.events.containsKey(CoreActionType.SERVER_NUMERIC));
  89. final int[] counts = new int[6];
  90. for (Object[] args : tal.events.values(CoreActionType.SERVER_NUMERIC)) {
  91. counts[(Integer) args[1]]++;
  92. assertSame("Server arg for numeric " + args[1] + " should be same. "
  93. + "Actual: " + args[0].hashCode() + " Expected: " + server.hashCode(),
  94. server, args[0]);
  95. }
  96. assertEquals(1, counts[1]);
  97. assertEquals(1, counts[2]);
  98. assertEquals(1, counts[3]);
  99. assertEquals(1, counts[4]);
  100. assertEquals(2, counts[5]);
  101. server.disconnect();
  102. }*/
  103. }