123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- /*
- * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
- package com.dmdirc.addons.ui_swing.dialogs.actionsmanager;
-
- import com.dmdirc.actions.Action;
- import com.dmdirc.actions.ActionGroup;
- import com.dmdirc.actions.CoreActionType;
- import com.dmdirc.actions.interfaces.ActionType;
- import com.dmdirc.harness.ui.WindowButtonHandler;
- import java.util.ArrayList;
- import java.util.Arrays;
- import org.junit.Before;
- import org.junit.Test;
- import org.uispec4j.Panel;
- import org.uispec4j.Table;
- import org.uispec4j.UISpecTestCase;
- import org.uispec4j.interception.WindowInterceptor;
- import static org.mockito.Mockito.*;
-
- public class ActionsGroupPanelTest extends UISpecTestCase {
-
- private Action action1, action2, action3, action4;
- private ActionGroup group;
- private Panel panel;
- private Table table;
-
- @Before
- @Override
- public void setUp() {
- action1 = mock(Action.class);
- when(action1.getName()).thenReturn("name 1");
- when(action1.getTriggers()).thenReturn(new ActionType[] {
- CoreActionType.ACTION_CREATED, CoreActionType.ACTION_DELETED,
- });
- when(action1.getResponse()).thenReturn(new String[] { "A" });
-
- action2 = mock(Action.class);
- when(action2.getName()).thenReturn("name 2");
- when(action2.getTriggers()).thenReturn(new ActionType[] {
- CoreActionType.ACTION_CREATED
- });
- when(action2.getResponse()).thenReturn(new String[0]);
-
- action3 = mock(Action.class);
- when(action3.getName()).thenReturn("name 3");
- when(action3.getTriggers()).thenReturn(new ActionType[] {
- CoreActionType.ACTION_CREATED, CoreActionType.ACTION_DELETED,
- });
- when(action3.getResponse()).thenReturn(new String[] {
- "Response line 1",
- "Response line 2",
- "Response line 3",
- });
-
- action4 = mock(Action.class);
- when(action4.getName()).thenReturn("name 4");
- when(action4.getTriggers()).thenReturn(new ActionType[] {
- CoreActionType.ACTION_CREATED
- });
- when(action4.getResponse()).thenReturn(new String[] {
- "Response line 1",
- "Response line 2",
- "Response line 4",
- });
-
- group = mock(ActionGroup.class);
- when(group.getActions()).thenReturn(new ArrayList<Action>(Arrays.asList(new Action[]{
- action1, action2, action3, action4,
- })));
-
- panel = new Panel(new ActionsGroupPanel(null, group));
- table = panel.getTable();
- }
-
- @Test
- public void testTable() {
- assertTrue(table.getHeader().contentEquals("Name", "Trigger", "Response"));
-
- assertTrue(table.contentEquals(new String[][]{
- {"name 1", "Action created", "A"},
- {"name 2", "Action created", ""},
- {"name 3", "Action created", "Response line 1, Response line 2, Response line 3"},
- {"name 4", "Action created", "Response line 1, Response line 2, Response line 4"},
- }));
- }
-
- @Test
- public void testTableSorting() {
- assertTrue(table.getHeader().contentEquals("Name", "Trigger", "Response"));
-
- table.getHeader().click("Name");
-
- assertTrue(table.contentEquals(new String[][]{
- {"name 4", "Action created", "Response line 1, Response line 2, Response line 4"},
- {"name 3", "Action created", "Response line 1, Response line 2, Response line 3"},
- {"name 2", "Action created", ""},
- {"name 1", "Action created", "A"},
- }));
-
- table.getHeader().click("Response");
-
- assertTrue(table.contentEquals(new String[][]{
- {"name 2", "Action created", ""},
- {"name 1", "Action created", "A"},
- {"name 3", "Action created", "Response line 1, Response line 2, Response line 3"},
- {"name 4", "Action created", "Response line 1, Response line 2, Response line 4"},
- }));
- }
-
- @Test
- public void testDeletingCancel() {
- table.selectRow(1);
-
- WindowInterceptor.init(panel.getButton("Delete").triggerClick())
- .process(new WindowButtonHandler("Confirm deletion", "No")).run();
-
- assertTrue(table.contentEquals(new String[][]{
- {"name 1", "Action created", "A"},
- {"name 2", "Action created", ""},
- {"name 3", "Action created", "Response line 1, Response line 2, Response line 3"},
- {"name 4", "Action created", "Response line 1, Response line 2, Response line 4"},
- }));
- verify(group, never()).deleteAction((Action) anyObject());
- }
-
- public void testDeletingOk() {
- table.selectRow(1);
-
- WindowInterceptor.init(panel.getButton("Delete").triggerClick())
- .process(new WindowButtonHandler("Confirm deletion", "Yes")).run();
-
- verify(group).deleteAction(same(action2));
- }
-
- public void testDeletingSorted() {
- table.getHeader().click("Name");
-
- table.selectRow(1);
-
- WindowInterceptor.init(panel.getButton("Delete").triggerClick())
- .process(new WindowButtonHandler("Confirm deletion", "Yes")).run();
-
- verify(group).deleteAction(same(action3));
- }
-
- public void testTableDeleting() {
- assertTrue(table.contentEquals(new String[][]{
- {"name 1", "Action created", "A"},
- {"name 2", "Action created", ""},
- {"name 3", "Action created", "Response line 1, Response line 2, Response line 3"},
- {"name 4", "Action created", "Response line 1, Response line 2, Response line 4"},
- }));
-
- when(group.getActions()).thenReturn(new ArrayList<Action>(Arrays.asList(new Action[]{
- action1, action3, action4,
- })));
-
- ((ActionsGroupPanel) panel.getAwtComponent()).actionDeleted("name 2");
- ((ActionsGroupPanel) panel.getAwtComponent()).actionDeleted("name 7");
-
- assertTrue(table.contentEquals(new String[][]{
- {"name 1", "Action created", "A"},
- {"name 3", "Action created", "Response line 1, Response line 2, Response line 3"},
- {"name 4", "Action created", "Response line 1, Response line 2, Response line 4"},
- }));
- }
-
- }
|