Search in sources :

Example 11 with IBean

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);
}
Also used : BeanMetaData(org.eclipse.scout.rt.platform.BeanMetaData) IBean(org.eclipse.scout.rt.platform.IBean) Test(org.junit.Test)

Example 12 with IBean

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);
    }
}
Also used : IBeanManager(org.eclipse.scout.rt.platform.IBeanManager) IBean(org.eclipse.scout.rt.platform.IBean)

Aggregations

IBean (org.eclipse.scout.rt.platform.IBean)12 BeanMetaData (org.eclipse.scout.rt.platform.BeanMetaData)9 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)4 Subject (javax.security.auth.Subject)2 JobCompletionDelayOnSessionShutdown (org.eclipse.scout.rt.client.ClientConfigProperties.JobCompletionDelayOnSessionShutdown)2 TestEnvironmentClientSession (org.eclipse.scout.rt.client.testenvironment.TestEnvironmentClientSession)2 IBeanInstanceProducer (org.eclipse.scout.rt.platform.IBeanInstanceProducer)2 IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)2 RunWithSubject (org.eclipse.scout.rt.testing.platform.runner.RunWithSubject)2 SafeStatementInvoker (org.eclipse.scout.rt.testing.platform.runner.SafeStatementInvoker)2 File (java.io.File)1 Field (java.lang.reflect.Field)1 Permission (java.security.Permission)1 Callable (java.util.concurrent.Callable)1 IClientSession (org.eclipse.scout.rt.client.IClientSession)1 Coordinates (org.eclipse.scout.rt.client.ui.Coordinates)1 IBeanDecorationFactory (org.eclipse.scout.rt.platform.IBeanDecorationFactory)1 IBeanManager (org.eclipse.scout.rt.platform.IBeanManager)1 TimedOutError (org.eclipse.scout.rt.platform.util.concurrent.TimedOutError)1