Search in sources :

Example 21 with IEclipseContext

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

the class InjectionErrorReportingTest method testConstructorCastError.

/**
 * Shows the error message for an exception in the injected constructor
 */
@Test(expected = InjectionException.class)
public void testConstructorCastError() {
    IEclipseContext context = EclipseContextFactory.create();
    TestData methodValue = new TestData();
    context.set("testing", methodValue);
    ContextInjectionFactory.make(InjectedConstructorCast.class, context);
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 22 with IEclipseContext

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

the class ContextPerformanceTest method testSetValueRunAndTrack.

/**
 * Tests setting a value in a context that a RAT is listening to. This test mimics what occurs
 * when handlers change in e4. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=305038
 */
public void testSetValueRunAndTrack() {
    context.set("somefunction", new ContextFunction() {

        @Override
        public Object compute(IEclipseContext context, String contextKey) {
            // make sure this function has a large number of dependencies
            for (int i = 0; i < 1000; i++) {
                context.get("NonExistentValue-" + i);
            }
            return context.get("something");
        }
    });
    context.runAndTrack(new RunAndTrack() {

        @Override
        public boolean changed(IEclipseContext context) {
            context.get("somefunction");
            return true;
        }
    });
    new PerformanceTestRunner() {

        int i = 0;

        @Override
        protected void test() {
            context.set("something", "value-" + i++);
        }
    }.run(this, 10, 400);
}
Also used : ContextFunction(org.eclipse.e4.core.contexts.ContextFunction) RunAndTrack(org.eclipse.e4.core.contexts.RunAndTrack) PerformanceTestRunner(org.eclipse.core.tests.harness.PerformanceTestRunner) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext)

Example 23 with IEclipseContext

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

the class ContextPerformanceTest method testSetContextFunction.

public void testSetContextFunction() {
    context.set("somefunction", new ContextFunction() {

        @Override
        public Object compute(IEclipseContext context, String contextKey) {
            return context.get("something");
        }
    });
    new PerformanceTestRunner() {

        int i = 0;

        @Override
        protected void test() {
            context.set("something", "value-" + i++);
        }
    }.run(this, 10, 600000);
}
Also used : ContextFunction(org.eclipse.e4.core.contexts.ContextFunction) PerformanceTestRunner(org.eclipse.core.tests.harness.PerformanceTestRunner) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext)

Example 24 with IEclipseContext

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

the class ContextPerformanceTest method testLookupContextFunction.

public void testLookupContextFunction() {
    context.set("somefunction", new ContextFunction() {

        @Override
        public Object compute(IEclipseContext context, String contextKey) {
            return "result";
        }
    });
    new PerformanceTestRunner() {

        @Override
        protected void test() {
            context.get("somefunction");
        }
    }.run(this, 10, 5000000);
}
Also used : ContextFunction(org.eclipse.e4.core.contexts.ContextFunction) PerformanceTestRunner(org.eclipse.core.tests.harness.PerformanceTestRunner) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext)

Example 25 with IEclipseContext

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

the class DisposeClassLinkTest method testBug430041.

@Test
public void testBug430041() {
    IEclipseContext context = EclipseContextFactory.create();
    TestBug430041 obj = ContextInjectionFactory.make(TestBug430041.class, context);
    context.dispose();
    assertEquals(1, obj.preDestroy);
}
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