package jmri.configurexml; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import java.awt.GraphicsEnvironment; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import java.text.ParseException; import java.util.stream.Stream; import jmri.*; import jmri.jmrit.logix.WarrantPreferences; import jmri.util.FileUtil; import jmri.util.JUnitAppender; import jmri.util.JUnitUtil; import org.junit.jupiter.api.*; import org.junit.jupiter.api.io.TempDir; import org.junit.jupiter.params.provider.Arguments; /** * Base for testing load-and-store of configuration files. *
* Creating a parameterized test class that extends this class will test each * file in a "load" directory by loading it, then storing it, then comparing * (with certain lines skipped) against either a file by the same name in the * "loadref" directory, or against the original file itself. A minimal test * class is:
public class LoadAndStoreTest extends LoadAndStoreTestBase {
public static Stream&Arguments& data() {
return getFiles(new File("java/test/jmri/configurexml"), false, true);
}
@ParameterizedTest
@MethodSource("data")
public void loadAndStoreTest(File file, boolean pass) { super.validate(file, pass); }
}
*
* @author Bob Jacobsen Copyright 2009, 2014
* @since 2.5.5 (renamed & reworked in 3.9 series)
*/
public class LoadAndStoreTestBase {
public enum SaveType {
All, Config, Prefs, User, UserPrefs
}
private SaveType saveType = SaveType.Config;
private boolean guiOnly = false;
/**
* Get all XML files in a directory and validate the ability to load and
* store them.
*
* @param saveType the type (i.e. level) of ConfigureXml information being
* saved
* @param isGUI true for files containing GUI elements, i.e. panels.
* These can only be loaded once (others can be loaded
* twice, and that's tested when this is false), and can't
* be loaded when running headless.
*/
public LoadAndStoreTestBase(SaveType saveType, boolean isGUI) {
this.saveType = saveType;
this.guiOnly = isGUI;
}
/**
* Get all XML files in a directory and validate the ability to load and
* store them.
*
* @param directory the directory containing XML files; the subdirectory
* load under this directory will be used
* @param recurse if true, will recurse into subdirectories
* @param pass if true, successful validation will pass; if false,
* successful validation will fail
* @return a stream of {@link Arguments}, where each Argument contains the
* {@link java.io.File} to validate and a boolean matching the pass
* parameter
*/
public static Stream