Search in sources :

Example 26 with IEclipseContext

use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.

the class DisposeClassLinkTest method testMake.

@Test
public void testMake() throws Exception {
    IEclipseContext context = EclipseContextFactory.create();
    MyTest test = ContextInjectionFactory.make(MyTest.class, context);
    assertEquals(0, test.getCount());
    context.dispose();
    assertEquals(1, test.getCount());
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 27 with IEclipseContext

use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.

the class DisposeClassLinkTest method testDisposeParent.

@Test
public void testDisposeParent() throws Exception {
    IEclipseContext parentContext = EclipseContextFactory.create();
    IEclipseContext context = parentContext.createChild();
    MyTest test = ContextInjectionFactory.make(MyTest.class, context);
    assertEquals(0, test.getCount());
    context.dispose();
    assertEquals(1, test.getCount());
    parentContext.dispose();
    assertEquals(1, test.getCount());
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 28 with IEclipseContext

use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.

the class DisposeClassLinkTest method testInjectedWithContext.

@Test
public void testInjectedWithContext() throws Exception {
    IEclipseContext context = EclipseContextFactory.create();
    InjectionObject obj = ContextInjectionFactory.make(InjectionObject.class, context);
    assertEquals("The object has been injected with the context", context, obj.context);
    assertEquals("@PostConstruct should have been called once", 1, obj.postConstruct);
    assertEquals("@PreDestroy should not have been called", 0, obj.preDestroy);
    context.dispose();
    assertNotNull(obj.context);
    assertEquals("@PostConstruct should only have been called once", 1, obj.postConstruct);
    assertEquals("@PreDestroy should have been called during uninjection", 1, obj.preDestroy);
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 29 with IEclipseContext

use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.

the class InjectionOrderTest method testSpecialMethodOnFailure.

/**
 * Make sure special methods are not getting called in case injection failed
 */
@Test
public void testSpecialMethodOnFailure() {
    IEclipseContext appContext = EclipseContextFactory.create();
    boolean exception = false;
    try {
        ContextInjectionFactory.make(InjectUnsatisfied.class, appContext);
    } catch (InjectionException e) {
        exception = true;
    }
    assertTrue(exception);
    appContext.dispose();
    assertEquals(0, InjectUnsatisfied.count);
}
Also used : InjectionException(org.eclipse.e4.core.di.InjectionException) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 30 with IEclipseContext

use of org.eclipse.e4.core.contexts.IEclipseContext in project eclipse.platform.runtime by eclipse.

the class InjectBridgeTest method testInvokation.

@Test
public void testInvokation() {
    IEclipseContext context = EclipseContextFactory.create();
    context.set(String.class, "Value");
    ContextInjectionFactory.invoke(new Concrete(), Execute.class, context);
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) 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