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.

MainFrameTest.java 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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.ui_swing;
  23. import com.dmdirc.Main;
  24. import com.dmdirc.config.IdentityManager;
  25. import com.dmdirc.config.InvalidIdentityFileException;
  26. import com.dmdirc.addons.ui_swing.dialogs.FeedbackDialog;
  27. import com.dmdirc.addons.ui_swing.dialogs.NewServerDialog;
  28. import com.dmdirc.addons.ui_swing.dialogs.about.AboutDialog;
  29. import com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsManagerDialog;
  30. import com.dmdirc.addons.ui_swing.dialogs.aliases.AliasManagerDialog;
  31. import com.dmdirc.addons.ui_swing.dialogs.prefs.SwingPreferencesDialog;
  32. import com.dmdirc.addons.ui_swing.dialogs.profiles.ProfileManagerDialog;
  33. import java.lang.reflect.InvocationTargetException;
  34. import javax.swing.SwingUtilities;
  35. import org.fest.swing.finder.WindowFinder;
  36. import org.fest.swing.fixture.DialogFixture;
  37. import org.fest.swing.fixture.FrameFixture;
  38. import org.junit.After;
  39. import org.junit.Before;
  40. import org.junit.BeforeClass;
  41. import org.junit.Test;
  42. public class MainFrameTest {
  43. private static FrameFixture window;
  44. private DialogFixture newwin;
  45. private static SwingController controller;
  46. @BeforeClass
  47. public static void setUpClass() throws InvalidIdentityFileException {
  48. IdentityManager.load();
  49. controller = new SwingController();
  50. controller.onLoad();
  51. Main.setUI(controller);
  52. }
  53. @Before
  54. public void setUp() {
  55. if (window == null) {
  56. window = new FrameFixture(controller.getMainWindow());
  57. window.show();
  58. }
  59. }
  60. @Test
  61. public void testNewServerDialog() {
  62. window.menuItemWithPath("Server", "New Server...").click();
  63. newwin = WindowFinder.findDialog(NewServerDialog.class)
  64. .withTimeout(5000).using(window.robot);
  65. newwin.requireVisible();
  66. }
  67. @Test
  68. public void testAboutDialog() {
  69. window.menuItemWithPath("Help", "About").click();
  70. newwin = WindowFinder.findDialog(AboutDialog.class)
  71. .withTimeout(5000).using(window.robot);
  72. newwin.requireVisible();
  73. }
  74. @Test
  75. public void testFeedbackDialog() {
  76. window.menuItemWithPath("Help", "Send Feedback").click();
  77. newwin = WindowFinder.findDialog(FeedbackDialog.class)
  78. .withTimeout(5000).using(window.robot);
  79. newwin.requireVisible();
  80. }
  81. @Test
  82. public void testPreferencesDialog() {
  83. window.menuItemWithPath("Settings", "Preferences").click();
  84. newwin = WindowFinder.findDialog(SwingPreferencesDialog.class)
  85. .withTimeout(5000).using(window.robot);
  86. newwin.requireVisible();
  87. }
  88. @Test
  89. public void testProfileManagerDialog() {
  90. window.menuItemWithPath("Settings", "Profile Manager").click();
  91. newwin = WindowFinder.findDialog(ProfileManagerDialog.class)
  92. .withTimeout(5000).using(window.robot);
  93. newwin.requireVisible();
  94. }
  95. @Test
  96. public void testActionsManagerDialog() {
  97. window.menuItemWithPath("Settings", "Actions Manager").click();
  98. newwin = WindowFinder.findDialog(ActionsManagerDialog.class)
  99. .withTimeout(5000).using(window.robot);
  100. newwin.requireVisible();
  101. }
  102. @Test
  103. public void testAliasManagerDialog() {
  104. window.menuItemWithPath("Settings", "Alias Manager").click();
  105. newwin = WindowFinder.findDialog(AliasManagerDialog.class)
  106. .withTimeout(5000).using(window.robot);
  107. newwin.requireVisible();
  108. }
  109. @Test
  110. public void testChannelServerSettings() {
  111. window.menuItemWithPath("Channel", "Channel Settings").requireDisabled();
  112. }
  113. @Test
  114. public void testServerServerSettings() {
  115. window.menuItemWithPath("Server", "Server settings").requireDisabled();
  116. }
  117. @After
  118. public void tearDown() throws InterruptedException, InvocationTargetException {
  119. SwingUtilities.invokeAndWait(new Runnable() {
  120. @Override
  121. public void run() {
  122. close();
  123. }
  124. });
  125. }
  126. protected void close() {
  127. if (newwin != null && newwin.target != null) {
  128. try {
  129. newwin.target.dispose();
  130. } catch (Throwable ex) {
  131. ex.printStackTrace();
  132. }
  133. }
  134. }
  135. }