Can getNextId() be called without error in code being executed by a FeaturesRunner unit test?

Hello,

I'm working on unit tests as described at http://doc.nuxeo.com/display/public/CORG/Unit+Testing#UnitTesting-Overview. My Nuxeo Studio extension also has custom UID generation as described at http://doc.nuxeo.com/display/Studio/Configure+the+ID+generation+using+functions. The unit test class runs to completion and the UID function works correctly, but I notice the following tracebacks in my test run logs:

 Exception: OperationException
 Caught error: Failed to invoke operation Context.SetVar

 ...

 Caused by: java.lang.NullPointerException
         at org.nuxeo.ecm.automation.features.PlatformFunctions.getNextId(PlatformFunctions.java:169)
         ... 65 more

If I explicitly @Deploy the org.nuxeo.ecm.platform.uidgen.core to get around the null response to getService in that function, I receive a different error:

 Caused by: java.lang.NullPointerException
         at org.nuxeo.ecm.platform.uidgen.service.UIDSequencerImpl.activatePersistenceProvider(UIDSequencerImpl.java:67)
         at org.nuxeo.ecm.platform.uidgen.service.UIDSequencerImpl.getOrCreatePersistenceProvider(UIDSequencerImpl.java:54)
         at org.nuxeo.ecm.platform.uidgen.service.UIDSequencerImpl.getNext(UIDSequencerImpl.java:87)
         at org.nuxeo.ecm.automation.features.PlatformFunctions.getNextId(PlatformFunctions.java:169)
         ... 65 more

Is there some annotation or tweak I need to do to my unit test to be able to access this functionality without throwing spurious errors in the log?

Edit for answer:

The following contribution was needed in my test case.

  <extension target="org.nuxeo.ecm.core.persistence.PersistenceComponent"
             point="hibernate">
    <hibernateConfiguration name="NXUIDSequencer">
      <properties>
        <property name="hibernate.connection.url">jdbc:h2:mem:uidseq</property>;
        <property name="hibernate.connection.driver_class">org.h2.Driver</property>
        <property name="hibernate.connection.auto_commit">true</property>
        <property name="hibernate.connection.pool_size">1</property>;
        <property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property>
        <property name="hibernate.hbm2ddl.auto">update</property>
        <property name="hibernate.show_sql">false</property>
        <property name="hibernate.format_sql">true</property>
      </properties>
    </hibernateConfiguration>
  </extension>

I also used the following annotations for my test case:

@RunWith(FeaturesRunner.class)
@Deploy({"org.nuxeo.ecm.core.persistence",
"org.nuxeo.ecm.platform.uidgen.core", "org.nuxeo.runtime.datasource"})
@LocalDeploy({"com.example.bundle:OSGI-INF/test-uid-datasource.xml"})
@Features({AutomationFeature.class, RuntimeFeature.class, TransactionalFeature.class})
@RepositoryConfig(type= BackendType.H2, user = "Administrator", init=DefaultRepositoryInit.class)
0 votes

2 answers

3322 views

ANSWER



This is indeed a Deploying issue, you still need to add different bundles as org.nuxeo.ecm.platform.uidgen.core

You can take a look at these tests which are using platform functions: https://github.com/nuxeo/nuxeo-services/tree/master/nuxeo-platform-uidgen-core/src/test/java/org/nuxeo/ecm/platform/uidgen

1 votes



Excellent, thank you very much. I accepted your answer because the Hibernate configuration for NXUIDSequencer seems to be a missing but important piece, but Damien Metzler's was helpful too.
03/04/2014


The second error you get is about the PersistenceService not being deployed. So you also have to add another bundles in your @Deploy annotation. Bundles are “org.nuxeo.runtime.datasource” and “org.nuxeo.ecm.core.persistence” and possibly some other. You can have a look at AuditFeature that deploys everything to make test base on audit work (it also need the PersistenceService)

1 votes