Search in sources :

Example 81 with IEclipseContext

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

the class GenericsInjectionTest method testNamedInjection.

@Test
public synchronized void testNamedInjection() {
    Animal testAnimal = new Animal();
    Bird testBird = new Bird();
    BirdHouse testBirdHouse = new BirdHouse();
    // create context
    IEclipseContext context = EclipseContextFactory.create();
    context.set(Animal.class, testAnimal);
    context.set(Bird.class, testBird);
    context.set("test", testBirdHouse);
    TestNamedObject userObject = new TestNamedObject();
    ContextInjectionFactory.inject(userObject, context);
    // check field injection
    assertEquals(testBirdHouse, userObject.field);
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 82 with IEclipseContext

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

the class GroupedUpdatesTest method testGrouping.

@Test
public void testGrouping() {
    final IEclipseContext context = EclipseContextFactory.create();
    context.set("string1", "x");
    context.set("string2", "y");
    InjectTarget target = new InjectTargetWait();
    ContextInjectionFactory.inject(target, context);
    assertEquals(1, target.countMain);
    target.resetCounters();
    context.set("string1", "a");
    context.set("string2", "b");
    assertEquals(0, target.countMain);
    assertEquals(0, target.countSecondary);
    context.processWaiting();
    assertEquals(1, target.countMain);
    assertEquals(1, target.countSecondary);
    // do it again to make sure we properly cleared waiting updates
    context.processWaiting();
    assertEquals(1, target.countMain);
    assertEquals(1, target.countSecondary);
    // now with 3 updates
    target.resetCounters();
    context.set("string1", "x");
    context.set("string2", "y");
    context.set("string2", "z");
    context.set("string1", "delta");
    assertEquals(0, target.countMain);
    assertEquals(0, target.countSecondary);
    context.processWaiting();
    assertEquals(1, target.countMain);
    assertEquals(1, target.countSecondary);
    assertEquals(target.s1, "delta");
    assertEquals(target.s2, "z");
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 83 with IEclipseContext

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

the class GroupedUpdatesTest method testNoGrouping.

@Test
public void testNoGrouping() {
    IEclipseContext context = EclipseContextFactory.create();
    context.set("string1", "x");
    context.set("string2", "y");
    InjectTarget target = new InjectTargetImmediate();
    ContextInjectionFactory.inject(target, context);
    assertEquals(1, target.countMain);
    target.resetCounters();
    // I want these two sets to be one transaction
    context.set("string1", "a");
    context.set("string2", "b");
    assertEquals(2, target.countMain);
    assertEquals(1, target.countSecondary);
    context.processWaiting();
    assertEquals(2, target.countMain);
    assertEquals(1, target.countSecondary);
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 84 with IEclipseContext

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

the class InjectionOrderTest method testDisposeMethod.

/**
 * Tests to ensure that the injection/uninjection order of fields is correct.
 * <p>
 * See bug 304859.
 * </p>
 */
@Test
public void testDisposeMethod() throws Exception {
    // create a context
    IEclipseContext appContext = EclipseContextFactory.create();
    // set a value
    appContext.set("inject", "a");
    // instantiate the object
    InjectTargetMethod injectTargetMethod = ContextInjectionFactory.make(InjectTargetMethod.class, appContext);
    // change the requested value so another injection occurs
    appContext.set("inject", "b");
    // now we dispose the context
    appContext.dispose();
    // check that the second 'set' invocation did not alter the order of notifications
    assertTrue("@PreDestroy was incorrectly called after the method was uninjected", injectTargetMethod.nonNull);
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 85 with IEclipseContext

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

the class InjectionOrderTest method testDisposeField.

/**
 * Tests to ensure that the injection/uninjection order of methods is correct.
 * <p>
 * See bug 304859.
 * </p>
 */
@Test
public void testDisposeField() throws Exception {
    // create a context
    IEclipseContext appContext = EclipseContextFactory.create();
    // set a value
    appContext.set("inject", "a");
    // instantiate the object
    InjectTargetField injectTargetField = ContextInjectionFactory.make(InjectTargetField.class, appContext);
    // change the requested value so another injection occurs
    appContext.set("inject", "b");
    // now we dispose the context
    appContext.dispose();
    assertTrue("@PreDestroy was incorrectly called after the field was uninjected", injectTargetField.nonNull);
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Aggregations

IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)197 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 MApplication (org.eclipse.e4.ui.model.application.MApplication)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