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.

ActionsGroupPanelTest.java 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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.dialogs.actionsmanager;
  23. import com.dmdirc.actions.Action;
  24. import com.dmdirc.actions.ActionGroup;
  25. import com.dmdirc.actions.CoreActionType;
  26. import com.dmdirc.actions.interfaces.ActionType;
  27. import com.dmdirc.harness.ui.WindowButtonHandler;
  28. import java.util.ArrayList;
  29. import java.util.Arrays;
  30. import org.junit.Before;
  31. import org.junit.Test;
  32. import org.uispec4j.Panel;
  33. import org.uispec4j.Table;
  34. import org.uispec4j.UISpecTestCase;
  35. import org.uispec4j.interception.WindowInterceptor;
  36. import static org.mockito.Mockito.*;
  37. public class ActionsGroupPanelTest extends UISpecTestCase {
  38. private Action action1, action2, action3, action4;
  39. private ActionGroup group;
  40. private Panel panel;
  41. private Table table;
  42. @Before
  43. @Override
  44. public void setUp() {
  45. action1 = mock(Action.class);
  46. when(action1.getName()).thenReturn("name 1");
  47. when(action1.getTriggers()).thenReturn(new ActionType[] {
  48. CoreActionType.ACTION_CREATED, CoreActionType.ACTION_DELETED,
  49. });
  50. when(action1.getResponse()).thenReturn(new String[] { "A" });
  51. action2 = mock(Action.class);
  52. when(action2.getName()).thenReturn("name 2");
  53. when(action2.getTriggers()).thenReturn(new ActionType[] {
  54. CoreActionType.ACTION_CREATED
  55. });
  56. when(action2.getResponse()).thenReturn(new String[0]);
  57. action3 = mock(Action.class);
  58. when(action3.getName()).thenReturn("name 3");
  59. when(action3.getTriggers()).thenReturn(new ActionType[] {
  60. CoreActionType.ACTION_CREATED, CoreActionType.ACTION_DELETED,
  61. });
  62. when(action3.getResponse()).thenReturn(new String[] {
  63. "Response line 1",
  64. "Response line 2",
  65. "Response line 3",
  66. });
  67. action4 = mock(Action.class);
  68. when(action4.getName()).thenReturn("name 4");
  69. when(action4.getTriggers()).thenReturn(new ActionType[] {
  70. CoreActionType.ACTION_CREATED
  71. });
  72. when(action4.getResponse()).thenReturn(new String[] {
  73. "Response line 1",
  74. "Response line 2",
  75. "Response line 4",
  76. });
  77. group = mock(ActionGroup.class);
  78. when(group.getActions()).thenReturn(new ArrayList<Action>(Arrays.asList(new Action[]{
  79. action1, action2, action3, action4,
  80. })));
  81. panel = new Panel(new ActionsGroupPanel(null, group));
  82. table = panel.getTable();
  83. }
  84. @Test
  85. public void testTable() {
  86. assertTrue(table.getHeader().contentEquals("Name", "Trigger", "Response"));
  87. assertTrue(table.contentEquals(new String[][]{
  88. {"name 1", "Action created", "A"},
  89. {"name 2", "Action created", ""},
  90. {"name 3", "Action created", "Response line 1, Response line 2, Response line 3"},
  91. {"name 4", "Action created", "Response line 1, Response line 2, Response line 4"},
  92. }));
  93. }
  94. @Test
  95. public void testTableSorting() {
  96. assertTrue(table.getHeader().contentEquals("Name", "Trigger", "Response"));
  97. table.getHeader().click("Name");
  98. assertTrue(table.contentEquals(new String[][]{
  99. {"name 4", "Action created", "Response line 1, Response line 2, Response line 4"},
  100. {"name 3", "Action created", "Response line 1, Response line 2, Response line 3"},
  101. {"name 2", "Action created", ""},
  102. {"name 1", "Action created", "A"},
  103. }));
  104. table.getHeader().click("Response");
  105. assertTrue(table.contentEquals(new String[][]{
  106. {"name 2", "Action created", ""},
  107. {"name 1", "Action created", "A"},
  108. {"name 3", "Action created", "Response line 1, Response line 2, Response line 3"},
  109. {"name 4", "Action created", "Response line 1, Response line 2, Response line 4"},
  110. }));
  111. }
  112. @Test
  113. public void testDeletingCancel() {
  114. table.selectRow(1);
  115. WindowInterceptor.init(panel.getButton("Delete").triggerClick())
  116. .process(new WindowButtonHandler("DMDirc: Confirm deletion", "No")).run();
  117. assertTrue(table.contentEquals(new String[][]{
  118. {"name 1", "Action created", "A"},
  119. {"name 2", "Action created", ""},
  120. {"name 3", "Action created", "Response line 1, Response line 2, Response line 3"},
  121. {"name 4", "Action created", "Response line 1, Response line 2, Response line 4"},
  122. }));
  123. verify(group, never()).deleteAction((Action) anyObject());
  124. }
  125. public void testDeletingOk() {
  126. table.selectRow(1);
  127. WindowInterceptor.init(panel.getButton("Delete").triggerClick())
  128. .process(new WindowButtonHandler("DMDirc: Confirm deletion", "Yes")).run();
  129. verify(group).deleteAction(same(action2));
  130. }
  131. public void testDeletingSorted() {
  132. table.getHeader().click("Name");
  133. table.selectRow(1);
  134. WindowInterceptor.init(panel.getButton("Delete").triggerClick())
  135. .process(new WindowButtonHandler("DMDirc: Confirm deletion", "Yes")).run();
  136. verify(group).deleteAction(same(action3));
  137. }
  138. public void testTableDeleting() {
  139. assertTrue(table.contentEquals(new String[][]{
  140. {"name 1", "Action created", "A"},
  141. {"name 2", "Action created", ""},
  142. {"name 3", "Action created", "Response line 1, Response line 2, Response line 3"},
  143. {"name 4", "Action created", "Response line 1, Response line 2, Response line 4"},
  144. }));
  145. when(group.getActions()).thenReturn(new ArrayList<Action>(Arrays.asList(new Action[]{
  146. action1, action3, action4,
  147. })));
  148. ((ActionsGroupPanel) panel.getAwtComponent()).actionDeleted("name 2");
  149. ((ActionsGroupPanel) panel.getAwtComponent()).actionDeleted("name 7");
  150. assertTrue(table.contentEquals(new String[][]{
  151. {"name 1", "Action created", "A"},
  152. {"name 3", "Action created", "Response line 1, Response line 2, Response line 3"},
  153. {"name 4", "Action created", "Response line 1, Response line 2, Response line 4"},
  154. }));
  155. }
  156. }