@Test
  public void testJNDIReference() throws Exception {
    final EntityManagerFactory emf =
        Persistence.createEntityManagerFactory("ogm", TestHelper.getEnvironmentProperties());
    SessionFactory factory = ((HibernateEntityManagerFactory) emf).getSessionFactory();
    Reference reference = factory.getReference();
    assertThat(reference.getClassName()).isEqualTo(OgmSessionFactoryImpl.class.getName());
    assertThat(reference.getFactoryClassName())
        .isEqualTo(OgmSessionFactoryObjectFactory.class.getName());
    assertThat(reference.get(0)).isNotNull();
    assertThat(reference.getFactoryClassLocation()).isNull();

    OgmSessionFactoryObjectFactory objFactory = new OgmSessionFactoryObjectFactory();
    SessionFactory factoryFromRegistry =
        (SessionFactory) objFactory.getObjectInstance(reference, null, null, null);
    assertThat(factoryFromRegistry.getClass()).isEqualTo(OgmSessionFactoryImpl.class);
    assertThat(factoryFromRegistry.getReference()).isEqualTo(factory.getReference());

    emf.close();
  }
  @Test
  public void testWrappedFromEntityManagerAPI() throws Exception {
    final EntityManagerFactory emf =
        Persistence.createEntityManagerFactory("ogm", TestHelper.getEnvironmentProperties());
    assertThat(HibernateEntityManagerFactory.class.isAssignableFrom(emf.getClass())).isTrue();
    SessionFactory factory = ((HibernateEntityManagerFactory) emf).getSessionFactory();
    assertThat(factory.getClass()).isEqualTo(OgmSessionFactoryImpl.class);

    Session s = factory.openSession();
    assertThat(s.getClass()).isEqualTo(OgmSessionImpl.class);
    assertThat(s.getSessionFactory().getClass()).isEqualTo(OgmSessionFactoryImpl.class);
    s.close();

    EntityManager em = emf.createEntityManager();
    assertThat(em.unwrap(Session.class) instanceof OgmSession);
    assertThat(em.getDelegate().getClass()).isEqualTo(OgmSessionImpl.class);

    em.close();

    emf.close();
  }
  /**
   * Provides a default {@link OgmConfiguration} for tests, using the given set of annotated entity
   * types.
   *
   * @param entityTypes the entity types for which to build a configuration
   * @return a default configuration based on the given types
   */
  public static OgmConfiguration getDefaultTestConfiguration(Class<?>... entityTypes) {
    OgmConfiguration configuration = new OgmConfiguration();

    // by default use the new id generator scheme...
    configuration.setProperty(Configuration.USE_NEW_ID_GENERATOR_MAPPINGS, "true");

    for (Map.Entry<String, String> entry : TestHelper.getEnvironmentProperties().entrySet()) {
      configuration.setProperty(entry.getKey(), entry.getValue());
    }

    configuration.setProperty(Environment.HBM2DDL_AUTO, "none");

    // volatile indexes for Hibernate Search (if used)
    configuration.setProperty("hibernate.search.default.directory_provider", "ram");
    // disable warnings about unspecified Lucene version
    configuration.setProperty("hibernate.search.lucene_version", "LUCENE_35");

    for (Class<?> aClass : entityTypes) {
      configuration.addAnnotatedClass(aClass);
    }

    return configuration;
  }