<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Can getNextId() be called without error in code being executed by a FeaturesRunner unit test? in Nuxeo Forum</title>
    <link>https://connect.hyland.com/t5/nuxeo-forum/can-getnextid-be-called-without-error-in-code-being-executed-by/m-p/321745#M8746</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I'm working on unit tests as described at &lt;A href="http://doc.nuxeo.com/display/public/CORG/Unit+Testing#UnitTesting-Overview"&gt;http://doc.nuxeo.com/display/public/CORG/Unit+Testing#UnitTesting-Overview&lt;/A&gt;. My Nuxeo Studio extension also has custom UID generation as described at &lt;A href="http://doc.nuxeo.com/display/Studio/Configure+the+ID+generation+using+functions"&gt;http://doc.nuxeo.com/display/Studio/Configure+the+ID+generation+using+functions&lt;/A&gt;.  The unit test class runs to completion and the UID function works correctly, but I notice the following tracebacks in my test run logs:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt; 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
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If I explicitly &lt;CODE&gt;@Deploy&lt;/CODE&gt; the &lt;CODE&gt;org.nuxeo.ecm.platform.uidgen.core&lt;/CODE&gt; to get around the null response to &lt;CODE&gt;getService&lt;/CODE&gt; in that function, I receive a different error:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt; 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
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;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?&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Edit for answer&lt;/STRONG&gt;:&lt;/P&gt;
&lt;P&gt;The following contribution was needed in my test case.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;  &amp;lt;extension target="org.nuxeo.ecm.core.persistence.PersistenceComponent"
             point="hibernate"&amp;gt;
    &amp;lt;hibernateConfiguration name="NXUIDSequencer"&amp;gt;
      &amp;lt;properties&amp;gt;
        &amp;lt;property name="hibernate.connection.url"&amp;gt;jdbc:h2:mem:uidseq&amp;lt;/property&amp;gt;;
        &amp;lt;property name="hibernate.connection.driver_class"&amp;gt;org.h2.Driver&amp;lt;/property&amp;gt;
        &amp;lt;property name="hibernate.connection.auto_commit"&amp;gt;true&amp;lt;/property&amp;gt;
        &amp;lt;property name="hibernate.connection.pool_size"&amp;gt;1&amp;lt;/property&amp;gt;;
        &amp;lt;property name="hibernate.dialect"&amp;gt;org.hibernate.dialect.H2Dialect&amp;lt;/property&amp;gt;
        &amp;lt;property name="hibernate.hbm2ddl.auto"&amp;gt;update&amp;lt;/property&amp;gt;
        &amp;lt;property name="hibernate.show_sql"&amp;gt;false&amp;lt;/property&amp;gt;
        &amp;lt;property name="hibernate.format_sql"&amp;gt;true&amp;lt;/property&amp;gt;
      &amp;lt;/properties&amp;gt;
    &amp;lt;/hibernateConfiguration&amp;gt;
  &amp;lt;/extension&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I also used the following annotations for my test case:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;@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)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 03 Mar 2014 19:00:33 GMT</pubDate>
    <dc:creator>Steven_Huwig1</dc:creator>
    <dc:date>2014-03-03T19:00:33Z</dc:date>
    <item>
      <title>Can getNextId() be called without error in code being executed by a FeaturesRunner unit test?</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/can-getnextid-be-called-without-error-in-code-being-executed-by/m-p/321745#M8746</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I'm working on unit tests as described at &lt;A href="http://doc.nuxeo.com/display/public/CORG/Unit+Testing#UnitTesting-Overview"&gt;http://doc.nuxeo.com/display/public/CORG/Unit+Testing#UnitTesting-Overview&lt;/A&gt;. My Nuxeo Studio extension also has custom UID generation as described at &lt;A href="http://doc.nuxeo.com/display/Studio/Configure+the+ID+generation+using+functions"&gt;http://doc.nuxeo.com/display/Studio/Configure+the+ID+generation+using+functions&lt;/A&gt;.  The unit test class runs to completion and the UID function works correctly, but I notice the following tracebacks in my test run logs:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt; 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
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If I explicitly &lt;CODE&gt;@Deploy&lt;/CODE&gt; the &lt;CODE&gt;org.nuxeo.ecm.platform.uidgen.core&lt;/CODE&gt; to get around the null response to &lt;CODE&gt;getService&lt;/CODE&gt; in that function, I receive a different error:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt; 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
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;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?&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Edit for answer&lt;/STRONG&gt;:&lt;/P&gt;
&lt;P&gt;The following contribution was needed in my test case.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;  &amp;lt;extension target="org.nuxeo.ecm.core.persistence.PersistenceComponent"
             point="hibernate"&amp;gt;
    &amp;lt;hibernateConfiguration name="NXUIDSequencer"&amp;gt;
      &amp;lt;properties&amp;gt;
        &amp;lt;property name="hibernate.connection.url"&amp;gt;jdbc:h2:mem:uidseq&amp;lt;/property&amp;gt;;
        &amp;lt;property name="hibernate.connection.driver_class"&amp;gt;org.h2.Driver&amp;lt;/property&amp;gt;
        &amp;lt;property name="hibernate.connection.auto_commit"&amp;gt;true&amp;lt;/property&amp;gt;
        &amp;lt;property name="hibernate.connection.pool_size"&amp;gt;1&amp;lt;/property&amp;gt;;
        &amp;lt;property name="hibernate.dialect"&amp;gt;org.hibernate.dialect.H2Dialect&amp;lt;/property&amp;gt;
        &amp;lt;property name="hibernate.hbm2ddl.auto"&amp;gt;update&amp;lt;/property&amp;gt;
        &amp;lt;property name="hibernate.show_sql"&amp;gt;false&amp;lt;/property&amp;gt;
        &amp;lt;property name="hibernate.format_sql"&amp;gt;true&amp;lt;/property&amp;gt;
      &amp;lt;/properties&amp;gt;
    &amp;lt;/hibernateConfiguration&amp;gt;
  &amp;lt;/extension&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I also used the following annotations for my test case:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;@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)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Mar 2014 19:00:33 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/can-getnextid-be-called-without-error-in-code-being-executed-by/m-p/321745#M8746</guid>
      <dc:creator>Steven_Huwig1</dc:creator>
      <dc:date>2014-03-03T19:00:33Z</dc:date>
    </item>
    <item>
      <title>Re: Can getNextId() be called without error in code being executed by a FeaturesRunner unit test?</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/can-getnextid-be-called-without-error-in-code-being-executed-by/m-p/321746#M8747</link>
      <description>&lt;P&gt;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)&lt;/P&gt;</description>
      <pubDate>Tue, 04 Mar 2014 10:35:32 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/can-getnextid-be-called-without-error-in-code-being-executed-by/m-p/321746#M8747</guid>
      <dc:creator>Damien_Metzler</dc:creator>
      <dc:date>2014-03-04T10:35:32Z</dc:date>
    </item>
    <item>
      <title>Re: Can getNextId() be called without error in code being executed by a FeaturesRunner unit test?</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/can-getnextid-be-called-without-error-in-code-being-executed-by/m-p/321747#M8748</link>
      <description>&lt;P&gt;This is indeed a Deploying issue, you still need to add different bundles as org.nuxeo.ecm.platform.uidgen.core&lt;/P&gt;
&lt;P&gt;You can take a look at these tests which are using platform functions: &lt;A href="https://github.com/nuxeo/nuxeo-services/tree/master/nuxeo-platform-uidgen-core/src/test/java/org/nuxeo/ecm/platform/uidgen" target="test_blank"&gt;https://github.com/nuxeo/nuxeo-services/tree/master/nuxeo-platform-uidgen-core/src/test/java/org/nuxeo/ecm/platform/uidgen&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Mar 2014 11:11:53 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/can-getnextid-be-called-without-error-in-code-being-executed-by/m-p/321747#M8748</guid>
      <dc:creator>Vladimir_Pasqui</dc:creator>
      <dc:date>2014-03-04T11:11:53Z</dc:date>
    </item>
    <item>
      <title>Re: Can getNextId() be called without error in code being executed by a FeaturesRunner unit test?</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/can-getnextid-be-called-without-error-in-code-being-executed-by/m-p/321748#M8749</link>
      <description>&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Mar 2014 22:37:11 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/can-getnextid-be-called-without-error-in-code-being-executed-by/m-p/321748#M8749</guid>
      <dc:creator>Steven_Huwig1</dc:creator>
      <dc:date>2014-03-04T22:37:11Z</dc:date>
    </item>
  </channel>
</rss>

