Search in sources :

Example 31 with IEclipseContext

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);
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 32 with IEclipseContext

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);
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 33 with IEclipseContext

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);
}
Also used : Execute(org.eclipse.e4.core.di.annotations.Execute) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) IInjector(org.eclipse.e4.core.di.IInjector) Test(org.junit.Test)

Example 34 with IEclipseContext

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);
    }
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 35 with IEclipseContext

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);
    }
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Aggregations

IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)195 Test (org.junit.Test)142 RunAndTrack (org.eclipse.e4.core.contexts.RunAndTrack)18 ContextFunction (org.eclipse.e4.core.contexts.ContextFunction)17 BundleContext (org.osgi.framework.BundleContext)15 IEntity (org.whole.lang.model.IEntity)11 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)9 Execute (org.eclipse.e4.core.di.annotations.Execute)7 MPart (org.eclipse.e4.ui.model.application.ui.basic.MPart)6 IImportAsModelDialogFactory (org.whole.lang.ui.dialogs.IImportAsModelDialogFactory)6 Hashtable (java.util.Hashtable)5 PrimaryObjectSupplier (org.eclipse.e4.core.di.suppliers.PrimaryObjectSupplier)4 Named (javax.inject.Named)3 PerformanceTestRunner (org.eclipse.core.tests.harness.PerformanceTestRunner)3 InjectionException (org.eclipse.e4.core.di.InjectionException)3 CanExecute (org.eclipse.e4.core.di.annotations.CanExecute)3 Optional (org.eclipse.e4.core.di.annotations.Optional)3 UISynchronize (org.eclipse.e4.ui.di.UISynchronize)3 ContextMenuProvider (org.eclipse.gef.ContextMenuProvider)3 IMenuManager (org.eclipse.jface.action.IMenuManager)3