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


I'm working on unit tests as described at My Nuxeo Studio extension also has custom UID generation as described at 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(
         ... 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(
         at org.nuxeo.ecm.platform.uidgen.service.UIDSequencerImpl.getOrCreatePersistenceProvider(
         at org.nuxeo.ecm.platform.uidgen.service.UIDSequencerImpl.getNext(
         at org.nuxeo.ecm.automation.features.PlatformFunctions.getNextId(
         ... 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"
    <hibernateConfiguration name="NXUIDSequencer">
        <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="">update</property>
        <property name="hibernate.show_sql">false</property>
        <property name="hibernate.format_sql">true</property>

I also used the following annotations for my test case:

"org.nuxeo.ecm.platform.uidgen.core", "org.nuxeo.runtime.datasource"})
@Features({AutomationFeature.class, RuntimeFeature.class, TransactionalFeature.class})
@RepositoryConfig(type= BackendType.H2, user = "Administrator", init=DefaultRepositoryInit.class)
0 votes

2 answers



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:

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.

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