Skip to content

Commit

Permalink
add test of non-empty roster. (still no consists in roster).
Browse files Browse the repository at this point in the history
  • Loading branch information
pabender committed Jul 28, 2019
1 parent f8f930a commit 0635aa5
Showing 1 changed file with 74 additions and 4 deletions.
78 changes: 74 additions & 4 deletions java/test/jmri/jmrit/consisttool/ConsistToolFrameTest.java
@@ -1,5 +1,8 @@
package jmri.jmrit.consisttool;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.awt.GraphicsEnvironment;
import java.lang.reflect.Field;
import jmri.Consist;
Expand All @@ -8,7 +11,10 @@
import jmri.InstanceManager;
import jmri.LocoAddress;
import jmri.jmrit.throttle.ThrottleOperator;
import jmri.jmrit.roster.Roster;
import jmri.jmrit.roster.RosterEntry;
import jmri.util.JUnitUtil;
import jmri.util.FileUtil;
import jmri.util.swing.JemmyUtil;
import org.junit.*;
import org.junit.rules.TemporaryFolder;
Expand Down Expand Up @@ -55,11 +61,11 @@ public void testAdd() {
ConsistToolFrame frame = new ConsistToolFrame();
frame.setVisible(true);
//Assert.assertTrue("Consists List empty",InstanceManager.getDefault(ConsistManager.class).getConsistList().isEmpty());
// get a ConsistToolScaffold
ConsistToolScaffold cs = new ConsistToolScaffold();
// get a ConsistToolScaffold
ConsistToolScaffold cs = new ConsistToolScaffold();
// set up a consist.
cs.setConsistAddressValue("1");
cs.setLocoAddressValue("12");
cs.setConsistAddressValue("1");
cs.setLocoAddressValue("12");
cs.pushAddButton();
// check to see if a conist was added
DccLocoAddress conAddr = new DccLocoAddress(1,false);
Expand Down Expand Up @@ -181,8 +187,72 @@ public void testScanEmptyRoster() {
cs.startRosterScan();
cs.requestClose();
new org.netbeans.jemmy.QueueTool().waitEmpty(100); //pause for frame tot close
Assert.assertTrue("Consists List empty",InstanceManager.getDefault(ConsistManager.class).getConsistList().isEmpty());
}

@Test
public void testScanRosterNoConsists() throws IOException,FileNotFoundException {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
Roster r = createTestRoster();
ConsistToolFrame frame = new ConsistToolFrame();
frame.setVisible(true);
// get a ConsistToolScaffold
ConsistToolScaffold cs = new ConsistToolScaffold();
cs.startRosterScan();
cs.requestClose();
new org.netbeans.jemmy.QueueTool().waitEmpty(100); //pause for frame tot close
Assert.assertTrue("Consists List empty",InstanceManager.getDefault(ConsistManager.class).getConsistList().isEmpty());
}

public Roster createTestRoster() throws IOException, FileNotFoundException {
// this uses explicit filenames intentionally, to ensure that
// the resulting files go into the test tree area.

// store files in random temp directory
File rosterDir = folder.newFolder();
FileUtil.createDirectory(rosterDir);

File f = new File(rosterDir, "rosterTest.xml");
// File should never be there is TemporaryFolder working
if (f.exists()) Assert.fail("rosterTest.xml in "+rosterDir+" already present: "+f);

// create a roster with known contents
Roster r = new Roster();
r.setRosterLocation(rosterDir.getAbsolutePath());
r.setRosterIndexFileName("rosterTest.xml");
RosterEntry e1 = new RosterEntry("file name Bob");
e1.setId("Bob");
e1.setDccAddress("123");
e1.setRoadNumber("123");
e1.setRoadName("SP");
e1.ensureFilenameExists();
e1.putAttribute("key a", "value a");
e1.putAttribute("key b", "value b");
r.addEntry(e1);
RosterEntry e2 = new RosterEntry("file name Bill");
e2.setId("Bill");
e2.setDccAddress("456");
e2.setRoadNumber("123");
e2.setRoadName("ATSF");
e2.setDecoderModel("81");
e2.setDecoderFamily("33");
e2.ensureFilenameExists();
e2.putAttribute("key a", "value a");
r.addEntry(e2);
RosterEntry e3 = new RosterEntry("file name Ben");
e3.setId("Ben");
e3.setRoadNumber("123");
e3.setRoadName("UP");
e3.ensureFilenameExists();
e3.putAttribute("key b", "value b");
r.addEntry(e3);

// write it
//r.writeFile(r.getRosterIndexPath());
return r;
}


@Before
public void setUp() throws java.io.IOException {
JUnitUtil.setUp();
Expand Down

0 comments on commit 0635aa5

Please sign in to comment.