use of jmri.profile.NullProfile in project JMRI by JMRI.
the class JmriUserPreferencesManagerTest method testReadUserPreferences.
@Test
public void testReadUserPreferences() throws IOException {
JUnitUtil.resetProfileManager(new NullProfile(folder.newFolder(Profile.PROFILE)));
Point location = new Point(69, 96);
Dimension windowSize = new Dimension(100, 200);
UserPreferencesManager m1 = new TestJmriUserPreferencesManager();
m1.setSaveAllowed(false);
m1.setProperty(strClass, "test1", "value1");
m1.setProperty(strClass, "intTest", 42);
m1.setProperty(strClass, "doubleTest", Math.PI);
m1.setProperty(strClass, "booleanTest", true);
m1.setWindowLocation(strClass, location);
m1.setWindowSize(strClass, windowSize);
m1.setPreferenceState(strClass, "test2", true);
m1.setPreferenceState(strClass, "test3", false);
m1.setSimplePreferenceState(strClass, true);
m1.setComboBoxLastSelection(strClass, "selection1");
m1.setSaveAllowed(true);
File target = new File(new File(new File(ProfileManager.getDefault().getActiveProfile().getPath(), "profile"), NodeIdentity.identity()), "user-interface.xml");
Assert.assertTrue(target.exists());
Assert.assertTrue(target.isFile());
if (log.isDebugEnabled()) {
Files.lines(target.toPath()).forEach((line) -> log.debug(line));
}
JUnitUtil.resetInstanceManager();
JUnitUtil.resetPreferencesProviders();
JmriUserPreferencesManager m2 = new JmriUserPreferencesManager();
m2.readUserPreferences();
Assert.assertEquals("value1", m2.getProperty(strClass, "test1"));
Assert.assertEquals(42, m2.getProperty(strClass, "intTest"));
Assert.assertEquals(Math.PI, m2.getProperty(strClass, "doubleTest"));
Assert.assertEquals(true, m2.getProperty(strClass, "booleanTest"));
Assert.assertEquals(location, m2.getWindowLocation(strClass));
Assert.assertEquals(windowSize, m2.getWindowSize(strClass));
Assert.assertEquals(true, m2.getPreferenceState(strClass, "test2"));
Assert.assertEquals(false, m2.getPreferenceState(strClass, "test3"));
Assert.assertEquals(true, m2.getSimplePreferenceState(strClass));
Assert.assertEquals("selection1", m2.getComboBoxLastSelection(strClass));
}
use of jmri.profile.NullProfile in project JMRI by JMRI.
the class JUnitUtil method resetProfileManager.
/**
* Use only if profile contents are not to be verified or modified in test.
* If a profile will be written to and its contents verified as part of a
* test use {@link #resetProfileManager(jmri.profile.Profile)} with a
* provided profile.
*
* The new profile will have the name {@literal TestProfile }, the id
* {@literal 00000000 }, and will be in the directory {@literal temp }
* within the sources working copy.
*/
public static void resetProfileManager() {
try {
Profile profile = new NullProfile("TestProfile", "00000000", FileUtil.getFile(FileUtil.SETTINGS));
resetProfileManager(profile);
} catch (FileNotFoundException ex) {
log.error("Settings directory \"{}\" does not exist", FileUtil.SETTINGS);
} catch (IOException | IllegalArgumentException ex) {
log.error("Unable to create profile", ex);
}
}
use of jmri.profile.NullProfile in project JMRI by JMRI.
the class JmriUserPreferencesManagerTest method testSaveElement.
@Test
public void testSaveElement() throws IOException {
JUnitUtil.resetProfileManager(new NullProfile(folder.newFolder(Profile.PROFILE)));
Point location = new Point(69, 96);
Dimension windowSize = new Dimension(100, 200);
UserPreferencesManager m1 = new TestJmriUserPreferencesManager();
m1.setSaveAllowed(false);
m1.setProperty(strClass, "test1", "value1");
m1.setProperty(strClass, "intTest", 42);
m1.setProperty(strClass, "doubleTest", Math.PI);
m1.setProperty(strClass, "booleanTest", true);
m1.setWindowLocation(strClass, location);
m1.setWindowSize(strClass, windowSize);
m1.setPreferenceState(strClass, "test2", true);
m1.setPreferenceState(strClass, "test3", false);
m1.setSimplePreferenceState(strClass, true);
m1.setComboBoxLastSelection(strClass, "selection1");
m1.setSaveAllowed(true);
File target = new File(new File(new File(ProfileManager.getDefault().getActiveProfile().getPath(), "profile"), NodeIdentity.identity()), "user-interface.xml");
Assert.assertTrue(target.exists());
Assert.assertTrue(target.isFile());
if (log.isDebugEnabled()) {
Files.lines(target.toPath()).forEach((line) -> log.debug(line));
}
JUnitUtil.resetInstanceManager();
JUnitUtil.resetPreferencesProviders();
JmriUserPreferencesManager m2 = new JmriUserPreferencesManager();
m2.readUserPreferences();
Assert.assertEquals("value1", m2.getProperty(strClass, "test1"));
Assert.assertEquals(42, m2.getProperty(strClass, "intTest"));
Assert.assertEquals(Math.PI, m2.getProperty(strClass, "doubleTest"));
Assert.assertEquals(true, m2.getProperty(strClass, "booleanTest"));
Assert.assertEquals(location, m2.getWindowLocation(strClass));
Assert.assertEquals(windowSize, m2.getWindowSize(strClass));
Assert.assertEquals(true, m2.getPreferenceState(strClass, "test2"));
Assert.assertEquals(false, m2.getPreferenceState(strClass, "test3"));
Assert.assertEquals(true, m2.getSimplePreferenceState(strClass));
Assert.assertEquals("selection1", m2.getComboBoxLastSelection(strClass));
}
Aggregations