| Setting IEclipsePreferences in headless build [message #1207881] | 
Sun, 24 November 2013 15:41   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
In my pure-e4 application I have a class that accesses preference values via the @Preference annotation: 
@Inject @Preference(nodePath = "my.application.bundle.id", value = "FOO") String fooName;
  
This works fine. I also have a JUnit plug-in test for this class where I want to set the Preference to a certain value: 
IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode("my.application.bundle.id");
prefs.put("FOO", "bar");
 
This also works fine when running the test in Eclipse. However, when running a headless build (Tycho) I get the following error for the test: 
Unable to process "ClassUnderTest.fooName": no actual value was found for the argument "String[@org.eclipse.e4.core.di.extensions.Preference(nodePath=my.application.bundle.id, value=FOO)]".
  
Normal injections via @Inject work fine in Tycho plug-in tests. So there seems to be a problem with the @Preference annotation. I tried several things, e.g. adding prefs to an IEclipseContext in my test and injecting it into ClassUnderTest: 
IEclipseContext context = EclipseContextFactory.create();
context.set(IEclipsePreferences.class, prefs);
ContextInjectionFactory.make(ClassUnderTest.class, context);
  
but that didn't change anything. I suspect the problem lies in the fact that "Preference values are not stored directly in the IEclipseContext but contributed by an ExtendedObjectSupplier" [vogella.com] 
 
How can I create a Preference Value in my JUnit plug-in test so it can be injected and accessed by ClassUnderTest when running the test with Tycho?
 |  
 |  
  | 
 | 
| Re: Setting IEclipsePreferences in headless build [message #1209769 is a reply to message #1209437] | 
Mon, 25 November 2013 12:50   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
In fact, I was missing equinox.ds since I wasn't aware of its relation to ExtendedObjectSuppliers.  
I added the following to my plugin-test's pom file 
<plugin>
  <groupId>org.eclipse.tycho</groupId>
  <artifactId>tycho-surefire-plugin</artifactId>
  <configuration>
    <dependencies>
      <dependency>
        <type>p2-installable-unit</type>
        <artifactId>org.eclipse.equinox.ds</artifactId>
      </dependency>
    </dependencies>
  </configuration>
</plugin>
 
and now everything works fine.  
Awesome! Thanks for the quick reply! 
Thorsten
 |  
 |  
  | 
Powered by 
FUDForum. Page generated in 0.04011 seconds