Skip to content
Permalink
Browse files

More testing

  • Loading branch information...
danielboudreau danielboudreau
danielboudreau authored and danielboudreau committed Nov 7, 2018
1 parent ee8aae9 commit ed8861a80823319b1a891a88c77625182963e1d6
@@ -1,6 +1,14 @@
package jmri.jmrit.operations.automation.actions;

import jmri.util.JUnitUtil;
import java.io.File;
import java.io.IOException;
import jmri.InstanceManager;
import jmri.jmrit.operations.OperationsManager;
import jmri.jmrit.operations.OperationsTestCase;
import jmri.jmrit.operations.automation.AutomationItem;
import jmri.jmrit.operations.setup.Setup;
import jmri.jmrit.operations.trains.excel.TrainCustomSwitchList;
import jmri.util.JUnitOperationsUtil;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
@@ -10,22 +18,105 @@
*
* @author Paul Bender Copyright (C) 2017
*/
public class RunSwitchListActionTest {
public class RunSwitchListActionTest extends OperationsTestCase {

@Test
public void testCTor() {
RunSwitchListAction t = new RunSwitchListAction();
Assert.assertNotNull("exists",t);
}

@Test
public void testActionNoAutomationItem() {
RunSwitchListAction action = new RunSwitchListAction();
Assert.assertNotNull("exists", action);
// does nothing, no automationItem
action.doAction();
}

@Test
public void testGetActionName() {
RunSwitchListAction action = new RunSwitchListAction();
Assert.assertEquals("name", Bundle.getMessage("RunSwitchList"), action.getName());
}

@Test
public void testIsMessageOkEnabled() {
RunSwitchListAction action = new RunSwitchListAction();
Assert.assertTrue(action.isMessageOkEnabled());
}

@Test
public void testIsMessageFailEnabled() {
RunSwitchListAction action = new RunSwitchListAction();
Assert.assertTrue(action.isMessageFailEnabled());
}

@Test
public void testIsConcurrentAction() {
RunSwitchListAction action = new RunSwitchListAction();
Assert.assertFalse(action.isConcurrentAction());
}

@Test
public void testRunSwitchListActionFailures() {

JUnitOperationsUtil.initOperationsData();

RunSwitchListAction action = new RunSwitchListAction();
Assert.assertNotNull("exists", action);
AutomationItem automationItem = new AutomationItem("TestId");
automationItem.setAction(action);
Assert.assertEquals("confirm registered", automationItem, action.getAutomationItem());

// confirm that default is not enabled
Assert.assertFalse(Setup.isGenerateCsvSwitchListEnabled());

// does nothing, not enabled
action.doAction();
Assert.assertFalse(automationItem.isActionRunning());
Assert.assertFalse(automationItem.isActionSuccessful());

jmri.util.JUnitAppender.assertWarnMessage("Generate CSV Switch List isn't enabled!");

Setup.setGenerateCsvSwitchListEnabled(true);

// does nothing, excel program not configured
action.doAction();
Assert.assertFalse(automationItem.isActionRunning());
Assert.assertFalse(automationItem.isActionSuccessful());

jmri.util.JUnitAppender.assertWarnMessage(
"Manifest creator file not found!, directory name: csvSwitchLists, file name: MC4JMRI.xls");

// load dummy file
File file = new File(
InstanceManager.getDefault(OperationsManager.class)
.getFile(InstanceManager.getDefault(TrainCustomSwitchList.class).getDirectoryName()),
"Test_Excel_File.xls");
InstanceManager.getDefault(TrainCustomSwitchList.class).setFileName(file.getName());

try {
file.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

// confirm file exists
Assert.assertTrue(InstanceManager.getDefault(TrainCustomSwitchList.class).excelFileExists());
}

// The minimal setup for log4J
@Override
@Before
public void setUp() {
JUnitUtil.setUp(); }
super.setUp(); }

@Override
@After
public void tearDown() {
JUnitUtil.tearDown();
super.tearDown();
}

// private final static Logger log = LoggerFactory.getLogger(RunSwitchListActionTest.class);
@@ -1,31 +1,144 @@
package jmri.jmrit.operations.automation.actions;

import jmri.util.JUnitUtil;
import java.io.File;
import java.io.IOException;
import jmri.InstanceManager;
import jmri.jmrit.operations.OperationsManager;
import jmri.jmrit.operations.OperationsTestCase;
import jmri.jmrit.operations.automation.AutomationItem;
import jmri.jmrit.operations.setup.Setup;
import jmri.jmrit.operations.trains.Train;
import jmri.jmrit.operations.trains.TrainManager;
import jmri.jmrit.operations.trains.excel.TrainCustomManifest;
import jmri.util.JUnitOperationsUtil;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

/**
*
* @author Paul Bender Copyright (C) 2017
* @author Paul Bender Copyright (C) 2017
*/
public class RunTrainActionTest {
public class RunTrainActionTest extends OperationsTestCase {

@Test
public void testCTor() {
RunTrainAction t = new RunTrainAction();
Assert.assertNotNull("exists",t);
Assert.assertNotNull("exists", t);
}

@Test
public void testActionNoAutomationItem() {
RunTrainAction action = new RunTrainAction();
Assert.assertNotNull("exists", action);
// does nothing, no automationItem
action.doAction();
}

@Test
public void testGetActionName() {
RunTrainAction action = new RunTrainAction();
Assert.assertEquals("name", Bundle.getMessage("RunTrain"), action.getName());
}

@Test
public void testIsMessageOkEnabled() {
RunTrainAction action = new RunTrainAction();
Assert.assertTrue(action.isMessageOkEnabled());
}

@Test
public void testIsMessageFailEnabled() {
RunTrainAction action = new RunTrainAction();
Assert.assertTrue(action.isMessageFailEnabled());
}

@Test
public void testIsConcurrentAction() {
RunTrainAction action = new RunTrainAction();
Assert.assertFalse(action.isConcurrentAction());
}

@Test
public void testRunTrainActionFailures() {

JUnitOperationsUtil.initOperationsData();

RunTrainAction action = new RunTrainAction();
Assert.assertNotNull("exists", action);
AutomationItem automationItem = new AutomationItem("TestId");
automationItem.setAction(action);
Assert.assertEquals("confirm registered", automationItem, action.getAutomationItem());

// confirm that default is not enabled
Assert.assertFalse(Setup.isGenerateCsvManifestEnabled());

// does nothing, not enabled
action.doAction();
Assert.assertFalse(automationItem.isActionRunning());
Assert.assertFalse(automationItem.isActionSuccessful());

jmri.util.JUnitAppender.assertWarnMessage("Generate CSV Manifest isn't enabled!");

Setup.setGenerateCsvManifestEnabled(true);

// does nothing, excel program not configured
action.doAction();
Assert.assertFalse(automationItem.isActionRunning());
Assert.assertFalse(automationItem.isActionSuccessful());

jmri.util.JUnitAppender.assertWarnMessage(
"Manifest creator file not found!, directory name: csvManifests, file name: MC4JMRI.xls");

// load dummy file
File file = new File(
InstanceManager.getDefault(OperationsManager.class)
.getFile(InstanceManager.getDefault(TrainCustomManifest.class).getDirectoryName()),
"Test_Excel_File.xls");
InstanceManager.getDefault(TrainCustomManifest.class).setFileName(file.getName());

try {
file.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

// confirm file exists
Assert.assertTrue(InstanceManager.getDefault(TrainCustomManifest.class).excelFileExists());

TrainManager tmanager = InstanceManager.getDefault(TrainManager.class);
Train train1 = tmanager.getTrainById("1");
Assert.assertNotNull(train1);

// does nothing, no train assignment
action.doAction();
Assert.assertFalse(automationItem.isActionRunning());
Assert.assertFalse(automationItem.isActionSuccessful());

jmri.util.JUnitAppender.assertWarnMessage("No train selected for custom manifest");

automationItem.setTrain(train1);
// does nothing, train isn't built
action.doAction();
Assert.assertFalse(automationItem.isActionRunning());
Assert.assertFalse(automationItem.isActionSuccessful());

jmri.util.JUnitAppender.assertWarnMessage("Train (STF) needs to be built before creating a custom manifest");
}

// The minimal setup for log4J
@Override
@Before
public void setUp() {
JUnitUtil.setUp(); }
super.setUp();
}

@Override
@After
public void tearDown() {
JUnitUtil.tearDown();
super.tearDown();
}

// private final static Logger log = LoggerFactory.getLogger(RunTrainActionTest.class);
@@ -1,6 +1,11 @@
package jmri.jmrit.operations.automation.actions;

import jmri.util.JUnitUtil;
import jmri.InstanceManager;
import jmri.jmrit.operations.OperationsTestCase;
import jmri.jmrit.operations.automation.AutomationItem;
import jmri.jmrit.operations.trains.Train;
import jmri.jmrit.operations.trains.TrainManager;
import jmri.util.JUnitOperationsUtil;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
@@ -10,22 +15,105 @@
*
* @author Paul Bender Copyright (C) 2017
*/
public class WaitSwitchListActionTest {
public class WaitSwitchListActionTest extends OperationsTestCase {

@Test
public void testCTor() {
WaitSwitchListAction t = new WaitSwitchListAction();
Assert.assertNotNull("exists",t);
}

@Test
public void testActionNoAutomationItem() {
WaitSwitchListAction action = new WaitSwitchListAction();
Assert.assertNotNull("exists", action);
// does nothing, no automationItem
action.doAction();
}

@Test
public void testGetActionName() {
WaitSwitchListAction action = new WaitSwitchListAction();
Assert.assertEquals("name", Bundle.getMessage("WaitForSwitchListChange"), action.getName());
}

@Test
public void testIsMessageOkEnabled() {
WaitSwitchListAction action = new WaitSwitchListAction();
Assert.assertTrue(action.isMessageOkEnabled());
}

@Test
public void testIsMessageFailEnabled() {
WaitSwitchListAction action = new WaitSwitchListAction();
Assert.assertFalse(action.isMessageFailEnabled());
}

@Test
public void testIsConcurrentAction() {
WaitSwitchListAction action = new WaitSwitchListAction();
Assert.assertTrue(action.isConcurrentAction());
}

@Test
public void testCancel() {
JUnitOperationsUtil.initOperationsData();

WaitSwitchListAction action = new WaitSwitchListAction();
Assert.assertNotNull("exists", action);
AutomationItem automationItem = new AutomationItem("TestId");
automationItem.setAction(action);
Assert.assertEquals("confirm registered", automationItem, action.getAutomationItem());

action.doAction();
Assert.assertTrue(automationItem.isActionRunning());
Assert.assertFalse(automationItem.isActionSuccessful());

// cancel
action.cancelAction();
Assert.assertFalse(automationItem.isActionRunning());
Assert.assertFalse(automationItem.isActionSuccessful());
}

@Test
public void testWaitSwitchListAction() {
JUnitOperationsUtil.initOperationsData();
TrainManager tmanager = InstanceManager.getDefault(TrainManager.class);
Train train1 = tmanager.getTrainById("1");
Assert.assertNotNull(train1);

// confirm default
Assert.assertTrue(train1.isBuildEnabled());

WaitSwitchListAction action = new WaitSwitchListAction();
Assert.assertNotNull("exists", action);
AutomationItem automationItem = new AutomationItem("TestId");
automationItem.setAction(action);
Assert.assertEquals("confirm registered", automationItem, action.getAutomationItem());

// start wait
action.doAction();
Assert.assertTrue(automationItem.isActionRunning());
Assert.assertFalse(automationItem.isActionSuccessful());

// build train
Assert.assertTrue(train1.build());

Assert.assertFalse(automationItem.isActionRunning());
Assert.assertTrue(automationItem.isActionSuccessful());
}


// The minimal setup for log4J
@Override
@Before
public void setUp() {
JUnitUtil.setUp(); }
super.setUp(); }

@Override
@After
public void tearDown() {
JUnitUtil.tearDown();
super.tearDown();
}

// private final static Logger log = LoggerFactory.getLogger(WaitSwitchListActionTest.class);

0 comments on commit ed8861a

Please sign in to comment.
You can’t perform that action at this time.