I've used Studio to define an extension point for a new converter. Now I am trying to write a JUnit test that will test it using the Nuxeo Eclipse IDE.
In the setup() method of the test, the following bundles are deployed:
super.setUp();
deployBundle("org.nuxeo.ecm.core.api");
deployBundle("org.nuxeo.ecm.core.convert.api");
deployBundle("org.nuxeo.ecm.core.convert");
deployBundle("org.nuxeo.ecm.platform.commandline.executor");
deployBundle("org.nuxeo.ecm.platform.convert");
cs = Framework.getLocalService(ConversionService.class);
But I'm finding in the main method of the test when it queries the list of all converters that my new converter isn't in the list -- I do see 14 standard converters.
List<String> cc = cs.getRegistredConverters();
I think the reason that I'm not seeing it is because I haven't deployed the extension bundle developed on Studio where the converter is defined via extension points.
When I add the studio extension bundle to the list of deployed bundles in the setup():
deployBundle("studio.extensions.myconverter");
The test program fails and I see in the console log:
DEBUG [OSGiRuntimeService] Loading component for: studio.extensions.myconverter path: OSGI-INF/extensions.xml url: jar:file:/C:/NuxeoDev/nuxeo-cap-5.9.5-tomcat-sdk/nxserver/bundles/myconverter.jar!/OSGI-INF/extensions.xml
INFO [ComponentManagerImpl] Registering component: service:studio.extensions.myconverter
INFO [ComponentRegistry] Registering component: service:studio.extensions.myconverter
DEBUG [ComponentManagerImpl] Dispatching event: COMPONENT_REGISTERED: service:studio.extensions.myconverter
INFO [ComponentManagerImpl] Registration delayed for component: service:studio.extensions.myconverter. Waiting for: [service:org.nuxeo.runtime.started, service:org.nuxeo.ecm.platform.actions, service:org.nuxeo.ecm.directory.sql.storage]
There's the message about "Registration delayed for component"
I thought the message means that it's missing org.nuxeo.runtime.started, ...
So, I tried for example to then also deploy the following before I attempt deploying the Studio extensions:
deployBundle("org.nuxeo.runtime"); // org.nuxeo.runtime.started
But when I do that, it fails with the error:
Failed to start bundle at: C:\NuxeoDev\nuxeo-cap-5.9.5-tomcat-sdk\nxserver\bundles\nuxeo-runtime-5.9.5.jar with activator: org.nuxeo.runtime.osgi.OSGiRuntimeActivator
and I see the following in the console:
DEBUG [OSGiRuntimeService] Bundle: org.nuxeo.runtime components: OSGI-INF/EventService.xml,OSGI-INF/ResourceService.xml,OSGI-INF/DeploymentService.xml,OSGI-INF/LoginComponent.xml,OSGI-INF/ContributionPersistence.xml
DEBUG [OSGiRuntimeService] Loading component for: org.nuxeo.runtime path: OSGI-INF/EventService.xml url: jar:file:/C:/NuxeoDev/nuxeo-cap-5.9.5-tomcat-sdk/nxserver/bundles/nuxeo-runtime-5.9.5.jar!/OSGI-INF/EventService.xml
DEBUG [OSGiRuntimeService] Loading component for: org.nuxeo.runtime path: OSGI-INF/ResourceService.xml url: jar:file:/C:/NuxeoDev/nuxeo-cap-5.9.5-tomcat-sdk/nxserver/bundles/nuxeo-runtime-5.9.5.jar!/OSGI-INF/ResourceService.xml
DEBUG [OSGiRuntimeService] Loading component for: org.nuxeo.runtime path: OSGI-INF/DeploymentService.xml url: jar:file:/C:/NuxeoDev/nuxeo-cap-5.9.5-tomcat-sdk/nxserver/bundles/nuxeo-runtime-5.9.5.jar!/OSGI-INF/DeploymentService.xml
DEBUG [OSGiRuntimeService] Loading component for: org.nuxeo.runtime path: OSGI-INF/LoginComponent.xml url: jar:file:/C:/NuxeoDev/nuxeo-cap-5.9.5-tomcat-sdk/nxserver/bundles/nuxeo-runtime-5.9.5.jar!/OSGI-INF/LoginComponent.xml
DEBUG [OSGiRuntimeService] Loading component for: org.nuxeo.runtime path: OSGI-INF/ContributionPersistence.xml url: jar:file:/C:/NuxeoDev/nuxeo-cap-5.9.5-tomcat-sdk/nxserver/bundles/nuxeo-runtime-5.9.5.jar!/OSGI-INF/ContributionPersistence.xml
DEBUG [OSGiRuntimeService] Home directory: null
DEBUG [OSGiRuntimeService] Working directory: c:\temp\Nuxeo\nxruntime-main-2136295918980629551.tmp\
Any suggestions for what I'm doing wrong?
Is there something that I'm maybe missing in how I've set up the test?
Edit
I have created what seems to be the simplest test for using the Nuxeo IDE JUnit4 wizard. I created a unit test for my plugin project by selecting "Studio Unit Test" from the Nuxeo Artifact Wizard in eclipse. I added a simple test case to it and then tried to run the JUnit test in debug mode:
package com.mycompany.nuxeo.convert.plugins;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.nuxeo.ecm.core.api.CoreSession;
import org.nuxeo.ecm.core.api.DocumentModel;
import org.nuxeo.ecm.platform.test.PlatformFeature;
import org.nuxeo.runtime.test.runner.Deploy;
import org.nuxeo.runtime.test.runner.Features;
import org.nuxeo.runtime.test.runner.FeaturesRunner;
import com.google.inject.Inject;
@RunWith(FeaturesRunner.class)
@Features(PlatformFeature.class)
@Deploy({
})
public class bbbbbb {
@Inject
CoreSession coreSession;
@Test public void testService() throws Exception {
System.out.print("Hello world!");
Assert.assertNotNull(coreSession);
}
}
I put a break inside testService() test case and select Debug from within Eclipse. But the break point is never hit.
I assume that all methods annotated as @Test should be run.
I have debug logging turned up and in the console I see a lot of Nuxeo components being registered, but there are what appear to be quite a few failures too, like the following:
INFO [ComponentManagerImpl] Unregistering component: service:org.nuxeo.ecm.core.scheduler.SchedulerService
DEBUG [ComponentManagerImpl] Dispatching event: DEACTIVATING_COMPONENT: service:org.nuxeo.ecm.core.scheduler.SchedulerService
DEBUG [ComponentManagerImpl] Dispatching event: COMPONENT_DEACTIVATED: service:org.nuxeo.ecm.core.scheduler.SchedulerService
DEBUG [ComponentManagerImpl] Dispatching event: COMPONENT_UNRESOLVED: service:org.nuxeo.ecm.core.scheduler.SchedulerService
DEBUG [ComponentManagerImpl] Dispatching event: COMPONENT_UNREGISTERED: service:org.nuxeo.ecm.core.scheduler.SchedulerService}
I'm not sure if it is because of these messages that the test case isn't run? When I try to run the test without the method testService(), I get an error "No Runnable Methods" and there is no debug output showing that it is attempting to load components.
The test case is associated with a plugin project created using the Nuxeo wizard. The project has "Nuxeo SDK" libraries associated with the project.
Is this the right way to set up a Nuxeo JUnit test to be run inside Eclipse?
Edit August 30, 2014
After now going back to my original test case...
When I again add my bundle created in Studio ("studio.extensions.myconverter") to the the Deploy annotation list, I get the error: java.lang.RuntimeException: Could not resolve bundle org.nuxeo.ecm.platform.actions
org.nuxeo.ecm.platform.actions is referenced from NXRuntimeTestCase, but when looking through all available Manifest.**** files in Nuxeo source code, I don't see that bundle is defined. Should this not be getting referenced from NXRuntimeTestCase? [I do see that there is a bundle called org.nuxeo.ecm.actions which has an Export-Package org.nuxeo.ecm.platform.actions, but not a bundle with that name.]
I also have a question about correctly setting up Eclipse JUnit testing. I was missing a number of bundles related to testing that weren't automatically included with my plugin project. I needed to manually build bundles like nuxeo-core-test-5.9.5.jar, nuxeo-features-test-5.9.5.jar, ...
I then copied these over and used from within Eclipse.
Is there a way to not have to build these bundle jar files manually -- like having the wizard in the ide automatically include the correct test bundle jars?