117 lines
4.1 KiB
Java
117 lines
4.1 KiB
Java
package jmri.jmrit.logixng.expressions.swing;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
|
|
import javax.swing.JDialog;
|
|
import javax.swing.JPanel;
|
|
|
|
import jmri.InstanceManager;
|
|
import jmri.Light;
|
|
import jmri.LightManager;
|
|
import jmri.jmrit.logixng.*;
|
|
import jmri.jmrit.logixng.actions.IfThenElse;
|
|
import jmri.jmrit.logixng.expressions.ExpressionLight;
|
|
import jmri.jmrit.logixng.swing.SwingConfiguratorInterfaceTestBase;
|
|
import jmri.util.JUnitUtil;
|
|
import jmri.util.junit.annotations.DisabledIfHeadless;
|
|
|
|
import org.netbeans.jemmy.operators.*;
|
|
|
|
import org.junit.jupiter.api.AfterEach;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Disabled;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
/**
|
|
* Test ExpressionLightSwing
|
|
*
|
|
* @author Daniel Bergqvist 2018
|
|
*/
|
|
public class ExpressionLightSwingTest extends SwingConfiguratorInterfaceTestBase {
|
|
|
|
@Test
|
|
@DisabledIfHeadless
|
|
public void testCtor() {
|
|
|
|
ExpressionLightSwing t = new ExpressionLightSwing();
|
|
assertNotNull( t, "exists");
|
|
}
|
|
|
|
@Test
|
|
@DisabledIfHeadless
|
|
public void testPanel() {
|
|
|
|
JDialog dialog = new JDialog();
|
|
|
|
ExpressionLightSwing t = new ExpressionLightSwing(dialog);
|
|
JPanel panel = t.getConfigPanel(new JPanel());
|
|
assertNotNull( panel, "exists");
|
|
}
|
|
|
|
@Disabled("Fails in Java 11 testing")
|
|
@Test
|
|
@DisabledIfHeadless
|
|
public void testDialogUseExistingLight() throws SocketAlreadyConnectedException {
|
|
|
|
Light l1 = InstanceManager.getDefault(LightManager.class).provide("IL1");
|
|
InstanceManager.getDefault(LightManager.class).provide("IL2");
|
|
|
|
jmri.jmrit.logixng.LogixNG logixNG = InstanceManager.getDefault(jmri.jmrit.logixng.LogixNG_Manager.class)
|
|
.createLogixNG("A logixNG with an empty conditionlNG");
|
|
ConditionalNG conditionalNG = InstanceManager.getDefault(ConditionalNG_Manager.class).createConditionalNG(logixNG, "IQC1", null);
|
|
|
|
IfThenElse action = new IfThenElse("IQDA1", null);
|
|
MaleSocket maleSocket = InstanceManager.getDefault(DigitalActionManager.class).registerAction(action);
|
|
conditionalNG.getChild(0).connect(maleSocket);
|
|
|
|
ExpressionLight expression = new ExpressionLight("IQDE1", null);
|
|
maleSocket = InstanceManager.getDefault(DigitalExpressionManager.class).registerExpression(expression);
|
|
action.getChild(0).connect(maleSocket);
|
|
|
|
JDialogOperator jdo = editItem(conditionalNG, "Edit ConditionalNG IQC1", "Edit ? ", 1);
|
|
|
|
new JComboBoxOperator(jdo, 0).setSelectedItem(l1);
|
|
new JComboBoxOperator(jdo, 1).setSelectedItem(Is_IsNot_Enum.IsNot);
|
|
new JComboBoxOperator(jdo, 2).setSelectedItem(ExpressionLight.LightState.Off);
|
|
|
|
new JButtonOperator(jdo, "OK").push(); // NOI18N
|
|
|
|
JUnitUtil.waitFor(() -> {return expression.getSelectNamedBean().getNamedBean() != null;}, "nb not null");
|
|
|
|
assertEquals("IL1", expression.getSelectNamedBean().getNamedBean().getBean().getSystemName());
|
|
assertEquals(ExpressionLight.LightState.Off, expression.getBeanState());
|
|
}
|
|
|
|
@Test
|
|
@DisabledIfHeadless
|
|
public void testCreatePanel() {
|
|
|
|
JDialog dialog = new JDialog();
|
|
|
|
assertNotNull( new ExpressionLightSwing(dialog).getConfigPanel(new JPanel()),
|
|
"panel is not null");
|
|
assertNotNull( new ExpressionLightSwing(dialog).getConfigPanel(new ExpressionLight("IQDE1", null), new JPanel()),
|
|
"panel is not null");
|
|
}
|
|
|
|
@BeforeEach
|
|
public void setUp() {
|
|
JUnitUtil.setUp();
|
|
JUnitUtil.resetInstanceManager();
|
|
JUnitUtil.resetProfileManager();
|
|
JUnitUtil.initConfigureManager();
|
|
JUnitUtil.initInternalLightManager();
|
|
InstanceManager.getDefault(LogixNGPreferences.class).setShowSystemUserNames(true);
|
|
JUnitUtil.initLogixNGManager();
|
|
}
|
|
|
|
@AfterEach
|
|
public void tearDown() {
|
|
jmri.jmrit.logixng.util.LogixNG_Thread.stopAllLogixNGThreads();
|
|
JUnitUtil.deregisterBlockManagerShutdownTask();
|
|
JUnitUtil.tearDown();
|
|
}
|
|
|
|
}
|