use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class InjectBridgeTest method testInvokationFail.
@Test(expected = InjectionException.class)
public void testInvokationFail() {
IEclipseContext context = EclipseContextFactory.create();
context.set(Object.class, "Value");
ContextInjectionFactory.invoke(new Concrete(), Execute.class, context);
}
use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class InjectBridgeTest method testInjectionFail.
@Test(expected = InjectionException.class)
public void testInjectionFail() {
IEclipseContext context = EclipseContextFactory.create();
context.set(Object.class, "Value");
ContextInjectionFactory.make(Concrete.class, context);
}
use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class ProviderInjectionTest method testInvokeWithProvider.
@Test
public synchronized void testInvokeWithProvider() {
// create context
IEclipseContext context = EclipseContextFactory.create();
context.set(String.class.getName(), "abc");
IInjector injector = InjectorFactory.getDefault();
injector.addBinding(TestData.class);
TestInvokeClass userObject = new TestInvokeClass();
assertEquals(1, ContextInjectionFactory.invoke(userObject, Execute.class, context, null));
assertNotNull(userObject.provider.get());
assertEquals("abc", userObject.provider.get().data);
}
use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.
the class ServiceContextTest method testServiceRanking.
@Test
public void testServiceRanking() throws InterruptedException {
BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext();
IEclipseContext serviceContext = EclipseContextFactory.getServiceContext(context);
TestBean bean = ContextInjectionFactory.make(TestBean.class, serviceContext);
assertNull(bean.testService);
ServiceReference<TestServiceController> ref = context.getServiceReference(TestServiceController.class);
TestServiceController controller = context.getService(ref);
try {
controller.enableTestServiceB();
// give the service registry and the injection some time
Thread.sleep(100);
assertNotNull(bean.testService);
assertSame(TestServiceB.class, bean.testService.getClass());
assertNotNull(bean.testOtherService);
assertSame(TestServiceB.class, bean.testOtherService.getClass());
// enable a service with a lower ranking
controller.enableTestServiceA();
// give the service registry and the injection some time
Thread.sleep(100);
assertNotNull(bean.testService);
// we expect that still the highest ranked service is injected
assertSame(TestServiceB.class, bean.testService.getClass());
assertNotNull(bean.testOtherService);
assertSame(TestServiceB.class, bean.testOtherService.getClass());
controller.disableTestServiceB();
// give the service registry and the injection some time
Thread.sleep(100);
assertNotNull(bean.testService);
assertSame(TestServiceA.class, bean.testService.getClass());
assertNotNull(bean.testOtherService);
assertSame(TestServiceA.class, bean.testOtherService.getClass());
controller.disableTestServiceA();
// give the service registry and the injection some time
Thread.sleep(100);
assertNull(bean.testService);
assertNull(bean.testOtherService);
} finally {
controller.disableTestServiceA();
controller.disableTestServiceB();
// 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 ServiceContextTest method testOptionalReferences.
@Test
public void testOptionalReferences() throws InterruptedException {
BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext();
IEclipseContext serviceContext = EclipseContextFactory.getServiceContext(context);
TestBean bean = ContextInjectionFactory.make(TestBean.class, serviceContext);
assertNull(bean.testService);
ServiceReference<TestServiceController> ref = context.getServiceReference(TestServiceController.class);
TestServiceController controller = context.getService(ref);
try {
controller.enableTestServiceA();
// give the service registry and the injection some time
Thread.sleep(100);
assertNotNull(bean.testService);
assertSame(TestServiceA.class, bean.testService.getClass());
assertNotNull(bean.testOtherService);
assertSame(TestServiceA.class, bean.testOtherService.getClass());
controller.enableTestServiceB();
// give the service registry and the injection some time
Thread.sleep(100);
assertNotNull(bean.testService);
assertSame(TestServiceB.class, bean.testService.getClass());
assertNotNull(bean.testOtherService);
assertSame(TestServiceB.class, bean.testOtherService.getClass());
controller.disableTestServiceB();
// give the service registry and the injection some time
Thread.sleep(100);
assertNotNull(bean.testService);
assertSame(TestServiceA.class, bean.testService.getClass());
assertNotNull(bean.testOtherService);
assertSame(TestServiceA.class, bean.testOtherService.getClass());
controller.disableTestServiceA();
// give the service registry and the injection some time
Thread.sleep(100);
assertNull(bean.testService);
assertNull(bean.testOtherService);
} finally {
controller.disableTestServiceA();
controller.disableTestServiceB();
// give the service registry and the injection some time to ensure
// clear state after this test
Thread.sleep(100);
}
}
Aggregations