use of org.eclipse.scout.rt.platform.IBean in project scout.rt by eclipse.
the class PreferencesTest method test.
@Test
public void test() throws Exception {
Preferences prefs = new Preferences("X", null);
prefs.put("any", "Any");
prefs.putBoolean("bool", true);
prefs.putByteArray("byte", new byte[] { (byte) 1, (byte) 2, (byte) 3 });
prefs.putDouble("double", 1.23);
prefs.putFloat("float", 1.23f);
prefs.putInt("int", 123);
prefs.putLong("long", 123L);
assertEquals(true, prefs.isDirty());
assertEquals("X", prefs.name());
assertEquals(7, prefs.keys().size());
assertEquals("Any", prefs.get("any", null));
assertEquals("Xyz", prefs.get("xyz", "Xyz"));
assertEquals(true, prefs.getBoolean("bool", false));
assertEquals(true, prefs.getBoolean("xyz", true));
assertArrayEquals(new byte[] { (byte) 1, (byte) 2, (byte) 3 }, prefs.getByteArray("byte", null));
assertArrayEquals(new byte[] { (byte) 9 }, prefs.getByteArray("xyz", new byte[] { (byte) 9 }));
assertEquals(1.23, prefs.getDouble("double", 0), 0.0);
assertEquals(9.0, prefs.getDouble("xyz", 9.0), 0.0);
assertEquals(1.23f, prefs.getFloat("float", 0), 0.0);
assertEquals(9.0f, prefs.getFloat("xyz", 9.0f), 0.0);
assertEquals(123, prefs.getInt("int", 0));
assertEquals(9, prefs.getInt("xyz", 9));
assertEquals(123L, prefs.getLong("long", 0));
assertEquals(9L, prefs.getLong("xyz", 9L));
prefs.put("double", "123");
prefs.put("float", "123");
prefs.put("int", "123");
prefs.put("long", "123");
assertEquals(123.0, prefs.getDouble("double", 0), 0.0);
assertEquals(123f, prefs.getFloat("float", 0), 0.0);
assertEquals(123, prefs.getInt("int", 0));
assertEquals(123L, prefs.getLong("long", 0));
TestingUserPreferencesStorageService svc = new TestingUserPreferencesStorageService();
List<IBean<?>> registerServices = TestingUtility.registerBeans(new BeanMetaData(IUserPreferencesStorageService.class).withInitialInstance(svc).withApplicationScoped(true));
try {
prefs.flush();
} finally {
TestingUtility.unregisterBeans(registerServices);
}
assertFalse(prefs.isDirty());
assertTrue(svc.m_flushed);
}
use of org.eclipse.scout.rt.platform.IBean in project scout.rt by eclipse.
the class RegisterBeanStatement method evaluate.
@Override
public void evaluate() throws Throwable {
final IBeanManager beanManager = Platform.get().getBeanManager();
final IBean bean = beanManager.registerBean(m_beanMetaData);
try {
m_next.evaluate();
} finally {
beanManager.unregisterBean(bean);
}
}
Aggregations