cancel
Showing results for 
Search instead for 
Did you mean: 

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

Steven_Huwig1
Star Contributor
Star Contributor

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)
1 ACCEPTED ANSWER

Vladimir_Pasqui
Star Collaborator
Star Collaborator

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/nux...

View answer in original post

3 REPLIES 3

Damien_Metzler
Star Contributor
Star Contributor

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)

Vladimir_Pasqui
Star Collaborator
Star Collaborator

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/nux...

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.

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.