Search in sources :

Example 1 with ObjectBasic

use of org.eclipse.e4.core.internal.tests.contexts.inject.ObjectBasic in project eclipse.platform.runtime by eclipse.

the class ContextInjectionTest method testInjection.

/**
 * Tests basic context injection
 */
@Test
public synchronized void testInjection() {
    Integer testInt = Integer.valueOf(123);
    String testString = "abc";
    Double testDouble = Double.valueOf(1.23);
    Float testFloat = Float.valueOf(12.3f);
    Character testChar = Character.valueOf('v');
    // create context
    IEclipseContext context = EclipseContextFactory.create();
    context.set(Integer.class, testInt);
    context.set(String.class, testString);
    context.set(Double.class, testDouble);
    context.set(Float.class, testFloat);
    context.set(Character.class, testChar);
    ObjectBasic userObject = new ObjectBasic();
    ContextInjectionFactory.inject(userObject, context);
    // check field injection
    assertEquals(testString, userObject.injectedString);
    assertEquals(testInt, userObject.getInt());
    // assertEquals(context, userObject.context);
    // check method injection
    assertEquals(1, userObject.setMethodCalled);
    assertEquals(1, userObject.setMethodCalled2);
    assertEquals(testDouble, userObject.d);
    assertEquals(testFloat, userObject.f);
    assertEquals(testChar, userObject.c);
    // check post processing
    assertTrue(userObject.finalized);
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 2 with ObjectBasic

use of org.eclipse.e4.core.internal.tests.contexts.inject.ObjectBasic in project eclipse.platform.runtime by eclipse.

the class ContextDynamicTest method testAddRemove.

/**
 * Tests objects being added and removed from the context
 */
@Test
public synchronized void testAddRemove() {
    Integer testInt = Integer.valueOf(123);
    String testString = "abc";
    Double testDouble = Double.valueOf(1.23);
    Float testFloat = Float.valueOf(12.3f);
    Character testChar = Character.valueOf('v');
    // create original context
    IEclipseContext context = EclipseContextFactory.create();
    context.set(Integer.class.getName(), testInt);
    context.set(String.class.getName(), testString);
    context.set(Double.class.getName(), testDouble);
    context.set(Float.class.getName(), testFloat);
    context.set(Character.class.getName(), testChar);
    ObjectBasic userObject = new ObjectBasic();
    ContextInjectionFactory.inject(userObject, context);
    // check basic injection
    assertEquals(testString, userObject.injectedString);
    assertEquals(testInt, userObject.getInt());
    assertEquals(context, userObject.context);
    assertEquals(1, userObject.setMethodCalled);
    assertEquals(1, userObject.setMethodCalled2);
    assertEquals(testDouble, userObject.d);
    assertEquals(testFloat, userObject.f);
    assertEquals(testChar, userObject.c);
    // change value
    Double testDouble2 = Double.valueOf(3.45);
    Integer testInt2 = Integer.valueOf(123);
    context.set(Double.class.getName(), testDouble2);
    context.set(Integer.class.getName(), testInt2);
    // and check
    assertEquals(testString, userObject.injectedString);
    assertEquals(testInt2, userObject.getInt());
    assertEquals(context, userObject.context);
    assertEquals(2, userObject.setMethodCalled);
    assertEquals(1, userObject.setMethodCalled2);
    assertEquals(testDouble2, userObject.d);
    assertEquals(testFloat, userObject.f);
    assertEquals(testChar, userObject.c);
    // remove element
    context.remove(String.class.getName());
    context.remove(Character.class.getName());
    // and check
    assertNull(userObject.injectedString);
    assertEquals(testInt2, userObject.getInt());
    assertEquals(context, userObject.context);
    assertEquals(2, userObject.setMethodCalled);
    assertEquals(2, userObject.setMethodCalled2);
    assertEquals(testDouble2, userObject.d);
    assertEquals(testFloat, userObject.f);
    assertNull(userObject.c);
}
Also used : ObjectBasic(org.eclipse.e4.core.internal.tests.contexts.inject.ObjectBasic) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 3 with ObjectBasic

use of org.eclipse.e4.core.internal.tests.contexts.inject.ObjectBasic in project eclipse.platform.runtime by eclipse.

the class ContextDynamicTest method testParentAddRemove.

/**
 * Tests objects being added and removed from the context
 */
@Test
public synchronized void testParentAddRemove() {
    Integer testInt = Integer.valueOf(123);
    String testString = "abc";
    Double testDouble = Double.valueOf(1.23);
    Float testFloat = Float.valueOf(12.3f);
    Character testChar = Character.valueOf('v');
    // create original context
    IEclipseContext parentContext = EclipseContextFactory.create();
    parentContext.set(Integer.class.getName(), testInt);
    parentContext.set(String.class.getName(), testString);
    parentContext.set(Double.class.getName(), testDouble);
    parentContext.set(Float.class.getName(), testFloat);
    parentContext.set(Character.class.getName(), testChar);
    IEclipseContext context = parentContext.createChild();
    ObjectBasic userObject = new ObjectBasic();
    ContextInjectionFactory.inject(userObject, context);
    // check basic injection
    assertEquals(testString, userObject.injectedString);
    assertEquals(testInt, userObject.getInt());
    assertEquals(context, userObject.context);
    assertEquals(1, userObject.setMethodCalled);
    assertEquals(1, userObject.setMethodCalled2);
    assertEquals(testDouble, userObject.d);
    assertEquals(testFloat, userObject.f);
    assertEquals(testChar, userObject.c);
    // change value
    Double testDouble2 = Double.valueOf(3.45);
    Integer testInt2 = Integer.valueOf(123);
    context.set(Double.class.getName(), testDouble2);
    context.set(Integer.class.getName(), testInt2);
    // and check
    assertEquals(testString, userObject.injectedString);
    assertEquals(testInt2, userObject.getInt());
    assertEquals(context, userObject.context);
    assertEquals(2, userObject.setMethodCalled);
    assertEquals(1, userObject.setMethodCalled2);
    assertEquals(testDouble2, userObject.d);
    assertEquals(testFloat, userObject.f);
    assertEquals(testChar, userObject.c);
    // remove element
    parentContext.remove(String.class.getName());
    parentContext.remove(Character.class.getName());
    // and check
    assertNull(userObject.injectedString);
    assertEquals(testInt2, userObject.getInt());
    assertEquals(context, userObject.context);
    assertEquals(2, userObject.setMethodCalled);
    assertEquals(2, userObject.setMethodCalled2);
    assertEquals(testDouble2, userObject.d);
    assertEquals(testFloat, userObject.f);
    assertNull(userObject.c);
}
Also used : ObjectBasic(org.eclipse.e4.core.internal.tests.contexts.inject.ObjectBasic) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 4 with ObjectBasic

use of org.eclipse.e4.core.internal.tests.contexts.inject.ObjectBasic in project eclipse.platform.runtime by eclipse.

the class ContextInjectionTest method testInjectionFromParent.

/**
 * Tests injection of objects from parent context
 */
@Test
public synchronized void testInjectionFromParent() {
    Integer testInt = Integer.valueOf(123);
    String testString = "abc";
    Double testDouble = Double.valueOf(1.23);
    Float testFloat = Float.valueOf(12.3f);
    Character testChar = Character.valueOf('v');
    // create parent context
    IEclipseContext parentContext = EclipseContextFactory.create();
    parentContext.set(Integer.class.getName(), testInt);
    parentContext.set(String.class.getName(), testString);
    // create child context
    IEclipseContext context = parentContext.createChild();
    context.set(Double.class.getName(), testDouble);
    context.set(Float.class.getName(), testFloat);
    context.set(Character.class.getName(), testChar);
    ObjectBasic userObject = new ObjectBasic();
    ContextInjectionFactory.inject(userObject, context);
    // check field injection
    assertEquals(testString, userObject.injectedString);
    assertEquals(testInt, userObject.getInt());
    // assertEquals(context, userObject.context);
    // check method injection
    assertEquals(1, userObject.setMethodCalled);
    assertEquals(1, userObject.setMethodCalled2);
    assertEquals(testDouble, userObject.d);
    assertEquals(testFloat, userObject.f);
    assertEquals(testChar, userObject.c);
    // check post processing
    assertTrue(userObject.finalized);
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 5 with ObjectBasic

use of org.eclipse.e4.core.internal.tests.contexts.inject.ObjectBasic in project eclipse.platform.runtime by eclipse.

the class AnnotationsInjectionTest method testInjection.

/**
 * Tests basic context injection
 */
@Test
public synchronized void testInjection() {
    Integer testInt = Integer.valueOf(123);
    String testString = "abc";
    Double testDouble = Double.valueOf(1.23);
    Float testFloat = Float.valueOf(12.3f);
    Character testChar = Character.valueOf('v');
    // create context
    IEclipseContext context = EclipseContextFactory.create();
    context.set(Integer.class, testInt);
    context.set(String.class, testString);
    context.set(Double.class, testDouble);
    context.set(Float.class, testFloat);
    context.set(Character.class, testChar);
    ObjectBasic userObject = new ObjectBasic();
    ContextInjectionFactory.inject(userObject, context);
    // check field injection
    assertEquals(testString, userObject.injectedString);
    assertEquals(testInt, userObject.getInt());
    assertEquals(context, userObject.context);
    // check method injection
    assertEquals(1, userObject.setMethodCalled);
    assertEquals(1, userObject.setMethodCalled2);
    assertEquals(testDouble, userObject.d);
    assertEquals(testFloat, userObject.f);
    assertEquals(testChar, userObject.c);
    // check post processing
    assertTrue(userObject.finalized);
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Aggregations

IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)5 Test (org.junit.Test)5 ObjectBasic (org.eclipse.e4.core.internal.tests.contexts.inject.ObjectBasic)2