88 lines
2.6 KiB
Java
88 lines
2.6 KiB
Java
package jmri.jmrix.openlcb.configurexml;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
|
|
import static org.junit.jupiter.api.Assumptions.assumeFalse;
|
|
|
|
import jmri.InstanceManager;
|
|
import jmri.Reporter;
|
|
import jmri.jmrix.openlcb.OlcbReporterManager;
|
|
import jmri.jmrix.openlcb.OlcbTestInterface;
|
|
import jmri.util.JUnitUtil;
|
|
|
|
import org.jdom2.Element;
|
|
|
|
import org.junit.jupiter.api.AfterEach;
|
|
import org.junit.jupiter.api.BeforeAll;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
/**
|
|
* OlcbReporterManagerXmlTest.java
|
|
*
|
|
* Test for the OlcbReporterManagerXml class
|
|
*
|
|
* @author Paul Bender Copyright (C) 2016
|
|
* Balazs Racz (C) 2018, 2023
|
|
*/
|
|
public class OlcbReporterManagerXmlTest {
|
|
|
|
@Test
|
|
public void testSaveAndRestore() {
|
|
log.debug("FIRST START");
|
|
t = new OlcbTestInterface(new OlcbTestInterface.CreateConfigurationManager());
|
|
OlcbReporterManager mgr = t.configurationManager.getReporterManager();
|
|
OlcbReporterManagerXml xmlmgr = new OlcbReporterManagerXml();
|
|
|
|
mgr.newReporter("MR1.2.3.4.5.6.0.0", "rep1");
|
|
t.flush();
|
|
t.assertSentMessage(":X194a4c4cN010203040506ffff;");
|
|
t.assertNoSentMessages();
|
|
|
|
Element stored = xmlmgr.store(mgr);
|
|
assertNotNull(stored);
|
|
|
|
t.dispose();
|
|
InstanceManager.getDefault().clearAll();
|
|
|
|
log.debug("SECOND START");
|
|
|
|
t = new OlcbTestInterface(new OlcbTestInterface.CreateConfigurationManager());
|
|
mgr = t.configurationManager.getReporterManager();
|
|
|
|
xmlmgr.load(stored, null);
|
|
|
|
Reporter r2 = mgr.getBySystemName("MR1.2.3.4.5.6.0.0");
|
|
assertNotNull(r2);
|
|
assertEquals("rep1", r2.getUserName());
|
|
t.flush();
|
|
t.assertSentMessage(":X194a4c4cN010203040506ffff;");
|
|
t.assertNoSentMessages();
|
|
|
|
t.dispose();
|
|
}
|
|
|
|
private OlcbTestInterface t;
|
|
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(OlcbReporterManagerXmlTest.class);
|
|
|
|
@BeforeAll
|
|
public static void checkSeparate() {
|
|
// this test is run separately because it leaves a lot of threads behind
|
|
assumeFalse( Boolean.getBoolean("jmri.skipTestsRequiringSeparateRunning"), "Ignoring intermittent test");
|
|
}
|
|
|
|
@BeforeEach
|
|
public void setUp() {
|
|
JUnitUtil.setUp();
|
|
}
|
|
|
|
@AfterEach
|
|
public void tearDown() {
|
|
JUnitUtil.clearShutDownManager(); // put in place because AbstractMRTrafficController implementing subclass was not terminated properly
|
|
JUnitUtil.tearDown();
|
|
}
|
|
|
|
}
|
|
|