249 lines
8.8 KiB
Java
249 lines
8.8 KiB
Java
package jmri.jmrit.beantable;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
|
import javax.swing.JFrame;
|
|
|
|
import jmri.InstanceManager;
|
|
import jmri.Logix;
|
|
|
|
import jmri.util.*;
|
|
import jmri.util.junit.annotations.DisabledIfHeadless;
|
|
import jmri.util.junit.annotations.ToDo;
|
|
import jmri.util.swing.JemmyUtil;
|
|
|
|
import org.junit.jupiter.api.*;
|
|
|
|
import org.netbeans.jemmy.operators.JButtonOperator;
|
|
import org.netbeans.jemmy.operators.JCheckBoxOperator;
|
|
import org.netbeans.jemmy.operators.JFrameOperator;
|
|
import org.netbeans.jemmy.operators.JTextFieldOperator;
|
|
|
|
/**
|
|
* Tests for the LogixTableAction Class
|
|
* Re-created using JUnit5 with support for the new conditional editors
|
|
* @author Dave Sand Copyright (C) 2017
|
|
*/
|
|
@Timeout(10)
|
|
public class LogixTableActionTest extends AbstractTableActionBase<Logix> {
|
|
|
|
@Test
|
|
public void testCtor() {
|
|
assertNotNull( new LogixTableAction(), "LogixTableActionTest Constructor Return");
|
|
}
|
|
|
|
@Test
|
|
@DisabledIfHeadless
|
|
public void testStringCtor() {
|
|
assertNotNull( new LogixTableAction("test"), "LogixTableActionTest Constructor Return");
|
|
}
|
|
|
|
@Override
|
|
public String getTableFrameName() {
|
|
return Bundle.getMessage("TitleLogixTable"); // NOI18N
|
|
}
|
|
|
|
@Override
|
|
@Test
|
|
public void testGetClassDescription() {
|
|
assertEquals( Bundle.getMessage("TitleLogixTable"), a.getClassDescription(),
|
|
"Logix Table Action class description");
|
|
}
|
|
|
|
/**
|
|
* Check the return value of includeAddButton.
|
|
* <p>
|
|
* The table generated by this action includes an Add Button.
|
|
*/
|
|
@Override
|
|
@Test
|
|
public void testIncludeAddButton() {
|
|
assertTrue( a.includeAddButton(), "Default include add button");
|
|
}
|
|
|
|
@Test
|
|
@DisabledIfHeadless
|
|
public void testLogixBrowser() {
|
|
|
|
LogixTableAction lgxTable = (LogixTableAction) a;
|
|
|
|
lgxTable.browserPressed("IX101"); // NOI18N
|
|
|
|
JFrame frame = JFrameOperator.waitJFrame(Bundle.getMessage("BrowserTitle"), true, true); // NOI18N
|
|
assertNotNull(frame);
|
|
JUnitUtil.dispose(frame);
|
|
}
|
|
|
|
@Test
|
|
@DisabledIfHeadless
|
|
public void testWhereUsed() {
|
|
|
|
LogixTableAction lgxTable = (LogixTableAction) a;
|
|
|
|
lgxTable.makeWhereUsedWindow();
|
|
|
|
JFrame frame = JFrameOperator.waitJFrame(Bundle.getMessage("DisplayWhereUsed"), true, true); // NOI18N
|
|
assertNotNull(frame);
|
|
JUnitUtil.dispose(frame);
|
|
}
|
|
|
|
@Test
|
|
@DisabledIfHeadless
|
|
public void testListEditor() {
|
|
|
|
LogixTableAction lgxTable = (LogixTableAction) a;
|
|
|
|
lgxTable.editPressed("IX101"); // NOI18N
|
|
JFrameOperator frame = new JFrameOperator(Bundle.getMessage("TitleEditLogix")); // NOI18N
|
|
assertNotNull(frame);
|
|
new JButtonOperator(frame, Bundle.getMessage("ButtonDone")).push(); // NOI18N
|
|
}
|
|
|
|
@Test
|
|
@DisabledIfHeadless
|
|
public void testTreeEditor() {
|
|
|
|
InstanceManager.getDefault(jmri.UserPreferencesManager.class).
|
|
setProperty("jmri.jmrit.beantable.LogixTableAction", "Edit Mode", "TREEEDIT"); // NOI18N
|
|
a.actionPerformed(null);
|
|
LogixTableAction lgxTable = (LogixTableAction) a;
|
|
JFrameOperator lgxFrame = new JFrameOperator(Bundle.getMessage("TitleLogixTable")); // NOI18N
|
|
assertNotNull(lgxFrame);
|
|
|
|
lgxTable.editPressed("IX104"); // NOI18N
|
|
JFrameOperator cdlFrame = new JFrameOperator(Bundle.getMessage("TitleEditLogix")); // NOI18N
|
|
assertNotNull(cdlFrame);
|
|
new JButtonOperator(cdlFrame, Bundle.getMessage("ButtonDone")).push(); // NOI18N
|
|
lgxFrame.dispose();
|
|
}
|
|
|
|
@Test
|
|
@DisabledIfHeadless
|
|
public void testAddLogixAutoName() {
|
|
|
|
LogixTableAction lgxTable = (LogixTableAction) a;
|
|
|
|
lgxTable.actionPerformed(null); // show table
|
|
JFrame lgxFrame = JFrameOperator.waitJFrame(Bundle.getMessage("TitleLogixTable"), true, true); // NOI18N
|
|
assertNotNull( lgxFrame, "Found Logix Frame");
|
|
|
|
lgxTable.addPressed(null);
|
|
JFrameOperator addFrame = new JFrameOperator(Bundle.getMessage("TitleAddLogix")); // NOI18N
|
|
assertNotNull( addFrame, "Found Add Logix Frame");
|
|
|
|
new JCheckBoxOperator(addFrame, 0).clickMouse();
|
|
new JTextFieldOperator(addFrame, 1).setText("Logix 999"); // NOI18N
|
|
new JButtonOperator(addFrame, Bundle.getMessage("ButtonCreate")).push(); // NOI18N
|
|
|
|
Logix chk999 = jmri.InstanceManager.getDefault(jmri.LogixManager.class).getLogix("Logix 999"); // NOI18N
|
|
assertNotNull( chk999, "Verify IX999 Added");
|
|
|
|
// Add creates an edit frame; find and dispose
|
|
JFrame editFrame = JFrameOperator.waitJFrame(Bundle.getMessage("TitleEditLogix"), true, true); // NOI18N
|
|
JUnitUtil.dispose(editFrame);
|
|
|
|
JUnitUtil.dispose(lgxFrame);
|
|
}
|
|
|
|
@Test
|
|
@DisabledIfHeadless
|
|
public void testAddLogix() {
|
|
LogixTableAction lgxTable = (LogixTableAction) a;
|
|
|
|
lgxTable.actionPerformed(null); // show table
|
|
JFrame lgxFrame = JFrameOperator.waitJFrame(Bundle.getMessage("TitleLogixTable"), true, true); // NOI18N
|
|
assertNotNull( lgxFrame, "Found Logix Frame");
|
|
|
|
lgxTable.addPressed(null);
|
|
new org.netbeans.jemmy.QueueTool().waitEmpty();
|
|
JFrameOperator addFrame = new JFrameOperator(Bundle.getMessage("TitleAddLogix")); // NOI18N
|
|
assertNotNull( addFrame, "Found Add Logix Frame");
|
|
|
|
new JTextFieldOperator(addFrame, 0).setText("105"); // NOI18N
|
|
new JTextFieldOperator(addFrame, 1).setText("Logix 105"); // NOI18N
|
|
new JButtonOperator(addFrame, Bundle.getMessage("ButtonCreate")).push(); // NOI18N
|
|
|
|
Logix chk105 = jmri.InstanceManager.getDefault(jmri.LogixManager.class).getLogix("Logix 105"); // NOI18N
|
|
assertNotNull( chk105, "Verify IX105 Added");
|
|
|
|
// Add creates an edit frame; find and dispose
|
|
JFrame editFrame = JFrameOperator.waitJFrame(Bundle.getMessage("TitleEditLogix"), true, true); // NOI18N
|
|
JUnitUtil.dispose(editFrame);
|
|
|
|
JUnitUtil.dispose(lgxFrame);
|
|
}
|
|
|
|
@Test
|
|
@DisabledIfHeadless
|
|
public void testDeleteLogix() throws InterruptedException {
|
|
LogixTableAction lgxTable = (LogixTableAction) a;
|
|
|
|
lgxTable.actionPerformed(null); // show table
|
|
JFrame lgxFrame = JFrameOperator.waitJFrame(Bundle.getMessage("TitleLogixTable"), true, true); // NOI18N
|
|
assertNotNull( lgxFrame, "Found Logix Frame");
|
|
|
|
// Delete IX102, respond No
|
|
Thread t1 = JemmyUtil.createModalDialogOperatorThread(Bundle.getMessage("QuestionTitle"), Bundle.getMessage("ButtonNo")); // NOI18N
|
|
lgxTable.deletePressed("IX102"); // NOI18N
|
|
t1.join();
|
|
Logix chk102 = jmri.InstanceManager.getDefault(jmri.LogixManager.class).getBySystemName("IX102"); // NOI18N
|
|
assertNotNull( chk102, "Verify IX102 Not Deleted");
|
|
|
|
// Delete IX103, respond Yes
|
|
Thread t2 = JemmyUtil.createModalDialogOperatorThread(Bundle.getMessage("QuestionTitle"), Bundle.getMessage("ButtonYes")); // NOI18N
|
|
lgxTable.deletePressed("IX103"); // NOI18N
|
|
t2.join();
|
|
Logix chk103 = jmri.InstanceManager.getDefault(jmri.LogixManager.class).getBySystemName("IX103"); // NOI18N
|
|
assertNull( chk103, "Verify IX103 Is Deleted");
|
|
|
|
JUnitUtil.dispose(lgxFrame);
|
|
}
|
|
|
|
@Override
|
|
public String getAddFrameName(){
|
|
return Bundle.getMessage("TitleAddLogix");
|
|
}
|
|
|
|
@Test
|
|
@Disabled("Logix create frame does not have a hardware address")
|
|
@Override
|
|
@ToDo("Re-write parent class test to use the right name")
|
|
public void testAddThroughDialog() {
|
|
}
|
|
|
|
@Test
|
|
@Disabled("Logix create frame does not have a hardware address")
|
|
@Override
|
|
@ToDo("Re-write parent class test to use the right name, or add without dialog")
|
|
public void testEditButton() {
|
|
}
|
|
|
|
@BeforeEach
|
|
@Override
|
|
public void setUp() {
|
|
JUnitUtil.setUp();
|
|
JUnitUtil.resetProfileManager();
|
|
JUnitUtil.initLogixManager();
|
|
JUnitUtil.initDefaultUserMessagePreferences();
|
|
|
|
InstanceManager.getDefault(jmri.LogixManager.class).createNewLogix("IX101", "Logix 101");
|
|
InstanceManager.getDefault(jmri.LogixManager.class).createNewLogix("IX102", "Logix 102");
|
|
InstanceManager.getDefault(jmri.LogixManager.class).createNewLogix("IX103", "Logix 103");
|
|
InstanceManager.getDefault(jmri.LogixManager.class).createNewLogix("IX104", "Logix 104");
|
|
|
|
helpTarget = "package.jmri.jmrit.beantable.LogixTable";
|
|
a = new LogixTableAction();
|
|
}
|
|
|
|
@AfterEach
|
|
@Override
|
|
public void tearDown() {
|
|
a = null;
|
|
JUnitUtil.deregisterBlockManagerShutdownTask();
|
|
JUnitUtil.tearDown();
|
|
}
|
|
}
|