cancel
Showing results for 
Search instead for 
Did you mean: 

Nuxeo IDE Test

dweisinger
Confirmed Champ
Confirmed Champ

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.mf 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?

6 REPLIES 6

Damien_Metzler
Star Contributor
Star Contributor

Hello,

org.nuxeo.runtime should already be deployed by the test framework. To get the org.nuxeo.runtime.started component deployed, you can deploy a fake component :

<component name="org.nuxeo.runtime.started">
</component>

But which test framework are you using ? You should follow http://doc.nuxeo.com/display/CORG/Unit+Testing and use the CoreFeature in order not to have to deploy manually all core bundles.

I've tried to create a working example of a JUnit test by using the IDE Wizard for generating a "Studio JUnit Test". I've added more information in my description above. But it still isn't working for me.

The messages you see are not failure. By using the FeaturesRunner, it starts the nuxeo runtime (component are loading) and stops it at the end (components are unloaded). What is the result of your simple test ?

I have a breakpoint in the test method, but it doesn't get there. Also when I check the console log, I don't see the "Hello world" message. But you're right, in the console debug information it looks like it is loading up components and then unloading them, but it never runs the method annotated with @Test.

I have the simple test case working now. I wasn't looking at the JUnit Failure traceback -- there I saw that I was missing the test jar nuxeo-core-storage-sql-test-5.9.5.jar. After including that it is working.

My questions are

Getting started

Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.