-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: OGM Tests using persistence.xml configuration
PostPosted: Mon Apr 10, 2017 6:04 am 
Newbie

Joined: Mon Apr 03, 2017 6:04 am
Posts: 4
Hi,

I am working on a new datastore provider based on NeoEmf. My entity classes are generated and I can not (can, but probably too much work) modify the generation templates in order to add JPA annotations to them. As a result, I would like to use xxx-orm.xml mappings to describe my entities.

I am trying to test this by extending the OgmTestCase (and thus using OgmTestRunner). It seems that the current implementation does not scan the test/resources folder to find persistence.xml files. As a result if I remove the hiberante.properties file and use a persistence.xml file the tests fail.

I am getting an exception:
Code:
Cannot load class org.hibernate.ogm.datastore.infinispan.impl.InfinispanEmbeddedDatastoreProvider specified via configuration property 'hibernate.ogm.datastore.provider'


Which indicates that the test is not loading my datastore provider (btw, why is infinispan the default?) . It works when using the hiberante.properties.

Is there any way I can instruct the test case to use the properties.xml file to load the database/entities configuration?

My current digging suggests that I would ahve to modify (extend) the OgmTestRunner and the ogm.utils.TestHelper in order to
change how the SessionFactory is craeted and add the orm.xml mappings programatically (using addResource). Probably by using a new annotation @TestMappings so that the test case can provide a list of mapping files that should be added to the session factory.

Thanks!


Top
 Profile  
 
 Post subject: Re: OGM Tests using persistence.xml configuration
PostPosted: Tue Apr 11, 2017 6:48 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
Can you try with `OgmJpaTestCase`? It will use a different runner (OgmJpaTestRunner) that seems suited for what you are looking for.

That's the implementation we use when we want to test bwith JPA, OgmTestCase is for when we want to test the HIbernate Session.

We also have a JUnit rule to select a specific persistence XML file. You can check JPAJTATest for an example:

Code:
public class JPAJTATest extends OgmJpaTestCase {
   @Rule
   public PackagingRule packaging = new PackagingRule( "persistencexml/transaction-type-jta.xml", Poem.class );

   @Test
   public void testBootstrapAndCRUD() throws Exception {

      final EntityManagerFactory emf = Persistence.createEntityManagerFactory(
            "transaction-type-jta", TestHelper.getDefaultTestSettings()
      );

      TransactionManager transactionManager = getTransactionManager( emf );

      transactionManager.begin();
      final EntityManager em = emf.createEntityManager();
      Poem poem = new Poem();
      poem.setName( "L'albatros" );
      em.persist( poem );
      transactionManager.commit();

      em.clear();

      transactionManager.begin();
      em.joinTransaction();
      poem = em.find( Poem.class, poem.getId() );
      assertThat( poem ).isNotNull();
      assertThat( poem.getName() ).isEqualTo( "L'albatros" );
      em.remove( poem );
      transactionManager.commit();

      em.close();

      dropSchemaAndDatabase( emf );
      emf.close();
   }

   @Override
   public Class<?>[] getAnnotatedClasses() {
      return new Class<?>[] { Poem.class };
   }
}


Historyically, Hibernate OGM was born has a mapper for Infinispan and I think that's the reason is still set as a default.


Top
 Profile  
 
 Post subject: Re: OGM Tests using persistence.xml configuration
PostPosted: Tue Apr 11, 2017 9:23 am 
Newbie

Joined: Mon Apr 03, 2017 6:04 am
Posts: 4
Thanks, that seems exactly what I need!

On a realted note, what is the approach to testing?

I find that each datastore follows it own set of tests, that is some use the Bookmark entity to test type mappings, others not. Some create an initial dabase some dont... I was hoping to follow the lead of the exsiting datastores, but frankly I am lost on what is expected to be tested.

Any pointes/links to information on what you expect/need from a datastore, test wise?

Cheers,


Top
 Profile  
 
 Post subject: Re: OGM Tests using persistence.xml configuration
PostPosted: Wed Apr 12, 2017 5:21 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
In core there are several test under the package: org.hibernate.ogm.backendtck
These tests are executed by default for each dialect. Every dialects may have additional tests that are run only on that particular dialect, it depends what we are testing and when we were working on it.

For example, in Neo4j we use native cypher queries to make that the content of the db is exactly the one we expect after some operations.
Sometimes, we re-used the same entity model in different tests, this is something taht we tend to avoid now and we prefer if each test uses it's own model (unless the tests are related somehow).

The reason for having different approaches is that every datastore is different, for example if you have an embedded or in memory datastore is very easy to start it up at the beginning of the test create the database and then destroy everything. Some other datastores don't have an embedded or in emory version and therefore we prefer to start them before the build and then execute the tests on them. Usually we dopr the database or delete everything after each test using the method in TestHelper'#dropSchemaAndDatabase. In short, it dependes what you can do with the datastore you are working with.

In general we expect that the dialect can pass most of the tests in the backendtck package, it means it should be able to execute CRUD operations on entities and associations with Id generation. We also expect some documentation describing the mapping (tests would be ideal). These requirement might change depedeing on the datastore.

Being able to convert HQL queries is not that important in the beginning.

There are other things that can be added but it usually varies from datastore to datastore.

I think the thing to keep in mind is that we expect to have documentation, tests a build that passes and clean code.

I hope this help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.