use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class ServiceSupplierTestCase method testDynamicAddRemove.
@Test
public void testDynamicAddRemove() {
BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext();
IEclipseContext serviceContext = EclipseContextFactory.getServiceContext(context);
TestBean bean = ContextInjectionFactory.make(TestBean.class, serviceContext);
assertEquals(1, bean.serviceInjectionCount);
assertEquals(1, bean.serviceListInjectionCount);
TestService t = new TestService() {
};
Hashtable<String, Object> properties = new Hashtable<>();
// $NON-NLS-1$
properties.put("service.ranking", 52);
this.registrations.add(context.registerService(TestService.class, t, properties));
assertSame(t, bean.service);
assertEquals(2, bean.serviceInjectionCount);
assertEquals(2, bean.serviceListInjectionCount);
assertEquals(5, bean.serviceList.size());
assertSame(t, bean.serviceList.get(0));
ServiceRegistration<?> registration = this.registrations.get(0);
registration.unregister();
this.registrations.remove(registration);
assertEquals(3, bean.serviceInjectionCount);
assertEquals(3, bean.serviceListInjectionCount);
assertSame(SampleServiceA.class, bean.service.getClass());
assertEquals(4, bean.serviceList.size());
assertSame(SampleServiceA.class, bean.serviceList.get(0).getClass());
assertSame(SampleServiceB.class, bean.serviceList.get(1).getClass());
}
use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class ServiceSupplierTestCase method testOptionalReferences.
@Test
public void testOptionalReferences() throws InterruptedException {
BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext();
IEclipseContext serviceContext = EclipseContextFactory.getServiceContext(context);
TestDisabledBean bean = ContextInjectionFactory.make(TestDisabledBean.class, serviceContext);
assertNull(bean.disabledService);
assertEquals(0, bean.services.size());
ServiceReference<ComponentEnabler> ref = context.getServiceReference(ComponentEnabler.class);
ComponentEnabler enabler = context.getService(ref);
try {
enabler.enableDisabledServiceA();
// give the service registry and the injection some time
Thread.sleep(100);
assertNotNull(bean.disabledService);
assertEquals(1, bean.services.size());
assertSame(DisabledServiceA.class, bean.disabledService.getClass());
enabler.enableDisabledServiceB();
// give the service registry and the injection some time
Thread.sleep(100);
assertNotNull(bean.disabledService);
assertEquals(2, bean.services.size());
assertSame(DisabledServiceB.class, bean.disabledService.getClass());
enabler.disableDisabledServiceB();
// give the service registry and the injection some time
Thread.sleep(100);
assertNotNull(bean.disabledService);
assertEquals(1, bean.services.size());
assertSame(DisabledServiceA.class, bean.disabledService.getClass());
enabler.disableDisabledServiceA();
// give the service registry and the injection some time
Thread.sleep(100);
assertNull(bean.disabledService);
assertEquals(0, bean.services.size());
} finally {
enabler.disableDisabledServiceA();
enabler.disableDisabledServiceB();
// give the service registry and the injection some time to ensure
// clear state after this test
Thread.sleep(100);
}
}
use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class ComputedValueLimitationTest method testVolatileFunction.
@Test
public void testVolatileFunction() {
IEclipseContext context = EclipseContextFactory.create();
context.set("time", new Time());
long time = ((Long) context.get("time")).longValue();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
//
}
long newTime = ((Long) context.get("time")).longValue();
assertTrue(time != newTime);
}
use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class InjectionErrorReportingTest method testFieldInjectionError.
/**
* Shows the error message for an unresolved field value
*/
@Test(expected = InjectionException.class)
public void testFieldInjectionError() {
IEclipseContext context = EclipseContextFactory.create();
TestData methodValue = new TestData();
context.set("testing", methodValue);
InjectedField object = new InjectedField();
ContextInjectionFactory.inject(object, context);
}
use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class InjectionErrorReportingTest method testMethodInjectionError.
/**
* Shows the error message for an unresolved method argument
*/
@Test(expected = InjectionException.class)
public void testMethodInjectionError() {
IEclipseContext context = EclipseContextFactory.create();
TestData methodValue = new TestData();
context.set("testing", methodValue);
InjectedMethod object = new InjectedMethod();
ContextInjectionFactory.inject(object, context);
}
Aggregations