Skip to content

Commit

Permalink
Merge pull request #7090 from pabender/cucumber
Browse files Browse the repository at this point in the history
Move application start tests to cucumber.
  • Loading branch information
pabender committed Jun 16, 2019
2 parents 4790f8c + f7d14a1 commit d73ea5c
Show file tree
Hide file tree
Showing 34 changed files with 229 additions and 20 deletions.
18 changes: 11 additions & 7 deletions .classpath
Expand Up @@ -122,17 +122,21 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/cucumber-core-2.0.1.jar"/>
<classpathentry kind="lib" path="lib/cucumber-java-2.0.1.jar"/>
<classpathentry kind="lib" path="lib/cucumber-java8-2.0.1.jar"/>
<classpathentry kind="lib" path="lib/cucumber-junit-2.0.1.jar"/>
<classpathentry kind="lib" path="lib/cucumber-core-4.3.1.jar"/>
<classpathentry kind="lib" path="lib/cucumber-java-4.3.1.jar"/>
<classpathentry kind="lib" path="lib/cucumber-java8-4.3.1.jar"/>
<classpathentry kind="lib" path="lib/cucumber-junit-4.3.1.jar"/>
<classpathentry kind="lib" path="lib/cucumber-html-4.3.1.jar"/>
<classpathentry kind="lib" path="lib/cucumber-jvm-deps-1.0.6.jar"/>
<classpathentry kind="lib" path="lib/cucumber-picocontainer-2.0.1.jar"/>
<classpathentry kind="lib" path="lib/gherkin-4.1.3.jar"/>
<classpathentry kind="lib" path="lib/cucumber-picocontainer-4.3.1.jar"/>
<classpathentry kind="lib" path="lib/cucumber-expressions-6.2.2.jar"/>
<classpathentry kind="lib" path="lib/gherkin-5.1.0.jar"/>
<classpathentry kind="lib" path="lib/gherkin-jvm-deps-1.0.4.jar"/>
<classpathentry kind="lib" path="lib/picocontainer-2.15.jar"/>
<classpathentry kind="lib" path="lib/tag-expressions-1.0.1.jar"/>
<classpathentry kind="lib" path="lib/tag-expressions-1.1.1.jar"/>
<classpathentry kind="lib" path="lib/typetools-0.5.0.jar"/>
<classpathentry kind="lib" path="lib/datatable-1.1.12.jar"/>
<classpathentry kind="lib" path="lib/datatable-dependencies-1.1.12.jar"/>
<classpathentry kind="lib" path="lib/webdrivermanager-3.4.0.jar"/>
<classpathentry kind="lib" path="lib/jarchivelib-1.0.0.jar"/>
<classpathentry kind="lib" path="lib/mqtt-client-0.4.0.jar"/>
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -8,7 +8,7 @@ addons:
- dbus-x11
- tidy
firefox: latest
chrome: stable
chrome: beta

before_install:
# ensure no unwanted defaults are set
Expand Down
20 changes: 13 additions & 7 deletions build.xml
Expand Up @@ -273,17 +273,21 @@
<pathelement location="${libdir}/jemmy-22-00c9f753cd0a.jar"/>
<pathelement location="${libdir}/system-rules-1.16.0.jar"/>
<!-- cucumber and it's dependencies -->
<pathelement location="${libdir}/cucumber-core-2.0.1.jar"/>
<pathelement location="${libdir}/cucumber-java-2.0.1.jar"/>
<pathelement location="${libdir}/cucumber-java8-2.0.1.jar"/>
<pathelement location="${libdir}/cucumber-junit-2.0.1.jar"/>
<pathelement location="${libdir}/cucumber-core-4.3.1.jar"/>
<pathelement location="${libdir}/cucumber-java-4.3.1.jar"/>
<pathelement location="${libdir}/cucumber-java8-4.3.1.jar"/>
<pathelement location="${libdir}/cucumber-junit-4.3.1.jar"/>
<pathelement location="${libdir}/cucumber-jvm-deps-1.0.6.jar"/>
<pathelement location="${libdir}/cucumber-picocontainer-2.0.1.jar"/>
<pathelement location="${libdir}/gherkin-4.1.3.jar"/>
<pathelement location="${libdir}/cucumber-picocontainer-4.3.1.jar"/>
<pathelement location="${libdir}/cucumber-html-0.2.7.jar"/>
<pathelement location="${libdir}/cucumber-expressions-6.2.2.jar"/>
<pathelement location="${libdir}/gherkin-5.1.0.jar"/>
<pathelement location="${libdir}/gherkin-jvm-deps-1.0.4.jar"/>
<pathelement location="${libdir}/picocontainer-2.15.jar"/>
<pathelement location="${libdir}/tag-expressions-1.0.1.jar"/>
<pathelement location="${libdir}/tag-expressions-1.1.1.jar"/>
<pathelement location="${libdir}/typetools-0.5.0.jar"/>
<pathelement location="${libdir}/datatable-1.1.12.jar"/>
<pathelement location="${libdir}/datatable-dependencies-1.1.12.jar"/>
<!-- Selenium and it's dependencies -->
<pathelement location="${libdir}/selenium-server-standalone-3.6.0.jar"/>
<pathelement location="${libdir}/webdrivermanager-3.4.0.jar"/>
Expand Down Expand Up @@ -1347,6 +1351,7 @@
<sysproperty key="log4j.ignoreTCL" path="true/"/>
<sysproperty key="java.library.path" path=".:${libdir}:${arch.lib.path}"/>
<sysproperty key="jmri.prefsdir" path="${tempdir}"/>
<sysproperty key="cucumber.options" value="--tags 'not @Ignore' --tags 'not @headed'"/>
<sysproperty key="jinput.plugins" path="net.bobis.jinput.hidraw.HidRawEnvironmentPlugin"/>

<sysproperty key="java.awt.headless" value="true"/>
Expand Down Expand Up @@ -1397,6 +1402,7 @@
<sysproperty key="log4j.ignoreTCL" path="true/"/>
<sysproperty key="java.library.path" path=".:${libdir}:${arch.lib.path}"/>
<sysproperty key="jmri.prefsdir" path="${tempdir}"/>
<sysproperty key="cucumber.options" value="--tags 'not @Ignore' --tags 'not @headed'"/>
<sysproperty key="jinput.plugins" path="net.bobis.jinput.hidraw.HidRawEnvironmentPlugin"/>

<sysproperty key="java.awt.headless" value="true"/>
Expand Down
62 changes: 62 additions & 0 deletions java/acceptancetest/features/apps/ApplicationStart.feature
@@ -0,0 +1,62 @@
@apptest @Headed
Feature: JMRI Applications

Scenario Outline: Application Start
Given I am using profile <profile>
When starting application <application> with <name>
Then <infoline> is printed to the console
And a frame with title <name> is displayed

@FailingTests @Ignore
Examples: Tests that are failing
| application | profile | name | infoline |
| apps.PanelPro.PanelPro | java/test/apps/PanelPro/profiles/EasyDcc_Simulator | PanelProPro | Main initialization done |
| apps.DecoderPro.DecoderPro | java/test/apps/PanelPro/profiles/Grapevine_Simulator | DispatcherPro | DecoderPro version |

@PanelProTest
Examples: PanelPro Tests
| application | profile | name | infoline |
| apps.PanelPro.PanelPro | java/test/apps/PanelPro/profiles/LocoNet_Simulator | PanelPro | Main initialization done |
| apps.PanelPro.PanelPro | java/test/apps/PanelPro/profiles/TMCC_Simulator | PanelPro | Main initialization done |
| apps.PanelPro.PanelPro | java/test/apps/PanelPro/profiles/Prevent_Init_Loop | PanelPro | Main initialization done |
| apps.PanelPro.PanelPro | java/test/apps/PanelPro/profiles/Grapevine_Simulator | PanelPro | Main initialization done |
| apps.PanelPro.PanelPro | java/test/apps/PanelPro/profiles/Sprog_Simulator | PanelPro | Main initialization done |

@DecoderProTest
Examples: DecoderPro Tests
| application | profile | name | infoline |
| apps.DecoderPro.DecoderPro | java/test/apps/PanelPro/profiles/LocoNet_Simulator | DecoderPro | DecoderPro version |
| apps.DecoderPro.DecoderPro | java/test/apps/PanelPro/profiles/EasyDcc_Simulator | DecoderPro | DecoderPro version |
| apps.DecoderPro.DecoderPro | java/test/apps/PanelPro/profiles/TMCC_Simulator | DecoderPro | DecoderPro version |
| apps.DecoderPro.DecoderPro | java/test/apps/PanelPro/profiles/Prevent_Init_Loop | DecoderPro | DecoderPro version |
| apps.DecoderPro.DecoderPro | java/test/apps/PanelPro/profiles/Sprog_Simulator | DecoderPro | DecoderPro version |

@DecoderPro3Test
Examples: DecoderPro3 Tests
| application | profile | name | infoline |
| apps.gui3.dp3.DecoderPro3 | java/test/apps/PanelPro/profiles/LocoNet_Simulator | DecoderPro: All Entries | DecoderPro version |
| apps.gui3.dp3.DecoderPro3 | java/test/apps/PanelPro/profiles/EasyDcc_Simulator | DecoderPro: All Entries | DecoderPro version |
| apps.gui3.dp3.DecoderPro3 | java/test/apps/PanelPro/profiles/TMCC_Simulator | DecoderPro: All Entries | DecoderPro version |
| apps.gui3.dp3.DecoderPro3 | java/test/apps/PanelPro/profiles/Prevent_Init_Loop | DecoderPro: All Entries | DecoderPro version |
| apps.gui3.dp3.DecoderPro3 | java/test/apps/PanelPro/profiles/Grapevine_Simulator | DecoderPro: All Entries | DecoderPro version |
| apps.gui3.dp3.DecoderPro3 | java/test/apps/PanelPro/profiles/Sprog_Simulator | DecoderPro: All Entries | DecoderPro version |

@SoundProTest
Examples: SoundPro Tests
| application | profile | name | infoline |
| apps.SoundPro.SoundPro | java/test/apps/PanelPro/profiles/LocoNet_Simulator | SoundPro | SoundPro version |
| apps.SoundPro.SoundPro | java/test/apps/PanelPro/profiles/EasyDcc_Simulator | SoundPro | SoundPro version |
| apps.SoundPro.SoundPro | java/test/apps/PanelPro/profiles/TMCC_Simulator | SoundPro | SoundPro version |
| apps.SoundPro.SoundPro | java/test/apps/PanelPro/profiles/Prevent_Init_Loop | SoundPro | SoundPro version |
| apps.SoundPro.SoundPro | java/test/apps/PanelPro/profiles/Grapevine_Simulator | SoundPro | SoundPro version |
| apps.SoundPro.SoundPro | java/test/apps/PanelPro/profiles/Sprog_Simulator | SoundPro | SoundPro version |

@DispatcherProTest
Examples: DispatcherPro Tests
| application | profile | name | infoline |
| apps.DispatcherPro.DispatcherPro | java/test/apps/PanelPro/profiles/LocoNet_Simulator | DispatcherPro | DispatcherPro version |
| apps.DispatcherPro.DispatcherPro | java/test/apps/PanelPro/profiles/EasyDcc_Simulator | DispatcherPro | DispatcherPro version |
| apps.DispatcherPro.DispatcherPro | java/test/apps/PanelPro/profiles/TMCC_Simulator | DispatcherPro | DispatcherPro version |
| apps.DispatcherPro.DispatcherPro | java/test/apps/PanelPro/profiles/Prevent_Init_Loop | DispatcherPro | DispatcherPro version |
| apps.DispatcherPro.DispatcherPro | java/test/apps/PanelPro/profiles/Grapevine_Simulator | DispatcherPro | DispatcherPro version |
| apps.DispatcherPro.DispatcherPro | java/test/apps/PanelPro/profiles/Sprog_Simulator | DispatcherPro | DispatcherPro version |
15 changes: 15 additions & 0 deletions java/acceptancetest/features/apps/HeadlessApplicationStart.feature
@@ -0,0 +1,15 @@
@apptest @Headless
Feature: Headless JMRI Applications

Scenario Outline: Application Start
Given I am using profile <profile>
When starting application <application> with <name>
Then <infoline> is printed to the console

@JmriFacelessTest @Ignore
Examples: Headless Tests
| application | profile | name | infoline |
| apps.JmriFaceless | java/test/apps/PanelPro/profiles/LocoNet_Simulator | JmriFaceless | JmriFaceless version |
| apps.JmriFaceless | java/test/apps/PanelPro/profiles/EasyDcc_Simulator | JmriFaceless | JmriFaceless version |
| apps.JmriFaceless | java/test/apps/PanelPro/profiles/TMCC_Simulator | JmriFaceless | JmriFaceless version |
| apps.JmriFaceless | java/test/apps/PanelPro/profiles/Grapevine_Simulator | JmriFaceless | JmriFaceless version |
@@ -0,0 +1,112 @@
package apps;

import cucumber.api.java8.En;
import cucumber.api.PendingException;
import org.junit.Assert;
import java.io.File;
import org.apache.commons.io.FileUtils;
import java.nio.file.Files;
import java.lang.reflect.Method;
import jmri.managers.DefaultShutDownManager;
import jmri.util.JmriJFrame;
import jmri.util.JUnitAppender;
import jmri.util.JUnitUtil;
import org.netbeans.jemmy.operators.JButtonOperator;
import org.netbeans.jemmy.operators.JDialogOperator;

/**
* Cucumber step definitions for Application Acceptance tests.
*
* @author Paul Bender Copyright (C) 2018
*/
public class ApplicationTestAcceptanceSteps implements En {

String[] tags = {"@apptest"};
File tempFolder;

public ApplicationTestAcceptanceSteps(jmri.InstanceManager instance) {


Before(tags,() -> {
JUnitUtil.setUp();
JUnitUtil.clearShutDownManager();
JUnitUtil.resetApplication();
});

Given("^I am using profile (.*)$", (String profile) -> {
try {
// create a custom profile
tempFolder =Files.createTempDirectory("AppTest").toFile();
File profileDir = new File(tempFolder.getAbsolutePath() + File.separator + "Name" );
FileUtils.copyDirectory(new File(profile), profileDir );
System.setProperty("jmri.prefsdir",tempFolder.getAbsolutePath());
System.setProperty("org.jmri.profile", profileDir.getAbsolutePath() );
} catch(java.io.IOException ioe) {
Assert.fail("Unable to create temporary profile");
}
});

When("^starting application (.*) with (.*)", (String application,String frametitle ) -> {
try {
// use redirection to start the application.
Class appclass = Class.forName(application);
Method method = appclass.getMethod("main",String[].class);
String[] params = new String[]{frametitle};
method.invoke(null,(Object)params);
} catch(java.lang.ClassNotFoundException cnf){
Assert.fail("Class " + application + " not found");
} catch(java.lang.NoSuchMethodException |
java.lang.IllegalAccessException ex){
Assert.fail("Error calling main method");
}
});

Then("^a frame with title (.*) is displayed$", (String frameTitle) -> {
JUnitUtil.waitFor(()->{return JmriJFrame.getFrame(frameTitle) != null;}, "window up");
});

Then("^(.*) is printed to the console$", (String infoLine) -> {
JUnitUtil.waitFor(()->{return JUnitAppender.checkForMessageStartingWith(infoLine) != null;}, "first Info line seen");
});

After(tags,() -> {
dismissClosingDialogs(); // this method starts a new thread
try{
// gracefully shutdown, but don't exit
((DefaultShutDownManager)instance.getDefault(jmri.ShutDownManager.class)).shutdown(0, false);
} finally {
// wait for threads, etc
jmri.util.JUnitUtil.releaseThread(this, 5000);
}
FileUtils.deleteDirectory(tempFolder);
System.clearProperty("jmri.prefsdir");
System.clearProperty("org.jmri.profile");
JUnitUtil.clearShutDownManager();
JUnitUtil.tearDown();
});

}

private void dismissClosingDialogs(){
// the Unsaved Changes dialog doesn't appear every time we close,
// so put pressing No button in that dialog into a thread by itself.
// If the dialog appears, the button will be clicked, but it's not
// an error if the dialog doesn't appear.
Thread t = new Thread( () -> {
try {
JDialogOperator d = new JDialogOperator(Bundle.getMessage("UnsavedChangesTitle"));
// Find the button that deletes the panel
JButtonOperator bo = new JButtonOperator(d,Bundle.getMessage("ButtonNo"));

// Click button to delete panel and close window
bo.push();
} catch (Exception e) {
// exceptions in this thread are not considered an error.
return;
}
});
t.setName("Unsaved Changes Dialog Close Thread");
t.start();
}

}
Expand Up @@ -23,6 +23,7 @@ public WebServerScaffold(jmri.InstanceManager instance) {

Before(tags, () -> {
jmri.util.JUnitUtil.resetProfileManager();
instance.setDefault(jmri.web.server.WebServerPreferences.class, new jmri.web.server.WebServerPreferences());
jmri.util.JUnitUtil.initConfigureManager();
jmri.util.JUnitUtil.initInternalTurnoutManager();
jmri.util.JUnitUtil.initInternalLightManager();
Expand Down
1 change: 1 addition & 0 deletions java/test/apps/DecoderPro/DecoderProTest.java
Expand Up @@ -22,6 +22,7 @@
* @author Paul Bender Copyright (C) 2017, 2019
* @author Bob Jacobsen Copyright (C) 2017
*/
@Ignore("Replaced with Cucumber test")
public class DecoderProTest extends apps.LaunchJmriAppBase {

protected void launch(String[] args) {
Expand Down
1 change: 1 addition & 0 deletions java/test/apps/DispatcherPro/DispatcherProTest.java
Expand Up @@ -22,6 +22,7 @@
* @author Paul Bender Copyright (C) 2017, 2019
* @author Bob Jacobsen Copyright (C) 2017
*/
@Ignore("Replaced with a Cucumber test")
public class DispatcherProTest extends apps.LaunchJmriAppBase {

protected void launch(String[] args) {
Expand Down
1 change: 1 addition & 0 deletions java/test/apps/LaunchJmriAppBase.java
Expand Up @@ -104,6 +104,7 @@ protected void cleanup() {
@Before
public void setUp() {
JUnitUtil.setUp();
JUnitUtil.clearShutDownManager();
JUnitUtil.resetApplication();
}

Expand Down
2 changes: 1 addition & 1 deletion java/test/apps/PackageTest.java
Expand Up @@ -44,7 +44,7 @@
apps.gui.PackageTest.class,
SampleMinimalProgramTest.class,
SystemConsoleTest.class,
AppsLaunchFrameTest.class
AppsLaunchFrameTest.class,
})
/**
* Invoke complete set of tests for the apps package
Expand Down
1 change: 1 addition & 0 deletions java/test/apps/PanelPro/PanelProTest.java
Expand Up @@ -23,6 +23,7 @@
* @author Paul Bender Copyright (C) 2017, 2019
* @author Bob Jacobsen Copyright (C) 2017
*/
@Ignore("Replaced with a Cucumber test")
public class PanelProTest extends apps.LaunchJmriAppBase {

protected void launch(String[] args) {
Expand Down
1 change: 1 addition & 0 deletions java/test/apps/SoundPro/SoundProTest.java
Expand Up @@ -22,6 +22,7 @@
* @author Paul Bender Copyright (C) 2017
* @author Bob Jacobsen Copyright (C) 2017
*/
@Ignore("Replaced with a Cucumber test")
public class SoundProTest extends apps.LaunchJmriAppBase {

protected void launch(String[] args) {
Expand Down
3 changes: 2 additions & 1 deletion java/test/jmri/RunCucumberTest.java
Expand Up @@ -25,7 +25,8 @@
@RunWith(Cucumber.class)
@CucumberOptions(plugin = {"junit:cucumber-results.xml","progress","json:cucumber-results.json"},
features="java/acceptancetest/features",
tags = {"not @webtest"})
tags = {"not @webtest", "not @Ignore", "not @ignore"},
glue = {"apps","jmri"} )
public class RunCucumberTest {

@BeforeClass
Expand Down
Binary file removed lib/cucumber-core-2.0.1.jar
Binary file not shown.
Binary file added lib/cucumber-core-4.3.1.jar
Binary file not shown.
Binary file added lib/cucumber-expressions-6.2.2.jar
Binary file not shown.
Binary file added lib/cucumber-html-0.2.7.jar
Binary file not shown.
Binary file removed lib/cucumber-java-2.0.1.jar
Binary file not shown.
Binary file added lib/cucumber-java-4.3.1.jar
Binary file not shown.
Binary file removed lib/cucumber-java8-2.0.1.jar
Binary file not shown.
Binary file added lib/cucumber-java8-4.3.1.jar
Binary file not shown.
Binary file removed lib/cucumber-junit-2.0.1.jar
Binary file not shown.
Binary file added lib/cucumber-junit-4.3.1.jar
Binary file not shown.
Binary file removed lib/cucumber-picocontainer-2.0.1.jar
Binary file not shown.
Binary file added lib/cucumber-picocontainer-4.3.1.jar
Binary file not shown.
Binary file added lib/datatable-1.1.12.jar
Binary file not shown.
Binary file added lib/datatable-dependencies-1.1.12.jar
Binary file not shown.
Binary file renamed lib/gherkin-4.1.3.jar → lib/gherkin-5.1.0.jar
Binary file not shown.
Binary file removed lib/tag-expressions-1.0.1.jar
Binary file not shown.
Binary file added lib/tag-expressions-1.1.1.jar
Binary file not shown.

0 comments on commit d73ea5c

Please sign in to comment.